From 9f02934faf2d7a7762780a387998e87df15bbab2 Mon Sep 17 00:00:00 2001 From: yova Date: Wed, 31 Jan 2024 01:33:27 +0100 Subject: [PATCH] confirm push to ghost delete cached images on start --- .../java/org/wntr/mdeditor/MainActivity.kt | 65 +++++++++++-------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/wntr/mdeditor/MainActivity.kt b/app/src/main/java/org/wntr/mdeditor/MainActivity.kt index 7e84afb..0be57a1 100644 --- a/app/src/main/java/org/wntr/mdeditor/MainActivity.kt +++ b/app/src/main/java/org/wntr/mdeditor/MainActivity.kt @@ -143,7 +143,7 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - + supportActionBar!!.setDisplayShowTitleEnabled(false) deleteCache() @@ -409,34 +409,41 @@ class MainActivity : AppCompatActivity() { } R.id.push_ghost -> { - webView.evaluateJavascript("getHtml();", { - val msg = URLDecoder.decode(it.removeSurrounding("\"")) - if (metaData.metaData.get("url") !== null) { - CoroutineScope(Dispatchers.Main).launch { - withContext(Dispatchers.IO) { - if (metaData.getId() == null) { - this@MainActivity.runOnUiThread({ - Toast.makeText( - this@MainActivity, - "No ID for url in Metadata found. Deleted? Trying repost.", - Toast.LENGTH_LONG - ).show() - }) - sendPosting(html=msg, author = credManager.username) - } else { - Log.i(javaClass.simpleName,"posting $msg") - updatePost( - title = metaData.get("title") ?: getDisplayName(thisFileUri), - author = credManager.username, - html = msg, - id = metaData.getId()!! - ) + with(AlertDialog.Builder(this)){ + setTitle("Push to ghostCMS?") + setPositiveButton("Yes", { dialog, id -> + webView.evaluateJavascript("getHtml();", { + val msg = URLDecoder.decode(it.removeSurrounding("\"")) + if (metaData.metaData.get("url") !== null) { + CoroutineScope(Dispatchers.Main).launch { + withContext(Dispatchers.IO) { + if (metaData.getId() == null) { + this@MainActivity.runOnUiThread({ + Toast.makeText( + this@MainActivity, + "No ID for url in Metadata found. Deleted? Trying repost.", + Toast.LENGTH_LONG + ).show() + }) + sendPosting(html=msg, author = credManager.username) + } else { + Log.i(javaClass.simpleName,"posting $msg") + updatePost( + 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 -> { ghostSettings.launch(Intent(this, LoginActivity::class.java)) @@ -720,6 +727,7 @@ class MainActivity : AppCompatActivity() { try { val dir = File(cacheDir, "html") deleteDir(dir) + deleteDir(applicationContext.filesDir) } catch (e: java.lang.Exception) { e.printStackTrace() } @@ -1137,6 +1145,7 @@ class MainActivity : AppCompatActivity() { webView.evaluateJavascript(script, { thisFileUri = uri Log.d(javaClass.simpleName,"File read: ${thisFileUri}") + saveFile() }) webView.requestFocus() })