fedilab-Android-App/app/src/main/java/app/fedilab/android/activities/PeertubeEditUploadActivity....

604 lines
26 KiB
Java
Raw Normal View History

2019-05-18 11:10:30 +02:00
package app.fedilab.android.activities;
2019-01-07 19:16:15 +01:00
/* Copyright 2019 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* This file is a part of Fedilab
2019-01-07 19:16:15 +01:00
*
* 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.
*
2019-05-18 11:10:30 +02:00
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2019-01-07 19:16:15 +01:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
2019-01-07 19:16:15 +01:00
* see <http://www.gnu.org/licenses>. */
2019-01-12 17:36:24 +01:00
import android.content.Intent;
2019-01-07 19:16:15 +01:00
import android.content.SharedPreferences;
2019-11-13 12:54:01 +01:00
import android.graphics.drawable.ColorDrawable;
2019-01-07 19:16:15 +01:00
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2019-11-20 11:57:25 +01:00
import android.widget.AdapterView;
2019-01-07 19:16:15 +01:00
import android.widget.ArrayAdapter;
import android.widget.Button;
2019-01-08 16:24:02 +01:00
import android.widget.CheckBox;
import android.widget.EditText;
2019-01-07 19:16:15 +01:00
import android.widget.ImageView;
2019-08-18 17:41:10 +02:00
import android.widget.LinearLayout;
2019-11-20 11:57:25 +01:00
import android.widget.Spinner;
2019-01-07 19:16:15 +01:00
import android.widget.TextView;
import android.widget.Toast;
2019-11-15 16:32:25 +01:00
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
2019-01-08 19:29:07 +01:00
import java.util.HashMap;
2019-01-08 16:24:02 +01:00
import java.util.Iterator;
import java.util.LinkedHashMap;
2019-01-07 19:16:15 +01:00
import java.util.List;
2019-01-08 16:24:02 +01:00
import java.util.Map;
2019-01-07 19:16:15 +01:00
2019-11-15 16:32:25 +01:00
import app.fedilab.android.R;
import app.fedilab.android.asynctasks.PostActionAsyncTask;
import app.fedilab.android.asynctasks.PostPeertubeAsyncTask;
import app.fedilab.android.asynctasks.RetrievePeertubeChannelsAsyncTask;
import app.fedilab.android.asynctasks.RetrievePeertubeSingleAsyncTask;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.client.Entities.Peertube;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.interfaces.OnPostActionInterface;
import app.fedilab.android.interfaces.OnRetrievePeertubeInterface;
2019-11-15 16:32:25 +01:00
import es.dmoral.toasty.Toasty;
2019-01-08 16:24:02 +01:00
import mabbas007.tagsedittext.TagsEditText;
2019-01-07 19:16:15 +01:00
2019-01-09 10:13:35 +01:00
import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
2019-05-18 11:10:30 +02:00
import static app.fedilab.android.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
2019-01-07 19:16:15 +01:00
2019-01-12 17:36:24 +01:00
public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface, OnPostActionInterface {
2019-01-07 19:16:15 +01:00
2019-11-15 16:32:25 +01:00
HashMap<Integer, String> categoryToSend;
HashMap<Integer, String> licenseToSend;
HashMap<Integer, String> privacyToSend;
HashMap<String, String> languageToSend;
HashMap<String, String> channelToSend;
2019-11-20 11:57:25 +01:00
private Button set_upload_submit;
private Spinner set_upload_privacy, set_upload_categories, set_upload_licenses, set_upload_languages, set_upload_channel;
2019-01-08 16:24:02 +01:00
private EditText p_video_title, p_video_description;
private TagsEditText p_video_tags;
private CheckBox set_upload_nsfw, set_upload_enable_comments;
2019-01-08 16:43:17 +01:00
private LinkedHashMap<String, String> channels;
2019-01-07 19:16:15 +01:00
private String videoId;
2019-01-08 16:43:17 +01:00
private Account channel;
2019-01-08 16:24:02 +01:00
2019-01-07 19:16:15 +01:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2019-05-18 11:10:30 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
2019-01-07 19:16:15 +01:00
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2019-09-06 17:55:14 +02:00
switch (theme) {
2019-01-07 19:16:15 +01:00
case Helper.THEME_LIGHT:
2019-11-09 15:47:38 +01:00
setTheme(R.style.AppTheme_Fedilab);
2019-01-07 19:16:15 +01:00
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack);
break;
default:
setTheme(R.style.AppThemeDark);
}
Bundle b = getIntent().getExtras();
2019-09-06 17:55:14 +02:00
if (b != null) {
2019-01-07 19:16:15 +01:00
videoId = b.getString("video_id", null);
}
2019-09-06 17:55:14 +02:00
if (videoId == null) {
2019-01-09 16:04:14 +01:00
videoId = sharedpreferences.getString(Helper.VIDEO_ID, null);
}
2019-09-06 17:55:14 +02:00
if (getSupportActionBar() != null)
2019-01-07 19:16:15 +01:00
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
2019-09-06 17:55:14 +02:00
if (actionBar != null) {
2019-05-18 11:10:30 +02:00
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
2019-01-07 19:16:15 +01:00
assert inflater != null;
2020-04-08 12:42:15 +02:00
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PeertubeEditUploadActivity.this), false);
2019-11-15 19:36:39 +01:00
view.setBackground(new ColorDrawable(ContextCompat.getColor(PeertubeEditUploadActivity.this, R.color.cyanea_primary)));
2019-01-07 19:16:15 +01:00
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
2020-04-08 13:01:28 +02:00
toolbar_close.setOnClickListener(v -> finish());
2019-01-08 10:50:43 +01:00
toolbar_title.setText(R.string.update_video);
2019-01-07 19:16:15 +01:00
}
2019-01-08 10:50:43 +01:00
setContentView(R.layout.activity_peertube_edit);
2019-01-07 19:16:15 +01:00
set_upload_submit = findViewById(R.id.set_upload_submit);
2019-11-20 11:57:25 +01:00
Button set_upload_delete = findViewById(R.id.set_upload_delete);
2019-01-08 16:24:02 +01:00
set_upload_privacy = findViewById(R.id.set_upload_privacy);
set_upload_channel = findViewById(R.id.set_upload_channel);
set_upload_categories = findViewById(R.id.set_upload_categories);
set_upload_licenses = findViewById(R.id.set_upload_licenses);
set_upload_languages = findViewById(R.id.set_upload_languages);
p_video_title = findViewById(R.id.p_video_title);
p_video_description = findViewById(R.id.p_video_description);
p_video_tags = findViewById(R.id.p_video_tags);
set_upload_nsfw = findViewById(R.id.set_upload_nsfw);
set_upload_enable_comments = findViewById(R.id.set_upload_enable_comments);
2019-01-09 10:13:35 +01:00
2020-04-08 13:01:28 +02:00
set_upload_delete.setOnClickListener(v -> {
AlertDialog.Builder builderInner;
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme1 = sharedpreferences1.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int style;
if (theme1 == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme1 == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
} else {
style = R.style.Dialog;
2019-01-12 17:36:24 +01:00
}
2020-04-08 13:01:28 +02:00
builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this, style);
builderInner.setMessage(getString(R.string.delete_video_confirmation));
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
new PostActionAsyncTask(PeertubeEditUploadActivity.this, API.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
dialog.dismiss();
});
builderInner.show();
2019-01-12 17:36:24 +01:00
});
2019-01-09 10:13:35 +01:00
//Get params from the API
2019-09-06 17:55:14 +02:00
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
2019-01-08 16:24:02 +01:00
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
LinkedHashMap<String, String> translations = null;
2019-09-06 17:55:14 +02:00
if (peertubeInformation.getTranslations() != null)
2019-01-08 16:24:02 +01:00
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
//Populate catgories
String[] categoriesA = new String[categories.size()];
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
2019-01-08 16:24:02 +01:00
int i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-11-15 16:32:25 +01:00
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
2020-06-17 18:20:35 +02:00
categoriesA[i] = pair.getValue();
2019-01-08 16:24:02 +01:00
else
2019-11-15 16:32:25 +01:00
categoriesA[i] = translations.get(pair.getValue());
2019-01-08 16:24:02 +01:00
it.remove();
i++;
}
ArrayAdapter<String> adapterCatgories = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, categoriesA);
set_upload_categories.setAdapter(adapterCatgories);
//Populate licenses
String[] licensesA = new String[licences.size()];
it = licences.entrySet().iterator();
i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-11-15 16:32:25 +01:00
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
2020-06-17 18:20:35 +02:00
licensesA[i] = pair.getValue();
2019-01-08 16:24:02 +01:00
else
2019-11-15 16:32:25 +01:00
licensesA[i] = translations.get(pair.getValue());
2019-01-08 16:24:02 +01:00
it.remove();
i++;
}
ArrayAdapter<String> adapterLicenses = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, licensesA);
set_upload_licenses.setAdapter(adapterLicenses);
//Populate languages
String[] languagesA = new String[languages.size()];
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<String, String>> itl = languages.entrySet().iterator();
2019-01-08 16:24:02 +01:00
i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<String, String> pair = itl.next();
2019-11-15 16:32:25 +01:00
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
2020-06-17 18:20:35 +02:00
languagesA[i] = pair.getValue();
2019-01-08 16:24:02 +01:00
else
2019-11-15 16:32:25 +01:00
languagesA[i] = translations.get(pair.getValue());
2019-01-08 16:24:02 +01:00
it.remove();
i++;
}
ArrayAdapter<String> adapterLanguages = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, languagesA);
set_upload_languages.setAdapter(adapterLanguages);
//Populate languages
String[] privaciesA = new String[privacies.size()];
it = privacies.entrySet().iterator();
i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-11-15 16:32:25 +01:00
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
2020-06-17 18:20:35 +02:00
privaciesA[i] = pair.getValue();
2019-01-08 16:24:02 +01:00
else
2019-11-15 16:32:25 +01:00
privaciesA[i] = translations.get(pair.getValue());
2019-01-08 16:24:02 +01:00
it.remove();
i++;
}
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, privaciesA);
set_upload_privacy.setAdapter(adapterPrivacies);
2019-01-07 19:16:15 +01:00
2020-04-08 12:42:15 +02:00
String peertubeInstance = Helper.getLiveInstance(PeertubeEditUploadActivity.this);
2019-01-07 19:16:15 +01:00
new RetrievePeertubeSingleAsyncTask(PeertubeEditUploadActivity.this, peertubeInstance, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2019-01-08 16:43:17 +01:00
channels = new LinkedHashMap<>();
2019-01-09 17:30:18 +01:00
2019-01-07 19:16:15 +01:00
}
@Override
public void onRetrievePeertube(APIResponse apiResponse) {
2019-09-06 17:55:14 +02:00
if (apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
2020-04-08 12:42:15 +02:00
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
2019-01-07 19:16:15 +01:00
else
2020-04-08 12:42:15 +02:00
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
2019-01-09 15:27:02 +01:00
set_upload_submit.setEnabled(true);
2019-01-07 19:16:15 +01:00
return;
}
//Peertube video
Peertube peertube = apiResponse.getPeertubes().get(0);
2019-01-08 16:24:02 +01:00
2019-09-06 17:55:14 +02:00
if (peertube.isUpdate()) {
2020-04-08 12:42:15 +02:00
Toasty.success(PeertubeEditUploadActivity.this, getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show();
2019-01-09 10:13:35 +01:00
peertube.setUpdate(false);
2019-01-09 15:27:02 +01:00
set_upload_submit.setEnabled(true);
2019-09-06 17:55:14 +02:00
} else {
2019-01-09 15:27:02 +01:00
new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2019-01-09 10:13:35 +01:00
}
languageToSend = peertube.getLanguage();
licenseToSend = peertube.getLicense();
privacyToSend = peertube.getPrivacy();
categoryToSend = peertube.getCategory();
2019-01-09 17:30:18 +01:00
2019-09-06 17:55:14 +02:00
if (languageToSend == null) {
2019-01-09 17:30:18 +01:00
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
2019-09-06 17:55:14 +02:00
Map.Entry<String, String> entryString = languages.entrySet().iterator().next();
2019-01-09 17:30:18 +01:00
languageToSend = new HashMap<>();
languageToSend.put(entryString.getKey(), entryString.getValue());
}
2019-09-06 17:55:14 +02:00
if (licenseToSend == null) {
2019-01-09 17:30:18 +01:00
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
2019-09-06 17:55:14 +02:00
Map.Entry<Integer, String> entryInt = licences.entrySet().iterator().next();
2019-01-09 17:30:18 +01:00
licenseToSend = new HashMap<>();
licenseToSend.put(entryInt.getKey(), entryInt.getValue());
}
2019-09-06 17:55:14 +02:00
if (categoryToSend == null) {
2019-01-09 17:30:18 +01:00
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
2019-09-06 17:55:14 +02:00
Map.Entry<Integer, String> entryInt = categories.entrySet().iterator().next();
2019-01-09 17:30:18 +01:00
categoryToSend = new HashMap<>();
categoryToSend.put(entryInt.getKey(), entryInt.getValue());
}
2019-09-06 17:55:14 +02:00
if (privacyToSend == null) {
2019-01-09 17:30:18 +01:00
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
2019-09-06 17:55:14 +02:00
Map.Entry<Integer, String> entryInt = privacies.entrySet().iterator().next();
2019-01-09 17:30:18 +01:00
privacyToSend = new HashMap<>();
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
}
2019-01-09 15:27:02 +01:00
String language = null;
2019-09-06 17:55:14 +02:00
if (languageToSend != null) {
2019-01-09 15:27:02 +01:00
Map.Entry<String, String> entryString = languageToSend.entrySet().iterator().next();
language = entryString.getValue();
}
String license = null;
2019-09-06 17:55:14 +02:00
if (licenseToSend != null) {
2019-01-09 15:27:02 +01:00
Map.Entry<Integer, String> entryInt = licenseToSend.entrySet().iterator().next();
license = entryInt.getValue();
}
String privacy = null;
2019-09-06 17:55:14 +02:00
if (privacyToSend != null) {
2019-01-09 15:27:02 +01:00
Map.Entry<Integer, String> entryInt = privacyToSend.entrySet().iterator().next();
privacy = entryInt.getValue();
}
2019-01-08 19:29:07 +01:00
2019-01-09 15:27:02 +01:00
String category = null;
2019-09-06 17:55:14 +02:00
if (categoryToSend != null) {
2019-01-09 15:27:02 +01:00
Map.Entry<Integer, String> entryInt = categoryToSend.entrySet().iterator().next();
category = entryInt.getValue();
}
2019-01-08 19:29:07 +01:00
2019-01-08 16:43:17 +01:00
channel = peertube.getChannel();
2019-01-08 16:24:02 +01:00
String title = peertube.getName();
boolean commentEnabled = peertube.isCommentsEnabled();
boolean isNSFW = peertube.isSensitive();
set_upload_enable_comments.setChecked(commentEnabled);
set_upload_nsfw.setChecked(isNSFW);
p_video_title.setText(title);
2019-01-08 19:29:07 +01:00
p_video_description.setText(peertube.getDescription());
2019-01-08 16:24:02 +01:00
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
int languagePosition = 0;
2019-09-06 17:55:14 +02:00
if (languages.containsValue(language)) {
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<String, String>> it = languages.entrySet().iterator();
2019-01-08 16:24:02 +01:00
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<String, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (pair.getValue().equals(language))
2019-01-08 16:24:02 +01:00
break;
it.remove();
languagePosition++;
}
}
int privacyPosition = 0;
2019-09-06 17:55:14 +02:00
if (privacy != null && privacies.containsValue(privacy)) {
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<Integer, String>> it = privacies.entrySet().iterator();
2019-01-08 16:24:02 +01:00
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (pair.getValue().equals(privacy))
2019-01-08 16:24:02 +01:00
break;
it.remove();
privacyPosition++;
}
}
int licensePosition = 0;
2019-09-06 17:55:14 +02:00
if (license != null && licences.containsValue(license)) {
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<Integer, String>> it = licences.entrySet().iterator();
2019-01-08 16:24:02 +01:00
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (pair.getValue().equals(license))
2019-01-08 16:24:02 +01:00
break;
it.remove();
licensePosition++;
}
}
int categoryPosition = 0;
2019-09-06 17:55:14 +02:00
if (category != null && categories.containsValue(category)) {
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
2019-01-08 16:24:02 +01:00
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (pair.getValue().equals(category))
2019-01-08 16:24:02 +01:00
break;
it.remove();
categoryPosition++;
}
}
2019-01-09 10:13:35 +01:00
//Manage privacies
2019-11-20 11:57:25 +01:00
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2019-01-09 10:13:35 +01:00
@Override
2019-11-20 11:57:25 +01:00
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
2019-01-09 10:13:35 +01:00
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<Integer, String>> it = privaciesCheck.entrySet().iterator();
2019-01-09 10:13:35 +01:00
int i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (i == position) {
2019-01-09 10:13:35 +01:00
privacyToSend = new HashMap<>();
2020-06-17 18:20:35 +02:00
privacyToSend.put(pair.getKey(), pair.getValue());
2019-01-09 10:13:35 +01:00
break;
}
it.remove();
i++;
}
}
2019-11-20 11:57:25 +01:00
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
2019-01-09 10:13:35 +01:00
});
2019-11-20 11:57:25 +01:00
set_upload_licenses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2019-01-09 10:13:35 +01:00
@Override
2019-11-20 11:57:25 +01:00
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
2019-01-09 10:13:35 +01:00
LinkedHashMap<Integer, String> licensesCheck = new LinkedHashMap<>(peertubeInformation.getLicences());
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<Integer, String>> it = licensesCheck.entrySet().iterator();
2019-01-09 10:13:35 +01:00
int i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (i == position) {
2019-01-09 10:13:35 +01:00
licenseToSend = new HashMap<>();
2020-06-17 18:20:35 +02:00
licenseToSend.put(pair.getKey(), pair.getValue());
2019-01-09 10:13:35 +01:00
break;
}
it.remove();
i++;
}
}
2019-11-20 11:57:25 +01:00
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
2019-01-09 10:13:35 +01:00
});
//Manage categories
2019-11-20 11:57:25 +01:00
set_upload_categories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2019-01-09 10:13:35 +01:00
@Override
2019-11-20 11:57:25 +01:00
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
2019-01-09 10:13:35 +01:00
LinkedHashMap<Integer, String> categoriesCheck = new LinkedHashMap<>(peertubeInformation.getCategories());
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<Integer, String>> it = categoriesCheck.entrySet().iterator();
2019-01-09 10:13:35 +01:00
int i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<Integer, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (i == position) {
2019-01-09 10:13:35 +01:00
categoryToSend = new HashMap<>();
2020-06-17 18:20:35 +02:00
categoryToSend.put(pair.getKey(), pair.getValue());
2019-01-09 10:13:35 +01:00
break;
}
it.remove();
i++;
}
}
2019-11-20 11:57:25 +01:00
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
2019-01-09 10:13:35 +01:00
});
2019-11-20 11:57:25 +01:00
2019-01-09 10:13:35 +01:00
//Manage languages
2019-11-20 11:57:25 +01:00
set_upload_languages.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2019-01-09 10:13:35 +01:00
@Override
2019-11-20 11:57:25 +01:00
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
2019-01-09 10:13:35 +01:00
LinkedHashMap<String, String> languagesCheck = new LinkedHashMap<>(peertubeInformation.getLanguages());
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<String, String>> it = languagesCheck.entrySet().iterator();
2019-01-09 10:13:35 +01:00
int i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<String, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (i == position) {
2019-01-09 10:13:35 +01:00
languageToSend = new HashMap<>();
2020-06-17 18:20:35 +02:00
languageToSend.put(pair.getKey(), pair.getValue());
2019-01-09 10:13:35 +01:00
break;
}
it.remove();
i++;
}
}
2019-11-20 11:57:25 +01:00
@Override
public void onNothingSelected(AdapterView<?> parent) {
2019-01-09 10:13:35 +01:00
2019-11-20 11:57:25 +01:00
}
});
2019-01-09 10:13:35 +01:00
//Manage languages
2019-11-20 11:57:25 +01:00
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2019-01-09 10:13:35 +01:00
@Override
2019-11-20 11:57:25 +01:00
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
2019-01-09 10:13:35 +01:00
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<String, String>> it = channelsCheck.entrySet().iterator();
2019-01-09 10:13:35 +01:00
int i = 0;
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<String, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (i == position) {
2019-01-09 10:13:35 +01:00
channelToSend = new HashMap<>();
2020-06-17 18:20:35 +02:00
channelToSend.put(pair.getKey(), pair.getValue());
2019-01-09 15:27:02 +01:00
2019-01-09 10:13:35 +01:00
break;
}
it.remove();
i++;
}
}
2019-11-20 11:57:25 +01:00
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
2019-01-09 10:13:35 +01:00
});
2020-04-08 13:01:28 +02:00
set_upload_submit.setOnClickListener(v -> {
String title1 = p_video_title.getText().toString().trim();
String description = p_video_description.getText().toString().trim();
boolean isNSFW1 = set_upload_nsfw.isChecked();
boolean commentEnabled1 = set_upload_enable_comments.isChecked();
peertube.setName(title1);
peertube.setDescription(description);
peertube.setSensitive(isNSFW1);
peertube.setCommentsEnabled(commentEnabled1);
peertube.setCategory(categoryToSend);
peertube.setLicense(licenseToSend);
peertube.setLanguage(languageToSend);
peertube.setChannelForUpdate(channelToSend);
peertube.setPrivacy(privacyToSend);
List<String> tags = p_video_tags.getTags();
peertube.setTags(tags);
set_upload_submit.setEnabled(false);
new PostPeertubeAsyncTask(PeertubeEditUploadActivity.this, peertube, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
2019-01-09 10:13:35 +01:00
});
2019-11-20 11:57:25 +01:00
set_upload_privacy.setSelection(privacyPosition);
set_upload_languages.setSelection(languagePosition);
set_upload_licenses.setSelection(licensePosition);
set_upload_categories.setSelection(categoryPosition);
2019-01-08 16:24:02 +01:00
List<String> tags = peertube.getTags();
2019-09-06 17:55:14 +02:00
if (tags != null && tags.size() > 0) {
2020-06-17 18:20:35 +02:00
String[] tagsA = tags.toArray(new String[0]);
2019-01-08 16:24:02 +01:00
p_video_tags.setTags(tagsA);
}
2019-01-08 16:43:17 +01:00
2019-01-07 19:16:15 +01:00
}
@Override
public void onRetrievePeertubeComments(APIResponse apiResponse) {
}
@Override
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
2019-09-06 17:55:14 +02:00
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
if (apiResponse.getError().getError() != null)
2020-04-08 12:42:15 +02:00
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
2019-01-07 19:16:15 +01:00
else
2020-04-08 12:42:15 +02:00
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
2019-01-07 19:16:15 +01:00
return;
}
//Populate channels
List<Account> accounts = apiResponse.getAccounts();
String[] channelName = new String[accounts.size()];
int i = 0;
2019-09-06 17:55:14 +02:00
for (Account account : accounts) {
channels.put(account.getUsername(), account.getId());
2019-01-07 19:16:15 +01:00
channelName[i] = account.getUsername();
i++;
}
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, channelName);
set_upload_channel.setAdapter(adapterChannel);
2019-01-08 16:43:17 +01:00
int channelPosition = 0;
2019-09-06 17:55:14 +02:00
if (channels.containsKey(channel.getUsername())) {
2019-01-09 10:13:35 +01:00
LinkedHashMap<String, String> channelsIterator = new LinkedHashMap<>(channels);
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<String, String>> it = channelsIterator.entrySet().iterator();
2019-01-08 16:43:17 +01:00
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<String, String> pair = it.next();
2019-09-06 17:55:14 +02:00
if (pair.getKey().equals(channel.getUsername())) {
2019-01-09 15:27:02 +01:00
channelToSend = new HashMap<>();
2020-06-17 18:20:35 +02:00
channelToSend.put(pair.getKey(), pair.getValue());
2019-01-08 16:43:17 +01:00
break;
2019-01-09 15:27:02 +01:00
}
2019-01-08 16:43:17 +01:00
it.remove();
channelPosition++;
}
}
2019-11-20 11:57:25 +01:00
set_upload_channel.setSelection(channelPosition);
2019-01-08 16:43:17 +01:00
set_upload_submit.setEnabled(true);
2019-01-07 19:16:15 +01:00
}
2019-01-12 17:36:24 +01:00
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
2020-04-08 12:42:15 +02:00
Intent intent = new Intent(PeertubeEditUploadActivity.this, MainActivity.class);
2019-05-18 11:10:30 +02:00
intent.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS);
2019-01-12 17:36:24 +01:00
startActivity(intent);
finish();
}
2019-01-07 19:16:15 +01:00
}