Warn when the account might not see the message in quick replies

This commit is contained in:
tom79 2019-06-28 16:24:33 +02:00
parent 7d832ace3b
commit 25f349e898
4 changed files with 137 additions and 3 deletions

View File

@ -0,0 +1,64 @@
/* Copyright 2019 Thomas Schneider
*
* This file is a part of Fedilab
*
* 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.
*
* Fedilab 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 Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
package app.fedilab.android.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.client.API;
import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.client.Entities.Relationship;
import app.fedilab.android.interfaces.OnRetrieveRelationshipQuickReplyInterface;
/**
* Created by Thomas on 29/06/2019.
* Retrieves relationship between the authenticated user and another account
*/
public class RetrieveRelationshipQuickReplyAsyncTask extends AsyncTask<Void, Void, Void> {
private app.fedilab.android.client.Entities.Status status;
private Relationship relationship;
private OnRetrieveRelationshipQuickReplyInterface listener;
private Error error;
private WeakReference<Context> contextReference;
public RetrieveRelationshipQuickReplyAsyncTask(Context context, app.fedilab.android.client.Entities.Status status, OnRetrieveRelationshipQuickReplyInterface onRetrieveRelationshipQuickReplyInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveRelationshipQuickReplyInterface;
this.status = status;
}
@Override
protected Void doInBackground(Void... params) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
API api = new API(this.contextReference.get());
relationship = api.getRelationship(status.getReblog()!=null?status.getReblog().getAccount().getId():status.getAccount().getId());
error = api.getError();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveRelationshipQuickReply(relationship, status, error);
}
}

View File

@ -140,6 +140,8 @@ public class Status implements Parcelable{
private boolean customFeaturesDisplayed = false;
private boolean shortReply = false;
private int warningFetched = -1;
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
@ -201,6 +203,7 @@ public class Status implements Parcelable{
dest.writeByte(this.autoHiddenCW ? (byte) 1 : (byte) 0);
dest.writeByte(this.customFeaturesDisplayed ? (byte) 1 : (byte) 0);
dest.writeByte(this.shortReply ? (byte) 1 : (byte) 0);
dest.writeInt(this.warningFetched);
}
protected Status(Parcel in) {
@ -265,6 +268,7 @@ public class Status implements Parcelable{
this.autoHiddenCW = in.readByte() != 0;
this.customFeaturesDisplayed = in.readByte() != 0;
this.shortReply = in.readByte() != 0;
this.warningFetched = in.readInt();
}
public static final Creator<Status> CREATOR = new Creator<Status>() {
@ -1421,4 +1425,12 @@ public class Status implements Parcelable{
public void setCustomFeaturesDisplayed(boolean customFeaturesDisplayed) {
this.customFeaturesDisplayed = customFeaturesDisplayed;
}
public int getWarningFetched() {
return warningFetched;
}
public void setWarningFetched(int warningFetched) {
this.warningFetched = warningFetched;
}
}

View File

@ -51,7 +51,6 @@ import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -108,6 +107,8 @@ import java.util.regex.Pattern;
import app.fedilab.android.activities.AccountReportActivity;
import app.fedilab.android.asynctasks.PostStatusAsyncTask;
import app.fedilab.android.asynctasks.RetrieveRelationshipAsyncTask;
import app.fedilab.android.asynctasks.RetrieveRelationshipQuickReplyAsyncTask;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.Account;
@ -120,6 +121,7 @@ import app.fedilab.android.client.Entities.ManageTimelines;
import app.fedilab.android.client.Entities.Notification;
import app.fedilab.android.client.Entities.Poll;
import app.fedilab.android.client.Entities.PollOptions;
import app.fedilab.android.client.Entities.Relationship;
import app.fedilab.android.client.Entities.Status;
import app.fedilab.android.client.Entities.TagTimeline;
import app.fedilab.android.helper.CrossActions;
@ -127,6 +129,8 @@ import app.fedilab.android.helper.CustomTextView;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastalabAutoCompleteTextView;
import app.fedilab.android.interfaces.OnPostStatusActionInterface;
import app.fedilab.android.interfaces.OnRetrieveRelationshipInterface;
import app.fedilab.android.interfaces.OnRetrieveRelationshipQuickReplyInterface;
import app.fedilab.android.interfaces.OnRetrieveSearcAccountshInterface;
import app.fedilab.android.interfaces.OnRetrieveSearchInterface;
import app.fedilab.android.jobs.ScheduledBoostsSyncJob;
@ -177,7 +181,7 @@ import static app.fedilab.android.helper.Helper.changeDrawableColor;
* Created by Thomas on 24/04/2017.
* Adapter for Status
*/
public class StatusListAdapter extends RecyclerView.Adapter implements OnPostActionInterface, OnRetrieveFeedsInterface, OnRetrieveEmojiInterface, OnRetrieveRepliesInterface, OnRetrieveCardInterface, OnPollInterface, OnRefreshCachedStatusInterface, OnRetrieveSearcAccountshInterface, OnRetrieveSearchInterface, OnPostStatusActionInterface {
public class StatusListAdapter extends RecyclerView.Adapter implements OnPostActionInterface, OnRetrieveFeedsInterface, OnRetrieveEmojiInterface, OnRetrieveRepliesInterface, OnRetrieveCardInterface, OnPollInterface, OnRefreshCachedStatusInterface, OnRetrieveSearcAccountshInterface, OnRetrieveSearchInterface, OnPostStatusActionInterface, OnRetrieveRelationshipQuickReplyInterface {
private Context context;
private List<Status> statuses;
@ -205,6 +209,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
private ArrayList<String> splitToot;
private int stepSpliToot;
private String in_reply_to_status;
private TextView warning_message;
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, List<Status> statuses){
super();
@ -491,6 +496,19 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
@Override
public void onRetrieveRelationshipQuickReply(Relationship relationship, Status status, Error error) {
if( error != null){
return;
}
if( relationship.isBlocked_by() ){
warning_message.setVisibility(View.VISIBLE);
status.setWarningFetched(1);
}else{
status.setWarningFetched(0);
}
}
private class ViewHolderEmpty extends RecyclerView.ViewHolder{
ViewHolderEmpty(View itemView) {
@ -608,7 +626,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
MastalabAutoCompleteTextView quick_reply_text;
ImageView quick_reply_switch_to_full;
TextView toot_space_left;
TextView toot_space_left, warning_message;
ImageView quick_reply_emoji;
Button quick_reply_button;
ImageView quick_reply_privacy;
@ -732,6 +750,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
quick_reply_button = itemView.findViewById(R.id.quick_reply_button);
quick_reply_privacy = itemView.findViewById(R.id.quick_reply_privacy);
warning_message = itemView.findViewById(R.id.warning_message);
}
}
@ -2479,6 +2499,16 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
@Override
public void onClick(View v) {
if (quick_reply) {
holder.warning_message.setVisibility(View.GONE);
if( status.getWarningFetched() == -1 ){
warning_message = holder.warning_message;
new RetrieveRelationshipQuickReplyAsyncTask(context, status,StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else if(status.getWarningFetched() == 1){
holder.warning_message.setVisibility(View.VISIBLE);
}
boolean shown = status.isShortReply();
if (!shown) {
for (Status s : statuses) {

View File

@ -0,0 +1,28 @@
/* Copyright 2019 Thomas Schneider
*
* This file is a part of Fedilab
*
* 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.
*
* Fedilab 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 Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
package app.fedilab.android.interfaces;
import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.client.Entities.Relationship;
import app.fedilab.android.client.Entities.Status;
/**
* Created by Thomas on 29/06/2019.
* Interface when relationship has been retrieved for an account
*/
public interface OnRetrieveRelationshipQuickReplyInterface {
void onRetrieveRelationshipQuickReply(Relationship relationship, Status status, Error error);
}