|
|
|
@ -201,58 +201,24 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
saveFile()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
|
super.onResume()
|
|
|
|
|
loadMetaFromSharedPrefs()
|
|
|
|
|
|
|
|
|
|
var uri:Uri? = null
|
|
|
|
|
var mimeType: String? = null
|
|
|
|
|
|
|
|
|
|
if ( intent!= null ) {
|
|
|
|
|
if (intent.action == Intent.ACTION_SEND && intent.extras != null) {
|
|
|
|
|
if (intent.extras!!.get(Intent.EXTRA_STREAM) != null){
|
|
|
|
|
uri = intent.extras!!.get(Intent.EXTRA_STREAM) as Uri
|
|
|
|
|
mimeType = "image"
|
|
|
|
|
} else {
|
|
|
|
|
uri = parse(intent.extras!!.getCharSequence(Intent.EXTRA_TEXT).toString())
|
|
|
|
|
}
|
|
|
|
|
} else if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
|
|
|
|
|
uri = parse(intent.dataString)
|
|
|
|
|
mimeType = contentResolver.getType(uri)
|
|
|
|
|
if (mimeType != null) {
|
|
|
|
|
if (mimeType.split("/")[0] == "text" ) {
|
|
|
|
|
Log.i(javaClass.simpleName, "Wanna open a text file")
|
|
|
|
|
mimeType = "text"
|
|
|
|
|
}
|
|
|
|
|
else if (mimeType.split("/")[0] == "image" ) {
|
|
|
|
|
Log.i(javaClass.simpleName, "Wanna upload a image")
|
|
|
|
|
mimeType = "image"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Log.i(javaClass.simpleName,"Uri: $uri")
|
|
|
|
|
if (uri != null && uri.toString()!="null") {
|
|
|
|
|
intentScheme = uri.scheme!!
|
|
|
|
|
if (intentScheme == "content") {
|
|
|
|
|
Log.i(javaClass.simpleName, "content intent")
|
|
|
|
|
}
|
|
|
|
|
else if (intentScheme =="http" || intentScheme == "https") {
|
|
|
|
|
intentScheme = "link"
|
|
|
|
|
Log.i(javaClass.simpleName, "link intent")
|
|
|
|
|
}
|
|
|
|
|
else Log.i(javaClass.simpleName, "unknown intent")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loadMetaFromSharedPrefs()
|
|
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
if (mimeType == "text" && intentScheme == "content") {
|
|
|
|
|
readFile(intent.data!!)
|
|
|
|
|
} else {
|
|
|
|
|
//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
|
|
|
|
|
}
|
|
|
|
|
} else { // No start with intent data. Load previously used file
|
|
|
|
|
if (thisFileUri !== null) readFile(thisFileUri!!)
|
|
|
|
|
}
|
|
|
|
|
return@withContext
|
|
|
|
|
}
|
|
|
|
|
webView.evaluateJavascript("onRead();"){}
|
|
|
|
|
webView.evaluateJavascript("onRead();") {}
|
|
|
|
|
|
|
|
|
|
if (metaData.metaData.get("url") !== null) {
|
|
|
|
|
val url = parse(metaData.metaData.get("url"))
|
|
|
|
@ -262,14 +228,66 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
Log.i(javaClass.simpleName, "Starting api controller for: $apiHost")
|
|
|
|
|
api = ghostAPI(applicationContext, apiHost)
|
|
|
|
|
}
|
|
|
|
|
if (intentScheme == "link" && uri.toString() !="null") {
|
|
|
|
|
mdToAppend += "[](${uri})\n"
|
|
|
|
|
webView.evaluateJavascript("onRead();"){}
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, null as CharSequence?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
override fun onNewIntent(intent:Intent) {
|
|
|
|
|
super.onNewIntent(intent)
|
|
|
|
|
|
|
|
|
|
Log.i(javaClass.simpleName, "intent data onNewIntent: ${intent.data.toString()}\nIntent action: ${intent.action}")
|
|
|
|
|
|
|
|
|
|
var uri:Uri? = null
|
|
|
|
|
var mimeType: String? = null
|
|
|
|
|
|
|
|
|
|
if (intent.action == Intent.ACTION_SEND && intent.extras != null) {
|
|
|
|
|
if (intent.extras!!.get(Intent.EXTRA_STREAM) != null){
|
|
|
|
|
uri = intent.extras!!.get(Intent.EXTRA_STREAM) as Uri
|
|
|
|
|
mimeType = "image"
|
|
|
|
|
} else {
|
|
|
|
|
uri = parse(intent.extras!!.getCharSequence(Intent.EXTRA_TEXT).toString())
|
|
|
|
|
}
|
|
|
|
|
if (intentScheme == "content" && mimeType == "image" && uri != null) {
|
|
|
|
|
} else if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
|
|
|
|
|
uri = parse(intent.dataString)
|
|
|
|
|
mimeType = contentResolver.getType(uri)
|
|
|
|
|
if (mimeType != null) {
|
|
|
|
|
if (mimeType.split("/")[0] == "text" ) {
|
|
|
|
|
Log.i(javaClass.simpleName, "Wanna open a text file")
|
|
|
|
|
mimeType = "text"
|
|
|
|
|
}
|
|
|
|
|
else if (mimeType.split("/")[0] == "image" ) {
|
|
|
|
|
Log.i(javaClass.simpleName, "Wanna upload a image")
|
|
|
|
|
mimeType = "image"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Log.i(javaClass.simpleName,"Uri: $uri")
|
|
|
|
|
if (uri != null && uri.toString()!="null") {
|
|
|
|
|
intentScheme = uri.scheme!!
|
|
|
|
|
if (intentScheme == "content") {
|
|
|
|
|
Log.i(javaClass.simpleName, "content intent")
|
|
|
|
|
}
|
|
|
|
|
else if (intentScheme =="http" || intentScheme == "https") {
|
|
|
|
|
intentScheme = "link"
|
|
|
|
|
Log.i(javaClass.simpleName, "link intent")
|
|
|
|
|
}
|
|
|
|
|
else Log.i(javaClass.simpleName, "unknown intent")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (intentScheme == "link" && uri.toString() !="null") {
|
|
|
|
|
mdToAppend += "[](${uri})\n"
|
|
|
|
|
webView.evaluateJavascript("onRead();"){}
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, null as CharSequence?)
|
|
|
|
|
}
|
|
|
|
|
if (intentScheme == "content") {
|
|
|
|
|
if (mimeType == "image" && uri != null) {
|
|
|
|
|
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();") {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -940,6 +958,10 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
uri,
|
|
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
|
|
|
|
)
|
|
|
|
|
} catch (e: java.lang.SecurityException) {
|
|
|
|
|
Log.d(javaClass.simpleName, "Couldn't get persistable URI permissions. Trying to grant 'em.\n${e.stackTraceToString()}")
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
grantUriPermission(
|
|
|
|
|
"org.wntr.mdeditor",
|
|
|
|
|
uri,
|
|
|
|
@ -1024,8 +1046,8 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected fun onSaveInstanceState(outState: Bundle) {
|
|
|
|
|
super.onSaveInstanceState(outState)
|
|
|
|
|
override fun onPause() {
|
|
|
|
|
super.onPause()
|
|
|
|
|
/*outState.putString("test", "onSaveInstanceState-String")*/
|
|
|
|
|
webView.evaluateJavascript("saveFile();", ValueCallback<String>() {})
|
|
|
|
|
webView.evaluateJavascript("easyMDE.codemirror.doc.getCursor();") {
|
|
|
|
@ -1033,7 +1055,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
Log.i(javaClass.simpleName,"Cursor: $it")
|
|
|
|
|
saveMetaToSharedPrefs()
|
|
|
|
|
}
|
|
|
|
|
Log.i(javaClass.simpleName, "\"onSaveInstanceState\" durchlaufen")
|
|
|
|
|
Log.i(javaClass.simpleName, "\"onPause\" durchlaufen")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
|
|
|
|