Browse Source

Bookmark page generation moved to LightningView to avoid call loop between BrowserActivity and LightningView through BrowserController

master
Stefano Pacifici 9 years ago
parent
commit
2563e81f7a
  1. 29
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 2
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  3. 5
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  4. 2
      app/src/main/java/acr/browser/lightning/controller/BrowserController.java
  5. 15
      app/src/main/java/acr/browser/lightning/utils/IntentUtils.java
  6. 37
      app/src/main/java/acr/browser/lightning/view/LightningView.java

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

@ -1471,31 +1471,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1471,31 +1471,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
return super.onCreateOptionsMenu(menu);
}
/**
* open the HTML bookmarks page, parameter view is the WebView that should show the page
*/
@Override
public void openBookmarkPage(WebView view) {
if (view == null)
return;
Bitmap folderIcon = ThemeUtils.getThemedBitmap(this, R.drawable.ic_folder, false);
FileOutputStream outputStream = null;
File image = new File(mActivity.getCacheDir(), "folder.png");
try {
outputStream = new FileOutputStream(image);
folderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
folderIcon.recycle();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
Utils.close(outputStream);
}
File bookmarkWebPage = new File(mActivity.getFilesDir(), Constants.BOOKMARKS_FILENAME);
bookmarkPage.buildBookmarkPage(null, bookmarkManager.getBookmarksFromFolder(null, true));
view.loadUrl(Constants.FILE + bookmarkWebPage);
}
@Override
public void updateTabs() {
eventBus.post(new BrowserEvents.TabsChanged());
@ -2232,7 +2207,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -2232,7 +2207,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final WebView currentWebView = currentTab.getWebView();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) {
openBookmarkPage(currentWebView);
currentTab.loadBookmarkpage();
}
if (currentTab != null) {
eventBus.post(new BrowserEvents.CurrentPageUrl(currentTab.getUrl()));
@ -2250,7 +2225,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -2250,7 +2225,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final WebView currentWebView = currentTab.getWebView();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) {
openBookmarkPage(currentWebView);
currentTab.loadBookmarkpage();
}
if (currentTab != null) {
eventBus.post(new BrowserEvents.CurrentPageUrl(currentTab.getUrl()));

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

@ -37,4 +37,6 @@ public interface AppComponent { @@ -37,4 +37,6 @@ public interface AppComponent {
PreferenceManager getPreferenceManager();
void inject(LightningPreferenceFragment fragment);
BookmarkPage getBookmarkPage();
}

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

@ -62,7 +62,8 @@ public final class BookmarkPage { @@ -62,7 +62,8 @@ public final class BookmarkPage {
CACHE_DIR = context.getCacheDir();
}
public void buildBookmarkPage(final String folder, final List<HistoryItem> list) {
public void buildBookmarkPage(final String folder) {
final List<HistoryItem> list = manager.getBookmarksFromFolder(folder, true);
final File bookmarkWebPage;
if (folder == null || folder.isEmpty()) {
bookmarkWebPage = new File(FILES_DIR, Constants.BOOKMARKS_FILENAME);
@ -83,7 +84,7 @@ public final class BookmarkPage { @@ -83,7 +84,7 @@ public final class BookmarkPage {
new Thread(new Runnable() {
@Override
public void run() {
buildBookmarkPage(item.getTitle(), manager.getBookmarksFromFolder(item.getTitle(), true));
buildBookmarkPage(item.getTitle());
}
}).run();
} else {

2
app/src/main/java/acr/browser/lightning/controller/BrowserController.java

@ -48,8 +48,6 @@ public interface BrowserController { @@ -48,8 +48,6 @@ public interface BrowserController {
void longClickPage(String url);
void openBookmarkPage(WebView view);
void showFileChooser(ValueCallback<Uri[]> filePathCallback);
void closeEmptyTab();

15
app/src/main/java/acr/browser/lightning/utils/IntentUtils.java

@ -2,6 +2,7 @@ package acr.browser.lightning.utils; @@ -2,6 +2,7 @@ package acr.browser.lightning.utils;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
@ -19,7 +20,7 @@ import acr.browser.lightning.controller.BrowserController; @@ -19,7 +20,7 @@ import acr.browser.lightning.controller.BrowserController;
public class IntentUtils {
private final Activity mActivity;
private final Context mActivity;
private static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
+ // switch on case insensitive matching
@ -28,8 +29,8 @@ public class IntentUtils { @@ -28,8 +29,8 @@ public class IntentUtils {
"(?:http|https|file):\\/\\/" + "|(?:inline|data|about|javascript):" + "|(?:.*:.*@)"
+ ')' + "(.*)");
public IntentUtils(BrowserController controller) {
mActivity = controller.getActivity();
public IntentUtils(Context context) {
mActivity = context.getApplicationContext();
}
public boolean startActivityForUrl(WebView tab, String url) {
@ -64,9 +65,11 @@ public class IntentUtils { @@ -64,9 +65,11 @@ public class IntentUtils {
return false;
}
try {
if (mActivity.startActivityIfNeeded(intent, -1)) {
return true;
}
// TODO Restore this
// if (mActivity.startActivityIfNeeded(intent, -1)) {
// return true;
// }
mActivity.startActivity(intent);
} catch (ActivityNotFoundException ex) {
ex.printStackTrace();
}

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

@ -51,6 +51,7 @@ import android.widget.LinearLayout; @@ -51,6 +51,7 @@ import android.widget.LinearLayout;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
@ -75,14 +76,13 @@ public class LightningView { @@ -75,14 +76,13 @@ public class LightningView {
private final Title mTitle;
private WebView mWebView;
private final boolean mIsIncognitoTab;
private final BrowserController mBrowserController;
private final BrowserController mBrowserController = null; // TODO REMOVE
private final GestureDetector mGestureDetector;
private final Activity mActivity;
private static String mHomepage;
private static String mDefaultUserAgent;
// TODO fix so that mWebpageBitmap can be static - static changes the icon when switching from light to dark and then back to light
private final Bitmap mWebpageBitmap;
@Inject
PreferenceManager mPreferences;
private final AdBlock mAdBlock;
private final IntentUtils mIntentUtils;
@ -104,7 +104,7 @@ public class LightningView { @@ -104,7 +104,7 @@ public class LightningView {
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
@SuppressLint("NewApi")
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito, BrowserController controller) {
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito) {
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mActivity = activity;
mWebView = new WebView(activity);
@ -117,9 +117,7 @@ public class LightningView { @@ -117,9 +117,7 @@ public class LightningView {
mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();
mBrowserController = controller;
mIntentUtils = new IntentUtils(mBrowserController);
mIntentUtils = new IntentUtils(activity);
mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
mWebView.setFocusableInTouchMode(true);
mWebView.setFocusable(true);
@ -161,12 +159,37 @@ public class LightningView { @@ -161,12 +159,37 @@ public class LightningView {
if (mHomepage.startsWith("about:home")) {
mWebView.loadUrl(StartPage.getHomepage(mActivity));
} else if (mHomepage.startsWith("about:bookmarks")) {
mBrowserController.openBookmarkPage(mWebView);
loadBookmarkpage();
} else {
mWebView.loadUrl(mHomepage);
}
}
/**
* Load the HTML bookmarks page in this view
*/
public void loadBookmarkpage() {
if (mWebView == null)
return;
Bitmap folderIcon = ThemeUtils.getThemedBitmap(mActivity, R.drawable.ic_folder, false);
FileOutputStream outputStream = null;
File image = new File(mActivity.getCacheDir(), "folder.png");
try {
outputStream = new FileOutputStream(image);
folderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
folderIcon.recycle();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
Utils.close(outputStream);
}
File bookmarkWebPage = new File(mActivity.getFilesDir(), Constants.BOOKMARKS_FILENAME);
BrowserApp.getAppComponent().getBookmarkPage().buildBookmarkPage(null);
mWebView.loadUrl(Constants.FILE + bookmarkWebPage);
}
/**
* Initialize the preference driven settings of the WebView
*

Loading…
Cancel
Save