|
|
|
@ -2,6 +2,7 @@ package org.wntr.mdeditor
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.app.AlertDialog
|
|
|
|
|
import android.content.ActivityNotFoundException
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
@ -186,33 +187,20 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
Log.i(javaClass.simpleName, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
fun triggerNewBuffer(value: String) {
|
|
|
|
|
saveFile()
|
|
|
|
|
mdeValue = value
|
|
|
|
|
metaData = mdMeta()
|
|
|
|
|
selectFileForSaveAs()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
fun triggerOpenFile() {
|
|
|
|
|
openFile()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
fun triggerSaveFile(value: String) {
|
|
|
|
|
mdeValue = value
|
|
|
|
|
saveFile()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
/*@JavascriptInterface
|
|
|
|
|
fun getHeight(): Int {
|
|
|
|
|
val displayMetrics = DisplayMetrics()
|
|
|
|
|
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
|
|
|
|
val height = displayMetrics.heightPixels
|
|
|
|
|
Log.i(javaClass.simpleName, "display is $height pixels high.")
|
|
|
|
|
return height
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
fun refresh() {
|
|
|
|
@ -317,9 +305,6 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
webView.evaluateJavascript(script , {
|
|
|
|
|
if (it == "false" && thisFileUri != null) {
|
|
|
|
|
saveFile()
|
|
|
|
|
this@MainActivity.runOnUiThread {
|
|
|
|
|
webView.evaluateJavascript("easyMDE.codemirror.doc.markClean();", {})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -462,7 +447,6 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
} else
|
|
|
|
|
shareGhost(msg, ::sendPost)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
R.id.settings -> {
|
|
|
|
|
ghostSettings.launch(Intent(this, LoginActivity::class.java))
|
|
|
|
@ -1003,6 +987,9 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
Log.d(javaClass.simpleName, "File saved: ${thisFileUri}")
|
|
|
|
|
textFile.close()
|
|
|
|
|
this@MainActivity.runOnUiThread {
|
|
|
|
|
webView.evaluateJavascript("easyMDE.codemirror.doc.markClean();", {})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
@ -1132,15 +1119,16 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
"easyMDE.codemirror.doc.markClean();" +
|
|
|
|
|
"easyMDE.codemirror.focus();" +
|
|
|
|
|
"easyMDE.codemirror.doc.setCursor(JSON.parse(`${metaData.cursor}`));" +
|
|
|
|
|
"pasteText();}"
|
|
|
|
|
"pasteText();" +
|
|
|
|
|
"easyMDE.updateStatusBar(\"displayName\",\"${getDisplayName(uri)}\");}"
|
|
|
|
|
|
|
|
|
|
Log.d(javaClass.simpleName, "executing in webview:\n${script}")
|
|
|
|
|
webView.evaluateJavascript(script, {
|
|
|
|
|
thisFileUri = uri
|
|
|
|
|
Log.d(javaClass.simpleName,"File read: ${thisFileUri}")
|
|
|
|
|
})
|
|
|
|
|
webView.requestFocus()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1160,7 +1148,15 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
val uriString = prefs.getString("lastFile", "noLastFile")
|
|
|
|
|
|
|
|
|
|
if (uriString == "noLastFile") {
|
|
|
|
|
with(AlertDialog.Builder(this)){
|
|
|
|
|
setPositiveButton("Open", { dialog, id ->
|
|
|
|
|
openFile()
|
|
|
|
|
})
|
|
|
|
|
setNeutralButton("New", { dialog, id ->
|
|
|
|
|
selectFileForSaveAs()
|
|
|
|
|
})
|
|
|
|
|
show()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
thisFileUri = parse(uriString)
|
|
|
|
|
metaData.cursor = prefs.getString("cursor", "nocursor") ?: "{ line: 0, ch: 0, sticky: null }"
|
|
|
|
|