diff options
author | stom79 <tschneider.ac@gmail.com> | 2019-01-07 19:16:15 +0100 |
---|---|---|
committer | stom79 <tschneider.ac@gmail.com> | 2019-01-07 19:16:15 +0100 |
commit | 5143c54359472799b07b8b79978283d4472e7f83 (patch) | |
tree | c6f120ef3489cb8f7d58dcb6fbedefac53c3d88d /app/src/main/java/fr/gouv/etalab | |
parent | 0c1d123196e668b7d67f52c39283c721cc4ae3e0 (diff) |
Back end display videos - 1
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab')
11 files changed, 495 insertions, 44 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 285b933aa..6ffbf67f4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -102,6 +102,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveMetaDataAsyncTask; +import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeInformationAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteDataAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask; @@ -270,6 +271,12 @@ public abstract class BaseMainActivity extends BaseActivity activity = this; rateThisApp(); + //Intialize Peertube information + if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){ + try{ + new RetrievePeertubeInformationAsyncTask(getApplicationContext()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }catch (Exception ignored){} + } Helper.canPin = false; Helper.fillMapEmoji(getApplicationContext()); @@ -2036,6 +2043,7 @@ public abstract class BaseMainActivity extends BaseActivity SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(token); bundle.putString("targetedid",account.getUsername()); + bundle.putBoolean("ownvideos", true); fragment.setArguments(bundle); fragmentTag = "MY_VIDEOS"; fragmentManager.beginTransaction() diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java index 6d52592df..38a8553a8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java @@ -663,6 +663,11 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube } @Override + public void onRetrievePeertubeChannels(APIResponse apiResponse) { + + } + + @Override public void onDestroy() { super.onDestroy(); if( torrentStream != null && torrentStream.isStreaming()) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeEditUploadActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeEditUploadActivity.java new file mode 100644 index 000000000..5e4a0373b --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeEditUploadActivity.java @@ -0,0 +1,170 @@ +package fr.gouv.etalab.mastodon.activities; +/* 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>. */ + + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import java.util.HashMap; +import java.util.List; + +import es.dmoral.toasty.Toasty; +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeChannelsAsyncTask; +import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleAsyncTask; +import fr.gouv.etalab.mastodon.client.APIResponse; +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 static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT; + +public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface { + + + private Button set_upload_file, set_upload_submit; + private Spinner set_upload_privacy, set_upload_channel; + private TextView set_upload_file_name; + private HashMap<String, String> channels; + private String videoId; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + switch (theme){ + case Helper.THEME_LIGHT: + setTheme(R.style.AppTheme); + break; + case Helper.THEME_DARK: + setTheme(R.style.AppThemeDark); + break; + case Helper.THEME_BLACK: + setTheme(R.style.AppThemeBlack); + break; + default: + setTheme(R.style.AppThemeDark); + } + Bundle b = getIntent().getExtras(); + + if(b != null) { + videoId = b.getString("video_id", null); + } + + if( getSupportActionBar() != null) + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ActionBar actionBar = getSupportActionBar(); + if( actionBar != null ) { + LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + assert inflater != null; + @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, null); + actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); + ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); + TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); + toolbar_close.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + toolbar_title.setText(R.string.action_about); + if (theme == THEME_LIGHT){ + Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar); + Helper.colorizeToolbar(toolbar, R.color.black, PeertubeEditUploadActivity.this); + } + } + setContentView(R.layout.activity_peertube_upload); + + set_upload_file = findViewById(R.id.set_upload_file); + 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); + + String peertubeInstance = Helper.getLiveInstance(getApplicationContext()); + new RetrievePeertubeSingleAsyncTask(PeertubeEditUploadActivity.this, peertubeInstance, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + channels = new HashMap<>(); + } + + + + + @Override + public void onRetrievePeertube(APIResponse apiResponse) { + if( apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().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; + } + + //Peertube video + Peertube peertube = apiResponse.getPeertubes().get(0); + new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + //TODO: hydrate form + } + + @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); + + //TODO: spinner must point in the right value + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java index 6fe51c872..3ffb14787 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java @@ -160,6 +160,16 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe @Override public void onRetrievePeertube(APIResponse apiResponse) { + + } + + @Override + public void onRetrievePeertubeComments(APIResponse apiResponse) { + + } + + @Override + public void onRetrievePeertubeChannels(APIResponse apiResponse) { if( apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0){ if ( apiResponse.getError().getError() != null) Toasty.error(PeertubeUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); @@ -222,9 +232,4 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe } }); } - - @Override - public void onRetrievePeertubeComments(APIResponse apiResponse) { - - } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java index ddfe14d3f..4d050c386 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java @@ -64,6 +64,6 @@ public class RetrievePeertubeChannelsAsyncTask extends AsyncTask<Void, Void, Voi @Override protected void onPostExecute(Void result) { - listener.onRetrievePeertube(apiResponse); + listener.onRetrievePeertubeChannels(apiResponse); } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeInformationAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeInformationAsyncTask.java new file mode 100644 index 000000000..05faaa559 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeInformationAsyncTask.java @@ -0,0 +1,59 @@ +/* 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.Entities.PeertubeInformation; +import fr.gouv.etalab.mastodon.client.HttpsConnection; +import fr.gouv.etalab.mastodon.client.PeertubeAPI; + + +/** + * Created by Thomas on 07/01/2019. + * Retrieves peertube informations + */ + +public class RetrievePeertubeInformationAsyncTask extends AsyncTask<Void, Void, Void> { + + + + private WeakReference<Context> contextReference; + public static PeertubeInformation peertubeInformation; + + + + public RetrievePeertubeInformationAsyncTask(Context context){ + this.contextReference = new WeakReference<>(context); + } + + @Override + protected Void doInBackground(Void... params) { + PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get()); + try { + peertubeInformation = peertubeAPI.getPeertubeInformation(); + } catch (HttpsConnection.HttpsConnectionException e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/PeertubeInformation.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/PeertubeInformation.java new file mode 100644 index 000000000..c0e33c6df --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/PeertubeInformation.java @@ -0,0 +1,91 @@ +package fr.gouv.etalab.mastodon.client.Entities; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/* 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>. */ + + +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; + + public static final Map<String, String> langueMapped; + static { + HashMap<String, String> aMap = new HashMap<>(); + aMap.put("ca", "ca-ES"); + aMap.put("de", "de-DE"); + aMap.put("en", "en-US"); + aMap.put("es", "es-ES"); + aMap.put("eo", "eo"); + aMap.put("eu", "eu-ES"); + aMap.put("fr", "fr-FR"); + aMap.put("oc", "oc"); + aMap.put("pt", "pt-BR"); + aMap.put("sv", "sv-SE"); + aMap.put("cs", "cs-CZ"); + aMap.put("zh-CN", "zh-Hans-CN"); + aMap.put("zh-TW", "zh-Hans-TW"); + langueMapped = Collections.unmodifiableMap(aMap); + } + + + public HashMap<String, String> getTranslations() { + return translations; + } + + public void setTranslations(HashMap<String, String> translations) { + this.translations = translations; + } + + public HashMap<Integer, String> getCategories() { + return categories; + } + + public void setCategories(HashMap<Integer, String> categories) { + this.categories = categories; + } + + public HashMap<String, String> getLanguages() { + return languages; + } + + public void setLanguages(HashMap<String, String> languages) { + this.languages = languages; + } + + public HashMap<Integer, String> getLicences() { + return licences; + } + + public void setLicences(HashMap<Integer, String> licences) { + this.licences = licences; + } + + public HashMap<Integer, String> getPrivacies() { + return privacies; + } + + public void setPrivacies(HashMap<Integer, String> privacies) { + this.privacies = privacies; + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java index a35f9cef4..6624eb9b9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import fr.gouv.etalab.mastodon.R; @@ -52,6 +53,7 @@ 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; @@ -202,6 +204,87 @@ public class PeertubeAPI { return apiResponse; } + + + /*** + * Verifiy credential of the authenticated user *synchronously* + * @return Account + */ + public PeertubeInformation getPeertubeInformation() throws HttpsConnection.HttpsConnectionException { + PeertubeInformation peertubeInformation = new PeertubeInformation(); + try { + + String response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/categories"), 60, null, null); + JSONObject categories = new JSONObject(response); + HashMap<Integer, String> _pcategories = new HashMap<>(); + for( int i = 1 ; i <= categories.length() ; i++){ + _pcategories.put(i, categories.getString(String.valueOf(i))); + + } + peertubeInformation.setCategories(_pcategories); + + response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/languages"), 60, null, null); + JSONObject languages = new JSONObject(response); + HashMap<String, String> _languages = new HashMap<>(); + Iterator<String> iter = languages.keys(); + while (iter.hasNext()) { + String key = iter.next(); + try { + _languages.put(key, (String) languages.get(key)); + } catch (JSONException ignored) {} + } + peertubeInformation.setLanguages(_languages); + + response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/privacies"), 60, null, null); + JSONObject privacies = new JSONObject(response); + HashMap<Integer, String> _pprivacies = new HashMap<>(); + for( int i = 1 ; i <= privacies.length() ; i++){ + _pprivacies.put(i, privacies.getString(String.valueOf(i))); + + } + peertubeInformation.setPrivacies(_pprivacies); + + + response = new HttpsConnection(context).get(getAbsoluteUrl("/videos/licences"), 60, null, null); + JSONObject licences = new JSONObject(response); + HashMap<Integer, String> _plicences = new HashMap<>(); + for( int i = 1 ; i <= licences.length() ; i++){ + _plicences.put(i, licences.getString(String.valueOf(i))); + + } + peertubeInformation.setLicences(_plicences); + + + String instance = Helper.getLiveInstance(context); + String lang; + 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) {} + } + peertubeInformation.setTranslations(_translations); + + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + return peertubeInformation; + } + /*** * Verifiy credential of the authenticated user *synchronously* * @return Account diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java index 937c01321..cb325f144 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java @@ -37,6 +37,7 @@ import java.util.regex.Pattern; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.activities.PeertubeActivity; +import fr.gouv.etalab.mastodon.activities.PeertubeEditUploadActivity; import fr.gouv.etalab.mastodon.activities.ShowAccountActivity; import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask; @@ -59,15 +60,25 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio private LayoutInflater layoutInflater; private Context context; private String instance; + private boolean ownVideos; public PeertubeAdapter(Context context, String instance, List<Peertube> peertubes){ this.peertubes = peertubes; layoutInflater = LayoutInflater.from(context); this.context = context; this.instance = instance; + this.ownVideos = false; } + public PeertubeAdapter(Context context, String instance, boolean ownVideos, List<Peertube> peertubes){ + this.peertubes = peertubes; + layoutInflater = LayoutInflater.from(context); + this.context = context; + this.instance = instance; + this.ownVideos = ownVideos; + } + @NonNull @Override @@ -101,49 +112,65 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, peertube.getCreated_at()))); holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(peertube.getView()))); - holder.peertube_profile.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //For remote peertube instance - if( !peertube.getInstance().equals(Helper.getLiveInstance(context))) - CrossActions.doCrossProfile(context, account); - else { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putBoolean("peertubeaccount", true); - b.putParcelable("account", peertube.getAccount()); - intent.putExtras(b); - context.startActivity(intent); - } - } - }); Glide.with(holder.peertube_video_image.getContext()) .load("https://" + peertube.getInstance() + peertube.getThumbnailPath()) .into(holder.peertube_video_image); - if( account.getAvatar() != null && !account.getAvatar().startsWith("http")) + if (account.getAvatar() != null && !account.getAvatar().startsWith("http")) account.setAvatar("https://" + peertube.getInstance() + account.getAvatar()); Helper.loadGiF(context, account.getAvatar(), holder.peertube_profile); - holder.main_container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(context, PeertubeActivity.class); - Bundle b = new Bundle(); - if( (instance == null || instance.trim().length() == 0) && MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) - instance = Helper.getLiveInstance(context); - String finalUrl = "https://" + instance + peertube.getEmbedPath(); - Pattern link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/embed\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$"); - Matcher matcherLink = link.matcher(finalUrl); - if( matcherLink.find()) { - String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2); - b.putString("peertubeLinkToFetch", url); - b.putString("peertube_instance", matcherLink.group(1).replace("https://","").replace("http://","")); - b.putString("video_id", matcherLink.group(2)); + + + if( !this.ownVideos) { + holder.peertube_profile.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //For remote peertube instance + if (!peertube.getInstance().equals(Helper.getLiveInstance(context))) + CrossActions.doCrossProfile(context, account); + else { + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putBoolean("peertubeaccount", true); + b.putParcelable("account", peertube.getAccount()); + + intent.putExtras(b); + context.startActivity(intent); + } + } + }); + holder.main_container.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, PeertubeActivity.class); + Bundle b = new Bundle(); + if ((instance == null || instance.trim().length() == 0) && MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) + instance = Helper.getLiveInstance(context); + String finalUrl = "https://" + instance + peertube.getEmbedPath(); + Pattern link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/embed\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$"); + Matcher matcherLink = link.matcher(finalUrl); + if (matcherLink.find()) { + String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2); + b.putString("peertubeLinkToFetch", url); + b.putString("peertube_instance", matcherLink.group(1).replace("https://", "").replace("http://", "")); + b.putString("video_id", matcherLink.group(2)); + } + intent.putExtras(b); + context.startActivity(intent); } - intent.putExtras(b); - context.startActivity(intent); - } - }); + }); + }else{ + holder.main_container.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, PeertubeEditUploadActivity.class); + Bundle b = new Bundle(); + b.putString("video_id",peertube.getId()); + intent.putExtras(b); + context.startActivity(intent); + } + }); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 02bfcfbf5..c49a46d04 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -111,6 +111,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private String updatedBookMark; private String lastReadToot; private boolean ischannel; + private boolean ownVideos; public DisplayStatusFragment(){ } @@ -132,6 +133,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if (bundle != null) { type = (RetrieveFeedsAsyncTask.Type) bundle.get("type"); targetedId = bundle.getString("targetedid", null); + ownVideos = bundle.getBoolean("ownvideos", false); //Peetube account watching its videos tag = bundle.getString("tag", null); showMediaOnly = bundle.getBoolean("showMediaOnly",false); showPinned = bundle.getBoolean("showPinned",false); @@ -196,7 +198,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if( remoteInstance != null && MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) //if it's a Peertube account connected remoteInstance = account.getInstance(); BaseMainActivity.displayPeertube = remoteInstance; - peertubeAdapater = new PeertubeAdapter(context, remoteInstance, this.peertubes); + peertubeAdapater = new PeertubeAdapter(context, remoteInstance, ownVideos, this.peertubes); lv_status.setAdapter(peertubeAdapater); } mLayoutManager = new LinearLayoutManager(context); @@ -435,7 +437,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn this.peertubes.addAll(apiResponse.getPeertubes()); //If no item were inserted previously the adapter is created if( previousPosition == 0) { - peertubeAdapater = new PeertubeAdapter(context, remoteInstance, this.peertubes); + peertubeAdapater = new PeertubeAdapter(context, remoteInstance, ownVideos, this.peertubes); lv_status.setAdapter(peertubeAdapater); }else peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size()); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrievePeertubeInterface.java b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrievePeertubeInterface.java index 8c64cf4e0..e914705d5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrievePeertubeInterface.java +++ b/ |