mirror of https://github.com/jlelse/teleposter
Replaced History with Bookmarks
This commit is contained in:
parent
6ce9e5b7ef
commit
90d134dc70
|
@ -2,7 +2,9 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="telegra.ph">
|
package="telegra.ph">
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
|
<uses-feature
|
||||||
|
android:name="android.hardware.touchscreen"
|
||||||
|
android:required="false"/>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
@ -20,8 +22,10 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|
||||||
<category android:name="android.intent.category.BROWSABLE"/>
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
|
||||||
<data android:scheme="http"/>
|
<data android:scheme="http"/>
|
||||||
<data android:scheme="https"/>
|
<data android:scheme="https"/>
|
||||||
<data android:host="telegra.ph"/>
|
<data android:host="telegra.ph"/>
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package telegra.ph
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.preference.PreferenceManager
|
|
||||||
|
|
||||||
fun Context.getHistory() = PreferenceManager.getDefaultSharedPreferences(this).getStringSet("history", mutableSetOf<String>())
|
|
||||||
|
|
||||||
fun Context.addToHistory(entry: String) {
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putStringSet("history", getHistory().apply {
|
|
||||||
add(entry)
|
|
||||||
}).apply()
|
|
||||||
}
|
|
|
@ -35,11 +35,13 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
|
||||||
overScrollMode = View.OVER_SCROLL_NEVER
|
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())
|
loadPage(intent.dataString.split("/").last())
|
||||||
} else {
|
else loadEditor()
|
||||||
webView?.loadUrl(TELEGRAPH)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadEditor() {
|
||||||
|
webView?.loadUrl(TELEGRAPH)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadPage(path: String) {
|
private fun loadPage(path: String) {
|
||||||
|
@ -54,7 +56,6 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
|
||||||
html += htmlEnd
|
html += htmlEnd
|
||||||
webView?.loadDataWithBaseURL(it.url, html, "text/html; charset=UTF-8", null, null)
|
webView?.loadDataWithBaseURL(it.url, html, "text/html; charset=UTF-8", null, null)
|
||||||
url = it.url
|
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 {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.history -> {
|
R.id.create -> {
|
||||||
MaterialDialog.Builder(this)
|
loadEditor()
|
||||||
.title(R.string.history)
|
true
|
||||||
.items(getHistory().reversed().map { it.split("xxx;xxx")[1] })
|
|
||||||
.itemsCallback { materialDialog, view, i, charSequence ->
|
|
||||||
loadPage(getHistory().reversed().map { it.split("xxx;xxx")[0] }[i])
|
|
||||||
}
|
}
|
||||||
|
R.id.bookmarks -> {
|
||||||
|
MaterialDialog.Builder(this)
|
||||||
|
.title(R.string.bookmarks)
|
||||||
|
.items(bookmarks().reversed().map { it.split("xxx;xxx")[1] })
|
||||||
|
.itemsCallback { materialDialog, view, i, charSequence ->
|
||||||
|
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()
|
.show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package telegra.ph
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.preference.PreferenceManager
|
||||||
|
|
||||||
|
fun Context.bookmarks(): MutableList<String> = 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()
|
||||||
|
}
|
|
@ -2,8 +2,16 @@
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/history"
|
android:id="@+id/create"
|
||||||
android:title="@string/history"
|
android:title="@string/create"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/bookmarks"
|
||||||
|
android:title="@string/bookmarks"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/bookmark"
|
||||||
|
android:title="@string/bookmark_this"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/share"
|
android:id="@+id/share"
|
||||||
|
|
|
@ -5,5 +5,11 @@
|
||||||
<string name="help_text">
|
<string name="help_text">
|
||||||
<![CDATA[<h3>How to use text formatting?</h3>You can use formatting like <b>bold</b>, <i>italics</i> and so on at least on Lollipop and above by double tapping the text.<h3>The app only shows strange things!</h3>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!]]>
|
<![CDATA[<h3>How to use text formatting?</h3>You can use formatting like <b>bold</b>, <i>italics</i> and so on at least on Lollipop and above by double tapping the text.<h3>The app only shows strange things!</h3>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!]]>
|
||||||
</string>
|
</string>
|
||||||
<string name="history">History</string>
|
<string name="bookmarks">Bookmarks</string>
|
||||||
|
<string name="bookmark_this">Bookmark this</string>
|
||||||
|
<string name="create">Create</string>
|
||||||
|
<string name="title_question">Title?</string>
|
||||||
|
<string name="title_hint">Awesome Post #1</string>
|
||||||
|
<string name="delete">Delete</string>
|
||||||
|
<string name="delete_question">Do you really want to delete this?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue