Reducing usage of file names
This commit is contained in:
parent
954f8c5885
commit
73136e4b56
@ -95,7 +95,6 @@ import acr.browser.lightning.browser.BookmarksView;
|
|||||||
import acr.browser.lightning.browser.BrowserPresenter;
|
import acr.browser.lightning.browser.BrowserPresenter;
|
||||||
import acr.browser.lightning.browser.BrowserView;
|
import acr.browser.lightning.browser.BrowserView;
|
||||||
import acr.browser.lightning.browser.TabsView;
|
import acr.browser.lightning.browser.TabsView;
|
||||||
import acr.browser.lightning.constant.BookmarkPage;
|
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.constant.DownloadsPage;
|
import acr.browser.lightning.constant.DownloadsPage;
|
||||||
import acr.browser.lightning.constant.HistoryPage;
|
import acr.browser.lightning.constant.HistoryPage;
|
||||||
@ -2178,8 +2177,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void handleBookmarksChange() {
|
public void handleBookmarksChange() {
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
|
if (currentTab != null && UrlUtils.isBookmarkUrl(currentTab.getUrl())) {
|
||||||
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
|
||||||
currentTab.loadBookmarkpage();
|
currentTab.loadBookmarkpage();
|
||||||
}
|
}
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
@ -2190,8 +2188,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void handleDownloadDeleted() {
|
public void handleDownloadDeleted() {
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
|
if (currentTab != null && UrlUtils.isDownloadsUrl(currentTab.getUrl())) {
|
||||||
&& currentTab.getUrl().endsWith(DownloadsPage.FILENAME)) {
|
|
||||||
currentTab.loadDownloadspage();
|
currentTab.loadDownloadspage();
|
||||||
}
|
}
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
|
@ -56,7 +56,10 @@ public final class DownloadsPage {
|
|||||||
|
|
||||||
private static final String END = "</div></body></html>";
|
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 Application mApp;
|
||||||
@Inject PreferenceManager mPreferenceManager;
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
@ -74,11 +77,9 @@ public final class DownloadsPage {
|
|||||||
return Single.create(new SingleAction<String>() {
|
return Single.create(new SingleAction<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
public void onSubscribe(@NonNull SingleSubscriber<String> subscriber) {
|
||||||
mFilesDir = mApp.getFilesDir();
|
|
||||||
|
|
||||||
buildDownloadsPage();
|
buildDownloadsPage();
|
||||||
|
|
||||||
File downloadsWebPage = new File(mFilesDir, FILENAME);
|
File downloadsWebPage = new File(getDownloadsPageFile(mApp), FILENAME);
|
||||||
|
|
||||||
subscriber.onItem(Constants.FILE + downloadsWebPage);
|
subscriber.onItem(Constants.FILE + downloadsWebPage);
|
||||||
subscriber.onComplete();
|
subscriber.onComplete();
|
||||||
@ -120,7 +121,7 @@ public final class DownloadsPage {
|
|||||||
FileWriter bookWriter = null;
|
FileWriter bookWriter = null;
|
||||||
try {
|
try {
|
||||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||||
bookWriter = new FileWriter(new File(mFilesDir, FILENAME), false);
|
bookWriter = new FileWriter(getDownloadsPageFile(mApp), false);
|
||||||
bookWriter.write(downloadsBuilder.toString());
|
bookWriter.write(downloadsBuilder.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -61,6 +61,18 @@ public class HistoryPage {
|
|||||||
|
|
||||||
private static final String END = "</div></body></html>";
|
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;
|
@NonNull private final String mTitle;
|
||||||
|
|
||||||
@Inject Application mApp;
|
@Inject Application mApp;
|
||||||
@ -98,7 +110,7 @@ public class HistoryPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
historyBuilder.append(END);
|
historyBuilder.append(END);
|
||||||
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
|
File historyWebPage = getHistoryPageFile(mApp);
|
||||||
FileWriter historyWriter = null;
|
FileWriter historyWriter = null;
|
||||||
try {
|
try {
|
||||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||||
@ -131,7 +143,7 @@ public class HistoryPage {
|
|||||||
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(application.getFilesDir(), FILENAME);
|
File historyWebPage = getHistoryPageFile(application);
|
||||||
if (historyWebPage.exists()) {
|
if (historyWebPage.exists()) {
|
||||||
historyWebPage.delete();
|
historyWebPage.delete();
|
||||||
}
|
}
|
||||||
|
@ -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>";
|
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;
|
@NonNull private final String mTitle;
|
||||||
|
|
||||||
@Inject Application mApp;
|
@Inject Application mApp;
|
||||||
@ -151,7 +156,7 @@ public class StartPage {
|
|||||||
homepageBuilder.append(searchUrl);
|
homepageBuilder.append(searchUrl);
|
||||||
homepageBuilder.append(END);
|
homepageBuilder.append(END);
|
||||||
|
|
||||||
File homepage = new File(mApp.getFilesDir(), FILENAME);
|
File homepage = getStartPageFile(mApp);
|
||||||
FileWriter hWriter = null;
|
FileWriter hWriter = null;
|
||||||
try {
|
try {
|
||||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||||
|
@ -35,6 +35,7 @@ import acr.browser.lightning.download.DownloadHandler;
|
|||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.utils.IntentUtils;
|
import acr.browser.lightning.utils.IntentUtils;
|
||||||
import acr.browser.lightning.utils.Preconditions;
|
import acr.browser.lightning.utils.Preconditions;
|
||||||
|
import acr.browser.lightning.utils.UrlUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO Rename this class it doesn't build dialogs only for bookmarks
|
* TODO Rename this class it doesn't build dialogs only for bookmarks
|
||||||
@ -72,7 +73,7 @@ public class LightningDialogBuilder {
|
|||||||
@NonNull final UIController uiController,
|
@NonNull final UIController uiController,
|
||||||
@NonNull final String url) {
|
@NonNull final String url) {
|
||||||
final HistoryItem item;
|
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
|
// TODO hacky, make a better bookmark mechanism in the future
|
||||||
final Uri uri = Uri.parse(url);
|
final Uri uri = Uri.parse(url);
|
||||||
final String filename = uri.getLastPathSegment();
|
final String filename = uri.getLastPathSegment();
|
||||||
|
@ -48,7 +48,6 @@ import acr.browser.lightning.app.BrowserApp;
|
|||||||
import acr.browser.lightning.constant.BookmarkPage;
|
import acr.browser.lightning.constant.BookmarkPage;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.constant.DownloadsPage;
|
import acr.browser.lightning.constant.DownloadsPage;
|
||||||
import acr.browser.lightning.constant.HistoryPage;
|
|
||||||
import acr.browser.lightning.constant.StartPage;
|
import acr.browser.lightning.constant.StartPage;
|
||||||
import acr.browser.lightning.controller.UIController;
|
import acr.browser.lightning.controller.UIController;
|
||||||
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||||
@ -989,21 +988,21 @@ public class LightningView {
|
|||||||
final WebView.HitTestResult result = mWebView.getHitTestResult();
|
final WebView.HitTestResult result = mWebView.getHitTestResult();
|
||||||
String currentUrl = mWebView.getUrl();
|
String currentUrl = mWebView.getUrl();
|
||||||
if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) {
|
if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) {
|
||||||
if (currentUrl.endsWith(HistoryPage.FILENAME)) {
|
if (UrlUtils.isHistoryUrl(currentUrl)) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, url);
|
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, url);
|
||||||
} else if (result != null && result.getExtra() != null) {
|
} else if (result != null && result.getExtra() != null) {
|
||||||
final String newUrl = result.getExtra();
|
final String newUrl = result.getExtra();
|
||||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl);
|
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl);
|
||||||
}
|
}
|
||||||
} else if (currentUrl.endsWith(BookmarkPage.FILENAME)) {
|
} else if (UrlUtils.isBookmarkUrl(currentUrl)) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url);
|
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url);
|
||||||
} else if (result != null && result.getExtra() != null) {
|
} else if (result != null && result.getExtra() != null) {
|
||||||
final String newUrl = result.getExtra();
|
final String newUrl = result.getExtra();
|
||||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl);
|
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl);
|
||||||
}
|
}
|
||||||
} else if (currentUrl.endsWith(DownloadsPage.FILENAME)) {
|
} else if (UrlUtils.isDownloadsUrl(currentUrl)) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, url);
|
mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, url);
|
||||||
} else if (result != null && result.getExtra() != null) {
|
} else if (result != null && result.getExtra() != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user