|
|
@ -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 |
|
|
@ -34,25 +37,25 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> { |
|
|
|
public static final String FILENAME = "bookmarks.html"; |
|
|
|
public static final String FILENAME = "bookmarks.html"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String HEADING_1 = "<!DOCTYPE html><html xmlns=http://www.w3.org/1999/xhtml>\n" + |
|
|
|
private static final String HEADING_1 = "<!DOCTYPE html><html xmlns=http://www.w3.org/1999/xhtml>\n" + |
|
|
|
"<head>\n" + |
|
|
|
"<head>\n" + |
|
|
|
"<meta content=en-us http-equiv=Content-Language />\n" + |
|
|
|
"<meta content=en-us http-equiv=Content-Language />\n" + |
|
|
|
"<meta content='text/html; charset=utf-8' http-equiv=Content-Type />\n" + |
|
|
|
"<meta content='text/html; charset=utf-8' http-equiv=Content-Type />\n" + |
|
|
|
"<meta name=viewport content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'>\n" + |
|
|
|
"<meta name=viewport content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'>\n" + |
|
|
|
"<title>"; |
|
|
|
"<title>"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String HEADING_2 = "</title>\n" + |
|
|
|
private static final String HEADING_2 = "</title>\n" + |
|
|
|
"</head>\n" + |
|
|
|
"</head>\n" + |
|
|
|
"<style>body{background:#f5f5f5;max-width:100%;min-height:100%}#content{width:100%;max-width:800px;margin:0 auto;text-align:center}.box{vertical-align:middle;text-align:center;position:relative;display:inline-block;height:45px;width:150px;margin:10px;background-color:#fff;box-shadow:0 3px 6px rgba(0,0,0,0.25);font-family:Arial;color:#444;font-size:12px;-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px}.box-content{height:25px;width:100%;vertical-align:middle;text-align:center;display:table-cell}p.ellipses{" + |
|
|
|
"<style>body{background:#f5f5f5;max-width:100%;min-height:100%}#content{width:100%;max-width:800px;margin:0 auto;text-align:center}.box{vertical-align:middle;text-align:center;position:relative;display:inline-block;height:45px;width:150px;margin:10px;background-color:#fff;box-shadow:0 3px 6px rgba(0,0,0,0.25);font-family:Arial;color:#444;font-size:12px;-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px}.box-content{height:25px;width:100%;vertical-align:middle;text-align:center;display:table-cell}p.ellipses{" + |
|
|
|
"width:130px;font-size: small;font-family: Arial, Helvetica, 'sans-serif';white-space:nowrap;overflow:hidden;text-align:left;vertical-align:middle;margin:auto;text-overflow:ellipsis;-o-text-overflow:ellipsis;-ms-text-overflow:ellipsis}.box a{width:100%;height:100%;position:absolute;left:0;top:0}img{vertical-align:middle;margin-right:10px;width:20px;height:20px;}.margin{margin:10px}</style>\n" + |
|
|
|
"width:130px;font-size: small;font-family: Arial, Helvetica, 'sans-serif';white-space:nowrap;overflow:hidden;text-align:left;vertical-align:middle;margin:auto;text-overflow:ellipsis;-o-text-overflow:ellipsis;-ms-text-overflow:ellipsis}.box a{width:100%;height:100%;position:absolute;left:0;top:0}img{vertical-align:middle;margin-right:10px;width:20px;height:20px;}.margin{margin:10px}</style>\n" + |
|
|
|
"<body><div id=content>"; |
|
|
|
"<body><div id=content>"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String PART1 = "<div class=box><a href='"; |
|
|
|
private static final String PART1 = "<div class=box><a href='"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String PART2 = "'></a>\n" + |
|
|
|
private static final String PART2 = "'></a>\n" + |
|
|
|
"<div class=margin>\n" + |
|
|
|
"<div class=margin>\n" + |
|
|
|
"<div class=box-content>\n" + |
|
|
|
"<div class=box-content>\n" + |
|
|
|
"<p class=ellipses>\n" + |
|
|
|
"<p class=ellipses>\n" + |
|
|
|
"<img src='"; |
|
|
|
"<img src='"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String PART3 = "https://www.google.com/s2/favicons?domain="; |
|
|
|
private static final String PART3 = "https://www.google.com/s2/favicons?domain="; |
|
|
|
|
|
|
|
|
|
|
@ -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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@NonNull |
|
|
|
protected Void doInBackground(Void... params) { |
|
|
|
public Single<String> getBookmarkPage() { |
|
|
|
mCacheDir = mApp.getCacheDir(); |
|
|
|
return Single.create(new SingleAction<String>() { |
|
|
|
mFilesDir = mApp.getFilesDir(); |
|
|
|
@Override |
|
|
|
cacheDefaultFolderIcon(); |
|
|
|
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) { |
|
|
|
buildBookmarkPage(null, mManager); |
|
|
|
mCacheDir = mApp.getCacheDir(); |
|
|
|
return null; |
|
|
|
mFilesDir = mApp.getFilesDir(); |
|
|
|
} |
|
|
|
cacheDefaultFolderIcon(); |
|
|
|
|
|
|
|
buildBookmarkPage(null); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
File bookmarkWebPage = new File(mFilesDir, FILENAME); |
|
|
|
protected void onPostExecute(Void aVoid) { |
|
|
|
|
|
|
|
super.onPostExecute(aVoid); |
|
|
|
subscriber.onItem(Constants.FILE + bookmarkWebPage); |
|
|
|
LightningView tab = mTabReference.get(); |
|
|
|
subscriber.onComplete(); |
|
|
|
if (tab != null) { |
|
|
|
} |
|
|
|
File bookmarkWebPage = new File(mFilesDir, FILENAME); |
|
|
|
}); |
|
|
|
tab.loadUrl(Constants.FILE + bookmarkWebPage); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|