mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Notifications not deleted from cache
This commit is contained in:
		
							parent
							
								
									ee68f4fc7d
								
							
						
					
					
						commit
						d4aee3ff4e
					
				
					 6 changed files with 34 additions and 31 deletions
				
			
		|  | @ -415,14 +415,14 @@ public class StatusCache { | ||||||
|      * @return long - db id |      * @return long - db id | ||||||
|      * @throws DBException exception with database |      * @throws DBException exception with database | ||||||
|      */ |      */ | ||||||
|     public long deleteNotifications() throws DBException { |     public long deleteNotifications(String user_id, String instance) throws DBException { | ||||||
|         if (db == null) { |         if (db == null) { | ||||||
|             throw new DBException("db is null. Wrong initialization."); |             throw new DBException("db is null. Wrong initialization."); | ||||||
|         } |         } | ||||||
|         try { |         try { | ||||||
|             return db.delete(Sqlite.TABLE_STATUS_CACHE, |             return db.delete(Sqlite.TABLE_STATUS_CACHE, | ||||||
|                     Sqlite.COL_USER_ID + " =  ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_TYPE + "=?", |                     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) { |         } catch (Exception e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|             return -1; |             return -1; | ||||||
|  |  | ||||||
|  | @ -227,6 +227,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati | ||||||
|         binding.swipeContainer.setColorSchemeColors( |         binding.swipeContainer.setColorSchemeColors( | ||||||
|                 c1, c1, c1 |                 c1, c1, c1 | ||||||
|         ); |         ); | ||||||
|  |         initialConversations = null; | ||||||
|         binding.loader.setVisibility(View.VISIBLE); |         binding.loader.setVisibility(View.VISIBLE); | ||||||
|         binding.recyclerView.setVisibility(View.GONE); |         binding.recyclerView.setVisibility(View.GONE); | ||||||
|         timelinesVM = new ViewModelProvider(FragmentMastodonConversation.this).get(TimelinesVM.class); |         timelinesVM = new ViewModelProvider(FragmentMastodonConversation.this).get(TimelinesVM.class); | ||||||
|  |  | ||||||
|  | @ -162,13 +162,13 @@ public class FragmentMastodonNotification extends Fragment implements Notificati | ||||||
|         binding.loader.setVisibility(View.VISIBLE); |         binding.loader.setVisibility(View.VISIBLE); | ||||||
|         binding.recyclerView.setVisibility(View.GONE); |         binding.recyclerView.setVisibility(View.GONE); | ||||||
|         max_id = null; |         max_id = null; | ||||||
|  |         initialNotifications = null; | ||||||
|         route(null, false); |         route(null, false); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public View onCreateView(@NonNull LayoutInflater inflater, |     public View onCreateView(@NonNull LayoutInflater inflater, | ||||||
|                              ViewGroup container, Bundle savedInstanceState) { |                              ViewGroup container, Bundle savedInstanceState) { | ||||||
| 
 |  | ||||||
|         flagLoading = false; |         flagLoading = false; | ||||||
|         isViewInitialized = Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0; |         isViewInitialized = Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0; | ||||||
|         binding = FragmentPaginationBinding.inflate(inflater, container, false); |         binding = FragmentPaginationBinding.inflate(inflater, container, false); | ||||||
|  | @ -350,7 +350,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati | ||||||
|         if (!isAdded()) { |         if (!isAdded()) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||||
|         boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true); |         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.maxId = max_id; | ||||||
|         } |         } | ||||||
|         timelineParams.excludeType = getExcludeType(); |         timelineParams.excludeType = getExcludeType(); | ||||||
| 
 |  | ||||||
|         timelineParams.fetchingMissing = fetchingMissing; |         timelineParams.fetchingMissing = fetchingMissing; | ||||||
| 
 |  | ||||||
|         if (useCache) { |         if (useCache) { | ||||||
|             getCachedNotifications(direction, fetchingMissing, timelineParams); |             getCachedNotifications(direction, fetchingMissing, timelineParams); | ||||||
|         } else { |         } else { | ||||||
|  |  | ||||||
|  | @ -232,7 +232,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. | ||||||
| 
 | 
 | ||||||
|         timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class); |         timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class); | ||||||
|         accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class); |         accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class); | ||||||
| 
 |         initialStatuses = null; | ||||||
|         binding.loader.setVisibility(View.VISIBLE); |         binding.loader.setVisibility(View.VISIBLE); | ||||||
|         binding.recyclerView.setVisibility(View.GONE); |         binding.recyclerView.setVisibility(View.GONE); | ||||||
|         max_id = statusReport != null ? statusReport.id : null; |         max_id = statusReport != null ? statusReport.id : null; | ||||||
|  |  | ||||||
|  | @ -99,8 +99,10 @@ public class FragmentNotificationContainer extends Fragment { | ||||||
|                 db.setPositiveButton(R.string.delete_all, (dialog, id) -> { |                 db.setPositiveButton(R.string.delete_all, (dialog, id) -> { | ||||||
|                     changes.set(true); |                     changes.set(true); | ||||||
|                     NotificationsVM notificationsVM = new ViewModelProvider(FragmentNotificationContainer.this).get(NotificationsVM.class); |                     NotificationsVM notificationsVM = new ViewModelProvider(FragmentNotificationContainer.this).get(NotificationsVM.class); | ||||||
|                     notificationsVM.clearNotification(BaseMainActivity.currentInstance, BaseMainActivity.currentToken) |                     notificationsVM.clearNotification(BaseMainActivity.currentUserID, BaseMainActivity.currentInstance, BaseMainActivity.currentToken) | ||||||
|                             .observe(getViewLifecycleOwner(), unused -> Toasty.info(requireActivity(), R.string.delete_notification_all, Toasty.LENGTH_LONG).show()); |                             .observe(getViewLifecycleOwner(), unused -> { | ||||||
|  |                                 Toasty.info(requireActivity(), R.string.delete_notification_all, Toasty.LENGTH_LONG).show(); | ||||||
|  |                             }); | ||||||
|                     dialog.dismiss(); |                     dialog.dismiss(); | ||||||
|                 }); |                 }); | ||||||
|                 db.setNegativeButton(R.string.cancel, (dialog, id) -> 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())); |                     ((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) -> { |             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(); |                 dialog.dismiss(); | ||||||
|             }); |             }); | ||||||
|             AlertDialog alertDialog = dialogBuilder.create(); |             AlertDialog alertDialog = dialogBuilder.create(); | ||||||
|  | @ -241,6 +227,27 @@ public class FragmentNotificationContainer extends Fragment { | ||||||
|         return binding.getRoot(); |         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 |     @Override | ||||||
|     public void onResume() { |     public void onResume() { | ||||||
|         super.onResume(); |         super.onResume(); | ||||||
|  |  | ||||||
|  | @ -223,21 +223,19 @@ public class NotificationsVM extends AndroidViewModel { | ||||||
|     /** |     /** | ||||||
|      * Get a notification for the authenticated account by its id |      * Get a notification for the authenticated account by its id | ||||||
|      * |      * | ||||||
|  |      * @param user_id  String - UserId for the api call | ||||||
|      * @param instance String - Instance for the api call |      * @param instance String - Instance for the api call | ||||||
|      * @param token    String - Token of the authenticated account |      * @param token    String - Token of the authenticated account | ||||||
|      */ |      */ | ||||||
|     public LiveData<Void> clearNotification(@NonNull String instance, String token) { |     public LiveData<Void> clearNotification(@NonNull String user_id, @NonNull String instance, String token) { | ||||||
|         voidMutableLiveData = new MutableLiveData<>(); |         voidMutableLiveData = new MutableLiveData<>(); | ||||||
|         MastodonNotificationsService mastodonNotificationsService = init(instance); |         MastodonNotificationsService mastodonNotificationsService = init(instance); | ||||||
|         new Thread(() -> { |         new Thread(() -> { | ||||||
|             Call<Void> voidCall = mastodonNotificationsService.clearAllNotifications(token); |             Call<Void> voidCall = mastodonNotificationsService.clearAllNotifications(token); | ||||||
|             try { |  | ||||||
|                 new StatusCache(getApplication().getApplicationContext()).deleteNotifications(); |  | ||||||
|             } catch (Exception ignored) { |  | ||||||
|             } |  | ||||||
|             if (voidCall != null) { |             if (voidCall != null) { | ||||||
|                 try { |                 try { | ||||||
|                     voidCall.execute(); |                     voidCall.execute(); | ||||||
|  |                     new StatusCache(getApplication().getApplicationContext()).deleteNotifications(user_id, instance); | ||||||
|                 } catch (Exception e) { |                 } catch (Exception e) { | ||||||
|                     e.printStackTrace(); |                     e.printStackTrace(); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue