diff --git a/Ninja/.idea/workspace.xml b/Ninja/.idea/workspace.xml index beb8eb8..d5df4b7 100644 --- a/Ninja/.idea/workspace.xml +++ b/Ninja/.idea/workspace.xml @@ -74,8 +74,6 @@ @@ -134,10 +134,8 @@ - @@ -162,9 +160,6 @@ - - - @@ -229,62 +224,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -302,9 +246,9 @@ - + - + @@ -532,7 +476,7 @@ - + @@ -540,60 +484,30 @@ - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -737,13 +624,6 @@ - - - - - - - @@ -779,14 +659,14 @@ + + + - - - @@ -796,14 +676,14 @@ + + + - - - @@ -919,114 +799,150 @@ - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - - - - + + + - + - - - - - + + + + + + + + + - - + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + - + - - + + - + - - + + - + - - + + + + + + + + + - + - - - - - - - - - + + + @@ -1082,7 +998,7 @@ - Android|Ninja + Ninja \ No newline at end of file diff --git a/Ninja/libs/jsoup-1.8.2.jar b/Ninja/libs/jsoup-1.8.2.jar new file mode 100644 index 0000000..74ea084 Binary files /dev/null and b/Ninja/libs/jsoup-1.8.2.jar differ diff --git a/Ninja/res/values/strings_app.xml b/Ninja/res/values/strings_app.xml index 290f16b..2c970e4 100644 --- a/Ninja/res/values/strings_app.xml +++ b/Ninja/res/values/strings_app.xml @@ -15,7 +15,7 @@ Ninja - 1.2.5 + 1.2.6 diff --git a/Ninja/res/values/strings_key.xml b/Ninja/res/values/strings_key.xml index c473ce8..4ff5de8 100644 --- a/Ninja/res/values/strings_key.xml +++ b/Ninja/res/values/strings_key.xml @@ -4,7 +4,7 @@ - SP_FIRST_17 + SP_FIRST_18 diff --git a/Ninja/res/xml/preference_clear.xml b/Ninja/res/xml/preference_clear.xml index b3b8ed7..d8762d8 100644 --- a/Ninja/res/xml/preference_clear.xml +++ b/Ninja/res/xml/preference_clear.xml @@ -9,7 +9,7 @@ + android:title="@string/clear_title_bookmarks"> diff --git a/Ninja/src/io/github/mthli/Ninja/Activity/ClearActivity.java b/Ninja/src/io/github/mthli/Ninja/Activity/ClearActivity.java index a7adf19..e40ca66 100644 --- a/Ninja/src/io/github/mthli/Ninja/Activity/ClearActivity.java +++ b/Ninja/src/io/github/mthli/Ninja/Activity/ClearActivity.java @@ -64,7 +64,7 @@ private void clear() { boolean clearBookmarks = sp.getBoolean(getString(R.string.sp_clear_bookmarks), false); boolean clearCache = sp.getBoolean(getString(R.string.sp_clear_cache), true); boolean clearCookie = sp.getBoolean(getString(R.string.sp_clear_cookie), false); - boolean clearFormData = sp.getBoolean(getString(R.string.sp_clear_form_data), true); + boolean clearFormData = sp.getBoolean(getString(R.string.sp_clear_form_data), false); boolean clearHistory = sp.getBoolean(getString(R.string.sp_clear_history), true); boolean clearPasswords = sp.getBoolean(getString(R.string.sp_clear_passwords), false); diff --git a/Ninja/src/io/github/mthli/Ninja/Service/ClearService.java b/Ninja/src/io/github/mthli/Ninja/Service/ClearService.java index 1db64ca..b0af938 100644 --- a/Ninja/src/io/github/mthli/Ninja/Service/ClearService.java +++ b/Ninja/src/io/github/mthli/Ninja/Service/ClearService.java @@ -26,7 +26,7 @@ private void clear() { boolean clearBookmarks = sp.getBoolean(getString(R.string.sp_clear_bookmarks), false); boolean clearCache = sp.getBoolean(getString(R.string.sp_clear_cache), true); boolean clearCookie = sp.getBoolean(getString(R.string.sp_clear_cookie), false); - boolean clearFormData = sp.getBoolean(getString(R.string.sp_clear_form_data), true); + boolean clearFormData = sp.getBoolean(getString(R.string.sp_clear_form_data), false); boolean clearHistory = sp.getBoolean(getString(R.string.sp_clear_history), true); boolean clearPasswords = sp.getBoolean(getString(R.string.sp_clear_passwords), false); diff --git a/Ninja/src/io/github/mthli/Ninja/Unit/BrowserUnit.java b/Ninja/src/io/github/mthli/Ninja/Unit/BrowserUnit.java index 06ea16c..f3d39fc 100644 --- a/Ninja/src/io/github/mthli/Ninja/Unit/BrowserUnit.java +++ b/Ninja/src/io/github/mthli/Ninja/Unit/BrowserUnit.java @@ -16,17 +16,20 @@ import io.github.mthli.Ninja.Database.RecordAction; import io.github.mthli.Ninja.R; import io.github.mthli.Ninja.View.NinjaToast; -import org.json.JSONObject; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import java.io.*; import java.net.URLEncoder; -import java.util.List; -import java.util.Locale; +import java.util.*; import java.util.regex.Pattern; public class BrowserUnit { public static final int PROGRESS_MAX = 100; public static final int PROGRESS_MIN = 0; + public static final String SUFFIX_HTML = ".html"; public static final String SUFFIX_PNG = ".png"; public static final String SUFFIX_TXT = ".txt"; @@ -40,6 +43,10 @@ public class BrowserUnit { public static final String MIME_TYPE_IMAGE = "image/*"; public static final String BASE_URL = "file:///android_asset/"; + public static final String NINJA_BOOKMARK_TYPE = "
{title}"; + public static final String NINJA_BOOKMARK_TITLE = "{title}"; + public static final String NINJA_BOOKMARK_URL = "{url}"; + public static final String NINJA_BOOKMARK_TIME = "{time}"; public static final String NINJA_INTRODUCTION_EN = "ninja_introduction_en.html"; public static final String NINJA_INTRODUCTION_ZH = "ninja_introduction_zh.html"; @@ -242,21 +249,21 @@ public static String exportBookmarks(Context context) { action.close(); String filename = context.getString(R.string.bookmarks_filename); - File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), filename + SUFFIX_TXT); + File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), filename + SUFFIX_HTML); int count = 0; while (file.exists()) { count++; - file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), filename + "." + count + SUFFIX_TXT); + file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), filename + "." + count + SUFFIX_HTML); } try { BufferedWriter writer = new BufferedWriter(new FileWriter(file, false)); for (Record record : list) { - JSONObject object = new JSONObject(); - object.put(RecordUnit.COLUMN_TITLE, record.getTitle()); - object.put(RecordUnit.COLUMN_URL, record.getURL()); - object.put(RecordUnit.COLUMN_TIME, record.getTime()); - writer.write(object.toString()); + String type = NINJA_BOOKMARK_TYPE; + type = type.replace(NINJA_BOOKMARK_TITLE, record.getTitle()); + type = type.replace(NINJA_BOOKMARK_URL, record.getURL()); + type = type.replace(NINJA_BOOKMARK_TIME, String.valueOf(record.getTime())); + writer.write(type); writer.newLine(); } writer.close(); @@ -297,29 +304,38 @@ public static int importBookmarks(Context context, File file) { if (file == null) { return -1; } + List list = new ArrayList<>(); - int count = 0; try { RecordAction action = new RecordAction(context); action.open(true); - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line; - while ((line = reader.readLine()) != null) { - JSONObject object = new JSONObject(line); + + Document document = Jsoup.parse(file, URL_ENCODING); + Elements elements = document.select("a"); + for (Element element : elements) { Record record = new Record(); - record.setTitle(object.getString(RecordUnit.COLUMN_TITLE).trim()); - record.setURL(object.getString(RecordUnit.COLUMN_URL).trim()); - record.setTime(object.getLong(RecordUnit.COLUMN_TIME)); + record.setTitle(element.text()); + record.setURL(element.attr("href").trim()); + record.setTime(System.currentTimeMillis()); if (!action.checkBookmark(record)) { - action.addBookmark(record); - count++; + list.add(record); } } - reader.close(); + + Collections.sort(list, new Comparator() { + @Override + public int compare(Record first, Record second) { + return first.getTitle().compareTo(second.getTitle()); + } + }); + + for (Record record : list) { + action.addBookmark(record); + } action.close(); } catch (Exception e) {} - return count; + return list.size(); } public static int importWhitelist(Context context, File file) { diff --git a/README.md b/README.md index 68a0517..c5ca9fd 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A web browser that open links in background without ever leaving your favorite a [Ninja in Coolapk](http://coolapk.com/apk/io.github.mthli.Ninja "Ninja in Cookapk") -[Download latest Ninja.apk](https://github.com/mthli/Ninja/releases/download/v1.2.5/Ninja.1.2.5.apk "Ninja.1.2.5.apk") +[Download latest Ninja.apk](https://github.com/mthli/Ninja/releases/download/v1.2.6/Ninja.1.2.6.apk "Ninja.1.2.6.apk") __SUPPORT: Android 4.1+__