toggle themes

hauntED
yova 3 months ago
parent 96c2fefd0d
commit 482c3e9756

@ -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, {})
})

@ -2,7 +2,6 @@ function onRead() {
easyMDE.codemirror.doc.setValue(Android.getValue())
easyMDE.codemirror.doc.markClean()
easyMDE.codemirror.focus()
console.log(Android.getCursor())
easyMDE.codemirror.doc.setCursor(JSON.parse(Android.getCursor()))
pasteText()
}
@ -79,6 +78,13 @@ function toggleBar() {
Android.toggleBar()
easyMDE.codemirror.focus()
}
themes = [ "solarized", "3024-night"]
i=1
function toggleTheme() {
easyMDE.codemirror.setOption("theme",themes[i])
i++
if (i>themes.length-1) i=0
}
const easyMDE = new EasyMDE({
spellChecker: false,
@ -110,24 +116,17 @@ const easyMDE = new EasyMDE({
],
toolbar: [
{
name: "day",
action: () => easyMDE.codemirror.setOption("theme","solarized"),
className: "fa fa-sun",
title: "Day Theme"
},
{
name: "night",
action: () => easyMDE.codemirror.setOption("theme","3024-night"),
name: "toggleTheme",
action: toggleTheme,
className: "fa fa-moon",
title: "Night Theme"
title: "Toggle Theme"
},
"guide",
{
name: "share",
action: shareText,
className: "fa fa-share-nodes",
title: "Share"
}, "undo",
},"strikethrough", "horizontal-rule","undo",
{
name: "preview",
action: myPreview,

Loading…
Cancel
Save