Update notifications with post calls
This commit is contained in:
parent
ded7cdb51f
commit
c332923aa7
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class API {
|
|||
REBLOG,
|
||||
UNREBLOG,
|
||||
MUTE,
|
||||
MUTE_NOTIFICATIONS,
|
||||
UNMUTE,
|
||||
BLOCK,
|
||||
UNBLOCK,
|
||||
|
@ -731,6 +732,27 @@ 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("muting_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);
|
||||
}catch (Exception e) {
|
||||
setDefaultError();
|
||||
}
|
||||
return actionCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the post action
|
||||
|
|
|
@ -80,7 +80,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
|
||||
final AccountsListAdapter.ViewHolder holder = (AccountsListAdapter.ViewHolder) viewHolder;
|
||||
final Account account = accounts.get(position);
|
||||
|
||||
|
@ -114,10 +114,24 @@ 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){
|
||||
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_mute);
|
||||
doAction = API.StatusAction.UNMUTE;
|
||||
holder.account_follow.setVisibility(View.VISIBLE);
|
||||
holder.account_follow_request.setVisibility(View.GONE);
|
||||
|
||||
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, targetedId, account.isMuting_notifications(), AccountsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
accountsListAdapter.notifyItemChanged(position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -237,7 +251,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 +266,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);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
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>
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
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>
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue