Skip to content

Commit

Permalink
feat(notification-filters): add new settings entry for notification f…
Browse files Browse the repository at this point in the history
…ilters. No logic implemented just yet
  • Loading branch information
LucasGGamerM committed Oct 1, 2023
1 parent 9e27e21 commit 8adb1d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.joinmastodon.android.model.ContentType;
import org.joinmastodon.android.model.Emoji;
import org.joinmastodon.android.model.PushSubscription;
import org.joinmastodon.android.model.TimelineDefinition;

import java.lang.reflect.Type;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class AccountLocalPreferences{
// MOSHIDON
private final static Type recentEmojisType = new TypeToken<Map<String, Integer>>() {}.getType();
public Map<String, Integer> recentEmojis;
private final static Type notificationFiltersType = new TypeToken<PushSubscription.Alerts>() {}.getType();
public PushSubscription.Alerts notificationFilters;

public AccountLocalPreferences(SharedPreferences prefs, AccountSession session){
this.prefs=prefs;
Expand Down Expand Up @@ -77,6 +80,7 @@ public AccountLocalPreferences(SharedPreferences prefs, AccountSession session){

// MOSHIDON
recentEmojis=fromJson(prefs.getString("recentEmojis", "{}"), recentEmojisType, new HashMap<>());
notificationFilters=fromJson(prefs.getString("notificationFilters", gson.toJson(PushSubscription.Alerts.ofAll())), notificationFiltersType, PushSubscription.Alerts.ofAll());
}

public long getNotificationsPauseEndTime(){
Expand Down Expand Up @@ -113,6 +117,7 @@ public void save(){

// MOSHIDON
.putString("recentEmojis", gson.toJson(recentEmojis))
.putString("notificationFilters", gson.toJson(notificationFilters))
.apply();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.FragmentRootLinearLayout;

public class NotificationsFragment extends MastodonToolbarFragment implements ScrollableToTop, ProvidesAssistContent, HasElevationOnScrollListener {
public class NotificationsFragment extends MastodonToolbarFragment implements ScrollableToTop, ProvidesAssistContent, HasElevationOnScrollListener, HasAccountID {

TabLayout tabLayout;
private ViewPager2 pager;
Expand Down Expand Up @@ -140,34 +140,43 @@ public boolean onOptionsItemSelected(MenuItem item) {
ctx.getString(R.string.notification_type_mentions_and_replies),
ctx.getString(R.string.notification_type_reblog),
ctx.getString(R.string.notification_type_favorite),
ctx.getString(R.string.notification_type_favorite),
ctx.getString(R.string.notification_type_follow),
ctx.getString(R.string.notification_type_poll),
ctx.getString(R.string.sk_notification_type_update),
ctx.getString(R.string.sk_notification_type_posts)
};

final boolean[] checkedItems = new boolean[listItems.length];

final List<String> selectedItems = Arrays.asList(listItems);
boolean[] checkedItems = {
getLocalPrefs().notificationFilters.mention,
getLocalPrefs().notificationFilters.reblog,
getLocalPrefs().notificationFilters.favourite,
getLocalPrefs().notificationFilters.follow,
getLocalPrefs().notificationFilters.poll,
getLocalPrefs().notificationFilters.update,
getLocalPrefs().notificationFilters.status,
};

M3AlertDialogBuilder dialogBuilder = new M3AlertDialogBuilder(ctx);
dialogBuilder.setTitle(R.string.sk_settings_filters);
dialogBuilder.setMultiChoiceItems(listItems, checkedItems, (dialog, which, isChecked) -> {
checkedItems[which] = isChecked;
String currentItem = selectedItems.get(which);
});

dialogBuilder.setPositiveButton(R.string.save, (d, which) -> {
// lp.publishButtonText=input.getEditText().getText().toString().trim();
// lp.save();
// publishTextItem.subtitle=getPublishButtonText();
// rebindItem(publishTextItem);
getLocalPrefs().notificationFilters.mention=checkedItems[0];
getLocalPrefs().notificationFilters.reblog=checkedItems[1];
getLocalPrefs().notificationFilters.favourite=checkedItems[2];
getLocalPrefs().notificationFilters.follow=checkedItems[3];
getLocalPrefs().notificationFilters.poll=checkedItems[4];
getLocalPrefs().notificationFilters.update=checkedItems[5];
getLocalPrefs().notificationFilters.status=checkedItems[6];
getLocalPrefs().save();

this.allNotificationsFragment.reload();
}).setNeutralButton(R.string.clear, (d, which) -> {
// lp.publishButtonText=null;
// lp.save();
// publishTextItem.subtitle=getPublishButtonText();
// rebindItem(publishTextItem);
Arrays.fill(checkedItems, true);

this.allNotificationsFragment.reload();
}).setNegativeButton(R.string.cancel, (d, which) -> {});

dialogBuilder.create().show();
Expand Down Expand Up @@ -366,6 +375,11 @@ public void onProvideAssistContent(AssistContent assistContent) {
callFragmentToProvideAssistContent(getFragmentForPage(pager.getCurrentItem()), assistContent);
}

@Override
public String getAccountID(){
return accountID;
}

private class DiscoverPagerAdapter extends RecyclerView.Adapter<SimpleViewHolder>{
@NonNull
@Override
Expand Down

0 comments on commit 8adb1d5

Please sign in to comment.