Browse Source

Reducing usage of file names

master
anthony restaino 8 years ago
parent
commit
73136e4b56
  1. 7
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 11
      app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java
  3. 16
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java
  4. 7
      app/src/main/java/acr/browser/lightning/constant/StartPage.java
  5. 3
      app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java
  6. 7
      app/src/main/java/acr/browser/lightning/view/LightningView.java

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

@ -95,7 +95,6 @@ import acr.browser.lightning.browser.BookmarksView; @@ -95,7 +95,6 @@ import acr.browser.lightning.browser.BookmarksView;
import acr.browser.lightning.browser.BrowserPresenter;
import acr.browser.lightning.browser.BrowserView;
import acr.browser.lightning.browser.TabsView;
import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.DownloadsPage;
import acr.browser.lightning.constant.HistoryPage;
@ -2178,8 +2177,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -2178,8 +2177,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override
public void handleBookmarksChange() {
final LightningView currentTab = mTabsManager.getCurrentTab();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {
if (currentTab != null && UrlUtils.isBookmarkUrl(currentTab.getUrl())) {
currentTab.loadBookmarkpage();
}
if (currentTab != null) {
@ -2190,8 +2188,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -2190,8 +2188,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override
public void handleDownloadDeleted() {
final LightningView currentTab = mTabsManager.getCurrentTab();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(DownloadsPage.FILENAME)) {
if (currentTab != null && UrlUtils.isDownloadsUrl(currentTab.getUrl())) {
currentTab.loadDownloadspage();
}
if (currentTab != null) {

11
app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java

@ -56,7 +56,10 @@ public final class DownloadsPage { @@ -56,7 +56,10 @@ public final class DownloadsPage {
private static final String END = "</div></body></html>";
private File mFilesDir;
@NonNull
private static File getDownloadsPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
@Inject Application mApp;
@Inject PreferenceManager mPreferenceManager;
@ -74,11 +77,9 @@ public final class DownloadsPage { @@ -74,11 +77,9 @@ public final class DownloadsPage {
return Single.create(new SingleAction<String>() {
@Override
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
mFilesDir = mApp.getFilesDir();
buildDownloadsPage();
File downloadsWebPage = new File(mFilesDir, FILENAME);
File downloadsWebPage = new File(getDownloadsPageFile(mApp), FILENAME);
subscriber.onItem(Constants.FILE + downloadsWebPage);
subscriber.onComplete();
@ -120,7 +121,7 @@ public final class DownloadsPage { @@ -120,7 +121,7 @@ public final class DownloadsPage {
FileWriter bookWriter = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed
bookWriter = new FileWriter(new File(mFilesDir, FILENAME), false);
bookWriter = new FileWriter(getDownloadsPageFile(mApp), false);
bookWriter.write(downloadsBuilder.toString());
} catch (IOException e) {
e.printStackTrace();

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

@ -61,6 +61,18 @@ public class HistoryPage { @@ -61,6 +61,18 @@ public class HistoryPage {
private static final String END = "</div></body></html>";
/**
* Get the file that the history page is stored in
* or should be stored in.
*
* @param application the application used to access the file.
* @return a valid file object, note that the file might not exist.
*/
@NonNull
private static File getHistoryPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
@NonNull private final String mTitle;
@Inject Application mApp;
@ -98,7 +110,7 @@ public class HistoryPage { @@ -98,7 +110,7 @@ public class HistoryPage {
}
historyBuilder.append(END);
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
File historyWebPage = getHistoryPageFile(mApp);
FileWriter historyWriter = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed
@ -131,7 +143,7 @@ public class HistoryPage { @@ -131,7 +143,7 @@ public class HistoryPage {
return Completable.create(new CompletableAction() {
@Override
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
File historyWebPage = new File(application.getFilesDir(), FILENAME);
File historyWebPage = getHistoryPageFile(application);
if (historyWebPage.exists()) {
historyWebPage.delete();
}

7
app/src/main/java/acr/browser/lightning/constant/StartPage.java

@ -54,6 +54,11 @@ public class StartPage { @@ -54,6 +54,11 @@ public class StartPage {
private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}</script></body></html>";
@NonNull
private static File getStartPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
@NonNull private final String mTitle;
@Inject Application mApp;
@ -151,7 +156,7 @@ public class StartPage { @@ -151,7 +156,7 @@ public class StartPage {
homepageBuilder.append(searchUrl);
homepageBuilder.append(END);
File homepage = new File(mApp.getFilesDir(), FILENAME);
File homepage = getStartPageFile(mApp);
FileWriter hWriter = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed

3
app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java

@ -35,6 +35,7 @@ import acr.browser.lightning.download.DownloadHandler; @@ -35,6 +35,7 @@ import acr.browser.lightning.download.DownloadHandler;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.IntentUtils;
import acr.browser.lightning.utils.Preconditions;
import acr.browser.lightning.utils.UrlUtils;
/**
* TODO Rename this class it doesn't build dialogs only for bookmarks
@ -72,7 +73,7 @@ public class LightningDialogBuilder { @@ -72,7 +73,7 @@ public class LightningDialogBuilder {
@NonNull final UIController uiController,
@NonNull final String url) {
final HistoryItem item;
if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) {
if (UrlUtils.isBookmarkUrl(url)) {
// TODO hacky, make a better bookmark mechanism in the future
final Uri uri = Uri.parse(url);
final String filename = uri.getLastPathSegment();

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

@ -48,7 +48,6 @@ import acr.browser.lightning.app.BrowserApp; @@ -48,7 +48,6 @@ import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.DownloadsPage;
import acr.browser.lightning.constant.HistoryPage;
import acr.browser.lightning.constant.StartPage;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.dialog.LightningDialogBuilder;
@ -989,21 +988,21 @@ public class LightningView { @@ -989,21 +988,21 @@ public class LightningView {
final WebView.HitTestResult result = mWebView.getHitTestResult();
String currentUrl = mWebView.getUrl();
if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) {
if (currentUrl.endsWith(HistoryPage.FILENAME)) {
if (UrlUtils.isHistoryUrl(currentUrl)) {
if (url != null) {
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, url);
} else if (result != null && result.getExtra() != null) {
final String newUrl = result.getExtra();
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl);
}
} else if (currentUrl.endsWith(BookmarkPage.FILENAME)) {
} else if (UrlUtils.isBookmarkUrl(currentUrl)) {
if (url != null) {
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url);
} else if (result != null && result.getExtra() != null) {
final String newUrl = result.getExtra();
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl);
}
} else if (currentUrl.endsWith(DownloadsPage.FILENAME)) {
} else if (UrlUtils.isDownloadsUrl(currentUrl)) {
if (url != null) {
mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, url);
} else if (result != null && result.getExtra() != null) {

Loading…
Cancel
Save