Commit d4aee3ff authored by Thomas's avatar Thomas
Browse files

Notifications not deleted from cache

parent ee68f4fc
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -415,14 +415,14 @@ public class StatusCache {
     * @return long - db id
     * @throws DBException exception with database
     */
    public long deleteNotifications() throws DBException {
    public long deleteNotifications(String user_id, String instance) throws DBException {
        if (db == null) {
            throw new DBException("db is null. Wrong initialization.");
        }
        try {
            return db.delete(Sqlite.TABLE_STATUS_CACHE,
                    Sqlite.COL_USER_ID + " =  ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_TYPE + "=?",
                    new String[]{MainActivity.currentUserID, MainActivity.currentInstance, Timeline.TimeLineEnum.NOTIFICATION.getValue()});
                    new String[]{user_id, instance, Timeline.TimeLineEnum.NOTIFICATION.getValue()});
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
+1 −0
Original line number Diff line number Diff line
@@ -227,6 +227,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
        binding.swipeContainer.setColorSchemeColors(
                c1, c1, c1
        );
        initialConversations = null;
        binding.loader.setVisibility(View.VISIBLE);
        binding.recyclerView.setVisibility(View.GONE);
        timelinesVM = new ViewModelProvider(FragmentMastodonConversation.this).get(TimelinesVM.class);
+1 −4
Original line number Diff line number Diff line
@@ -162,13 +162,13 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
        binding.loader.setVisibility(View.VISIBLE);
        binding.recyclerView.setVisibility(View.GONE);
        max_id = null;
        initialNotifications = null;
        route(null, false);
    }


    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        flagLoading = false;
        isViewInitialized = Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0;
        binding = FragmentPaginationBinding.inflate(inflater, container, false);
@@ -350,7 +350,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
        if (!isAdded()) {
            return;
        }

        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
        boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true);

@@ -369,9 +368,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
            timelineParams.maxId = max_id;
        }
        timelineParams.excludeType = getExcludeType();

        timelineParams.fetchingMissing = fetchingMissing;

        if (useCache) {
            getCachedNotifications(direction, fetchingMissing, timelineParams);
        } else {
+1 −1
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.

        timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
        accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);

        initialStatuses = null;
        binding.loader.setVisibility(View.VISIBLE);
        binding.recyclerView.setVisibility(View.GONE);
        max_id = statusReport != null ? statusReport.id : null;
+26 −19
Original line number Diff line number Diff line
@@ -99,8 +99,10 @@ public class FragmentNotificationContainer extends Fragment {
                db.setPositiveButton(R.string.delete_all, (dialog, id) -> {
                    changes.set(true);
                    NotificationsVM notificationsVM = new ViewModelProvider(FragmentNotificationContainer.this).get(NotificationsVM.class);
                    notificationsVM.clearNotification(BaseMainActivity.currentInstance, BaseMainActivity.currentToken)
                            .observe(getViewLifecycleOwner(), unused -> Toasty.info(requireActivity(), R.string.delete_notification_all, Toasty.LENGTH_LONG).show());
                    notificationsVM.clearNotification(BaseMainActivity.currentUserID, BaseMainActivity.currentInstance, BaseMainActivity.currentToken)
                            .observe(getViewLifecycleOwner(), unused -> {
                                Toasty.info(requireActivity(), R.string.delete_notification_all, Toasty.LENGTH_LONG).show();
                            });
                    dialog.dismiss();
                });
                db.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
@@ -189,24 +191,8 @@ public class FragmentNotificationContainer extends Fragment {
                    ((MaterialButton) v1).setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_baseline_expand_less_24, requireContext().getTheme()));
                }
            });
            dialogBuilder.setOnDismissListener(dialogInterface -> doAction(changes.get(), excludedCategoriesList));
            dialogBuilder.setPositiveButton(R.string.close, (dialog, id) -> {
                if (changes.get()) {
                    SharedPreferences.Editor editor = sharedpreferences.edit();
                    if (excludedCategoriesList.size() > 0) {
                        StringBuilder cat = new StringBuilder();
                        for (String category : excludedCategoriesList) {
                            cat.append(category).append('|');
                        }
                        if (cat.toString().endsWith("|")) {
                            cat.setLength(cat.length() - 1);
                        }
                        editor.putString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, cat.toString());
                    } else {
                        editor.putString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, null);
                    }
                    editor.commit();
                    ((BaseMainActivity) requireActivity()).refreshFragment();
                }
                dialog.dismiss();
            });
            AlertDialog alertDialog = dialogBuilder.create();
@@ -241,6 +227,27 @@ public class FragmentNotificationContainer extends Fragment {
        return binding.getRoot();
    }

    private void doAction(boolean changed, List<String> excludedCategoriesList) {
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
        if (changed) {
            SharedPreferences.Editor editor = sharedpreferences.edit();
            if (excludedCategoriesList.size() > 0) {
                StringBuilder cat = new StringBuilder();
                for (String category : excludedCategoriesList) {
                    cat.append(category).append('|');
                }
                if (cat.toString().endsWith("|")) {
                    cat.setLength(cat.length() - 1);
                }
                editor.putString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, cat.toString());
            } else {
                editor.putString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, null);
            }
            editor.commit();
            ((BaseMainActivity) requireActivity()).refreshFragment();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
Loading