|
|
|
@ -7,6 +7,7 @@ import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import android.net.Uri.parse
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.os.ParcelFileDescriptor
|
|
|
|
|
import android.provider.DocumentsContract
|
|
|
|
@ -16,6 +17,8 @@ import android.util.Log
|
|
|
|
|
import android.view.Menu
|
|
|
|
|
import android.view.Menu.NONE
|
|
|
|
|
import android.view.MenuItem
|
|
|
|
|
import android.view.WindowInsets
|
|
|
|
|
import android.view.WindowManager
|
|
|
|
|
import android.webkit.ConsoleMessage
|
|
|
|
|
import android.webkit.JavascriptInterface
|
|
|
|
|
import android.webkit.ValueCallback
|
|
|
|
@ -175,11 +178,38 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
return cursor.toString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
fun isFullscreen() : Boolean{
|
|
|
|
|
return supportActionBar!!.isShowing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
fun toggleBar() {
|
|
|
|
|
this@MainActivity.runOnUiThread({
|
|
|
|
|
if (supportActionBar!!.isShowing) supportActionBar!!.hide()
|
|
|
|
|
else supportActionBar!!.show()
|
|
|
|
|
if (supportActionBar!!.isShowing) {
|
|
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
|
|
window.insetsController?.hide(WindowInsets.Type.statusBars())
|
|
|
|
|
} else {
|
|
|
|
|
window.setFlags(
|
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
supportActionBar!!.hide()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
|
|
window.insetsController?.show(WindowInsets.Type.statusBars())
|
|
|
|
|
} else {
|
|
|
|
|
window.setFlags(
|
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
supportActionBar!!.show()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -235,9 +265,11 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
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();") {}
|
|
|
|
@ -281,7 +313,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Log.i(javaClass.simpleName,"Uri: $uri")
|
|
|
|
|
Log.i(javaClass.simpleName,"Got a new intent with URI: $uri")
|
|
|
|
|
if (uri != null && uri.toString()!="null") {
|
|
|
|
|
intentScheme = uri.scheme!!
|
|
|
|
|
if (intentScheme == "content") {
|
|
|
|
@ -831,8 +863,8 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
uri,
|
|
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION and Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
|
|
|
|
)
|
|
|
|
|
readFile(uri)
|
|
|
|
|
|
|
|
|
|
thisFileUri = uri
|
|
|
|
|
saveMetaToSharedPrefs()
|
|
|
|
|
if (metaData.metaData.get("url") == null) {
|
|
|
|
|
deleteVisible = false
|
|
|
|
|
invalidateOptionsMenu()
|
|
|
|
@ -990,9 +1022,9 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
).show()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
try {
|
|
|
|
|
contentResolver.openInputStream(uri)?.use { inputStream ->
|
|
|
|
|
BufferedReader(InputStreamReader(inputStream)).use { reader ->
|
|
|
|
|
var i = ""
|
|
|
|
@ -1003,39 +1035,42 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
i += line + '\n'
|
|
|
|
|
line = reader.readLine()
|
|
|
|
|
}
|
|
|
|
|
mdeValue = metaData.extractMetadataFromMarkdown(i)
|
|
|
|
|
}
|
|
|
|
|
mdeValue = metaData.extractMetadataFromMarkdown(i)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (e: java.io.FileNotFoundException) {
|
|
|
|
|
Log.d(javaClass.simpleName, "File not found during reading:\n${e.stackTraceToString()}")
|
|
|
|
|
this@MainActivity.runOnUiThread({
|
|
|
|
|
selectFileForSaveAs()
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
this@MainActivity,
|
|
|
|
|
"File not found during reading.\n$e",
|
|
|
|
|
Toast.LENGTH_LONG
|
|
|
|
|
).show()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
catch (e: Exception) {
|
|
|
|
|
Log.d(javaClass.simpleName, e.stackTraceToString())
|
|
|
|
|
this@MainActivity.runOnUiThread({
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
this@MainActivity,
|
|
|
|
|
"Error during reading.\n$e",
|
|
|
|
|
Toast.LENGTH_LONG
|
|
|
|
|
).show()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this@MainActivity.runOnUiThread({
|
|
|
|
|
val script = "easyMDE.codemirror.doc.setValue(`${mdeValue}`);"
|
|
|
|
|
Log.d(javaClass.simpleName, "executing in webview:\n${script}")
|
|
|
|
|
webView.evaluateJavascript(script, {})
|
|
|
|
|
})
|
|
|
|
|
thisFileUri = uri
|
|
|
|
|
saveMetaToSharedPrefs()
|
|
|
|
|
Log.d(javaClass.simpleName,"File read: ${thisFileUri}")
|
|
|
|
|
}
|
|
|
|
|
} catch (e: java.io.FileNotFoundException) {
|
|
|
|
|
Log.d(javaClass.simpleName, "File not found during reading:\n${e.stackTraceToString()}")
|
|
|
|
|
this.runOnUiThread({
|
|
|
|
|
selectFileForSaveAs()
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
this,
|
|
|
|
|
"File not found during reading.\n$e",
|
|
|
|
|
Toast.LENGTH_LONG
|
|
|
|
|
).show()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
catch (e: Exception) {
|
|
|
|
|
Log.d(javaClass.simpleName, e.stackTraceToString())
|
|
|
|
|
this.runOnUiThread({
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
this,
|
|
|
|
|
"Error during reading.\n$e",
|
|
|
|
|
Toast.LENGTH_LONG
|
|
|
|
|
).show()
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
thisFileUri = uri
|
|
|
|
|
saveMetaToSharedPrefs()
|
|
|
|
|
this.runOnUiThread({
|
|
|
|
|
webView.evaluateJavascript("onRead();", {})
|
|
|
|
|
})
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|