]> jfr.im git - i.jfr.im-android.git/commitdiff
add stuff main
authorJohn Runyon <redacted>
Wed, 24 May 2023 00:53:53 +0000 (18:53 -0600)
committerJohn Runyon <redacted>
Wed, 24 May 2023 00:53:53 +0000 (18:53 -0600)
.idea/vcs.xml [new file with mode: 0644]
app/src/main/java/im/jfr/i/ShareActivity.kt

diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644 (file)
index 0000000..35eb1dd
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
index 47d55f75e14beb02f5a6a9cfa800d1fb02bb3ace..8d91cdb8900cff99397ada463c3b0878b52132d3 100644 (file)
@@ -14,18 +14,19 @@ import android.widget.Toast
 import org.json.JSONObject
 import java.net.HttpURLConnection
 import java.net.URL
+import kotlin.system.exitProcess
 
 class ShareActivity : AppCompatActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_share)
 
-        when {
-            intent?.action == Intent.ACTION_SEND -> {
+        when (intent?.action) {
+            Intent.ACTION_SEND -> {
                 if (intent.type?.startsWith("image/") == true) {
-                    Thread(Runnable {
+                    Thread {
                         handleImage(intent)
-                    }).start()
+                    }.start()
                 } else {
                     assert(false) { "Uhoh! Unsupported MIME" }
                 }
@@ -36,9 +37,9 @@ class ShareActivity : AppCompatActivity() {
         }
     }
 
-    fun handleImage(intent: Intent) {
+    private fun handleImage(intent: Intent) {
         val hyphens = "--".toByteArray()
-        val boundary = "o3C5AoN2J8vuyaYPh9Ewd4xvQwS5DjpJFSeRNF6sAPhS4QrbNL".toByteArray()
+        val boundary = "o3C5AoN2J8vyaYPh9Ewd4xvQwS5DjpJFSeRNF6sAPhS4QrbNL".toByteArray()
         val crlf = "\r\n".toByteArray()
 
         val url = URL("https://i.jfr.im/upload.php").openConnection() as HttpURLConnection
@@ -46,7 +47,7 @@ class ShareActivity : AppCompatActivity() {
         url.requestMethod = "POST"
         url.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary.toString(Charsets.UTF_8))
         val output = url.outputStream
-        output.write(hyphens + boundary + crlf);
+        output.write(hyphens + boundary + crlf)
         (intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let {
             output.write("Content-Disposition: form-data; name=\"files[]\";filename=\"$it\"\r\n".toByteArray())
             output.write(("Content-Type: "+intent.type+"\r\n").toByteArray())
@@ -61,6 +62,7 @@ class ShareActivity : AppCompatActivity() {
                 len = input.read(buffer)
             }
             */
+            input?.close()
             output.write(crlf)
             output.write(hyphens + boundary + hyphens + crlf)
         }
@@ -69,7 +71,7 @@ class ShareActivity : AppCompatActivity() {
         val jsonStr = url.inputStream.readBytes().toString(Charsets.UTF_8)
         val jsonObj = JSONObject(jsonStr)
         assert(jsonObj.optBoolean("success", false)) { "Response JSON not success" }
-        var uploadedLink = jsonObj.getJSONArray("files").getJSONObject(0).getString("url")
+        val uploadedLink = jsonObj.getJSONArray("files").getJSONObject(0).getString("url")
         (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(ClipData.newPlainText(uploadedLink, uploadedLink))
 
         tv.post {
@@ -78,7 +80,7 @@ class ShareActivity : AppCompatActivity() {
                 Toast.makeText(applicationContext, "Copied", Toast.LENGTH_SHORT).show()
 
             runOnUiThread {
-                System.exit(0)
+                exitProcess(0)
             }
         }
     }