Fix crashes
This commit is contained in:
parent
311c416883
commit
8cc32140d5
10 changed files with 98 additions and 89 deletions
|
@ -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<String>? = null
|
||||
lateinit var saveFab: ExtendedFloatingActionButton
|
||||
lateinit var saveFab: MaterialButton
|
||||
|
||||
private var savedSongPaths: List<String>? = 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()
|
||||
|
|
|
@ -198,7 +198,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
|
|||
val songs = AlbumLoader.getAlbum(this, id).blockingFirst().songs
|
||||
val paths = ArrayList<String>(songs!!.size)
|
||||
for (song in songs) {
|
||||
paths.add(song.data!!)
|
||||
paths.add(song.data)
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ class SongTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
||||
setNoImageMode()
|
||||
setUpViews()
|
||||
setupToolbar()
|
||||
|
|
|
@ -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<CharSequence>(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<Song>("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<String> = 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<Song>("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 {
|
||||
|
|
|
@ -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<Song>("songs")
|
||||
val songs = arguments?.getParcelableArrayList<Song>("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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Song> helperList = new ArrayList<>();
|
||||
helperList.add(song);
|
||||
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 ContentResolver resolver = context.getContentResolver();
|
||||
final String[] projection = new String[]{"max(" + MediaStore.Audio.Playlists.Members.PLAY_ORDER + ")",};
|
||||
|
|
|
@ -139,20 +139,29 @@
|
|||
android:inputType="text|number"
|
||||
android:maxLines="1" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="52dp" />
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/saveTags"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/save"
|
||||
app:cornerRadius="25dp"
|
||||
app:icon="@drawable/ic_save_white_24dp"
|
||||
app:iconGravity="textStart" />
|
||||
app:iconGravity="textStart"
|
||||
tools:backgroundTint="@color/md_red_400" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -163,18 +163,27 @@
|
|||
android:inputType="text|number"
|
||||
android:maxLines="1" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="52dp" />
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/saveTags"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/save"
|
||||
app:cornerRadius="25dp"
|
||||
app:icon="@drawable/ic_save_white_24dp"
|
||||
app:iconGravity="textStart" />
|
||||
app:iconGravity="textStart"
|
||||
tools:backgroundTint="@color/md_red_400" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -239,19 +239,29 @@
|
|||
android:inputType="textMultiLine" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="52dp" />
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/saveTags"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/save"
|
||||
app:cornerRadius="25dp"
|
||||
app:icon="@drawable/ic_save_white_24dp"
|
||||
app:iconGravity="textStart" />
|
||||
app:iconGravity="textStart"
|
||||
tools:backgroundTint="@color/md_red_400" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
|
|
|
@ -1,53 +1,6 @@
|
|||
<?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">
|
||||
|
||||
|
@ -95,6 +48,7 @@
|
|||
|
||||
<item name="windowActionBar">false</item>
|
||||
|
||||
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
|
||||
</style>
|
||||
|
||||
<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="windowActionBar">false</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.RetroMusic.Base.Black" parent="@style/Theme.RetroMusic.Base">
|
||||
|
@ -127,6 +82,7 @@
|
|||
<item name="android:fontFamily">@font/circular</item>
|
||||
|
||||
<item name="windowActionBar">false</item>
|
||||
|
||||
</style>
|
||||
|
||||
<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="windowActionBar">false</item>
|
||||
|
||||
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
@ -228,4 +186,9 @@
|
|||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="MaterialAlertDialogTheme" parent="@style/ThemeOverlay.MaterialComponents.Dialog">
|
||||
<item name="android:dialogCornerRadius" tools:targetApi="p">12dp</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in a new issue