Skip to content

Commit

Permalink
Merge pull request #13 from TradeMe/dark-mode
Browse files Browse the repository at this point in the history
Add Dark Mode support to Konfigure-Android
  • Loading branch information
Jamie Sanson authored Mar 11, 2020
2 parents 0611156 + 27203b8 commit c6d0c8d
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 72 deletions.
2 changes: 1 addition & 1 deletion common.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ext.version = "1.0.0"
ext.version = "1.1.0"
ext.group = "nz.co.trademe.konfigure"
ext.repo = "Konfigure"
ext.org = "trademe"
Expand Down
2 changes: 1 addition & 1 deletion konfigure-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"
}
3 changes: 1 addition & 2 deletions konfigure-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<application>
<activity
android:name=".ui.ConfigActivity"
android:theme="@style/Theme.Config.NoActionBar" />
android:name=".ui.ConfigActivity" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package nz.co.trademe.konfigure.android.ui.adapter.viewholder

import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources
import nz.co.trademe.konfigure.android.R

internal class DividerViewHolder(
parent: ViewGroup
) : BaseViewHolder(parent.inflate(R.layout.view_holder_divider))
) : BaseViewHolder(parent.inflate(R.layout.view_holder_divider)) {

init {
itemView.setBackgroundColor(AppCompatResources.getColorStateList(itemView.context, R.color.color_divider).defaultColor)
}
}
4 changes: 4 additions & 0 deletions konfigure-android/src/main/res/color/color_divider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.18" android:color="?colorOnSurface"/>
</selector>
25 changes: 15 additions & 10 deletions konfigure-android/src/main/res/layout/activity_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:theme="@style/Theme.MaterialComponents.DayNight"
android:background="?android:colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_5pc">
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/emptyStateLayout"
Expand All @@ -14,15 +15,16 @@
android:layout_marginTop="128dp"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible"
tools:ignore="UseCompoundDrawables">
tools:ignore="UseCompoundDrawables"
tools:visibility="visible">

<ImageView
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_gravity="center"
android:alpha="0.54"
android:contentDescription="@null"
android:tint="@color/black_54pc"
android:tint="?colorOnSurface"
android:tintMode="src_in"
app:srcCompat="@drawable/ic_search_black_24dp"
tools:targetApi="lollipop" />
Expand All @@ -31,8 +33,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:text="@string/no_results_found" />
android:text="@string/no_results_found"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
</LinearLayout>

<nz.co.trademe.konfigure.android.ui.view.ConfigView
Expand All @@ -45,13 +47,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:minHeight="?actionBarSize"
android:theme="@style/MainToolbar"
app:layout_scrollFlags="scroll|enterAlways" />
style="@style/Widget.MaterialComponents.Toolbar.PrimarySurface"
android:theme="@style/ThemeOverlay.Konfigure.Toolbar.PrimarySurface"
app:layout_scrollFlags="scroll|enterAlways"
tools:targetApi="lollipop" />

</com.google.android.material.appbar.AppBarLayout>

Expand Down
4 changes: 3 additions & 1 deletion konfigure-android/src/main/res/layout/edit_config_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/configTextInputLayout"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/configTextInputEditText"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:clickable="true"
android:focusable="true"
android:background="?colorSurface"
android:foreground="?selectableItemBackground"
android:orientation="horizontal"
android:padding="16dp">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black_18pc"/>
android:layout_height="1dp"/>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:background="?colorSurface"
android:orientation="vertical">

<TextView
Expand Down
4 changes: 2 additions & 2 deletions konfigure-android/src/main/res/layout/view_holder_number.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:clickable="true"
android:focusable="true"
android:background="?colorSurface"
android:foreground="?selectableItemBackground"
android:orientation="vertical"
android:padding="16dp">
Expand Down Expand Up @@ -33,7 +33,7 @@
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:textColor="@color/black_54pc"
android:textColor="?android:textColorSecondary"
tools:text="1234" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/white">
android:background="?colorSurface">

<TextView
android:id="@+id/descriptionTextView"
Expand Down Expand Up @@ -40,7 +40,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:strokeColor="?colorAccent" />
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions konfigure-android/src/main/res/layout/view_holder_string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
android:background="?colorSurface"
android:orientation="vertical"
android:padding="16dp">

Expand All @@ -33,7 +33,7 @@
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:textColor="@color/black_54pc"
android:textColor="?android:textColorSecondary"
tools:text="Current value: '{'0001': [4, 10]}'" />

</LinearLayout>
7 changes: 4 additions & 3 deletions konfigure-android/src/main/res/menu/menu_config.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search_black_24dp"
app:showAsAction="always|collapseActionView"
android:title="@string/search"
app:iconTint="?colorOnPrimarySurface"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="@string/search"/>
app:showAsAction="always|collapseActionView" />
</menu>
7 changes: 0 additions & 7 deletions konfigure-android/src/main/res/values/colors.xml

This file was deleted.

20 changes: 0 additions & 20 deletions konfigure-android/src/main/res/values/styles.xml

This file was deleted.

8 changes: 8 additions & 0 deletions konfigure-android/src/main/res/values/theme_overlays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="ThemeOverlay.Konfigure.Toolbar.PrimarySurface" parent="">
<item name="colorControlNormal">?colorOnPrimarySurface</item>
<item name="actionMenuTextColor">?colorOnPrimarySurface</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0'

implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha03'
Expand Down
16 changes: 16 additions & 0 deletions sample/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/purple_300</item>
<item name="colorPrimaryDark">@color/purple_300_dark</item>
<item name="colorAccent">@color/light_blue_200</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">?colorSurface</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

</resources>
13 changes: 10 additions & 3 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<!-- Light mode -->
<color name="purple_600">#8e24aa</color>
<color name="purple_600_dark">#5c007a</color>
<color name="light_blue_500">#03a9f4</color>

<!-- Dark mode -->
<color name="purple_300">#ba68c8</color>
<color name="purple_300_dark">#883997</color>
<color name="light_blue_200">#81d4fa</color>

</resources>
18 changes: 7 additions & 11 deletions sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/purple_600</item>
<item name="colorPrimaryDark">@color/purple_600_dark</item>
<item name="colorAccent">@color/light_blue_500</item>
</style>

<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

</resources>

0 comments on commit c6d0c8d

Please sign in to comment.