Rate videos + comments - #692

This commit is contained in:
stom79 2019-01-04 16:41:47 +01:00
parent 15abff8c2b
commit 13785b0db3
12 changed files with 371 additions and 781 deletions

View File

@ -44,7 +44,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
@ -61,11 +63,14 @@ import javax.net.ssl.HttpsURLConnection;
import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleCommentsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.Status;
@ -73,12 +78,14 @@ import fr.gouv.etalab.mastodon.client.TLSSocketFactory;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.helper.FullScreenMediaController;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads;
@ -87,7 +94,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads;
* Peertube activity
*/
public class PeertubeActivity extends BaseActivity implements OnRetrievePeertubeInterface {
public class PeertubeActivity extends BaseActivity implements OnRetrievePeertubeInterface, OnPostActionInterface {
private String peertubeInstance, videoId;
private FullScreenMediaController.fullscreen fullscreen;
@ -100,6 +107,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private int stopPosition;
private Peertube peertube;
private TextView toolbar_title;
public static String video_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -163,7 +171,6 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
videoView = findViewById(R.id.media_video);
new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void change(){
@ -200,41 +207,84 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
finish();
return true;
case R.id.action_comment:
Toasty.info(PeertubeActivity.this, getString(R.string.retrieve_remote_status), Toast.LENGTH_LONG).show();
new AsyncTask<Void, Void, Void>() {
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
Toasty.info(PeertubeActivity.this, getString(R.string.retrieve_remote_status), Toast.LENGTH_LONG).show();
new AsyncTask<Void, Void, Void>() {
private List<fr.gouv.etalab.mastodon.client.Entities.Status> remoteStatuses;
private WeakReference<Context> contextReference = new WeakReference<>(PeertubeActivity.this);
private List<fr.gouv.etalab.mastodon.client.Entities.Status> remoteStatuses;
private WeakReference<Context> contextReference = new WeakReference<>(PeertubeActivity.this);
@Override
protected Void doInBackground(Void... voids) {
@Override
protected Void doInBackground(Void... voids) {
if(peertube != null) {
Results search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
if (search != null) {
remoteStatuses = search.getStatuses();
if (peertube != null) {
Results search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
if (search != null) {
remoteStatuses = search.getStatuses();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
Intent intent = new Intent(contextReference.get(), TootActivity.class);
Bundle b = new Bundle();
if (remoteStatuses == null || remoteStatuses.size() == 0) {
Toasty.error(contextReference.get(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
return;
}
if (remoteStatuses.get(0).getReblog() != null) {
b.putParcelable("tootReply", remoteStatuses.get(0).getReblog());
} else {
b.putParcelable("tootReply", remoteStatuses.get(0));
}
intent.putExtras(b); //Put your id to your next Intent
contextReference.get().startActivity(intent);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
if(! peertube.isCommentsEnabled()) {
Toasty.info(PeertubeActivity.this, getString(R.string.comment_no_allowed_peertube),Toast.LENGTH_LONG).show();
return true;
}
int style;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
style = R.style.DialogBlack;
}else {
style = R.style.Dialog;
}
AlertDialog.Builder builderInner;
builderInner = new AlertDialog.Builder(PeertubeActivity.this, style);
builderInner.setTitle(R.string.comment);
EditText input = new EditText(PeertubeActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
builderInner.setView(input);
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
dialog.dismiss();
}
});
builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
String comment = input.getText().toString();
if( comment.trim().length() > 0 ) {
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
Intent intent = new Intent(contextReference.get(), TootActivity.class);
Bundle b = new Bundle();
if( remoteStatuses == null || remoteStatuses.size() == 0){
Toasty.error(contextReference.get(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
return;
}
if( remoteStatuses.get(0).getReblog() != null ) {
b.putParcelable("tootReply", remoteStatuses.get(0).getReblog());
}else {
b.putParcelable("tootReply", remoteStatuses.get(0));
}
intent.putExtras(b); //Put your id to your next Intent
contextReference.get().startActivity(intent);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR );
});
builderInner.show();
}
return true;
default:
return super.onOptionsItemSelected(item);
@ -280,6 +330,31 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
peertube_dislike_count.setText(String.valueOf(peertube.getDislike()));
peertube_like_count.setText(String.valueOf(peertube.getLike()));
peertube_view_count.setText(String.valueOf(peertube.getView()));
video_id = peertube.getId();
changeColor();
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
peertube_like_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("like")?"none":"like";
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
}
});
peertube_dislike_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("dislike")?"none":"dislike";
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
}
});
}
Uri uri = Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null));
try {
@ -467,4 +542,30 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
});
builderSingle.show();
}
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
if( peertube.isCommentsEnabled() && statusAction == API.StatusAction.PEERTUBECOMMENT)
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void changeColor(){
if( peertube.getMyRating() != null && peertube.getMyRating().equals("like")){
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.positive_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.neutral_thumbs);
}else if( peertube.getMyRating() != null && peertube.getMyRating().equals("dislike")){
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.neutral_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.negative_thumbs);
}else {
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.neutral_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.neutral_thumbs);
}
Drawable thumbUp = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_thumb_up_peertube);
Drawable thumbDown = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_thumb_down_peertube);
peertube_like_count.setCompoundDrawablesWithIntrinsicBounds( null, thumbUp, null, null);
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds( null, thumbDown, null, null);
}
}

View File

@ -1193,7 +1193,6 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
}
@Override
public void onPostAction(int statusCode,API.StatusAction statusAction, String targetedId, Error error) {
Log.v(Helper.TAG,statusAction + " * " + statusCode + " - error4: " + error);
if( error != null){
Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();

View File

@ -40,7 +40,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
private OnPostActionInterface listener;
private int statusCode;
private API.StatusAction apiAction;
private String targetedId;
private String targetedId, targetedComment;
private String comment;
private fr.gouv.etalab.mastodon.client.Entities.Status status;
private Account account, remoteAccount;
@ -49,7 +49,6 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean muteNotifications;
private Error error;
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
@ -97,6 +96,16 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
this.muteNotifications = muteNotifications;
}
public PostActionAsyncTask(Context context, String targetedId, String comment, String targetedComment, OnPostActionInterface onPostActionInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = API.StatusAction.PEERTUBEREPLY;
this.targetedId = targetedId;
this.comment = comment;
this.targetedComment = targetedComment;
}
@Override
protected Void doInBackground(Void... params) {
@ -162,6 +171,16 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
if( apiAction == API.StatusAction.FOLLOW || apiAction == API.StatusAction.UNFOLLOW)
statusCode = peertubeAPI.postAction(apiAction, targetedId);
else if( apiAction == API.StatusAction.RATEVIDEO )
statusCode = peertubeAPI.postRating(targetedId, comment);
else if( apiAction == API.StatusAction.PEERTUBECOMMENT)
statusCode = peertubeAPI.postComment(targetedId, comment);
else if( apiAction == API.StatusAction.PEERTUBEREPLY)
statusCode = peertubeAPI.postReply(targetedId, comment, targetedComment);
else if( apiAction == API.StatusAction.PEERTUBEDELETECOMMENT) {
statusCode = peertubeAPI.deleteComment(targetedId, comment);
targetedId = comment;
}
error = peertubeAPI.getError();
}
return null;

View File

@ -13,11 +13,16 @@
* 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.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.interfaces.OnRetrievePeertubeInterface;
@ -51,6 +56,10 @@ public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, Void>
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);
}
return null;
}

View File

@ -110,7 +110,11 @@ public class API {
UNENDORSE,
SHOW_BOOST,
HIDE_BOOST,
BLOCK_DOMAIN
BLOCK_DOMAIN,
RATEVIDEO,
PEERTUBECOMMENT,
PEERTUBEREPLY,
PEERTUBEDELETECOMMENT
}
public enum accountPrivacy {

View File

@ -46,6 +46,7 @@ public class Peertube {
private String category;
private String license;
private String language;
private String myRating = "none";
private JSONObject cache;
@ -254,4 +255,12 @@ public class Peertube {
public void setLanguage(String language) {
this.language = language;
}
public String getMyRating() {
return myRating;
}
public void setMyRating(String myRating) {
this.myRating = myRating;
}
}

View File

@ -963,123 +963,6 @@ public class PeertubeAPI {
/**
* Retrieves public tag timeline *synchronously*
* @param tag String
* @param local boolean only local timeline
* @param max_id String id max
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getPublicTimelineTag(String tag, boolean local, String max_id, List<String> any, List<String> all, List<String> none){
return getPublicTimelineTag(tag, local, false, max_id, null, tootPerPage, any, all, none);
}
/**
* Retrieves public tag timeline *synchronously*
* @param tag String
* @param local boolean only local timeline
* @param since_id String since id
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getPublicTimelineTagSinceId(String tag, boolean local, String since_id, List<String> any, List<String> all, List<String> none){
return getPublicTimelineTag(tag, local, false, null, since_id, tootPerPage, any, all, none);
}
/**
* Retrieves public tag timeline *synchronously*
* @param tag String
* @param local boolean only local timeline
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
private APIResponse getPublicTimelineTag(String tag, boolean local, boolean onlymedia, String max_id, String since_id, int limit, List<String> any, List<String> all, List<String> none){
HashMap<String, String> params = new HashMap<>();
if( local)
params.put("local", Boolean.toString(true));
if( max_id != null )
params.put("max_id", max_id);
if( since_id != null )
params.put("since_id", since_id);
if( 0 > limit || limit > 40)
limit = 40;
if( onlymedia)
params.put("only_media", Boolean.toString(true));
if( any != null && any.size() > 0) {
StringBuilder parameters = new StringBuilder();
for (String a : any)
parameters.append("any[]=").append(a).append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(6));
params.put("any[]", parameters.toString());
}
if( all != null && all.size() > 0) {
StringBuilder parameters = new StringBuilder();
for (String a : all)
parameters.append("all[]=").append(a).append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(6));
params.put("all[]", parameters.toString());
}
if( none != null && none.size() > 0) {
StringBuilder parameters = new StringBuilder();
for (String a : none)
parameters.append("none[]=").append(a).append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(7));
params.put("none[]", parameters.toString());
}
params.put("limit",String.valueOf(limit));
statuses = new ArrayList<>();
if( tag == null)
return null;
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/tag/%s",tag.trim())), 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;
}
/**
* Retrieves muted users by the authenticated account *synchronously*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getMuted(String max_id){
return getAccounts("/mutes", max_id, null, accountPerPage);
}
/**
* Retrieves blocked users by the authenticated account *synchronously*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getBlocks(String max_id){
return getAccounts("/blocks", max_id, null, accountPerPage);
}
/**
* Retrieves following for the account specified by targetedId *synchronously*
* @param targetedId String targetedId
@ -1149,24 +1032,16 @@ public class PeertubeAPI {
/**
* Retrieves blocked domains for the authenticated account *synchronously*
* @param max_id String id max
* Retrieves rating of user on a video *synchronously*
* @param id String id
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getBlockedDomain(String max_id){
HashMap<String, String> params = new HashMap<>();
if( max_id != null )
params.put("max_id", max_id);
params.put("limit","80");
domains = new ArrayList<>();
public String getRating(String id){
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/domain_blocks"), 60, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
domains = parseDomains(new JSONArray(response));
String response = httpsConnection.get(getAbsoluteUrl(String.format("/users/me/videos/%s/rating",id)), 60, null, prefKeyOauthTokenT);
return new JSONObject(response).get("rating").toString();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
@ -1178,133 +1053,7 @@ public class PeertubeAPI {
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setDomains(domains);
return apiResponse;
}
/**
* Delete a blocked domains for the authenticated account *synchronously*
* @param domain String domain name
*/
@SuppressWarnings("SameParameterValue")
public int deleteBlockedDomain(String domain){
HashMap<String, String> params = new HashMap<>();
params.put("domain",domain);
domains = new ArrayList<>();
HttpsConnection httpsConnection;
try {
httpsConnection = new HttpsConnection(context);
httpsConnection.delete(getAbsoluteUrl("/domain_blocks"), 60, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return actionCode;
}
/**
* Retrieves follow requests for the authenticated account *synchronously*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getFollowRequest(String max_id){
return getFollowRequest(max_id, null, accountPerPage);
}
/**
* Retrieves follow requests 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
*/
@SuppressWarnings("SameParameterValue")
private APIResponse getFollowRequest(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 > 40)
limit = 40;
params.put("limit",String.valueOf(limit));
accounts = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/follow_requests"), 60, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
accounts = parseAccountResponse(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.setAccounts(accounts);
return apiResponse;
}
/**
* Retrieves favourited status for the authenticated account *synchronously*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getFavourites(String max_id){
return getFavourites(max_id, null, tootPerPage);
}
/**
* Retrieves favourited status 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
*/
@SuppressWarnings("SameParameterValue")
private APIResponse getFavourites(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 > 40)
limit = 40;
params.put("limit",String.valueOf(limit));
statuses = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/favourites"), 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;
return null;
}
@ -1318,324 +1067,90 @@ public class PeertubeAPI {
return postAction(statusAction, targetedId, null, null);
}
/**
* Makes the post action for a status
* @param targetedId String id of the targeted Id *can be this of a status or an account*
* @param muteNotifications - boolean - notifications should be also muted
* @return in status code - Should be equal to 200 when action is done
*/
public int muteNotifications(String targetedId, boolean muteNotifications){
HashMap<String, String> params = new HashMap<>();
params.put("notifications", Boolean.toString(muteNotifications));
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
httpsConnection.post(getAbsoluteUrl(String.format("/accounts/%s/mute", targetedId)), 60, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} 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();
}
return actionCode;
public int postRating(String targetedId, String actionMore){
return postAction(API.StatusAction.RATEVIDEO, targetedId, actionMore, null);
}
/**
* Makes the post action
* @param status Status object related to the status
* @param comment String comment for the report
* @return in status code - Should be equal to 200 when action is done
*/
public int reportAction(Status status, String comment){
return postAction(API.StatusAction.REPORT, null, status, comment);
public int postComment(String targetedId, String actionMore){
return postAction(API.StatusAction.PEERTUBECOMMENT, targetedId, actionMore, null);
}
public int statusAction(Status status){
return postAction(API.StatusAction.CREATESTATUS, null, status, null);
public int postReply(String targetedId, String actionMore, String targetedComment){
return postAction(API.StatusAction.PEERTUBEREPLY, targetedId, actionMore, targetedComment);
}
public int deleteComment(String targetedId, String targetedComment){
return postAction(API.StatusAction.PEERTUBEDELETECOMMENT, targetedId, null, targetedComment);
}
/**
* Makes the post action
* @param statusAction Enum
* @param targetedId String id of the targeted Id *can be this of a status or an account*
* @param status Status object related to the status
* @param comment String comment for the report
* @param actionMore String another action
* @param targetedComment String another action
* @return in status code - Should be equal to 200 when action is done
*/
private int postAction(API.StatusAction statusAction, String targetedId, Status status, String comment ){
private int postAction(API.StatusAction statusAction, String targetedId, String actionMore, String targetedComment){
String action;
String actionCall = "POST";
HashMap<String, String> params = null;
switch (statusAction){
case FAVOURITE:
action = String.format("/statuses/%s/favourite", targetedId);
break;
case UNFAVOURITE:
action = String.format("/statuses/%s/unfavourite", targetedId);
break;
case REBLOG:
action = String.format("/statuses/%s/reblog", targetedId);
break;
case UNREBLOG:
action = String.format("/statuses/%s/unreblog", targetedId);
break;
case FOLLOW:
action = "/users/me/subscriptions";
params = new HashMap<>();
params.put("uri", targetedId);
break;
case REMOTE_FOLLOW:
action = "/follows";
params = new HashMap<>();
params.put("uri", targetedId);
break;
case UNFOLLOW:
action = String.format("/users/me/subscriptions/%s", targetedId);
actionCall = "DELETE";
break;
case BLOCK:
action = String.format("/accounts/%s/block", targetedId);
break;
case BLOCK_DOMAIN:
action = "/domain_blocks";
case RATEVIDEO:
action = String.format("/videos/%s/rate", targetedId);
params = new HashMap<>();
params.put("domain", targetedId);
params.put("rating", actionMore);
actionCall = "PUT";
break;
case UNBLOCK:
action = String.format("/accounts/%s/unblock", targetedId);
break;
case MUTE:
action = String.format("/accounts/%s/mute", targetedId);
break;
case UNMUTE:
action = String.format("/accounts/%s/unmute", targetedId);
break;
case PIN:
action = String.format("/statuses/%s/pin", targetedId);
break;
case UNPIN:
action = String.format("/statuses/%s/unpin", targetedId);
break;
case ENDORSE:
action = String.format("/accounts/%s/pin", targetedId);
break;
case UNENDORSE:
action = String.format("/accounts/%s/unpin", targetedId);
break;
case SHOW_BOOST:
case PEERTUBECOMMENT:
action = String.format("/videos/%s/comment-threads", targetedId);
params = new HashMap<>();
params.put("reblogs","true");
action = String.format("/accounts/%s/follow", targetedId);
params.put("text", actionMore);
break;
case HIDE_BOOST:
case PEERTUBEDELETECOMMENT:
action = String.format("/videos/%s/comments/%s", targetedId, targetedComment);
actionCall = "DELETE";
break;
case PEERTUBEREPLY:
action = String.format("/videos/%s/comment/%s", targetedId, targetedComment);
params = new HashMap<>();
params.put("reblogs","false");
action = String.format("/accounts/%s/follow", targetedId);
break;
case UNSTATUS:
action = String.format("/statuses/%s", targetedId);
break;
case AUTHORIZE:
action = String.format("/follow_requests/%s/authorize", targetedId);
break;
case REJECT:
action = String.format("/follow_requests/%s/reject", targetedId);
break;
case REPORT:
action = "/reports";
params = new HashMap<>();
params.put("account_id", status.getAccount().getId());
params.put("comment", comment);
params.put("status_ids[]", status.getId());
break;
case CREATESTATUS:
params = new HashMap<>();
action = "/statuses";
try {
params.put("status", URLEncoder.encode(status.getContent(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
params.put("status", status.getContent());
}
if( status.getIn_reply_to_id() != null)
params.put("in_reply_to_id", status.getIn_reply_to_id());
if( status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0 ) {
StringBuilder parameters = new StringBuilder();
for(Attachment attachment: status.getMedia_attachments())
parameters.append("media_ids[]=").append(attachment.getId()).append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(12));
params.put("media_ids[]", parameters.toString());
}
if( status.isSensitive())
params.put("sensitive", Boolean.toString(status.isSensitive()));
if( status.getSpoiler_text() != null)
try {
params.put("spoiler_text", URLEncoder.encode(status.getSpoiler_text(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
params.put("spoiler_text", status.getSpoiler_text());
}
params.put("visibility", status.getVisibility());
params.put("text", actionMore);
break;
default:
return -1;
}
if(statusAction != API.StatusAction.UNSTATUS ) {
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
if( actionCall.equals("POST"))
httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
else if( actionCall.equals("DELETE"))
httpsConnection.delete(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
}else{
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
httpsConnection.delete(getAbsoluteUrl(action), 60, null, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
if( actionCall.equals("POST"))
httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
else if( actionCall.equals("DELETE"))
httpsConnection.delete(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
else if( actionCall.equals("PUT"))
httpsConnection.put(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return actionCode;
}
/**
* Posts a status
* @param status Status object related to the status
* @return APIResponse
*/
public APIResponse postStatusAction(Status status){
HashMap<String, String> params = new HashMap<>();
try {
params.put("status", URLEncoder.encode(status.getContent(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
params.put("status", status.getContent());
}
if( status.getIn_reply_to_id() != null)
params.put("in_reply_to_id", status.getIn_reply_to_id());
if( status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0 ) {
StringBuilder parameters = new StringBuilder();
for(Attachment attachment: status.getMedia_attachments())
parameters.append("media_ids[]=").append(attachment.getId()).append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(12));
params.put("media_ids[]", parameters.toString());
}
if( status.isSensitive())
params.put("sensitive", Boolean.toString(status.isSensitive()));
if( status.getSpoiler_text() != null)
try {
params.put("spoiler_text", URLEncoder.encode(status.getSpoiler_text(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
params.put("spoiler_text", status.getSpoiler_text());
}
params.put("visibility", status.getVisibility());
statuses = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.post(getAbsoluteUrl("/statuses"), 60, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
Status statusreturned = parseStatuses(context, new JSONObject(response));
statuses.add(statusreturned);
} 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;
}
/**
* Posts a status
* @param notificationId String, the current notification id, if null all notifications are deleted
* @return APIResponse
*/
public APIResponse postNoticationAction(String notificationId){
String action;
HashMap<String, String> params = new HashMap<>();
if( notificationId == null)
action = "/notifications/clear";
else {
params.put("id",notificationId);
action = "/notifications/dismiss";
}
try {
new HttpsConnection(context).post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return apiResponse;
}
/**
* Retrieves notifications for the authenticated account since an id*synchronously*
* @param since_id String since max
* @return APIResponse
*/
public APIResponse getNotificationsSince(String since_id, boolean display){
return getNotifications(null, since_id, notificationPerPage, display);
}
/**
* Retrieves notifications for the authenticated account since an id*synchronously*
* @param since_id String since max
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getNotificationsSince(String since_id, int notificationPerPage, boolean display){
return getNotifications(null, since_id, notificationPerPage, display);
}
/**
* Retrieves notifications for the authenticated account *synchronously*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getNotifications(String max_id, boolean display){
return getNotifications(max_id, null, notificationPerPage, display);
}
/**
* Retrieves notifications for the authenticated account *synchronously*
@ -2176,214 +1691,6 @@ public class PeertubeAPI {
}
/**
* Add an account in a list
* @param id String, id of the list
* @param account_ids String, account to add
* @return APIResponse
*/
//TODO: it is unclear what is returned here
//TODO: improves doc https://github.com/tootsuite/documentation/blob/4bb149c73f40fa58fd7265a336703dd2d83efb1c/Using-the-API/API.md#addingremoving-accounts-tofrom-a-list
public APIResponse addAccountToList(String id, String[] account_ids){
HashMap<String, String> params = new HashMap<>();
StringBuilder parameters = new StringBuilder();
for(String val: account_ids)
parameters.append("account_ids[]=").append(val).append("&");
if( parameters.length() > 0) {
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(14));
params.put("account_ids[]", parameters.toString());
}
try {
new HttpsConnection(context).post(getAbsoluteUrl(String.format("/lists/%s/accounts", id)), 60, params, prefKeyOauthTokenT);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return apiResponse;
}
/**
* Delete an account from a list
* @param id String, the id of the list
* @return APIResponse
*/
public int deleteAccountFromList(String id, String[] account_ids){
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
StringBuilder parameters = new StringBuilder();
HashMap<String, String> params = new HashMap<>();
for(String val: account_ids)
parameters.append("account_ids[]=").append(val).append("&");
if( parameters.length() > 0) {
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(14));
params.put("account_ids[]", parameters.toString());
}
httpsConnection.delete(getAbsoluteUrl(String.format("/lists/%s/accounts", id)), 60, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} 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();
}
return actionCode;
}
/**
* Posts a list
* @param title String, the title of the list
* @return APIResponse
*/
public APIResponse createList(String title){
HashMap<String, String> params = new HashMap<>();
params.put("title",title);
List<fr.gouv.etalab.mastodon.client.Entities.List> lists = new ArrayList<>();
fr.gouv.etalab.mastodon.client.Entities.List list;
try {
String response = new HttpsConnection(context).post(getAbsoluteUrl("/lists"), 60, params, prefKeyOauthTokenT);
list = parseList(new JSONObject(response));
lists.add(list);
} 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.setLists(lists);
return apiResponse;
}
/**
* Update a list by its id
* @param id String, the id of the list
* @param title String, the title of the list
* @return APIResponse
*/
public APIResponse updateList(String id, String title){
HashMap<String, String> params = new HashMap<>();
params.put("title",title);
List<fr.gouv.etalab.mastodon.client.Entities.List> lists = new ArrayList<>();
fr.gouv.etalab.mastodon.client.Entities.List list;
try {
String response = new HttpsConnection(context).put(getAbsoluteUrl(String.format("/lists/%s", id)), 60, params, prefKeyOauthTokenT);
list = parseList(new JSONObject(response));
lists.add(list);
} 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.setLists(lists);
return apiResponse;
}
/**
* Delete a list by its id
* @param id String, the id of the list
* @return APIResponse
*/
public int deleteList(String id){
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
httpsConnection.delete(getAbsoluteUrl(String.format("/lists/%s", id)), 60, null, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
}
return actionCode;
}
/**
* Retrieves list from Communitywiki *synchronously*
* @return APIResponse
*/
public ArrayList<String> getCommunitywikiList() {
ArrayList<String> list = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrlCommunitywiki("/list"), 60, null, prefKeyOauthTokenT);
JSONArray jsonArray = new JSONArray(response);
int len = jsonArray.length();
for (int i=0;i<len;i++){
list.add(jsonArray.get(i).toString());
}
} 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 list;
}
/**
* Retrieves list from Communitywiki *synchronously*
* @return APIResponse
*/
public ArrayList<String> getCommunitywikiList(String name) {
ArrayList<String> list = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrlCommunitywiki(String.format("/list/%s", name)), 60, null, prefKeyOauthTokenT);
JSONArray jsonArray = new JSONArray(response);
for(int i = 0; i < jsonArray.length(); i++){
try {
list.add(jsonArray.getJSONObject(i).getString("acct"));
} catch (JSONException ignored) {}
}
} 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 list;
}
/**

View File

@ -95,12 +95,14 @@ import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
import fr.gouv.etalab.mastodon.activities.MediaActivity;
import fr.gouv.etalab.mastodon.activities.PeertubeActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.activities.TootInfoActivity;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
@ -129,6 +131,7 @@ import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO;
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
import static fr.gouv.etalab.mastodon.activities.BaseMainActivity.social;
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK;
@ -339,6 +342,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
Button status_show_more_content;
SparkButton spark_button_fav, spark_button_reblog;
RelativeLayout horizontal_second_image;
LinearLayout status_peertube_container;
TextView status_peertube_reply, status_peertube_delete;
public View getView(){
return itemView;
}
@ -422,6 +429,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
spark_button_fav = itemView.findViewById(R.id.spark_button_fav);
spark_button_reblog = itemView.findViewById(R.id.spark_button_reblog);
horizontal_second_image = itemView.findViewById(R.id.horizontal_second_image);
status_peertube_container = itemView.findViewById(R.id.status_peertube_container);
status_peertube_reply = itemView.findViewById(R.id.status_peertube_reply);
status_peertube_delete = itemView.findViewById(R.id.status_peertube_delete);
}
}
@ -436,6 +448,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
isCompactMode = false;
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition)
return FOCUSED_STATUS;
else if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && !Helper.filterToots(context, statuses.get(position), timedMute, type))
@ -627,7 +641,86 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
//Display a preview for accounts that have replied *if enabled and only for home timeline*
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
holder.status_action_container.setVisibility(View.GONE);
holder.status_peertube_container.setVisibility(View.VISIBLE);
holder.status_peertube_reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builderInner;
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(context, style);
builderInner.setTitle(R.string.comment);
EditText input = new EditText(context);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
builderInner.setView(input);
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
dialog.dismiss();
}
});
builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
String comment = input.getText().toString();
if( comment.trim().length() > 0 ) {
new PostActionAsyncTask(context, PeertubeActivity.video_id, comment, status.getId(),StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
}
});
builderInner.show();
}
});
if( status.getAccount().getId().equals(userId))
holder.status_peertube_delete.setVisibility(View.VISIBLE);
else
holder.status_peertube_delete.setVisibility(View.GONE);
holder.status_peertube_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builderInner;
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(context, style);
builderInner.setTitle(R.string.delete_comment);
builderInner.setMessage(R.string.delete_comment_confirm);
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(context, API.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, null, status.getId(),StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
});
builderInner.show();
}
});
}
if( status.isNew())
holder.new_element.setVisibility(View.VISIBLE);
else
@ -1174,7 +1267,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
Helper.loadGiF(context, status.getConversationProfilePicture().get(3), holder.conversation_pp_4);
}
}
holder.status_action_container.setVisibility(View.VISIBLE);
boolean differentLanguage = false;
if( status.getReblog() == null)
differentLanguage = status.getLanguage() != null && !status.getLanguage().trim().equals(currentLocale);
@ -2583,6 +2675,17 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
position++;
}
}
if( statusAction == API.StatusAction.PEERTUBEDELETECOMMENT){
int position = 0;
for(Status status: statuses){
if( status.getId().equals(targetedId)) {
statuses.remove(status);
statusListAdapter.notifyItemRemoved(position);
break;
}
position++;
}
}
}
public void notifyStatusChanged(Status status){

View File

@ -97,7 +97,6 @@
android:id="@+id/peertube_like_count"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:drawableTop="@drawable/ic_thumb_up_peertube"
android:drawablePadding="5dp"
android:layout_width="wrap_content"
android:layout_marginRight="10dp"
@ -111,7 +110,6 @@
android:id="@+id/peertube_dislike_count"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:drawableTop="@drawable/ic_thumb_down_peertube"
android:drawablePadding="5dp"
android:layout_width="wrap_content"
android:layout_marginRight="10dp"

View File

@ -683,6 +683,38 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginStart="60dp"
android:layout_marginLeft="60dp"
android:id="@+id/status_peertube_container"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<TextView
android:drawablePadding="2dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:textColor="?colorAccent"
android:visibility="gone"
android:text="@string/reply"
android:id="@+id/status_peertube_reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:drawablePadding="2dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:visibility="gone"
android:textColor="?colorAccent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="@string/delete"
android:id="@+id/status_peertube_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>/
<LinearLayout
android:layout_marginStart="60dp"
android:layout_marginLeft="60dp"

View File

@ -104,4 +104,10 @@
<!-- TOASTY -->
<color name="toasty_text">#2e2e2e</color>
<color name="toasty_background">#c8c8c8</color>
<color name="neutral_thumbs">#606984</color>
<color name="positive_thumbs">#2b90d9</color>
<color name="negative_thumbs">#F44336</color>
</resources>

View File

@ -793,6 +793,9 @@
<string name="recently_added">Recently added</string>
<string name="local">Local</string>
<string name="upload_video">Upload</string>
<string name="reply">Reply</string>
<string name="delete_comment">Delete a comment</string>
<string name="delete_comment_confirm">Are you sure to delete this comment?</string>
<!-- end languages -->
</resources>