Back end for edition of videos
This commit is contained in:
parent
e9e4f51d56
commit
4ea77d489a
|
@ -27,13 +27,18 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
|
@ -44,18 +49,24 @@ import fr.gouv.etalab.mastodon.client.Entities.Account;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
|
||||
import mabbas007.tagsedittext.TagsEditText;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
|
||||
|
||||
public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface {
|
||||
|
||||
|
||||
private Button set_upload_submit;
|
||||
private Spinner set_upload_privacy, set_upload_channel;
|
||||
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 TextView set_upload_file_name;
|
||||
private HashMap<String, String> channels;
|
||||
private String videoId;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -107,10 +118,99 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
setContentView(R.layout.activity_peertube_edit);
|
||||
|
||||
|
||||
set_upload_file_name = findViewById(R.id.set_upload_file_name);
|
||||
set_upload_channel = findViewById(R.id.set_upload_channel);
|
||||
set_upload_privacy = findViewById(R.id.set_upload_privacy);
|
||||
set_upload_submit = findViewById(R.id.set_upload_submit);
|
||||
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);
|
||||
|
||||
|
||||
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;
|
||||
if( peertubeInformation.getTranslations() != null)
|
||||
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
|
||||
|
||||
//Populate catgories
|
||||
String[] categoriesA = new String[categories.size()];
|
||||
Iterator it = categories.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if( translations == null ||translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
|
||||
categoriesA[i] = (String)pair.getValue();
|
||||
else
|
||||
categoriesA[i] = translations.get((String)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 pair = (Map.Entry)it.next();
|
||||
if( translations == null || translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
|
||||
licensesA[i] = (String)pair.getValue();
|
||||
else
|
||||
licensesA[i] = translations.get((String)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()];
|
||||
it = languages.entrySet().iterator();
|
||||
i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if( translations == null || translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
|
||||
languagesA[i] = (String)pair.getValue();
|
||||
else
|
||||
languagesA[i] = translations.get((String)pair.getValue());
|
||||
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()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if( translations == null || translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
|
||||
privaciesA[i] = (String)pair.getValue();
|
||||
else
|
||||
privaciesA[i] = translations.get((String)pair.getValue());
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
|
||||
android.R.layout.simple_spinner_dropdown_item, privaciesA);
|
||||
set_upload_privacy.setAdapter(adapterPrivacies);
|
||||
|
||||
|
||||
String peertubeInstance = Helper.getLiveInstance(getApplicationContext());
|
||||
new RetrievePeertubeSingleAsyncTask(PeertubeEditUploadActivity.this, peertubeInstance, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
@ -135,6 +235,88 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
|
|||
Peertube peertube = apiResponse.getPeertubes().get(0);
|
||||
new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
//TODO: hydrate form
|
||||
|
||||
String language = peertube.getLanguage();
|
||||
String license = peertube.getLicense();
|
||||
String description = peertube.getDescription();
|
||||
String privacy = peertube.getPrivacy();
|
||||
String category = peertube.getCategory();
|
||||
Account 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(description);
|
||||
|
||||
|
||||
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;
|
||||
if( peertubeInformation.getTranslations() != null)
|
||||
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
|
||||
|
||||
|
||||
int languagePosition = 0;
|
||||
if( languages.containsValue(language)){
|
||||
Iterator it = languages.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if(pair.getValue().equals(language))
|
||||
break;
|
||||
it.remove();
|
||||
languagePosition++;
|
||||
}
|
||||
}
|
||||
int privacyPosition = 0;
|
||||
if( privacies.containsValue(privacy)){
|
||||
Iterator it = privacies.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if(pair.getValue().equals(privacy))
|
||||
break;
|
||||
it.remove();
|
||||
privacyPosition++;
|
||||
}
|
||||
}
|
||||
int licensePosition = 0;
|
||||
if( licences.containsValue(license)){
|
||||
Iterator it = licences.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if(pair.getValue().equals(license))
|
||||
break;
|
||||
it.remove();
|
||||
licensePosition++;
|
||||
}
|
||||
}
|
||||
int categoryPosition = 0;
|
||||
if( categories.containsValue(category)){
|
||||
Iterator it = categories.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
if(pair.getValue().equals(category))
|
||||
break;
|
||||
it.remove();
|
||||
categoryPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
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[tags.size()]);
|
||||
p_video_tags.setTags(tagsA);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1868,6 +1868,8 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
private void restoreToot(long id){
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
StoredStatus draft = new StatusStoredDAO(TootActivity.this, db).getStatus(id);
|
||||
if( draft == null)
|
||||
return;
|
||||
Status status = draft.getStatus();
|
||||
//Retrieves attachments
|
||||
if( removed ){
|
||||
|
|
|
@ -54,11 +54,16 @@ public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(this.contextReference.get());
|
||||
apiResponse = api.getSinglePeertube(this.instanceName, videoId);
|
||||
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0) {
|
||||
String rate = new PeertubeAPI(this.contextReference.get()).getRating(videoId);
|
||||
apiResponse.getPeertubes().get(0).setMyRating(rate);
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
API api = new API(this.contextReference.get());
|
||||
apiResponse = api.getSinglePeertube(this.instanceName, videoId);
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getSinglePeertube(this.instanceName, videoId);
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0) {
|
||||
String rate = new PeertubeAPI(this.contextReference.get()).getRating(videoId);
|
||||
apiResponse.getPeertubes().get(0).setMyRating(rate);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -40,12 +40,15 @@ public class Peertube {
|
|||
private int duration;
|
||||
private String instance;
|
||||
private Account account;
|
||||
private Account channel;
|
||||
private List<String> resolution;
|
||||
private List<String> tags;
|
||||
private boolean commentsEnabled;
|
||||
private boolean sensitive;
|
||||
private String category;
|
||||
private String license;
|
||||
private String language;
|
||||
private String privacy;
|
||||
private String myRating = "none";
|
||||
|
||||
private JSONObject cache;
|
||||
|
@ -272,4 +275,28 @@ public class Peertube {
|
|||
public void setMyRating(String myRating) {
|
||||
this.myRating = myRating;
|
||||
}
|
||||
|
||||
public Account getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void setChannel(Account channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public String getPrivacy() {
|
||||
return privacy;
|
||||
}
|
||||
|
||||
public void setPrivacy(String privacy) {
|
||||
this.privacy = privacy;
|
||||
}
|
||||
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package fr.gouv.etalab.mastodon.client.Entities;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/* Copyright 2019 Thomas Schneider
|
||||
*
|
||||
|
@ -23,15 +21,15 @@ import java.util.Map;
|
|||
public class PeertubeInformation {
|
||||
|
||||
|
||||
private HashMap<Integer, String> categories;
|
||||
private HashMap<String, String> languages;
|
||||
private HashMap<Integer, String> licences;
|
||||
private HashMap<Integer, String> privacies;
|
||||
private HashMap<String, String> translations;
|
||||
private LinkedHashMap<Integer, String> categories;
|
||||
private LinkedHashMap<String, String> languages;
|
||||
private LinkedHashMap<Integer, String> licences;
|
||||
private LinkedHashMap<Integer, String> privacies;
|
||||
private LinkedHashMap<String, String> translations;
|
||||
|
||||
public static final Map<String, String> langueMapped;
|
||||
public static final LinkedHashMap<String, String> langueMapped;
|
||||
static {
|
||||
HashMap<String, String> aMap = new HashMap<>();
|
||||
LinkedHashMap<String, String> aMap = new LinkedHashMap<>();
|
||||
aMap.put("ca", "ca-ES");
|
||||
aMap.put("de", "de-DE");
|
||||
aMap.put("en", "en-US");
|
||||
|
@ -45,47 +43,47 @@ public class PeertubeInformation {
|
|||
aMap.put("cs", "cs-CZ");
|
||||
aMap.put("zh-CN", "zh-Hans-CN");
|
||||
aMap.put("zh-TW", "zh-Hans-TW");
|
||||
langueMapped = Collections.unmodifiableMap(aMap);
|
||||
langueMapped = aMap;
|
||||
}
|
||||
|
||||
|
||||
public HashMap<String, String> getTranslations() {
|
||||
public LinkedHashMap<String, String> getTranslations() {
|
||||
return translations;
|
||||
}
|
||||
|
||||
public void setTranslations(HashMap<String, String> translations) {
|
||||
public void setTranslations(LinkedHashMap<String, String> translations) {
|
||||
this.translations = translations;
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getCategories() {
|
||||
public LinkedHashMap<Integer, String> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(HashMap<Integer, String> categories) {
|
||||
public void setCategories(LinkedHashMap<Integer, String> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getLanguages() {
|
||||
public LinkedHashMap<String, String> getLanguages() {
|
||||
return languages;
|
||||
}
|
||||
|
||||
public void setLanguages(HashMap<String, String> languages) {
|
||||
public void setLanguages(LinkedHashMap<String, String> languages) {
|
||||
this.languages = languages;
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getLicences() {
|
||||
public LinkedHashMap<Integer, String> getLicences() {
|
||||
return licences;
|
||||
}
|
||||
|
||||
public void setLicences(HashMap<Integer, String> licences) {
|
||||
public void setLicences(LinkedHashMap<Integer, String> licences) {
|
||||
this.licences = licences;
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getPrivacies() {
|
||||
public LinkedHashMap<Integer, String> getPrivacies() {
|
||||
return privacies;
|
||||
}
|
||||
|
||||
public void setPrivacies(HashMap<Integer, String> privacies) {
|
||||
public void setPrivacies(LinkedHashMap<Integer, String> privacies) {
|
||||
this.privacies = privacies;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import java.util.Map;
|
|||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Application;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Card;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
|
||||
|
@ -50,14 +49,11 @@ import fr.gouv.etalab.mastodon.client.Entities.Filters;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.HowToVideo;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Instance;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.InstanceSocial;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.PeertubeInformation;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Tag;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
@ -216,7 +212,7 @@ public class PeertubeAPI {
|
|||
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/categories"), 60, null, null);
|
||||
JSONObject categories = new JSONObject(response);
|
||||
HashMap<Integer, String> _pcategories = new HashMap<>();
|
||||
LinkedHashMap<Integer, String> _pcategories = new LinkedHashMap<>();
|
||||
for( int i = 1 ; i <= categories.length() ; i++){
|
||||
_pcategories.put(i, categories.getString(String.valueOf(i)));
|
||||
|
||||
|
@ -225,7 +221,7 @@ public class PeertubeAPI {
|
|||
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/languages"), 60, null, null);
|
||||
JSONObject languages = new JSONObject(response);
|
||||
HashMap<String, String> _languages = new HashMap<>();
|
||||
LinkedHashMap<String, String> _languages = new LinkedHashMap<>();
|
||||
Iterator<String> iter = languages.keys();
|
||||
while (iter.hasNext()) {
|
||||
String key = iter.next();
|
||||
|
@ -237,7 +233,7 @@ public class PeertubeAPI {
|
|||
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/privacies"), 60, null, null);
|
||||
JSONObject privacies = new JSONObject(response);
|
||||
HashMap<Integer, String> _pprivacies = new HashMap<>();
|
||||
LinkedHashMap<Integer, String> _pprivacies = new LinkedHashMap<>();
|
||||
for( int i = 1 ; i <= privacies.length() ; i++){
|
||||
_pprivacies.put(i, privacies.getString(String.valueOf(i)));
|
||||
|
||||
|
@ -247,7 +243,7 @@ public class PeertubeAPI {
|
|||
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/licences"), 60, null, null);
|
||||
JSONObject licences = new JSONObject(response);
|
||||
HashMap<Integer, String> _plicences = new HashMap<>();
|
||||
LinkedHashMap<Integer, String> _plicences = new LinkedHashMap<>();
|
||||
for( int i = 1 ; i <= licences.length() ; i++){
|
||||
_plicences.put(i, licences.getString(String.valueOf(i)));
|
||||
|
||||
|
@ -256,22 +252,24 @@ public class PeertubeAPI {
|
|||
|
||||
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
String lang;
|
||||
String lang = null;
|
||||
if(PeertubeInformation.langueMapped.containsKey( Locale.getDefault().getLanguage()))
|
||||
lang = PeertubeInformation.langueMapped.get(Locale.getDefault().getLanguage());
|
||||
else
|
||||
lang = "en-US";
|
||||
response = new HttpsConnection(context).get(String.format( "https://"+instance+"/client/locales/%s/server.json", lang), 60, null, null);
|
||||
JSONObject translations = new JSONObject(response);
|
||||
HashMap<String, String> _translations = new HashMap<>();
|
||||
Iterator<String> itertrans = translations.keys();
|
||||
while (itertrans.hasNext()) {
|
||||
String key = itertrans.next();
|
||||
try {
|
||||
_translations.put(key, (String) translations.get(key));
|
||||
} catch (JSONException ignored) {}
|
||||
|
||||
if( lang != null && !lang.startsWith("en")) {
|
||||
response = new HttpsConnection(context).get(String.format("https://" + instance + "/client/locales/%s/server.json", lang), 60, null, null);
|
||||
JSONObject translations = new JSONObject(response);
|
||||
LinkedHashMap<String, String> _translations = new LinkedHashMap<>();
|
||||
Iterator<String> itertrans = translations.keys();
|
||||
while (itertrans.hasNext()) {
|
||||
String key = itertrans.next();
|
||||
try {
|
||||
_translations.put(key, (String) translations.get(key));
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
}
|
||||
peertubeInformation.setTranslations(_translations);
|
||||
}
|
||||
peertubeInformation.setTranslations(_translations);
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -595,173 +593,6 @@ public class PeertubeAPI {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves one status *synchronously*
|
||||
*
|
||||
* @param statusId String Id of the status
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getStatusbyId(String statusId) {
|
||||
statuses = new ArrayList<>();
|
||||
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s", statusId)), 60, null, prefKeyOauthTokenT);
|
||||
Status status = parseStatuses(context, new JSONObject(response));
|
||||
statuses.add(status);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the context of status with replies *synchronously*
|
||||
*
|
||||
* @param statusId Id of the status
|
||||
* @return List<Status>
|
||||
*/
|
||||
public fr.gouv.etalab.mastodon.client.Entities.Context getStatusContext(String statusId) {
|
||||
fr.gouv.etalab.mastodon.client.Entities.Context statusContext = new fr.gouv.etalab.mastodon.client.Entities.Context();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/context", statusId)), 60, null, prefKeyOauthTokenT);
|
||||
statusContext = parseContext(new JSONObject(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return statusContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves direct timeline for the account *synchronously*
|
||||
* @param max_id String id max
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getDirectTimeline( String max_id) {
|
||||
return getDirectTimeline(max_id, null, tootPerPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves conversation timeline for the account *synchronously*
|
||||
* @param max_id String id max
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getConversationTimeline( String max_id) {
|
||||
return getConversationTimeline(max_id, null, tootPerPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves direct timeline for the account since an Id value *synchronously*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getConversationTimelineSinceId(String since_id) {
|
||||
return getConversationTimeline(null, since_id, tootPerPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves conversation timeline for the account *synchronously*
|
||||
* @param max_id String id max
|
||||
* @param since_id String since the id
|
||||
* @param limit int limit - max value 40
|
||||
* @return APIResponse
|
||||
*/
|
||||
private APIResponse getConversationTimeline(String max_id, String since_id, int limit) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (max_id != null)
|
||||
params.put("max_id", max_id);
|
||||
if (since_id != null)
|
||||
params.put("since_id", since_id);
|
||||
if (0 > limit || limit > 80)
|
||||
limit = 80;
|
||||
params.put("limit",String.valueOf(limit));
|
||||
conversations = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/conversations"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
conversations = parseConversations(new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setConversations(conversations);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves direct timeline for the account since an Id value *synchronously*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getDirectTimelineSinceId(String since_id) {
|
||||
return getDirectTimeline(null, since_id, tootPerPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves direct timeline for the account *synchronously*
|
||||
* @param max_id String id max
|
||||
* @param since_id String since the id
|
||||
* @param limit int limit - max value 40
|
||||
* @return APIResponse
|
||||
*/
|
||||
private APIResponse getDirectTimeline(String max_id, String since_id, int limit) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (max_id != null)
|
||||
params.put("max_id", max_id);
|
||||
if (since_id != null)
|
||||
params.put("since_id", since_id);
|
||||
if (0 > limit || limit > 80)
|
||||
limit = 80;
|
||||
params.put("limit",String.valueOf(limit));
|
||||
statuses = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/timelines/direct"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1273,78 +1104,6 @@ public class PeertubeAPI {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves notifications for the authenticated account *synchronously*
|
||||
* @param max_id String id max
|
||||
* @param since_id String since the id
|
||||
* @param limit int limit - max value 40
|
||||
* @return APIResponse
|
||||
*/
|
||||
private APIResponse getNotifications(String max_id, String since_id, int limit, boolean display){
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if( max_id != null )
|
||||
params.put("max_id", max_id);
|
||||
if( since_id != null )
|
||||
params.put("since_id", since_id);
|
||||
if( 0 > limit || limit > 30)
|
||||
limit = 30;
|
||||
params.put("limit",String.valueOf(limit));
|
||||
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notif_follow, notif_add, notif_mention, notif_share;
|
||||
if( display) {
|
||||
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, true);
|
||||
notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD_FILTER, true);
|
||||
notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION_FILTER, true);
|
||||
notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE_FILTER, true);
|
||||
}else{
|
||||
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
||||
notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
||||
notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||
notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
||||
}
|
||||
StringBuilder parameters = new StringBuilder();
|
||||
|
||||
if( !notif_follow )
|
||||
parameters.append("exclude_types[]=").append("follow").append("&");
|
||||
if( !notif_add )
|
||||
parameters.append("exclude_types[]=").append("favourite").append("&");
|
||||
if( !notif_share )
|
||||
parameters.append("exclude_types[]=").append("reblog").append("&");
|
||||
if( !notif_mention )
|
||||
parameters.append("exclude_types[]=").append("mention").append("&");
|
||||
if( parameters.length() > 0) {
|
||||
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
|
||||
params.put("exclude_types[]", parameters.toString());
|
||||
}
|
||||
|
||||
|
||||
List<Notification> notifications = new ArrayList<>();
|
||||
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/notifications"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
notifications = parseNotificationResponse(new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setNotifications(notifications);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Changes media description
|
||||
|
@ -1378,39 +1137,6 @@ public class PeertubeAPI {
|
|||
return attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Accounts and feeds when searching *synchronously*
|
||||
*
|
||||
* @param query String search
|
||||
* @return List<Account>
|
||||
*/
|
||||
public Results search(String query) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
try {
|
||||
params.put("q", URLEncoder.encode(query, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
params.put("q", query);
|
||||
}
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/search"), 60, params, prefKeyOauthTokenT);
|
||||
results = parseResultsResponse(new JSONObject(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves Accounts when searching (ie: via @...) *synchronously*
|
||||
|
@ -1702,46 +1428,6 @@ public class PeertubeAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves list timeline *synchronously*
|
||||
* @param list_id String id of the list
|
||||
* @param max_id String id max
|
||||
* @param since_id String since the id
|
||||
* @param limit int limit - max value 40
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getListTimeline(String list_id, String max_id, String since_id, int limit) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (max_id != null)
|
||||
params.put("max_id", max_id);
|
||||
if (since_id != null)
|
||||
params.put("since_id", since_id);
|
||||
if (0 > limit || limit > 80)
|
||||
limit = 80;
|
||||
params.put("limit",String.valueOf(limit));
|
||||
statuses = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/list/%s",list_id)), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1814,23 +1500,6 @@ public class PeertubeAPI {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response an unique account
|
||||
* @param resobj JSONObject
|
||||
* @return Account
|
||||
*/
|
||||
private Results parseResultsResponse(JSONObject resobj){
|
||||
|
||||
Results results = new Results();
|
||||
try {
|
||||
results.setAccounts(parseAccountResponse(resobj.getJSONArray("accounts")));
|
||||
results.setStatuses(parseStatuses(context, resobj.getJSONArray("statuses")));
|
||||
results.setHashtags(parseTags(resobj.getJSONArray("hashtags")));
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique Car
|
||||
|
@ -2035,6 +1704,9 @@ public class PeertubeAPI {
|
|||
peertube.setPreviewPath(resobj.get("previewPath").toString());
|
||||
peertube.setThumbnailPath(resobj.get("thumbnailPath").toString());
|
||||
peertube.setAccount(parseAccountResponsePeertube(context, resobj.getJSONObject("account")));
|
||||
try {
|
||||
peertube.setChannel(parseAccountResponsePeertube(context, resobj.getJSONObject("channel")));
|
||||
}catch (Exception ignored){}
|
||||
peertube.setView(Integer.parseInt(resobj.get("views").toString()));
|
||||
peertube.setLike(Integer.parseInt(resobj.get("likes").toString()));
|
||||
peertube.setDislike(Integer.parseInt(resobj.get("dislikes").toString()));
|
||||
|
@ -2043,6 +1715,11 @@ public class PeertubeAPI {
|
|||
peertube.setCategory(resobj.getJSONObject("category").get("label").toString());
|
||||
peertube.setLicense(resobj.getJSONObject("licence").get("label").toString());
|
||||
peertube.setLanguage(resobj.getJSONObject("language").get("label").toString());
|
||||
peertube.setPrivacy(resobj.getJSONObject("privacy").get("label").toString());
|
||||
try {
|
||||
peertube.setCommentsEnabled(Boolean.parseBoolean(resobj.get("commentsEnabled").toString()));
|
||||
}catch (Exception ignored){}
|
||||
|
||||
try {
|
||||
peertube.setCreated_at(Helper.mstStringToDate(context, resobj.get("createdAt").toString()));
|
||||
} catch (ParseException e) {
|
||||
|
@ -2079,6 +1756,30 @@ public class PeertubeAPI {
|
|||
peertube.setDislike(Integer.parseInt(resobj.get("dislikes").toString()));
|
||||
peertube.setDuration(Integer.parseInt(resobj.get("duration").toString()));
|
||||
peertube.setAccount(parseAccountResponsePeertube(context, resobj.getJSONObject("account")));
|
||||
List<String> tags = new ArrayList<>();
|
||||
try {
|
||||
JSONArray tagsA = resobj.getJSONArray("tags");
|
||||
for(int i = 0 ; i < tagsA.length() ; i++){
|
||||
String value = tagsA.getString(i);
|
||||
tags.add(value);
|
||||
}
|
||||
peertube.setTags(tags);
|
||||
}catch (Exception ignored){}
|
||||
try {
|
||||
peertube.setChannel(parseAccountResponsePeertube(context, resobj.getJSONObject("channel")));
|
||||
}catch (Exception ignored){}
|
||||
peertube.setSensitive(Boolean.parseBoolean(resobj.get("nsfw").toString()));
|
||||
peertube.setCategory(resobj.getJSONObject("category").get("label").toString());
|
||||
peertube.setLicense(resobj.getJSONObject("licence").get("label").toString());
|
||||
peertube.setLanguage(resobj.getJSONObject("language").get("label").toString());
|
||||
peertube.setPrivacy(resobj.getJSONObject("privacy").get("label").toString());
|
||||
|
||||
try {
|
||||
peertube.setCreated_at(Helper.mstStringToDate(context, resobj.get("createdAt").toString()));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
peertube.setCreated_at(Helper.mstStringToDate(context, resobj.get("createdAt").toString()));
|
||||
} catch (ParseException e) {
|
||||
|
@ -2157,356 +1858,9 @@ public class PeertubeAPI {
|
|||
return howToVideo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for several conversations
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Conversation>
|
||||
*/
|
||||
private List<Conversation> parseConversations(JSONArray jsonArray){
|
||||
|
||||
List<Conversation> conversations = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length() ){
|
||||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Conversation conversation = parseConversation(context, resobj);
|
||||
i++;
|
||||
conversations.add(conversation);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
}
|
||||
return conversations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for unique conversation
|
||||
* @param resobj JSONObject
|
||||
* @return Conversation
|
||||
*/
|
||||
@SuppressWarnings("InfiniteRecursion")
|
||||
private Conversation parseConversation(Context context, JSONObject resobj) {
|
||||
Conversation conversation = new Conversation();
|
||||
try {
|
||||
conversation.setId(resobj.get("id").toString());
|
||||
conversation.setUnread(Boolean.parseBoolean(resobj.get("unread").toString()));
|
||||
conversation.setAccounts(parseAccountResponse(resobj.getJSONArray("accounts")));
|
||||
conversation.setLast_status(parseStatuses(context, resobj.getJSONObject("last_status")));
|
||||
}catch (JSONException ignored) {}
|
||||
return conversation;
|
||||
}
|
||||
/**
|
||||
* Parse json response for several status
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Status>
|
||||
*/
|
||||
public static List<Status> parseStatuses(Context context, JSONArray jsonArray){
|
||||
|
||||
List<Status> statuses = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length() ){
|
||||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Status status = parseStatuses(context, resobj);
|
||||
i++;
|
||||
statuses.add(status);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for unique status
|
||||
* @param resobj JSONObject
|
||||
* @return Status
|
||||
*/
|
||||
@SuppressWarnings("InfiniteRecursion")
|
||||
public static Status parseStatuses(Context context, JSONObject resobj){
|
||||
Status status = new Status();
|
||||
try {
|
||||
status.setId(resobj.get("id").toString());
|
||||
status.setUri(resobj.get("uri").toString());
|
||||
status.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString()));
|
||||
status.setIn_reply_to_id(resobj.get("in_reply_to_id").toString());
|
||||
status.setIn_reply_to_account_id(resobj.get("in_reply_to_account_id").toString());
|
||||
status.setSensitive(Boolean.parseBoolean(resobj.get("sensitive").toString()));
|
||||
status.setSpoiler_text(resobj.get("spoiler_text").toString());
|
||||
try {
|
||||
status.setVisibility(resobj.get("visibility").toString());
|
||||
}catch (Exception e){status.setVisibility("public");}
|
||||
status.setLanguage(resobj.get("language").toString());
|
||||
status.setUrl(resobj.get("url").toString());
|
||||
//Retrieves attachments
|
||||
JSONArray arrayAttachement = resobj.getJSONArray("media_attachments");
|
||||
ArrayList<Attachment> attachments = new ArrayList<>();
|
||||
if( arrayAttachement != null){
|
||||
for(int j = 0 ; j < arrayAttachement.length() ; j++){
|
||||
JSONObject attObj = arrayAttachement.getJSONObject(j);
|
||||
Attachment attachment = new Attachment();
|
||||
attachment.setId(attObj.get("id").toString());
|
||||
attachment.setPreview_url(attObj.get("preview_url").toString());
|
||||
attachment.setRemote_url(attObj.get("remote_url").toString());
|
||||
attachment.setType(attObj.get("type").toString());
|
||||
attachment.setText_url(attObj.get("text_url").toString());
|
||||
attachment.setUrl(attObj.get("url").toString());
|
||||
try {
|
||||
attachment.setDescription(attObj.get("description").toString());
|
||||
}catch (JSONException ignore){}
|
||||
attachments.add(attachment);
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
||||
status.setCard(parseCardResponse(resobj.getJSONObject("card")));
|
||||
}catch (Exception e){status.setCard(null);}
|
||||
|
||||
|
||||
status.setMedia_attachments(attachments);
|
||||
//Retrieves mentions
|
||||
List<Mention> mentions = new ArrayList<>();
|
||||
JSONArray arrayMention = resobj.getJSONArray("mentions");
|
||||
if( arrayMention != null){
|
||||
for(int j = 0 ; j < arrayMention.length() ; j++){
|
||||
JSONObject menObj = arrayMention.getJSONObject(j);
|
||||
Mention mention = new Mention();
|
||||
mention.setId(menObj.get("id").toString());
|
||||
mention.setUrl(menObj.get("url").toString());
|
||||
mention.setAcct(menObj.get("acct").toString());
|
||||
mention.setUsername(menObj.get("username").toString());
|
||||
mentions.add(mention);
|
||||
}
|
||||
}
|
||||
status.setMentions(mentions);
|
||||
//Retrieves tags
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
JSONArray arrayTag = resobj.getJSONArray("tags");
|
||||
if( arrayTag != null){
|
||||
for(int j = 0 ; j < arrayTag.length() ; j++){
|
||||
JSONObject tagObj = arrayTag.getJSONObject(j);
|
||||
Tag tag = new Tag();
|
||||
tag.setName(tagObj.get("name").toString());
|
||||
tag.setUrl(tagObj.get("url").toString());
|
||||
tags.add(tag);
|
||||
}
|
||||
}
|
||||
status.setTags(tags);
|
||||
|
||||
//Retrieves emjis
|
||||
List<Emojis> emojiList = new ArrayList<>();
|
||||
try {
|
||||
JSONArray emojisTag = resobj.getJSONArray("emojis");
|
||||
if( emojisTag != null){
|
||||
for(int j = 0 ; j < emojisTag.length() ; j++){
|
||||
JSONObject emojisObj = emojisTag.getJSONObject(j);
|
||||
Emojis emojis = parseEmojis(emojisObj);
|
||||
emojiList.add(emojis);
|
||||
}
|
||||
}
|
||||
status.setEmojis(emojiList);
|
||||
}catch (Exception e){
|
||||
status.setEmojis(new ArrayList<>());
|
||||
}
|
||||
|
||||
//Retrieve Application
|
||||
Application application = new Application();
|
||||
try {
|
||||
if(resobj.getJSONObject("application") != null){
|
||||
application.setName(resobj.getJSONObject("application").getString("name"));
|
||||
application.setWebsite(resobj.getJSONObject("application").getString("website"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
application = new Application();
|
||||
}
|
||||
status.setApplication(application);
|
||||
|
||||
status.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
|
||||
status.setContent(resobj.get("content").toString());
|
||||
status.setFavourites_count(Integer.valueOf(resobj.get("favourites_count").toString()));
|
||||
status.setReblogs_count(Integer.valueOf(resobj.get("reblogs_count").toString()));
|
||||
try{
|
||||
status.setReplies_count(Integer.valueOf(resobj.get("replies_count").toString()));
|
||||
}catch (Exception e){
|
||||
status.setReplies_count(-1);
|
||||
}
|
||||
try {
|
||||
status.setReblogged(Boolean.valueOf(resobj.get("reblogged").toString()));
|
||||
}catch (Exception e){
|
||||
status.setReblogged(false);
|
||||
}
|
||||
try {
|
||||
status.setFavourited(Boolean.valueOf(resobj.get("favourited").toString()));
|
||||
}catch (Exception e){
|
||||
status.setFavourited(false);
|
||||
}
|
||||
try {
|
||||
status.setMuted(Boolean.valueOf(resobj.get("muted").toString()));
|
||||
}catch (Exception e){
|
||||
status.setMuted(false);
|
||||
}
|
||||
try {
|
||||
status.setPinned(Boolean.valueOf(resobj.get("pinned").toString()));
|
||||
}catch (JSONException e){
|
||||
status.setPinned(false);
|
||||
}
|
||||
try{
|
||||
status.setReblog(parseStatuses(context, resobj.getJSONObject("reblog")));
|
||||
}catch (Exception ignored){}
|
||||
} catch (JSONException ignored) {} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response for several notes (Misskey)
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Status>
|
||||
*/
|
||||
public static List<Status> parseNotes(Context context, String instance, JSONArray jsonArray){
|
||||
|
||||
List<Status> statuses = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length() ){
|
||||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Status status = parseNotes(context, instance, resobj);
|
||||
i++;
|
||||
statuses.add(status);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for unique note (misskey)
|
||||
* @param resobj JSONObject
|
||||
* @return Status
|
||||
*/
|
||||
@SuppressWarnings("InfiniteRecursion")
|
||||
public static Status parseNotes(Context context, String instance, JSONObject resobj){
|
||||
Status status = new Status();
|
||||
try {
|
||||
status.setId(resobj.get("id").toString());
|
||||
status.setUri("https://" + instance + "/notes/" + resobj.get("id").toString());
|
||||
status.setCreated_at(Helper.mstStringToDate(context, resobj.get("createdAt").toString()));
|
||||
status.setIn_reply_to_id(resobj.get("replyId").toString());
|
||||
status.setSensitive(false);
|
||||
if(resobj.get("cw") != null && !resobj.get("cw").toString().equals("null"))
|
||||
status.setSpoiler_text(resobj.get("cw").toString());
|
||||
try {
|
||||
status.setVisibility(resobj.get("visibility").toString());
|
||||
}catch (Exception e){status.setVisibility("public"); e.printStackTrace();}
|
||||
status.setUrl("https://" + instance + "/notes/" + resobj.get("id").toString());
|
||||
//Retrieves attachments
|
||||
JSONArray arrayAttachement = resobj.getJSONArray("media");
|
||||
ArrayList<Attachment> attachments = new ArrayList<>();
|
||||
if( arrayAttachement != null){
|
||||
for(int j = 0 ; j < arrayAttachement.length() ; j++){
|
||||
JSONObject attObj = arrayAttachement.getJSONObject(j);
|
||||
Attachment attachment = new Attachment();
|
||||
attachment.setId(attObj.get("id").toString());
|
||||
attachment.setPreview_url(attObj.get("thumbnailUrl").toString());
|
||||
attachment.setRemote_url(attObj.get("url").toString());
|
||||
if( attObj.get("type").toString().contains("/")){
|
||||
attachment.setType(attObj.get("type").toString().split("/")[0]);
|
||||
}else
|
||||
attachment.setType(attObj.get("type").toString());
|
||||
attachment.setText_url(attObj.get("url").toString());
|
||||
attachment.setUrl(attObj.get("url").toString());
|
||||
if(attObj.get("isSensitive").toString().equals("true")){
|
||||
status.setSensitive(true);
|
||||
}
|
||||
try {
|
||||
attachment.setDescription(attObj.get("comment").toString());
|
||||
}catch (JSONException ignore){ignore.printStackTrace();}
|
||||
attachments.add(attachment);
|
||||
}
|
||||
}
|
||||
try {
|
||||
status.setCard(parseCardResponse(resobj.getJSONObject("card")));
|
||||
}catch (Exception e){status.setCard(null);}
|
||||
|
||||
status.setMedia_attachments(attachments);
|
||||
//Retrieves mentions
|
||||
List<Mention> mentions = new ArrayList<>();
|
||||
|
||||
status.setAccount(parseMisskeyAccountResponse(context, instance, resobj.getJSONObject("user")));
|
||||
status.setContent(resobj.get("text").toString());
|
||||
try{
|
||||
status.setReplies_count(Integer.valueOf(resobj.get("repliesCount").toString()));
|
||||
}catch (Exception e){
|
||||
status.setReplies_count(-1);
|
||||
}
|
||||
try {
|
||||
status.setFavourited(Boolean.valueOf(resobj.get("isFavorited").toString()));
|
||||
}catch (Exception e){
|
||||
status.setFavourited(false);
|
||||
}
|
||||
try{
|
||||
if(resobj.getJSONObject("renoteId") != null && !resobj.getJSONObject("renoteId").toString().equals("null"))
|
||||
status.setReblog(parseStatuses(context, resobj.getJSONObject("renote")));
|
||||
}catch (Exception ignored){}
|
||||
|
||||
status.setMentions(mentions);
|
||||
//Retrieves tags
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
JSONArray arrayTag = resobj.getJSONArray("tags");
|
||||
if( arrayTag != null){
|
||||
for(int j = 0 ; j < arrayTag.length() ; j++){
|
||||
JSONObject tagObj = arrayTag.getJSONObject(j);
|
||||
Tag tag = new Tag();
|
||||
tag.setName(tagObj.get("name").toString());
|
||||
tag.setUrl(tagObj.get("url").toString());
|
||||
tags.add(tag);
|
||||
}
|
||||
}
|
||||
status.setTags(tags);
|
||||
|
||||
//Retrieves emjis
|
||||
List<Emojis> emojiList = new ArrayList<>();
|
||||
try {
|
||||
JSONArray emojisTag = resobj.getJSONArray("emojis");
|
||||
if( emojisTag != null){
|
||||
for(int j = 0 ; j < emojisTag.length() ; j++){
|
||||
JSONObject emojisObj = emojisTag.getJSONObject(j);
|
||||
Emojis emojis = parseMisskeyEmojis(emojisObj);
|
||||
emojiList.add(emojis);
|
||||
}
|
||||
}
|
||||
status.setEmojis(emojiList);
|
||||
}catch (Exception e){
|
||||
status.setEmojis(new ArrayList<>());
|
||||
}
|
||||
|
||||
//Retrieve Application
|
||||
Application application = new Application();
|
||||
try {
|
||||
if(resobj.getJSONObject("application") != null){
|
||||
application.setName(resobj.getJSONObject("application").getString("name"));
|
||||
application.setWebsite(resobj.getJSONObject("application").getString("website"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
application = new Application();
|
||||
}
|
||||
status.setApplication(application);
|
||||
|
||||
|
||||
} catch (JSONException ignored) {} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
/**
|
||||
* Parse json response an unique instance
|
||||
* @param resobj JSONObject
|
||||
|
@ -2967,22 +2321,7 @@ public class PeertubeAPI {
|
|||
return relationships;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for the context
|
||||
* @param jsonObject JSONObject
|
||||
* @return fr.gouv.etalab.mastodon.client.Entities.Context
|
||||
*/
|
||||
private fr.gouv.etalab.mastodon.client.Entities.Context parseContext(JSONObject jsonObject){
|
||||
|
||||
fr.gouv.etalab.mastodon.client.Entities.Context context = new fr.gouv.etalab.mastodon.client.Entities.Context();
|
||||
try {
|
||||
context.setAncestors(parseStatuses(this.context, jsonObject.getJSONArray("ancestors")));
|
||||
context.setDescendants(parseStatuses(this.context, jsonObject.getJSONArray("descendants")));
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique attachment
|
||||
|
@ -3018,51 +2357,6 @@ public class PeertubeAPI {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response an unique notification
|
||||
* @param resobj JSONObject
|
||||
* @return Account
|
||||
*/
|
||||
public static Notification parseNotificationResponse(Context context, JSONObject resobj){
|
||||
|
||||
Notification notification = new Notification();
|
||||
try {
|
||||
notification.setId(resobj.get("id").toString());
|
||||
notification.setType(resobj.get("type").toString());
|
||||
notification.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString()));
|
||||
notification.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
|
||||
try{
|
||||
notification.setStatus(parseStatuses(context, resobj.getJSONObject("status")));
|
||||
}catch (Exception ignored){}
|
||||
notification.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString()));
|
||||
} catch (JSONException ignored) {} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for list of notifications
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Notification>
|
||||
*/
|
||||
private List<Notification> parseNotificationResponse(JSONArray jsonArray){
|
||||
|
||||
List<Notification> notifications = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length() ) {
|
||||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Notification notification = parseNotificationResponse(context, resobj);
|
||||
notifications.add(notification);
|
||||
i++;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -81,16 +81,18 @@
|
|||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:labelFor="@+id/p_video_description"
|
||||
android:text="@string/title"
|
||||
android:text="@string/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:inputType="textMultiLine"
|
||||
android:id="@+id/p_video_description"
|
||||
android:layout_width="match_parent"
|
||||
android:lines="5"
|
||||
android:maxLines="5"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text" />
|
||||
android:scrollbars="vertical"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Videos channels -->
|
||||
|
|
|
@ -808,6 +808,7 @@
|
|||
<string name="peertube_nsfw">This video contains mature or explicit content</string>
|
||||
<string name="peertube_enable_comments">Enable video comments</string>
|
||||
<string name="update_video">Update video</string>
|
||||
<string name="description">Description</string>
|
||||
<!-- end languages -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue