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