|
|
@ -6,27 +6,30 @@ package acr.browser.lightning.constant; |
|
|
|
import android.app.Activity; |
|
|
|
import android.app.Activity; |
|
|
|
import android.app.Application; |
|
|
|
import android.app.Application; |
|
|
|
import android.graphics.Bitmap; |
|
|
|
import android.graphics.Bitmap; |
|
|
|
import android.os.AsyncTask; |
|
|
|
|
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.anthonycr.bonsai.Single; |
|
|
|
|
|
|
|
import com.anthonycr.bonsai.SingleAction; |
|
|
|
|
|
|
|
import com.anthonycr.bonsai.SingleSubscriber; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.FileWriter; |
|
|
|
import java.io.FileWriter; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.lang.ref.WeakReference; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject; |
|
|
|
|
|
|
|
|
|
|
|
import acr.browser.lightning.R; |
|
|
|
import acr.browser.lightning.R; |
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
import acr.browser.lightning.database.BookmarkManager; |
|
|
|
import acr.browser.lightning.database.BookmarkManager; |
|
|
|
import acr.browser.lightning.database.HistoryItem; |
|
|
|
import acr.browser.lightning.database.HistoryItem; |
|
|
|
import acr.browser.lightning.utils.ThemeUtils; |
|
|
|
import acr.browser.lightning.utils.ThemeUtils; |
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
import acr.browser.lightning.view.LightningView; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final class BookmarkPage extends AsyncTask<Void, Void, Void> { |
|
|
|
public final class BookmarkPage { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The bookmark page standard suffix |
|
|
|
* The bookmark page standard suffix |
|
|
@ -67,38 +70,34 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> { |
|
|
|
private File mFilesDir; |
|
|
|
private File mFilesDir; |
|
|
|
private File mCacheDir; |
|
|
|
private File mCacheDir; |
|
|
|
|
|
|
|
|
|
|
|
private final Application mApp; |
|
|
|
@Inject Application mApp; |
|
|
|
private final BookmarkManager mManager; |
|
|
|
@Inject BookmarkManager mManager; |
|
|
|
@NonNull private final WeakReference<LightningView> mTabReference; |
|
|
|
|
|
|
|
private final Bitmap mFolderIcon; |
|
|
|
private final Bitmap mFolderIcon; |
|
|
|
@NonNull private final String mTitle; |
|
|
|
@NonNull private final String mTitle; |
|
|
|
|
|
|
|
|
|
|
|
public BookmarkPage(LightningView tab, @NonNull Activity activity, BookmarkManager manager) { |
|
|
|
public BookmarkPage(@NonNull Activity activity) { |
|
|
|
mApp = BrowserApp.get(activity); |
|
|
|
BrowserApp.getAppComponent().inject(this); |
|
|
|
final Bitmap folderIcon = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, false); |
|
|
|
mFolderIcon = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, false); |
|
|
|
mTitle = mApp.getString(R.string.action_bookmarks); |
|
|
|
mTitle = mApp.getString(R.string.action_bookmarks); |
|
|
|
mManager = manager; |
|
|
|
|
|
|
|
mTabReference = new WeakReference<>(tab); |
|
|
|
|
|
|
|
mFolderIcon = folderIcon; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
|
|
|
public Single<String> getBookmarkPage() { |
|
|
|
|
|
|
|
return Single.create(new SingleAction<String>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Void doInBackground(Void... params) { |
|
|
|
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) { |
|
|
|
mCacheDir = mApp.getCacheDir(); |
|
|
|
mCacheDir = mApp.getCacheDir(); |
|
|
|
mFilesDir = mApp.getFilesDir(); |
|
|
|
mFilesDir = mApp.getFilesDir(); |
|
|
|
cacheDefaultFolderIcon(); |
|
|
|
cacheDefaultFolderIcon(); |
|
|
|
buildBookmarkPage(null, mManager); |
|
|
|
buildBookmarkPage(null); |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void onPostExecute(Void aVoid) { |
|
|
|
|
|
|
|
super.onPostExecute(aVoid); |
|
|
|
|
|
|
|
LightningView tab = mTabReference.get(); |
|
|
|
|
|
|
|
if (tab != null) { |
|
|
|
|
|
|
|
File bookmarkWebPage = new File(mFilesDir, FILENAME); |
|
|
|
File bookmarkWebPage = new File(mFilesDir, FILENAME); |
|
|
|
tab.loadUrl(Constants.FILE + bookmarkWebPage); |
|
|
|
|
|
|
|
|
|
|
|
subscriber.onItem(Constants.FILE + bookmarkWebPage); |
|
|
|
|
|
|
|
subscriber.onComplete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void cacheDefaultFolderIcon() { |
|
|
|
private void cacheDefaultFolderIcon() { |
|
|
@ -115,8 +114,8 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void buildBookmarkPage(@Nullable final String folder, @NonNull final BookmarkManager manager) { |
|
|
|
private void buildBookmarkPage(@Nullable final String folder) { |
|
|
|
final List<HistoryItem> list = manager.getBookmarksCopyFromFolder(folder, true); |
|
|
|
final List<HistoryItem> list = mManager.getBookmarksCopyFromFolder(folder, true); |
|
|
|
final File bookmarkWebPage; |
|
|
|
final File bookmarkWebPage; |
|
|
|
if (folder == null || folder.isEmpty()) { |
|
|
|
if (folder == null || folder.isEmpty()) { |
|
|
|
bookmarkWebPage = new File(mFilesDir, FILENAME); |
|
|
|
bookmarkWebPage = new File(mFilesDir, FILENAME); |
|
|
@ -134,7 +133,7 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> { |
|
|
|
bookmarkBuilder.append(Constants.FILE).append(folderPage); |
|
|
|
bookmarkBuilder.append(Constants.FILE).append(folderPage); |
|
|
|
bookmarkBuilder.append(PART2); |
|
|
|
bookmarkBuilder.append(PART2); |
|
|
|
bookmarkBuilder.append(folderIconPath); |
|
|
|
bookmarkBuilder.append(folderIconPath); |
|
|
|
buildBookmarkPage(item.getTitle(), manager); |
|
|
|
buildBookmarkPage(item.getTitle()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bookmarkBuilder.append(item.getUrl()); |
|
|
|
bookmarkBuilder.append(item.getUrl()); |
|
|
|
bookmarkBuilder.append(PART2).append(PART3); |
|
|
|
bookmarkBuilder.append(PART2).append(PART3); |
|
|
@ -157,8 +156,4 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void load() { |
|
|
|
|
|
|
|
executeOnExecutor(BrowserApp.getIOThread()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|