diff --git a/app/src/main/java/telegra/ph/Api.kt b/app/src/main/java/telegra/ph/Api.kt index f77d010..c5173e6 100644 --- a/app/src/main/java/telegra/ph/Api.kt +++ b/app/src/main/java/telegra/ph/Api.kt @@ -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) { diff --git a/app/src/main/java/telegra/ph/MainActivity.kt b/app/src/main/java/telegra/ph/MainActivity.kt index 8220ae6..483a85b 100644 --- a/app/src/main/java/telegra/ph/MainActivity.kt +++ b/app/src/main/java/telegra/ph/MainActivity.kt @@ -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,14 +179,19 @@ 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 -> - if (success) showPage(page) - else showError() - } - else Api().createPage(accessToken(), json, title.toString()) { success, page -> - if (success) showPage(page) - else showError() - } + 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(), name.toString()) { success, page -> + if (success) showPage(page) + else showError() + } + }) + .show() }) .show() } diff --git a/app/src/main/java/telegra/ph/Prefs.kt b/app/src/main/java/telegra/ph/Prefs.kt index 6e74809..1e24638 100644 --- a/app/src/main/java/telegra/ph/Prefs.kt +++ b/app/src/main/java/telegra/ph/Prefs.kt @@ -19,4 +19,10 @@ 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() } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c37019..645acae 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,7 +3,7 @@ Share Help - Why can\'t I add images?Unfortunately I wasn\'t able to add the feature yet.

Why can\'t I select headings?

Same reasons as above, but you can do it manually via the code editor.

Why can\'t I see all my published posts?

That\'s coming soon!

Why can\'t I login with my Telegram account?

That\'s not possible!

Why can\'t I add my name to the post?

That\'s coming soon!

Used libraries

Material Dialogs, Bridge, AdvancedWebView

About

This app is made by Jan-Lukas Else and it\'s code is published on Github.]]>
+ Why can\'t I add images?Unfortunately I wasn\'t able to add the feature yet.

Why can\'t I select headings?

Same reasons as above, but you can do it manually via the code editor.

Why can\'t I login with my Telegram account?

That\'s not possible!

Used libraries

Material Dialogs, Bridge, AdvancedWebView

About

This app is made by Jan-Lukas Else and it\'s code is published on Github.]]> Bookmarks Bookmark this Create @@ -23,4 +23,6 @@ ]]> Published posts - + Your name? + Awesome Writer + \ No newline at end of file