2019-05-26 15:56:02 +02:00
|
|
|
package app.fedilab.android.fragments;
|
|
|
|
/* Copyright 2019 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Fedilab
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.InputFilter;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2019-11-20 11:57:25 +01:00
|
|
|
import android.widget.AdapterView;
|
2019-05-26 17:56:02 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2019-05-26 15:56:02 +02:00
|
|
|
import android.widget.EditText;
|
2019-08-18 17:41:10 +02:00
|
|
|
import android.widget.LinearLayout;
|
2019-05-26 15:56:02 +02:00
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.RelativeLayout;
|
2019-11-20 11:57:25 +01:00
|
|
|
import android.widget.Spinner;
|
2019-05-26 15:56:02 +02:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
2019-05-26 17:56:02 +02:00
|
|
|
|
2019-05-26 19:41:04 +02:00
|
|
|
import net.gotev.uploadservice.MultipartUploadRequest;
|
|
|
|
import net.gotev.uploadservice.ServerResponse;
|
|
|
|
import net.gotev.uploadservice.UploadInfo;
|
|
|
|
import net.gotev.uploadservice.UploadNotificationConfig;
|
|
|
|
import net.gotev.uploadservice.UploadStatusDelegate;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-05-26 19:41:04 +02:00
|
|
|
import java.net.MalformedURLException;
|
2019-05-26 15:56:02 +02:00
|
|
|
import java.util.ArrayList;
|
2019-05-26 17:56:02 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedHashMap;
|
2019-05-26 15:56:02 +02:00
|
|
|
import java.util.List;
|
2019-05-26 17:56:02 +02:00
|
|
|
import java.util.Map;
|
2019-11-20 11:57:25 +01:00
|
|
|
import java.util.Objects;
|
2019-05-26 15:56:02 +02:00
|
|
|
|
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.activities.MainActivity;
|
2019-05-26 19:41:04 +02:00
|
|
|
import app.fedilab.android.activities.PlaylistsActivity;
|
2019-05-26 15:56:02 +02:00
|
|
|
import app.fedilab.android.asynctasks.ManagePlaylistsAsyncTask;
|
2019-05-26 17:56:02 +02:00
|
|
|
import app.fedilab.android.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
2019-05-26 15:56:02 +02:00
|
|
|
import app.fedilab.android.client.APIResponse;
|
2019-05-26 17:56:02 +02:00
|
|
|
import app.fedilab.android.client.Entities.Account;
|
|
|
|
import app.fedilab.android.client.Entities.Playlist;
|
|
|
|
import app.fedilab.android.drawers.PlaylistAdapter;
|
2019-05-26 15:56:02 +02:00
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.interfaces.OnPlaylistActionInterface;
|
2019-05-26 17:56:02 +02:00
|
|
|
import app.fedilab.android.interfaces.OnRetrievePeertubeInterface;
|
2019-05-26 15:56:02 +02:00
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
|
2019-05-26 17:56:02 +02:00
|
|
|
import static app.fedilab.android.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
|
|
|
|
2019-05-26 15:56:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 26/05/2019.
|
|
|
|
* Fragment to display Playlists
|
|
|
|
*/
|
2019-05-26 17:56:02 +02:00
|
|
|
public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActionInterface, OnRetrievePeertubeInterface {
|
2019-05-26 15:56:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
private Context context;
|
2019-05-26 17:56:02 +02:00
|
|
|
private List<Playlist> playlists;
|
2019-05-26 15:56:02 +02:00
|
|
|
private RelativeLayout mainLoader;
|
|
|
|
private FloatingActionButton add_new;
|
2019-05-26 17:56:02 +02:00
|
|
|
private PlaylistAdapter playlistAdapter;
|
2019-05-26 15:56:02 +02:00
|
|
|
private RelativeLayout textviewNoAction;
|
2019-05-26 17:56:02 +02:00
|
|
|
private HashMap<Integer, String> privacyToSend;
|
|
|
|
private HashMap<String, String> channelToSend;
|
2019-11-20 11:57:25 +01:00
|
|
|
private Spinner set_upload_channel;
|
|
|
|
private Spinner set_upload_privacy;
|
2019-05-26 17:56:02 +02:00
|
|
|
private HashMap<String, String> channels;
|
2019-05-26 15:56:02 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
//View for fragment is the same that fragment accounts
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_playlists, container, false);
|
|
|
|
|
|
|
|
context = getContext();
|
2019-05-26 17:56:02 +02:00
|
|
|
playlists = new ArrayList<>();
|
2019-05-26 15:56:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
ListView lv_playlist = rootView.findViewById(R.id.lv_playlist);
|
|
|
|
textviewNoAction = rootView.findViewById(R.id.no_action);
|
|
|
|
mainLoader = rootView.findViewById(R.id.loader);
|
|
|
|
RelativeLayout nextElementLoader = rootView.findViewById(R.id.loading_next_items);
|
|
|
|
mainLoader.setVisibility(View.VISIBLE);
|
|
|
|
nextElementLoader.setVisibility(View.GONE);
|
2019-05-26 17:56:02 +02:00
|
|
|
playlists = new ArrayList<>();
|
|
|
|
playlistAdapter = new PlaylistAdapter(context, playlists, textviewNoAction);
|
|
|
|
lv_playlist.setAdapter(playlistAdapter);
|
2021-01-19 17:43:51 +01:00
|
|
|
new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, DisplayPlaylistsFragment.this);
|
2019-05-26 15:56:02 +02:00
|
|
|
try {
|
|
|
|
add_new = ((MainActivity) context).findViewById(R.id.add_new);
|
2019-09-06 17:55:14 +02:00
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2019-05-26 17:56:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
LinkedHashMap<String, String> translations = null;
|
2019-09-06 17:55:14 +02:00
|
|
|
if (peertubeInformation != null && peertubeInformation.getTranslations() != null)
|
2019-05-26 17:56:02 +02:00
|
|
|
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
|
|
|
|
|
|
|
|
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
2019-09-06 17:55:14 +02:00
|
|
|
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
|
2019-05-26 17:56:02 +02:00
|
|
|
privacyToSend = new HashMap<>();
|
|
|
|
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
|
|
|
|
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
|
|
|
//Populate privacies
|
|
|
|
String[] privaciesA = new String[privacies.size()];
|
|
|
|
Iterator it = privacies.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
2019-09-06 17:55:14 +02:00
|
|
|
Map.Entry pair = (Map.Entry) it.next();
|
2019-11-15 16:32:25 +01:00
|
|
|
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
|
2019-09-06 17:55:14 +02:00
|
|
|
privaciesA[i] = (String) pair.getValue();
|
2019-05-26 17:56:02 +02:00
|
|
|
else
|
2019-11-15 16:32:25 +01:00
|
|
|
privaciesA[i] = translations.get(pair.getValue());
|
2019-05-26 17:56:02 +02:00
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
if (add_new != null) {
|
2019-05-26 17:56:02 +02:00
|
|
|
add_new.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
int style;
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
2019-09-06 17:55:14 +02:00
|
|
|
} else if (theme == Helper.THEME_BLACK) {
|
2019-05-26 17:56:02 +02:00
|
|
|
style = R.style.DialogBlack;
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
2019-05-26 17:56:02 +02:00
|
|
|
style = R.style.Dialog;
|
2019-05-26 15:56:02 +02:00
|
|
|
}
|
2019-05-26 17:56:02 +02:00
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
|
2019-09-06 17:55:14 +02:00
|
|
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
|
|
|
View dialogView = inflater.inflate(R.layout.add_playlist, new LinearLayout(context), false);
|
2019-05-26 17:56:02 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2021-01-19 17:43:51 +01:00
|
|
|
new RetrievePeertubeChannelsAsyncTask(context, DisplayPlaylistsFragment.this);
|
2019-05-26 17:56:02 +02:00
|
|
|
|
|
|
|
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
|
|
|
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
|
|
|
|
|
|
|
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
2019-05-26 19:41:04 +02:00
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
|
2019-05-26 19:41:04 +02:00
|
|
|
|
2019-05-26 17:56:02 +02:00
|
|
|
Playlist playlist = new Playlist();
|
|
|
|
playlist.setDisplayName(display_name.getText().toString().trim());
|
2019-09-06 17:55:14 +02:00
|
|
|
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
|
2019-05-26 17:56:02 +02:00
|
|
|
playlist.setDescription(description.getText().toString().trim());
|
|
|
|
}
|
2019-05-26 19:41:04 +02:00
|
|
|
String idChannel = null;
|
2019-09-06 17:55:14 +02:00
|
|
|
if (channelToSend != null) {
|
2019-05-26 17:56:02 +02:00
|
|
|
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
|
2019-05-26 19:41:04 +02:00
|
|
|
idChannel = channelM.getValue();
|
2019-09-06 17:55:14 +02:00
|
|
|
if (idChannel.length() > 0)
|
2019-05-26 19:41:04 +02:00
|
|
|
playlist.setVideoChannelId(idChannel);
|
2019-05-26 17:56:02 +02:00
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
|
2019-05-26 19:41:04 +02:00
|
|
|
String label = privacyM.getValue();
|
|
|
|
String idPrivacy = String.valueOf(privacyM.getKey());
|
2019-09-06 17:55:14 +02:00
|
|
|
if (label.equals("Public") && (playlist.getVideoChannelId() == null || playlist.getVideoChannelId().equals(""))) {
|
|
|
|
Toasty.error(context, context.getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
|
|
|
|
} else {
|
|
|
|
if (privacyToSend != null) {
|
2019-05-26 19:41:04 +02:00
|
|
|
playlist.setPrivacy(privacyToSend);
|
|
|
|
}
|
2021-01-19 17:43:51 +01:00
|
|
|
//new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST, playlist, null, null, DisplayPlaylistsFragment.this);
|
2019-05-26 19:41:04 +02:00
|
|
|
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
|
|
|
|
uploadConfig.getCompleted().autoClear = true;
|
|
|
|
try {
|
|
|
|
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
|
|
|
new MultipartUploadRequest(context, "https://" + Helper.getLiveInstance(context) + "/api/v1/video-playlists/")
|
|
|
|
//.addFileToUpload(uri.toString().replace("file://",""), "videofile")
|
|
|
|
.addHeader("Authorization", "Bearer " + token)
|
|
|
|
.setNotificationConfig(uploadConfig)
|
2019-09-06 17:55:14 +02:00
|
|
|
// .addParameter("name", filename)
|
2019-05-26 19:41:04 +02:00
|
|
|
.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;
|
2019-09-06 17:55:14 +02:00
|
|
|
if (getActivity() == null)
|
2019-05-26 19:41:04 +02:00
|
|
|
return;
|
|
|
|
displayPlaylistsFragment = (DisplayPlaylistsFragment) getActivity().getSupportFragmentManager().findFragmentByTag("PLAYLISTS");
|
|
|
|
final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
|
2019-09-06 17:55:14 +02:00
|
|
|
if (displayPlaylistsFragment != null) {
|
2019-05-26 19:41:04 +02:00
|
|
|
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);
|
2019-05-26 17:56:02 +02:00
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
|
|
|
Toasty.error(context, context.getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
|
2019-05-26 17:56:02 +02:00
|
|
|
}
|
2019-05-26 19:41:04 +02:00
|
|
|
|
2019-05-26 17:56:02 +02:00
|
|
|
}
|
|
|
|
});
|
2019-11-11 09:34:13 +01:00
|
|
|
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
2019-05-26 17:56:02 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog alertDialog = dialogBuilder.create();
|
2019-05-26 19:41:04 +02:00
|
|
|
alertDialog.setTitle(getString(R.string.action_playlist_create));
|
2019-05-26 17:56:02 +02:00
|
|
|
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss(DialogInterface dialogInterface) {
|
|
|
|
//Hide keyboard
|
|
|
|
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
assert imm != null;
|
|
|
|
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
});
|
2019-09-06 17:55:14 +02:00
|
|
|
if (alertDialog.getWindow() != null)
|
2019-05-26 17:56:02 +02:00
|
|
|
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
|
|
alertDialog.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-05-26 15:56:02 +02:00
|
|
|
return rootView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-09-06 17:55:14 +02:00
|
|
|
public void onCreate(Bundle saveInstance) {
|
2019-05-26 15:56:02 +02:00
|
|
|
super.onCreate(saveInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Context context) {
|
|
|
|
super.onAttach(context);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
|
|
|
mainLoader.setVisibility(View.GONE);
|
|
|
|
add_new.setEnabled(true);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (apiResponse.getError() != null) {
|
2019-11-15 16:32:25 +01:00
|
|
|
if (apiResponse.getError().getError().length() < 100) {
|
2019-09-30 18:14:46 +02:00
|
|
|
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
2019-11-15 16:32:25 +01:00
|
|
|
} else {
|
|
|
|
Toasty.error(context, getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
|
2019-09-30 18:14:46 +02:00
|
|
|
}
|
2019-05-26 15:56:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-05-26 19:41:04 +02:00
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) {
|
2019-05-26 19:41:04 +02:00
|
|
|
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
2019-05-26 17:56:02 +02:00
|
|
|
this.playlists.addAll(apiResponse.getPlaylists());
|
|
|
|
playlistAdapter.notifyDataSetChanged();
|
2019-05-26 15:56:02 +02:00
|
|
|
textviewNoAction.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
} else if (actionType == ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST) {
|
2019-05-26 19:41:04 +02:00
|
|
|
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
|
|
|
Intent intent = new Intent(context, PlaylistsActivity.class);
|
2019-05-26 15:56:02 +02:00
|
|
|
Bundle b = new Bundle();
|
2019-05-26 19:41:04 +02:00
|
|
|
b.putParcelable("playlist", apiResponse.getPlaylists().get(0));
|
2019-05-26 15:56:02 +02:00
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
2019-05-26 17:56:02 +02:00
|
|
|
this.playlists.add(0, apiResponse.getPlaylists().get(0));
|
|
|
|
playlistAdapter.notifyDataSetChanged();
|
2019-05-26 15:56:02 +02:00
|
|
|
textviewNoAction.setVisibility(View.GONE);
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
2019-11-15 16:32:25 +01:00
|
|
|
if (apiResponse.getError().getError().length() < 100) {
|
2019-09-30 18:14:46 +02:00
|
|
|
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
2019-11-15 16:32:25 +01:00
|
|
|
} else {
|
|
|
|
Toasty.error(context, getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
|
2019-09-30 18:14:46 +02:00
|
|
|
}
|
2019-05-26 15:56:02 +02:00
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
} else if (actionType == ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST) {
|
|
|
|
if (this.playlists.size() == 0)
|
2019-05-26 15:56:02 +02:00
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
2019-05-26 17:56:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrievePeertube(APIResponse apiResponse) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
|
|
|
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
|
|
|
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
2019-11-15 16:32:25 +01:00
|
|
|
if (apiResponse.getError().getError().length() < 100) {
|
2019-09-30 18:14:46 +02:00
|
|
|
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
2019-11-15 16:32:25 +01:00
|
|
|
} else {
|
|
|
|
Toasty.error(context, getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
|
2019-09-30 18:14:46 +02:00
|
|
|
}
|
2019-05-26 17:56:02 +02:00
|
|
|
else
|
|
|
|
Toasty.error(context, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Populate channels
|
|
|
|
List<Account> accounts = apiResponse.getAccounts();
|
2019-09-06 17:55:14 +02:00
|
|
|
String[] channelName = new String[accounts.size() + 1];
|
|
|
|
String[] channelId = new String[accounts.size() + 1];
|
2019-05-28 07:46:07 +02:00
|
|
|
int i = 1;
|
|
|
|
channelName[0] = "";
|
|
|
|
channelId[0] = "";
|
|
|
|
channels = new HashMap<>();
|
2019-09-06 17:55:14 +02:00
|
|
|
for (Account account : accounts) {
|
|
|
|
channels.put(account.getUsername(), account.getId());
|
2019-05-26 17:56:02 +02:00
|
|
|
channelName[i] = account.getUsername();
|
|
|
|
channelId[i] = account.getId();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
channelToSend = new HashMap<>();
|
|
|
|
channelToSend.put(channelName[0], channelId[0]);
|
2019-11-20 11:57:25 +01:00
|
|
|
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(Objects.requireNonNull(getActivity()),
|
2019-05-26 17:56:02 +02:00
|
|
|
android.R.layout.simple_spinner_dropdown_item, channelName);
|
|
|
|
set_upload_channel.setAdapter(adapterChannel);
|
|
|
|
|
|
|
|
LinkedHashMap<String, String> translations = null;
|
|
|
|
if (peertubeInformation.getTranslations() != null)
|
|
|
|
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
|
|
|
|
|
2019-05-26 19:41:04 +02:00
|
|
|
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPlaylistPrivacies());
|
2019-05-26 17:56:02 +02:00
|
|
|
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
|
|
|
|
privacyToSend = new HashMap<>();
|
|
|
|
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
|
2019-05-26 19:41:04 +02:00
|
|
|
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPlaylistPrivacies());
|
2019-05-26 17:56:02 +02:00
|
|
|
//Populate privacies
|
|
|
|
String[] privaciesA = new String[privacies.size()];
|
|
|
|
Iterator it = privacies.entrySet().iterator();
|
|
|
|
i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry pair = (Map.Entry) it.next();
|
2019-11-15 16:32:25 +01:00
|
|
|
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
|
2019-05-26 17:56:02 +02:00
|
|
|
privaciesA[i] = (String) pair.getValue();
|
|
|
|
else
|
2019-11-15 16:32:25 +01:00
|
|
|
privaciesA[i] = translations.get(pair.getValue());
|
2019-05-26 17:56:02 +02:00
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2019-11-20 11:57:25 +01:00
|
|
|
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(Objects.requireNonNull(getActivity()),
|
2019-05-26 17:56:02 +02:00
|
|
|
android.R.layout.simple_spinner_dropdown_item, privaciesA);
|
|
|
|
set_upload_privacy.setAdapter(adapterPrivacies);
|
|
|
|
|
|
|
|
//Manage privacies
|
2019-11-20 11:57:25 +01:00
|
|
|
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
2019-05-26 17:56:02 +02:00
|
|
|
@Override
|
2019-11-20 11:57:25 +01:00
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
2019-05-26 17:56:02 +02:00
|
|
|
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
|
|
|
Iterator it = privaciesCheck.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry pair = (Map.Entry) it.next();
|
|
|
|
if (i == position) {
|
|
|
|
privacyToSend = new HashMap<>();
|
|
|
|
privacyToSend.put((Integer) pair.getKey(), (String) pair.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 11:57:25 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
2019-05-26 17:56:02 +02:00
|
|
|
});
|
2019-05-27 19:42:41 +02:00
|
|
|
//Manage languages
|
2019-11-20 11:57:25 +01:00
|
|
|
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
2019-05-27 19:42:41 +02:00
|
|
|
@Override
|
2019-11-20 11:57:25 +01:00
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
2019-05-27 19:42:41 +02:00
|
|
|
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
|
|
|
|
Iterator it = channelsCheck.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
2019-09-06 17:55:14 +02:00
|
|
|
Map.Entry pair = (Map.Entry) it.next();
|
|
|
|
if (i == position) {
|
2019-05-27 19:42:41 +02:00
|
|
|
channelToSend = new HashMap<>();
|
2019-09-06 17:55:14 +02:00
|
|
|
channelToSend.put((String) pair.getKey(), (String) pair.getValue());
|
2019-05-27 19:42:41 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 11:57:25 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
2019-05-27 19:42:41 +02:00
|
|
|
});
|
2019-05-26 17:56:02 +02:00
|
|
|
}
|
2019-05-26 15:56:02 +02:00
|
|
|
}
|