Merge branch 'improve_muted' into develop

This commit is contained in:
stom79 2017-12-17 13:04:34 +01:00
commit bddb07e59a
9 changed files with 129 additions and 18 deletions

View File

@ -43,6 +43,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
private Account account;
private fr.gouv.etalab.mastodon.client.Entities.Status remoteStatus;
private WeakReference<Context> contextReference;
private boolean muteNotifications;
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface){
this.contextReference = new WeakReference<>(context);
@ -75,6 +76,13 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
this.comment = comment;
this.status = status;
}
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, boolean muteNotifications, OnPostActionInterface onPostActionInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
this.targetedId = targetedId;
this.muteNotifications = muteNotifications;
}
@Override
protected Void doInBackground(Void... params) {
@ -100,6 +108,8 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
statusCode = api.reportAction(status, comment);
else if (apiAction == API.StatusAction.CREATESTATUS)
statusCode = api.statusAction(status);
else if( apiAction == API.StatusAction.MUTE_NOTIFICATIONS)
statusCode = api.muteNotifications(targetedId, muteNotifications);
else
statusCode = api.postAction(apiAction, targetedId);
}

View File

@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.client;
import android.content.Context;
import android.content.SharedPreferences;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -62,6 +63,7 @@ public class API {
REBLOG,
UNREBLOG,
MUTE,
MUTE_NOTIFICATIONS,
UNMUTE,
BLOCK,
UNBLOCK,
@ -731,6 +733,29 @@ public class API {
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();
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 (Exception e) {
setDefaultError();
e.printStackTrace();
}
return actionCode;
}
/**
* Makes the post action
@ -1753,7 +1778,7 @@ public class API {
account.setNote(resobj.get("note").toString());
try{
account.setMoved_to_account(parseAccountResponse(context, resobj.getJSONObject("moved")));
}catch (Exception ignored){ignored.printStackTrace();}
}catch (Exception ignored){account.setMoved_to_account(null);}
account.setUrl(resobj.get("url").toString());
account.setAvatar(resobj.get("avatar").toString());
account.setAvatar_static(resobj.get("avatar_static").toString());
@ -1800,6 +1825,11 @@ public class API {
relationship.setFollowed_by(Boolean.valueOf(resobj.get("followed_by").toString()));
relationship.setBlocking(Boolean.valueOf(resobj.get("blocking").toString()));
relationship.setMuting(Boolean.valueOf(resobj.get("muting").toString()));
try {
relationship.setMuting_notifications(Boolean.valueOf(resobj.get("muting_notifications").toString()));
}catch (Exception ignored){
relationship.setMuting_notifications(true);
}
relationship.setRequested(Boolean.valueOf(resobj.get("requested").toString()));
} catch (JSONException e) {
setDefaultError();

View File

@ -61,7 +61,7 @@ public class Account implements Parcelable {
private followAction followType = followAction.NOTHING;
private boolean isMakingAction = false;
private Account moved_to_account;
private boolean muting_notifications;
public followAction getFollowType() {
return followType;
@ -87,6 +87,14 @@ public class Account implements Parcelable {
this.moved_to_account = moved_to_account;
}
public boolean isMuting_notifications() {
return muting_notifications;
}
public void setMuting_notifications(boolean muting_notifications) {
this.muting_notifications = muting_notifications;
}
public enum followAction{
FOLLOW,
NOT_FOLLOW,

View File

@ -27,6 +27,7 @@ public class Relationship {
private boolean blocking;
private boolean muting;
private boolean requested;
private boolean muting_notifications;
public String getId() {
return id;
@ -75,4 +76,12 @@ public class Relationship {
public void setRequested(boolean requested) {
this.requested = requested;
}
public boolean isMuting_notifications() {
return muting_notifications;
}
public void setMuting_notifications(boolean muting_notifications) {
this.muting_notifications = muting_notifications;
}
}

View File

@ -24,6 +24,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -114,10 +115,26 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
holder.account_follow.setVisibility(View.VISIBLE);
holder.account_follow_request.setVisibility(View.GONE);
}else if( account.getFollowType() == Account.followAction.MUTE){
holder.account_follow.setImageResource(R.drawable.ic_volume_mute);
if(account.isMuting_notifications())
holder.account_mute_notification.setImageResource(R.drawable.ic_notifications_active);
else
holder.account_mute_notification.setImageResource(R.drawable.ic_notifications_off);
holder.account_mute_notification.setVisibility(View.VISIBLE);
holder.account_follow.setImageResource(R.drawable.ic_volume_up);
doAction = API.StatusAction.UNMUTE;
holder.account_follow.setVisibility(View.VISIBLE);
holder.account_follow_request.setVisibility(View.GONE);
final int positionFinal = position;
holder.account_mute_notification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
account.setMuting_notifications(!account.isMuting_notifications());
new PostActionAsyncTask(context, API.StatusAction.MUTE_NOTIFICATIONS, account.getId(), account.isMuting_notifications(), AccountsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
accountsListAdapter.notifyItemChanged(positionFinal);
}
});
}
@ -237,7 +254,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
TextView account_sc;
TextView account_fgc;
TextView account_frc;
FloatingActionButton account_follow;
FloatingActionButton account_follow, account_mute_notification;
TextView account_follow_request;
LinearLayout account_container;
@ -252,6 +269,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
account_fgc = itemView.findViewById(R.id.account_fgc);
account_frc = itemView.findViewById(R.id.account_frc);
account_follow = itemView.findViewById(R.id.account_follow);
account_mute_notification = itemView.findViewById(R.id.account_mute_notification);
account_follow_request = itemView.findViewById(R.id.account_follow_request);
account_container = itemView.findViewById(R.id.account_container);
}

View File

@ -201,7 +201,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
if( type != RetrieveAccountsAsyncTask.Type.BLOCKED && type != RetrieveAccountsAsyncTask.Type.MUTED)
if( type != RetrieveAccountsAsyncTask.Type.BLOCKED )
new RetrieveManyRelationshipsAsyncTask(context, accounts,DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -225,15 +225,16 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
continue;
}
if( account.getId().equals(relationship.getId())){
account.setMuting_notifications(relationship.isMuting_notifications());
if( relationship.isFollowing())
account.setFollowType(Account.followAction.FOLLOW);
else
account.setFollowType(Account.followAction.NOT_FOLLOW);
if(relationship.isBlocking())
account.setFollowType(Account.followAction.BLOCK);
else if(relationship.isMuting())
else if(relationship.isMuting()) {
account.setFollowType(Account.followAction.MUTE);
else if(relationship.isRequested())
}else if(relationship.isRequested())
account.setFollowType(Account.followAction.REQUEST_SENT);
break;
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M7.58,4.08L6.15,2.65C3.75,4.48 2.17,7.3 2.03,10.5h2c0.15,-2.65 1.51,-4.97 3.55,-6.42zM19.97,10.5h2c-0.15,-3.2 -1.73,-6.02 -4.12,-7.85l-1.42,1.43c2.02,1.45 3.39,3.77 3.54,6.42zM18,11c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2v-5zM12,22c0.14,0 0.27,-0.01 0.4,-0.04 0.65,-0.14 1.18,-0.58 1.44,-1.18 0.1,-0.24 0.15,-0.5 0.15,-0.78h-4c0.01,1.1 0.9,2 2.01,2z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M20,18.69L7.84,6.14 5.27,3.49 4,4.76l2.8,2.8v0.01c-0.52,0.99 -0.8,2.16 -0.8,3.42v5l-2,2v1h13.73l2,2L21,19.72l-1,-1.03zM12,22c1.11,0 2,-0.89 2,-2h-4c0,1.11 0.89,2 2,2zM18,14.68L18,11c0,-3.08 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68c-0.15,0.03 -0.29,0.08 -0.42,0.12 -0.1,0.03 -0.2,0.07 -0.3,0.11h-0.01c-0.01,0 -0.01,0 -0.02,0.01 -0.23,0.09 -0.46,0.2 -0.68,0.31 0,0 -0.01,0 -0.01,0.01L18,14.68z"/>
</vector>

View File

@ -134,15 +134,32 @@
android:layout_gravity="center"
android:gravity="center"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/account_follow"
android:visibility="gone"
app:fabSize="mini"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:scaleType="fitXY"
android:layout_gravity="center"
android:gravity="center"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:id="@+id/account_follow"
android:visibility="gone"
app:fabSize="mini"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:scaleType="fitXY"
android:layout_gravity="center"
android:gravity="center"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/account_mute_notification"
android:visibility="gone"
app:fabSize="mini"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:scaleType="fitXY"
android:layout_gravity="center"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>