Browse Source

Cleaning up some event bus related code

master
Anthony Restaino 8 years ago
parent
commit
3d0788e650
  1. 13
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 20
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java
  3. 8
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  4. 1
      app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java
  5. 1
      app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java
  6. 98
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  7. 22
      app/src/main/java/acr/browser/lightning/utils/Utils.java

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

@ -2223,14 +2223,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
*/ */
@Subscribe @Subscribe
public void bookmarkChanged(final BookmarkEvents.BookmarkChanged event) { public void bookmarkChanged(final BookmarkEvents.BookmarkChanged event) {
final LightningView currentTab = mTabsManager.getCurrentTab(); handleBookmarksChange();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {
currentTab.loadBookmarkpage();
}
if (currentTab != null) {
mBookmarksView.handleUpdatedUrl(currentTab.getUrl());
}
} }
/** /**
@ -2240,6 +2233,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
*/ */
@Subscribe @Subscribe
public void bookmarkDeleted(final BookmarkEvents.Deleted event) { public void bookmarkDeleted(final BookmarkEvents.Deleted event) {
handleBookmarksChange();
}
private void handleBookmarksChange() {
final LightningView currentTab = mTabsManager.getCurrentTab(); final LightningView currentTab = mTabsManager.getCurrentTab();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE) if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) { && currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {

20
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -82,7 +82,7 @@ public class BookmarkManager {
private class BookmarkInitializer implements Runnable { private class BookmarkInitializer implements Runnable {
private final Context mContext; private final Context mContext;
public BookmarkInitializer(Context context) { BookmarkInitializer(Context context) {
mContext = context; mContext = context;
} }
@ -139,14 +139,14 @@ public class BookmarkManager {
private final List<HistoryItem> mBookmarks; private final List<HistoryItem> mBookmarks;
public BookmarksWriter(List<HistoryItem> bookmarks) { BookmarksWriter(List<HistoryItem> bookmarks) {
mBookmarks = bookmarks; mBookmarks = bookmarks;
} }
@Override @Override
public void run() { public void run() {
final File tempFile = new File(mFilesDir, final File tempFile = new File(mFilesDir,
String.format(Locale.US, "bm_%d.dat", System.currentTimeMillis())); String.format(Locale.US, "bm_%d.dat", System.currentTimeMillis()));
final File bookmarksFile = new File(mFilesDir, FILE_BOOKMARKS); final File bookmarksFile = new File(mFilesDir, FILE_BOOKMARKS);
boolean success = false; boolean success = false;
BufferedWriter bookmarkWriter = null; BufferedWriter bookmarkWriter = null;
@ -326,20 +326,20 @@ public class BookmarkManager {
public synchronized void exportBookmarks(@NonNull Activity activity) { public synchronized void exportBookmarks(@NonNull Activity activity) {
List<HistoryItem> bookmarkList = getAllBookmarks(true); List<HistoryItem> bookmarkList = getAllBookmarks(true);
File bookmarksExport = new File( File bookmarksExport = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"BookmarksExport.txt"); "BookmarksExport.txt");
int counter = 0; int counter = 0;
while (bookmarksExport.exists()) { while (bookmarksExport.exists()) {
counter++; counter++;
bookmarksExport = new File( bookmarksExport = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"BookmarksExport-" + counter + ".txt"); "BookmarksExport-" + counter + ".txt");
} }
BufferedWriter bookmarkWriter = null; BufferedWriter bookmarkWriter = null;
try { try {
//noinspection IOResourceOpenedButNotSafelyClosed //noinspection IOResourceOpenedButNotSafelyClosed
bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksExport, bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksExport,
false)); false));
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
for (HistoryItem item : bookmarkList) { for (HistoryItem item : bookmarkList) {
object.put(TITLE, item.getTitle()); object.put(TITLE, item.getTitle());
@ -350,7 +350,7 @@ public class BookmarkManager {
bookmarkWriter.newLine(); bookmarkWriter.newLine();
} }
Utils.showSnackbar(activity, activity.getString(R.string.bookmark_export_path) Utils.showSnackbar(activity, activity.getString(R.string.bookmark_export_path)
+ ' ' + bookmarksExport.getPath()); + ' ' + bookmarksExport.getPath());
} catch (@NonNull IOException | JSONException e) { } catch (@NonNull IOException | JSONException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
@ -547,7 +547,7 @@ public class BookmarkManager {
} }
if (o1.isFolder() == o2.isFolder()) { if (o1.isFolder() == o2.isFolder()) {
return o1.getTitle().toLowerCase(Locale.getDefault()) return o1.getTitle().toLowerCase(Locale.getDefault())
.compareTo(o2.getTitle().toLowerCase(Locale.getDefault())); .compareTo(o2.getTitle().toLowerCase(Locale.getDefault()));
} else { } else {
return o1.isFolder() ? 1 : -1; return o1.isFolder() ? 1 : -1;

8
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -11,6 +11,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -48,7 +49,6 @@ import acr.browser.lightning.async.AsyncExecutor;
import acr.browser.lightning.async.ImageDownloadTask; import acr.browser.lightning.async.ImageDownloadTask;
import acr.browser.lightning.browser.BookmarksView; import acr.browser.lightning.browser.BookmarksView;
import acr.browser.lightning.bus.BookmarkEvents; import acr.browser.lightning.bus.BookmarkEvents;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.controller.UIController; import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.database.BookmarkManager; import acr.browser.lightning.database.BookmarkManager;
@ -219,12 +219,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
ThemeUtils.getIconLightThemeColor(activity); ThemeUtils.getIconLightThemeColor(activity);
} }
@Subscribe
public void bookmarkChanged(BookmarkEvents.BookmarkChanged event) {
String folder = mBookmarkManager.getCurrentFolder();
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(folder, true), false);
}
private void updateBookmarkIndicator(final String url) { private void updateBookmarkIndicator(final String url) {
if (!mBookmarkManager.isBookmark(url)) { if (!mBookmarkManager.isBookmark(url)) {
mBookmarkImage.setImageResource(R.drawable.ic_action_star); mBookmarkImage.setImageResource(R.drawable.ic_action_star);

1
app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java

@ -24,7 +24,6 @@ import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.SimpleItemAnimator; import android.support.v7.widget.SimpleItemAnimator;
import android.view.View; import android.view.View;
import android.view.animation.AccelerateInterpolator; import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

1
app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java

@ -24,7 +24,6 @@ import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.SimpleItemAnimator; import android.support.v7.widget.SimpleItemAnimator;
import android.view.View; import android.view.View;
import android.view.animation.AccelerateInterpolator; import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

98
app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java

@ -15,55 +15,55 @@ import acr.browser.lightning.download.DownloadHandler;
public class PreferenceManager { public class PreferenceManager {
private static class Name { private static class Name {
public static final String ADOBE_FLASH_SUPPORT = "enableflash"; static final String ADOBE_FLASH_SUPPORT = "enableflash";
public static final String BLOCK_ADS = "AdBlock"; static final String BLOCK_ADS = "AdBlock";
public static final String BLOCK_IMAGES = "blockimages"; static final String BLOCK_IMAGES = "blockimages";
public static final String CLEAR_CACHE_EXIT = "cache"; static final String CLEAR_CACHE_EXIT = "cache";
public static final String COOKIES = "cookies"; static final String COOKIES = "cookies";
public static final String DOWNLOAD_DIRECTORY = "downloadLocation"; static final String DOWNLOAD_DIRECTORY = "downloadLocation";
public static final String FULL_SCREEN = "fullscreen"; static final String FULL_SCREEN = "fullscreen";
public static final String HIDE_STATUS_BAR = "hidestatus"; static final String HIDE_STATUS_BAR = "hidestatus";
public static final String HOMEPAGE = "home"; static final String HOMEPAGE = "home";
public static final String INCOGNITO_COOKIES = "incognitocookies"; static final String INCOGNITO_COOKIES = "incognitocookies";
public static final String JAVASCRIPT = "java"; static final String JAVASCRIPT = "java";
public static final String LOCATION = "location"; static final String LOCATION = "location";
public static final String OVERVIEW_MODE = "overviewmode"; static final String OVERVIEW_MODE = "overviewmode";
public static final String POPUPS = "newwindows"; static final String POPUPS = "newwindows";
public static final String RESTORE_LOST_TABS = "restoreclosed"; static final String RESTORE_LOST_TABS = "restoreclosed";
public static final String SAVE_PASSWORDS = "passwords"; static final String SAVE_PASSWORDS = "passwords";
public static final String SEARCH = "search"; static final String SEARCH = "search";
public static final String SEARCH_URL = "searchurl"; static final String SEARCH_URL = "searchurl";
public static final String TEXT_REFLOW = "textreflow"; static final String TEXT_REFLOW = "textreflow";
public static final String TEXT_SIZE = "textsize"; static final String TEXT_SIZE = "textsize";
public static final String USE_WIDE_VIEWPORT = "wideviewport"; static final String USE_WIDE_VIEWPORT = "wideviewport";
public static final String USER_AGENT = "agentchoose"; static final String USER_AGENT = "agentchoose";
public static final String USER_AGENT_STRING = "userAgentString"; static final String USER_AGENT_STRING = "userAgentString";
public static final String CLEAR_HISTORY_EXIT = "clearHistoryExit"; static final String CLEAR_HISTORY_EXIT = "clearHistoryExit";
public static final String CLEAR_COOKIES_EXIT = "clearCookiesExit"; static final String CLEAR_COOKIES_EXIT = "clearCookiesExit";
public static final String SAVE_URL = "saveUrl"; static final String SAVE_URL = "saveUrl";
public static final String RENDERING_MODE = "renderMode"; static final String RENDERING_MODE = "renderMode";
public static final String BLOCK_THIRD_PARTY = "thirdParty"; static final String BLOCK_THIRD_PARTY = "thirdParty";
public static final String ENABLE_COLOR_MODE = "colorMode"; static final String ENABLE_COLOR_MODE = "colorMode";
public static final String URL_BOX_CONTENTS = "urlContent"; static final String URL_BOX_CONTENTS = "urlContent";
public static final String INVERT_COLORS = "invertColors"; static final String INVERT_COLORS = "invertColors";
public static final String READING_TEXT_SIZE = "readingTextSize"; static final String READING_TEXT_SIZE = "readingTextSize";
public static final String THEME = "Theme"; static final String THEME = "Theme";
public static final String TEXT_ENCODING = "textEncoding"; static final String TEXT_ENCODING = "textEncoding";
public static final String CLEAR_WEBSTORAGE_EXIT = "clearWebStorageExit"; static final String CLEAR_WEBSTORAGE_EXIT = "clearWebStorageExit";
public static final String SHOW_TABS_IN_DRAWER = "showTabsInDrawer"; static final String SHOW_TABS_IN_DRAWER = "showTabsInDrawer";
public static final String DO_NOT_TRACK = "doNotTrack"; static final String DO_NOT_TRACK = "doNotTrack";
public static final String IDENTIFYING_HEADERS = "removeIdentifyingHeaders"; static final String IDENTIFYING_HEADERS = "removeIdentifyingHeaders";
public static final String SWAP_BOOKMARKS_AND_TABS = "swapBookmarksAndTabs"; static final String SWAP_BOOKMARKS_AND_TABS = "swapBookmarksAndTabs";
public static final String SEARCH_SUGGESTIONS = "searchSuggestions"; static final String SEARCH_SUGGESTIONS = "searchSuggestions";
public static final String USE_PROXY = "useProxy"; static final String USE_PROXY = "useProxy";
public static final String PROXY_CHOICE = "proxyChoice"; static final String PROXY_CHOICE = "proxyChoice";
public static final String USE_PROXY_HOST = "useProxyHost"; static final String USE_PROXY_HOST = "useProxyHost";
public static final String USE_PROXY_PORT = "useProxyPort"; static final String USE_PROXY_PORT = "useProxyPort";
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor"; static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
public static final String INITIAL_CHECK_FOR_I2P = "checkForI2P"; static final String INITIAL_CHECK_FOR_I2P = "checkForI2P";
public static final String LEAK_CANARY = "leakCanary"; static final String LEAK_CANARY = "leakCanary";
} }
public enum Suggestion { public enum Suggestion {

22
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -138,33 +138,39 @@ public final class Utils {
/** /**
* Displays a snackbar to the user with a String resource. * Displays a snackbar to the user with a String resource.
* <p>
* NOTE: If there is an accessibility manager enabled on
* the device, such as LastPass, then the snackbar animations
* will not work.
* *
* @param activity the activity needed to create a snackbar. * @param activity the activity needed to create a snackbar.
* @param resource the string resource to show to the user. * @param resource the string resource to show to the user.
*/ */
public static void showSnackbar(@NonNull Activity activity, @StringRes int resource) { public static void showSnackbar(@NonNull Activity activity, @StringRes int resource) {
View view = activity.findViewById(R.id.coordinator_layout); View view = activity.findViewById(android.R.id.content);
if (view == null) { if (view == null) {
Log.d(TAG, "Unable to find coordinator layout, using content view"); Log.e(TAG, "showSnackbar", new NullPointerException("Unable to find android.R.id.content"));
view = activity.findViewById(android.R.id.content); return;
} }
if (view == null) return;
Snackbar.make(view, resource, Snackbar.LENGTH_SHORT).show(); Snackbar.make(view, resource, Snackbar.LENGTH_SHORT).show();
} }
/** /**
* Displays a snackbar to the user with a string message. * Displays a snackbar to the user with a string message.
* <p>
* NOTE: If there is an accessibility manager enabled on
* the device, such as LastPass, then the snackbar animations
* will not work.
* *
* @param activity the activity needed to create a snackbar. * @param activity the activity needed to create a snackbar.
* @param message the string message to show to the user. * @param message the string message to show to the user.
*/ */
public static void showSnackbar(@NonNull Activity activity, @NonNull String message) { public static void showSnackbar(@NonNull Activity activity, @NonNull String message) {
View view = activity.findViewById(R.id.coordinator_layout); View view = activity.findViewById(android.R.id.content);
if (view == null) { if (view == null) {
Log.d(TAG, "Unable to find coordinator layout, using content view"); Log.e(TAG, "showSnackbar", new NullPointerException("Unable to find android.R.id.content"));
view = activity.findViewById(android.R.id.content); return;
} }
if (view == null) return;
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
} }

Loading…
Cancel
Save