Add missing annotations, clean up reactive code, simplify methods
This commit is contained in:
parent
c4921bbf20
commit
de4fdc86e0
@ -359,8 +359,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
|
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
mTabsManager.restoreTabsAndHandleIntent(this, getIntent(), isIncognito())
|
mTabsManager.initializeTabs(this, getIntent(), isIncognito())
|
||||||
.subscribe(new Subscription<Void>() {
|
.subscribe(new Subscription<Void>() {
|
||||||
|
@Override
|
||||||
|
public void onNext(Void item) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
// At this point we always have at least a tab in the tab manager
|
// At this point we always have at least a tab in the tab manager
|
||||||
@ -368,11 +371,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
mProxyUtils.checkForProxy(BrowserActivity.this);
|
mProxyUtils.checkForProxy(BrowserActivity.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(Void item) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +61,12 @@ public class TabsManager {
|
|||||||
* @param intent the intent that started the browser activity.
|
* @param intent the intent that started the browser activity.
|
||||||
* @param incognito whether or not we are in incognito mode.
|
* @param incognito whether or not we are in incognito mode.
|
||||||
*/
|
*/
|
||||||
public synchronized Observable<Void> restoreTabsAndHandleIntent(@NonNull final Activity activity,
|
public synchronized Observable<Void> initializeTabs(@NonNull final Activity activity,
|
||||||
@Nullable final Intent intent,
|
@Nullable final Intent intent,
|
||||||
final boolean incognito) {
|
final boolean incognito) {
|
||||||
return Observable.create(new Action<Void>() {
|
return Observable.create(new Action<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(final Subscriber<Void> subscriber) {
|
public void onSubscribe(@NonNull final Subscriber<Void> subscriber) {
|
||||||
|
|
||||||
|
|
||||||
// If incognito, only create one tab, do not handle intent
|
// If incognito, only create one tab, do not handle intent
|
||||||
@ -85,43 +85,7 @@ public class TabsManager {
|
|||||||
mTabList.clear();
|
mTabList.clear();
|
||||||
mCurrentTab = null;
|
mCurrentTab = null;
|
||||||
if (mPreferenceManager.getRestoreLostTabsEnabled()) {
|
if (mPreferenceManager.getRestoreLostTabsEnabled()) {
|
||||||
restoreState()
|
restoreLostTabs(url, activity, subscriber);
|
||||||
.subscribeOn(Schedulers.worker())
|
|
||||||
.observeOn(Schedulers.main())
|
|
||||||
.subscribe(new Subscription<Bundle>() {
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
if (url != null) {
|
|
||||||
if (url.startsWith(Constants.FILE)) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
||||||
builder.setCancelable(true)
|
|
||||||
.setTitle(R.string.title_warning)
|
|
||||||
.setMessage(R.string.message_blocked_local)
|
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
|
||||||
.setPositiveButton(R.string.action_open, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
newTab(activity, url, false);
|
|
||||||
}
|
|
||||||
}).show();
|
|
||||||
} else {
|
|
||||||
newTab(activity, url, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mTabList.size() == 0) {
|
|
||||||
newTab(activity, null, false);
|
|
||||||
}
|
|
||||||
subscriber.onComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(Bundle item) {
|
|
||||||
LightningView tab = newTab(activity, "", false);
|
|
||||||
if (tab.getWebView() != null) {
|
|
||||||
tab.getWebView().restoreState(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -129,6 +93,45 @@ public class TabsManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void restoreLostTabs(final String url, final Activity activity,
|
||||||
|
final Subscriber subscriber) {
|
||||||
|
restoreState().subscribeOn(Schedulers.worker())
|
||||||
|
.observeOn(Schedulers.main()).subscribe(new Subscription<Bundle>() {
|
||||||
|
@Override
|
||||||
|
public void onNext(Bundle item) {
|
||||||
|
LightningView tab = newTab(activity, "", false);
|
||||||
|
if (tab.getWebView() != null) {
|
||||||
|
tab.getWebView().restoreState(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
if (url != null) {
|
||||||
|
if (url.startsWith(Constants.FILE)) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
|
builder.setCancelable(true)
|
||||||
|
.setTitle(R.string.title_warning)
|
||||||
|
.setMessage(R.string.message_blocked_local)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.setPositiveButton(R.string.action_open, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
newTab(activity, url, false);
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
|
} else {
|
||||||
|
newTab(activity, url, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mTabList.size() == 0) {
|
||||||
|
newTab(activity, null, false);
|
||||||
|
}
|
||||||
|
subscriber.onComplete();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the tab at the given position in tabs list, or
|
* Return the tab at the given position in tabs list, or
|
||||||
* null if position is not in tabs list range.
|
* null if position is not in tabs list range.
|
||||||
@ -319,7 +322,7 @@ public class TabsManager {
|
|||||||
private Observable<Bundle> restoreState() {
|
private Observable<Bundle> restoreState() {
|
||||||
return Observable.create(new Action<Bundle>() {
|
return Observable.create(new Action<Bundle>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Subscriber<Bundle> subscriber) {
|
public void onSubscribe(@NonNull Subscriber<Bundle> subscriber) {
|
||||||
Bundle savedState = FileUtils.readBundleFromStorage(mApp, BUNDLE_STORAGE);
|
Bundle savedState = FileUtils.readBundleFromStorage(mApp, BUNDLE_STORAGE);
|
||||||
if (savedState != null) {
|
if (savedState != null) {
|
||||||
Log.d(Constants.TAG, "Restoring previous WebView state now");
|
Log.d(Constants.TAG, "Restoring previous WebView state now");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package acr.browser.lightning.react;
|
package acr.browser.lightning.react;
|
||||||
|
|
||||||
public interface Subscriber<T> {
|
public interface Subscriber<T> {
|
||||||
void onComplete();
|
|
||||||
|
|
||||||
void onNext(T item);
|
void onNext(T item);
|
||||||
|
|
||||||
|
void onComplete();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package acr.browser.lightning.react;
|
package acr.browser.lightning.react;
|
||||||
|
|
||||||
public interface Subscription<T> {
|
public interface Subscription<T> {
|
||||||
void onComplete();
|
|
||||||
|
|
||||||
void onNext(T item);
|
void onNext(T item);
|
||||||
|
|
||||||
|
void onComplete();
|
||||||
}
|
}
|
||||||
|
@ -376,33 +376,30 @@ public class LightningView {
|
|||||||
getPathObservable("appcache")
|
getPathObservable("appcache")
|
||||||
.subscribeOn(Schedulers.worker())
|
.subscribeOn(Schedulers.worker())
|
||||||
.subscribe(new Subscription<File>() {
|
.subscribe(new Subscription<File>() {
|
||||||
@Override
|
|
||||||
public void onComplete() {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(File item) {
|
public void onNext(File item) {
|
||||||
settings.setAppCachePath(item.getPath());
|
settings.setAppCachePath(item.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {}
|
||||||
});
|
});
|
||||||
|
|
||||||
getPathObservable("geolocation")
|
getPathObservable("geolocation")
|
||||||
.subscribeOn(Schedulers.worker())
|
.subscribeOn(Schedulers.worker())
|
||||||
.subscribe(new Subscription<File>() {
|
.subscribe(new Subscription<File>() {
|
||||||
@Override
|
|
||||||
public void onComplete() {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(File item) {
|
public void onNext(File item) {
|
||||||
settings.setGeolocationDatabasePath(item.getPath());
|
settings.setGeolocationDatabasePath(item.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {}
|
||||||
});
|
});
|
||||||
|
|
||||||
getPathObservable("databases")
|
getPathObservable("databases")
|
||||||
.subscribeOn(Schedulers.worker())
|
.subscribeOn(Schedulers.worker())
|
||||||
.subscribe(new Subscription<File>() {
|
.subscribe(new Subscription<File>() {
|
||||||
@Override
|
|
||||||
public void onComplete() {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(File item) {
|
public void onNext(File item) {
|
||||||
if (API < Build.VERSION_CODES.KITKAT) {
|
if (API < Build.VERSION_CODES.KITKAT) {
|
||||||
@ -410,6 +407,9 @@ public class LightningView {
|
|||||||
settings.setDatabasePath(item.getPath());
|
settings.setDatabasePath(item.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user