Skip to content

Commit cba300d

Browse files
committed
show the widget color change button in settings only at 1 widget
1 parent 7fac9e3 commit cba300d

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.simplemobiletools.notes.pro.extensions.config
1717
import com.simplemobiletools.notes.pro.extensions.updateWidgets
1818
import com.simplemobiletools.notes.pro.extensions.widgetsDB
1919
import com.simplemobiletools.notes.pro.helpers.*
20+
import com.simplemobiletools.notes.pro.models.Widget
2021
import kotlinx.android.synthetic.main.activity_settings.*
2122
import java.util.*
2223

@@ -200,15 +201,29 @@ class SettingsActivity : SimpleActivity() {
200201
}
201202

202203
private fun setupCustomizeWidgetColors() {
204+
var widgetToCustomize: Widget? = null
205+
203206
settings_customize_widget_colors_holder.setOnClickListener {
204207
Intent(this, WidgetConfigureActivity::class.java).apply {
205208
putExtra(IS_CUSTOMIZING_COLORS, true)
209+
210+
widgetToCustomize?.apply {
211+
putExtra(CUSTOMIZED_WIDGET_ID, widgetId)
212+
putExtra(CUSTOMIZED_WIDGET_KEY_ID, id)
213+
putExtra(CUSTOMIZED_WIDGET_NOTE_ID, noteId)
214+
putExtra(CUSTOMIZED_WIDGET_BG_COLOR, widgetBgColor)
215+
putExtra(CUSTOMIZED_WIDGET_TEXT_COLOR, widgetTextColor)
216+
}
217+
206218
startActivity(this)
207219
}
208220
}
209221

210222
ensureBackgroundThread {
211-
if (widgetsDB.getWidgets().size > 1) {
223+
val widgets = widgetsDB.getWidgets().filter { it.widgetId != 0 }
224+
if (widgets.size == 1) {
225+
widgetToCustomize = widgets.first()
226+
} else if (widgets.size > 1) {
212227
arrayListOf(widgets_divider, widgets_label, settings_customize_widget_colors_holder).forEach {
213228
it.beGone()
214229
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter
2222
import com.simplemobiletools.notes.pro.extensions.config
2323
import com.simplemobiletools.notes.pro.extensions.getTextSize
2424
import com.simplemobiletools.notes.pro.extensions.widgetsDB
25-
import com.simplemobiletools.notes.pro.helpers.MyWidgetProvider
26-
import com.simplemobiletools.notes.pro.helpers.NotesHelper
27-
import com.simplemobiletools.notes.pro.helpers.TYPE_CHECKLIST
25+
import com.simplemobiletools.notes.pro.helpers.*
2826
import com.simplemobiletools.notes.pro.models.ChecklistItem
2927
import com.simplemobiletools.notes.pro.models.Note
3028
import com.simplemobiletools.notes.pro.models.Widget
@@ -72,7 +70,15 @@ class WidgetConfigureActivity : SimpleActivity() {
7270
}
7371

7472
private fun initVariables() {
75-
mBgColor = config.widgetBgColor
73+
val extras = intent.extras
74+
if (extras?.getLong(CUSTOMIZED_WIDGET_ID, 0L) == 0L) {
75+
mBgColor = config.widgetBgColor
76+
mTextColor = config.widgetTextColor
77+
} else {
78+
mBgColor = extras?.getInt(CUSTOMIZED_WIDGET_BG_COLOR) ?: config.widgetBgColor
79+
mTextColor = extras?.getInt(CUSTOMIZED_WIDGET_TEXT_COLOR) ?: config.widgetTextColor
80+
}
81+
7682
if (mBgColor == 1) {
7783
mBgColor = Color.BLACK
7884
mBgAlpha = .2f
@@ -91,9 +97,8 @@ class WidgetConfigureActivity : SimpleActivity() {
9197
}
9298
updateBackgroundColor()
9399

94-
mTextColor = config.widgetTextColor
95100
updateTextColor()
96-
mIsCustomizingColors = intent.extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
101+
mIsCustomizingColors = extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
97102
notes_picker_holder.beVisibleIf(!mIsCustomizingColors)
98103

99104
NotesHelper(this).getNotes {
@@ -150,7 +155,12 @@ class WidgetConfigureActivity : SimpleActivity() {
150155
views.setBackgroundColor(R.id.text_note_view, mBgColor)
151156
views.setBackgroundColor(R.id.checklist_note_view, mBgColor)
152157
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
153-
val widget = Widget(null, mWidgetId, mCurrentNoteId, mBgColor, mTextColor)
158+
159+
val extras = intent.extras
160+
val id = if (extras?.containsKey(CUSTOMIZED_WIDGET_KEY_ID) == true) extras.getLong(CUSTOMIZED_WIDGET_KEY_ID) else null
161+
mWidgetId = extras?.getInt(CUSTOMIZED_WIDGET_ID, mWidgetId) ?: mWidgetId
162+
mCurrentNoteId = extras?.getLong(CUSTOMIZED_WIDGET_NOTE_ID, mCurrentNoteId) ?: mCurrentNoteId
163+
val widget = Widget(id, mWidgetId, mCurrentNoteId, mBgColor, mTextColor)
154164
ensureBackgroundThread {
155165
widgetsDB.insertOrUpdate(widget)
156166
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import android.graphics.Color
55
const val NOTE_ID = "note_id"
66
const val OPEN_NOTE_ID = "open_note_id"
77
const val DONE_CHECKLIST_ITEM_ALPHA = 0.4f
8+
const val CUSTOMIZED_WIDGET_ID = "customized_widget_id"
9+
const val CUSTOMIZED_WIDGET_KEY_ID = "customized_widget_key_id"
10+
const val CUSTOMIZED_WIDGET_NOTE_ID = "customized_widget_note_id"
11+
const val CUSTOMIZED_WIDGET_BG_COLOR = "customized_widget_bg_color"
12+
const val CUSTOMIZED_WIDGET_TEXT_COLOR = "customized_widget_text_color"
813
val DEFAULT_WIDGET_TEXT_COLOR = Color.parseColor("#FFF57C00")
914

1015
// shared preferences

0 commit comments

Comments
 (0)