From d02fdba6710ef6794807a2111e8b500ecf44b2fe Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 12 Sep 2020 16:53:04 +0200 Subject: [PATCH] Improve channel creation --- .../fedilabtube/AllPlaylistsActivity.java | 146 ++++++++++-------- .../fedilabtube/drawer/PlaylistAdapter.java | 5 + app/src/main/res/values/strings.xml | 2 +- 3 files changed, 84 insertions(+), 69 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java index 3889a7a..42d7100 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java @@ -15,6 +15,7 @@ package app.fedilab.fedilabtube; * see . */ import android.content.Context; +import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -26,6 +27,7 @@ import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; @@ -169,76 +171,82 @@ public class AllPlaylistsActivity extends AppCompatActivity { display_name.setText(playlistToEdit.getDisplayName()); description.setText(playlistToEdit.getDescription()); } - - dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> { - if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) { - PlaylistElement playlistElement = new PlaylistElement(); - playlistElement.setDisplayName(display_name.getText().toString().trim()); - if (description.getText() != null && description.getText().toString().trim().length() > 0) { - playlistElement.setDescription(description.getText().toString().trim()); - } - playlistElement.setVideoChannelId(idChannel); - String idPrivacy; - String label; - Map.Entry privacyM = privacyToSend.entrySet().iterator().next(); - idPrivacy = String.valueOf(privacyM.getKey()); - label = privacyM.getValue(); - if ((label.equals("Public") && (playlistElement.getVideoChannelId() == null || playlistElement.getVideoChannelId().equals("")))) { - Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show(); - } else { - if (privacyToSend != null) { - playlistElement.setPrivacy(idPrivacy); - } - new Thread(() -> { - try { - String playlistId; - if (playlistToEdit == null) { - playlistId = new PeertubeAPI(AllPlaylistsActivity.this).createPlaylist(playlistElement); - } else { - playlistId = playlistToEdit.getId(); - playlistElement.setPlaylistId(playlistId); - new PeertubeAPI(AllPlaylistsActivity.this).updatePlaylist(playlistElement); - } - Handler mainHandler = new Handler(Looper.getMainLooper()); - Runnable myRunnable = () -> { - Playlist playlist; - if (playlistToEdit == null) { - playlist = new Playlist(); - } else { - playlist = playlistToEdit; - } - playlist.setId(playlistId); - playlist.setDescription(playlistElement.getDescription()); - playlist.setDisplayName(playlistElement.getDisplayName()); - playlist.setVideoChannelId(playlistElement.getVideoChannelId()); - playlist.setPrivacy(privacyToSend); - if (playlistToEdit == null) { - playlists.add(playlist); - } - playlistAdapter.notifyDataSetChanged(); - }; - mainHandler.post(myRunnable); - } catch (HttpsConnection.HttpsConnectionException e) { - e.printStackTrace(); - Handler mainHandler = new Handler(Looper.getMainLooper()); - Runnable myRunnable = () -> { - if (e.getMessage() != null) { - Toasty.error(AllPlaylistsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); - } else { - Toasty.error(AllPlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - } - }; - mainHandler.post(myRunnable); - } - }).start(); - dialog.dismiss(); - } - } else { - Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show(); - } - }); + dialogBuilder.setPositiveButton(R.string.validate, null); dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); + AlertDialog alertDialog = dialogBuilder.create(); + alertDialog.setOnShowListener(dialogInterface -> { + + Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); + button.setOnClickListener(view -> { + if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) { + PlaylistElement playlistElement = new PlaylistElement(); + playlistElement.setDisplayName(display_name.getText().toString().trim()); + if (description.getText() != null && description.getText().toString().trim().length() > 0) { + playlistElement.setDescription(description.getText().toString().trim()); + } + playlistElement.setVideoChannelId(idChannel); + String idPrivacy; + String label; + Map.Entry privacyM = privacyToSend.entrySet().iterator().next(); + idPrivacy = String.valueOf(privacyM.getKey()); + label = privacyM.getValue(); + if ((label.trim().compareTo("Public") == 0 && (playlistElement.getVideoChannelId() == null || playlistElement.getVideoChannelId().trim().compareTo("null") == 0))) { + Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show(); + } else { + if (privacyToSend != null) { + playlistElement.setPrivacy(idPrivacy); + } + new Thread(() -> { + try { + String playlistId; + if (playlistToEdit == null) { + playlistId = new PeertubeAPI(AllPlaylistsActivity.this).createPlaylist(playlistElement); + } else { + playlistId = playlistToEdit.getId(); + playlistElement.setPlaylistId(playlistId); + new PeertubeAPI(AllPlaylistsActivity.this).updatePlaylist(playlistElement); + } + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> { + Playlist playlist; + if (playlistToEdit == null) { + playlist = new Playlist(); + } else { + playlist = playlistToEdit; + } + playlist.setId(playlistId); + playlist.setDescription(playlistElement.getDescription()); + playlist.setDisplayName(playlistElement.getDisplayName()); + playlist.setVideoChannelId(playlistElement.getVideoChannelId()); + playlist.setPrivacy(privacyToSend); + if (playlistToEdit == null) { + playlists.add(playlist); + } + playlistAdapter.notifyDataSetChanged(); + }; + mainHandler.post(myRunnable); + } catch (HttpsConnection.HttpsConnectionException e) { + e.printStackTrace(); + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> { + if (e.getMessage() != null) { + Toasty.error(AllPlaylistsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); + } else { + Toasty.error(AllPlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + } + }; + mainHandler.post(myRunnable); + } + }).start(); + alertDialog.dismiss(); + } + } else { + Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show(); + } + }); + }); + if (playlistToEdit == null) { alertDialog.setTitle(getString(R.string.action_playlist_create)); } else { @@ -320,6 +328,8 @@ public class AllPlaylistsActivity extends AppCompatActivity { if (pair != null) { set_upload_privacy.setSelection(pair.getKey() - 1); } + } else { + set_upload_privacy.setSelection(2); } //Manage privacies 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 226f321..8ab6618 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PlaylistAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PlaylistAdapter.java @@ -119,6 +119,11 @@ public class PlaylistAdapter extends BaseAdapter { context.startActivity(intent); }); + if (playlist.getDisplayName().compareTo("Watch later") == 0) { + holder.playlist_more.setVisibility(View.GONE); + } else { + holder.playlist_more.setVisibility(View.VISIBLE); + } holder.playlist_more.setOnClickListener(v -> { PopupMenu popup = new PopupMenu(context, holder.playlist_more); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7de7d87..e56c866 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -154,7 +154,7 @@ Créer une liste de lecture Modifier une liste de lecture Nom d\'affichage - Un canal est requis lorsque la liste de lecture est publique. + Une chaîne est requise lorsque la liste de lecture est publique. Vous devez fournir un nom d\'affichage ! Vous devez fournir un nom d\'affichage et un nom pour la chaîne! Cette liste de lecture est vide.