confirm push to ghost

delete cached images on start
hauntED
yova 4 months ago
parent da174106ee
commit 9f02934faf

@ -143,7 +143,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
supportActionBar!!.setDisplayShowTitleEnabled(false) supportActionBar!!.setDisplayShowTitleEnabled(false)
deleteCache() deleteCache()
@ -409,34 +409,41 @@ class MainActivity : AppCompatActivity() {
} }
R.id.push_ghost -> { R.id.push_ghost -> {
webView.evaluateJavascript("getHtml();", { with(AlertDialog.Builder(this)){
val msg = URLDecoder.decode(it.removeSurrounding("\"")) setTitle("Push to ghostCMS?")
if (metaData.metaData.get("url") !== null) { setPositiveButton("Yes", { dialog, id ->
CoroutineScope(Dispatchers.Main).launch { webView.evaluateJavascript("getHtml();", {
withContext(Dispatchers.IO) { val msg = URLDecoder.decode(it.removeSurrounding("\""))
if (metaData.getId() == null) { if (metaData.metaData.get("url") !== null) {
this@MainActivity.runOnUiThread({ CoroutineScope(Dispatchers.Main).launch {
Toast.makeText( withContext(Dispatchers.IO) {
this@MainActivity, if (metaData.getId() == null) {
"No ID for url in Metadata found. Deleted? Trying repost.", this@MainActivity.runOnUiThread({
Toast.LENGTH_LONG Toast.makeText(
).show() this@MainActivity,
}) "No ID for url in Metadata found. Deleted? Trying repost.",
sendPosting(html=msg, author = credManager.username) Toast.LENGTH_LONG
} else { ).show()
Log.i(javaClass.simpleName,"posting $msg") })
updatePost( sendPosting(html=msg, author = credManager.username)
title = metaData.get("title") ?: getDisplayName(thisFileUri), } else {
author = credManager.username, Log.i(javaClass.simpleName,"posting $msg")
html = msg, updatePost(
id = metaData.getId()!! title = metaData.get("title") ?: getDisplayName(thisFileUri),
) author = credManager.username,
html = msg,
id = metaData.getId()!!
)
}
}
} }
} } else
} shareGhost(msg, ::sendPost)
} else })
shareGhost(msg, ::sendPost) })
}) setNeutralButton("No", { dialog, id -> })
show()
}
} }
R.id.settings -> { R.id.settings -> {
ghostSettings.launch(Intent(this, LoginActivity::class.java)) ghostSettings.launch(Intent(this, LoginActivity::class.java))
@ -720,6 +727,7 @@ class MainActivity : AppCompatActivity() {
try { try {
val dir = File(cacheDir, "html") val dir = File(cacheDir, "html")
deleteDir(dir) deleteDir(dir)
deleteDir(applicationContext.filesDir)
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
e.printStackTrace() e.printStackTrace()
} }
@ -1137,6 +1145,7 @@ class MainActivity : AppCompatActivity() {
webView.evaluateJavascript(script, { webView.evaluateJavascript(script, {
thisFileUri = uri thisFileUri = uri
Log.d(javaClass.simpleName,"File read: ${thisFileUri}") Log.d(javaClass.simpleName,"File read: ${thisFileUri}")
saveFile()
}) })
webView.requestFocus() webView.requestFocus()
}) })

Loading…
Cancel
Save