Fix crashing on blacklist items clear

This commit is contained in:
h4h13 2019-05-16 23:26:22 +05:30
commit eec008ef4d
9 changed files with 126 additions and 26 deletions

View file

@ -121,15 +121,15 @@ dependencies {
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.fragment:fragment:1.1.0-alpha08' implementation 'androidx.fragment:fragment:1.1.0-alpha08'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05' implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04' implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha05'
implementation "androidx.gridlayout:gridlayout:1.0.0" implementation "androidx.gridlayout:gridlayout:1.0.0"
implementation "androidx.cardview:cardview:1.0.0" implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.palette:palette:1.0.0" implementation "androidx.palette:palette:1.0.0"
implementation 'androidx.annotation:annotation:1.1.0-beta01' implementation 'androidx.annotation:annotation:1.1.0-rc01'
implementation 'androidx.preference:preference:1.1.0-alpha05' implementation 'androidx.preference:preference:1.1.0-alpha05'
implementation "androidx.legacy:legacy-support-v13:1.0.0" implementation "androidx.legacy:legacy-support-v13:1.0.0"
implementation "androidx.legacy:legacy-preference-v14:1.0.0" implementation "androidx.legacy:legacy-preference-v14:1.0.0"
implementation 'com.google.android.material:material:1.1.0-alpha05' implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'androidx.palette:palette-ktx:1.0.0' implementation 'androidx.palette:palette-ktx:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0' implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

View file

@ -59,7 +59,7 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
val blacklistFolderChooserDialog = childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog? val blacklistFolderChooserDialog = childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog?
blacklistFolderChooserDialog?.setCallback(this) blacklistFolderChooserDialog?.setCallback(this)
refreshBlacklistData() refreshBlacklistData()
return MaterialDialog(context!!, BottomSheet()).sstathow { return MaterialDialog(context!!, BottomSheet()).show {
title(code.name.monkey.retromusic.R.string.blacklist) title(code.name.monkey.retromusic.R.string.blacklist)
positiveButton(android.R.string.ok) { positiveButton(android.R.string.ok) {
dismiss() dismiss()
@ -69,8 +69,8 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
title(code.name.monkey.retromusic.R.string.clear_blacklist) title(code.name.monkey.retromusic.R.string.clear_blacklist)
message(code.name.monkey.retromusic.R.string.do_you_want_to_clear_the_blacklist) message(code.name.monkey.retromusic.R.string.do_you_want_to_clear_the_blacklist)
positiveButton(code.name.monkey.retromusic.R.string.clear_action) { positiveButton(code.name.monkey.retromusic.R.string.clear_action) {
BlacklistStore.getInstance(context).clear(); BlacklistStore.getInstance(context).clear()
refreshBlacklistData(); refreshBlacklistData()
} }
negativeButton(android.R.string.cancel) negativeButton(android.R.string.cancel)
} }
@ -80,13 +80,13 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
dialog.setCallback(this@BlacklistPreferenceDialog) dialog.setCallback(this@BlacklistPreferenceDialog)
dialog.show(childFragmentManager, "FOLDER_CHOOSER"); dialog.show(childFragmentManager, "FOLDER_CHOOSER");
} }
listItems(items = paths) { dialog, index, text -> listItems(items = paths, waitForPositiveButton = false) { _, _, text ->
MaterialDialog(context, BottomSheet()).show { MaterialDialog(context, BottomSheet()).show {
title(code.name.monkey.retromusic.R.string.remove_from_blacklist) title(code.name.monkey.retromusic.R.string.remove_from_blacklist)
message(text = Html.fromHtml(getString(code.name.monkey.retromusic.R.string.do_you_want_to_remove_from_the_blacklist, text))) message(text = Html.fromHtml(getString(code.name.monkey.retromusic.R.string.do_you_want_to_remove_from_the_blacklist, text)))
positiveButton(code.name.monkey.retromusic.R.string.remove_action) { positiveButton(code.name.monkey.retromusic.R.string.remove_action) {
BlacklistStore.getInstance(context).removePath(File(text)); BlacklistStore.getInstance(context).removePath(File(text))
refreshBlacklistData(); refreshBlacklistData()
} }
negativeButton(android.R.string.cancel) negativeButton(android.R.string.cancel)
} }
@ -99,8 +99,8 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
private fun refreshBlacklistData() { private fun refreshBlacklistData() {
this.paths = BlacklistStore.getInstance(context!!).paths this.paths = BlacklistStore.getInstance(context!!).paths
val dialog = dialog as MaterialDialog val dialog = dialog as MaterialDialog?
dialog.listItems(items = paths) dialog?.listItems(items = paths)
} }
override fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File) { override fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File) {

View file

@ -21,16 +21,15 @@ import android.content.SharedPreferences.Editor;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.bottomnavigation.LabelVisibilityMode; import com.google.android.material.bottomnavigation.LabelVisibilityMode;
import java.io.File; import java.io.File;
import java.util.Objects; import java.util.Objects;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.viewpager.widget.ViewPager;
import code.name.monkey.retromusic.App; import code.name.monkey.retromusic.App;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.MainActivity; import code.name.monkey.retromusic.activities.MainActivity;
@ -151,23 +150,24 @@ public final class PreferenceUtil {
return R.style.Theme_RetroMusic_Black; return R.style.Theme_RetroMusic_Black;
case "black": case "black":
return R.style.Theme_RetroMusic_Black; return R.style.Theme_RetroMusic_Black;
case "daynight":
return R.style.Theme_RetroMusic_DayNight;
case "dark": case "dark":
default: default:
return R.style.Theme_RetroMusic; return R.style.Theme_RetroMusic;
} }
} }
public boolean getSleepTimerFinishMusic() {
return mPreferences.getBoolean(SLEEP_TIMER_FINISH_SONG, false);
}
public void setSleepTimerFinishMusic(final boolean value) { public void setSleepTimerFinishMusic(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit(); final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(SLEEP_TIMER_FINISH_SONG, value); editor.putBoolean(SLEEP_TIMER_FINISH_SONG, value);
editor.apply(); editor.apply();
} }
public boolean getSleepTimerFinishMusic() {
return mPreferences.getBoolean(SLEEP_TIMER_FINISH_SONG, false);
}
public String getUserBio() { public String getUserBio() {
return mPreferences.getString(USER_BIO, ""); return mPreferences.getString(USER_BIO, "");
} }

View file

@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="3dp" app:cardElevation="4dp"
app:cardUseCompatPadding="true" app:cardUseCompatPadding="true"
tools:ignore="MissingPrefix"> tools:ignore="MissingPrefix">

View file

@ -23,7 +23,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="0dp" app:cardElevation="4dp"
app:cardUseCompatPadding="true"> app:cardUseCompatPadding="true">
<ImageView <ImageView

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.RetroMusic.DayNight" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="md_corner_radius">12dp</item>
<item name="md_font_title">@font/circular</item>
<item name="md_font_body">@font/circular</item>
<item name="md_font_button">@font/circular</item>
<item name="md_color_button_text">@color/md_white_1000</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="roundSelector">@drawable/round_selector_dark</item>
<item name="rectSelector">@drawable/rect_selector_dark</item>
<item name="rectSelectorStrong">@drawable/rect_selector_strong_dark</item>
<item name="cardBackgroundColor">@color/md_grey_800</item>
<item name="defaultFooterColor">@color/md_grey_800</item>
<item name="dividerColor">@color/md_grey_800</item>
<item name="iconColor">@color/ate_secondary_text_dark</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item>
<!-- just in case-->
<item name="android:windowBackground">@color/md_grey_900</item>
<item name="colorAccent">@android:color/white</item>
<item name="colorPrimary">@android:color/black</item>
<item name="android:colorPrimary">@android:color/black</item>
<!-- necessary to find the overflow button later in the layout-->
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="bottomSheetDialogTheme">@style/BottomSheetDialog</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowExitTransition">@transition/grid_exit</item>
<item name="android:windowEnterTransition">@transition/grid_exit</item>
<item name="android:windowSharedElementEnterTransition">@transition/grid_exit</item>
<item name="android:windowSharedElementExitTransition">@transition/grid_exit</item>
<item name="android:fontFamily">@font/circular</item>
<item name="android:textColorPrimary">@color/md_white_1000</item>
</style>
</resources>

View file

@ -45,6 +45,7 @@
<item>@string/dark_theme_name</item> <item>@string/dark_theme_name</item>
<item>@string/black_theme_name</item> <item>@string/black_theme_name</item>
<item>@string/color_theme_name</item> <item>@string/color_theme_name</item>
<item>@string/day_night_theme_name</item>
</string-array> </string-array>
<string-array name="pref_grid_style_list_titles"> <string-array name="pref_grid_style_list_titles">
@ -97,6 +98,7 @@
<item>dark</item> <item>dark</item>
<item>black</item> <item>black</item>
<item>color</item> <item>color</item>
<item>daynight</item>
</string-array> </string-array>
<array name="pref_auto_download_images_values"> <array name="pref_auto_download_images_values">

View file

@ -124,6 +124,7 @@
<string name="color">Color</string> <string name="color">Color</string>
<string name="color_theme_name">Color</string> <string name="color_theme_name">Color</string>
<string name="day_night_theme_name">Day Night(alpha)</string>
<string name="colors">Colors</string> <string name="colors">Colors</string>

View file

@ -1,6 +1,55 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="Theme.RetroMusic.DayNight" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="md_corner_radius">12dp</item>
<item name="md_font_title">@font/circular</item>
<item name="md_font_body">@font/circular</item>
<item name="md_font_button">@font/circular</item>
<item name="md_color_button_text">@color/md_black_1000</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="roundSelector">@drawable/round_selector</item>
<item name="rectSelector">@drawable/rect_selector</item>
<item name="rectSelectorStrong">@drawable/rect_selector_strong</item>
<item name="cardBackgroundColor">@color/md_white_1000</item>
<item name="defaultFooterColor">@color/md_grey_500</item>
<item name="dividerColor">@color/md_grey_200</item>
<item name="iconColor">@color/ate_secondary_text_light</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<!-- just in case-->
<item name="android:windowBackground">@color/md_white_1000</item>
<item name="colorAccent">@android:color/black</item>
<item name="colorPrimary">@color/md_white_1000</item>
<!-- necessary to find the overflow button later in the layout-->
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="bottomSheetDialogTheme">@style/BottomSheetDialog</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowExitTransition">@transition/grid_exit</item>
<item name="android:windowEnterTransition">@transition/grid_exit</item>
<item name="android:windowSharedElementEnterTransition">@transition/grid_exit</item>
<item name="android:windowSharedElementExitTransition">@transition/grid_exit</item>
<item name="android:fontFamily">@font/circular</item>
<item name="android:textColorPrimary">@color/md_grey_900</item>
</style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar"> <style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
<item name="md_corner_radius">12dp</item> <item name="md_corner_radius">12dp</item>
@ -61,11 +110,8 @@
<style name="Theme.RetroMusic.Base.Black" parent="@style/Theme.RetroMusic.Base"> <style name="Theme.RetroMusic.Base.Black" parent="@style/Theme.RetroMusic.Base">
<item name="dividerColor">#18FFFFFF</item> <item name="dividerColor">#18FFFFFF</item>
<item name="defaultFooterColor">@color/md_grey_800</item> <item name="defaultFooterColor">@color/md_grey_800</item>
<item name="cardBackgroundColor">@color/md_grey_900</item> <item name="cardBackgroundColor">@color/md_grey_900</item>
<item name="md_background_color">@color/md_grey_900</item> <item name="md_background_color">@color/md_grey_900</item>
<item name="android:windowBackground">@color/md_black_1000</item> <item name="android:windowBackground">@color/md_black_1000</item>