diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt index 8bc7de93..c009a20b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt @@ -17,6 +17,7 @@ import com.simplemobiletools.notes.pro.extensions.config import com.simplemobiletools.notes.pro.extensions.updateWidgets import com.simplemobiletools.notes.pro.extensions.widgetsDB import com.simplemobiletools.notes.pro.helpers.* +import com.simplemobiletools.notes.pro.models.Widget import kotlinx.android.synthetic.main.activity_settings.* import java.util.* @@ -200,15 +201,29 @@ class SettingsActivity : SimpleActivity() { } private fun setupCustomizeWidgetColors() { + var widgetToCustomize: Widget? = null + settings_customize_widget_colors_holder.setOnClickListener { Intent(this, WidgetConfigureActivity::class.java).apply { putExtra(IS_CUSTOMIZING_COLORS, true) + + widgetToCustomize?.apply { + putExtra(CUSTOMIZED_WIDGET_ID, widgetId) + putExtra(CUSTOMIZED_WIDGET_KEY_ID, id) + putExtra(CUSTOMIZED_WIDGET_NOTE_ID, noteId) + putExtra(CUSTOMIZED_WIDGET_BG_COLOR, widgetBgColor) + putExtra(CUSTOMIZED_WIDGET_TEXT_COLOR, widgetTextColor) + } + startActivity(this) } } ensureBackgroundThread { - if (widgetsDB.getWidgets().size > 1) { + val widgets = widgetsDB.getWidgets().filter { it.widgetId != 0 } + if (widgets.size == 1) { + widgetToCustomize = widgets.first() + } else if (widgets.size > 1) { arrayListOf(widgets_divider, widgets_label, settings_customize_widget_colors_holder).forEach { it.beGone() } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt index 9fe4a273..de811f5f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt @@ -22,9 +22,7 @@ import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter import com.simplemobiletools.notes.pro.extensions.config import com.simplemobiletools.notes.pro.extensions.getTextSize import com.simplemobiletools.notes.pro.extensions.widgetsDB -import com.simplemobiletools.notes.pro.helpers.MyWidgetProvider -import com.simplemobiletools.notes.pro.helpers.NotesHelper -import com.simplemobiletools.notes.pro.helpers.TYPE_CHECKLIST +import com.simplemobiletools.notes.pro.helpers.* import com.simplemobiletools.notes.pro.models.ChecklistItem import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Widget @@ -72,7 +70,15 @@ class WidgetConfigureActivity : SimpleActivity() { } private fun initVariables() { - mBgColor = config.widgetBgColor + val extras = intent.extras + if (extras?.getLong(CUSTOMIZED_WIDGET_ID, 0L) == 0L) { + mBgColor = config.widgetBgColor + mTextColor = config.widgetTextColor + } else { + mBgColor = extras?.getInt(CUSTOMIZED_WIDGET_BG_COLOR) ?: config.widgetBgColor + mTextColor = extras?.getInt(CUSTOMIZED_WIDGET_TEXT_COLOR) ?: config.widgetTextColor + } + if (mBgColor == 1) { mBgColor = Color.BLACK mBgAlpha = .2f @@ -91,9 +97,8 @@ class WidgetConfigureActivity : SimpleActivity() { } updateBackgroundColor() - mTextColor = config.widgetTextColor updateTextColor() - mIsCustomizingColors = intent.extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false + mIsCustomizingColors = extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false notes_picker_holder.beVisibleIf(!mIsCustomizingColors) NotesHelper(this).getNotes { @@ -150,7 +155,12 @@ class WidgetConfigureActivity : SimpleActivity() { views.setBackgroundColor(R.id.text_note_view, mBgColor) views.setBackgroundColor(R.id.checklist_note_view, mBgColor) AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views) - val widget = Widget(null, mWidgetId, mCurrentNoteId, mBgColor, mTextColor) + + val extras = intent.extras + val id = if (extras?.containsKey(CUSTOMIZED_WIDGET_KEY_ID) == true) extras.getLong(CUSTOMIZED_WIDGET_KEY_ID) else null + mWidgetId = extras?.getInt(CUSTOMIZED_WIDGET_ID, mWidgetId) ?: mWidgetId + mCurrentNoteId = extras?.getLong(CUSTOMIZED_WIDGET_NOTE_ID, mCurrentNoteId) ?: mCurrentNoteId + val widget = Widget(id, mWidgetId, mCurrentNoteId, mBgColor, mTextColor) ensureBackgroundThread { widgetsDB.insertOrUpdate(widget) } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt index 026bbd88..1a49e375 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt @@ -5,6 +5,11 @@ import android.graphics.Color const val NOTE_ID = "note_id" const val OPEN_NOTE_ID = "open_note_id" const val DONE_CHECKLIST_ITEM_ALPHA = 0.4f +const val CUSTOMIZED_WIDGET_ID = "customized_widget_id" +const val CUSTOMIZED_WIDGET_KEY_ID = "customized_widget_key_id" +const val CUSTOMIZED_WIDGET_NOTE_ID = "customized_widget_note_id" +const val CUSTOMIZED_WIDGET_BG_COLOR = "customized_widget_bg_color" +const val CUSTOMIZED_WIDGET_TEXT_COLOR = "customized_widget_text_color" val DEFAULT_WIDGET_TEXT_COLOR = Color.parseColor("#FFF57C00") // shared preferences