diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e34cdf1..1a71f1c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,18 +1,20 @@ + package="telegra.ph"> - + + android:allowBackup="false" + android:icon="@drawable/telegraph" + android:label="@string/app_name" + android:supportsRtl="true" + android:theme="@style/AppTheme"> @@ -20,8 +22,10 @@ + + diff --git a/app/src/main/java/telegra/ph/History.kt b/app/src/main/java/telegra/ph/History.kt deleted file mode 100644 index b5474bb..0000000 --- a/app/src/main/java/telegra/ph/History.kt +++ /dev/null @@ -1,12 +0,0 @@ -package telegra.ph - -import android.content.Context -import android.preference.PreferenceManager - -fun Context.getHistory() = PreferenceManager.getDefaultSharedPreferences(this).getStringSet("history", mutableSetOf()) - -fun Context.addToHistory(entry: String) { - PreferenceManager.getDefaultSharedPreferences(this).edit().putStringSet("history", getHistory().apply { - add(entry) - }).apply() -} \ No newline at end of file diff --git a/app/src/main/java/telegra/ph/MainActivity.kt b/app/src/main/java/telegra/ph/MainActivity.kt index 1b250cf..3587198 100644 --- a/app/src/main/java/telegra/ph/MainActivity.kt +++ b/app/src/main/java/telegra/ph/MainActivity.kt @@ -35,11 +35,13 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener { overScrollMode = View.OVER_SCROLL_NEVER } - if (intent.action == Intent.ACTION_VIEW && !intent.dataString.isNullOrBlank() && intent.dataString.contains("telegra.ph")) { + if (intent.action == Intent.ACTION_VIEW && !intent.dataString.isNullOrBlank() && intent.dataString.contains("telegra.ph")) loadPage(intent.dataString.split("/").last()) - } else { - webView?.loadUrl(TELEGRAPH) - } + else loadEditor() + } + + private fun loadEditor() { + webView?.loadUrl(TELEGRAPH) } private fun loadPage(path: String) { @@ -54,7 +56,6 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener { html += htmlEnd webView?.loadDataWithBaseURL(it.url, html, "text/html; charset=UTF-8", null, null) url = it.url - addToHistory("${it.path}xxx;xxx${it.title}") } } } @@ -108,13 +109,38 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { - R.id.history -> { + R.id.create -> { + loadEditor() + true + } + R.id.bookmarks -> { MaterialDialog.Builder(this) - .title(R.string.history) - .items(getHistory().reversed().map { it.split("xxx;xxx")[1] }) + .title(R.string.bookmarks) + .items(bookmarks().reversed().map { it.split("xxx;xxx")[1] }) .itemsCallback { materialDialog, view, i, charSequence -> - loadPage(getHistory().reversed().map { it.split("xxx;xxx")[0] }[i]) + loadPage(bookmarks().reversed().map { it.split("xxx;xxx")[0] }[i]) } + .itemsLongCallback { materialDialog, view, i, charSequence -> + MaterialDialog.Builder(this) + .title(R.string.delete) + .content(R.string.delete_question) + .positiveText(android.R.string.yes) + .negativeText(android.R.string.no) + .onPositive { materialDialog, dialogAction -> + deleteBookmark(bookmarks().reversed().map { it.split("xxx;xxx")[0] }[i]) + } + .show() + true + } + .show() + true + } + R.id.bookmark -> { + MaterialDialog.Builder(this) + .title(R.string.title_question) + .input(getString(R.string.title_hint), "", { dialog, input -> + addBookmark("${(if (webView?.url != "about:blank") webView?.url ?: url else url).split("/").last()}xxx;xxx$input") + }) .show() true } diff --git a/app/src/main/java/telegra/ph/Prefs.kt b/app/src/main/java/telegra/ph/Prefs.kt new file mode 100644 index 0000000..6da1b69 --- /dev/null +++ b/app/src/main/java/telegra/ph/Prefs.kt @@ -0,0 +1,16 @@ +package telegra.ph + +import android.content.Context +import android.preference.PreferenceManager + +fun Context.bookmarks(): MutableList = PreferenceManager.getDefaultSharedPreferences(this).getString("bookmarks", null)?.split("+++;+++")?.toMutableList() ?: mutableListOf("apixxx;xxxAPI Documentation") + +fun Context.addBookmark(entry: String) { + PreferenceManager.getDefaultSharedPreferences(this).edit().putString("bookmarks", bookmarks().apply { + add(entry) + }.joinToString(separator = "+++;+++")).apply() +} + +fun Context.deleteBookmark(path: String) { + PreferenceManager.getDefaultSharedPreferences(this).edit().putString("bookmarks", bookmarks().filter { !it.contains(path) }.joinToString(separator = "+++;+++")).apply() +} \ No newline at end of file diff --git a/app/src/main/res/menu/activity_main.xml b/app/src/main/res/menu/activity_main.xml index fc2f41a..def311a 100644 --- a/app/src/main/res/menu/activity_main.xml +++ b/app/src/main/res/menu/activity_main.xml @@ -2,8 +2,16 @@ + + How to use text formatting?You can use formatting like bold, italics and so on at least on Lollipop and above by double tapping the text.

The app only shows strange things!

It\'s not verified, that the app will work on devices with KitKat or lower. In Lollipop Google introduced a Chrome based and updatable WebView with more features and fixes. I\'m sorry! But in December \'16 Telegram will publish docs for the Telegraph API, so I\'ll be able to create a native app instead of a wrapper. Be patient!]]> - History + Bookmarks + Bookmark this + Create + Title? + Awesome Post #1 + Delete + Do you really want to delete this?