Merge branch 'feature/post-notifications-toggle' into fork

This commit is contained in:
sk 2022-11-09 23:28:59 +01:00
commit 965ebc8669
5 changed files with 64 additions and 25 deletions

View File

@ -98,8 +98,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
private CoverImageView cover;
private View avatarBorder;
private TextView name, username, bio, followersCount, followersLabel, followingCount, followingLabel, postsCount, postsLabel;
private ProgressBarButton actionButton;
private Button notifyButton;
private ProgressBarButton actionButton, notifyButton;
private ViewPager2 pager;
private NestedRecyclerScrollView scrollView;
private AccountTimelineFragment postsFragment, postsWithRepliesFragment, pinnedPostsFragment, mediaFragment;
@ -110,7 +109,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
private float titleTransY;
private View postsBtn, followersBtn, followingBtn;
private EditText nameEdit, bioEdit;
private ProgressBar actionProgress;
private ProgressBar actionProgress, notifyProgress;
private FrameLayout[] tabViews;
private TabLayoutMediator tabLayoutMediator;
private TextView followsYouView;
@ -190,6 +189,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
nameEdit=content.findViewById(R.id.name_edit);
bioEdit=content.findViewById(R.id.bio_edit);
actionProgress=content.findViewById(R.id.action_progress);
notifyProgress=content.findViewById(R.id.notify_progress);
fab=content.findViewById(R.id.fab);
followsYouView=content.findViewById(R.id.follows_you);
@ -461,9 +461,9 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
UiUtils.loadCustomEmojiInTextView(name);
UiUtils.loadCustomEmojiInTextView(bio);
notifyButton.setVisibility(View.GONE);
if(AccountSessionManager.getInstance().isSelf(accountID, account)){
actionButton.setText(R.string.edit_profile);
notifyButton.setVisibility(View.GONE);
}else{
actionButton.setVisibility(View.GONE);
}
@ -626,11 +626,14 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
private void updateRelationship(){
invalidateOptionsMenu();
actionButton.setVisibility(View.VISIBLE);
UiUtils.setRelationshipToActionButton(relationship, actionButton);
actionProgress.setIndeterminateTintList(actionButton.getTextColors());
followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE);
notifyButton.setVisibility(relationship.following ? View.VISIBLE : View.GONE);
UiUtils.setRelationshipToActionButton(relationship, actionButton);
UiUtils.setRelationshipToActionButton(relationship, notifyButton, true);
actionProgress.setIndeterminateTintList(actionButton.getTextColors());
notifyProgress.setIndeterminateTintList(notifyButton.getTextColors());
followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE);
notifyButton.setSelected(relationship.notifying);
notifyButton.setContentDescription(getString(relationship.notifying ? R.string.user_post_notifications_on : R.string.user_post_notifications_off, '@'+account.username));
}
private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){
@ -697,6 +700,12 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
actionButton.setClickable(!visible);
}
private void setNotifyProgressVisible(boolean visible){
notifyButton.setTextVisible(!visible);
notifyProgress.setVisibility(visible ? View.VISIBLE : View.GONE);
notifyButton.setClickable(!visible);
}
private void loadAccountInfoAndEnterEditMode(){
if(editModeLoading)
return;
@ -866,7 +875,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
}
private void onNotifyButtonClick(View v) {
UiUtils.performToggleAccountNotifications(getActivity(), account, accountID, relationship, actionButton, this::updateRelationship);
UiUtils.performToggleAccountNotifications(getActivity(), account, accountID, relationship, actionButton, this::setNotifyProgressVisible, this::updateRelationship);
}
private void onAvatarClick(View v){

View File

@ -498,6 +498,11 @@ public class UiUtils{
}
public static void setRelationshipToActionButton(Relationship relationship, Button button){
setRelationshipToActionButton(relationship, button, false);
}
public static void setRelationshipToActionButton(Relationship relationship, Button button, boolean keepText){
CharSequence textBefore = keepText ? button.getText() : null;
boolean secondaryStyle;
if(relationship.blocking){
button.setText(R.string.button_blocked);
@ -516,6 +521,8 @@ public class UiUtils{
secondaryStyle=true;
}
if (keepText) button.setText(textBefore);
button.setEnabled(!relationship.blockedBy);
int attr=secondaryStyle ? R.attr.secondaryButtonStyle : android.R.attr.buttonStyle;
TypedArray ta=button.getContext().obtainStyledAttributes(new int[]{attr});
@ -532,17 +539,20 @@ public class UiUtils{
ta.recycle();
}
public static void performToggleAccountNotifications(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer<Relationship> resultCallback) {
public static void performToggleAccountNotifications(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer<Boolean> progressCallback, Consumer<Relationship> resultCallback) {
progressCallback.accept(true);
new SetAccountFollowed(account.id, true, relationship.showingReblogs, !relationship.notifying)
.setCallback(new Callback<>() {
@Override
public void onSuccess(Relationship result) {
resultCallback.accept(result);
progressCallback.accept(false);
Toast.makeText(activity, activity.getString(result.notifying ? R.string.user_post_notifications_on : R.string.user_post_notifications_off, '@'+account.username), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(ErrorResponse error) {
progressCallback.accept(false);
error.showToast(activity);
}
}).exec(accountID);

View File

@ -171,20 +171,40 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/profile_counters"
android:layout_alignParentEnd="true"
android:clipToPadding="false"
android:padding="16dp">
<Button
android:id="@+id/notify_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:paddingHorizontal="8dp"
android:drawableStart="@drawable/ic_fluent_alert_24_selector"
style="@style/Widget.Mastodon.Button.Secondary_LightOnDark" />
android:layout_alignParentEnd="true">
<FrameLayout
android:clipToPadding="false"
android:paddingVertical="16dp"
android:paddingLeft="16dp"
android:paddingRight="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<org.joinmastodon.android.ui.views.ProgressBarButton
android:id="@+id/notify_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="8dp"
android:drawableStart="@drawable/ic_fluent_alert_24_selector" />
<ProgressBar
android:id="@+id/notify_progress"
style="?android:progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="10dp"
android:indeterminate="true"
android:indeterminateTint="?colorButtonText"
android:outlineProvider="none"
android:visibility="gone" />
</FrameLayout>
<FrameLayout
android:clipToPadding="false"
android:paddingVertical="16dp"
android:paddingRight="16dp"
android:paddingLeft="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<org.joinmastodon.android.ui.views.ProgressBarButton

View File

@ -304,8 +304,8 @@
<string name="open_in_browser">Beitrag im Browser öffnen</string>
<string name="hide_boosts_from_user">Verberge geteilte Beiträge von %s</string>
<string name="show_boosts_from_user">Zeige geteilte Beiträge von %s</string>
<string name="user_post_notifications_on">Benachrichtigungen über neue Beiträge von %s aktiviert</string>
<string name="user_post_notifications_off">Benachrichtigungen über neue Beiträge von %s deaktiviert</string>
<string name="user_post_notifications_on">Benachrichtigungen über Beiträge von %s aktiviert</string>
<string name="user_post_notifications_off">Benachrichtigungen über Beiträge von %s deaktiviert</string>
<string name="signup_reason">Weshalb möchtest du beitreten?</string>
<string name="signup_reason_note">Dies wird uns dabei helfen, deine Anmeldungsanfrage besser zu verarbeiten.</string>
<string name="clear">Löschen</string>

View File

@ -310,8 +310,8 @@
<string name="open_in_browser">Open in browser</string>
<string name="hide_boosts_from_user">Hide reblogs from %s</string>
<string name="show_boosts_from_user">Show reblogs from %s</string>
<string name="user_post_notifications_on">Notifying about posts by %s</string>
<string name="user_post_notifications_off">No longer notifying about posts by %s</string>
<string name="user_post_notifications_on">Turned on post notifications for %s</string>
<string name="user_post_notifications_off">Turned off post notifications for %s</string>
<string name="signup_reason">why do you want to join?</string>
<string name="signup_reason_note">This will help us review your application.</string>
<string name="clear">Clear</string>