Fix crashes

This commit is contained in:
h4h13 2019-08-01 13:57:05 +05:30
parent 311c416883
commit 8cc32140d5
10 changed files with 98 additions and 89 deletions

View file

@ -17,13 +17,15 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsBaseActivity import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.activities.saf.SAFGuideActivity import code.name.monkey.retromusic.activities.saf.SAFGuideActivity
import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.RetroUtil
import code.name.monkey.retromusic.util.SAFUtil import code.name.monkey.retromusic.util.SAFUtil
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems import com.afollestad.materialdialogs.list.listItems
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton import com.google.android.material.button.MaterialButton
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlinx.android.synthetic.main.activity_album_tag_editor.* import kotlinx.android.synthetic.main.activity_album_tag_editor.*
import org.jaudiotagger.audio.AudioFile import org.jaudiotagger.audio.AudioFile
import org.jaudiotagger.audio.AudioFileIO import org.jaudiotagger.audio.AudioFileIO
@ -40,7 +42,7 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() {
private var paletteColorPrimary: Int = 0 private var paletteColorPrimary: Int = 0
private var isInNoImageMode: Boolean = false private var isInNoImageMode: Boolean = false
private var songPaths: List<String>? = null private var songPaths: List<String>? = null
lateinit var saveFab: ExtendedFloatingActionButton lateinit var saveFab: MaterialButton
private var savedSongPaths: List<String>? = null private var savedSongPaths: List<String>? = null
private val currentSongPath: String? = null private val currentSongPath: String? = null
@ -183,7 +185,7 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(contentViewLayout) setContentView(contentViewLayout)
saveFab = findViewById(code.name.monkey.retromusic.R.id.saveTags) saveFab = findViewById( R.id.saveTags)
getIntentExtras() getIntentExtras()
songPaths = getSongPaths() songPaths = getSongPaths()

View file

@ -198,7 +198,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
val songs = AlbumLoader.getAlbum(this, id).blockingFirst().songs val songs = AlbumLoader.getAlbum(this, id).blockingFirst().songs
val paths = ArrayList<String>(songs!!.size) val paths = ArrayList<String>(songs!!.size)
for (song in songs) { for (song in songs) {
paths.add(song.data!!) paths.add(song.data)
} }
return paths return paths
} }

View file

@ -35,7 +35,6 @@ class SongTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setNoImageMode() setNoImageMode()
setUpViews() setUpViews()
setupToolbar() setupToolbar()

View file

@ -21,7 +21,10 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.loaders.PlaylistLoader import code.name.monkey.retromusic.loaders.PlaylistLoader
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.PlaylistsUtil import code.name.monkey.retromusic.util.PlaylistsUtil
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.list.listItems
import kotlinx.android.synthetic.main.activity_user_info.*
class AddToPlaylistDialog : DialogFragment() { class AddToPlaylistDialog : DialogFragment() {
@ -31,21 +34,25 @@ class AddToPlaylistDialog : DialogFragment() {
): Dialog { ): Dialog {
val cntx = requireContext() val cntx = requireContext()
val playlists = PlaylistLoader.getAllPlaylists(cntx).blockingFirst() val playlists = PlaylistLoader.getAllPlaylists(cntx).blockingFirst()
val playlistNames = arrayOfNulls<CharSequence>(playlists.size + 1) val playlistNames: MutableList<String> = mutableListOf()
playlistNames[0] = cntx.resources.getString(code.name.monkey.retromusic.R.string.action_new_playlist) playlistNames.add(cntx.resources.getString(R.string.action_new_playlist))
return MaterialAlertDialogBuilder(requireContext()) for (p in playlists) {
.setTitle(R.string.add_playlist_title) playlistNames.add(p.name)
.setItems(playlistNames) { dialog, which -> }
val songs = arguments!!.getParcelableArrayList<Song>("songs") ?: return@setItems
if (which == 0) { return MaterialDialog(requireContext(), BottomSheet()).show {
title(R.string.add_playlist_title)
listItems(items = playlistNames) { dialog, index, _ ->
val songs = arguments!!.getParcelableArrayList<Song>("songs") ?: return@listItems
if (index == 0) {
dialog.dismiss() dialog.dismiss()
activity?.supportFragmentManager?.let { CreatePlaylistDialog.create(songs).show(it, "ADD_TO_PLAYLIST") } activity?.supportFragmentManager?.let { CreatePlaylistDialog.create(songs).show(it, "ADD_TO_PLAYLIST") }
} else { } else {
dialog.dismiss() dialog.dismiss()
PlaylistsUtil.addToPlaylist(cntx, songs, playlists[which - 1].id, true) PlaylistsUtil.addToPlaylist(cntx, songs, playlists[index - 1].id, true)
}
} }
} }
.create()
} }
companion object { companion object {

View file

@ -42,7 +42,9 @@ class CreatePlaylistDialog : DialogFragment() {
private lateinit var playlistView: TextInputEditText private lateinit var playlistView: TextInputEditText
private lateinit var actionNewPlaylistContainer: TextInputLayout private lateinit var actionNewPlaylistContainer: TextInputLayout
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(
savedInstanceState: Bundle?
): Dialog {
val materialDialog = MaterialDialog(activity!!, BottomSheet()) val materialDialog = MaterialDialog(activity!!, BottomSheet())
.show { .show {
title(string.new_playlist_title) title(string.new_playlist_title)
@ -52,12 +54,13 @@ class CreatePlaylistDialog : DialogFragment() {
if (activity == null) { if (activity == null) {
return@positiveButton return@positiveButton
} }
val songs = arguments!!.getParcelableArrayList<Song>("songs") val songs = arguments?.getParcelableArrayList<Song>("songs")
?: return@positiveButton
if (playlistView.text!!.toString().trim { it <= ' ' }.isNotEmpty()) { if (playlistView.text.toString().trim { it <= ' ' }.isNotEmpty()) {
val playlistId = PlaylistsUtil.createPlaylist(activity!!, playlistView.text!!.toString()) val playlistId = PlaylistsUtil.createPlaylist(requireContext(), playlistView.text.toString())
if (playlistId != -1 && activity != null) { if (playlistId != -1 && activity != null) {
PlaylistsUtil.addToPlaylist(activity!!, songs, playlistId, true) PlaylistsUtil.addToPlaylist(requireContext(), songs, playlistId, true)
} }
} }
} }

View file

@ -25,6 +25,9 @@ import android.provider.BaseColumns;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -36,8 +39,6 @@ import code.name.monkey.retromusic.model.Playlist;
import code.name.monkey.retromusic.model.PlaylistSong; import code.name.monkey.retromusic.model.PlaylistSong;
import code.name.monkey.retromusic.model.Song; import code.name.monkey.retromusic.model.Song;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.annotations.Nullable;
import static android.provider.MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI; import static android.provider.MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
@ -112,13 +113,19 @@ public class PlaylistsUtil {
} }
} }
public static void addToPlaylist(@NonNull final Context context, final Song song, final int playlistId, final boolean showToastOnFinish) { public static void addToPlaylist(@NonNull Context context,
@NonNull Song song,
int playlistId,
boolean showToastOnFinish) {
List<Song> helperList = new ArrayList<>(); List<Song> helperList = new ArrayList<>();
helperList.add(song); helperList.add(song);
addToPlaylist(context, helperList, playlistId, showToastOnFinish); addToPlaylist(context, helperList, playlistId, showToastOnFinish);
} }
public static void addToPlaylist(@NonNull final Context context, @NonNull final List<Song> songs, final int playlistId, final boolean showToastOnFinish) { public static void addToPlaylist(@NonNull Context context,
@NonNull List<Song> songs,
int playlistId,
boolean showToastOnFinish) {
final int size = songs.size(); final int size = songs.size();
final ContentResolver resolver = context.getContentResolver(); final ContentResolver resolver = context.getContentResolver();
final String[] projection = new String[]{"max(" + MediaStore.Audio.Playlists.Members.PLAY_ORDER + ")",}; final String[] projection = new String[]{"max(" + MediaStore.Audio.Playlists.Members.PLAY_ORDER + ")",};

View file

@ -139,20 +139,29 @@
android:inputType="text|number" android:inputType="text|number"
android:maxLines="1" /> android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="52dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton <com.google.android.material.button.MaterialButton
android:id="@+id/saveTags" android:id="@+id/saveTags"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="16dp" android:layout_margin="16dp"
android:gravity="center" android:gravity="center"
android:paddingStart="32dp"
android:paddingTop="12dp"
android:paddingEnd="32dp"
android:paddingBottom="12dp"
android:text="@string/save" android:text="@string/save"
app:cornerRadius="25dp"
app:icon="@drawable/ic_save_white_24dp" app:icon="@drawable/ic_save_white_24dp"
app:iconGravity="textStart" /> app:iconGravity="textStart"
tools:backgroundTint="@color/md_red_400" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -163,18 +163,27 @@
android:inputType="text|number" android:inputType="text|number"
android:maxLines="1" /> android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="52dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton <com.google.android.material.button.MaterialButton
android:id="@+id/saveTags" android:id="@+id/saveTags"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom|center_horizontal"
android:layout_margin="16dp" android:layout_margin="16dp"
android:gravity="center" android:gravity="center"
android:paddingStart="32dp"
android:paddingTop="12dp"
android:paddingEnd="32dp"
android:paddingBottom="12dp"
android:text="@string/save" android:text="@string/save"
app:cornerRadius="25dp"
app:icon="@drawable/ic_save_white_24dp" app:icon="@drawable/ic_save_white_24dp"
app:iconGravity="textStart" /> app:iconGravity="textStart"
tools:backgroundTint="@color/md_red_400" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -239,19 +239,29 @@
android:inputType="textMultiLine" /> android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<Space
android:layout_width="match_parent"
android:layout_height="52dp" />
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton <com.google.android.material.button.MaterialButton
android:id="@+id/saveTags" android:id="@+id/saveTags"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom|center_horizontal"
android:layout_margin="16dp" android:layout_margin="16dp"
android:gravity="center" android:gravity="center"
android:paddingStart="32dp"
android:paddingTop="12dp"
android:paddingEnd="32dp"
android:paddingBottom="12dp"
android:text="@string/save" android:text="@string/save"
app:cornerRadius="25dp"
app:icon="@drawable/ic_save_white_24dp" app:icon="@drawable/ic_save_white_24dp"
app:iconGravity="textStart" /> app:iconGravity="textStart"
tools:backgroundTint="@color/md_red_400" />
<ProgressBar <ProgressBar
android:id="@+id/progressBar" android:id="@+id/progressBar"

View file

@ -1,53 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.RetroMusic.DayNight" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="md_corner_radius">16dp</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">
@ -95,6 +48,7 @@
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
</style> </style>
<style name="Theme.RetroMusic.Base.Color" parent="@style/Theme.RetroMusic.Base"> <style name="Theme.RetroMusic.Base.Color" parent="@style/Theme.RetroMusic.Base">
@ -105,6 +59,7 @@
<item name="md_color_button_text">@color/md_white_1000</item> <item name="md_color_button_text">@color/md_white_1000</item>
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
</style> </style>
<style name="Theme.RetroMusic.Base.Black" parent="@style/Theme.RetroMusic.Base"> <style name="Theme.RetroMusic.Base.Black" parent="@style/Theme.RetroMusic.Base">
@ -127,6 +82,7 @@
<item name="android:fontFamily">@font/circular</item> <item name="android:fontFamily">@font/circular</item>
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
</style> </style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar"> <style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
@ -175,6 +131,8 @@
<item name="android:textColorPrimary">@color/md_grey_900</item> <item name="android:textColorPrimary">@color/md_grey_900</item>
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
</style> </style>
@ -228,4 +186,9 @@
<item name="android:layout_width">wrap_content</item> <item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
</style> </style>
<style name="MaterialAlertDialogTheme" parent="@style/ThemeOverlay.MaterialComponents.Dialog">
<item name="android:dialogCornerRadius" tools:targetApi="p">12dp</item>
</style>
</resources> </resources>