Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit b166ca7

Browse files
committed
Implement post notifications button
1 parent ae50e61 commit b166ca7

File tree

11 files changed

+83
-25
lines changed

11 files changed

+83
-25
lines changed

mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountFollowed.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import org.joinmastodon.android.model.Relationship;
55

66
public class SetAccountFollowed extends MastodonAPIRequest<Relationship>{
7-
public SetAccountFollowed(String id, boolean followed, boolean showReblogs){
7+
public SetAccountFollowed(String id, boolean followed, boolean showReblogs, boolean notify){
88
super(HttpMethod.POST, "/accounts/"+id+"/"+(followed ? "follow" : "unfollow"), Relationship.class);
99
if(followed)
10-
setRequestBody(new Request(showReblogs, null));
10+
setRequestBody(new Request(showReblogs, notify));
1111
else
1212
setRequestBody(new Object());
1313
}

mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
9999
private View avatarBorder;
100100
private TextView name, username, bio, followersCount, followersLabel, followingCount, followingLabel, postsCount, postsLabel;
101101
private ProgressBarButton actionButton;
102+
private Button notifyButton;
102103
private ViewPager2 pager;
103104
private NestedRecyclerScrollView scrollView;
104105
private AccountTimelineFragment postsFragment, postsWithRepliesFragment, mediaFragment;
@@ -181,6 +182,7 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu
181182
postsLabel=content.findViewById(R.id.posts_label);
182183
postsBtn=content.findViewById(R.id.posts_btn);
183184
actionButton=content.findViewById(R.id.profile_action_btn);
185+
notifyButton=content.findViewById(R.id.notify_btn);
184186
pager=content.findViewById(R.id.pager);
185187
scrollView=content.findViewById(R.id.scroller);
186188
tabbar=content.findViewById(R.id.tabbar);
@@ -256,6 +258,7 @@ public void getOutline(View view, Outline outline){
256258
});
257259

258260
actionButton.setOnClickListener(this::onActionButtonClick);
261+
notifyButton.setOnClickListener(this::onNotifyButtonClick);
259262
avatar.setOnClickListener(this::onAvatarClick);
260263
cover.setOnClickListener(this::onCoverClick);
261264
refreshLayout.setOnRefreshListener(this);
@@ -454,6 +457,7 @@ private void bindHeaderView(){
454457

455458
if(AccountSessionManager.getInstance().isSelf(accountID, account)){
456459
actionButton.setText(R.string.edit_profile);
460+
notifyButton.setVisibility(View.GONE);
457461
}else{
458462
actionButton.setVisibility(View.GONE);
459463
}
@@ -566,7 +570,7 @@ public boolean onOptionsItemSelected(MenuItem item){
566570
updateRelationship();
567571
});
568572
}else if(id==R.id.hide_boosts){
569-
new SetAccountFollowed(account.id, true, !relationship.showingReblogs)
573+
new SetAccountFollowed(account.id, true, !relationship.showingReblogs, relationship.notifying)
570574
.setCallback(new Callback<>(){
571575
@Override
572576
public void onSuccess(Relationship result){
@@ -614,6 +618,8 @@ private void updateRelationship(){
614618
UiUtils.setRelationshipToActionButton(relationship, actionButton);
615619
actionProgress.setIndeterminateTintList(actionButton.getTextColors());
616620
followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE);
621+
notifyButton.setVisibility(relationship.following ? View.VISIBLE : View.GONE);
622+
notifyButton.setSelected(relationship.notifying);
617623
}
618624

619625
private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){
@@ -847,6 +853,10 @@ private List<Attachment> createFakeAttachments(String url, Drawable drawable){
847853
return Collections.singletonList(att);
848854
}
849855

856+
private void onNotifyButtonClick(View v) {
857+
UiUtils.performToggleAccountNotifications(getActivity(), account, accountID, relationship, actionButton, this::updateRelationship);
858+
}
859+
850860
private void onAvatarClick(View v){
851861
if(isInEditMode){
852862
startImagePicker(AVATAR_RESULT);

mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private boolean onContextMenuItemSelected(MenuItem item){
353353
bindRelationship();
354354
});
355355
}else if(id==R.id.hide_boosts){
356-
new SetAccountFollowed(account.id, true, !relationship.showingReblogs)
356+
new SetAccountFollowed(account.id, true, !relationship.showingReblogs, relationship.notifying)
357357
.setCallback(new Callback<>(){
358358
@Override
359359
public void onSuccess(Relationship result){

mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void onButtonClick(View v){
125125
}
126126

127127
private void onUnfollowClick(){
128-
new SetAccountFollowed(reportAccount.id, false, false)
128+
new SetAccountFollowed(reportAccount.id, false, false, false)
129129
.setCallback(new Callback<>(){
130130
@Override
131131
public void onSuccess(Relationship result){

mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import android.database.Cursor;
1212
import android.graphics.Bitmap;
1313
import android.graphics.Canvas;
14-
import android.graphics.Typeface;
1514
import android.graphics.drawable.BitmapDrawable;
1615
import android.graphics.drawable.Drawable;
1716
import android.graphics.drawable.InsetDrawable;
@@ -435,14 +434,30 @@ public static void setRelationshipToActionButton(Relationship relationship, Butt
435434
ta.recycle();
436435
}
437436

437+
public static void performToggleAccountNotifications(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer<Relationship> resultCallback) {
438+
new SetAccountFollowed(account.id, true, relationship.showingReblogs, !relationship.notifying)
439+
.setCallback(new Callback<>() {
440+
@Override
441+
public void onSuccess(Relationship result) {
442+
resultCallback.accept(result);
443+
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();
444+
}
445+
446+
@Override
447+
public void onError(ErrorResponse error) {
448+
error.showToast(activity);
449+
}
450+
}).exec(accountID);
451+
}
452+
438453
public static void performAccountAction(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer<Boolean> progressCallback, Consumer<Relationship> resultCallback){
439454
if(relationship.blocking){
440455
confirmToggleBlockUser(activity, accountID, account, true, resultCallback);
441456
}else if(relationship.muting){
442457
confirmToggleMuteUser(activity, accountID, account, true, resultCallback);
443458
}else{
444459
progressCallback.accept(true);
445-
new SetAccountFollowed(account.id, !relationship.following && !relationship.requested, true)
460+
new SetAccountFollowed(account.id, !relationship.following && !relationship.requested, true, false)
446461
.setCallback(new Callback<>(){
447462
@Override
448463
public void onSuccess(Relationship result){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:pathData="M9.042 19.003h5.916c-0.238 1.418-1.472 2.498-2.958 2.498-1.486 0-2.72-1.08-2.958-2.498zm2.958-17c4.142 0 7.5 3.359 7.5 7.5v4l1.418 3.16c0.055 0.122 0.084 0.254 0.084 0.389 0 0.524-0.426 0.95-0.95 0.95h-16.1c-0.134 0-0.266-0.029-0.388-0.083-0.479-0.215-0.693-0.777-0.479-1.256l1.415-3.16V9.49l0.005-0.25C4.644 5.211 7.955 2.004 12 2.004z" android:fillColor="@color/fluent_default_icon_tint"/>
3+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:pathData="M12 1.996c4.05 0 7.357 3.195 7.496 7.25l0.004 0.25v4.097l1.38 3.156c0.07 0.158 0.105 0.329 0.105 0.5 0 0.691-0.56 1.25-1.25 1.25L15 18.502c0 1.657-1.343 3-3 3-1.598 0-2.904-1.249-2.995-2.823L9 18.499H4.275c-0.171 0-0.34-0.034-0.498-0.103-0.633-0.275-0.924-1.01-0.649-1.644L4.5 13.594V9.496c0-4.155 3.352-7.5 7.5-7.5zM13.5 18.5l-3 0.002c0 0.829 0.672 1.5 1.5 1.5 0.78 0 1.42-0.595 1.493-1.355L13.5 18.5zM12 3.496c-3.32 0-6 2.674-6 6v4.41L4.656 17h14.697L18 13.907V9.509l-0.003-0.225C17.885 6.05 15.242 3.496 12 3.496z" android:fillColor="@color/fluent_default_icon_tint"/>
3+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--~ Copyright (c) 2022. ~ Microsoft Corporation. All rights reserved.-->
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="@drawable/ic_fluent_alert_24_filled" android:state_activated="true"/>
5+
<item android:drawable="@drawable/ic_fluent_alert_24_filled" android:state_checked="true"/>
6+
<item android:drawable="@drawable/ic_fluent_alert_24_filled" android:state_selected="true"/>
7+
<item android:drawable="@drawable/ic_fluent_alert_24_regular"/>
8+
</selector>

mastodon/src/main/res/layout/fragment_profile.xml

+33-18
Original file line numberDiff line numberDiff line change
@@ -166,31 +166,46 @@
166166
</LinearLayout>
167167
</LinearLayout>
168168

169-
<FrameLayout
169+
<LinearLayout
170170
android:id="@+id/profile_action_btn_wrap"
171171
android:layout_width="wrap_content"
172172
android:layout_height="wrap_content"
173-
android:layout_alignParentEnd="true"
174173
android:layout_below="@id/profile_counters"
175-
android:padding="16dp"
176-
android:clipToPadding="false">
177-
<org.joinmastodon.android.ui.views.ProgressBarButton
178-
android:id="@+id/profile_action_btn"
174+
android:layout_alignParentEnd="true"
175+
android:clipToPadding="false"
176+
android:padding="16dp">
177+
178+
<Button
179+
android:id="@+id/notify_btn"
179180
android:layout_width="wrap_content"
180181
android:layout_height="wrap_content"
181-
tools:text="Edit Profile"/>
182-
<ProgressBar
183-
android:id="@+id/action_progress"
182+
android:layout_marginRight="8dp"
183+
android:paddingHorizontal="8dp"
184+
android:drawableStart="@drawable/ic_fluent_alert_24_selector"
185+
style="@style/Widget.Mastodon.Button.Secondary_LightOnDark" />
186+
187+
<FrameLayout
184188
android:layout_width="wrap_content"
185-
android:layout_height="wrap_content"
186-
android:layout_gravity="center"
187-
android:indeterminate="true"
188-
style="?android:progressBarStyleSmall"
189-
android:elevation="10dp"
190-
android:outlineProvider="none"
191-
android:indeterminateTint="?colorButtonText"
192-
android:visibility="gone"/>
193-
</FrameLayout>
189+
android:layout_height="wrap_content">
190+
<org.joinmastodon.android.ui.views.ProgressBarButton
191+
android:id="@+id/profile_action_btn"
192+
android:layout_width="wrap_content"
193+
android:layout_height="wrap_content"
194+
tools:text="Edit Profile" />
195+
196+
<ProgressBar
197+
android:id="@+id/action_progress"
198+
style="?android:progressBarStyleSmall"
199+
android:layout_width="wrap_content"
200+
android:layout_height="wrap_content"
201+
android:layout_gravity="center"
202+
android:elevation="10dp"
203+
android:indeterminate="true"
204+
android:indeterminateTint="?colorButtonText"
205+
android:outlineProvider="none"
206+
android:visibility="gone" />
207+
</FrameLayout>
208+
</LinearLayout>
194209

195210
<TextView
196211
android:id="@+id/name"

mastodon/src/main/res/values-de-rDE/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@
284284
<string name="open_in_browser">Beitrag im Browser öffnen</string>
285285
<string name="hide_boosts_from_user">Verberge geteilte Beiträge von %s</string>
286286
<string name="show_boosts_from_user">Zeige geteilte Beiträge von %s</string>
287+
<string name="user_post_notifications_on">Benachrichtigungen über neue Beiträge von %s aktiviert</string>
288+
<string name="user_post_notifications_off">Benachrichtigungen über neue Beiträge von %s deaktiviert</string>
287289
<string name="signup_reason">Weshalb möchtest du beitreten?</string>
288290
<string name="signup_reason_note">Dies wird uns dabei helfen, deine Anmeldungsanfrage besser zu verarbeiten.</string>
289291
<string name="clear">Löschen</string>

mastodon/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@
290290
<string name="open_in_browser">Open in browser</string>
291291
<string name="hide_boosts_from_user">Hide reblogs from %s</string>
292292
<string name="show_boosts_from_user">Show reblogs from %s</string>
293+
<string name="user_post_notifications_on">Notifying about posts by %s</string>
294+
<string name="user_post_notifications_off">No longer notifying about posts by %s</string>
293295
<string name="signup_reason">why do you want to join?</string>
294296
<string name="signup_reason_note">This will help us review your application.</string>
295297
<string name="clear">Clear</string>

0 commit comments

Comments
 (0)