|
|
@ -3,27 +3,31 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package acr.browser.lightning.constant; |
|
|
|
package acr.browser.lightning.constant; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application; |
|
|
|
|
|
|
|
import android.os.AsyncTask; |
|
|
|
|
|
|
|
import android.support.annotation.NonNull; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileWriter; |
|
|
|
import java.io.FileWriter; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.lang.ref.WeakReference; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
|
|
|
|
import acr.browser.lightning.database.HistoryItem; |
|
|
|
|
|
|
|
import acr.browser.lightning.R; |
|
|
|
import acr.browser.lightning.R; |
|
|
|
|
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
import acr.browser.lightning.database.HistoryDatabase; |
|
|
|
import acr.browser.lightning.database.HistoryDatabase; |
|
|
|
|
|
|
|
import acr.browser.lightning.database.HistoryItem; |
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
|
|
|
|
import acr.browser.lightning.view.LightningView; |
|
|
|
|
|
|
|
|
|
|
|
public class HistoryPage { |
|
|
|
public class HistoryPage extends AsyncTask<Void, Void, Void> { |
|
|
|
|
|
|
|
|
|
|
|
public static final String FILENAME = "history.html"; |
|
|
|
public static final String FILENAME = "history.html"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String HEADING = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"><title>" |
|
|
|
private static final String HEADING_1 = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"><title>"; |
|
|
|
+ BrowserApp.getContext().getString(R.string.action_history) |
|
|
|
|
|
|
|
+ "</title></head><style>body { background: #e1e1e1;}.box { vertical-align:middle;position:relative; display: block; margin: 10px;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:5px; background-color:#fff;box-shadow: 0px 2px 3px rgba( 0, 0, 0, 0.25 );font-family: Arial;color: #444;font-size: 12px;-moz-border-radius: 2px;-webkit-border-radius: 2px;border-radius: 2px;}.box a { width: 100%; height: 100%; position: absolute; left: 0; top: 0;}.black {color: black;font-size: 15px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}.font {color: gray;font-size: 10px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}</style><body><div id=\"content\">"; |
|
|
|
private static final String HEADING_2 = "</title></head><style>body { background: #e1e1e1;}.box { vertical-align:middle;position:relative; display: block; margin: 10px;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:5px; background-color:#fff;box-shadow: 0px 2px 3px rgba( 0, 0, 0, 0.25 );font-family: Arial;color: #444;font-size: 12px;-moz-border-radius: 2px;-webkit-border-radius: 2px;border-radius: 2px;}.box a { width: 100%; height: 100%; position: absolute; left: 0; top: 0;}.black {color: black;font-size: 15px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}.font {color: gray;font-size: 10px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}</style><body><div id=\"content\">"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String PART1 = "<div class=\"box\"><a href=\""; |
|
|
|
private static final String PART1 = "<div class=\"box\"><a href=\""; |
|
|
|
|
|
|
|
|
|
|
@ -35,24 +39,52 @@ public class HistoryPage { |
|
|
|
|
|
|
|
|
|
|
|
private static final String END = "</div></body></html>"; |
|
|
|
private static final String END = "</div></body></html>"; |
|
|
|
|
|
|
|
|
|
|
|
public static String getHistoryPage(Context context) { |
|
|
|
private final WeakReference<LightningView> mTabReference; |
|
|
|
StringBuilder historyBuilder = new StringBuilder(HistoryPage.HEADING); |
|
|
|
private final File mFilesDir; |
|
|
|
|
|
|
|
private final String mTitle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String mHistoryUrl = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public HistoryPage(LightningView tab, Application app) { |
|
|
|
|
|
|
|
mTabReference = new WeakReference<>(tab); |
|
|
|
|
|
|
|
mFilesDir = app.getFilesDir(); |
|
|
|
|
|
|
|
mTitle = app.getString(R.string.action_history); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected Void doInBackground(Void... params) { |
|
|
|
|
|
|
|
mHistoryUrl = getHistoryPage(); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void onPostExecute(Void aVoid) { |
|
|
|
|
|
|
|
super.onPostExecute(aVoid); |
|
|
|
|
|
|
|
LightningView tab = mTabReference.get(); |
|
|
|
|
|
|
|
if (tab != null && mHistoryUrl != null) { |
|
|
|
|
|
|
|
tab.loadUrl(mHistoryUrl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
|
|
|
private String getHistoryPage() { |
|
|
|
|
|
|
|
StringBuilder historyBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2); |
|
|
|
List<HistoryItem> historyList = getWebHistory(); |
|
|
|
List<HistoryItem> historyList = getWebHistory(); |
|
|
|
Iterator<HistoryItem> it = historyList.iterator(); |
|
|
|
Iterator<HistoryItem> it = historyList.iterator(); |
|
|
|
HistoryItem helper; |
|
|
|
HistoryItem helper; |
|
|
|
while (it.hasNext()) { |
|
|
|
while (it.hasNext()) { |
|
|
|
helper = it.next(); |
|
|
|
helper = it.next(); |
|
|
|
historyBuilder.append(HistoryPage.PART1); |
|
|
|
historyBuilder.append(PART1); |
|
|
|
historyBuilder.append(helper.getUrl()); |
|
|
|
historyBuilder.append(helper.getUrl()); |
|
|
|
historyBuilder.append(HistoryPage.PART2); |
|
|
|
historyBuilder.append(PART2); |
|
|
|
historyBuilder.append(helper.getTitle()); |
|
|
|
historyBuilder.append(helper.getTitle()); |
|
|
|
historyBuilder.append(HistoryPage.PART3); |
|
|
|
historyBuilder.append(PART3); |
|
|
|
historyBuilder.append(helper.getUrl()); |
|
|
|
historyBuilder.append(helper.getUrl()); |
|
|
|
historyBuilder.append(HistoryPage.PART4); |
|
|
|
historyBuilder.append(PART4); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
historyBuilder.append(HistoryPage.END); |
|
|
|
historyBuilder.append(END); |
|
|
|
File historyWebPage = new File(context.getFilesDir(), FILENAME); |
|
|
|
File historyWebPage = new File(mFilesDir, FILENAME); |
|
|
|
FileWriter historyWriter = null; |
|
|
|
FileWriter historyWriter = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
//noinspection IOResourceOpenedButNotSafelyClosed
|
|
|
|
//noinspection IOResourceOpenedButNotSafelyClosed
|
|
|
@ -70,4 +102,9 @@ public class HistoryPage { |
|
|
|
HistoryDatabase databaseHandler = BrowserApp.getHistoryDatabase(); |
|
|
|
HistoryDatabase databaseHandler = BrowserApp.getHistoryDatabase(); |
|
|
|
return databaseHandler.getLastHundredItems(); |
|
|
|
return databaseHandler.getLastHundredItems(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void load() { |
|
|
|
|
|
|
|
executeOnExecutor(BrowserApp.getIOThread()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |