|
|
|
@ -172,7 +172,6 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
fun getCursor(): String {
|
|
|
|
|
Log.i(javaClass.simpleName,"delivering cursor: ${metaData.cursor}")
|
|
|
|
|
val cursor = JSONObject(JSONObject(metaData.cursor), arrayOf("ch", "line"))
|
|
|
|
|
Log.i(javaClass.simpleName,"delivering cursor: $cursor")
|
|
|
|
|
return cursor.toString()
|
|
|
|
@ -258,30 +257,18 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
super.onResume()
|
|
|
|
|
|
|
|
|
|
loadMetaFromSharedPrefs()
|
|
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
//if (contentResolver.getType(parse(intent.dataString))!!.split("/")[0] == "text" && intentScheme == "content") {
|
|
|
|
|
if (intent.data != null) {
|
|
|
|
|
if (contentResolver.getType(parse(intent.dataString))!!.split("/")[0] == "text") {
|
|
|
|
|
readFile(intent.data!!)
|
|
|
|
|
intent.data = null
|
|
|
|
|
Log.d(javaClass.simpleName,"Loading on resume from intent data: ${intent.data}")
|
|
|
|
|
} else {}
|
|
|
|
|
} else { // No start with intent data. Load previously used file
|
|
|
|
|
if (thisFileUri !== null) readFile(thisFileUri!!)
|
|
|
|
|
Log.d(javaClass.simpleName,"Loading on resume from thisFileUri: ${thisFileUri}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
webView.evaluateJavascript("onRead();") {}
|
|
|
|
|
if (thisFileUri !== null) {
|
|
|
|
|
readFile(thisFileUri!!)
|
|
|
|
|
Log.d(javaClass.simpleName,"Loading on resume from thisFileUri: ${thisFileUri}")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (metaData.metaData.get("url") !== null) {
|
|
|
|
|
val url = parse(metaData.metaData.get("url"))
|
|
|
|
|
deleteVisible = true
|
|
|
|
|
invalidateOptionsMenu()
|
|
|
|
|
val apiHost = url.scheme + "://" + url.host
|
|
|
|
|
Log.i(javaClass.simpleName, "Starting api controller for: $apiHost")
|
|
|
|
|
api = ghostAPI(applicationContext, apiHost)
|
|
|
|
|
}
|
|
|
|
|
if (metaData.metaData.get("url") !== null) {
|
|
|
|
|
val url = parse(metaData.metaData.get("url"))
|
|
|
|
|
deleteVisible = true
|
|
|
|
|
invalidateOptionsMenu()
|
|
|
|
|
val apiHost = url.scheme + "://" + url.host
|
|
|
|
|
Log.i(javaClass.simpleName, "Starting api controller for: $apiHost")
|
|
|
|
|
api = ghostAPI(applicationContext, apiHost)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
override fun onNewIntent(intent:Intent) {
|
|
|
|
@ -328,7 +315,6 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
if (intentScheme == "link" && uri.toString() !="null") {
|
|
|
|
|
mdToAppend += "[](${uri})\n"
|
|
|
|
|
webView.evaluateJavascript("onRead();"){}
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, null as CharSequence?)
|
|
|
|
|
}
|
|
|
|
|
if (intentScheme == "content") {
|
|
|
|
@ -336,12 +322,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
pushImage(uri)
|
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, null as Uri?)
|
|
|
|
|
} else if (mimeType == "text" && intent.data != null ) {
|
|
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
readFile(intent.data!!)
|
|
|
|
|
}
|
|
|
|
|
webView.evaluateJavascript("onRead();") {}
|
|
|
|
|
}
|
|
|
|
|
readFile(intent.data!!)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1050,6 +1031,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
Toast.LENGTH_LONG
|
|
|
|
|
).show()
|
|
|
|
|
})
|
|
|
|
|
return@withContext
|
|
|
|
|
}
|
|
|
|
|
catch (e: Exception) {
|
|
|
|
|
Log.d(javaClass.simpleName, e.stackTraceToString())
|
|
|
|
@ -1060,9 +1042,12 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
Toast.LENGTH_LONG
|
|
|
|
|
).show()
|
|
|
|
|
})
|
|
|
|
|
return@withContext
|
|
|
|
|
}
|
|
|
|
|
this@MainActivity.runOnUiThread({
|
|
|
|
|
val script = "easyMDE.codemirror.doc.setValue(`${mdeValue}`);"
|
|
|
|
|
val script = "easyMDE.codemirror.doc.setValue(`${mdeValue}`);" +
|
|
|
|
|
"easyMDE.codemirror.doc.setCursor(JSON.parse(`${JSONObject(JSONObject(metaData.cursor), arrayOf("ch", "line"))}`));" +
|
|
|
|
|
"pasteText();"
|
|
|
|
|
Log.d(javaClass.simpleName, "executing in webview:\n${script}")
|
|
|
|
|
webView.evaluateJavascript(script, {})
|
|
|
|
|
})
|
|
|
|
|