mirror of https://github.com/jlelse/teleposter
Author name
This commit is contained in:
parent
dcf355895e
commit
2cc73c979a
|
@ -19,8 +19,8 @@ class Api {
|
|||
}
|
||||
}
|
||||
|
||||
fun createPage(accessToken: String?, content: String?, title: String?, callback: (success: Boolean, Page?) -> Unit) {
|
||||
Bridge.get("${ApiBase}createPage?access_token=%s&title=%s&content=%s&return_content=true", accessToken, title, content).asString { response, s, bridgeException ->
|
||||
fun createPage(accessToken: String?, content: String?, title: String?, name: String?, callback: (success: Boolean, Page?) -> Unit) {
|
||||
Bridge.get("${ApiBase}createPage?access_token=%s&title=%s&author_name=%s&content=%s&return_content=true", accessToken, title, name, content).asString { response, s, bridgeException ->
|
||||
if (!s.isNullOrBlank() && bridgeException == null) try {
|
||||
callback(true, JSONObject(s).parsePageResponse())
|
||||
} catch (e: Exception) {
|
||||
|
@ -30,8 +30,8 @@ class Api {
|
|||
}
|
||||
}
|
||||
|
||||
fun editPage(accessToken: String?, path: String?, content: String?, title: String?, callback: (success: Boolean, Page?) -> Unit) {
|
||||
Bridge.get("${ApiBase}editPage/$path?access_token=%s&title=%s&content=%s&return_content=true", accessToken, title, content).asString { response, s, bridgeException ->
|
||||
fun editPage(accessToken: String?, path: String?, content: String?, title: String?, name: String?, callback: (success: Boolean, Page?) -> Unit) {
|
||||
Bridge.get("${ApiBase}editPage/$path?access_token=%s&title=%s&author_name=%s&content=%s&return_content=true", accessToken, title, name, content).asString { response, s, bridgeException ->
|
||||
if (!s.isNullOrBlank() && bridgeException == null) try {
|
||||
callback(true, JSONObject(s).parsePageResponse())
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -85,6 +85,7 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
|
|||
webView?.visibility = View.VISIBLE
|
||||
editor?.visibility = View.GONE
|
||||
currentPage = page
|
||||
webView?.clearHistory()
|
||||
// Show
|
||||
page?.let {
|
||||
var html = getString(R.string.viewer_html_head)
|
||||
|
@ -178,16 +179,21 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
|
|||
MaterialDialog.Builder(this)
|
||||
.title(R.string.title_question)
|
||||
.input(getString(R.string.title_hint), currentPage?.title ?: "", { dialog, title ->
|
||||
if (isEdit) Api().editPage(accessToken(), currentPage?.path, json, title.toString()) { success, page ->
|
||||
MaterialDialog.Builder(this)
|
||||
.title(R.string.name_question)
|
||||
.input(getString(R.string.name_hint), if (isEdit) currentPage?.author_name ?: authorName() ?: "" else authorName() ?: "", { dialog, name ->
|
||||
if (isEdit) Api().editPage(accessToken(), currentPage?.path, json, title.toString(), name.toString()) { success, page ->
|
||||
if (success) showPage(page)
|
||||
else showError()
|
||||
}
|
||||
else Api().createPage(accessToken(), json, title.toString()) { success, page ->
|
||||
else Api().createPage(accessToken(), json, title.toString(), name.toString()) { success, page ->
|
||||
if (success) showPage(page)
|
||||
else showError()
|
||||
}
|
||||
})
|
||||
.show()
|
||||
})
|
||||
.show()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
@ -20,3 +20,9 @@ fun Context.accessToken(): String? = PreferenceManager.getDefaultSharedPreferenc
|
|||
fun Context.saveAccessToken(token: String) {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putString("accessToken", token).apply()
|
||||
}
|
||||
|
||||
fun Context.authorName(): String? = PreferenceManager.getDefaultSharedPreferences(this).getString("authorName", null)
|
||||
|
||||
fun Context.saveAuthorName(name: String) {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putString("authorName", name).apply()
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
<string name="share">Share</string>
|
||||
<string name="help">Help</string>
|
||||
<string name="help_text">
|
||||
<![CDATA[<h3>Why can\'t I add images?</h3>Unfortunately I wasn\'t able to add the feature yet.<h3>Why can\'t I select headings?</h3>Same reasons as above, but you can do it manually via the code editor.<h3>Why can\'t I see all my published posts?</h3>That\'s coming soon!<h3>Why can\'t I login with my Telegram account?</h3>That\'s not possible!<h3>Why can\'t I add my name to the post?</h3>That\'s coming soon!<h3>Used libraries</h3><a href=\"https://github.com/afollestad/material-dialogs\">Material Dialogs</a>, <a href=\"https://github.com/afollestad/bridge\">Bridge</a>, <a href=\"https://github.com/delight-im/Android-AdvancedWebView\">AdvancedWebView</a><h3>About</h3>This app is made by <a href="https://jlelse.eu">Jan-Lukas Else</a> and it\'s code is published on <a href="https://github.com/jlelse/teleposter">Github</a>.]]></string>
|
||||
<![CDATA[<h3>Why can\'t I add images?</h3>Unfortunately I wasn\'t able to add the feature yet.<h3>Why can\'t I select headings?</h3>Same reasons as above, but you can do it manually via the code editor.<h3>Why can\'t I login with my Telegram account?</h3>That\'s not possible!<h3>Used libraries</h3><a href=\"https://github.com/afollestad/material-dialogs\">Material Dialogs</a>, <a href=\"https://github.com/afollestad/bridge\">Bridge</a>, <a href=\"https://github.com/delight-im/Android-AdvancedWebView\">AdvancedWebView</a><h3>About</h3>This app is made by <a href="https://jlelse.eu">Jan-Lukas Else</a> and it\'s code is published on <a href="https://github.com/jlelse/teleposter">Github</a>.]]></string>
|
||||
<string name="bookmarks">Bookmarks</string>
|
||||
<string name="bookmark_this">Bookmark this</string>
|
||||
<string name="create">Create</string>
|
||||
|
@ -23,4 +23,6 @@
|
|||
<![CDATA[<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js\"></script><script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script></body></html>]]>
|
||||
</string>
|
||||
<string name="published">Published posts</string>
|
||||
<string name="name_question">Your name?</string>
|
||||
<string name="name_hint">Awesome Writer</string>
|
||||
</resources>
|
Loading…
Reference in New Issue