Browse Source

Making history page method static

master
anthony restaino 8 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 @@ -141,7 +141,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@BindView(R.id.progress_view) AnimatedProgressBar mProgressBar;
@BindView(R.id.search_bar) RelativeLayout mSearchBar;
// Toolbar Views
@BindView(R.id.toolbar) Toolbar mToolbar;
private View mSearchBackground;
@ -214,6 +213,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -214,6 +213,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
public abstract void updateHistory(@Nullable final String title, @NonNull final String url);
@NonNull
abstract Completable updateCookiePreference();
@Override
@ -433,6 +433,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -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) {
return intent != null && INTENT_PANIC_TRIGGER.equals(intent.getAction());
}
@ -442,7 +450,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -442,7 +450,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mTabsManager.newTab(this, "", false);
mTabsManager.switchToTab(0);
mTabsManager.clearSavedState();
new HistoryPage().deleteHistoryPage().subscribe();
HistoryPage.deleteHistoryPage(getApplication()).subscribe();
closeBrowser();
// System exit needed in the case of receiving
// 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 { @@ -34,7 +34,7 @@ public class MainActivity extends BrowserActivity {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}

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

@ -68,41 +68,41 @@ public class HistoryPage { @@ -68,41 +68,41 @@ public class HistoryPage {
final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2);
HistoryModel.lastHundredVisitedHistoryItems()
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override
public void onItem(@Nullable List<HistoryItem> item) {
Preconditions.checkNonNull(item);
Iterator<HistoryItem> it = item.iterator();
HistoryItem helper;
while (it.hasNext()) {
helper = it.next();
historyBuilder.append(PART1);
historyBuilder.append(helper.getUrl());
historyBuilder.append(PART2);
historyBuilder.append(helper.getTitle());
historyBuilder.append(PART3);
historyBuilder.append(helper.getUrl());
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();
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override
public void onItem(@Nullable List<HistoryItem> item) {
Preconditions.checkNonNull(item);
Iterator<HistoryItem> it = item.iterator();
HistoryItem helper;
while (it.hasNext()) {
helper = it.next();
historyBuilder.append(PART1);
historyBuilder.append(helper.getUrl());
historyBuilder.append(PART2);
historyBuilder.append(helper.getTitle());
historyBuilder.append(PART3);
historyBuilder.append(helper.getUrl());
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();
}
});
}
});
}
@ -116,11 +116,11 @@ public class HistoryPage { @@ -116,11 +116,11 @@ public class HistoryPage {
* when subscribed.
*/
@NonNull
public Completable deleteHistoryPage() {
public static Completable deleteHistoryPage(@NonNull final Application application) {
return Completable.create(new CompletableAction() {
@Override
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
File historyWebPage = new File(application.getFilesDir(), FILENAME);
if (historyWebPage.exists()) {
historyWebPage.delete();
}

Loading…
Cancel
Save