small changes to cab holder interface
This commit is contained in:
parent
dbacad4e6c
commit
ec649b5417
12 changed files with 6 additions and 201 deletions
3
app/proguard-rules.pro
vendored
3
app/proguard-rules.pro
vendored
|
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
-keep class com.dkanada.gramophone.**.* { *; }
|
-keep class com.dkanada.gramophone.**.* { *; }
|
||||||
-keepnames class **.* { *; }
|
-keepnames class **.* { *; }
|
||||||
-keepattributes SourceFile,LineNumberTable
|
-keepattributes SourceFile
|
||||||
|
-keepattributes LineNumberTable
|
||||||
|
|
||||||
# Jellyfin API
|
# Jellyfin API
|
||||||
-keepclasseswithmembers class org.jellyfin.apiclient.model.**.* { *; }
|
-keepclasseswithmembers class org.jellyfin.apiclient.model.**.* { *; }
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,6 @@ public abstract class AbsMusicPanelActivity extends AbsMusicServiceActivity impl
|
||||||
miniPlayerFragment.getView().setVisibility(alpha == 0 ? View.GONE : View.VISIBLE);
|
miniPlayerFragment.getView().setVisibility(alpha == 0 ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SlidingUpPanelLayout.PanelState getPanelState() {
|
public SlidingUpPanelLayout.PanelState getPanelState() {
|
||||||
return binding == null ? null : binding.slidingLayout.getPanelState();
|
return binding == null ? null : binding.slidingLayout.getPanelState();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,6 @@ public class AlbumDetailActivity extends AbsMusicContentActivity implements Pale
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialCab openCab(int menuRes, @NonNull final MaterialCab.Callback callback) {
|
public MaterialCab openCab(int menuRes, @NonNull final MaterialCab.Callback callback) {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) cab.finish();
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,6 @@ public class ArtistDetailActivity extends AbsMusicContentActivity implements Pal
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialCab openCab(int menuRes, @NonNull final MaterialCab.Callback callback) {
|
public MaterialCab openCab(int menuRes, @NonNull final MaterialCab.Callback callback) {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) cab.finish();
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,6 @@ public class GenreDetailActivity extends AbsMusicContentActivity implements CabH
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialCab openCab(final int menu, final MaterialCab.Callback callback) {
|
public MaterialCab openCab(final int menu, final MaterialCab.Callback callback) {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) cab.finish();
|
||||||
|
|
@ -124,8 +123,9 @@ public class GenreDetailActivity extends AbsMusicContentActivity implements CabH
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) {
|
||||||
else {
|
cab.finish();
|
||||||
|
} else {
|
||||||
binding.recyclerView.stopScroll();
|
binding.recyclerView.stopScroll();
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,6 @@ public class PlaylistDetailActivity extends AbsMusicContentActivity implements C
|
||||||
|| super.onOptionsItemSelected(item);
|
|| super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialCab openCab(final int menu, final MaterialCab.Callback callback) {
|
public MaterialCab openCab(final int menu, final MaterialCab.Callback callback) {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) cab.finish();
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import com.dkanada.gramophone.model.Song;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
||||||
|
|
||||||
protected static final int OFFSET_ITEM = 0;
|
protected static final int OFFSET_ITEM = 0;
|
||||||
protected static final int SONG = 1;
|
protected static final int SONG = 1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,188 +0,0 @@
|
||||||
package com.dkanada.gramophone.adapter.song;
|
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.core.util.Pair;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import com.afollestad.materialcab.MaterialCab;
|
|
||||||
import com.dkanada.gramophone.R;
|
|
||||||
import com.dkanada.gramophone.glide.CustomGlideRequest;
|
|
||||||
import com.dkanada.gramophone.helper.MusicPlayerRemote;
|
|
||||||
import com.dkanada.gramophone.helper.menu.SongMenuHelper;
|
|
||||||
import com.dkanada.gramophone.helper.menu.SongsMenuHelper;
|
|
||||||
import com.dkanada.gramophone.interfaces.CabHolder;
|
|
||||||
import com.dkanada.gramophone.model.Album;
|
|
||||||
import com.dkanada.gramophone.model.Song;
|
|
||||||
import com.dkanada.gramophone.util.NavigationUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab.Callback {
|
|
||||||
@Nullable
|
|
||||||
private final CabHolder cabHolder;
|
|
||||||
private MaterialCab cab;
|
|
||||||
private List<Song> dataSet;
|
|
||||||
private List<Song> checked;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final AppCompatActivity activity;
|
|
||||||
|
|
||||||
public ArtistSongAdapter(@NonNull AppCompatActivity activity, @NonNull List<Song> dataSet, @Nullable CabHolder cabHolder) {
|
|
||||||
super(activity, R.layout.item_list, dataSet);
|
|
||||||
this.activity = activity;
|
|
||||||
this.cabHolder = cabHolder;
|
|
||||||
this.dataSet = dataSet;
|
|
||||||
checked = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Song> getDataSet() {
|
|
||||||
return dataSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void swapDataSet(List<Song> dataSet) {
|
|
||||||
this.dataSet = dataSet;
|
|
||||||
clear();
|
|
||||||
addAll(dataSet);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
|
|
||||||
final Song song = getItem(position);
|
|
||||||
if (convertView == null) {
|
|
||||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_list, parent, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
final TextView songTitle = convertView.findViewById(R.id.title);
|
|
||||||
final TextView songInfo = convertView.findViewById(R.id.text);
|
|
||||||
final ImageView albumArt = convertView.findViewById(R.id.image);
|
|
||||||
final View shortSeparator = convertView.findViewById(R.id.short_separator);
|
|
||||||
|
|
||||||
if (position == getCount() - 1) {
|
|
||||||
if (shortSeparator != null) {
|
|
||||||
shortSeparator.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (shortSeparator != null) {
|
|
||||||
shortSeparator.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
songTitle.setText(song.title);
|
|
||||||
songInfo.setText(song.albumName);
|
|
||||||
|
|
||||||
CustomGlideRequest.Builder
|
|
||||||
.from(activity, song.primary, song.blurHash)
|
|
||||||
.build().into(albumArt);
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
albumArt.setTransitionName(activity.getString(R.string.transition_album_image));
|
|
||||||
}
|
|
||||||
|
|
||||||
final ImageView overflowButton = convertView.findViewById(R.id.menu);
|
|
||||||
overflowButton.setOnClickListener(new SongMenuHelper.OnClickSongMenu(activity) {
|
|
||||||
@Override
|
|
||||||
public Song getSong() {
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
if (item.getItemId() == R.id.action_go_to_album) {
|
|
||||||
Pair transition = Pair.create(albumArt, activity.getResources().getString(R.string.transition_album_image));
|
|
||||||
NavigationUtil.startAlbum(activity, new Album(song), transition);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onMenuItemClick(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
convertView.setActivated(isChecked(song));
|
|
||||||
convertView.setOnClickListener(view -> {
|
|
||||||
if (isInQuickSelectMode()) {
|
|
||||||
toggleChecked(song);
|
|
||||||
} else {
|
|
||||||
MusicPlayerRemote.openQueue(dataSet, position, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
convertView.setOnLongClickListener(view -> {
|
|
||||||
toggleChecked(song);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
return convertView;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull List<Song> selection) {
|
|
||||||
SongsMenuHelper.handleMenuClick(activity, selection, menuItem.getItemId());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void toggleChecked(Song song) {
|
|
||||||
if (cabHolder != null) {
|
|
||||||
openCabIfNecessary();
|
|
||||||
|
|
||||||
if (!checked.remove(song)) checked.add(song);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
|
|
||||||
final int size = checked.size();
|
|
||||||
if (size <= 0) cab.finish();
|
|
||||||
else if (size == 1) cab.setTitle(checked.get(0).title);
|
|
||||||
else if (size > 1) cab.setTitle(String.valueOf(size));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openCabIfNecessary() {
|
|
||||||
if (cabHolder != null) {
|
|
||||||
if (cab == null || !cab.isActive()) {
|
|
||||||
cab = cabHolder.openCab(R.menu.menu_select_media, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void unCheckAll() {
|
|
||||||
checked.clear();
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isChecked(Song song) {
|
|
||||||
return checked.contains(song);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isInQuickSelectMode() {
|
|
||||||
return cab != null && cab.isActive();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCabCreated(MaterialCab materialCab, Menu menu) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCabItemClicked(@NonNull MenuItem menuItem) {
|
|
||||||
onMultipleItemAction(menuItem, new ArrayList<>(checked));
|
|
||||||
cab.finish();
|
|
||||||
unCheckAll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCabFinished(MaterialCab materialCab) {
|
|
||||||
unCheckAll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -130,7 +130,6 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
||||||
return getCurrentFragment() instanceof PlaylistsFragment;
|
return getCurrentFragment() instanceof PlaylistsFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialCab openCab(final int menuRes, final MaterialCab.Callback callback) {
|
public MaterialCab openCab(final int menuRes, final MaterialCab.Callback callback) {
|
||||||
if (cab != null && cab.isActive()) cab.finish();
|
if (cab != null && cab.isActive()) cab.finish();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,5 @@ import androidx.annotation.NonNull;
|
||||||
import com.afollestad.materialcab.MaterialCab;
|
import com.afollestad.materialcab.MaterialCab;
|
||||||
|
|
||||||
public interface CabHolder {
|
public interface CabHolder {
|
||||||
@NonNull
|
|
||||||
MaterialCab openCab(final int menuRes, final MaterialCab.Callback callback);
|
MaterialCab openCab(final int menuRes, final MaterialCab.Callback callback);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,6 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">?android:attr/actionBarSize</item>
|
<item name="android:layout_height">?android:attr/actionBarSize</item>
|
||||||
<item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
|
<item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
|
||||||
<item name="popupTheme">?toolbarPopupTheme</item>
|
<item name="android:popupTheme" tools:ignore="NewApi">?toolbarPopupTheme</item>
|
||||||
<item name="android:elevation" tools:ignore="NewApi">@dimen/toolbar_elevation</item>
|
<item name="android:elevation" tools:ignore="NewApi">@dimen/toolbar_elevation</item>
|
||||||
<item name="android:transitionName" tools:ignore="NewApi">toolbar</item>
|
<item name="android:transitionName" tools:ignore="NewApi">toolbar</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue