More account interactions
This commit is contained in:
parent
9232428232
commit
0b983affcb
|
@ -0,0 +1,11 @@
|
|||
package org.joinmastodon.android.api.requests.accounts;
|
||||
|
||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||
import org.joinmastodon.android.model.Relationship;
|
||||
|
||||
public class SetAccountBlocked extends MastodonAPIRequest<Relationship>{
|
||||
public SetAccountBlocked(String id, boolean blocked){
|
||||
super(HttpMethod.POST, "/accounts/"+id+"/"+(blocked ? "block" : "unblock"), Relationship.class);
|
||||
setRequestBody(new Object());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.joinmastodon.android.api.requests.accounts;
|
||||
|
||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||
import org.joinmastodon.android.model.Relationship;
|
||||
|
||||
public class SetAccountMuted extends MastodonAPIRequest<Relationship>{
|
||||
public SetAccountMuted(String id, boolean muted){
|
||||
super(HttpMethod.POST, "/accounts/"+id+"/"+(muted ? "mute" : "unmute"), Relationship.class);
|
||||
setRequestBody(new Object());
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import android.animation.AnimatorListenerAdapter;
|
|||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -36,12 +37,15 @@ import org.joinmastodon.android.R;
|
|||
import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships;
|
||||
import org.joinmastodon.android.api.requests.accounts.GetAccountStatuses;
|
||||
import org.joinmastodon.android.api.requests.accounts.GetOwnAccount;
|
||||
import org.joinmastodon.android.api.requests.accounts.SetAccountBlocked;
|
||||
import org.joinmastodon.android.api.requests.accounts.SetAccountFollowed;
|
||||
import org.joinmastodon.android.api.requests.accounts.SetAccountMuted;
|
||||
import org.joinmastodon.android.api.requests.accounts.UpdateAccountCredentials;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.model.AccountField;
|
||||
import org.joinmastodon.android.model.Relationship;
|
||||
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
|
||||
import org.joinmastodon.android.ui.drawables.CoverOverlayGradientDrawable;
|
||||
import org.joinmastodon.android.ui.tabs.TabLayout;
|
||||
import org.joinmastodon.android.ui.tabs.TabLayoutMediator;
|
||||
|
@ -364,10 +368,10 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
menu.findItem(R.id.mute).setTitle(getString(relationship.muting ? R.string.unmute_user : R.string.mute_user, account.displayName));
|
||||
menu.findItem(R.id.block).setTitle(getString(relationship.blocking ? R.string.unblock_user : R.string.block_user, account.displayName));
|
||||
menu.findItem(R.id.report).setTitle(getString(R.string.report_user, account.displayName));
|
||||
String domain=account.getDomain();
|
||||
if(domain!=null)
|
||||
menu.findItem(R.id.block_domain).setTitle(getString(relationship.domainBlocking ? R.string.unblock_domain : R.string.block_domain, domain));
|
||||
else
|
||||
// String domain=account.getDomain();
|
||||
// if(domain!=null)
|
||||
// menu.findItem(R.id.block_domain).setTitle(getString(relationship.domainBlocking ? R.string.unblock_domain : R.string.block_domain, domain));
|
||||
// else
|
||||
menu.findItem(R.id.block_domain).setVisible(false);
|
||||
}
|
||||
|
||||
|
@ -379,6 +383,10 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, account.url);
|
||||
startActivity(Intent.createChooser(intent, item.getTitle()));
|
||||
}else if(id==R.id.mute){
|
||||
confirmToggleMuted();
|
||||
}else if(id==R.id.block){
|
||||
confirmToggleBlocked();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -408,7 +416,13 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
private void updateRelationship(){
|
||||
invalidateOptionsMenu();
|
||||
actionButton.setVisibility(View.VISIBLE);
|
||||
actionButton.setText(relationship.following ? R.string.button_following : R.string.button_follow);
|
||||
if(relationship.blocking){
|
||||
actionButton.setText(R.string.button_blocked);
|
||||
}else if(relationship.muting){
|
||||
actionButton.setText(R.string.button_muted);
|
||||
}else{
|
||||
actionButton.setText(relationship.following ? R.string.button_following : R.string.button_follow);
|
||||
}
|
||||
}
|
||||
|
||||
private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){
|
||||
|
@ -463,7 +477,13 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
else
|
||||
saveAndExitEditMode();
|
||||
}else{
|
||||
toggleFollowing();
|
||||
if(relationship.blocking){
|
||||
confirmToggleBlocked();
|
||||
}else if(relationship.muting){
|
||||
confirmToggleMuted();
|
||||
}else{
|
||||
toggleFollowing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -620,6 +640,60 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
.exec(accountID);
|
||||
}
|
||||
|
||||
private void confirmToggleMuted(){
|
||||
new M3AlertDialogBuilder(getActivity())
|
||||
.setTitle(relationship.muting ? R.string.confirm_unmute_title : R.string.confirm_mute_title)
|
||||
.setMessage(getString(relationship.muting ? R.string.confirm_unmute : R.string.confirm_mute, account.displayName))
|
||||
.setPositiveButton(relationship.muting ? R.string.do_unmute : R.string.do_mute, (dlg, i)->toggleMuted())
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void confirmToggleBlocked(){
|
||||
new M3AlertDialogBuilder(getActivity())
|
||||
.setTitle(relationship.blocking ? R.string.confirm_unblock_title : R.string.confirm_block_title)
|
||||
.setMessage(getString(relationship.blocking ? R.string.confirm_unblock : R.string.confirm_block, account.displayName))
|
||||
.setPositiveButton(relationship.blocking ? R.string.do_block : R.string.do_unblock, (dlg, i)->toggleBlocked())
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void toggleMuted(){
|
||||
new SetAccountMuted(account.id, !relationship.muting)
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(Relationship result){
|
||||
relationship=result;
|
||||
updateRelationship();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
error.showToast(getActivity());
|
||||
}
|
||||
})
|
||||
.wrapProgress(getActivity(), R.string.loading, false)
|
||||
.exec(accountID);
|
||||
}
|
||||
|
||||
private void toggleBlocked(){
|
||||
new SetAccountBlocked(account.id, !relationship.blocking)
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(Relationship result){
|
||||
relationship=result;
|
||||
updateRelationship();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
error.showToast(getActivity());
|
||||
}
|
||||
})
|
||||
.wrapProgress(getActivity(), R.string.loading, false)
|
||||
.exec(accountID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed(){
|
||||
if(isInEditMode){
|
||||
|
|
|
@ -23,9 +23,39 @@ public class M3AlertDialogBuilder extends AlertDialog.Builder{
|
|||
Button btn=alert.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
if(btn!=null){
|
||||
View buttonBar=(View) btn.getParent();
|
||||
buttonBar.setPadding(V.dp(16), V.dp(24), V.dp(16), V.dp(24));
|
||||
buttonBar.setPadding(V.dp(16), 0, V.dp(16), V.dp(24));
|
||||
((View)buttonBar.getParent()).setPadding(0, 0, 0, 0);
|
||||
}
|
||||
// hacc
|
||||
int titleID=getContext().getResources().getIdentifier("title_template", "id", "android");
|
||||
if(titleID!=0){
|
||||
View title=alert.findViewById(titleID);
|
||||
if(title!=null){
|
||||
int pad=V.dp(24);
|
||||
title.setPadding(pad, pad, pad, pad);
|
||||
}
|
||||
}
|
||||
int titleDividerID=getContext().getResources().getIdentifier("titleDividerNoCustom", "id", "android");
|
||||
if(titleDividerID!=0){
|
||||
View divider=alert.findViewById(titleDividerID);
|
||||
if(divider!=null){
|
||||
divider.getLayoutParams().height=0;
|
||||
}
|
||||
}
|
||||
int scrollViewID=getContext().getResources().getIdentifier("scrollView", "id", "android");
|
||||
if(scrollViewID!=0){
|
||||
View scrollView=alert.findViewById(scrollViewID);
|
||||
if(scrollView!=null){
|
||||
scrollView.setPadding(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
int messageID=getContext().getResources().getIdentifier("message", "id", "android");
|
||||
if(messageID!=0){
|
||||
View message=alert.findViewById(messageID);
|
||||
if(message!=null){
|
||||
message.setPadding(message.getPaddingLeft(), message.getPaddingTop(), message.getPaddingRight(), V.dp(24));
|
||||
}
|
||||
}
|
||||
return alert;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,4 +108,18 @@
|
|||
<item quantity="other">%,d voters</item>
|
||||
</plurals>
|
||||
<string name="poll_closed">Closed</string>
|
||||
<string name="confirm_mute_title">Mute Account</string>
|
||||
<string name="confirm_mute">Confirm to mute %s</string>
|
||||
<string name="do_mute">Mute</string>
|
||||
<string name="confirm_unmute_title">Unmute Account</string>
|
||||
<string name="confirm_unmute">Confirm to unmute %s</string>
|
||||
<string name="do_unmute">Unmute</string>
|
||||
<string name="confirm_block_title">Block Account</string>
|
||||
<string name="confirm_block">Confirm to block %s</string>
|
||||
<string name="do_block">Block</string>
|
||||
<string name="confirm_unblock_title">Unblock Account</string>
|
||||
<string name="confirm_unblock">Confirm to unblock %s</string>
|
||||
<string name="do_unblock">Unblock</string>
|
||||
<string name="button_muted">Muted</string>
|
||||
<string name="button_blocked">Blocked</string>
|
||||
</resources>
|
Loading…
Reference in New Issue