Fix remove from list
This commit is contained in:
parent
d6fbba857f
commit
df06590b00
|
@ -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,7 +97,6 @@ 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);
|
||||
|
@ -176,14 +169,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
|||
|
||||
@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();
|
||||
}
|
||||
asyncTask = new ManagePlaylistsAsyncTask(AllPlaylistsActivity.this, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -220,7 +206,6 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
|||
alertDialog.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue