|
|
|
@ -11,6 +11,9 @@ import java.io.FileOutputStream
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import java.io.InputStream
|
|
|
|
|
|
|
|
|
|
var thisFileUri: Uri? = null
|
|
|
|
|
var metaData = mdMeta()
|
|
|
|
|
|
|
|
|
|
fun checkURIResource(context: Context, uri: Uri?): Boolean {
|
|
|
|
|
val cursor = context.contentResolver.query(uri!!, null, null, null, null)
|
|
|
|
|
val doesExist = cursor != null && cursor.moveToFirst()
|
|
|
|
@ -41,9 +44,8 @@ fun createHtmlFile(context: Context, htmlString: String): File? {
|
|
|
|
|
try {
|
|
|
|
|
val storageDir = File(context.cacheDir, "html")
|
|
|
|
|
storageDir.mkdir()
|
|
|
|
|
htmlFile = File(storageDir.path + "/${getDisplayName(context,
|
|
|
|
|
MainActivity.thisFileUri
|
|
|
|
|
).split(".")[0]}.html")
|
|
|
|
|
htmlFile = File(storageDir.path + "/${getDisplayName(context,thisFileUri)
|
|
|
|
|
.split(".")[0]}.html")
|
|
|
|
|
if (htmlFile.exists()) htmlFile.delete()
|
|
|
|
|
htmlFile.createNewFile()
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
@ -159,12 +161,12 @@ fun queryName(context: Context, uri: Uri): String? {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun saveMetaToSharedPrefs(context: Context) {
|
|
|
|
|
if (MainActivity.thisFileUri == null) return
|
|
|
|
|
Log.d("saveMetaToSharedPrefs", "saving to shared prefs cursor: ${MainActivity.metaData.cursor} in file: ${MainActivity.thisFileUri}")
|
|
|
|
|
if (thisFileUri == null) return
|
|
|
|
|
Log.d("saveMetaToSharedPrefs", "saving to shared prefs cursor: ${metaData.cursor} in file: ${thisFileUri}")
|
|
|
|
|
context.getSharedPreferences("prefs", Context.MODE_PRIVATE)
|
|
|
|
|
.edit().apply {
|
|
|
|
|
putString("lastFile", MainActivity.thisFileUri.toString())
|
|
|
|
|
putString("cursor", MainActivity.metaData.cursor)
|
|
|
|
|
putString("lastFile", thisFileUri.toString())
|
|
|
|
|
putString("cursor", metaData.cursor)
|
|
|
|
|
apply()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -177,9 +179,9 @@ fun loadMetaFromSharedPrefs(context: Context): Boolean{
|
|
|
|
|
Log.i("loadMetaFromSharedPrefs","No lastfile saved")
|
|
|
|
|
return false
|
|
|
|
|
} else {
|
|
|
|
|
MainActivity.thisFileUri = Uri.parse(uriString)
|
|
|
|
|
MainActivity.metaData.cursor = prefs.getString("cursor", "nocursor") ?: "{ line: 0, ch: 0, sticky: null }"
|
|
|
|
|
Log.i("loadMetaFromSharedPrefs","Loaded cursor: ${MainActivity.metaData.cursor}")
|
|
|
|
|
thisFileUri = Uri.parse(uriString)
|
|
|
|
|
metaData.cursor = prefs.getString("cursor", "nocursor") ?: "{ line: 0, ch: 0, sticky: null }"
|
|
|
|
|
Log.i("loadMetaFromSharedPrefs","Loaded cursor: ${metaData.cursor}")
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|