diff --git a/Readme.md b/Readme.md index d2b699d..3df1cf5 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,8 @@ --- url: https://mary.joefix.it/haunted-intro/ -title: hauntED intro +title: hauntED Readme feature_image: https://mary.joefix.it/content/images/size/w1200/2023/11/IMG_20231105_132234.jpg +author: yova@freedomhost.de --- # hauntED 🚀 @@ -19,16 +20,22 @@ A simple markdown editor for ghost on android. Built with [simple-markdown-edito - send links from other apps to include as markdown syntax - dark mode - a lot of md functionality, like [links](https://git.gugelfrei.de) -- perfect for spantaneous content creation right from your hammock. 🏞ī¸ +- perfect for spontaneous content creation right from your hammock. 🏞ī¸ ## Recommendations as this uses webview, that is the chromium rendering engine adapted as android service, in respect to your privacy, it is advised to install an edited version like bromite or ungoogled webview. Most simple is to just buy a prepared fone [from me](https://gugelfrei.de). -made with ❤ī¸ by yv@wntr.org +made with ❤ī¸ by yv@wntr.org Šī¸ 2024 + + +![Screenshot_20240201-200704_MDEditor.png](https://mary.joefix.it/content/images/2024/02/Screenshot_20240201-200704_MDEditor.png) + +![Screenshot_20240201-200737_MDEditor.png](https://mary.joefix.it/content/images/2024/02/Screenshot_20240201-200737_MDEditor.png) + +![Screenshot_20240201-201115_MDEditor.png](https://mary.joefix.it/content/images/2024/02/Screenshot_20240201-201115_MDEditor.png) -![Screenshot_20240115-174321_MDEditor.png](https://mary.joefix.it/content/images/2024/01/Screenshot_20240115-174321_MDEditor.png) diff --git a/app/src/main/java/org/wntr/mdeditor/MainActivity.kt b/app/src/main/java/org/wntr/mdeditor/MainActivity.kt index 5ba5673..0e21b49 100644 --- a/app/src/main/java/org/wntr/mdeditor/MainActivity.kt +++ b/app/src/main/java/org/wntr/mdeditor/MainActivity.kt @@ -124,7 +124,6 @@ class MainActivity : AppCompatActivity() { var mdToAppend: String = "" var thisFileUri: Uri? = null var truncate = false - lateinit var tempFile: File lateinit var pickMultipleVisualMedia: ActivityResultLauncher lateinit var ghostSettings: ActivityResultLauncher lateinit var ghostMetaData: ActivityResultLauncher @@ -210,7 +209,17 @@ class MainActivity : AppCompatActivity() { @JavascriptInterface fun triggerShare(sharedText: String) { - shareHtml(sharedText) + val htmlFile = createHtmlFile(applicationContext, sharedText) + if (htmlFile == null) return + val htmlUri = FileProvider.getUriForFile(applicationContext, "org.wntr.mdeditor.fileprovider", htmlFile) + + with(Intent(Intent.ACTION_SEND)) { + htmlFile?.also { + type = "text/plain" + putExtra(Intent.EXTRA_STREAM, htmlUri) + startActivity(Intent.createChooser(this, "Share html")) + } + } } @JavascriptInterface @@ -705,62 +714,7 @@ class MainActivity : AppCompatActivity() { return true } - fun shareHtml(htmlString: String): Boolean { - try { - createHTMLFile() - } catch (e: Exception) { - Log.d(javaClass.simpleName, "Problem with accessing file\n${e.stackTraceToString()}") - Toast.makeText( - this, - "Problem with accessing file\n$e", - Toast.LENGTH_LONG - ).show() - return false - } - - try { - FileOutputStream(tempFile).use { - it.write(htmlString.toByteArray()) - } - - } catch (e: Exception) { - Toast.makeText( - this, - "Error during writing.\n$e", - Toast.LENGTH_LONG - ).show() - return false - } - Log.d(javaClass.simpleName, "File saved: ${tempFile.toURI()}") - Toast.makeText( - this, - "HTML output produced.", - Toast.LENGTH_LONG - ).show() - - val htmlUri = FileProvider.getUriForFile(this, "org.wntr.mdeditor.fileprovider", tempFile) - - with(Intent(Intent.ACTION_SEND)) { - tempFile?.also { - type = "text/plain" - putExtra(Intent.EXTRA_STREAM, htmlUri) - startActivity(Intent.createChooser(this, "Share html")) - } - } - return true - } - - @Throws(IOException::class) - private fun createHTMLFile() { -// Create an image file name - val storageDir = File(cacheDir, "html") - storageDir.mkdir() - tempFile = File(storageDir.path + "/${getDisplayName(applicationContext, thisFileUri).split(".")[0]}.html") - if (tempFile.exists()) tempFile.delete() - tempFile.createNewFile() - } - - fun openFile() { + fun openFile() { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply { addCategory(Intent.CATEGORY_OPENABLE) putExtra(DocumentsContract.EXTRA_INITIAL_URI, thisFileUri) diff --git a/app/src/main/java/org/wntr/mdeditor/helpers.kt b/app/src/main/java/org/wntr/mdeditor/helpers.kt index fee337d..43b469e 100644 --- a/app/src/main/java/org/wntr/mdeditor/helpers.kt +++ b/app/src/main/java/org/wntr/mdeditor/helpers.kt @@ -2,9 +2,13 @@ package org.wntr.mdeditor import android.annotation.SuppressLint import android.content.Context +import android.content.Intent import android.net.Uri import android.provider.OpenableColumns import android.util.Log +import android.widget.Toast +import androidx.core.content.ContextCompat.startActivity +import androidx.core.content.FileProvider import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -28,11 +32,56 @@ fun createFileFromStream(ins: InputStream, destination: File?) { os.flush() } } catch (ex: java.lang.Exception) { - Log.e("Save File", ex.message!!) + Log.e("Save img tmp file", ex.message!!) ex.printStackTrace() } } +fun createHtmlFile(context: Context, htmlString: String): File? { + val TAG="share HTML" + lateinit var htmlFile : File + + try { + val storageDir = File(context.cacheDir, "html") + storageDir.mkdir() + htmlFile = File(storageDir.path + "/${getDisplayName(context, + MainActivity.thisFileUri + ).split(".")[0]}.html") + if (htmlFile.exists()) htmlFile.delete() + htmlFile.createNewFile() + } catch (e: Exception) { + Log.d(TAG, "Problem with accessing file\n${e.stackTraceToString()}") + Toast.makeText( + context, + "Problem with accessing file\n$e", + Toast.LENGTH_LONG + ).show() + return null + } + + try { + FileOutputStream(htmlFile).use { + it.write(htmlString.toByteArray()) + } + + } catch (e: Exception) { + Toast.makeText( + context, + "Error during writing.\n$e", + Toast.LENGTH_LONG + ).show() + return null + } + Log.d(TAG, "File saved: ${htmlFile.toURI()}") + Toast.makeText( + context, + "HTML output produced.", + Toast.LENGTH_LONG + ).show() + + return htmlFile +} + fun deleteCache(context: Context) { try { val dir = File(context.cacheDir, "html")