Skip to content

Commit 5d82f2a

Browse files
committed
add a Settings button for customizing widget color without recreating it
1 parent 6fa76a8 commit 5d82f2a

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.simplemobiletools.flashlight.activities
22

3+
import android.content.Intent
34
import android.os.Bundle
45
import com.simplemobiletools.commons.extensions.beVisibleIf
56
import com.simplemobiletools.commons.extensions.updateTextColors
7+
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
68
import com.simplemobiletools.flashlight.R
79
import com.simplemobiletools.flashlight.extensions.config
810
import kotlinx.android.synthetic.main.activity_settings.*
@@ -18,6 +20,7 @@ class SettingsActivity : SimpleActivity() {
1820
super.onResume()
1921

2022
setupCustomizeColors()
23+
setupCustomizeWidgetColors()
2124
setupUseEnglish()
2225
setupAvoidWhatsNew()
2326
setupTurnFlashlightOn()
@@ -33,6 +36,15 @@ class SettingsActivity : SimpleActivity() {
3336
}
3437
}
3538

39+
private fun setupCustomizeWidgetColors() {
40+
settings_customize_widget_colors_holder.setOnClickListener {
41+
Intent(this, WidgetConfigureActivity::class.java).apply {
42+
putExtra(IS_CUSTOMIZING_COLORS, true)
43+
startActivity(this)
44+
}
45+
}
46+
}
47+
3648
private fun setupUseEnglish() {
3749
settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en")
3850
settings_use_english.isChecked = config.useEnglish

app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetConfigureActivity.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.simplemobiletools.commons.dialogs.ColorPickerDialog
1010
import com.simplemobiletools.commons.extensions.adjustAlpha
1111
import com.simplemobiletools.commons.extensions.applyColorFilter
1212
import com.simplemobiletools.commons.extensions.setFillWithStroke
13+
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
1314
import com.simplemobiletools.flashlight.R
1415
import com.simplemobiletools.flashlight.extensions.config
1516
import com.simplemobiletools.flashlight.helpers.MyWidgetProvider
@@ -28,12 +29,12 @@ class WidgetConfigureActivity : SimpleActivity() {
2829
setContentView(R.layout.widget_config)
2930
initVariables()
3031

31-
val extras = intent.extras
32-
if (extras != null)
33-
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
32+
val isCustomizingColors = intent.extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
33+
mWidgetId = intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID
3434

35-
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
35+
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID && !isCustomizingColors) {
3636
finish()
37+
}
3738

3839
config_save.setOnClickListener { saveConfig() }
3940
config_widget_color.setOnClickListener { pickBackgroundColor() }

app/src/main/res/layout/activity_settings.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@
3333

3434
</RelativeLayout>
3535

36+
<RelativeLayout
37+
android:id="@+id/settings_customize_widget_colors_holder"
38+
android:layout_width="match_parent"
39+
android:layout_height="wrap_content"
40+
android:layout_marginTop="@dimen/medium_margin"
41+
android:background="?attr/selectableItemBackground"
42+
android:paddingBottom="@dimen/activity_margin"
43+
android:paddingLeft="@dimen/normal_margin"
44+
android:paddingRight="@dimen/normal_margin"
45+
android:paddingTop="@dimen/activity_margin">
46+
47+
<com.simplemobiletools.commons.views.MyTextView
48+
android:id="@+id/settings_customize_widget_colors_label"
49+
android:layout_width="wrap_content"
50+
android:layout_height="wrap_content"
51+
android:layout_centerVertical="true"
52+
android:paddingLeft="@dimen/medium_margin"
53+
android:paddingStart="@dimen/medium_margin"
54+
android:text="@string/customize_widget_colors"/>
55+
56+
</RelativeLayout>
57+
3658
<RelativeLayout
3759
android:id="@+id/settings_use_english_holder"
3860
android:layout_width="match_parent"

0 commit comments

Comments
 (0)