Browse Source

Making html page generation reactive

master
anthony restaino 8 years ago
parent
commit
0819d35711
  1. 4
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 24
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  3. 6
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  4. 93
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  5. 48
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java
  6. 244
      app/src/main/java/acr/browser/lightning/constant/StartPage.java
  7. 47
      app/src/main/java/acr/browser/lightning/view/LightningView.java

4
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -423,7 +423,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mTabsManager.newTab(this, "", false); mTabsManager.newTab(this, "", false);
mTabsManager.switchToTab(0); mTabsManager.switchToTab(0);
mTabsManager.clearSavedState(); mTabsManager.clearSavedState();
HistoryPage.deleteHistoryPage(getApplication()); new HistoryPage().deleteHistoryPage().subscribe();
closeBrowser(); closeBrowser();
// System exit needed in the case of receiving // System exit needed in the case of receiving
// the panic intent since finish() isn't completely // 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 * function that opens the HTML history page in the browser
*/ */
private void openHistory() { private void openHistory() {
HistoryPage.getHistoryPage() new HistoryPage().getHistoryPage()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new SingleOnSubscribe<String>() { .subscribe(new SingleOnSubscribe<String>() {

24
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -164,11 +164,29 @@ public class TabsManager {
String url = item.getString(URL_KEY); String url = item.getString(URL_KEY);
if (url != null && tab.getWebView() != null) { if (url != null && tab.getWebView() != null) {
if (UrlUtils.isBookmarkUrl(url)) { 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)) { } 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)) { } else if (UrlUtils.isHistoryUrl(url)) {
HistoryPage.getHistoryPage() new HistoryPage().getHistoryPage()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new SingleOnSubscribe<String>() { .subscribe(new SingleOnSubscribe<String>() {

6
app/src/main/java/acr/browser/lightning/app/AppComponent.java

@ -8,6 +8,8 @@ import acr.browser.lightning.activity.TabsManager;
import acr.browser.lightning.activity.ThemableBrowserActivity; import acr.browser.lightning.activity.ThemableBrowserActivity;
import acr.browser.lightning.activity.ThemableSettingsActivity; import acr.browser.lightning.activity.ThemableSettingsActivity;
import acr.browser.lightning.browser.BrowserPresenter; 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.constant.StartPage;
import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.download.LightningDownloadListener; import acr.browser.lightning.download.LightningDownloadListener;
@ -62,6 +64,10 @@ public interface AppComponent {
void inject(StartPage startPage); void inject(StartPage startPage);
void inject(HistoryPage historyPage);
void inject(BookmarkPage bookmarkPage);
void inject(BrowserPresenter presenter); void inject(BrowserPresenter presenter);
void inject(TabsManager manager); void inject(TabsManager manager);

93
app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java

@ -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());
}
} }

48
app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

@ -8,6 +8,9 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log; 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.Single;
import com.anthonycr.bonsai.SingleAction; import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleOnSubscribe; import com.anthonycr.bonsai.SingleOnSubscribe;
@ -19,6 +22,8 @@ import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
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.HistoryItem; import acr.browser.lightning.database.HistoryItem;
@ -46,15 +51,21 @@ public class HistoryPage {
private static final String END = "</div></body></html>"; 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 @NonNull
public static Single<String> getHistoryPage() { public Single<String> getHistoryPage() {
return Single.create(new SingleAction<String>() { return Single.create(new SingleAction<String>() {
@Override @Override
public void onSubscribe(@NonNull final SingleSubscriber<String> subscriber) { 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 + mTitle + HEADING_2);
final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + title + HEADING_2);
HistoryModel.lastHundredVisitedHistoryItems() HistoryModel.lastHundredVisitedHistoryItems()
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() { .subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@ -76,7 +87,7 @@ public class HistoryPage {
} }
historyBuilder.append(END); historyBuilder.append(END);
File historyWebPage = new File(BrowserApp.getApplication().getFilesDir(), FILENAME); File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
FileWriter historyWriter = null; FileWriter historyWriter = null;
try { try {
//noinspection IOResourceOpenedButNotSafelyClosed //noinspection IOResourceOpenedButNotSafelyClosed
@ -97,17 +108,26 @@ public class HistoryPage {
} }
/** /**
* Use this method to immediately delete the history * Use this observable to immediately delete the history
* page on the current thread. This will clear the * page. This will clear the cached history page that was
* cached history page that was stored on file. * 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) { @NonNull
File historyWebPage = new File(application.getFilesDir(), FILENAME); public Completable deleteHistoryPage() {
if (historyWebPage.exists()) { return Completable.create(new CompletableAction() {
historyWebPage.delete(); @Override
} public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
if (historyWebPage.exists()) {
historyWebPage.delete();
}
subscriber.onComplete();
}
});
} }
} }

244
app/src/main/java/acr/browser/lightning/constant/StartPage.java

@ -4,14 +4,15 @@
package acr.browser.lightning.constant; package acr.browser.lightning.constant;
import android.app.Application; import android.app.Application;
import android.os.AsyncTask;
import android.support.annotation.NonNull; 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.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.WeakReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -19,9 +20,8 @@ import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils; 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"; 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>"; 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 String mTitle;
@NonNull private final Application mApp;
@NonNull private final WeakReference<LightningView> mTabReference;
@Inject Application mApp;
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
private String mStartpageUrl; public StartPage() {
public StartPage(LightningView tab, @NonNull Application app) {
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
mTitle = app.getString(R.string.home); mTitle = mApp.getString(R.string.home);
mApp = app;
mTabReference = new WeakReference<>(tab);
}
@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 @NonNull
private String getHomepage() { public Single<String> getHomepage() {
StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2); return Single.create(new SingleAction<String>() {
String icon; @Override
String searchUrl; public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
switch (mPreferenceManager.getSearchChoice()) {
case 0: StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2);
// CUSTOM SEARCH String icon;
icon = "file:///android_asset/lightning.png"; String searchUrl;
searchUrl = mPreferenceManager.getSearchUrl(); switch (mPreferenceManager.getSearchChoice()) {
break; case 0:
case 1: // CUSTOM SEARCH
// GOOGLE_SEARCH; icon = "file:///android_asset/lightning.png";
icon = "file:///android_asset/google.png"; searchUrl = mPreferenceManager.getSearchUrl();
// "https://www.google.com/images/srpr/logo11w.png"; break;
searchUrl = Constants.GOOGLE_SEARCH; case 1:
break; // GOOGLE_SEARCH;
case 2: icon = "file:///android_asset/google.png";
// ANDROID SEARCH; // "https://www.google.com/images/srpr/logo11w.png";
icon = "file:///android_asset/ask.png"; searchUrl = Constants.GOOGLE_SEARCH;
searchUrl = Constants.ASK_SEARCH; break;
break; case 2:
case 3: // ANDROID SEARCH;
// BING_SEARCH; icon = "file:///android_asset/ask.png";
icon = "file:///android_asset/bing.png"; searchUrl = Constants.ASK_SEARCH;
// "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png"; break;
searchUrl = Constants.BING_SEARCH; case 3:
break; // BING_SEARCH;
case 4: icon = "file:///android_asset/bing.png";
// YAHOO_SEARCH; // "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png";
icon = "file:///android_asset/yahoo.png"; searchUrl = Constants.BING_SEARCH;
// "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png"; break;
searchUrl = Constants.YAHOO_SEARCH; case 4:
break; // YAHOO_SEARCH;
case 5: icon = "file:///android_asset/yahoo.png";
// STARTPAGE_SEARCH; // "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png";
icon = "file:///android_asset/startpage.png"; searchUrl = Constants.YAHOO_SEARCH;
// "https://com/graphics/startp_logo.gif"; break;
searchUrl = Constants.STARTPAGE_SEARCH; case 5:
break; // STARTPAGE_SEARCH;
case 6: icon = "file:///android_asset/startpage.png";
// STARTPAGE_MOBILE // "https://com/graphics/startp_logo.gif";
icon = "file:///android_asset/startpage.png"; searchUrl = Constants.STARTPAGE_SEARCH;
// "https://com/graphics/startp_logo.gif"; break;
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH; case 6:
break; // STARTPAGE_MOBILE
case 7: icon = "file:///android_asset/startpage.png";
// DUCK_SEARCH; // "https://com/graphics/startp_logo.gif";
icon = "file:///android_asset/duckduckgo.png"; searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png"; break;
searchUrl = Constants.DUCK_SEARCH; case 7:
break; // DUCK_SEARCH;
case 8: icon = "file:///android_asset/duckduckgo.png";
// DUCK_LITE_SEARCH; // "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
icon = "file:///android_asset/duckduckgo.png"; searchUrl = Constants.DUCK_SEARCH;
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png"; break;
searchUrl = Constants.DUCK_LITE_SEARCH; case 8:
break; // DUCK_LITE_SEARCH;
case 9: icon = "file:///android_asset/duckduckgo.png";
// BAIDU_SEARCH; // "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
icon = "file:///android_asset/baidu.png"; searchUrl = Constants.DUCK_LITE_SEARCH;
// "http://www.baidu.com/img/bdlogo.gif"; break;
searchUrl = Constants.BAIDU_SEARCH; case 9:
break; // BAIDU_SEARCH;
case 10: icon = "file:///android_asset/baidu.png";
// YANDEX_SEARCH; // "http://www.baidu.com/img/bdlogo.gif";
icon = "file:///android_asset/yandex.png"; searchUrl = Constants.BAIDU_SEARCH;
// "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png"; break;
searchUrl = Constants.YANDEX_SEARCH; case 10:
break; // YANDEX_SEARCH;
default: icon = "file:///android_asset/yandex.png";
// DEFAULT GOOGLE_SEARCH; // "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png";
icon = "file:///android_asset/google.png"; searchUrl = Constants.YANDEX_SEARCH;
searchUrl = Constants.GOOGLE_SEARCH; break;
break; default:
// DEFAULT GOOGLE_SEARCH;
} icon = "file:///android_asset/google.png";
searchUrl = Constants.GOOGLE_SEARCH;
homepageBuilder.append(icon); break;
homepageBuilder.append(MIDDLE);
homepageBuilder.append(searchUrl); }
homepageBuilder.append(END);
homepageBuilder.append(icon);
File homepage = new File(mApp.getFilesDir(), FILENAME); homepageBuilder.append(MIDDLE);
FileWriter hWriter = null; homepageBuilder.append(searchUrl);
try { homepageBuilder.append(END);
//noinspection IOResourceOpenedButNotSafelyClosed
hWriter = new FileWriter(homepage, false); File homepage = new File(mApp.getFilesDir(), FILENAME);
hWriter.write(homepageBuilder.toString()); FileWriter hWriter = null;
} catch (IOException e) { try {
e.printStackTrace(); //noinspection IOResourceOpenedButNotSafelyClosed
} finally { hWriter = new FileWriter(homepage, false);
Utils.close(hWriter); hWriter.write(homepageBuilder.toString());
} } catch (IOException e) {
e.printStackTrace();
return Constants.FILE + homepage; } finally {
} Utils.close(hWriter);
}
public void load() {
executeOnExecutor(BrowserApp.getIOThread()); subscriber.onItem(Constants.FILE + homepage);
}
});
} }
} }

47
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -57,6 +57,7 @@ import acr.browser.lightning.preference.PreferenceManager;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
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.UrlUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
@ -81,16 +82,16 @@ public class LightningView {
private static String sDefaultUserAgent; private static String sDefaultUserAgent;
private static float sMaxFling; private static float sMaxFling;
private static final float[] sNegativeColorArray = { private static final float[] sNegativeColorArray = {
-1.0f, 0, 0, 0, 255, // red -1.0f, 0, 0, 0, 255, // red
0, -1.0f, 0, 0, 255, // green 0, -1.0f, 0, 0, 255, // green
0, 0, -1.0f, 0, 255, // blue 0, 0, -1.0f, 0, 255, // blue
0, 0, 0, 1.0f, 0 // alpha 0, 0, 0, 1.0f, 0 // alpha
}; };
private static final float[] sIncreaseContrastColorArray = { private static final float[] sIncreaseContrastColorArray = {
2.0f, 0, 0, 0, -160.f, // red 2.0f, 0, 0, 0, -160.f, // red
0, 2.0f, 0, 0, -160.f, // green 0, 2.0f, 0, 0, -160.f, // green
0, 0, 2.0f, 0, -160.f, // blue 0, 0, 2.0f, 0, -160.f, // blue
0, 0, 0, 1.0f, 0 // alpha 0, 0, 0, 1.0f, 0 // alpha
}; };
@NonNull private final LightningViewTitle mTitle; @NonNull private final LightningViewTitle mTitle;
@ -213,7 +214,16 @@ public class LightningView {
* UI thread. * UI thread.
*/ */
private void loadStartpage() { 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. * UI thread. It also caches the default folder icon locally.
*/ */
public void loadBookmarkpage() { public void loadBookmarkpage() {
if (mWebView == null) new BookmarkPage(mActivity).getBookmarkPage()
return; .subscribeOn(Schedulers.io())
new BookmarkPage(this, mActivity, mBookmarkManager).load(); .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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,
!mPreferences.getBlockThirdPartyCookiesEnabled()); !mPreferences.getBlockThirdPartyCookiesEnabled());
} }
} }
@ -695,7 +712,7 @@ public class LightningView {
break; break;
case 1: case 1:
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter( ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(
sNegativeColorArray); sNegativeColorArray);
mPaint.setColorFilter(filterInvert); mPaint.setColorFilter(filterInvert);
setHardwareRendering(); setHardwareRendering();
@ -724,7 +741,7 @@ public class LightningView {
case 4: case 4:
ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter( ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter(
sIncreaseContrastColorArray); sIncreaseContrastColorArray);
mPaint.setColorFilter(IncreaseHighContrast); mPaint.setColorFilter(IncreaseHighContrast);
setHardwareRendering(); setHardwareRendering();
break; break;

Loading…
Cancel
Save