Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrates Material design from AppCompat to MaterialComponents #141

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.github.ashutoshgngwr.noice.R
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PresetFragmentTest {

@Before
fun setup() {
fragmentScenario = launchFragmentInContainer<PresetFragment>(null, R.style.AppTheme)
fragmentScenario = launchFragmentInContainer<PresetFragment>(null, R.style.Theme_App)
.onFragment { fragment = it }

MockitoAnnotations.initMocks(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SavePresetDialogFragmentTest {

@Before
fun setup() {
fragmentScenario = launchFragmentInContainer<SavePresetDialogFragment>(null, R.style.AppTheme)
fragmentScenario = launchFragmentInContainer<SavePresetDialogFragment>(null, R.style.Theme_App)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SleepTimerFragmentTest {

@Before
fun setup() {
fragmentScenario = launchFragmentInContainer<SleepTimerFragment>(null, R.style.AppTheme)
fragmentScenario = launchFragmentInContainer<SleepTimerFragment>(null, R.style.Theme_App)
fragmentScenario.onFragment {
fragment = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SoundLibraryFragmentTest {

@Before
fun setup() {
fragmentScenario = launchFragmentInContainer<SoundLibraryFragment>(null, R.style.AppTheme, null)
fragmentScenario = launchFragmentInContainer<SoundLibraryFragment>(null, R.style.Theme_App, null)
fragmentScenario.onFragment {
fragment = it
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:theme="@style/Theme.App"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.view.GravityCompat
Expand All @@ -18,6 +17,7 @@ import com.github.ashutoshgngwr.noice.fragment.AboutFragment
import com.github.ashutoshgngwr.noice.fragment.PresetFragment
import com.github.ashutoshgngwr.noice.fragment.SleepTimerFragment
import com.github.ashutoshgngwr.noice.fragment.SoundLibraryFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_main.*

Expand Down Expand Up @@ -67,6 +67,9 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
PresetFragment::class.java.simpleName -> {
navigation_drawer.setCheckedItem(R.id.saved_presets)
}
SleepTimerFragment::class.java.simpleName -> {
navigation_drawer.setCheckedItem(R.id.sleep_timer)
}
AboutFragment::class.java.simpleName -> {
navigation_drawer.setCheckedItem(R.id.about)
}
Expand Down Expand Up @@ -103,7 +106,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
setFragment(SleepTimerFragment::class.java)
}
R.id.app_theme -> {
AlertDialog.Builder(this)
MaterialAlertDialogBuilder(this)
.setSingleChoiceItems(R.array.app_themes, getAppTheme()) { dialog, which ->
dialog.dismiss()
setAppTheme(which)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.github.ashutoshgngwr.noice.R
import com.github.ashutoshgngwr.noice.sound.Playback
import com.github.ashutoshgngwr.noice.sound.PlaybackControlEvents
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.gson.GsonBuilder
import com.google.gson.annotations.Expose
Expand Down Expand Up @@ -128,7 +128,7 @@ class PresetFragment : Fragment() {
}

itemView.button_delete.setOnClickListener {
AlertDialog.Builder(requireContext()).run {
MaterialAlertDialogBuilder(requireContext()).run {
setMessage(
getString(
R.string.preset_delete_confirmation,
Expand All @@ -151,9 +151,7 @@ class PresetFragment : Fragment() {
notifyDataSetChanged() // or call it explicitly
}

@Suppress("DEPRECATION")
Snackbar.make(requireView(), R.string.preset_deleted, Snackbar.LENGTH_LONG)
.setBackgroundTint(resources.getColor(R.color.colorPrimary))
.setAction(R.string.dismiss) { }
.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class SavePresetDialogFragment : BottomSheetDialogFragment() {
savedInstanceState: Bundle?
): View? {
// see https://github.com/material-components/material-components-android/issues/99
val ctxWrapper = ContextThemeWrapper(requireContext(), R.style.AppTheme)
// Also this is just needed to use the global background color '?android:attr/colorBackground'
val ctxWrapper = ContextThemeWrapper(requireContext(), R.style.Theme_App)
return inflater
.cloneInContext(ctxWrapper)
.inflate(R.layout.dialog_save_preset, container, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ class SoundLibraryFragment : Fragment() {
super.onDestroyView()
}

@Suppress("DEPRECATION")
fun showMessage(@StringRes messageId: Int) {
@Suppress("SameParameterValue")
private fun showMessage(@StringRes messageId: Int) {
Snackbar.make(requireView(), messageId, Snackbar.LENGTH_LONG)
.setAction(R.string.dismiss) { }
.setBackgroundTint(resources.getColor(R.color.colorPrimary))
.show()
}

Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/color/nav_view__item_text_color.xml

This file was deleted.

3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemIconTint="@color/nav_view__item_text_color"
app:itemTextColor="@color/nav_view__item_text_color"
android:background="?android:attr/colorBackground"
app:menu="@menu/main"/>

</androidx.drawerlayout.widget.DrawerLayout>
9 changes: 5 additions & 4 deletions app/src/main/res/layout/dialog_save_preset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical"
android:background="@color/colorBackground"
android:background="?android:attr/colorBackground"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

<TextView
style="@style/TextAppearance.AppCompat.Headline"
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/save_preset"/>

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="@+id/layout_edit_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -44,14 +45,14 @@
android:gravity="end|center_vertical">

<Button
style="@style/Widget.AppCompat.Button.Borderless.Colored"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"/>

<Button
style="@style/Widget.AppCompat.Button.Borderless.Colored"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:id="@+id/button_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/fragment_sleep_timer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
android:paddingTop="20dp"
android:paddingBottom="20dp">

<androidx.appcompat.widget.AppCompatTextView
style="@style/TextAppearance.AppCompat.Title"
<TextView
style="@style/TextAppearance.MaterialComponents.Headline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
Expand All @@ -31,9 +31,9 @@
android:layout_margin="20dp"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatButton
<Button
android:id="@+id/button_schedule"
style="@style/TextAppearance.AppCompat.Widget.Button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/schedule" />
Expand All @@ -42,9 +42,9 @@
android:layout_width="20dp"
android:layout_height="1dp" />

<androidx.appcompat.widget.AppCompatButton
<Button
android:id="@+id/button_reset"
style="@style/TextAppearance.AppCompat.Widget.Button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/res/layout/layout_list_item__preset.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/Widget.App.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
app:cardBackgroundColor="@color/colorCardBackground"
app:cardElevation="3dp"
app:cardCornerRadius="7dp"
app:contentPadding="15dp">
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -23,11 +18,11 @@
android:layout_height="wrap_content"
android:background="?android:selectableItemBackgroundBorderless"
android:src="@drawable/ic_action_play"
android:tint="@color/colorAccent"
android:tint="?attr/colorAccent"
android:contentDescription="@string/play_pause"/>

<TextView
style="@style/TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -44,7 +39,7 @@
android:layout_height="wrap_content"
android:background="?android:selectableItemBackgroundBorderless"
android:src="@drawable/ic_action_delete"
android:tint="@color/colorAccent"
android:tint="?attr/colorAccent"
android:contentDescription="@string/delete_preset"/>

</LinearLayout>
Expand Down
22 changes: 9 additions & 13 deletions app/src/main/res/layout/layout_list_item__sound.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.App.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
app:cardBackgroundColor="@color/colorCardBackground"
app:cardCornerRadius="7dp"
app:cardElevation="3dp"
app:contentPadding="15dp">
android:layout_height="wrap_content">

<!-- Lot of linear layouts because performance -->
<LinearLayout
Expand All @@ -25,7 +21,7 @@
android:contentDescription="@string/play_pause"
android:padding="5dp"
android:src="@drawable/ic_action_play"
android:tint="@color/colorAccent" />
android:tint="?attr/colorAccent" />

<LinearLayout
android:layout_width="0dp"
Expand All @@ -36,7 +32,7 @@

<TextView
android:id="@+id/title"
style="@style/TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
Expand All @@ -54,13 +50,13 @@
android:layout_height="wrap_content"
android:contentDescription="@string/volume"
android:src="@drawable/ic_stat_volume"
android:tint="@color/colorAccent" />
android:tint="?attr/colorAccent" />

<SeekBar
android:id="@+id/seekbar_volume"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
android:layout_weight="1"/>

</LinearLayout>

Expand All @@ -78,7 +74,7 @@
android:layout_height="wrap_content"
android:contentDescription="@string/repeat_time_period"
android:src="@drawable/ic_stat_time_period"
android:tint="@color/colorAccent" />
android:tint="?attr/colorAccent" />

<SeekBar
android:id="@+id/seekbar_time_period"
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorBackground">#373740</color>
<color name="colorCardBackground">#33333d</color>
<color name="about_background_color">#373740</color>
<color name="colorBackground">#3f3f4d</color>
<color name="colorCardBackground">#3c3c48</color>
<color name="colorHint">#828297</color>
<color name="colorNavigationViewText">@android:color/primary_text_dark</color>
<!-- Following is needed because AboutPage doesn't have any way to define custom style.
This is supposed to override its default background color -->
<color name="about_background_color">@color/colorBackground</color>
</resources>
12 changes: 7 additions & 5 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#27272f</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorPrimary">#1eb980</color>
<color name="colorPrimaryDark">#1d1d23</color>
<color name="colorAccent">#1eb980</color>
<color name="colorActionBar">#2b2b34</color>
<color name="colorBackground">#f8fAf9</color>
<color name="colorCardBackground">#f1f5f4</color>
<color name="about_background_color">#f8fAf9</color>
<color name="colorCardBackground">#fdfdfd</color>
<color name="colorHint">#7d7d68</color>
<color name="colorNavigationViewText">@android:color/primary_text_light</color>
<!-- Following is needed because AboutPage doesn't have any way to define custom style.
This is supposed to override its default background color -->
<color name="about_background_color">@color/colorBackground</color>
</resources>
Loading