2020-06-26 08:50:49 +02:00
|
|
|
package app.fedilab.fedilabtube;
|
2020-07-01 16:36:08 +02:00
|
|
|
/* Copyright 2020 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of TubeLab
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* TubeLab 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 TubeLab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2020-06-26 08:50:49 +02:00
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
import android.Manifest;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2020-09-03 19:08:53 +02:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.net.Uri;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
2020-09-03 19:08:53 +02:00
|
|
|
import android.view.MenuItem;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.EditText;
|
2020-09-03 19:08:53 +02:00
|
|
|
import android.widget.ImageView;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.widget.Spinner;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2020-06-26 14:34:39 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2020-09-03 19:08:53 +02:00
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
2020-06-26 08:50:49 +02:00
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.net.MalformedURLException;
|
2020-06-26 08:50:49 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2020-09-03 19:08:53 +02:00
|
|
|
import java.util.UUID;
|
2020-06-26 08:50:49 +02:00
|
|
|
|
2020-06-26 14:34:39 +02:00
|
|
|
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
|
|
|
|
import app.fedilab.fedilabtube.asynctasks.PostPeertubeAsyncTask;
|
|
|
|
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
|
|
|
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask;
|
|
|
|
import app.fedilab.fedilabtube.client.APIResponse;
|
|
|
|
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
|
|
|
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.helper.Helper;
|
|
|
|
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
|
|
|
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
2020-06-26 08:50:49 +02:00
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
import mabbas007.tagsedittext.TagsEditText;
|
|
|
|
|
|
|
|
import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
|
2020-06-26 14:34:39 +02:00
|
|
|
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
2020-06-26 08:50:49 +02:00
|
|
|
|
2020-06-26 14:34:39 +02:00
|
|
|
|
|
|
|
public class PeertubeEditUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface {
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
private final int PICK_IMAGE = 50378;
|
|
|
|
private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724;
|
2020-06-26 08:50:49 +02:00
|
|
|
HashMap<Integer, String> categoryToSend;
|
|
|
|
HashMap<Integer, String> licenseToSend;
|
|
|
|
HashMap<Integer, String> privacyToSend;
|
|
|
|
HashMap<String, String> languageToSend;
|
|
|
|
HashMap<String, String> channelToSend;
|
|
|
|
private Button set_upload_submit;
|
|
|
|
private Spinner set_upload_privacy, set_upload_categories, set_upload_licenses, set_upload_languages, set_upload_channel;
|
|
|
|
private EditText p_video_title, p_video_description;
|
|
|
|
private TagsEditText p_video_tags;
|
|
|
|
private CheckBox set_upload_nsfw, set_upload_enable_comments;
|
|
|
|
private LinkedHashMap<String, String> channels;
|
|
|
|
private String videoId;
|
|
|
|
private Account channel;
|
2020-09-03 19:08:53 +02:00
|
|
|
private ImageView p_video_preview;
|
|
|
|
private Button set_preview;
|
|
|
|
private Peertube peertube;
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2020-06-26 14:34:39 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
Bundle b = getIntent().getExtras();
|
|
|
|
|
|
|
|
if (b != null) {
|
|
|
|
videoId = b.getString("video_id", null);
|
|
|
|
}
|
|
|
|
if (videoId == null) {
|
|
|
|
videoId = sharedpreferences.getString(Helper.VIDEO_ID, null);
|
|
|
|
}
|
|
|
|
if (getSupportActionBar() != null)
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
setContentView(R.layout.activity_peertube_edit);
|
|
|
|
set_upload_submit = findViewById(R.id.set_upload_submit);
|
|
|
|
Button set_upload_delete = findViewById(R.id.set_upload_delete);
|
|
|
|
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);
|
2020-09-03 19:08:53 +02:00
|
|
|
p_video_preview = findViewById(R.id.p_video_preview);
|
2020-06-26 08:50:49 +02:00
|
|
|
set_upload_nsfw = findViewById(R.id.set_upload_nsfw);
|
|
|
|
set_upload_enable_comments = findViewById(R.id.set_upload_enable_comments);
|
2020-09-03 19:08:53 +02:00
|
|
|
set_preview = findViewById(R.id.set_preview);
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
set_upload_delete.setOnClickListener(v -> {
|
|
|
|
AlertDialog.Builder builderInner;
|
2020-06-26 14:34:39 +02:00
|
|
|
builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this);
|
2020-06-26 08:50:49 +02:00
|
|
|
builderInner.setMessage(getString(R.string.delete_video_confirmation));
|
|
|
|
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
|
2020-06-26 14:34:39 +02:00
|
|
|
new PostActionAsyncTask(PeertubeEditUploadActivity.this, PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
|
2020-06-26 08:50:49 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
builderInner.show();
|
|
|
|
});
|
|
|
|
//Get params from the API
|
|
|
|
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());
|
|
|
|
LinkedHashMap<String, String> translations = null;
|
2020-07-01 15:08:42 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
if (peertubeInformation.getTranslations() != null)
|
|
|
|
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
|
|
|
|
//Populate catgories
|
|
|
|
String[] categoriesA = new String[categories.size()];
|
|
|
|
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
|
|
|
|
categoriesA[i] = pair.getValue();
|
|
|
|
else
|
|
|
|
categoriesA[i] = translations.get(pair.getValue());
|
|
|
|
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()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
|
|
|
|
licensesA[i] = pair.getValue();
|
|
|
|
else
|
|
|
|
licensesA[i] = translations.get(pair.getValue());
|
|
|
|
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()];
|
|
|
|
Iterator<Map.Entry<String, String>> itl = languages.entrySet().iterator();
|
|
|
|
i = 0;
|
2020-07-01 15:08:42 +02:00
|
|
|
while (itl.hasNext()) {
|
2020-06-26 08:50:49 +02:00
|
|
|
Map.Entry<String, String> pair = itl.next();
|
|
|
|
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
|
|
|
|
languagesA[i] = pair.getValue();
|
|
|
|
else
|
|
|
|
languagesA[i] = translations.get(pair.getValue());
|
2020-07-01 15:08:42 +02:00
|
|
|
itl.remove();
|
2020-06-26 08:50:49 +02:00
|
|
|
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()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue()))
|
|
|
|
privaciesA[i] = pair.getValue();
|
|
|
|
else
|
|
|
|
privaciesA[i] = translations.get(pair.getValue());
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
2020-07-01 15:08:42 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
|
|
|
|
android.R.layout.simple_spinner_dropdown_item, privaciesA);
|
|
|
|
set_upload_privacy.setAdapter(adapterPrivacies);
|
|
|
|
|
|
|
|
|
|
|
|
String peertubeInstance = Helper.getLiveInstance(PeertubeEditUploadActivity.this);
|
|
|
|
new RetrievePeertubeSingleAsyncTask(PeertubeEditUploadActivity.this, peertubeInstance, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
|
|
|
|
channels = new LinkedHashMap<>();
|
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
setTitle(R.string.edit_video);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrievePeertube(APIResponse apiResponse) {
|
|
|
|
if (apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
|
|
|
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
|
|
|
else
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
set_upload_submit.setEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Peertube video
|
2020-09-03 19:08:53 +02:00
|
|
|
peertube = apiResponse.getPeertubes().get(0);
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
if (peertube.isUpdate()) {
|
|
|
|
Toasty.success(PeertubeEditUploadActivity.this, getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show();
|
|
|
|
peertube.setUpdate(false);
|
|
|
|
set_upload_submit.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
languageToSend = peertube.getLanguage();
|
|
|
|
licenseToSend = peertube.getLicense();
|
|
|
|
privacyToSend = peertube.getPrivacy();
|
|
|
|
categoryToSend = peertube.getCategory();
|
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
Glide.with(PeertubeEditUploadActivity.this)
|
|
|
|
.load("https://" + peertube.getInstance() + peertube.getThumbnailPath())
|
|
|
|
.into(p_video_preview);
|
|
|
|
|
|
|
|
set_preview.setOnClickListener(v -> {
|
|
|
|
if (ContextCompat.checkSelfPermission(PeertubeEditUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
|
|
|
|
PackageManager.PERMISSION_GRANTED) {
|
|
|
|
ActivityCompat.requestPermissions(PeertubeEditUploadActivity.this,
|
|
|
|
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
|
|
|
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
intent.setType("image/jpg");
|
|
|
|
String[] mimetypes = {"image/jpg", "image/jpeg"};
|
|
|
|
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
|
|
|
|
startActivityForResult(intent, PICK_IMAGE);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
if (languageToSend == null) {
|
|
|
|
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
|
|
|
Map.Entry<String, String> entryString = languages.entrySet().iterator().next();
|
|
|
|
languageToSend = new HashMap<>();
|
|
|
|
languageToSend.put(entryString.getKey(), entryString.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (licenseToSend == null) {
|
|
|
|
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
|
|
|
|
Map.Entry<Integer, String> entryInt = licences.entrySet().iterator().next();
|
|
|
|
licenseToSend = new HashMap<>();
|
|
|
|
licenseToSend.put(entryInt.getKey(), entryInt.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (categoryToSend == null) {
|
|
|
|
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
|
|
|
|
Map.Entry<Integer, String> entryInt = categories.entrySet().iterator().next();
|
|
|
|
categoryToSend = new HashMap<>();
|
|
|
|
categoryToSend.put(entryInt.getKey(), entryInt.getValue());
|
|
|
|
}
|
|
|
|
if (privacyToSend == null) {
|
|
|
|
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
|
|
|
Map.Entry<Integer, String> entryInt = privacies.entrySet().iterator().next();
|
|
|
|
privacyToSend = new HashMap<>();
|
|
|
|
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
String language = null;
|
|
|
|
if (languageToSend != null) {
|
|
|
|
Map.Entry<String, String> entryString = languageToSend.entrySet().iterator().next();
|
|
|
|
language = entryString.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
String license = null;
|
|
|
|
if (licenseToSend != null) {
|
|
|
|
Map.Entry<Integer, String> entryInt = licenseToSend.entrySet().iterator().next();
|
|
|
|
license = entryInt.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
String privacy = null;
|
|
|
|
if (privacyToSend != null) {
|
|
|
|
Map.Entry<Integer, String> entryInt = privacyToSend.entrySet().iterator().next();
|
|
|
|
privacy = entryInt.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
String category = null;
|
|
|
|
if (categoryToSend != null) {
|
|
|
|
Map.Entry<Integer, String> entryInt = categoryToSend.entrySet().iterator().next();
|
|
|
|
category = entryInt.getValue();
|
|
|
|
}
|
|
|
|
channel = peertube.getChannel();
|
|
|
|
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);
|
|
|
|
p_video_description.setText(peertube.getDescription());
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (languages.containsValue(language)) {
|
|
|
|
Iterator<Map.Entry<String, String>> it = languages.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<String, String> pair = it.next();
|
|
|
|
if (pair.getValue().equals(language))
|
|
|
|
break;
|
|
|
|
it.remove();
|
|
|
|
languagePosition++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int privacyPosition = 0;
|
|
|
|
if (privacy != null && privacies.containsValue(privacy)) {
|
|
|
|
Iterator<Map.Entry<Integer, String>> it = privacies.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (pair.getValue().equals(privacy))
|
|
|
|
break;
|
|
|
|
it.remove();
|
|
|
|
privacyPosition++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int licensePosition = 0;
|
|
|
|
if (license != null && licences.containsValue(license)) {
|
|
|
|
Iterator<Map.Entry<Integer, String>> it = licences.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (pair.getValue().equals(license))
|
|
|
|
break;
|
|
|
|
it.remove();
|
|
|
|
licensePosition++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int categoryPosition = 0;
|
|
|
|
if (category != null && categories.containsValue(category)) {
|
|
|
|
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (pair.getValue().equals(category))
|
|
|
|
break;
|
|
|
|
it.remove();
|
|
|
|
categoryPosition++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Manage privacies
|
|
|
|
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
|
|
|
Iterator<Map.Entry<Integer, String>> it = privaciesCheck.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (i == position) {
|
|
|
|
privacyToSend = new HashMap<>();
|
|
|
|
privacyToSend.put(pair.getKey(), pair.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
set_upload_licenses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
LinkedHashMap<Integer, String> licensesCheck = new LinkedHashMap<>(peertubeInformation.getLicences());
|
|
|
|
Iterator<Map.Entry<Integer, String>> it = licensesCheck.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (i == position) {
|
|
|
|
licenseToSend = new HashMap<>();
|
|
|
|
licenseToSend.put(pair.getKey(), pair.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//Manage categories
|
|
|
|
set_upload_categories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
LinkedHashMap<Integer, String> categoriesCheck = new LinkedHashMap<>(peertubeInformation.getCategories());
|
|
|
|
Iterator<Map.Entry<Integer, String>> it = categoriesCheck.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<Integer, String> pair = it.next();
|
|
|
|
if (i == position) {
|
|
|
|
categoryToSend = new HashMap<>();
|
|
|
|
categoryToSend.put(pair.getKey(), pair.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//Manage languages
|
|
|
|
set_upload_languages.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
LinkedHashMap<String, String> languagesCheck = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
|
|
|
Iterator<Map.Entry<String, String>> it = languagesCheck.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<String, String> pair = it.next();
|
|
|
|
if (i == position) {
|
|
|
|
languageToSend = new HashMap<>();
|
|
|
|
languageToSend.put(pair.getKey(), pair.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//Manage languages
|
|
|
|
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
|
|
|
|
Iterator<Map.Entry<String, String>> it = channelsCheck.entrySet().iterator();
|
|
|
|
int i = 0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<String, String> pair = it.next();
|
|
|
|
if (i == position) {
|
|
|
|
channelToSend = new HashMap<>();
|
|
|
|
channelToSend.put(pair.getKey(), pair.getValue());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
set_upload_privacy.setSelection(privacyPosition);
|
|
|
|
set_upload_languages.setSelection(languagePosition);
|
|
|
|
set_upload_licenses.setSelection(licensePosition);
|
|
|
|
set_upload_categories.setSelection(categoryPosition);
|
|
|
|
|
|
|
|
List<String> tags = peertube.getTags();
|
|
|
|
if (tags != null && tags.size() > 0) {
|
|
|
|
String[] tagsA = tags.toArray(new String[0]);
|
|
|
|
p_video_tags.setTags(tagsA);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) {
|
|
|
|
if (data == null || data.getData() == null) {
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
|
|
|
|
uploadConfig.getCompleted().autoClear = true;
|
|
|
|
try {
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
|
|
|
Uri uri = data.getData();
|
|
|
|
try {
|
|
|
|
String uploadId = UUID.randomUUID().toString();
|
|
|
|
new MultipartUploadRequest(PeertubeEditUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeEditUploadActivity.this) + "/api/v1/" + String.format("/videos/%s", peertube.getId()))
|
|
|
|
.addFileToUpload(uri.toString().replace("file://", ""), "previewfile")
|
|
|
|
.setMethod("PUT")
|
|
|
|
.addHeader("Authorization", "Bearer " + token)
|
|
|
|
.setNotificationConfig(uploadConfig)
|
|
|
|
.setMaxRetries(2)
|
|
|
|
.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) {
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
|
|
|
|
Glide.with(PeertubeEditUploadActivity.this)
|
|
|
|
.load(uri)
|
|
|
|
.into(p_video_preview);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancelled(Context context, UploadInfo uploadInfo) {
|
|
|
|
// your code here
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.startUpload();
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
if (item.getItemId() == android.R.id.home) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
@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().getError() != null)
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
|
|
|
else
|
|
|
|
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//Populate channels
|
|
|
|
List<Account> accounts = apiResponse.getAccounts();
|
|
|
|
String[] channelName = new String[accounts.size()];
|
|
|
|
int i = 0;
|
|
|
|
for (Account account : accounts) {
|
|
|
|
channels.put(account.getUsername(), account.getId());
|
|
|
|
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);
|
|
|
|
int channelPosition = 0;
|
|
|
|
if (channels.containsKey(channel.getUsername())) {
|
|
|
|
LinkedHashMap<String, String> channelsIterator = new LinkedHashMap<>(channels);
|
|
|
|
Iterator<Map.Entry<String, String>> it = channelsIterator.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<String, String> pair = it.next();
|
|
|
|
if (pair.getKey().equals(channel.getUsername())) {
|
|
|
|
channelToSend = new HashMap<>();
|
|
|
|
channelToSend.put(pair.getKey(), pair.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it.remove();
|
|
|
|
channelPosition++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_upload_channel.setSelection(channelPosition);
|
|
|
|
set_upload_submit.setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-26 14:34:39 +02:00
|
|
|
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
|
2020-06-26 08:50:49 +02:00
|
|
|
Intent intent = new Intent(PeertubeEditUploadActivity.this, MainActivity.class);
|
|
|
|
intent.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS);
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|