Skip to content

Commit 59c0214

Browse files
authored
Make edit note action buttons interchangeable (#881)
1 parent fb845b6 commit 59c0214

26 files changed

+1289
-957
lines changed

TRANSLATIONS.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ See [Android Translations Converter](https://github.com/Crustack/android-transla
1919
<!-- translations:start -->
2020
| Language | Coverage |
2121
|----------|----------|
22-
| 🇺🇸 English | 100% (336/336) |
23-
| 🇪🇸 Catalan | 19% (65/336) |
24-
| 🇨🇿 Czech | 93% (313/336) |
25-
| 🇩🇰 Danish | 20% (69/336) |
26-
| 🇩🇪 German | 97% (327/336) |
27-
| 🇬🇷 Greek | 21% (72/336) |
28-
| 🇪🇸 Spanish | 93% (314/336) |
29-
| 🇫🇷 French | 97% (327/336) |
30-
| 🇭🇺 Hungarian | 19% (65/336) |
31-
| 🇮🇩 Indonesian | 22% (75/336) |
32-
| 🇮🇹 Italian | 86% (291/336) |
33-
| 🇯🇵 Japanese | 21% (73/336) |
34-
| 🇲🇲 Burmese | 26% (90/336) |
35-
| 🇳🇴 Norwegian Bokmål | 31% (106/336) |
36-
| 🇳🇱 Dutch | 63% (212/336) |
37-
| 🇳🇴 Norwegian Nynorsk | 31% (106/336) |
38-
| 🇵🇱 Polish | 89% (300/336) |
39-
| 🇧🇷 Portuguese (Brazil) | 92% (312/336) |
40-
| 🇵🇹 Portuguese (Portugal) | 21% (71/336) |
41-
| 🇷🇴 Romanian | 89% (301/336) |
42-
| 🇷🇺 Russian | 90% (305/336) |
43-
| 🇸🇰 Slovak | 19% (65/336) |
44-
| 🇸🇮 Slovenian | 32% (109/336) |
45-
| 🇸🇪 Swedish | 18% (63/336) |
46-
| 🇵🇭 Tagalog | 19% (65/336) |
47-
| 🇹🇷 Turkish | 21% (73/336) |
48-
| 🇺🇦 Ukrainian | 97% (326/336) |
49-
| 🇻🇳 Vietnamese | 31% (107/336) |
50-
| 🇨🇳 Chinese (Simplified) | 96% (323/336) |
51-
| 🇹🇼 Chinese (Traditional) | 87% (294/336) |
22+
| 🇺🇸 English | 100% (337/337) |
23+
| 🇪🇸 Catalan | 19% (65/337) |
24+
| 🇨🇿 Czech | 92% (313/337) |
25+
| 🇩🇰 Danish | 20% (69/337) |
26+
| 🇩🇪 German | 97% (327/337) |
27+
| 🇬🇷 Greek | 21% (72/337) |
28+
| 🇪🇸 Spanish | 93% (314/337) |
29+
| 🇫🇷 French | 97% (327/337) |
30+
| 🇭🇺 Hungarian | 19% (65/337) |
31+
| 🇮🇩 Indonesian | 22% (75/337) |
32+
| 🇮🇹 Italian | 86% (291/337) |
33+
| 🇯🇵 Japanese | 21% (73/337) |
34+
| 🇲🇲 Burmese | 26% (90/337) |
35+
| 🇳🇴 Norwegian Bokmål | 31% (106/337) |
36+
| 🇳🇱 Dutch | 62% (212/337) |
37+
| 🇳🇴 Norwegian Nynorsk | 31% (106/337) |
38+
| 🇵🇱 Polish | 89% (300/337) |
39+
| 🇧🇷 Portuguese (Brazil) | 92% (312/337) |
40+
| 🇵🇹 Portuguese (Portugal) | 21% (71/337) |
41+
| 🇷🇴 Romanian | 89% (301/337) |
42+
| 🇷🇺 Russian | 90% (305/337) |
43+
| 🇸🇰 Slovak | 19% (65/337) |
44+
| 🇸🇮 Slovenian | 32% (109/337) |
45+
| 🇸🇪 Swedish | 18% (63/337) |
46+
| 🇵🇭 Tagalog | 19% (65/337) |
47+
| 🇹🇷 Turkish | 21% (73/337) |
48+
| 🇺🇦 Ukrainian | 96% (326/337) |
49+
| 🇻🇳 Vietnamese | 31% (107/337) |
50+
| 🇨🇳 Chinese (Simplified) | 95% (323/337) |
51+
| 🇹🇼 Chinese (Traditional) | 87% (294/337) |
5252
<!-- translations:end -->

app/src/main/java/com/philkes/notallyx/data/model/ModelExtensions.kt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
package com.philkes.notallyx.data.model
22

33
import android.content.Context
4+
import android.content.ContextWrapper
5+
import android.content.Intent
6+
import android.net.Uri
47
import android.text.Html
58
import android.util.Base64
9+
import androidx.core.content.IntentCompat
610
import androidx.core.text.toHtml
711
import com.philkes.notallyx.R
12+
import com.philkes.notallyx.data.dao.BaseNoteDao.Companion.MAX_BODY_CHAR_LENGTH
813
import com.philkes.notallyx.data.dao.NoteIdReminder
914
import com.philkes.notallyx.data.imports.markdown.createMarkdownFromBodyAndSpans
1015
import com.philkes.notallyx.data.model.BaseNote.Companion.COLOR_DEFAULT
1116
import com.philkes.notallyx.presentation.applySpans
17+
import com.philkes.notallyx.presentation.showToast
18+
import com.philkes.notallyx.presentation.viewmodel.NotallyModel
1219
import com.philkes.notallyx.utils.decodeToBitmap
20+
import com.philkes.notallyx.utils.getFileName
21+
import com.philkes.notallyx.utils.getMimeType
22+
import com.philkes.notallyx.utils.log
1323
import java.io.File
1424
import java.text.DateFormat
1525
import java.text.SimpleDateFormat
@@ -560,3 +570,72 @@ fun ColorString.isValid() =
560570
false
561571
}
562572
}
573+
574+
data class SharedNote(
575+
val title: String,
576+
val text: String,
577+
val images: List<FileAttachment>,
578+
val files: List<FileAttachment>,
579+
)
580+
581+
fun Intent.generateBaseNote(context: ContextWrapper): SharedNote {
582+
val title = getStringExtra(Intent.EXTRA_SUBJECT) ?: data?.let { context.getFileName(it) } ?: ""
583+
val intentFiles =
584+
IntentCompat.getParcelableArrayListExtra(this, Intent.EXTRA_STREAM, Uri::class.java)
585+
?: IntentCompat.getParcelableExtra(this, Intent.EXTRA_STREAM, Uri::class.java)?.let {
586+
listOf(it)
587+
}
588+
val text =
589+
(data?.let { uri ->
590+
context.contentResolver.openInputStream(uri)?.use { inputStream ->
591+
try {
592+
inputStream.bufferedReader().readText()
593+
} catch (e: Exception) {
594+
context.log(
595+
tag = "",
596+
msg = "Reading text contents from intent failed",
597+
throwable = e,
598+
)
599+
null
600+
}
601+
}
602+
?: run {
603+
context.showToast(R.string.cant_load_file)
604+
null
605+
}
606+
} ?: getStringExtra(Intent.EXTRA_TEXT) ?: "")
607+
.let {
608+
if (it.length > MAX_BODY_CHAR_LENGTH) {
609+
context.showToast(
610+
context.getString(
611+
R.string.note_text_too_long_truncated,
612+
MAX_BODY_CHAR_LENGTH,
613+
)
614+
)
615+
}
616+
it.take(MAX_BODY_CHAR_LENGTH)
617+
}
618+
val (images, files) =
619+
intentFiles?.let {
620+
val filesByType =
621+
it.groupBy { uri ->
622+
context.getMimeType(uri)?.let { mimeType ->
623+
if (mimeType.isImageMimeType) {
624+
NotallyModel.FileType.IMAGE
625+
} else {
626+
NotallyModel.FileType.ANY
627+
}
628+
} ?: NotallyModel.FileType.ANY
629+
}
630+
val images =
631+
filesByType[NotallyModel.FileType.IMAGE]?.let { images ->
632+
images.map { FileAttachment("", it.toString(), "") }
633+
} ?: listOf()
634+
val files =
635+
filesByType[NotallyModel.FileType.ANY]?.let { otherFiles ->
636+
otherFiles.map { FileAttachment("", it.toString(), "") }
637+
} ?: listOf()
638+
Pair(images, files)
639+
} ?: Pair(listOf(), listOf())
640+
return SharedNote(title, text, images, files = files)
641+
}

app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,12 @@ fun Menu.add(
225225
drawable: Int,
226226
showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM,
227227
groupId: Int = Menu.NONE,
228+
itemId: Int = Menu.NONE,
228229
order: Int = Menu.NONE,
229230
onClick: (item: MenuItem) -> Unit,
230231
): MenuItem {
231232
val menuItem =
232-
add(groupId, Menu.NONE, order, title).setIcon(drawable).setOnMenuItemClickListener { item ->
233+
add(groupId, itemId, order, title).setIcon(drawable).setOnMenuItemClickListener { item ->
233234
onClick(item)
234235
item.isChecked = true
235236
return@setOnMenuItemClickListener false

app/src/main/java/com/philkes/notallyx/presentation/activity/LockedActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class LockedActivity<T : ViewBinding> : AppCompatActivity() {
4545
private lateinit var biometricAuthenticationActivityResultLauncher:
4646
ActivityResultLauncher<Intent>
4747

48-
protected lateinit var binding: T
48+
internal lateinit var binding: T
4949
protected lateinit var preferences: NotallyXPreferences
5050
val baseModel: BaseNoteModel by viewModels()
5151

0 commit comments

Comments
 (0)