Skip to content

Commit

Permalink
[fix] Improves default category color and color selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderPaddyS committed Jan 15, 2024
1 parent 8780131 commit 4d324c0
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.secuso.privacyfriendlynotes.ui.adapter

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.preference.PreferenceManager
import android.util.TypedValue
import android.view.LayoutInflater
Expand Down Expand Up @@ -53,20 +54,37 @@ class CategoryAdapter(
override fun onBindViewHolder(holder: CategoryHolder, position: Int) {
val (_, name, color) = categories[position]
holder.textViewCategoryName.text = name
val backgroundColor = if (color != null) Color.parseColor(color) else {

if (color == null) {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorOnSurface, value, true)
value.data
}
if (PreferenceManager.getDefaultSharedPreferences(holder.itemView.context).getBoolean("settings_color_category", true)) {
if (isDarkMode(holder.textViewCategoryName.context)) {
holder.textViewCategoryName.setTextColor(backgroundColor)
holder.btnColorSelector.setBackgroundColor(backgroundColor)
val defaultColor = value.data

if (PreferenceManager.getDefaultSharedPreferences(holder.itemView.context).getBoolean("settings_color_category", true)) {
holder.btnColorSelector.setIconResource(R.drawable.transparent_checker)
holder.btnColorSelector.setBackgroundColor(holder.btnColorSelector.resources.getColor(R.color.transparent))
if (isDarkMode(holder.textViewCategoryName.context)) {
holder.textViewCategoryName.setTextColor(defaultColor)
} else {
holder.itemView.setBackgroundColor(defaultColor)
}
} else {
holder.itemView.setBackgroundColor(backgroundColor)
holder.btnExpandMenu.visibility = View.GONE
}
} else {
holder.btnExpandMenu.visibility = View.GONE
val backgroundColor = Color.parseColor(color)
if (PreferenceManager.getDefaultSharedPreferences(holder.itemView.context).getBoolean("settings_color_category", true)) {
holder.btnColorSelector.icon = null
holder.btnColorSelector.setBackgroundColor(backgroundColor)
if (isDarkMode(holder.textViewCategoryName.context)) {
holder.textViewCategoryName.setTextColor(backgroundColor)
} else {
holder.itemView.setBackgroundColor(backgroundColor)
}
} else {
holder.btnExpandMenu.visibility = View.GONE
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ class NoteAdapter(

if (colorCategory) {
mainActivityViewModel.categoryColor(currentNote.category) {
val color: Int = it?.let { Color.parseColor(it) } ?: run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorOnSurface, value, true)
value.data
}

if (DarkModeUtil.isDarkMode(holder.textViewTitle.context)) {
val color: Int = it?.let { Color.parseColor(it) } ?: run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorOnBackground, value, true)
value.data
}
holder.textViewTitle.setTextColor(color)
holder.textViewExtraText.setTextColor(color)
} else {
val color: Int = it?.let { Color.parseColor(it) } ?: run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorSurface, value, true)
value.data
}
holder.viewNoteItem.setBackgroundColor(color)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package org.secuso.privacyfriendlynotes.ui.manageCategories
import android.content.DialogInterface
import android.os.Bundle
import android.preference.PreferenceManager
import android.util.Log
import android.util.TypedValue
import android.view.View
import android.widget.EditText
import android.widget.ImageButton
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.toColorInt
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
Expand All @@ -46,7 +48,6 @@ class ManageCategoriesActivity : AppCompatActivity(), View.OnClickListener, OnDi
private val manageCategoriesViewModel: ManageCategoriesViewModel by lazy { ViewModelProvider(this)[ManageCategoriesViewModel::class.java] }
private val etName: EditText by lazy { findViewById(R.id.etName) }
private val recyclerList: RecyclerView by lazy { findViewById(R.id.recyclerview_category) }
private val btnResetColor: ImageButton by lazy { findViewById(R.id.category_menu_color_reset) }
private val btnColorSelector: MaterialButton by lazy { findViewById(R.id.btn_color_selector) }
private val btnExpandMenu: ImageButton by lazy { findViewById(R.id.category_expand_menu_button) }
private val expandMenu: LinearLayout by lazy { findViewById(R.id.category_expand_menu) }
Expand Down Expand Up @@ -94,11 +95,6 @@ class ManageCategoriesActivity : AppCompatActivity(), View.OnClickListener, OnDi
theme.resolveAttribute(R.attr.colorOnSurface, value, true)
btnColorSelector.setBackgroundColor(value.data)
btnExpandMenu.setOnClickListener { expandMenu.visibility = if (expandMenu.visibility == View.GONE) { View.VISIBLE } else { View.GONE } }
btnResetColor.setOnClickListener {
btnColorSelector.setBackgroundColor(resources.getColor(R.color.transparent))
manageCategoriesViewModel
catColor = null
}
btnColorSelector.setOnClickListener { displayColorDialog() }
} else {
btnExpandMenu.visibility = View.GONE
Expand All @@ -124,7 +120,7 @@ class ManageCategoriesActivity : AppCompatActivity(), View.OnClickListener, OnDi
if (sp.getBoolean(SettingsActivity.PREF_DEL_NOTES, false)) {
lifecycleScope.launch {
manageCategoriesViewModel.notes.collect {
notes -> notes.filter { it.category == cat._id }.forEach { manageCategoriesViewModel.delete(it) }
notes -> notes.filter { it.category == cat._id }.forEach { manageCategoriesViewModel.delete(it) }
}
}
}
Expand All @@ -138,21 +134,29 @@ class ManageCategoriesActivity : AppCompatActivity(), View.OnClickListener, OnDi
.cancelable(true) //allows close by tapping outside of dialog
.colors(this, R.array.mdcolor_500)
.choiceMode(SimpleColorDialog.SINGLE_CHOICE_DIRECT) //auto-close on selection
.neut(R.string.default_color)
.extra(bundle)
.show(this, TAG_COLORDIALOG)
}

override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean {
if (dialogTag == TAG_COLORDIALOG && which == DialogInterface.BUTTON_POSITIVE) {
val color = extras.getInt(SimpleColorDialog.COLOR)
// 0 is dismiss
if (dialogTag == TAG_COLORDIALOG && which != DialogInterface.BUTTON_NEGATIVE && which != 0) {
val color = if (which == DialogInterface.BUTTON_POSITIVE) "#${Integer.toHexString(extras.getInt(SimpleColorDialog.COLOR))}" else null;
val position = extras.getInt(CATEGORY_COLOR, -1)

// Check if the user changes a category color
if (position != -1) {
manageCategoriesViewModel.update(adapter.categories[position], "#${Integer.toHexString(color)}")
manageCategoriesViewModel.update(adapter.categories[position], color)
} else {
btnColorSelector.setBackgroundColor(color)
catColor = "#${Integer.toHexString(color)}"
if (color == null) {
btnColorSelector.setIconResource(R.drawable.transparent_checker)
btnColorSelector.setBackgroundColor(resources.getColor(R.color.transparent))
} else {
btnColorSelector.icon = null
btnColorSelector.setBackgroundColor(color.toColorInt())
}
catColor = color
}
return true
}
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/drawable/transparent_checker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="40"
android:viewportHeight="40"
android:width="40dp"
android:height="40dp">
<path
android:pathData="M0 0H100V100H0V0Z"
android:fillColor="#FFFFFF" />
<path
android:pathData="M0 0h10v10H0z"
android:fillColor="#969696" />
<path
android:pathData="M10 10h10v10H10z"
android:fillColor="#969696" />
<path
android:pathData="M20 20h10v10H20z"
android:fillColor="#969696" />
<path
android:pathData="M30 30h10v10H30z"
android:fillColor="#969696" />
<path
android:pathData="M30 10h10v10H30z"
android:fillColor="#969696" />
<path
android:pathData="M20 0h10v10H20z"
android:fillColor="#969696" />
<path
android:pathData="M0 20h10v10H0z"
android:fillColor="#969696" />
<path
android:pathData="M10 30h10v10H10z"
android:fillColor="#969696" />

</vector>
36 changes: 19 additions & 17 deletions app/src/main/res/layout/activity_manage_categories.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,26 @@
android:layout_height="match_parent"
android:layout_weight="0.55"/>

<ImageButton
android:id="@+id/category_menu_color_reset"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:backgroundTint="?attr/colorIconFill"
android:background="@drawable/ic_baseline_format_color_reset_icon_24dp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_color_selector"
<androidx.cardview.widget.CardView
android:id="@+id/btn_color_selector_transparent"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="0dp"
android:padding="0dp"
app:cornerRadius="10dp"
android:theme="@style/AppTheme.CategoryButton"
/>
android:layout_height="30dp"
app:cardCornerRadius="5dp"
>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_color_selector"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginStart="0dp"
android:layout_gravity="center_vertical"
android:padding="0dp"
app:icon="@drawable/transparent_checker"
app:iconTint="@color/transparent"
app:iconTintMode="add"
app:iconPadding="0dp"
android:theme="@style/AppTheme.CategoryButton"
/>
</androidx.cardview.widget.CardView>

</LinearLayout>

Expand Down
28 changes: 19 additions & 9 deletions app/src/main/res/layout/item_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,26 @@
android:backgroundTint="?attr/colorIconFill"
android:background="@drawable/ic_baseline_format_color_reset_icon_24dp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/category_item_color_selector"
<androidx.cardview.widget.CardView
android:id="@+id/btn_color_selector_transparent"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="0dp"
android:padding="0dp"
app:cornerRadius="10dp"
android:theme="@style/AppTheme.CategoryButton"
/>
android:layout_height="30dp"
app:cardCornerRadius="5dp"
>
<com.google.android.material.button.MaterialButton
android:id="@+id/category_item_color_selector"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginStart="0dp"
android:layout_gravity="center_vertical"
android:padding="0dp"
app:icon="@drawable/transparent_checker"
app:iconTint="@color/transparent"
app:iconTintMode="add"
app:iconPadding="0dp"
android:theme="@style/AppTheme.CategoryButton"
/>
</androidx.cardview.widget.CardView>

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="app_name_long">Privacy Friendly Notizen</string>
<string name="action_update">Speichern</string>
<string name="default_category">Standard</string>
<string name="default_color">Standard</string>
<string name="dialog_delete_message">Wollen Sie %1s endgültig löschen?</string>
<string name="dialog_delete_title">%1s löschen?</string>
<string name="dialog_need_category_message">Sie müssen mindestens eine Kategorie erstellen. Möchten Sie dies jetzt tun?</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<string name="app_name">Notes</string>
<string name="app_name_long">Privacy Friendly Notes</string>
<string name="default_category">デフォルト</string>
<string name="default_color">デフォルト</string>

<string name="title_manage_categories">カテゴリー</string>
<string name="title_textnote">テキスト メモ</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<string name="app_name">Notes</string>
<string name="app_name_long">Privacy Friendly Notes</string>
<string name="default_category">Default</string>
<string name="default_color">Default</string>

<string name="title_manage_categories">Categories</string>
<string name="title_textnote">Text Note</string>
Expand Down

0 comments on commit 4d324c0

Please sign in to comment.