diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index 284d792..1867fb1 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/src/acr/browser/lightning/BrowserActivity.java @@ -1834,45 +1834,16 @@ public class BrowserActivity extends Activity implements BrowserController { return bookmarks; } - /** - * returns a list of HistoryItems - */ - private List getLatestHistory() { - HistoryDatabaseHandler historyHandler = new HistoryDatabaseHandler(mContext); - return historyHandler.getLastHundredItems(); - } - /** * function that opens the HTML history page in the browser */ private void openHistory() { - + // use a thread so that history retrieval doesn't block the UI Thread history = new Thread(new Runnable() { @Override public void run() { - String historyHtml = HistoryPageVariables.Heading; - List historyList = getLatestHistory(); - Iterator it = historyList.iterator(); - HistoryItem helper; - while (it.hasNext()) { - helper = it.next(); - historyHtml += HistoryPageVariables.Part1 + helper.getUrl() - + HistoryPageVariables.Part2 + helper.getTitle() - + HistoryPageVariables.Part3 + helper.getUrl() - + HistoryPageVariables.Part4; - } - - historyHtml += HistoryPageVariables.End; - File historyWebPage = new File(getFilesDir(), "history.html"); - try { - FileWriter hWriter = new FileWriter(historyWebPage, false); - hWriter.write(historyHtml); - hWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - mCurrentView.loadUrl(Constants.FILE + historyWebPage); + mCurrentView.loadUrl(HistoryPage.getHistoryPage(mContext)); mSearch.setText(""); } @@ -1900,17 +1871,17 @@ public class BrowserActivity extends Activity implements BrowserController { * open the HTML bookmarks page, parameter view is the WebView that should show the page */ public void openBookmarkPage(WebView view) { - String bookmarkHtml = BookmarkPageVariables.Heading; + String bookmarkHtml = BookmarkPage.HEADING; Iterator iter = mBookmarkList.iterator(); HistoryItem helper; while (iter.hasNext()) { helper = iter.next(); - bookmarkHtml += (BookmarkPageVariables.Part1 + helper.getUrl() - + BookmarkPageVariables.Part2 + helper.getUrl() + BookmarkPageVariables.Part3 - + helper.getTitle() + BookmarkPageVariables.Part4); + bookmarkHtml += (BookmarkPage.PART1 + helper.getUrl() + + BookmarkPage.PART2 + helper.getUrl() + BookmarkPage.PART3 + + helper.getTitle() + BookmarkPage.PART4); } - bookmarkHtml += BookmarkPageVariables.End; - File bookmarkWebPage = new File(mContext.getFilesDir(), "bookmarks.html"); + bookmarkHtml += BookmarkPage.END; + File bookmarkWebPage = new File(mContext.getFilesDir(), BookmarkPage.FILENAME); try { FileWriter bookWriter = new FileWriter(bookmarkWebPage, false); bookWriter.write(bookmarkHtml); @@ -1980,7 +1951,7 @@ public class BrowserActivity extends Activity implements BrowserController { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); - startActivityForResult(Intent.createChooser(i, "File Chooser"), 1); + startActivityForResult(Intent.createChooser(i, getString(R.string.title_file_chooser)), 1); } @Override diff --git a/src/acr/browser/lightning/HistoryPage.java b/src/acr/browser/lightning/HistoryPage.java new file mode 100644 index 0000000..3a7529c --- /dev/null +++ b/src/acr/browser/lightning/HistoryPage.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014 A.C.R. Development + */ +package acr.browser.lightning; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import android.content.Context; + +public class HistoryPage { + + private static final String FILENAME = "history.html"; + + private static final String HEADING = "" + + BrowserApp.getAppContext().getString(R.string.action_history) + + "
"; + + private static final String PART1 = "

"; + + private static final String PART3 = "

"; + + private static final String PART4 = "

"; + + private static final String END = ""; + + public static String getHistoryPage(Context context) { + String historyHtml = HistoryPage.HEADING; + List historyList = getWebHistory(context); + Iterator it = historyList.iterator(); + HistoryItem helper; + while (it.hasNext()) { + helper = it.next(); + historyHtml += HistoryPage.PART1 + helper.getUrl() + HistoryPage.PART2 + + helper.getTitle() + HistoryPage.PART3 + helper.getUrl() + HistoryPage.PART4; + } + + historyHtml += HistoryPage.END; + File historyWebPage = new File(context.getFilesDir(), FILENAME); + try { + FileWriter historyWriter = new FileWriter(historyWebPage, false); + historyWriter.write(historyHtml); + historyWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return Constants.FILE + historyWebPage; + } + + private static List getWebHistory(Context context) { + HistoryDatabaseHandler databaseHandler = new HistoryDatabaseHandler(context); + return databaseHandler.getLastHundredItems(); + } +} diff --git a/src/acr/browser/lightning/HistoryPageVariables.java b/src/acr/browser/lightning/HistoryPageVariables.java deleted file mode 100644 index 1d6f51e..0000000 --- a/src/acr/browser/lightning/HistoryPageVariables.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2014 A.C.R. Development - */ -package acr.browser.lightning; - -public class HistoryPageVariables { - - public static final String Heading = "" - + BrowserApp.getAppContext().getString(R.string.action_history) - + "
"; - - public static final String Part1 = "

"; - - public static final String Part3 = "

"; - - public static final String Part4 = "

"; - - public static final String End = ""; -}