revisit Actionbar and File IO

add autosave  timer
hauntED
yova 4 months ago
parent 4c807243eb
commit 182122babf

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<targetSelectedWithDropDown> <runningDeviceTargetSelectedWithDropDown>
<Target> <Target>
<type value="QUICK_BOOT_TARGET" /> <type value="RUNNING_DEVICE_TARGET" />
<deviceKey> <deviceKey>
<Key> <Key>
<type value="VIRTUAL_DEVICE_PATH" /> <type value="SERIAL_NUMBER" />
<value value="$USER_HOME$/.android/avd/Pixel_5_API_30_2.avd" /> <value value="10.0.0.10:5555" />
</Key> </Key>
</deviceKey> </deviceKey>
</Target> </Target>
</targetSelectedWithDropDown> </runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-01-15T15:22:12.274341182Z" /> <timeTargetWasSelectedWithDropDown value="2024-01-23T18:08:32.458084060Z" />
</component> </component>
</project> </project>

@ -48,6 +48,7 @@ import java.io.InputStreamReader
import java.lang.Thread.sleep import java.lang.Thread.sleep
import java.net.URLDecoder import java.net.URLDecoder
import java.time.Instant import java.time.Instant
import kotlin.concurrent.fixedRateTimer
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@ -62,8 +63,8 @@ class MainActivity : AppCompatActivity() {
var metaData = mdMeta() var metaData = mdMeta()
var mdToAppend: String = "" var mdToAppend: String = ""
var thisFileUri: Uri? = null var thisFileUri: Uri? = null
var truncate = false
lateinit var tempFile: File lateinit var tempFile: File
var emptyFile = false
lateinit var pickMultipleVisualMedia: ActivityResultLauncher<PickVisualMediaRequest> lateinit var pickMultipleVisualMedia: ActivityResultLauncher<PickVisualMediaRequest>
lateinit var ghostSettings: ActivityResultLauncher<Intent> lateinit var ghostSettings: ActivityResultLauncher<Intent>
lateinit var ghostMetaData: ActivityResultLauncher<Intent> lateinit var ghostMetaData: ActivityResultLauncher<Intent>
@ -72,6 +73,7 @@ class MainActivity : AppCompatActivity() {
var ghostConnection = false var ghostConnection = false
lateinit var credManager: CredentialManager lateinit var credManager: CredentialManager
var intentScheme = "none" var intentScheme = "none"
var lastSaved = Instant.now().toEpochMilli()
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -120,7 +122,7 @@ class MainActivity : AppCompatActivity() {
@JavascriptInterface @JavascriptInterface
fun triggerOpenFile() { fun triggerOpenFile() {
openFile(thisFileUri!!) openFile()
} }
@JavascriptInterface @JavascriptInterface
@ -145,7 +147,7 @@ class MainActivity : AppCompatActivity() {
@JavascriptInterface @JavascriptInterface
fun triggerDisplayName(): String { fun triggerDisplayName(): String {
return getDisplayName() return getDisplayName(thisFileUri)
} }
@JavascriptInterface @JavascriptInterface
@ -172,6 +174,14 @@ class MainActivity : AppCompatActivity() {
Log.i(javaClass.simpleName,"delivering cursor: $cursor") Log.i(javaClass.simpleName,"delivering cursor: $cursor")
return cursor.toString() return cursor.toString()
} }
@JavascriptInterface
fun toggleBar() {
this@MainActivity.runOnUiThread({
if (supportActionBar!!.isShowing) supportActionBar!!.hide()
else supportActionBar!!.show()
})
}
} }
webView.addJavascriptInterface(jsi, "Android") webView.addJavascriptInterface(jsi, "Android")
@ -200,6 +210,18 @@ class MainActivity : AppCompatActivity() {
ghostMetaData = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { ghostMetaData = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
saveFile() saveFile()
} }
fixedRateTimer("timer",true,0,5000){
this@MainActivity.runOnUiThread {
webView.evaluateJavascript("easyMDE.codemirror.doc.isClean();", {
if (it == "false" && thisFileUri != null) {
saveFile()
this@MainActivity.runOnUiThread {
webView.evaluateJavascript("easyMDE.codemirror.doc.markClean();", {})
}
}
})
}
}
} }
override fun onResume() { override fun onResume() {
@ -305,6 +327,20 @@ class MainActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.itemId val id = item.itemId
when (id) { when (id) {
R.id.new_file -> {
truncate = true
selectFileForSaveAs()
}
R.id.open_file -> {
openFile()
}
R.id.save_file -> {
saveFile()
selectFileForSaveAs()
}
R.id.push_ghost -> { R.id.push_ghost -> {
webView.evaluateJavascript("getHtml();", { webView.evaluateJavascript("getHtml();", {
val msg = URLDecoder.decode(it.removeSurrounding("\"")) val msg = URLDecoder.decode(it.removeSurrounding("\""))
@ -323,7 +359,7 @@ class MainActivity : AppCompatActivity() {
} else { } else {
Log.i(javaClass.simpleName,"posting $msg") Log.i(javaClass.simpleName,"posting $msg")
updatePost( updatePost(
title = metaData.get("title") ?: getDisplayName(), title = metaData.get("title") ?: getDisplayName(thisFileUri),
author = credManager.username, author = credManager.username,
html = msg, html = msg,
id = metaData.getId()!! id = metaData.getId()!!
@ -514,7 +550,7 @@ class MainActivity : AppCompatActivity() {
} }
fun sendPosting(html: String, author: String): retrofit2.Response<Any> { fun sendPosting(html: String, author: String): retrofit2.Response<Any> {
val title = metaData.get("title") ?: "test" //getDisplayName() val title = metaData.get("title") ?: "test"
val post = sendPost(title, updated_at = Instant.now().toString(), authors = listOf(author), html, feature_image = metaData.get("feature_image")) val post = sendPost(title, updated_at = Instant.now().toString(), authors = listOf(author), html, feature_image = metaData.get("feature_image"))
val postings = sendPostList(listOf(post)) val postings = sendPostList(listOf(post))
var response: retrofit2.Response<posts> = retrofit2.Response.error( var response: retrofit2.Response<posts> = retrofit2.Response.error(
@ -690,33 +726,33 @@ class MainActivity : AppCompatActivity() {
// Create an image file name // Create an image file name
val storageDir = File(cacheDir, "html") val storageDir = File(cacheDir, "html")
storageDir.mkdir() storageDir.mkdir()
tempFile = File(storageDir.path + "/${getDisplayName().split(".")[0]}.html") tempFile = File(storageDir.path + "/${getDisplayName(thisFileUri).split(".")[0]}.html")
if (tempFile.exists()) tempFile.delete() if (tempFile.exists()) tempFile.delete()
tempFile.createNewFile() tempFile.createNewFile()
} }
fun openFile(uri: Uri) { fun openFile() {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri) putExtra(DocumentsContract.EXTRA_INITIAL_URI, thisFileUri)
type = "text/*" type = "text/*"
getDisplayName().apply { putExtra(Intent.EXTRA_TITLE, getDisplayName()) } getDisplayName(thisFileUri).apply { putExtra(Intent.EXTRA_TITLE, getDisplayName(
thisFileUri)) }
addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
} }
startActivityForResult(intent, OPEN_FILE) startActivityForResult(intent, OPEN_FILE)
Log.i(javaClass.simpleName, "Buffer gelesen")
} }
@SuppressLint("Range") @SuppressLint("Range")
fun getDisplayName(): String { fun getDisplayName(uri: Uri?): String {
// via: https://stackoverflow.com/questions/5568874/how-to-extract-the-file-name-from-uri-returned-from-intent-action-get-content // via: https://stackoverflow.com/questions/5568874/how-to-extract-the-file-name-from-uri-returned-from-intent-action-get-content
var result: String? = null; var result: String? = null;
if (thisFileUri == null) return "hauntED.md" if (uri == null) return "hauntED.md"
if (thisFileUri!!.getScheme().equals("content")) { if (uri!!.getScheme().equals("content")) {
val cursor = getContentResolver().query(thisFileUri!!, null, null, null, null); val cursor = getContentResolver().query(uri!!, null, null, null, null);
try { try {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
@ -726,7 +762,7 @@ class MainActivity : AppCompatActivity() {
} }
} }
if (result == null) { if (result == null) {
result = thisFileUri!!.getPath(); result = uri!!.getPath();
val cut = result!!.lastIndexOf('/'); val cut = result!!.lastIndexOf('/');
if (cut != -1) { if (cut != -1) {
result = result.substring(cut + 1); result = result.substring(cut + 1);
@ -739,7 +775,7 @@ class MainActivity : AppCompatActivity() {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply { val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "text/*" type = "text/*"
putExtra(Intent.EXTRA_TITLE, getDisplayName()) putExtra(Intent.EXTRA_TITLE, getDisplayName(thisFileUri))
addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
@ -785,11 +821,9 @@ class MainActivity : AppCompatActivity() {
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
) )
thisFileUri = uri Log.d(javaClass.simpleName, "Saving to: ${getDisplayName(thisFileUri)}\n${getDisplayName(uri)}")
if (getDisplayName(thisFileUri) + " (1)" != getDisplayName(uri)) thisFileUri = uri
saveAs() saveAs()
webView.evaluateJavascript("easyMDE.codemirror.focus()", ValueCallback<String>() {})
Log.i(javaClass.simpleName, "file newly written")
} }
} else if (requestCode == OPEN_FILE && resultCode == Activity.RESULT_OK) { } else if (requestCode == OPEN_FILE && resultCode == Activity.RESULT_OK) {
resultData?.data?.also { uri -> resultData?.data?.also { uri ->
@ -797,8 +831,7 @@ class MainActivity : AppCompatActivity() {
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION and Intent.FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION and Intent.FLAG_GRANT_WRITE_URI_PERMISSION
) )
thisFileUri = uri readFile(uri)
saveMetaToSharedPrefs()
if (metaData.metaData.get("url") == null) { if (metaData.metaData.get("url") == null) {
deleteVisible = false deleteVisible = false
@ -811,12 +844,8 @@ class MainActivity : AppCompatActivity() {
} }
} }
fun getFileContents(): String { fun saveFile() {
return metaData.toString() + mdeValue if (thisFileUri == null) return
}
fun saveFile(): Boolean {
if (thisFileUri == null) return false
lateinit var textFile: ParcelFileDescriptor lateinit var textFile: ParcelFileDescriptor
try { try {
@ -835,7 +864,7 @@ class MainActivity : AppCompatActivity() {
).show() ).show()
} }
) )
return false return
// TODO: implement workaround for this bug. See: https://stackoverflow.com/q/69248596 // TODO: implement workaround for this bug. See: https://stackoverflow.com/q/69248596
} catch (e: java.io.FileNotFoundException) { } catch (e: java.io.FileNotFoundException) {
Log.d(javaClass.simpleName, "File not found. Deleted while loaded?\n${e.stackTraceToString()}") Log.d(javaClass.simpleName, "File not found. Deleted while loaded?\n${e.stackTraceToString()}")
@ -849,7 +878,7 @@ class MainActivity : AppCompatActivity() {
} }
) )
selectFileForSaveAs() selectFileForSaveAs()
return false return
} }
catch (e: Exception) { catch (e: Exception) {
@ -863,77 +892,80 @@ class MainActivity : AppCompatActivity() {
).show() ).show()
} }
) )
return false return
}
/* This block is currently actually not needed as the change logic is made in js */
//TODO: Rework this for change check on network file provider
Log.d(
javaClass.simpleName,
"Size in cache: ${mdeValue.toByteArray().size} Size on disk: ${textFile.statSize}"
)
if (getFileContents().length.toLong() == textFile.statSize) {
Log.d(javaClass.simpleName, "No change on disk, file not saved.")
return false
} }
try { try {
contentResolver.openFileDescriptor(thisFileUri!!, "wt")?.use { this. runOnUiThread({
FileOutputStream(it.fileDescriptor).use { webView.evaluateJavascript("getValue();") {
it.write(getFileContents().toByteArray()) mdeValue =
metaData.toString() + URLDecoder.decode(it.removeSurrounding("\""))
if (mdeValue.length.toLong() == textFile.statSize) {
Log.d(javaClass.simpleName, "No change on disk, file not saved.")
return@evaluateJavascript
}
contentResolver.openFileDescriptor(thisFileUri!!, "wt")?.use {
FileOutputStream(it.fileDescriptor).use {
it.write(mdeValue.toByteArray())
}
}
Log.d(javaClass.simpleName, "File saved: ${thisFileUri}")
Toast.makeText(
this,
"File saved.",
Toast.LENGTH_SHORT
).show()
textFile.close()
} }
} })
} catch (e: Exception) { } catch (e: Exception) {
Toast.makeText( Toast.makeText(
this, this,
"Error during writing.\n$e", "Error during writing.\n$e",
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
return false return
} }
Log.d(javaClass.simpleName, "File saved: ${thisFileUri}")
this.runOnUiThread({
Toast.makeText(
this,
"File saved.",
Toast.LENGTH_SHORT
).show()
})
textFile.close()
return true
} }
private fun saveAs(): Boolean { private fun saveAs() {
lateinit var textFile: ParcelFileDescriptor
try { try {
textFile = contentResolver.openFileDescriptor(thisFileUri!!, "w")!! lateinit var textFile: ParcelFileDescriptor
textFile.checkError() try {
} catch (e: Exception) { textFile = contentResolver.openFileDescriptor(thisFileUri!!, "w")!!
textFile.checkError()
} catch (e: Exception) {
Toast.makeText(
this,
"Problem with accessing file\n$e",
Toast.LENGTH_LONG
).show()
return
}
if (truncate) {
mdeValue = ""
truncate = false
}
FileOutputStream(textFile.fileDescriptor).use {
it.write(mdeValue.toByteArray())
}
Toast.makeText( Toast.makeText(
this, this,
"Problem with accessing file\n$e", "File saved.",
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
return false Log.i(javaClass.simpleName, "file newly written")
} webView.evaluateJavascript("onRead();", ValueCallback<String>() {})
try {
FileOutputStream(textFile.fileDescriptor).use { textFile.close()
it.write(getFileContents().toByteArray()) saveMetaToSharedPrefs()
}
} catch (e: Exception) { } catch (e: Exception) {
Toast.makeText( Toast.makeText(
this, this,
"Error during writing.\n$e", "Error during writing.\n$e",
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
return false
} }
Toast.makeText(
this,
"File saved.",
Toast.LENGTH_LONG
).show()
textFile.close()
saveMetaToSharedPrefs()
return true
} }
@Throws(IOException::class) @Throws(IOException::class)
@ -962,10 +994,6 @@ class MainActivity : AppCompatActivity() {
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
}) })
/*
openFile(uri)
return false
*/
} }
try { try {
contentResolver.openInputStream(uri)?.use { inputStream -> contentResolver.openInputStream(uri)?.use { inputStream ->
@ -1004,9 +1032,11 @@ class MainActivity : AppCompatActivity() {
}) })
return false return false
} }
thisFileUri = uri thisFileUri = uri
saveMetaToSharedPrefs() saveMetaToSharedPrefs()
this.runOnUiThread({
webView.evaluateJavascript("onRead();", {})
})
return true return true
} }
@ -1035,7 +1065,7 @@ class MainActivity : AppCompatActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
/*outState.putString("test", "onSaveInstanceState-String")*/ /*outState.putString("test", "onSaveInstanceState-String")*/
webView.evaluateJavascript("saveFile();", ValueCallback<String>() {}) saveFile()
webView.evaluateJavascript("easyMDE.codemirror.doc.getCursor();") { webView.evaluateJavascript("easyMDE.codemirror.doc.getCursor();") {
metaData.cursor=it metaData.cursor=it
Log.i(javaClass.simpleName,"Cursor: $it") Log.i(javaClass.simpleName,"Cursor: $it")

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -14,7 +14,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constrainedHeight="true" app:layout_constrainedHeight="true"
tools:context=".MainActivity"/> tools:context=".MainActivity"/>
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
@ -22,9 +22,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:elevation="4dp" android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@android:color/transparent" app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -1,19 +1,31 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/new_file"
android:title="New File"
android:icon="@android:drawable/ic_menu_add"
app:showAsAction="always" />
<item android:id="@+id/open_file"
android:title="Open File"
android:icon="@drawable/ic_menu_archive"
app:showAsAction="always" />
<item android:id="@+id/save_file"
android:title="Save File"
android:icon="@android:drawable/ic_menu_save"
app:showAsAction="always" />
<item android:id="@+id/push_ghost" <item android:id="@+id/push_ghost"
android:title="Push to ghost" android:title="Push to ghost"
android:icon="@android:drawable/ic_menu_upload" android:icon="@android:drawable/ic_menu_upload"
app:showAsAction="never" /> app:showAsAction="always" />
<item android:id="@+id/settings" <item android:id="@+id/settings"
android:title="Settings" android:title="Settings"
android:icon="@android:drawable/ic_menu_directions" android:icon="@android:drawable/ic_menu_preferences"
app:showAsAction="never" /> app:showAsAction="always" />
<item android:id="@+id/image" <item android:id="@+id/image"
android:title="Image" android:title="Image"
android:icon="@android:drawable/ic_menu_send" android:icon="@android:drawable/ic_menu_gallery"
app:showAsAction="never"/> app:showAsAction="always"/>
<item android:id="@+id/metadata" <item android:id="@+id/metadata"
android:title="Metadata" android:title="Metadata"
android:icon="@android:drawable/ic_menu_set_as" android:icon="@android:drawable/ic_menu_more"
app:showAsAction="never"/> app:showAsAction="always"/>
</menu> </menu>

@ -22,14 +22,13 @@ function openFile() {
saveFile() saveFile()
Android.triggerOpenFile() Android.triggerOpenFile()
onRead() onRead()
easyMDE.codemirror.doc.markClean()
} }
function dispatchCut() { function dispatchCut() {
console.log("dispatch cut") console.log("dispatch cut")
easyMDE.codemirror.getTextArea().dispatchEvent(new Event("cut")) easyMDE.codemirror.getTextArea().dispatchEvent(new Event("cut"))
} }
function getValue() { function getValue() {
return easyMDE.value() return encodeURIComponent(easyMDE.value())
} }
function myPreview() { function myPreview() {
saveFile() saveFile()
@ -48,13 +47,6 @@ function shareText() {
Android.triggerShare(easyMDE.markdown(easyMDE.codemirror.doc.getValue())) Android.triggerShare(easyMDE.markdown(easyMDE.codemirror.doc.getValue()))
} }
function shareGhostText() {
saveFile()
if (confirm('Are you sure you want to publish this?')) {
Android.triggerGhost(easyMDE.markdown(easyMDE.codemirror.doc.getValue()))
}
}
function getHtml() { function getHtml() {
return encodeURIComponent(easyMDE.markdown(easyMDE.codemirror.doc.getValue())) return encodeURIComponent(easyMDE.markdown(easyMDE.codemirror.doc.getValue()))
} }
@ -67,7 +59,6 @@ function appendText() {
} }
} }
function pasteText() { function pasteText() {
data = new DataTransfer() data = new DataTransfer()
data.setData("text/plain", Android.getMdToAppend()) data.setData("text/plain", Android.getMdToAppend())
@ -77,6 +68,10 @@ function pasteText() {
document.getElementsByClassName("CodeMirror-scroll")[0].dispatchEvent(event); document.getElementsByClassName("CodeMirror-scroll")[0].dispatchEvent(event);
saveFile() saveFile()
} }
function toggleBar() {
Android.toggleBar()
easyMDE.codemirror.focus()
}
const easyMDE = new EasyMDE({ const easyMDE = new EasyMDE({
spellChecker: false, spellChecker: false,
@ -108,66 +103,23 @@ const easyMDE = new EasyMDE({
], ],
toolbar: [ toolbar: [
{ {
name: "more", name: "day",
className: "fa-solid fa-angles-down", action: () => easyMDE.codemirror.setOption("theme","solarized"),
title: "more", className: "fa fa-sun",
children: [ title: "Day Theme"
{
name: "saveAs",
action: saveAs,
className: "fa fa-star",
title: "saveAs"
},
{
name: "new",
action: blankBuffer,
className: "fa fa-file",
title: "New"
},
/* {
name: "refresh",
action: refresh,
className: "fa fa-refresh",
title: "Refresh"
},*/
{
name: "day",
action: () => easyMDE.codemirror.setOption("theme","solarized"),
className: "fa fa-sun",
title: "Day Theme"
},
{
name: "night",
action: () => easyMDE.codemirror.setOption("theme","3024-night"),
className: "fa fa-moon",
title: "Night Theme"
},
"guide"
]
},
{
name: "save",
action: saveFile,
className: "fa fa-save",
title: "Save"
}, },
{ {
name: "open", name: "night",
action: openFile, action: () => easyMDE.codemirror.setOption("theme","3024-night"),
className: "fa-regular fa-folder-open", className: "fa fa-moon",
title: "Open" title: "Night Theme"
}, },
"guide",
{ {
name: "share", name: "share",
action: shareText, action: shareText,
className: "fa fa-share-nodes", className: "fa fa-share-nodes",
title: "Share" title: "Share"
},
{
name: "shareGhost",
action: shareGhostText,
className: "fa fa-ghost",
title: "Share Ghost"
}, "undo", }, "undo",
{ {
name: "preview", name: "preview",
@ -176,7 +128,13 @@ const easyMDE = new EasyMDE({
title: "Preview", title: "Preview",
noDisable: true noDisable: true
},"redo", },"redo",
"bold", "italic","link","code" "bold", "italic","link","code",
{
name: "toggle",
action: toggleBar,
className: "fa fa-expand",
title: "Toggle Bar",
}
] ]
}); });
onRead(); onRead();
Loading…
Cancel
Save