Browse Source

Making history page method static

master
anthony restaino 7 years ago
parent
commit
efe3375389
  1. 12
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 2
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java
  3. 72
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

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

@ -141,7 +141,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@BindView(R.id.progress_view) AnimatedProgressBar mProgressBar; @BindView(R.id.progress_view) AnimatedProgressBar mProgressBar;
@BindView(R.id.search_bar) RelativeLayout mSearchBar; @BindView(R.id.search_bar) RelativeLayout mSearchBar;
// Toolbar Views // Toolbar Views
@BindView(R.id.toolbar) Toolbar mToolbar; @BindView(R.id.toolbar) Toolbar mToolbar;
private View mSearchBackground; private View mSearchBackground;
@ -214,6 +213,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
public abstract void updateHistory(@Nullable final String title, @NonNull final String url); public abstract void updateHistory(@Nullable final String title, @NonNull final String url);
@NonNull
abstract Completable updateCookiePreference(); abstract Completable updateCookiePreference();
@Override @Override
@ -433,6 +433,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
} }
/**
* Determines if an intent is originating
* from a panic trigger.
*
* @param intent the intent to check.
* @return true if the panic trigger sent
* the intent, false otherwise.
*/
static boolean isPanicTrigger(@Nullable Intent intent) { static boolean isPanicTrigger(@Nullable Intent intent) {
return intent != null && INTENT_PANIC_TRIGGER.equals(intent.getAction()); return intent != null && INTENT_PANIC_TRIGGER.equals(intent.getAction());
} }
@ -442,7 +450,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mTabsManager.newTab(this, "", false); mTabsManager.newTab(this, "", false);
mTabsManager.switchToTab(0); mTabsManager.switchToTab(0);
mTabsManager.clearSavedState(); mTabsManager.clearSavedState();
new HistoryPage().deleteHistoryPage().subscribe(); HistoryPage.deleteHistoryPage(getApplication()).subscribe();
closeBrowser(); closeBrowser();
// System exit needed in the case of receiving // System exit needed in the case of receiving
// the panic intent since finish() isn't completely // the panic intent since finish() isn't completely

2
app/src/main/java/acr/browser/lightning/activity/MainActivity.java

@ -34,7 +34,7 @@ public class MainActivity extends BrowserActivity {
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(@NonNull Menu menu) {
getMenuInflater().inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }

72
app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

@ -68,41 +68,41 @@ public class HistoryPage {
final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2); final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2);
HistoryModel.lastHundredVisitedHistoryItems() HistoryModel.lastHundredVisitedHistoryItems()
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() { .subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override @Override
public void onItem(@Nullable List<HistoryItem> item) { public void onItem(@Nullable List<HistoryItem> item) {
Preconditions.checkNonNull(item); Preconditions.checkNonNull(item);
Iterator<HistoryItem> it = item.iterator(); Iterator<HistoryItem> it = item.iterator();
HistoryItem helper; HistoryItem helper;
while (it.hasNext()) { while (it.hasNext()) {
helper = it.next(); helper = it.next();
historyBuilder.append(PART1); historyBuilder.append(PART1);
historyBuilder.append(helper.getUrl()); historyBuilder.append(helper.getUrl());
historyBuilder.append(PART2); historyBuilder.append(PART2);
historyBuilder.append(helper.getTitle()); historyBuilder.append(helper.getTitle());
historyBuilder.append(PART3); historyBuilder.append(PART3);
historyBuilder.append(helper.getUrl()); historyBuilder.append(helper.getUrl());
historyBuilder.append(PART4); historyBuilder.append(PART4);
}
historyBuilder.append(END);
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
FileWriter historyWriter = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed
historyWriter = new FileWriter(historyWebPage, false);
historyWriter.write(historyBuilder.toString());
} catch (IOException e) {
Log.e(TAG, "Unable to write history page to disk", e);
} finally {
Utils.close(historyWriter);
}
subscriber.onItem(Constants.FILE + historyWebPage);
subscriber.onComplete();
} }
});
historyBuilder.append(END);
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
FileWriter historyWriter = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed
historyWriter = new FileWriter(historyWebPage, false);
historyWriter.write(historyBuilder.toString());
} catch (IOException e) {
Log.e(TAG, "Unable to write history page to disk", e);
} finally {
Utils.close(historyWriter);
}
subscriber.onItem(Constants.FILE + historyWebPage);
subscriber.onComplete();
}
});
} }
}); });
} }
@ -116,11 +116,11 @@ public class HistoryPage {
* when subscribed. * when subscribed.
*/ */
@NonNull @NonNull
public Completable deleteHistoryPage() { public static Completable deleteHistoryPage(@NonNull final Application application) {
return Completable.create(new CompletableAction() { return Completable.create(new CompletableAction() {
@Override @Override
public void onSubscribe(@NonNull CompletableSubscriber subscriber) { public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
File historyWebPage = new File(mApp.getFilesDir(), FILENAME); File historyWebPage = new File(application.getFilesDir(), FILENAME);
if (historyWebPage.exists()) { if (historyWebPage.exists()) {
historyWebPage.delete(); historyWebPage.delete();
} }

Loading…
Cancel
Save