mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 17:48:52 -06:00
Follow current theme; implement color switching
This commit is contained in:
@@ -17,9 +17,12 @@
|
|||||||
android:theme="@style/AppBaseTheme">
|
android:theme="@style/AppBaseTheme">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
|
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:name=".activities.habits.edit.EditHabitActivity" />
|
android:name=".activities.habits.edit.EditHabitActivity">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value=".activities.habits.list.ListHabitsActivity" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.backup.api_key"
|
android:name="com.google.android.backup.api_key"
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.activities
|
package org.isoron.uhabits.activities
|
||||||
|
|
||||||
|
import android.app.*
|
||||||
import android.content.res.Configuration.*
|
import android.content.res.Configuration.*
|
||||||
import android.os.Build.VERSION.*
|
import android.os.Build.VERSION.*
|
||||||
import androidx.core.content.*
|
import androidx.core.content.*
|
||||||
@@ -30,8 +31,8 @@ import javax.inject.*
|
|||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
class AndroidThemeSwitcher
|
class AndroidThemeSwitcher
|
||||||
@Inject constructor(
|
constructor(
|
||||||
private val activity: BaseActivity,
|
private val activity: Activity,
|
||||||
preferences: Preferences
|
preferences: Preferences
|
||||||
) : ThemeSwitcher(preferences) {
|
) : ThemeSwitcher(preferences) {
|
||||||
|
|
||||||
|
|||||||
@@ -51,5 +51,5 @@ interface HabitsActivityComponent {
|
|||||||
val listHabitsScreen: ListHabitsScreen
|
val listHabitsScreen: ListHabitsScreen
|
||||||
val listHabitsSelectionMenu: ListHabitsSelectionMenu
|
val listHabitsSelectionMenu: ListHabitsSelectionMenu
|
||||||
val showHabitScreen: ShowHabitScreen
|
val showHabitScreen: ShowHabitScreen
|
||||||
val themeSwitcher: AndroidThemeSwitcher
|
val themeSwitcher: ThemeSwitcher
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,17 @@ package org.isoron.uhabits.activities
|
|||||||
|
|
||||||
import dagger.*
|
import dagger.*
|
||||||
import org.isoron.androidbase.activities.*
|
import org.isoron.androidbase.activities.*
|
||||||
|
import org.isoron.uhabits.core.preferences.*
|
||||||
import org.isoron.uhabits.core.ui.*
|
import org.isoron.uhabits.core.ui.*
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
abstract class HabitsActivityModule {
|
class HabitsActivityModule {
|
||||||
@Binds @ActivityScope
|
|
||||||
internal abstract fun getThemeSwitcher(t: AndroidThemeSwitcher): ThemeSwitcher
|
@Provides
|
||||||
|
@ActivityScope
|
||||||
|
fun getThemeSwitcher(activity: BaseActivity,
|
||||||
|
prefs: Preferences
|
||||||
|
): ThemeSwitcher {
|
||||||
|
return AndroidThemeSwitcher(activity, prefs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,23 +19,58 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.activities.habits.edit
|
package org.isoron.uhabits.activities.habits.edit
|
||||||
|
|
||||||
|
import android.content.res.*
|
||||||
import android.graphics.*
|
import android.graphics.*
|
||||||
import android.os.*
|
import android.os.*
|
||||||
import androidx.appcompat.app.*
|
import androidx.appcompat.app.*
|
||||||
import androidx.appcompat.widget.*
|
import kotlinx.android.synthetic.main.activity_edit_habit.*
|
||||||
|
import org.isoron.androidbase.utils.*
|
||||||
import org.isoron.uhabits.*
|
import org.isoron.uhabits.*
|
||||||
|
import org.isoron.uhabits.activities.*
|
||||||
|
import org.isoron.uhabits.activities.common.dialogs.*
|
||||||
|
import org.isoron.uhabits.core.preferences.*
|
||||||
|
import org.isoron.uhabits.core.ui.*
|
||||||
|
import org.isoron.uhabits.preferences.*
|
||||||
|
import org.isoron.uhabits.utils.*
|
||||||
|
|
||||||
class EditHabitActivity : AppCompatActivity() {
|
class EditHabitActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var themeSwitcher: AndroidThemeSwitcher
|
||||||
|
|
||||||
|
var paletteColor = 11
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
val prefs = Preferences(SharedPreferencesStorage(this))
|
||||||
|
themeSwitcher = AndroidThemeSwitcher(this, prefs)
|
||||||
|
themeSwitcher.apply()
|
||||||
|
|
||||||
setContentView(R.layout.activity_edit_habit)
|
setContentView(R.layout.activity_edit_habit)
|
||||||
|
updateColors()
|
||||||
|
|
||||||
window.statusBarColor = Color.parseColor("#B4285A")
|
|
||||||
|
|
||||||
val toolbar = findViewById<Toolbar>(R.id.toolbar)
|
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
supportActionBar?.elevation = 10.0f
|
supportActionBar?.elevation = 10.0f
|
||||||
|
|
||||||
|
val colorPickerDialogFactory = ColorPickerDialogFactory(this)
|
||||||
|
colorButton.setOnClickListener {
|
||||||
|
val dialog = colorPickerDialogFactory.create(paletteColor)
|
||||||
|
dialog.setListener { paletteColor ->
|
||||||
|
this.paletteColor = paletteColor
|
||||||
|
updateColors()
|
||||||
|
}
|
||||||
|
dialog.show(supportFragmentManager, "colorPicker")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateColors() {
|
||||||
|
val androidColor = PaletteUtils.getColor(this, paletteColor)
|
||||||
|
colorButton.backgroundTintList = ColorStateList.valueOf(androidColor)
|
||||||
|
if(!themeSwitcher.isNightMode) {
|
||||||
|
val darkerAndroidColor = ColorUtils.mixColors(Color.BLACK, androidColor, 0.15f)
|
||||||
|
window.statusBarColor = darkerAndroidColor
|
||||||
|
toolbar.setBackgroundColor(androidColor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class EditHabitDialog extends AppCompatDialogFragment
|
|||||||
public int getTheme()
|
public int getTheme()
|
||||||
{
|
{
|
||||||
HabitsActivity activity = (HabitsActivity) getActivity();
|
HabitsActivity activity = (HabitsActivity) getActivity();
|
||||||
return activity.getComponent().getThemeSwitcher().getDialogTheme();
|
return ((AndroidThemeSwitcher) activity.getComponent().getThemeSwitcher()).getDialogTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
android:viewportWidth="24.0"
|
android:viewportWidth="24.0"
|
||||||
android:viewportHeight="24.0">
|
android:viewportHeight="24.0">
|
||||||
<path
|
<path
|
||||||
android:fillColor="#A0000000"
|
android:fillColor="?attr/mediumContrastTextColor"
|
||||||
android:pathData="M7,10l5,5 5,-5z"/>
|
android:pathData="M7,10l5,5 5,-5z"/>
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<solid android:color="#FFFFFF"/>
|
<solid android:color="?attr/highContrastReverseTextColor"/>
|
||||||
<stroke android:width="1dp" android:color="#c0c0c0" />
|
<stroke android:width="1dp" android:color="?attr/lowContrastTextColor" />
|
||||||
<corners android:radius="3dp"/>
|
<corners android:radius="4dp"/>
|
||||||
<padding
|
<padding
|
||||||
android:left="0dp"
|
android:left="0dp"
|
||||||
android:top="8dp"
|
android:top="8dp"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/white"
|
android:background="?attr/highContrastReverseTextColor"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".activities.habits.edit.EditHabitActivity">
|
tools:context=".activities.habits.edit.EditHabitActivity">
|
||||||
@@ -17,13 +17,13 @@
|
|||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="#E23673"
|
android:background="?attr/colorPrimary"
|
||||||
android:elevation="2dp"
|
android:elevation="2dp"
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:minHeight="?attr/actionBarSize"
|
android:minHeight="?attr/actionBarSize"
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||||
app:title="Edit habit"
|
app:title="@string/create_habit"
|
||||||
app:titleTextColor="@android:color/white">
|
app:titleTextColor="@color/white">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/material_text_button"
|
android:id="@+id/material_text_button"
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:text="SAVE"
|
android:text="@string/save"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
app:rippleColor="@color/white"
|
app:rippleColor="@color/white"
|
||||||
app:strokeColor="@color/white" />
|
app:strokeColor="@color/white" />
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="-17dp"
|
android:layout_marginTop="-17dp"
|
||||||
android:layout_marginBottom="-4dp"
|
android:layout_marginBottom="-4dp"
|
||||||
android:background="@color/white"
|
android:background="?attr/highContrastReverseTextColor"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
android:textSize="@dimen/smallTextSize"
|
android:textSize="@dimen/smallTextSize"
|
||||||
@@ -122,13 +122,14 @@
|
|||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="-17dp"
|
android:layout_marginTop="-17dp"
|
||||||
android:layout_marginBottom="-4dp"
|
android:layout_marginBottom="-4dp"
|
||||||
android:background="@color/white"
|
android:background="?attr/highContrastReverseTextColor"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
android:textSize="@dimen/smallTextSize"
|
android:textSize="@dimen/smallTextSize"
|
||||||
android:text="Color" />
|
android:text="Color" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatButton
|
<androidx.appcompat.widget.AppCompatButton
|
||||||
|
android:id="@+id/colorButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
@@ -168,7 +169,7 @@
|
|||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="-17dp"
|
android:layout_marginTop="-17dp"
|
||||||
android:layout_marginBottom="-4dp"
|
android:layout_marginBottom="-4dp"
|
||||||
android:background="@color/white"
|
android:background="?attr/highContrastReverseTextColor"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
android:textSize="@dimen/smallTextSize"
|
android:textSize="@dimen/smallTextSize"
|
||||||
@@ -209,20 +210,21 @@
|
|||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="-17dp"
|
android:layout_marginTop="-17dp"
|
||||||
android:layout_marginBottom="-4dp"
|
android:layout_marginBottom="-4dp"
|
||||||
android:background="@color/white"
|
android:background="?attr/highContrastReverseTextColor"
|
||||||
android:textSize="@dimen/smallTextSize"
|
android:textSize="@dimen/smallTextSize"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
android:text="@string/frequency" />
|
android:text="@string/frequency" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/frequencyPicker"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
|
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
|
||||||
android:textSize="@dimen/regularTextSize"
|
android:textSize="@dimen/regularTextSize"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:text="@string/every_day"
|
android:text="@string/every_day"
|
||||||
android:textColor="@color/black" />
|
android:textColor="?attr/highContrastTextColor" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
@@ -249,7 +251,7 @@
|
|||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="-17dp"
|
android:layout_marginTop="-17dp"
|
||||||
android:layout_marginBottom="-4dp"
|
android:layout_marginBottom="-4dp"
|
||||||
android:background="@color/white"
|
android:background="?attr/highContrastReverseTextColor"
|
||||||
android:textSize="@dimen/smallTextSize"
|
android:textSize="@dimen/smallTextSize"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
@@ -261,7 +263,7 @@
|
|||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
|
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
|
||||||
android:textSize="@dimen/regularTextSize"
|
android:textSize="@dimen/regularTextSize"
|
||||||
android:textColor="@color/black"
|
android:textColor="?attr/highContrastTextColor"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:text="@string/reminder_off" />
|
android:text="@string/reminder_off" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -291,7 +293,7 @@
|
|||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="-17dp"
|
android:layout_marginTop="-17dp"
|
||||||
android:layout_marginBottom="-4dp"
|
android:layout_marginBottom="-4dp"
|
||||||
android:background="@color/white"
|
android:background="?attr/highContrastReverseTextColor"
|
||||||
android:textSize="@dimen/smallTextSize"
|
android:textSize="@dimen/smallTextSize"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
@@ -302,7 +304,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/transparent"
|
android:background="@color/transparent"
|
||||||
android:textSize="@dimen/regularTextSize"
|
android:textSize="@dimen/regularTextSize"
|
||||||
android:textColor="@color/black"
|
android:textColor="?attr/highContrastTextColor"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:hint="(Optional)" />
|
android:hint="(Optional)" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
<style name="AppBaseTheme" parent="@style/Theme.MaterialComponents.Light.NoActionBar">
|
||||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||||
<item name="android:dialogTheme">@style/Theme.AppCompat.Light.Dialog</item>
|
<item name="android:dialogTheme">@style/Theme.AppCompat.Light.Dialog</item>
|
||||||
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog</item>
|
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog</item>
|
||||||
@@ -30,9 +30,9 @@
|
|||||||
<item name="selectedBackground">@drawable/selected_box_light</item>
|
<item name="selectedBackground">@drawable/selected_box_light</item>
|
||||||
<item name="cardBackground">@drawable/card_light_background</item>
|
<item name="cardBackground">@drawable/card_light_background</item>
|
||||||
|
|
||||||
<item name="colorPrimary">@color/blue_grey_800</item>
|
<item name="colorPrimary">#363636</item>
|
||||||
<item name="colorPrimaryDark">@color/blue_grey_900</item>
|
<item name="colorPrimaryDark">#303030</item>
|
||||||
<item name="colorAccent">?aboutScreenColor</item>
|
<item name="colorAccent">#303030</item>
|
||||||
<item name="cardBgColor">@color/grey_50</item>
|
<item name="cardBgColor">@color/grey_50</item>
|
||||||
<item name="windowBackgroundColor">@color/grey_200</item>
|
<item name="windowBackgroundColor">@color/grey_200</item>
|
||||||
<item name="headerBackgroundColor">@color/grey_200</item>
|
<item name="headerBackgroundColor">@color/grey_200</item>
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
<item name="android:textSize">@dimen/smallTextSize</item>
|
<item name="android:textSize">@dimen/smallTextSize</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppBaseThemeDark" parent="@style/Theme.AppCompat.NoActionBar">
|
<style name="AppBaseThemeDark" parent="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar">
|
||||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||||
<item name="android:dialogTheme">@style/Theme.AppCompat.Dialog</item>
|
<item name="android:dialogTheme">@style/Theme.AppCompat.Dialog</item>
|
||||||
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Dialog</item>
|
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Dialog</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user