From f139d02c2c80ac792250e5c9a4b953d82006c27a Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 4 Sep 2020 16:58:50 +0200 Subject: [PATCH] clean --- .../fedilabtube/drawer/PlaylistAdapter.java | 78 +++++++++++++------ .../res/drawable/ic_baseline_more_vert_24.xml | 10 +-- app/src/main/res/layout/drawer_playlist.xml | 62 +++++++++------ app/src/main/res/menu/playlist_menu.xml | 14 ++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 114 insertions(+), 51 deletions(-) create mode 100644 app/src/main/res/menu/playlist_menu.xml diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PlaylistAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PlaylistAdapter.java index a379905..f734837 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PlaylistAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PlaylistAdapter.java @@ -23,14 +23,21 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.appcompat.widget.PopupMenu; + +import com.bumptech.glide.Glide; import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.List; +import java.util.Map; +import app.fedilab.fedilabtube.PeertubeEditUploadActivity; import app.fedilab.fedilabtube.PlaylistsActivity; import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask; @@ -77,18 +84,27 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte if (convertView == null) { convertView = layoutInflater.inflate(R.layout.drawer_playlist, parent, false); holder = new ViewHolder(); - holder.search_title = convertView.findViewById(R.id.search_keyword); - holder.search_container = convertView.findViewById(R.id.search_container); - holder.action_delete = convertView.findViewById(R.id.action_delete); + holder.preview_title = convertView.findViewById(R.id.preview_title); + holder.preview_visibility = convertView.findViewById(R.id.preview_visibility); + holder.preview_description = convertView.findViewById(R.id.preview_description); + holder.playlist_container = convertView.findViewById(R.id.playlist_container); + holder.preview_playlist = convertView.findViewById(R.id.preview_playlist); + holder.playlist_more = convertView.findViewById(R.id.playlist_more); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } + Glide.with(context) + .load("https://"+playlist.getOwnerAccount().getHost()+playlist.getThumbnailPath()) + .into(holder.preview_playlist); - holder.search_title.setText(playlist.getDisplayName()); + holder.preview_title.setText(playlist.getDisplayName()); + holder.preview_description.setText(playlist.getDescription()); + Map.Entry privacyM = playlist.getPrivacy().entrySet().iterator().next(); + holder.preview_visibility.setText(privacyM.getValue()); - holder.search_container.setOnClickListener(v -> { + holder.playlist_container.setOnClickListener(v -> { Intent intent = new Intent(context, PlaylistsActivity.class); Bundle b = new Bundle(); b.putParcelable("playlist", playlist); @@ -97,21 +113,36 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte }); - holder.action_delete.setOnClickListener(v -> { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(context.getString(R.string.action_lists_delete) + ": " + playlist.getDisplayName()); - builder.setMessage(context.getString(R.string.action_lists_confirm_delete)); - builder.setIcon(android.R.drawable.ic_dialog_alert) - .setPositiveButton(R.string.yes, (dialog, which) -> { - playlists.remove(playlist); - notifyDataSetChanged(); - new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST, playlist, null, null, PlaylistAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - if (playlists.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE) - textviewNoAction.setVisibility(View.VISIBLE); - dialog.dismiss(); - }) - .setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss()) - .show(); + holder.playlist_more.setOnClickListener(v -> { + PopupMenu popup = new PopupMenu(context, holder.playlist_more); + popup.getMenuInflater() + .inflate(R.menu.playlist_menu, popup.getMenu()); + popup.setOnMenuItemClickListener(item -> { + switch (item.getItemId()) { + case R.id.action_delete: + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(context.getString(R.string.action_lists_delete) + ": " + playlist.getDisplayName()); + builder.setMessage(context.getString(R.string.action_lists_confirm_delete)); + builder.setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(R.string.yes, (dialog, which) -> { + playlists.remove(playlist); + notifyDataSetChanged(); + new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST, playlist, null, null, PlaylistAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (playlists.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE) + textviewNoAction.setVisibility(View.VISIBLE); + dialog.dismiss(); + }) + .setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss()) + .show(); + break; + case R.id.action_edit: + + break; + } + return true; + }); + popup.show(); + }); return convertView; } @@ -122,9 +153,10 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte } private static class ViewHolder { - LinearLayout search_container; - TextView search_title; - FloatingActionButton action_delete; + LinearLayout playlist_container; + ImageView preview_playlist; + TextView preview_title, preview_visibility, preview_description; + ImageButton playlist_more; } diff --git a/app/src/main/res/drawable/ic_baseline_more_vert_24.xml b/app/src/main/res/drawable/ic_baseline_more_vert_24.xml index 14ff51e..34b93ec 100644 --- a/app/src/main/res/drawable/ic_baseline_more_vert_24.xml +++ b/app/src/main/res/drawable/ic_baseline_more_vert_24.xml @@ -1,10 +1,10 @@ - + android:viewportHeight="24" + android:tint="?attr/colorControlNormal"> + diff --git a/app/src/main/res/layout/drawer_playlist.xml b/app/src/main/res/layout/drawer_playlist.xml index e82d94a..5c6bc37 100644 --- a/app/src/main/res/layout/drawer_playlist.xml +++ b/app/src/main/res/layout/drawer_playlist.xml @@ -18,7 +18,7 @@ + + + - + app:layout_constraintEnd_toStartOf="@+id/preview_description" + app:layout_constraintStart_toEndOf="@+id/preview_playlist" + app:layout_constraintTop_toBottomOf="@+id/preview_title" /> - - + diff --git a/app/src/main/res/menu/playlist_menu.xml b/app/src/main/res/menu/playlist_menu.xml new file mode 100644 index 0000000..f9da37c --- /dev/null +++ b/app/src/main/res/menu/playlist_menu.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ced43c3..afa8bdb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -207,4 +207,5 @@ Supprimer la chaƮne Afficher la liste Supprimer la liste de lecture + Modifier \ No newline at end of file