Skip to content

Commit 44f9e35

Browse files
committed
Updated search option to include deleted and archived notes
1 parent 225fd58 commit 44f9e35

File tree

10 files changed

+96
-40
lines changed

10 files changed

+96
-40
lines changed

CONTRIBUTORS.md

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
### Translations
22
1. 🇬🇧 English
33
2. 🇭🇺 Hungarian
4-
3. 🇳🇱 Dutch by [tlmnot](https://github.com/tlmnot)
5-
4. 🇨🇿 Czech by [tomo90](https://github.com/tomo90)
6-
5. 🇯🇵 Japanese by [kato-k](https://github.com/kato-k)
7-
6. 🇦🇩 Catalan by retiolus
8-
7. 🇵🇱 Polish by [ZiomaleQ](https://github.com/ZiomaleQ)
9-
8. 🇸🇰 Slovak by [Juraj Liso](https://github.com/LiJu09)
10-
9. 🇮🇩 Indonesian by [zmni](https://github.com/zmni)
11-
10. 🇮🇹 Italian by Luigi Sforza
12-
11. 🇪🇸 Spanish by Jose Casas
13-
12. 🇹🇷 Turkish by Helpful User
14-
13. 🇺🇦 Ukrainian by Alex Shpak
15-
14. 🇩🇰 Danish by [shoddysheep](https://github.com/shoddysheep)
16-
15. 🇸🇪 Swedish by Erik Lindström
17-
16. 🇷🇺 Russian by Denis Bondarenko
18-
17. 🇫🇷 French by Arnaud Dieumegard, [Co-7](https://github.com/Co-7)
19-
18. 🇧🇷 Portuguese (Brazil) by [fabianski7](https://github.com/fabianski7)
20-
19. 🇵🇹 Portuguese (Portugal) by [joaopmatos](https://github.com/joaopmatos)
21-
20. 🇳🇴 Norwegian (Bokmål) by Fredrik Magnussen, [Erik Thom](https://github.com/erikthm)
22-
21. 🇳🇴 Norwegian (Nynorsk) by [Erik Thom](https://github.com/erikthm)
23-
22. 🇵🇭 Tagalog by Isaiah Collins Abetong
24-
23. 🇨🇳 Chinese (Simplified) by [Austin Huang](https://github.com/austinhuang0131)
25-
24. 🇩🇪 German by Maximilian Braunschmied, [jonas-haeusler](https://github.com/jonas-haeusler), [samuel141](https://github.com/samuel141)
4+
3. 🇬🇷 Greek by xamps
5+
4. 🇳🇱 Dutch by [tlmnot](https://github.com/tlmnot)
6+
5. 🇨🇿 Czech by [tomo90](https://github.com/tomo90)
7+
6. 🇯🇵 Japanese by [kato-k](https://github.com/kato-k)
8+
7. 🇦🇩 Catalan by retiolus
9+
8. 🇵🇱 Polish by [ZiomaleQ](https://github.com/ZiomaleQ)
10+
9. 🇸🇰 Slovak by [Juraj Liso](https://github.com/LiJu09)
11+
10. 🇮🇩 Indonesian by [zmni](https://github.com/zmni)
12+
11. 🇮🇹 Italian by Luigi Sforza
13+
12. 🇪🇸 Spanish by Jose Casas
14+
13. 🇹🇷 Turkish by Helpful User
15+
14. 🇺🇦 Ukrainian by Alex Shpak
16+
15. 🇩🇰 Danish by [shoddysheep](https://github.com/shoddysheep)
17+
16. 🇸🇪 Swedish by Erik Lindström
18+
17. 🇷🇺 Russian by Denis Bondarenko
19+
18. 🇫🇷 French by Arnaud Dieumegard, [Co-7](https://github.com/Co-7)
20+
19. 🇧🇷 Portuguese (Brazil) by [fabianski7](https://github.com/fabianski7)
21+
20. 🇵🇹 Portuguese (Portugal) by [joaopmatos](https://github.com/joaopmatos)
22+
21. 🇳🇴 Norwegian (Bokmål) by Fredrik Magnussen, [Erik Thom](https://github.com/erikthm)
23+
22. 🇳🇴 Norwegian (Nynorsk) by [Erik Thom](https://github.com/erikthm)
24+
23. 🇵🇭 Tagalog by Isaiah Collins Abetong
25+
24. 🇨🇳 Chinese (Simplified) by [Austin Huang](https://github.com/austinhuang0131)
26+
25. 🇩🇪 German by Maximilian Braunschmied, [jonas-haeusler](https://github.com/jonas-haeusler), [samuel141](https://github.com/samuel141)

app/src/main/java/com/omgodse/notally/activities/TakeNote.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ class TakeNote : NotallyActivity(Type.NOTE) {
118118
}
119119

120120
private fun setupMovementMethod() {
121+
val items = Operations.createArray(this, R.string.edit, R.string.open_link)
121122
val movementMethod = LinkMovementMethod { span ->
122123
MaterialAlertDialogBuilder(this)
123-
.setItems(R.array.linkOptions) { dialog, which ->
124+
.setItems(items) { dialog, which ->
124125
if (which == 1) {
125126
val spanStart = binding.EnterBody.text?.getSpanStart(span)
126127
val spanEnd = binding.EnterBody.text?.getSpanEnd(span)

app/src/main/java/com/omgodse/notally/fragments/Search.kt

+37
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,46 @@
11
package com.omgodse.notally.fragments
22

3+
import android.os.Bundle
4+
import android.view.Menu
5+
import android.view.MenuInflater
6+
import android.view.View
7+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
38
import com.omgodse.notally.R
9+
import com.omgodse.notally.miscellaneous.Operations
10+
import com.omgodse.notally.miscellaneous.add
11+
import com.omgodse.notally.room.Folder
412

513
class Search : NotallyFragment() {
614

15+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
16+
super.onViewCreated(view, savedInstanceState)
17+
setHasOptionsMenu(true)
18+
}
19+
20+
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
21+
menu.add(R.string.filter, R.drawable.filter) { showFilterDialog() }
22+
}
23+
24+
25+
private fun showFilterDialog() {
26+
val items = Operations.createArray(requireContext(), R.string.notes, R.string.deleted, R.string.archived)
27+
val checked = when (model.folder) {
28+
Folder.NOTES -> 0
29+
Folder.DELETED -> 1
30+
Folder.ARCHIVED -> 2
31+
}
32+
MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.filter)
33+
.setSingleChoiceItems(items, checked) { dialog, index ->
34+
dialog.cancel()
35+
when (index) {
36+
0 -> model.folder = Folder.NOTES
37+
1 -> model.folder = Folder.DELETED
38+
2 -> model.folder = Folder.ARCHIVED
39+
}
40+
}.setNegativeButton(R.string.cancel, null).show()
41+
}
42+
43+
744
override fun getBackground() = R.drawable.search
845

946
override fun getObservable() = model.searchResults

app/src/main/java/com/omgodse/notally/miscellaneous/Operations.kt

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ object Operations {
1515

1616
const val extraCharSequence = "com.omgodse.notally.extra.charSequence"
1717

18+
19+
fun createArray(context: Context, vararg ids: Int): Array<String> {
20+
return Array(ids.size) { index -> context.getString(ids[index]) }
21+
}
22+
23+
1824
fun extractColor(color: Color, context: Context): Int {
1925
val id = when (color) {
2026
Color.DEFAULT -> R.color.Default

app/src/main/java/com/omgodse/notally/room/dao/BaseNoteDao.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ interface BaseNoteDao {
7676
suspend fun getListOfBaseNotesByLabelImpl(label: String): List<BaseNote>
7777

7878

79-
fun getBaseNotesByKeyword(keyword: String): LiveData<List<BaseNote>> {
80-
val result = getBaseNotesByKeyword(keyword, Folder.NOTES)
79+
fun getBaseNotesByKeyword(keyword: String, folder: Folder): LiveData<List<BaseNote>> {
80+
val result = getBaseNotesByKeywordImpl(keyword, folder)
8181
return Transformations.map(result) { list -> list.filter { baseNote -> matchesKeyword(baseNote, keyword) } }
8282
}
8383

8484
@Query("SELECT * FROM BaseNote WHERE folder = :folder AND (title LIKE '%' || :keyword || '%' OR body LIKE '%' || :keyword || '%' OR items LIKE '%' || :keyword || '%' OR labels LIKE '%' || :keyword || '%') ORDER BY pinned DESC, timestamp DESC")
85-
fun getBaseNotesByKeyword(keyword: String, folder: Folder): LiveData<List<BaseNote>>
85+
fun getBaseNotesByKeywordImpl(keyword: String, folder: Folder): LiveData<List<BaseNote>>
8686

8787

8888
private fun matchesKeyword(baseNote: BaseNote, keyword: String): Boolean {

app/src/main/java/com/omgodse/notally/room/livedata/SearchResult.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.omgodse.notally.room.livedata
33
import androidx.lifecycle.LiveData
44
import androidx.lifecycle.Observer
55
import com.omgodse.notally.room.BaseNote
6+
import com.omgodse.notally.room.Folder
67
import com.omgodse.notally.room.Item
78
import com.omgodse.notally.room.dao.BaseNoteDao
89
import kotlinx.coroutines.CoroutineScope
@@ -23,12 +24,12 @@ class SearchResult(
2324
value = emptyList()
2425
}
2526

26-
fun fetch(keyword: String) {
27+
fun fetch(keyword: String, folder: Folder) {
2728
job?.cancel()
2829
liveData?.removeObserver(observer)
2930
job = scope.launch {
3031
if (keyword.isNotEmpty()) {
31-
liveData = baseNoteDao.getBaseNotesByKeyword(keyword)
32+
liveData = baseNoteDao.getBaseNotesByKeyword(keyword, folder)
3233
liveData?.observeForever(observer)
3334
} else value = emptyList()
3435
}

app/src/main/java/com/omgodse/notally/viewmodels/BaseNoteModel.kt

+11-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
4747
val deletedNotes = Content(baseNoteDao.getFrom(Folder.DELETED), ::transform)
4848
val archivedNotes = Content(baseNoteDao.getFrom(Folder.ARCHIVED), ::transform)
4949

50+
var folder = Folder.NOTES
51+
set(value) {
52+
if (field != value) {
53+
field = value
54+
searchResults.fetch(keyword, folder)
55+
}
56+
}
5057
var keyword = String()
5158
set(value) {
5259
if (field != value) {
5360
field = value
54-
searchResults.fetch(value)
61+
searchResults.fetch(keyword, folder)
5562
}
5663
}
5764

@@ -64,14 +71,13 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
6471
viewModelScope.launch {
6572
val previousNotes = getPreviousNotes()
6673
val previousLabels = getPreviousLabels()
67-
val delete: (file: File) -> Unit = { file: File -> file.delete() }
6874
if (previousNotes.isNotEmpty() || previousLabels.isNotEmpty()) {
6975
database.withTransaction {
7076
labelDao.insert(previousLabels)
7177
baseNoteDao.insert(previousNotes)
72-
getNotePath().listFiles()?.forEach(delete)
73-
getDeletedPath().listFiles()?.forEach(delete)
74-
getArchivedPath().listFiles()?.forEach(delete)
78+
getNotePath().listFiles()?.forEach { file -> file.delete() }
79+
getDeletedPath().listFiles()?.forEach { file -> file.delete() }
80+
getArchivedPath().listFiles()?.forEach { file -> file.delete() }
7581
getLabelsPreferences().edit(true) { clear() }
7682
}
7783
}

app/src/main/res/drawable/filter.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
<path
8+
android:fillColor="#000000"
9+
android:pathData="M7,6h10l-5.01,6.3L7,6zM4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z" />
10+
</vector>

app/src/main/res/values/arrays.xml

-7
This file was deleted.

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<!-- Menu Options -->
1212
<string name="share">Share</string>
13+
<string name="filter">Filter</string>
1314
<string name="search">Search</string>
1415
<string name="delete">Delete</string>
1516
<string name="restore">Restore</string>

0 commit comments

Comments
 (0)