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