Fixing bug where folders didn't show up on the bookmarks page
This commit is contained in:
parent
73136e4b56
commit
12a93d208d
@ -8,6 +8,7 @@ import android.app.Application;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Single;
|
import com.anthonycr.bonsai.Single;
|
||||||
import com.anthonycr.bonsai.SingleAction;
|
import com.anthonycr.bonsai.SingleAction;
|
||||||
@ -75,8 +76,16 @@ public final class BookmarkPage {
|
|||||||
|
|
||||||
private static final String FOLDER_ICON = "folder.png";
|
private static final String FOLDER_ICON = "folder.png";
|
||||||
|
|
||||||
private File mFilesDir;
|
@NonNull
|
||||||
private File mCacheDir;
|
private static File getBookmarkPage(@NonNull Application application, @Nullable String folder) {
|
||||||
|
String prefix = !TextUtils.isEmpty(folder) ? folder + '-' : "";
|
||||||
|
return new File(application.getFilesDir(), prefix + FILENAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private static File getFaviconFile(@NonNull Application application) {
|
||||||
|
return new File(application.getCacheDir(), FOLDER_ICON);
|
||||||
|
}
|
||||||
|
|
||||||
@Inject Application mApp;
|
@Inject Application mApp;
|
||||||
@Inject BookmarkModel mManager;
|
@Inject BookmarkModel mManager;
|
||||||
@ -95,12 +104,10 @@ public final class BookmarkPage {
|
|||||||
return Single.create(new SingleAction<String>() {
|
return Single.create(new SingleAction<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
||||||
mCacheDir = mApp.getCacheDir();
|
|
||||||
mFilesDir = mApp.getFilesDir();
|
|
||||||
cacheDefaultFolderIcon();
|
cacheDefaultFolderIcon();
|
||||||
buildBookmarkPage(null);
|
buildBookmarkPage(null);
|
||||||
|
|
||||||
File bookmarkWebPage = new File(mFilesDir, FILENAME);
|
File bookmarkWebPage = getBookmarkPage(mApp, null);
|
||||||
|
|
||||||
subscriber.onItem(Constants.FILE + bookmarkWebPage);
|
subscriber.onItem(Constants.FILE + bookmarkWebPage);
|
||||||
subscriber.onComplete();
|
subscriber.onComplete();
|
||||||
@ -110,9 +117,8 @@ public final class BookmarkPage {
|
|||||||
|
|
||||||
private void cacheDefaultFolderIcon() {
|
private void cacheDefaultFolderIcon() {
|
||||||
FileOutputStream outputStream = null;
|
FileOutputStream outputStream = null;
|
||||||
File image = new File(mCacheDir, FOLDER_ICON);
|
|
||||||
try {
|
try {
|
||||||
outputStream = new FileOutputStream(image);
|
outputStream = new FileOutputStream(getFaviconFile(mApp));
|
||||||
mFolderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
|
mFolderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
|
||||||
mFolderIcon.recycle();
|
mFolderIcon.recycle();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
@ -126,23 +132,40 @@ public final class BookmarkPage {
|
|||||||
mManager.getBookmarksFromFolderSorted(folder)
|
mManager.getBookmarksFromFolderSorted(folder)
|
||||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onItem(@Nullable List<HistoryItem> list) {
|
public void onItem(@Nullable final List<HistoryItem> list) {
|
||||||
Preconditions.checkNonNull(list);
|
Preconditions.checkNonNull(list);
|
||||||
|
|
||||||
final File bookmarkWebPage;
|
if (folder == null) {
|
||||||
if (folder == null || folder.isEmpty()) {
|
mManager.getFoldersSorted()
|
||||||
bookmarkWebPage = new File(mFilesDir, FILENAME);
|
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||||
} else {
|
@Override
|
||||||
bookmarkWebPage = new File(mFilesDir, folder + '-' + FILENAME);
|
public void onItem(@Nullable List<HistoryItem> item) {
|
||||||
|
Preconditions.checkNonNull(item);
|
||||||
|
|
||||||
|
list.addAll(item);
|
||||||
|
|
||||||
|
buildPageHtml(list, null);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
buildPageHtml(list, folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildPageHtml(@NonNull List<HistoryItem> bookmarksAndFolders, @Nullable String folder) {
|
||||||
|
final File bookmarkWebPage = getBookmarkPage(mApp, folder);
|
||||||
|
|
||||||
final StringBuilder bookmarkBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2);
|
final StringBuilder bookmarkBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2);
|
||||||
|
|
||||||
final String folderIconPath = Constants.FILE + mCacheDir + '/' + FOLDER_ICON;
|
final String folderIconPath = getFaviconFile(mApp).toString();
|
||||||
for (int n = 0, size = list.size(); n < size; n++) {
|
|
||||||
final HistoryItem item = list.get(n);
|
for (int n = 0, size = bookmarksAndFolders.size(); n < size; n++) {
|
||||||
|
final HistoryItem item = bookmarksAndFolders.get(n);
|
||||||
bookmarkBuilder.append(PART1);
|
bookmarkBuilder.append(PART1);
|
||||||
if (item.isFolder()) {
|
if (item.isFolder()) {
|
||||||
final File folderPage = new File(mFilesDir, item.getTitle() + '-' + FILENAME);
|
final File folderPage = getBookmarkPage(mApp, item.getTitle());
|
||||||
bookmarkBuilder.append(Constants.FILE).append(folderPage);
|
bookmarkBuilder.append(Constants.FILE).append(folderPage);
|
||||||
bookmarkBuilder.append(PART2);
|
bookmarkBuilder.append(PART2);
|
||||||
bookmarkBuilder.append(folderIconPath);
|
bookmarkBuilder.append(folderIconPath);
|
||||||
@ -168,7 +191,5 @@ public final class BookmarkPage {
|
|||||||
Utils.close(bookWriter);
|
Utils.close(bookWriter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public final class DownloadsPage {
|
|||||||
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
||||||
buildDownloadsPage();
|
buildDownloadsPage();
|
||||||
|
|
||||||
File downloadsWebPage = new File(getDownloadsPageFile(mApp), FILENAME);
|
File downloadsWebPage = getDownloadsPageFile(mApp);
|
||||||
|
|
||||||
subscriber.onItem(Constants.FILE + downloadsWebPage);
|
subscriber.onItem(Constants.FILE + downloadsWebPage);
|
||||||
subscriber.onComplete();
|
subscriber.onComplete();
|
||||||
|
@ -49,6 +49,7 @@ import acr.browser.lightning.utils.AdBlock;
|
|||||||
import acr.browser.lightning.utils.IntentUtils;
|
import acr.browser.lightning.utils.IntentUtils;
|
||||||
import acr.browser.lightning.utils.Preconditions;
|
import acr.browser.lightning.utils.Preconditions;
|
||||||
import acr.browser.lightning.utils.ProxyUtils;
|
import acr.browser.lightning.utils.ProxyUtils;
|
||||||
|
import acr.browser.lightning.utils.UrlUtils;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
|
||||||
public class LightningWebClient extends WebViewClient {
|
public class LightningWebClient extends WebViewClient {
|
||||||
@ -359,7 +360,7 @@ public class LightningWebClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (url.startsWith(Constants.FILE)) {
|
} else if (url.startsWith(Constants.FILE) && !UrlUtils.isSpecialUrl(url)) {
|
||||||
File file = new File(url.replace(Constants.FILE, ""));
|
File file = new File(url.replace(Constants.FILE, ""));
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user