|
@@ -4,6 +4,7 @@ import android.content.Intent
|
|
import android.content.pm.PackageManager
|
|
import android.content.pm.PackageManager
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
import android.util.Log
|
|
import android.util.Log
|
|
|
|
+import android.view.View
|
|
import android.widget.TextView
|
|
import android.widget.TextView
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
@@ -18,6 +19,7 @@ import kotlinx.coroutines.withContext
|
|
import okhttp3.OkHttpClient
|
|
import okhttp3.OkHttpClient
|
|
import okhttp3.Request
|
|
import okhttp3.Request
|
|
import okhttp3.RequestBody.Companion.toRequestBody
|
|
import okhttp3.RequestBody.Companion.toRequestBody
|
|
|
|
+import org.json.JSONArray
|
|
import org.json.JSONObject
|
|
import org.json.JSONObject
|
|
|
|
|
|
class SendNoteActivity : AppCompatActivity() {
|
|
class SendNoteActivity : AppCompatActivity() {
|
|
@@ -28,13 +30,19 @@ class SendNoteActivity : AppCompatActivity() {
|
|
setContentView(R.layout.activity_send_note)
|
|
setContentView(R.layout.activity_send_note)
|
|
|
|
|
|
val settings = TriliumSettings(this)
|
|
val settings = TriliumSettings(this)
|
|
-
|
|
|
|
if (!settings.isConfigured()) {
|
|
if (!settings.isConfigured()) {
|
|
// We can't do anything useful if we're not configured. Abort out.
|
|
// We can't do anything useful if we're not configured. Abort out.
|
|
Toast.makeText(this, getString(R.string.sender_not_configured_note), Toast.LENGTH_LONG).show()
|
|
Toast.makeText(this, getString(R.string.sender_not_configured_note), Toast.LENGTH_LONG).show()
|
|
finish()
|
|
finish()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ if (settings.noteLabel.isNotEmpty()) {
|
|
|
|
+ // We have a label to apply to this note! Indicate in the UI.
|
|
|
|
+ labelList.text = getString(R.string.label_preview_template, settings.noteLabel)
|
|
|
|
+ } else {
|
|
|
|
+ // Hide the label text preview.
|
|
|
|
+ labelList.visibility = View.GONE
|
|
|
|
+ }
|
|
|
|
|
|
// If we're a share-intent, pre-populate the note.
|
|
// If we're a share-intent, pre-populate the note.
|
|
when (intent?.action) {
|
|
when (intent?.action) {
|
|
@@ -125,6 +133,7 @@ class SendNoteActivity : AppCompatActivity() {
|
|
*/
|
|
*/
|
|
private suspend fun sendNote(noteTitle: String, noteText: String, triliumAddress: String, apiToken: String): Boolean {
|
|
private suspend fun sendNote(noteTitle: String, noteText: String, triliumAddress: String, apiToken: String): Boolean {
|
|
val tag = "SendNoteCoroutine"
|
|
val tag = "SendNoteCoroutine"
|
|
|
|
+ val settings = TriliumSettings(this)
|
|
|
|
|
|
return withContext(Dispatchers.IO) {
|
|
return withContext(Dispatchers.IO) {
|
|
val client = OkHttpClient()
|
|
val client = OkHttpClient()
|
|
@@ -139,6 +148,16 @@ class SendNoteActivity : AppCompatActivity() {
|
|
}
|
|
}
|
|
json.put("content", HtmlConverter().convertPlainTextToHtml(noteText))
|
|
json.put("content", HtmlConverter().convertPlainTextToHtml(noteText))
|
|
|
|
|
|
|
|
+ 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", "")
|
|
|
|
+ val labelList = JSONArray()
|
|
|
|
+ labelList.put(label)
|
|
|
|
+ json.put("labels", labelList)
|
|
|
|
+ }
|
|
|
|
+
|
|
val body = json.toString().toRequestBody(Utils.JSON)
|
|
val body = json.toString().toRequestBody(Utils.JSON)
|
|
|
|
|
|
val request = Request.Builder()
|
|
val request = Request.Builder()
|