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 c41f95615..fc47334ed 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 @@ -156,6 +156,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_TARGETED_ACCOUNT; import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID; +import static fr.gouv.etalab.mastodon.helper.Helper.RELOAD_MYVIDEOS; import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_INSTANCE; import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_REMOTE; import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_URL; @@ -977,8 +978,8 @@ public abstract class BaseMainActivity extends BaseActivity .replace(R.id.main_app_container, statusFragment, fragmentTag).commit(); } } - //toolbar_search.setQuery("", false); - //toolbar_search.setIconified(true); + toolbar_search.setQuery("", false); + toolbar_search.setIconified(true); if( main_app_container.getVisibility() == View.VISIBLE){ main_app_container.setVisibility(View.VISIBLE); viewPager.setVisibility(View.GONE); @@ -1639,7 +1640,24 @@ public abstract class BaseMainActivity extends BaseActivity intentShow.putExtras(b); startActivity(intentShow); } - }else if( extras.getInt(INTENT_ACTION) == SEARCH_INSTANCE){ + }else if( extras.getInt(INTENT_ACTION) == RELOAD_MYVIDEOS){ + Bundle bundle = new Bundle(); + DisplayStatusFragment fragment = new DisplayStatusFragment(); + bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.MYVIDEOS); + bundle.putString("instanceType","PEERTUBE"); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); + 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); + String fragmentTag = "MY_VIDEOS"; + FragmentManager fragmentManager = getSupportFragmentManager(); + fragmentManager.beginTransaction() + .replace(R.id.main_app_container, fragment, fragmentTag).commit(); + } + else if( extras.getInt(INTENT_ACTION) == SEARCH_INSTANCE){ String instance = extras.getString(INSTANCE_NAME); DisplayStatusFragment statusFragment; Bundle bundle = new Bundle(); 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 index 7f4775099..2a5cd5e09 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeEditUploadActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeEditUploadActivity.java @@ -17,10 +17,13 @@ package fr.gouv.etalab.mastodon.activities; import android.annotation.SuppressLint; import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; @@ -43,25 +46,31 @@ import java.util.Map; import es.dmoral.toasty.Toasty; import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask; 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.API; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.client.Entities.Peertube; import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; 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.INTENT_ACTION; +import static fr.gouv.etalab.mastodon.helper.Helper.RELOAD_MYVIDEOS; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT; import static fr.gouv.etalab.mastodon.helper.Helper.changeMaterialSpinnerColor; -public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface { +public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface, OnPostActionInterface { - private Button set_upload_submit; + private Button set_upload_submit, set_upload_delete; private MaterialSpinner 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; @@ -102,7 +111,6 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie if( videoId == null){ videoId = sharedpreferences.getString(Helper.VIDEO_ID, null); } - if( getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); ActionBar actionBar = getSupportActionBar(); @@ -130,6 +138,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie set_upload_submit = findViewById(R.id.set_upload_submit); + set_upload_delete = findViewById(R.id.set_upload_delete); set_upload_privacy = findViewById(R.id.set_upload_privacy); set_upload_channel = findViewById(R.id.set_upload_channel); set_upload_categories = findViewById(R.id.set_upload_categories); @@ -151,6 +160,38 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie changeMaterialSpinnerColor(PeertubeEditUploadActivity.this, set_upload_privacy); + set_upload_delete.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + AlertDialog.Builder builderInner; + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + int style; + if (theme == Helper.THEME_DARK) { + style = R.style.DialogDark; + } else if (theme == Helper.THEME_BLACK){ + style = R.style.DialogBlack; + }else { + style = R.style.Dialog; + } + builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this, style); + builderInner.setMessage(getString(R.string.delete_video_confirmation)); + builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + dialog.dismiss(); + } + }); + builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR); + dialog.dismiss(); + } + }); + builderInner.show(); + } + }); //Get params from the API LinkedHashMap categories = new LinkedHashMap<>(peertubeInformation.getCategories()); LinkedHashMap licences = new LinkedHashMap<>(peertubeInformation.getLicences()); @@ -572,4 +613,12 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie set_upload_submit.setEnabled(true); } + + @Override + public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + intent.putExtra(INTENT_ACTION, RELOAD_MYVIDEOS); + startActivity(intent); + finish(); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java index ef8248214..525a0bbb9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java @@ -180,6 +180,8 @@ public class PostActionAsyncTask extends AsyncTask { else if( apiAction == API.StatusAction.PEERTUBEDELETECOMMENT) { statusCode = peertubeAPI.deleteComment(targetedId, comment); targetedId = comment; + } else if( apiAction == API.StatusAction.PEERTUBEDELETEVIDEO) { + statusCode = peertubeAPI.deleteVideo(targetedId); } error = peertubeAPI.getError(); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeSingleAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeSingleAsyncTask.java index e4a69b7ba..3240bec11 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeSingleAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeSingleAsyncTask.java @@ -15,6 +15,7 @@ package fr.gouv.etalab.mastodon.asynctasks; import android.content.Context; +import android.content.SharedPreferences; import android.os.AsyncTask; import java.lang.ref.WeakReference; @@ -23,6 +24,7 @@ import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.PeertubeAPI; +import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface; @@ -59,8 +61,10 @@ public class RetrievePeertubeSingleAsyncTask extends AsyncTask 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) { + SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); + apiResponse = peertubeAPI.getSinglePeertube(this.instanceName, videoId, token); + if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) { String rate = new PeertubeAPI(this.contextReference.get()).getRating(videoId); if( rate != null) apiResponse.getPeertubes().get(0).setMyRating(rate); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 0d2f99120..10673f976 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -117,7 +117,8 @@ public class API { RATEVIDEO, PEERTUBECOMMENT, PEERTUBEREPLY, - PEERTUBEDELETECOMMENT + PEERTUBEDELETECOMMENT, + PEERTUBEDELETEVIDEO } public enum accountPrivacy { 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 75c5b5929..f658574dc 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 @@ -873,13 +873,12 @@ public class PeertubeAPI { * Retrieves Peertube videos from an instance *synchronously* * @return APIResponse */ - public APIResponse getSinglePeertube(String instance, String videoId) { - + public APIResponse getSinglePeertube(String instance, String videoId, String token) { Peertube peertube = null; try { HttpsConnection httpsConnection = new HttpsConnection(context); - String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/videos/%s", videoId), 60, null, null); + String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/videos/%s", videoId), 60, null, token); JSONObject jsonObject = new JSONObject(response); peertube = parseSinglePeertube(context, instance, jsonObject); } catch (HttpsConnection.HttpsConnectionException e) { @@ -1016,6 +1015,10 @@ public class PeertubeAPI { public int deleteComment(String targetedId, String targetedComment){ return postAction(API.StatusAction.PEERTUBEDELETECOMMENT, targetedId, null, targetedComment); } + + public int deleteVideo(String targetedId){ + return postAction(API.StatusAction.PEERTUBEDELETEVIDEO, targetedId, null, null); + } /** * Makes the post action * @param statusAction Enum @@ -1054,6 +1057,10 @@ public class PeertubeAPI { action = String.format("/videos/%s/comments/%s", targetedId, targetedComment); actionCall = "DELETE"; break; + case PEERTUBEDELETEVIDEO: + action = String.format("/videos/%s", targetedId); + actionCall = "DELETE"; + break; case PEERTUBEREPLY: action = String.format("/videos/%s/comment/%s", targetedId, targetedComment); params = new HashMap<>(); 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 6a26df057..06426aac9 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 @@ -165,7 +165,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio public void onClick(View v) { Intent intent = new Intent(context, PeertubeEditUploadActivity.class); Bundle b = new Bundle(); - b.putString("video_id",peertube.getId()); + b.putString("video_id",peertube.getUuid()); intent.putExtras(b); context.startActivity(intent); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index ee1f19c8c..73b1a4c48 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -253,7 +253,7 @@ public class Helper { public static final int SEARCH_TAG = 7; public static final int SEARCH_INSTANCE = 8; public static final int SEARCH_REMOTE = 9; - + public static final int RELOAD_MYVIDEOS = 10; //Settings public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page"; public static final String SET_ACCOUNTS_PER_PAGE = "set_accounts_per_page"; diff --git a/app/src/main/res/layout/activity_peertube_edit.xml b/app/src/main/res/layout/activity_peertube_edit.xml index c228d5a9b..55bfbd636 100644 --- a/app/src/main/res/layout/activity_peertube_edit.xml +++ b/app/src/main/res/layout/activity_peertube_edit.xml @@ -217,17 +217,42 @@ android:layout_height="wrap_content" /> - -