Some fixes
This commit is contained in:
parent
38e39d3466
commit
cf27cb06c0
|
@ -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();
|
||||
|
|
|
@ -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<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||
LinkedHashMap<Integer, String> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -180,6 +180,8 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -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<Void, Void, Void>
|
|||
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);
|
||||
|
|
|
@ -117,7 +117,8 @@ public class API {
|
|||
RATEVIDEO,
|
||||
PEERTUBECOMMENT,
|
||||
PEERTUBEREPLY,
|
||||
PEERTUBEDELETECOMMENT
|
||||
PEERTUBEDELETECOMMENT,
|
||||
PEERTUBEDELETEVIDEO
|
||||
|
||||
}
|
||||
public enum accountPrivacy {
|
||||
|
|
|
@ -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<>();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -217,17 +217,42 @@
|
|||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_gravity="center"
|
||||
>
|
||||
|
||||
<!-- Videos upload edit submit -->
|
||||
<Button
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/set_upload_delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:backgroundTint="@color/unfollow"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:layout_margin="10dp"
|
||||
android:text="@string/delete_video" />
|
||||
|
||||
<!-- Videos upload edit submit -->
|
||||
<Button
|
||||
android:layout_marginTop="40dp"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/set_upload_submit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:enabled="false"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:text="@string/update_video" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
|
|
@ -814,6 +814,8 @@
|
|||
<string name="upload_video_success">The video has been uploaded!</string>
|
||||
<string name="uploading">Uploading, please wait…</string>
|
||||
<string name="video_uploaded_action">Click here to edit the video data.</string>
|
||||
<string name="delete_video">Delete video</string>
|
||||
<string name="delete_video_confirmation">Are you sure to delete this video?</string>
|
||||
<!-- end languages -->
|
||||
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
<item name="android:textColor">@color/black</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="AppTheme_NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:textColor">@color/light_black</item>
|
||||
<item name="android:scrollbarThumbVertical">@color/transparent</item>
|
||||
|
|
Loading…
Reference in New Issue