Browse Source

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
master
Anthony Restaino 9 years ago
parent
commit
dbc186db9b
  1. 27
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  2. 9
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  3. 30
      app/src/main/java/acr/browser/lightning/utils/UrlUtils.java
  4. 3
      app/src/main/java/acr/browser/lightning/view/LightningView.java

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

@ -21,7 +21,12 @@ import javax.inject.Inject; @@ -21,7 +21,12 @@ import javax.inject.Inject;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.BookmarkPage;
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.react.Action;
import acr.browser.lightning.react.Observable;
@ -29,6 +34,7 @@ import acr.browser.lightning.react.OnSubscribe; @@ -29,6 +34,7 @@ import acr.browser.lightning.react.OnSubscribe;
import acr.browser.lightning.react.Schedulers;
import acr.browser.lightning.react.Subscriber;
import acr.browser.lightning.utils.FileUtils;
import acr.browser.lightning.utils.UrlUtils;
import acr.browser.lightning.view.LightningView;
/**
@ -40,6 +46,7 @@ public class TabsManager { @@ -40,6 +46,7 @@ public class TabsManager {
private static final String TAG = TabsManager.class.getSimpleName();
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 final List<LightningView> mTabList = new ArrayList<>(1);
@ -50,6 +57,8 @@ public class TabsManager { @@ -50,6 +57,8 @@ public class TabsManager {
private List<Runnable> mPostInitializationWorkList = new ArrayList<>();
@Inject PreferenceManager mPreferenceManager;
@Inject BookmarkManager mBookmarkManager;
@Inject HistoryDatabase mHistoryManager;
@Inject Bus mEventBus;
@Inject Application mApp;
@ -123,6 +132,7 @@ public class TabsManager { @@ -123,6 +132,7 @@ public class TabsManager {
} else {
newTab(activity, null, false);
finishInitialization();
subscriber.onComplete();
}
}
@ -132,12 +142,22 @@ public class TabsManager { @@ -132,12 +142,22 @@ public class TabsManager {
private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity,
@NonNull final Subscriber subscriber) {
restoreState().subscribeOn(Schedulers.worker())
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<Bundle>() {
@Override
public void onNext(Bundle item) {
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);
}
}
@ -357,9 +377,12 @@ public class TabsManager { @@ -357,9 +377,12 @@ public class TabsManager {
for (int n = 0; n < mTabList.size(); n++) {
LightningView tab = mTabList.get(n);
Bundle state = new Bundle(ClassLoader.getSystemClassLoader());
if (tab.getWebView() != null) {
if (tab.getWebView() != null && !UrlUtils.isSpecialUrl(tab.getUrl())) {
tab.getWebView().saveState(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);

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

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
*/
package acr.browser.lightning.constant;
import android.app.Activity;
import android.app.Application;
import android.graphics.Bitmap;
import android.os.AsyncTask;
@ -21,6 +22,7 @@ import acr.browser.lightning.R; @@ -21,6 +22,7 @@ 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;
@ -69,9 +71,10 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> { @@ -69,9 +71,10 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
private final Bitmap mFolderIcon;
@NonNull private final String mTitle;
public BookmarkPage(LightningView tab, @NonNull Application app, BookmarkManager manager, Bitmap folderIcon) {
mApp = app;
mTitle = app.getString(R.string.action_bookmarks);
public BookmarkPage(LightningView tab, @NonNull Activity activity, BookmarkManager manager) {
mApp = BrowserApp.get(activity);
final Bitmap folderIcon = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, false);
mTitle = mApp.getString(R.string.action_bookmarks);
mManager = manager;
mTabReference = new WeakReference<>(tab);
mFolderIcon = folderIcon;

30
app/src/main/java/acr/browser/lightning/utils/UrlUtils.java

@ -166,4 +166,34 @@ public class UrlUtils { @@ -166,4 +166,34 @@ public class UrlUtils {
url.endsWith(HistoryPage.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);
}
}

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

@ -196,8 +196,7 @@ public class LightningView { @@ -196,8 +196,7 @@ public class LightningView {
public void loadBookmarkpage() {
if (mWebView == null)
return;
Bitmap folderIcon = ThemeUtils.getThemedBitmap(mActivity, R.drawable.ic_folder, false);
new BookmarkPage(this, BrowserApp.get(mActivity), mBookmarkManager, folderIcon).load();
new BookmarkPage(this, mActivity, mBookmarkManager).load();
}
/**

Loading…
Cancel
Save