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
return super.onCreateOptionsMenu(menu); 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 @Override
public void updateTabs() { public void updateTabs() {
eventBus.post(new BrowserEvents.TabsChanged()); eventBus.post(new BrowserEvents.TabsChanged());
@ -2232,7 +2207,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final WebView currentWebView = currentTab.getWebView(); final WebView currentWebView = currentTab.getWebView();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE) if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) { && currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) {
openBookmarkPage(currentWebView); currentTab.loadBookmarkpage();
} }
if (currentTab != null) { if (currentTab != null) {
eventBus.post(new BrowserEvents.CurrentPageUrl(currentTab.getUrl())); eventBus.post(new BrowserEvents.CurrentPageUrl(currentTab.getUrl()));
@ -2250,7 +2225,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final WebView currentWebView = currentTab.getWebView(); final WebView currentWebView = currentTab.getWebView();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE) if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) { && currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) {
openBookmarkPage(currentWebView); currentTab.loadBookmarkpage();
} }
if (currentTab != null) { if (currentTab != null) {
eventBus.post(new BrowserEvents.CurrentPageUrl(currentTab.getUrl())); 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 {
PreferenceManager getPreferenceManager(); PreferenceManager getPreferenceManager();
void inject(LightningPreferenceFragment fragment); 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 {
CACHE_DIR = context.getCacheDir(); 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; final File bookmarkWebPage;
if (folder == null || folder.isEmpty()) { if (folder == null || folder.isEmpty()) {
bookmarkWebPage = new File(FILES_DIR, Constants.BOOKMARKS_FILENAME); bookmarkWebPage = new File(FILES_DIR, Constants.BOOKMARKS_FILENAME);
@ -83,7 +84,7 @@ public final class BookmarkPage {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
buildBookmarkPage(item.getTitle(), manager.getBookmarksFromFolder(item.getTitle(), true)); buildBookmarkPage(item.getTitle());
} }
}).run(); }).run();
} else { } else {

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

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

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

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

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

@ -51,6 +51,7 @@ import android.widget.LinearLayout;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -75,14 +76,13 @@ public class LightningView {
private final Title mTitle; private final Title mTitle;
private WebView mWebView; private WebView mWebView;
private final boolean mIsIncognitoTab; private final boolean mIsIncognitoTab;
private final BrowserController mBrowserController; private final BrowserController mBrowserController = null; // TODO REMOVE
private final GestureDetector mGestureDetector; private final GestureDetector mGestureDetector;
private final Activity mActivity; private final Activity mActivity;
private static String mHomepage; private static String mHomepage;
private static String mDefaultUserAgent; 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 // 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; private final Bitmap mWebpageBitmap;
@Inject
PreferenceManager mPreferences; PreferenceManager mPreferences;
private final AdBlock mAdBlock; private final AdBlock mAdBlock;
private final IntentUtils mIntentUtils; private final IntentUtils mIntentUtils;
@ -104,7 +104,7 @@ public class LightningView {
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION}; private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
@SuppressLint("NewApi") @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(); mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mActivity = activity; mActivity = activity;
mWebView = new WebView(activity); mWebView = new WebView(activity);
@ -117,9 +117,7 @@ public class LightningView {
mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity(); mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();
mBrowserController = controller; mIntentUtils = new IntentUtils(activity);
mIntentUtils = new IntentUtils(mBrowserController);
mWebView.setDrawingCacheBackgroundColor(Color.WHITE); mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
mWebView.setFocusableInTouchMode(true); mWebView.setFocusableInTouchMode(true);
mWebView.setFocusable(true); mWebView.setFocusable(true);
@ -161,12 +159,37 @@ public class LightningView {
if (mHomepage.startsWith("about:home")) { if (mHomepage.startsWith("about:home")) {
mWebView.loadUrl(StartPage.getHomepage(mActivity)); mWebView.loadUrl(StartPage.getHomepage(mActivity));
} else if (mHomepage.startsWith("about:bookmarks")) { } else if (mHomepage.startsWith("about:bookmarks")) {
mBrowserController.openBookmarkPage(mWebView); loadBookmarkpage();
} else { } else {
mWebView.loadUrl(mHomepage); 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 * Initialize the preference driven settings of the WebView
* *

Loading…
Cancel
Save