Fixed bugs related restore tabs option
- fixed tab being blank if option was off - fixed bug where bookmarks would show sub folder if browser was closed in that folder if option was on
This commit is contained in:
parent
d7faeaa2fc
commit
dbc186db9b
@ -21,7 +21,12 @@ 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.constant.BookmarkPage;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
|
import acr.browser.lightning.constant.HistoryPage;
|
||||||
|
import acr.browser.lightning.constant.StartPage;
|
||||||
|
import acr.browser.lightning.database.BookmarkManager;
|
||||||
|
import acr.browser.lightning.database.HistoryDatabase;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.react.Action;
|
import acr.browser.lightning.react.Action;
|
||||||
import acr.browser.lightning.react.Observable;
|
import acr.browser.lightning.react.Observable;
|
||||||
@ -29,6 +34,7 @@ import acr.browser.lightning.react.OnSubscribe;
|
|||||||
import acr.browser.lightning.react.Schedulers;
|
import acr.browser.lightning.react.Schedulers;
|
||||||
import acr.browser.lightning.react.Subscriber;
|
import acr.browser.lightning.react.Subscriber;
|
||||||
import acr.browser.lightning.utils.FileUtils;
|
import acr.browser.lightning.utils.FileUtils;
|
||||||
|
import acr.browser.lightning.utils.UrlUtils;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,6 +46,7 @@ public class TabsManager {
|
|||||||
|
|
||||||
private static final String TAG = TabsManager.class.getSimpleName();
|
private static final String TAG = TabsManager.class.getSimpleName();
|
||||||
private static final String BUNDLE_KEY = "WEBVIEW_";
|
private static final String BUNDLE_KEY = "WEBVIEW_";
|
||||||
|
private static final String URL_KEY = "URL_KEY";
|
||||||
private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel";
|
private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel";
|
||||||
|
|
||||||
private final List<LightningView> mTabList = new ArrayList<>(1);
|
private final List<LightningView> mTabList = new ArrayList<>(1);
|
||||||
@ -50,6 +57,8 @@ public class TabsManager {
|
|||||||
private List<Runnable> mPostInitializationWorkList = new ArrayList<>();
|
private List<Runnable> mPostInitializationWorkList = new ArrayList<>();
|
||||||
|
|
||||||
@Inject PreferenceManager mPreferenceManager;
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
|
@Inject BookmarkManager mBookmarkManager;
|
||||||
|
@Inject HistoryDatabase mHistoryManager;
|
||||||
@Inject Bus mEventBus;
|
@Inject Bus mEventBus;
|
||||||
@Inject Application mApp;
|
@Inject Application mApp;
|
||||||
|
|
||||||
@ -123,6 +132,7 @@ public class TabsManager {
|
|||||||
} else {
|
} else {
|
||||||
newTab(activity, null, false);
|
newTab(activity, null, false);
|
||||||
finishInitialization();
|
finishInitialization();
|
||||||
|
subscriber.onComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -132,12 +142,22 @@ public class TabsManager {
|
|||||||
|
|
||||||
private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity,
|
private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity,
|
||||||
@NonNull final Subscriber subscriber) {
|
@NonNull final Subscriber subscriber) {
|
||||||
|
|
||||||
restoreState().subscribeOn(Schedulers.worker())
|
restoreState().subscribeOn(Schedulers.worker())
|
||||||
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<Bundle>() {
|
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<Bundle>() {
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Bundle item) {
|
public void onNext(Bundle item) {
|
||||||
LightningView tab = newTab(activity, "", false);
|
LightningView tab = newTab(activity, "", false);
|
||||||
if (tab.getWebView() != null) {
|
String url = item.getString(URL_KEY);
|
||||||
|
if (url != null && tab.getWebView() != null) {
|
||||||
|
if (UrlUtils.isBookmarkUrl(url)) {
|
||||||
|
new BookmarkPage(tab, activity, mBookmarkManager).load();
|
||||||
|
} else if (UrlUtils.isStartPageUrl(url)) {
|
||||||
|
new StartPage(tab, mApp).load();
|
||||||
|
} else if (UrlUtils.isHistoryUrl(url)) {
|
||||||
|
new HistoryPage(tab, mApp, mHistoryManager).load();
|
||||||
|
}
|
||||||
|
} else if (tab.getWebView() != null) {
|
||||||
tab.getWebView().restoreState(item);
|
tab.getWebView().restoreState(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,9 +377,12 @@ public class TabsManager {
|
|||||||
for (int n = 0; n < mTabList.size(); n++) {
|
for (int n = 0; n < mTabList.size(); n++) {
|
||||||
LightningView tab = mTabList.get(n);
|
LightningView tab = mTabList.get(n);
|
||||||
Bundle state = new Bundle(ClassLoader.getSystemClassLoader());
|
Bundle state = new Bundle(ClassLoader.getSystemClassLoader());
|
||||||
if (tab.getWebView() != null) {
|
if (tab.getWebView() != null && !UrlUtils.isSpecialUrl(tab.getUrl())) {
|
||||||
tab.getWebView().saveState(state);
|
tab.getWebView().saveState(state);
|
||||||
outState.putBundle(BUNDLE_KEY + n, state);
|
outState.putBundle(BUNDLE_KEY + n, state);
|
||||||
|
} else if (tab.getWebView() != null) {
|
||||||
|
state.putString(URL_KEY, tab.getUrl());
|
||||||
|
outState.putBundle(BUNDLE_KEY + n, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileUtils.writeBundleToStorage(mApp, outState, BUNDLE_STORAGE);
|
FileUtils.writeBundleToStorage(mApp, outState, BUNDLE_STORAGE);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package acr.browser.lightning.constant;
|
package acr.browser.lightning.constant;
|
||||||
|
|
||||||
|
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.os.AsyncTask;
|
||||||
@ -21,6 +22,7 @@ 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.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
|
|
||||||
@ -69,9 +71,10 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
|
|||||||
private final Bitmap mFolderIcon;
|
private final Bitmap mFolderIcon;
|
||||||
@NonNull private final String mTitle;
|
@NonNull private final String mTitle;
|
||||||
|
|
||||||
public BookmarkPage(LightningView tab, @NonNull Application app, BookmarkManager manager, Bitmap folderIcon) {
|
public BookmarkPage(LightningView tab, @NonNull Activity activity, BookmarkManager manager) {
|
||||||
mApp = app;
|
mApp = BrowserApp.get(activity);
|
||||||
mTitle = app.getString(R.string.action_bookmarks);
|
final Bitmap folderIcon = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, false);
|
||||||
|
mTitle = mApp.getString(R.string.action_bookmarks);
|
||||||
mManager = manager;
|
mManager = manager;
|
||||||
mTabReference = new WeakReference<>(tab);
|
mTabReference = new WeakReference<>(tab);
|
||||||
mFolderIcon = folderIcon;
|
mFolderIcon = folderIcon;
|
||||||
|
@ -166,4 +166,34 @@ public class UrlUtils {
|
|||||||
url.endsWith(HistoryPage.FILENAME) ||
|
url.endsWith(HistoryPage.FILENAME) ||
|
||||||
url.endsWith(StartPage.FILENAME));
|
url.endsWith(StartPage.FILENAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the url is a url for the bookmark page.
|
||||||
|
*
|
||||||
|
* @param url the url to check, may be null.
|
||||||
|
* @return true if the url is a bookmark url, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isBookmarkUrl(@Nullable String url) {
|
||||||
|
return url != null && url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the url is a url for the history page.
|
||||||
|
*
|
||||||
|
* @param url the url to check, may be null.
|
||||||
|
* @return true if the url is a history url, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isHistoryUrl(@Nullable String url) {
|
||||||
|
return url != null && url.startsWith(Constants.FILE) && url.endsWith(HistoryPage.FILENAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the url is a url for the start page.
|
||||||
|
*
|
||||||
|
* @param url the url to check, may be null.
|
||||||
|
* @return true if the url is a start page url, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isStartPageUrl(@Nullable String url) {
|
||||||
|
return url != null && url.startsWith(Constants.FILE) && url.endsWith(StartPage.FILENAME);
|
||||||
|
}
|
||||||
}
|
}
|
@ -196,8 +196,7 @@ public class LightningView {
|
|||||||
public void loadBookmarkpage() {
|
public void loadBookmarkpage() {
|
||||||
if (mWebView == null)
|
if (mWebView == null)
|
||||||
return;
|
return;
|
||||||
Bitmap folderIcon = ThemeUtils.getThemedBitmap(mActivity, R.drawable.ic_folder, false);
|
new BookmarkPage(this, mActivity, mBookmarkManager).load();
|
||||||
new BookmarkPage(this, BrowserApp.get(mActivity), mBookmarkManager, folderIcon).load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user