2 Revīzijas 01beafb824 ... 6a6562642d

Autors SHA1 Ziņojums Datums
  zadam 6a6562642d version 0.2 2 gadi atpakaļ
  zadam 83964a4bb3 set configured label also for shared image 2 gadi atpakaļ

+ 2 - 2
app/build.gradle

@@ -28,8 +28,8 @@ android {
         applicationId "io.github.zadam.triliumsender"
         minSdkVersion 21
         targetSdkVersion 32
-        versionCode 1
-        versionName "0.1"
+        versionCode 2
+        versionName "0.2"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
     buildTypes {

+ 16 - 0
app/src/main/java/io/github/zadam/triliumsender/ShareActivity.kt

@@ -18,6 +18,8 @@ import okhttp3.MediaType.Companion.toMediaType
 import okhttp3.MultipartBody
 import okhttp3.OkHttpClient
 import okhttp3.Request
+import org.json.JSONArray
+import org.json.JSONObject
 
 
 class ShareActivity : AppCompatActivity() {
@@ -87,6 +89,19 @@ class ShareActivity : AppCompatActivity() {
      * @return the result of the attempted image send.
      */
     private suspend fun doSendImage(imageUri: Uri, mimeType: String, triliumAddress: String, apiToken: String): SendImageResult {
+        val settings = TriliumSettings(this)
+
+        val labelList = JSONArray()
+
+        if (settings.noteLabel.isNotEmpty()) {
+            // The api actually supports a list of key-value pairs, but for now we just write one label.
+            val label = JSONObject()
+            label.put("name", settings.noteLabel)
+            label.put("value", "")
+
+            labelList.put(label)
+        }
+
         return withContext(Dispatchers.IO) {
             val tag = "SendImageCoroutine"
 
@@ -98,6 +113,7 @@ class ShareActivity : AppCompatActivity() {
                     .url("$triliumAddress/api/sender/image")
                     .addHeader("Authorization", apiToken)
                     .addHeader("X-Local-Date", Utils.localDateStr())
+                    .addHeader("X-Labels", labelList.toString())
                     .post(requestBody)
                     .build()