Front end + back end video updates
This commit is contained in:
parent
cdfad1b0d9
commit
de98ca8d79
|
@ -43,6 +43,7 @@ import java.util.Map;
|
|||
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostPeertubeAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
@ -52,6 +53,7 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
|||
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
|
||||
import mabbas007.tagsedittext.TagsEditText;
|
||||
|
||||
import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
|
||||
import static fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeMaterialSpinnerColor;
|
||||
|
@ -67,6 +69,11 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
private LinkedHashMap<String, String> channels;
|
||||
private String videoId;
|
||||
private Account channel;
|
||||
HashMap<Integer, String> categoryToSend;
|
||||
HashMap<Integer, String> licenseToSend;
|
||||
HashMap<Integer, String> privacyToSend;
|
||||
HashMap<String, String> languageToSend;
|
||||
HashMap<String, String> channelToSend;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -131,6 +138,9 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
set_upload_nsfw = findViewById(R.id.set_upload_nsfw);
|
||||
set_upload_enable_comments = findViewById(R.id.set_upload_enable_comments);
|
||||
|
||||
|
||||
|
||||
//Change spinner colors
|
||||
changeMaterialSpinnerColor(PeertubeEditUploadActivity.this, set_upload_channel);
|
||||
changeMaterialSpinnerColor(PeertubeEditUploadActivity.this, set_upload_categories);
|
||||
changeMaterialSpinnerColor(PeertubeEditUploadActivity.this, set_upload_licenses);
|
||||
|
@ -138,6 +148,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
changeMaterialSpinnerColor(PeertubeEditUploadActivity.this, set_upload_privacy);
|
||||
|
||||
|
||||
//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());
|
||||
|
@ -242,18 +253,24 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
Peertube peertube = apiResponse.getPeertubes().get(0);
|
||||
new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
HashMap<String, String> languageM = peertube.getLanguage();
|
||||
HashMap<Integer, String> licenseM = peertube.getLicense();
|
||||
HashMap<Integer, String> privacyM = peertube.getPrivacy();
|
||||
HashMap<Integer, String> categoryM = peertube.getCategory();
|
||||
if( peertube.isUpdate()){
|
||||
Toasty.success(PeertubeEditUploadActivity.this, getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show();
|
||||
peertube.setUpdate(false);
|
||||
}
|
||||
|
||||
Map.Entry<String,String> entryString = languageM.entrySet().iterator().next();
|
||||
languageToSend = peertube.getLanguage();
|
||||
licenseToSend = peertube.getLicense();
|
||||
privacyToSend = peertube.getPrivacy();
|
||||
categoryToSend = peertube.getCategory();
|
||||
|
||||
|
||||
Map.Entry<String,String> entryString = languageToSend.entrySet().iterator().next();
|
||||
String language = entryString.getValue();
|
||||
Map.Entry<Integer,String> entryInt = licenseM.entrySet().iterator().next();
|
||||
Map.Entry<Integer,String> entryInt = licenseToSend.entrySet().iterator().next();
|
||||
String license = entryInt.getValue();
|
||||
entryInt = privacyM.entrySet().iterator().next();
|
||||
entryInt = privacyToSend.entrySet().iterator().next();
|
||||
String privacy = entryInt.getValue();
|
||||
entryInt = categoryM.entrySet().iterator().next();
|
||||
entryInt = categoryToSend.entrySet().iterator().next();
|
||||
String category = entryInt.getValue();
|
||||
|
||||
channel = peertube.getChannel();
|
||||
|
@ -322,6 +339,129 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
}
|
||||
}
|
||||
|
||||
//Manage privacies
|
||||
set_upload_privacy.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
|
||||
@Override
|
||||
public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
});
|
||||
//Manage license
|
||||
set_upload_licenses.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
|
||||
@Override
|
||||
public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
|
||||
LinkedHashMap<Integer, String> licensesCheck = new LinkedHashMap<>(peertubeInformation.getLicences());
|
||||
Iterator it = licensesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if( i == position){
|
||||
licenseToSend = new HashMap<>();
|
||||
licenseToSend.put((Integer)pair.getKey(), (String)pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
//Manage categories
|
||||
set_upload_categories.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
|
||||
@Override
|
||||
public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
|
||||
LinkedHashMap<Integer, String> categoriesCheck = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||
Iterator it = categoriesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if( i == position){
|
||||
categoryToSend = new HashMap<>();
|
||||
categoryToSend.put((Integer)pair.getKey(), (String)pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
//Manage languages
|
||||
set_upload_languages.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
|
||||
@Override
|
||||
public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
|
||||
LinkedHashMap<String, String> languagesCheck = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||
Iterator it = languagesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if( i == position){
|
||||
languageToSend = new HashMap<>();
|
||||
languageToSend.put((String)pair.getKey(), (String)pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Manage languages
|
||||
set_upload_channel.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
|
||||
@Override
|
||||
public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
|
||||
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
|
||||
Iterator it = channelsCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if( i == position){
|
||||
channelToSend = new HashMap<>();
|
||||
channelToSend.put((String)pair.getKey(), (String)pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
set_upload_submit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String title = p_video_title.getText().toString().trim();
|
||||
String description = p_video_description.getText().toString().trim();
|
||||
boolean isNSFW = set_upload_nsfw.isChecked();
|
||||
boolean commentEnabled = set_upload_enable_comments.isChecked();
|
||||
Peertube peertubeSent = new Peertube();
|
||||
peertube.setName(title);
|
||||
peertube.setDescription(description);
|
||||
peertube.setSensitive(isNSFW);
|
||||
peertube.setCommentsEnabled(commentEnabled);
|
||||
peertube.setCategory(categoryToSend);
|
||||
peertube.setLicense(licenseToSend);
|
||||
peertube.setLanguage(languageToSend);
|
||||
peertube.setChannelForUpdate(channelToSend);
|
||||
List<String> tags = p_video_tags.getTags();
|
||||
if( tags != null && tags.size() > 0)
|
||||
peertube.setTags(tags);
|
||||
set_upload_submit.setEnabled(false);
|
||||
new PostPeertubeAsyncTask(PeertubeEditUploadActivity.this, peertube, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
|
||||
set_upload_privacy.setSelectedIndex(privacyPosition);
|
||||
set_upload_languages.setSelectedIndex(languagePosition);
|
||||
set_upload_licenses.setSelectedIndex(licensePosition);
|
||||
|
@ -365,7 +505,8 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
|
||||
int channelPosition = 0;
|
||||
if( channels.containsKey(channel.getUsername())){
|
||||
Iterator it = channels.entrySet().iterator();
|
||||
LinkedHashMap<String, String> channelsIterator = new LinkedHashMap<>(channels);
|
||||
Iterator it = channelsIterator.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if(pair.getKey().equals(channel.getUsername()))
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/* Copyright 2019 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastalab 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 Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.asynctasks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
||||
import fr.gouv.etalab.mastodon.client.PeertubeAPI;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 09/01/2019.
|
||||
* Update a Peertube video
|
||||
*/
|
||||
|
||||
public class PostPeertubeAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private Peertube peertube;
|
||||
|
||||
|
||||
|
||||
public PostPeertubeAsyncTask(Context context, Peertube peertube, OnRetrievePeertubeInterface onRetrievePeertubeInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.peertube = peertube;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.updateVideo(peertube);
|
||||
if( apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
|
||||
apiResponse.getPeertubes().get(0).setUpdate(true);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertube(apiResponse);
|
||||
}
|
||||
}
|
|
@ -50,7 +50,9 @@ public class Peertube {
|
|||
private HashMap<Integer, String> license;
|
||||
private HashMap<String, String> language;
|
||||
private HashMap<Integer, String> privacy;
|
||||
private HashMap<String, String> channelForUpdate;
|
||||
private String myRating = "none";
|
||||
private boolean isUpdate = false; // I allow to set it to true when dealing with API updates
|
||||
|
||||
private JSONObject cache;
|
||||
|
||||
|
@ -304,4 +306,20 @@ public class Peertube {
|
|||
public void setPrivacy(HashMap<Integer, String> privacy) {
|
||||
this.privacy = privacy;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getChannelForUpdate() {
|
||||
return channelForUpdate;
|
||||
}
|
||||
|
||||
public void setChannelForUpdate(HashMap<String, String> channelForUpdate) {
|
||||
this.channelForUpdate = channelForUpdate;
|
||||
}
|
||||
|
||||
public boolean isUpdate() {
|
||||
return isUpdate;
|
||||
}
|
||||
|
||||
public void setUpdate(boolean update) {
|
||||
isUpdate = update;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,10 +160,45 @@ public class PeertubeAPI {
|
|||
* @return APIResponse
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private APIResponse updateVideo(Peertube peertube) {
|
||||
public APIResponse updateVideo(Peertube peertube) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("id",peertube.getId());
|
||||
|
||||
//Category
|
||||
Map.Entry<Integer,String> categoryM = peertube.getCategory().entrySet().iterator().next();
|
||||
Integer idCategory = categoryM.getKey();
|
||||
params.put("category", String.valueOf(idCategory));
|
||||
//License
|
||||
Map.Entry<Integer,String> licenseM = peertube.getLicense().entrySet().iterator().next();
|
||||
Integer idLicense= licenseM.getKey();
|
||||
params.put("licence", String.valueOf(idLicense));
|
||||
//language
|
||||
Map.Entry<String,String> languagesM = peertube.getLanguage().entrySet().iterator().next();
|
||||
String iDlanguage = languagesM.getKey();
|
||||
params.put("language", iDlanguage);
|
||||
//Privacy
|
||||
Map.Entry<Integer,String> privacyM = peertube.getPrivacy().entrySet().iterator().next();
|
||||
Integer idPrivacy = privacyM.getKey();
|
||||
params.put("privacy", String.valueOf(idPrivacy));
|
||||
//Channel
|
||||
Map.Entry<String,String> channelsM = peertube.getChannelForUpdate().entrySet().iterator().next();
|
||||
String iDChannel = channelsM.getKey();
|
||||
params.put("channelId", iDChannel);
|
||||
|
||||
|
||||
params.put("name", peertube.getName());
|
||||
params.put("description", peertube.getDescription());
|
||||
|
||||
params.put("nsfw", String.valueOf(peertube.isSensitive()));
|
||||
params.put("commentsEnabled", String.valueOf(peertube.isCommentsEnabled()));
|
||||
if( peertube.getTags() != null && peertube.getTags().size() > 0){
|
||||
int i = 0;
|
||||
for(String tag: peertube.getTags()){
|
||||
params.put("tags["+i+"]", tag);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
params.put("support", "null");
|
||||
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
|
|
|
@ -809,6 +809,7 @@
|
|||
<string name="peertube_enable_comments">Enable video comments</string>
|
||||
<string name="update_video">Update video</string>
|
||||
<string name="description">Description</string>
|
||||
<string name="toast_peertube_video_updated">The video has been updated!</string>
|
||||
<!-- end languages -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue