From 8cc32140d5063bd9583112b152f0aa7d1ecf9c25 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Thu, 1 Aug 2019 13:57:05 +0530 Subject: [PATCH] Fix crashes --- .../tageditor/AbsTagEditorActivity.kt | 8 ++- .../tageditor/AlbumTagEditorActivity.kt | 2 +- .../tageditor/SongTagEditorActivity.kt | 1 - .../retromusic/dialogs/AddToPlaylistDialog.kt | 37 +++++++----- .../dialogs/CreatePlaylistDialog.kt | 13 ++-- .../monkey/retromusic/util/PlaylistsUtil.java | 15 +++-- .../layout-land/activity_album_tag_editor.xml | 15 ++++- .../res/layout/activity_album_tag_editor.xml | 19 ++++-- .../res/layout/activity_song_tag_editor.xml | 18 ++++-- app/src/main/res/values/styles_parents.xml | 59 ++++--------------- 10 files changed, 98 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt index f122b7d0..e0971bd7 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt @@ -17,13 +17,15 @@ import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper 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.saf.SAFGuideActivity import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.SAFUtil import com.afollestad.materialdialogs.MaterialDialog 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 org.jaudiotagger.audio.AudioFile import org.jaudiotagger.audio.AudioFileIO @@ -40,7 +42,7 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() { private var paletteColorPrimary: Int = 0 private var isInNoImageMode: Boolean = false private var songPaths: List? = null - lateinit var saveFab: ExtendedFloatingActionButton + lateinit var saveFab: MaterialButton private var savedSongPaths: List? = null private val currentSongPath: String? = null @@ -183,7 +185,7 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() { super.onCreate(savedInstanceState) setContentView(contentViewLayout) - saveFab = findViewById(code.name.monkey.retromusic.R.id.saveTags) + saveFab = findViewById( R.id.saveTags) getIntentExtras() songPaths = getSongPaths() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt index 244989eb..21b0ec61 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AlbumTagEditorActivity.kt @@ -198,7 +198,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher { val songs = AlbumLoader.getAlbum(this, id).blockingFirst().songs val paths = ArrayList(songs!!.size) for (song in songs) { - paths.add(song.data!!) + paths.add(song.data) } return paths } diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/SongTagEditorActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/SongTagEditorActivity.kt index f8346265..7b14d850 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/SongTagEditorActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/SongTagEditorActivity.kt @@ -35,7 +35,6 @@ class SongTagEditorActivity : AbsTagEditorActivity(), TextWatcher { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setNoImageMode() setUpViews() setupToolbar() diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt index 83ce34bd..f65154ee 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt @@ -21,7 +21,10 @@ import code.name.monkey.retromusic.R import code.name.monkey.retromusic.loaders.PlaylistLoader import code.name.monkey.retromusic.model.Song 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() { @@ -31,21 +34,25 @@ class AddToPlaylistDialog : DialogFragment() { ): Dialog { val cntx = requireContext() val playlists = PlaylistLoader.getAllPlaylists(cntx).blockingFirst() - val playlistNames = arrayOfNulls(playlists.size + 1) - playlistNames[0] = cntx.resources.getString(code.name.monkey.retromusic.R.string.action_new_playlist) - return MaterialAlertDialogBuilder(requireContext()) - .setTitle(R.string.add_playlist_title) - .setItems(playlistNames) { dialog, which -> - val songs = arguments!!.getParcelableArrayList("songs") ?: return@setItems - if (which == 0) { - dialog.dismiss() - activity?.supportFragmentManager?.let { CreatePlaylistDialog.create(songs).show(it, "ADD_TO_PLAYLIST") } - } else { - dialog.dismiss() - PlaylistsUtil.addToPlaylist(cntx, songs, playlists[which - 1].id, true) - } + val playlistNames: MutableList = mutableListOf() + playlistNames.add(cntx.resources.getString(R.string.action_new_playlist)) + for (p in playlists) { + playlistNames.add(p.name) + } + + return MaterialDialog(requireContext(), BottomSheet()).show { + title(R.string.add_playlist_title) + listItems(items = playlistNames) { dialog, index, _ -> + val songs = arguments!!.getParcelableArrayList("songs") ?: return@listItems + if (index == 0) { + dialog.dismiss() + activity?.supportFragmentManager?.let { CreatePlaylistDialog.create(songs).show(it, "ADD_TO_PLAYLIST") } + } else { + dialog.dismiss() + PlaylistsUtil.addToPlaylist(cntx, songs, playlists[index - 1].id, true) } - .create() + } + } } companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt index ba89e4a6..83ecb2f2 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt @@ -42,7 +42,9 @@ class CreatePlaylistDialog : DialogFragment() { private lateinit var playlistView: TextInputEditText private lateinit var actionNewPlaylistContainer: TextInputLayout - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + override fun onCreateDialog( + savedInstanceState: Bundle? + ): Dialog { val materialDialog = MaterialDialog(activity!!, BottomSheet()) .show { title(string.new_playlist_title) @@ -52,12 +54,13 @@ class CreatePlaylistDialog : DialogFragment() { if (activity == null) { return@positiveButton } - val songs = arguments!!.getParcelableArrayList("songs") + val songs = arguments?.getParcelableArrayList("songs") + ?: return@positiveButton - if (playlistView.text!!.toString().trim { it <= ' ' }.isNotEmpty()) { - val playlistId = PlaylistsUtil.createPlaylist(activity!!, playlistView.text!!.toString()) + if (playlistView.text.toString().trim { it <= ' ' }.isNotEmpty()) { + val playlistId = PlaylistsUtil.createPlaylist(requireContext(), playlistView.text.toString()) if (playlistId != -1 && activity != null) { - PlaylistsUtil.addToPlaylist(activity!!, songs, playlistId, true) + PlaylistsUtil.addToPlaylist(requireContext(), songs, playlistId, true) } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java index 00ab4dc1..9a425637 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java @@ -25,6 +25,9 @@ import android.provider.BaseColumns; import android.provider.MediaStore; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import java.io.File; import java.io.IOException; 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.Song; import io.reactivex.Observable; -import io.reactivex.annotations.NonNull; -import io.reactivex.annotations.Nullable; 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 helperList = new ArrayList<>(); helperList.add(song); addToPlaylist(context, helperList, playlistId, showToastOnFinish); } - public static void addToPlaylist(@NonNull final Context context, @NonNull final List songs, final int playlistId, final boolean showToastOnFinish) { + public static void addToPlaylist(@NonNull Context context, + @NonNull List songs, + int playlistId, + boolean showToastOnFinish) { final int size = songs.size(); final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[]{"max(" + MediaStore.Audio.Playlists.Members.PLAY_ORDER + ")",}; diff --git a/app/src/main/res/layout-land/activity_album_tag_editor.xml b/app/src/main/res/layout-land/activity_album_tag_editor.xml index 072738af..021b5a07 100644 --- a/app/src/main/res/layout-land/activity_album_tag_editor.xml +++ b/app/src/main/res/layout-land/activity_album_tag_editor.xml @@ -139,20 +139,29 @@ android:inputType="text|number" android:maxLines="1" /> - + + - + app:iconGravity="textStart" + tools:backgroundTint="@color/md_red_400" /> diff --git a/app/src/main/res/layout/activity_album_tag_editor.xml b/app/src/main/res/layout/activity_album_tag_editor.xml index f3713701..1a5ea25c 100755 --- a/app/src/main/res/layout/activity_album_tag_editor.xml +++ b/app/src/main/res/layout/activity_album_tag_editor.xml @@ -163,18 +163,27 @@ android:inputType="text|number" android:maxLines="1" /> - + + - + app:iconGravity="textStart" + tools:backgroundTint="@color/md_red_400" /> diff --git a/app/src/main/res/layout/activity_song_tag_editor.xml b/app/src/main/res/layout/activity_song_tag_editor.xml index 254c0d29..7fd58147 100755 --- a/app/src/main/res/layout/activity_song_tag_editor.xml +++ b/app/src/main/res/layout/activity_song_tag_editor.xml @@ -239,19 +239,29 @@ android:inputType="textMultiLine" /> + + - + app:iconGravity="textStart" + tools:backgroundTint="@color/md_red_400" /> - + - @@ -228,4 +186,9 @@ wrap_content wrap_content + + + \ No newline at end of file