Making html page generation reactive
This commit is contained in:
parent
bed8163399
commit
0819d35711
@ -423,7 +423,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
mTabsManager.newTab(this, "", false);
|
||||
mTabsManager.switchToTab(0);
|
||||
mTabsManager.clearSavedState();
|
||||
HistoryPage.deleteHistoryPage(getApplication());
|
||||
new HistoryPage().deleteHistoryPage().subscribe();
|
||||
closeBrowser();
|
||||
// System exit needed in the case of receiving
|
||||
// the panic intent since finish() isn't completely
|
||||
@ -1533,7 +1533,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
* function that opens the HTML history page in the browser
|
||||
*/
|
||||
private void openHistory() {
|
||||
HistoryPage.getHistoryPage()
|
||||
new HistoryPage().getHistoryPage()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
|
@ -164,11 +164,29 @@ public class TabsManager {
|
||||
String url = item.getString(URL_KEY);
|
||||
if (url != null && tab.getWebView() != null) {
|
||||
if (UrlUtils.isBookmarkUrl(url)) {
|
||||
new BookmarkPage(tab, activity, mBookmarkManager).load();
|
||||
new BookmarkPage(activity).getBookmarkPage()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void onItem(@Nullable String item) {
|
||||
Preconditions.checkNonNull(item);
|
||||
tab.loadUrl(item);
|
||||
}
|
||||
});
|
||||
} else if (UrlUtils.isStartPageUrl(url)) {
|
||||
new StartPage(tab, mApp).load();
|
||||
new StartPage().getHomepage()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void onItem(@Nullable String item) {
|
||||
Preconditions.checkNonNull(item);
|
||||
tab.loadUrl(item);
|
||||
}
|
||||
});
|
||||
} else if (UrlUtils.isHistoryUrl(url)) {
|
||||
HistoryPage.getHistoryPage()
|
||||
new HistoryPage().getHistoryPage()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
|
@ -8,6 +8,8 @@ import acr.browser.lightning.activity.TabsManager;
|
||||
import acr.browser.lightning.activity.ThemableBrowserActivity;
|
||||
import acr.browser.lightning.activity.ThemableSettingsActivity;
|
||||
import acr.browser.lightning.browser.BrowserPresenter;
|
||||
import acr.browser.lightning.constant.BookmarkPage;
|
||||
import acr.browser.lightning.constant.HistoryPage;
|
||||
import acr.browser.lightning.constant.StartPage;
|
||||
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||
import acr.browser.lightning.download.LightningDownloadListener;
|
||||
@ -62,6 +64,10 @@ public interface AppComponent {
|
||||
|
||||
void inject(StartPage startPage);
|
||||
|
||||
void inject(HistoryPage historyPage);
|
||||
|
||||
void inject(BookmarkPage bookmarkPage);
|
||||
|
||||
void inject(BrowserPresenter presenter);
|
||||
|
||||
void inject(TabsManager manager);
|
||||
|
@ -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
|
||||
@ -34,25 +37,25 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
|
||||
public static final String FILENAME = "bookmarks.html";
|
||||
|
||||
private static final String HEADING_1 = "<!DOCTYPE html><html xmlns=http://www.w3.org/1999/xhtml>\n" +
|
||||
"<head>\n" +
|
||||
"<meta content=en-us http-equiv=Content-Language />\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" +
|
||||
"<title>";
|
||||
"<head>\n" +
|
||||
"<meta content=en-us http-equiv=Content-Language />\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" +
|
||||
"<title>";
|
||||
|
||||
private static final String HEADING_2 = "</title>\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{" +
|
||||
"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>";
|
||||
"</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{" +
|
||||
"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>";
|
||||
|
||||
private static final String PART1 = "<div class=box><a href='";
|
||||
|
||||
private static final String PART2 = "'></a>\n" +
|
||||
"<div class=margin>\n" +
|
||||
"<div class=box-content>\n" +
|
||||
"<p class=ellipses>\n" +
|
||||
"<img src='";
|
||||
"<div class=margin>\n" +
|
||||
"<div class=box-content>\n" +
|
||||
"<p class=ellipses>\n" +
|
||||
"<img src='";
|
||||
|
||||
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 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 folderIcon = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, false);
|
||||
public BookmarkPage(@NonNull Activity activity) {
|
||||
BrowserApp.getAppComponent().inject(this);
|
||||
mFolderIcon = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, false);
|
||||
mTitle = mApp.getString(R.string.action_bookmarks);
|
||||
mManager = manager;
|
||||
mTabReference = new WeakReference<>(tab);
|
||||
mFolderIcon = folderIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
mCacheDir = mApp.getCacheDir();
|
||||
mFilesDir = mApp.getFilesDir();
|
||||
cacheDefaultFolderIcon();
|
||||
buildBookmarkPage(null, mManager);
|
||||
return null;
|
||||
}
|
||||
@NonNull
|
||||
public Single<String> getBookmarkPage() {
|
||||
return Single.create(new SingleAction<String>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
||||
mCacheDir = mApp.getCacheDir();
|
||||
mFilesDir = mApp.getFilesDir();
|
||||
cacheDefaultFolderIcon();
|
||||
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);
|
||||
}
|
||||
File bookmarkWebPage = new File(mFilesDir, FILENAME);
|
||||
|
||||
subscriber.onItem(Constants.FILE + bookmarkWebPage);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
final List<HistoryItem> list = manager.getBookmarksCopyFromFolder(folder, true);
|
||||
private void buildBookmarkPage(@Nullable final String folder) {
|
||||
final List<HistoryItem> list = mManager.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> {
|
||||
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> {
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
executeOnExecutor(BrowserApp.getIOThread());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.anthonycr.bonsai.Completable;
|
||||
import com.anthonycr.bonsai.CompletableAction;
|
||||
import com.anthonycr.bonsai.CompletableSubscriber;
|
||||
import com.anthonycr.bonsai.Single;
|
||||
import com.anthonycr.bonsai.SingleAction;
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
@ -19,6 +22,8 @@ import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.app.BrowserApp;
|
||||
import acr.browser.lightning.database.HistoryItem;
|
||||
@ -46,15 +51,21 @@ public class HistoryPage {
|
||||
|
||||
private static final String END = "</div></body></html>";
|
||||
|
||||
private HistoryPage() {}
|
||||
@NonNull private final String mTitle;
|
||||
|
||||
@Inject Application mApp;
|
||||
|
||||
public HistoryPage() {
|
||||
BrowserApp.getAppComponent().inject(this);
|
||||
mTitle = mApp.getString(R.string.action_history);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Single<String> getHistoryPage() {
|
||||
public Single<String> getHistoryPage() {
|
||||
return Single.create(new SingleAction<String>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull final SingleSubscriber<String> subscriber) {
|
||||
final String title = BrowserApp.getApplication().getString(R.string.action_history);
|
||||
final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + title + HEADING_2);
|
||||
final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2);
|
||||
|
||||
HistoryModel.lastHundredVisitedHistoryItems()
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
@ -76,7 +87,7 @@ public class HistoryPage {
|
||||
}
|
||||
|
||||
historyBuilder.append(END);
|
||||
File historyWebPage = new File(BrowserApp.getApplication().getFilesDir(), FILENAME);
|
||||
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
|
||||
FileWriter historyWriter = null;
|
||||
try {
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
@ -97,17 +108,26 @@ public class HistoryPage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to immediately delete the history
|
||||
* page on the current thread. This will clear the
|
||||
* cached history page that was stored on file.
|
||||
* Use this observable to immediately delete the history
|
||||
* page. This will clear the cached history page that was
|
||||
* stored on file.
|
||||
*
|
||||
* @param application the application object needed to get the file.
|
||||
* @return a completable that deletes the history page
|
||||
* when subscribed.
|
||||
*/
|
||||
public static void deleteHistoryPage(@NonNull Application application) {
|
||||
File historyWebPage = new File(application.getFilesDir(), FILENAME);
|
||||
if (historyWebPage.exists()) {
|
||||
historyWebPage.delete();
|
||||
}
|
||||
@NonNull
|
||||
public Completable deleteHistoryPage() {
|
||||
return Completable.create(new CompletableAction() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
|
||||
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
|
||||
if (historyWebPage.exists()) {
|
||||
historyWebPage.delete();
|
||||
}
|
||||
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -4,14 +4,15 @@
|
||||
package acr.browser.lightning.constant;
|
||||
|
||||
import android.app.Application;
|
||||
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.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -19,9 +20,8 @@ import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.app.BrowserApp;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
import acr.browser.lightning.view.LightningView;
|
||||
|
||||
public class StartPage extends AsyncTask<Void, Void, Void> {
|
||||
public class StartPage {
|
||||
|
||||
public static final String FILENAME = "homepage.html";
|
||||
|
||||
@ -55,142 +55,118 @@ public class StartPage extends AsyncTask<Void, Void, Void> {
|
||||
private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}</script></body></html>";
|
||||
|
||||
@NonNull private final String mTitle;
|
||||
@NonNull private final Application mApp;
|
||||
@NonNull private final WeakReference<LightningView> mTabReference;
|
||||
|
||||
@Inject Application mApp;
|
||||
@Inject PreferenceManager mPreferenceManager;
|
||||
|
||||
private String mStartpageUrl;
|
||||
|
||||
public StartPage(LightningView tab, @NonNull Application app) {
|
||||
public StartPage() {
|
||||
BrowserApp.getAppComponent().inject(this);
|
||||
mTitle = app.getString(R.string.home);
|
||||
mApp = app;
|
||||
mTabReference = new WeakReference<>(tab);
|
||||
mTitle = mApp.getString(R.string.home);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
mStartpageUrl = getHomepage();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
LightningView tab = mTabReference.get();
|
||||
if (tab != null) {
|
||||
tab.loadUrl(mStartpageUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method builds the homepage and returns the local URL to be loaded
|
||||
* when it finishes building.
|
||||
*
|
||||
* @return the URL to load
|
||||
*/
|
||||
@NonNull
|
||||
private String getHomepage() {
|
||||
StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2);
|
||||
String icon;
|
||||
String searchUrl;
|
||||
switch (mPreferenceManager.getSearchChoice()) {
|
||||
case 0:
|
||||
// CUSTOM SEARCH
|
||||
icon = "file:///android_asset/lightning.png";
|
||||
searchUrl = mPreferenceManager.getSearchUrl();
|
||||
break;
|
||||
case 1:
|
||||
// GOOGLE_SEARCH;
|
||||
icon = "file:///android_asset/google.png";
|
||||
// "https://www.google.com/images/srpr/logo11w.png";
|
||||
searchUrl = Constants.GOOGLE_SEARCH;
|
||||
break;
|
||||
case 2:
|
||||
// ANDROID SEARCH;
|
||||
icon = "file:///android_asset/ask.png";
|
||||
searchUrl = Constants.ASK_SEARCH;
|
||||
break;
|
||||
case 3:
|
||||
// BING_SEARCH;
|
||||
icon = "file:///android_asset/bing.png";
|
||||
// "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png";
|
||||
searchUrl = Constants.BING_SEARCH;
|
||||
break;
|
||||
case 4:
|
||||
// YAHOO_SEARCH;
|
||||
icon = "file:///android_asset/yahoo.png";
|
||||
// "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png";
|
||||
searchUrl = Constants.YAHOO_SEARCH;
|
||||
break;
|
||||
case 5:
|
||||
// STARTPAGE_SEARCH;
|
||||
icon = "file:///android_asset/startpage.png";
|
||||
// "https://com/graphics/startp_logo.gif";
|
||||
searchUrl = Constants.STARTPAGE_SEARCH;
|
||||
break;
|
||||
case 6:
|
||||
// STARTPAGE_MOBILE
|
||||
icon = "file:///android_asset/startpage.png";
|
||||
// "https://com/graphics/startp_logo.gif";
|
||||
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
|
||||
break;
|
||||
case 7:
|
||||
// DUCK_SEARCH;
|
||||
icon = "file:///android_asset/duckduckgo.png";
|
||||
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
|
||||
searchUrl = Constants.DUCK_SEARCH;
|
||||
break;
|
||||
case 8:
|
||||
// DUCK_LITE_SEARCH;
|
||||
icon = "file:///android_asset/duckduckgo.png";
|
||||
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
|
||||
searchUrl = Constants.DUCK_LITE_SEARCH;
|
||||
break;
|
||||
case 9:
|
||||
// BAIDU_SEARCH;
|
||||
icon = "file:///android_asset/baidu.png";
|
||||
// "http://www.baidu.com/img/bdlogo.gif";
|
||||
searchUrl = Constants.BAIDU_SEARCH;
|
||||
break;
|
||||
case 10:
|
||||
// YANDEX_SEARCH;
|
||||
icon = "file:///android_asset/yandex.png";
|
||||
// "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png";
|
||||
searchUrl = Constants.YANDEX_SEARCH;
|
||||
break;
|
||||
default:
|
||||
// DEFAULT GOOGLE_SEARCH;
|
||||
icon = "file:///android_asset/google.png";
|
||||
searchUrl = Constants.GOOGLE_SEARCH;
|
||||
break;
|
||||
public Single<String> getHomepage() {
|
||||
return Single.create(new SingleAction<String>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
||||
|
||||
}
|
||||
StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2);
|
||||
String icon;
|
||||
String searchUrl;
|
||||
switch (mPreferenceManager.getSearchChoice()) {
|
||||
case 0:
|
||||
// CUSTOM SEARCH
|
||||
icon = "file:///android_asset/lightning.png";
|
||||
searchUrl = mPreferenceManager.getSearchUrl();
|
||||
break;
|
||||
case 1:
|
||||
// GOOGLE_SEARCH;
|
||||
icon = "file:///android_asset/google.png";
|
||||
// "https://www.google.com/images/srpr/logo11w.png";
|
||||
searchUrl = Constants.GOOGLE_SEARCH;
|
||||
break;
|
||||
case 2:
|
||||
// ANDROID SEARCH;
|
||||
icon = "file:///android_asset/ask.png";
|
||||
searchUrl = Constants.ASK_SEARCH;
|
||||
break;
|
||||
case 3:
|
||||
// BING_SEARCH;
|
||||
icon = "file:///android_asset/bing.png";
|
||||
// "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png";
|
||||
searchUrl = Constants.BING_SEARCH;
|
||||
break;
|
||||
case 4:
|
||||
// YAHOO_SEARCH;
|
||||
icon = "file:///android_asset/yahoo.png";
|
||||
// "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png";
|
||||
searchUrl = Constants.YAHOO_SEARCH;
|
||||
break;
|
||||
case 5:
|
||||
// STARTPAGE_SEARCH;
|
||||
icon = "file:///android_asset/startpage.png";
|
||||
// "https://com/graphics/startp_logo.gif";
|
||||
searchUrl = Constants.STARTPAGE_SEARCH;
|
||||
break;
|
||||
case 6:
|
||||
// STARTPAGE_MOBILE
|
||||
icon = "file:///android_asset/startpage.png";
|
||||
// "https://com/graphics/startp_logo.gif";
|
||||
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
|
||||
break;
|
||||
case 7:
|
||||
// DUCK_SEARCH;
|
||||
icon = "file:///android_asset/duckduckgo.png";
|
||||
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
|
||||
searchUrl = Constants.DUCK_SEARCH;
|
||||
break;
|
||||
case 8:
|
||||
// DUCK_LITE_SEARCH;
|
||||
icon = "file:///android_asset/duckduckgo.png";
|
||||
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
|
||||
searchUrl = Constants.DUCK_LITE_SEARCH;
|
||||
break;
|
||||
case 9:
|
||||
// BAIDU_SEARCH;
|
||||
icon = "file:///android_asset/baidu.png";
|
||||
// "http://www.baidu.com/img/bdlogo.gif";
|
||||
searchUrl = Constants.BAIDU_SEARCH;
|
||||
break;
|
||||
case 10:
|
||||
// YANDEX_SEARCH;
|
||||
icon = "file:///android_asset/yandex.png";
|
||||
// "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png";
|
||||
searchUrl = Constants.YANDEX_SEARCH;
|
||||
break;
|
||||
default:
|
||||
// DEFAULT GOOGLE_SEARCH;
|
||||
icon = "file:///android_asset/google.png";
|
||||
searchUrl = Constants.GOOGLE_SEARCH;
|
||||
break;
|
||||
|
||||
homepageBuilder.append(icon);
|
||||
homepageBuilder.append(MIDDLE);
|
||||
homepageBuilder.append(searchUrl);
|
||||
homepageBuilder.append(END);
|
||||
}
|
||||
|
||||
File homepage = new File(mApp.getFilesDir(), FILENAME);
|
||||
FileWriter hWriter = null;
|
||||
try {
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
hWriter = new FileWriter(homepage, false);
|
||||
hWriter.write(homepageBuilder.toString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
Utils.close(hWriter);
|
||||
}
|
||||
homepageBuilder.append(icon);
|
||||
homepageBuilder.append(MIDDLE);
|
||||
homepageBuilder.append(searchUrl);
|
||||
homepageBuilder.append(END);
|
||||
|
||||
return Constants.FILE + homepage;
|
||||
}
|
||||
File homepage = new File(mApp.getFilesDir(), FILENAME);
|
||||
FileWriter hWriter = null;
|
||||
try {
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
hWriter = new FileWriter(homepage, false);
|
||||
hWriter.write(homepageBuilder.toString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
Utils.close(hWriter);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
executeOnExecutor(BrowserApp.getIOThread());
|
||||
subscriber.onItem(Constants.FILE + homepage);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ import acr.browser.lightning.preference.PreferenceManager;
|
||||
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
|
||||
import acr.browser.lightning.utils.Preconditions;
|
||||
import acr.browser.lightning.utils.ProxyUtils;
|
||||
import acr.browser.lightning.utils.UrlUtils;
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
@ -81,16 +82,16 @@ public class LightningView {
|
||||
private static String sDefaultUserAgent;
|
||||
private static float sMaxFling;
|
||||
private static final float[] sNegativeColorArray = {
|
||||
-1.0f, 0, 0, 0, 255, // red
|
||||
0, -1.0f, 0, 0, 255, // green
|
||||
0, 0, -1.0f, 0, 255, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
-1.0f, 0, 0, 0, 255, // red
|
||||
0, -1.0f, 0, 0, 255, // green
|
||||
0, 0, -1.0f, 0, 255, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
};
|
||||
private static final float[] sIncreaseContrastColorArray = {
|
||||
2.0f, 0, 0, 0, -160.f, // red
|
||||
0, 2.0f, 0, 0, -160.f, // green
|
||||
0, 0, 2.0f, 0, -160.f, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
2.0f, 0, 0, 0, -160.f, // red
|
||||
0, 2.0f, 0, 0, -160.f, // green
|
||||
0, 0, 2.0f, 0, -160.f, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
};
|
||||
|
||||
@NonNull private final LightningViewTitle mTitle;
|
||||
@ -213,7 +214,16 @@ public class LightningView {
|
||||
* UI thread.
|
||||
*/
|
||||
private void loadStartpage() {
|
||||
new StartPage(this, BrowserApp.get(mActivity)).load();
|
||||
new StartPage().getHomepage()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void onItem(@Nullable String item) {
|
||||
Preconditions.checkNonNull(item);
|
||||
loadUrl(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -222,9 +232,16 @@ public class LightningView {
|
||||
* UI thread. It also caches the default folder icon locally.
|
||||
*/
|
||||
public void loadBookmarkpage() {
|
||||
if (mWebView == null)
|
||||
return;
|
||||
new BookmarkPage(this, mActivity, mBookmarkManager).load();
|
||||
new BookmarkPage(mActivity).getBookmarkPage()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void onItem(@Nullable String item) {
|
||||
Preconditions.checkNonNull(item);
|
||||
loadUrl(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -353,7 +370,7 @@ public class LightningView {
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,
|
||||
!mPreferences.getBlockThirdPartyCookiesEnabled());
|
||||
!mPreferences.getBlockThirdPartyCookiesEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@ -695,7 +712,7 @@ public class LightningView {
|
||||
break;
|
||||
case 1:
|
||||
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(
|
||||
sNegativeColorArray);
|
||||
sNegativeColorArray);
|
||||
mPaint.setColorFilter(filterInvert);
|
||||
setHardwareRendering();
|
||||
|
||||
@ -724,7 +741,7 @@ public class LightningView {
|
||||
|
||||
case 4:
|
||||
ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter(
|
||||
sIncreaseContrastColorArray);
|
||||
sIncreaseContrastColorArray);
|
||||
mPaint.setColorFilter(IncreaseHighContrast);
|
||||
setHardwareRendering();
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user