-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworks notes filtering. Adds more sorting orders. Sorting Order is now persistent.
- Loading branch information
1 parent
3cc1c3d
commit 4b03d45
Showing
15 changed files
with
238 additions
and
29 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
app/src/main/java/org/secuso/privacyfriendlynotes/model/SortingOrder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.secuso.privacyfriendlynotes.model | ||
|
||
import android.content.Context | ||
import android.preference.PreferenceManager | ||
import org.secuso.privacyfriendlynotes.preference.PreferenceKeys | ||
|
||
class SortingOrder(context: Context) { | ||
|
||
val prefManager = PreferenceManager.getDefaultSharedPreferences(context) | ||
var ordering = Options.values().filter { | ||
it.name == prefManager.getString(PreferenceKeys.SP_NOTES_ORDERING, Options.Creation.name) | ||
}.getOrElse(0) { _ -> Options.Creation } | ||
set(value) { | ||
prefManager.edit() | ||
.putString(PreferenceKeys.SP_NOTES_ORDERING, value.name) | ||
.apply() | ||
field = value | ||
} | ||
|
||
enum class Options { | ||
AlphabeticalAscending, | ||
TypeAscending, | ||
Creation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/src/main/java/org/secuso/privacyfriendlynotes/ui/helper/SortingOptionDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.secuso.privacyfriendlynotes.ui.helper | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.core.util.Consumer | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.android.material.bottomsheet.BottomSheetDialog | ||
import org.secuso.privacyfriendlynotes.R | ||
import org.secuso.privacyfriendlynotes.model.SortingOrder | ||
|
||
class SortingOptionDialog( | ||
context: Context, | ||
sortingOptionTextResId: Int, | ||
sortingOptionIconResId: Int, | ||
onChosen: Consumer<SortingOrder.Options> | ||
) { | ||
|
||
private val dialog = BottomSheetDialog(context) | ||
private val recyclerView by lazy { | ||
dialog.findViewById<RecyclerView>(R.id.sorting_options)!! | ||
} | ||
|
||
init { | ||
dialog.setContentView(R.layout.dialog_sorting_options) | ||
recyclerView.layoutManager = LinearLayoutManager(context) | ||
|
||
val icons = context.resources.obtainTypedArray(sortingOptionIconResId); | ||
val options = context.resources.getStringArray(sortingOptionTextResId) | ||
.zip((0 until icons.length()).map { icons.getResourceId(it, 0) }) | ||
.mapIndexed { i, (text, icon) -> SortingOptionData( | ||
text, | ||
icon, | ||
SortingOrder.Options.values()[i] | ||
) } | ||
icons.recycle() | ||
recyclerView.adapter = SortingOptionAdapter(options) { option -> | ||
onChosen.accept(option) | ||
dialog.dismiss() | ||
} | ||
} | ||
|
||
fun chooseSortingOption() { | ||
dialog.show() | ||
} | ||
|
||
data class SortingOptionData( | ||
val text: String, | ||
val icon: Int, | ||
val option: SortingOrder.Options | ||
) | ||
|
||
inner class SortingOptionAdapter( | ||
private val options: List<SortingOptionData>, | ||
private val onChosen: Consumer<SortingOrder.Options> | ||
): RecyclerView.Adapter<SortingOptionAdapter.SortingOptionHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SortingOptionHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.dialog_sorting_options_item, parent, false) | ||
return SortingOptionHolder(view) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return options.size | ||
} | ||
|
||
override fun onBindViewHolder(holder: SortingOptionHolder, position: Int) { | ||
holder.textView.text = options[position].text | ||
holder.imgView.setImageResource(options[position].icon) | ||
holder.itemView.setOnClickListener { _ -> onChosen.accept(options[position].option) } | ||
} | ||
|
||
inner class SortingOptionHolder(view: View): RecyclerView.ViewHolder(view) { | ||
val textView: TextView = view.findViewById(R.id.sorting_option_text) | ||
val imgView: ImageView = view.findViewById(R.id.sorting_option_icon) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/src/main/res/drawable/ic_baseline_access_time_icon_24dp.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<vector android:height="24dp" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="?attr/colorIconFill" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/> | ||
<path android:fillColor="?attr/colorIconFill" android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/> | ||
</vector> |
5 changes: 5 additions & 0 deletions
5
app/src/main/res/drawable/ic_baseline_edit_note_icon_24dp.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="?attr/colorIconFill" android:pathData="M3,10h11v2H3V10zM3,8h11V6H3V8zM3,16h7v-2H3V16zM18.01,12.87l0.71,-0.71c0.39,-0.39 1.02,-0.39 1.41,0l0.71,0.71c0.39,0.39 0.39,1.02 0,1.41l-0.71,0.71L18.01,12.87zM17.3,13.58l-5.3,5.3V21h2.12l5.3,-5.3L17.3,13.58z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="?attr/colorIconFill" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/sorting_options" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/alphabetical_ascending" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="10dp" | ||
android:orientation="horizontal"> | ||
<ImageView | ||
android:id="@+id/sorting_option_icon" | ||
android:layout_width="30dp" | ||
android:layout_height="30dp" | ||
android:layout_gravity="center_vertical" /> | ||
<TextView | ||
android:id="@+id/sorting_option_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="center_vertical" | ||
android:layout_marginStart="20dp" | ||
android:gravity="center_vertical"/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters