mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-01-20 21:50:58 +01:00
Improve channel creation
This commit is contained in:
parent
d8de74ce7a
commit
d02fdba671
@ -15,6 +15,7 @@ package app.fedilab.fedilabtube;
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
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<Integer, String> 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<Integer, String> 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
|
||||
|
@ -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);
|
||||
|
@ -154,7 +154,7 @@
|
||||
<string name="action_playlist_create">Créer une liste de lecture</string>
|
||||
<string name="action_playlist_edit">Modifier une liste de lecture</string>
|
||||
<string name="display_name">Nom d\'affichage</string>
|
||||
<string name="error_channel_mandatory">Un canal est requis lorsque la liste de lecture est publique.</string>
|
||||
<string name="error_channel_mandatory">Une chaîne est requise lorsque la liste de lecture est publique.</string>
|
||||
<string name="error_display_name">Vous devez fournir un nom d\'affichage !</string>
|
||||
<string name="error_display_name_channel">Vous devez fournir un nom d\'affichage et un nom pour la chaîne!</string>
|
||||
<string name="action_playlist_empty_content">Cette liste de lecture est vide.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user