Fix remove from list

This commit is contained in:
Thomas 2020-06-30 19:06:54 +02:00
parent d6fbba857f
commit df06590b00
7 changed files with 184 additions and 200 deletions

View File

@ -1,7 +1,6 @@
package app.fedilab.fedilabtube;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
@ -22,7 +21,6 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -46,7 +44,6 @@ import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
import app.fedilab.fedilabtube.fragment.DisplayPlaylistsFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
@ -59,10 +56,9 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
private AsyncTask<Void, Void, Void> asyncTask;
private List<Playlist> playlists;
private RelativeLayout mainLoader;
private FloatingActionButton add_new;
private PlaylistAdapter playlistAdapter;
private RelativeLayout textviewNoAction;
private HashMap<Integer, String> privacyToSend;
private HashMap<String, String> channelToSend;
@ -81,18 +77,16 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(R.string.playlists);
playlists = new ArrayList<>();
ListView lv_playlist = findViewById(R.id.lv_playlist);
textviewNoAction = findViewById(R.id.no_action);
mainLoader = findViewById(R.id.loader);
RelativeLayout nextElementLoader = findViewById(R.id.loading_next_items);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
playlists = new ArrayList<>();
playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
lv_playlist.setAdapter(playlistAdapter);
asyncTask = new ManagePlaylistsAsyncTask(AllPlaylistsActivity.this, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
add_new = findViewById(R.id.add_new);
@ -103,123 +97,114 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
if (add_new != null) {
add_new.setOnClickListener(view -> {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(AllPlaylistsActivity.this), false);
dialogBuilder.setView(dialogView);
EditText display_name = dialogView.findViewById(R.id.display_name);
EditText description = dialogView.findViewById(R.id.description);
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
add_new.setOnClickListener(view -> {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(AllPlaylistsActivity.this), false);
dialogBuilder.setView(dialogView);
EditText display_name = dialogView.findViewById(R.id.display_name);
EditText description = dialogView.findViewById(R.id.description);
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
new RetrievePeertubeChannelsAsyncTask(AllPlaylistsActivity.this, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrievePeertubeChannelsAsyncTask(AllPlaylistsActivity.this, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
Playlist playlist = new Playlist();
playlist.setDisplayName(display_name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
playlist.setDescription(description.getText().toString().trim());
}
String idChannel = null;
if (channelToSend != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
idChannel = channelM.getValue();
if (idChannel.length() > 0)
playlist.setVideoChannelId(idChannel);
}
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
String label = privacyM.getValue();
String idPrivacy = String.valueOf(privacyM.getKey());
if (label.equals("Public") && (playlist.getVideoChannelId() == null || playlist.getVideoChannelId().equals(""))) {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlist.setPrivacy(privacyToSend);
}
//new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST, playlist, null, null, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig.getCompleted().autoClear = true;
try {
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
new MultipartUploadRequest(AllPlaylistsActivity.this, "https://" + Helper.getLiveInstance(AllPlaylistsActivity.this) + "/api/v1/video-playlists/")
//.addFileToUpload(uri.toString().replace("file://",""), "videofile")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
// .addParameter("name", filename)
.addParameter("videoChannelId", idChannel)
.addParameter("privacy", idPrivacy)
.addParameter("displayName", playlist.getDisplayName())
.addParameter("description", playlist.getDescription())
.setMaxRetries(1)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here
}
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
// your code here
exception.printStackTrace();
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
DisplayPlaylistsFragment displayPlaylistsFragment;
displayPlaylistsFragment = (DisplayPlaylistsFragment) getSupportFragmentManager().findFragmentByTag("PLAYLISTS");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (displayPlaylistsFragment != null) {
ft.detach(displayPlaylistsFragment);
ft.attach(displayPlaylistsFragment);
ft.commit();
}
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here
}
})
.startUpload();
} catch (MalformedURLException e) {
e.printStackTrace();
}
dialog.dismiss();
add_new.setEnabled(false);
}
} else {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
Playlist playlist = new Playlist();
playlist.setDisplayName(display_name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
playlist.setDescription(description.getText().toString().trim());
}
String idChannel = null;
if (channelToSend != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
idChannel = channelM.getValue();
if (idChannel.length() > 0)
playlist.setVideoChannelId(idChannel);
}
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
String label = privacyM.getValue();
String idPrivacy = String.valueOf(privacyM.getKey());
if (label.equals("Public") && (playlist.getVideoChannelId() == null || playlist.getVideoChannelId().equals(""))) {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlist.setPrivacy(privacyToSend);
}
//new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST, playlist, null, null, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig.getCompleted().autoClear = true;
try {
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
new MultipartUploadRequest(AllPlaylistsActivity.this, "https://" + Helper.getLiveInstance(AllPlaylistsActivity.this) + "/api/v1/video-playlists/")
//.addFileToUpload(uri.toString().replace("file://",""), "videofile")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
// .addParameter("name", filename)
.addParameter("videoChannelId", idChannel)
.addParameter("privacy", idPrivacy)
.addParameter("displayName", playlist.getDisplayName())
.addParameter("description", playlist.getDescription())
.setMaxRetries(1)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here
}
});
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
// your code here
exception.printStackTrace();
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
asyncTask = new ManagePlaylistsAsyncTask(AllPlaylistsActivity.this, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here
}
})
.startUpload();
} catch (MalformedURLException e) {
e.printStackTrace();
}
dialog.dismiss();
add_new.setEnabled(false);
}
} else {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
}
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_playlist_create));
alertDialog.setOnDismissListener(dialogInterface -> {
//Hide keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0);
});
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
});
}
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_playlist_create));
alertDialog.setOnDismissListener(dialogInterface -> {
//Hide keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0);
});
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
});
}
@Override
@ -251,28 +236,15 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
this.playlists.addAll(apiResponse.getPlaylists());
playlistAdapter.notifyDataSetChanged();
List<Playlist> playlists = new ArrayList<>();
ListView lv_playlist = findViewById(R.id.lv_playlist);
PlaylistAdapter playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
playlists.addAll(apiResponse.getPlaylists());
lv_playlist.setAdapter(playlistAdapter);
textviewNoAction.setVisibility(View.GONE);
} else {
textviewNoAction.setVisibility(View.VISIBLE);
}
} else if (actionType == ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
Intent intent = new Intent(AllPlaylistsActivity.this, PlaylistsActivity.class);
Bundle b = new Bundle();
b.putParcelable("playlist", apiResponse.getPlaylists().get(0));
intent.putExtras(b);
startActivity(intent);
this.playlists.add(0, apiResponse.getPlaylists().get(0));
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
} else {
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
}
} else if (actionType == ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST) {
if (this.playlists.size() == 0)
textviewNoAction.setVisibility(View.VISIBLE);
}
}

View File

@ -5,12 +5,16 @@ import android.content.Context;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import net.gotev.uploadservice.UploadService;
public class FedilabTupe extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(FedilabTupe.this);
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
}

View File

@ -74,6 +74,7 @@ import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.Peertube;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
import app.fedilab.fedilabtube.client.entities.Status;
import app.fedilab.fedilabtube.client.entities.StatusDrawerParams;
import app.fedilab.fedilabtube.drawer.StatusListAdapter;
@ -117,7 +118,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
private ImageView send;
private TextView add_comment_read;
private EditText add_comment_write;
private List<String> playlistForVideo;
private List<PlaylistElement> playlistForVideo;
private List<Playlist> playlists;
public static void hideKeyboard(Activity activity) {
@ -228,7 +229,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
initFullscreenDialog();
initFullscreenButton();
}
if (Helper.isLoggedIn(PeertubeActivity.this)) {
if( Helper.isLoggedIn(PeertubeActivity.this)) {
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST, null, null, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -315,55 +316,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube_playlist.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) {
if (playlists != null && peertube.getId() != null) {
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
for (Playlist playlist : playlists) {
String title = null;
for (String id : playlistForVideo) {
if (playlist.getId().equals(id)) {
title = "" + playlist.getDisplayName();
break;
}
}
if (title == null) {
title = playlist.getDisplayName();
}
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
item.setOnMenuItemClickListener(item1 -> {
item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item1.setActionView(new View(PeertubeActivity.this));
item1.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item1) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item1) {
return false;
}
});
if (playlistForVideo.contains(playlist.getId())) {
item1.setTitle(playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.remove(playlist.getId());
} else {
item1.setTitle("" + playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.add(playlist.getId());
}
return false;
});
popup.show();
}
}
} else {
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
}
});
add_comment_read.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) {
@ -400,9 +352,15 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
for (Playlist playlist : playlists) {
String title = null;
for (String id : playlistForVideo) {
if (playlist.getId().equals(id)) {
boolean isPresent = false;
String elementId = null;
PlaylistElement playlistElementFinal = null;
for (PlaylistElement playlistElement : playlistForVideo) {
if (playlist.getId().equals(playlistElement.getPlaylistId())) {
title = "" + playlist.getDisplayName();
isPresent = true;
elementId = playlistElement.getPlaylistElementId();
playlistElementFinal = playlistElement;
break;
}
}
@ -410,6 +368,9 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
title = playlist.getDisplayName();
}
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
boolean finalIsPresent = isPresent;
String finalElementId = elementId;
PlaylistElement finalPlaylistElementFinal = playlistElementFinal;
item.setOnMenuItemClickListener(item1 -> {
item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item1.setActionView(new View(PeertubeActivity.this));
@ -424,14 +385,17 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
return false;
}
});
if (playlistForVideo.contains(playlist.getId())) {
if (finalIsPresent) {
item1.setTitle(playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.remove(playlist.getId());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, finalElementId, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.remove(finalPlaylistElementFinal);
} else {
item1.setTitle("" + playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.add(playlist.getId());
PlaylistElement playlistElement = new PlaylistElement();
playlistElement.setPlaylistElementId(finalElementId);
playlistElement.setPlaylistId(playlist.getId());
playlistForVideo.add(playlistElement);
}
return false;
});

View File

@ -9,6 +9,7 @@ import app.fedilab.fedilabtube.client.entities.Instance;
import app.fedilab.fedilabtube.client.entities.Peertube;
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
import app.fedilab.fedilabtube.client.entities.Status;
public class APIResponse {
@ -22,7 +23,7 @@ public class APIResponse {
private List<String> domains = null;
private Error error = null;
private String since_id, max_id;
private List<String> playlistForVideos;
private List<PlaylistElement> playlistForVideos;
private Instance instance;
private String stringData;
@ -94,11 +95,11 @@ public class APIResponse {
this.playlists = playlists;
}
public List<String> getPlaylistForVideos() {
public List<PlaylistElement> getPlaylistForVideos() {
return playlistForVideos;
}
public void setPlaylistForVideos(List<String> playlistForVideos) {
public void setPlaylistForVideos(List<PlaylistElement> playlistForVideos) {
this.playlistForVideos = playlistForVideos;
}

View File

@ -41,6 +41,7 @@ import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
import app.fedilab.fedilabtube.client.entities.PeertubeVideoNotification;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
import app.fedilab.fedilabtube.client.entities.Status;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
@ -1469,16 +1470,18 @@ public class PeertubeAPI {
HashMap<String, String> params = new HashMap<>();
params.put("videoIds", videoId);
List<String> ids = new ArrayList<>();
List<PlaylistElement> ids = new ArrayList<>();
try {
String response = new HttpsConnection(context).get(getAbsoluteUrl("/users/me/video-playlists/videos-exist"), 60, params, prefKeyOauthTokenT);
JSONArray jsonArray = new JSONObject(response).getJSONArray(videoId);
try {
int i = 0;
while (i < jsonArray.length()) {
PlaylistElement playlistElement = new PlaylistElement();
JSONObject resobj = jsonArray.getJSONObject(i);
String playlistId = resobj.getString("playlistId");
ids.add(playlistId);
playlistElement.setPlaylistId(resobj.getString("playlistId"));
playlistElement.setPlaylistElementId(resobj.getString("playlistElementId"));
ids.add(playlistElement);
i++;
}
} catch (JSONException e) {
@ -1549,6 +1552,7 @@ public class PeertubeAPI {
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
}

View File

@ -0,0 +1,41 @@
package app.fedilab.fedilabtube.client.entities;
public class PlaylistElement {
private String playlistElementId;
private String playlistId;
private long startTimestamp;
private long stopTimestamp;
public String getPlaylistElementId() {
return playlistElementId;
}
public void setPlaylistElementId(String playlistElementId) {
this.playlistElementId = playlistElementId;
}
public String getPlaylistId() {
return playlistId;
}
public void setPlaylistId(String playlistId) {
this.playlistId = playlistId;
}
public long getStartTimestamp() {
return startTimestamp;
}
public void setStartTimestamp(long startTimestamp) {
this.startTimestamp = startTimestamp;
}
public long getStopTimestamp() {
return stopTimestamp;
}
public void setStopTimestamp(long stopTimestamp) {
this.stopTimestamp = stopTimestamp;
}
}

View File

@ -32,14 +32,12 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
private List<Playlist> playlists;
private LayoutInflater layoutInflater;
private Context context;
private PlaylistAdapter playlistAdapter;
private RelativeLayout textviewNoAction;
public PlaylistAdapter(Context context, List<Playlist> lists, RelativeLayout textviewNoAction) {
this.playlists = lists;
layoutInflater = LayoutInflater.from(context);
this.context = context;
playlistAdapter = this;
this.textviewNoAction = textviewNoAction;
}
@ -97,7 +95,7 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
builder.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.yes, (dialog, which) -> {
playlists.remove(playlist);
playlistAdapter.notifyDataSetChanged();
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);