added changes for a possibly working emptyCache implementation (needs testing).

This commit is contained in:
Noah Vendrig 2024-10-23 14:06:15 +11:00
parent c43ecda702
commit e616c80adb
4 changed files with 37 additions and 1 deletions

View file

@ -42,4 +42,24 @@ public abstract class PlaceDao {
saveSynchronous(place);
});
}
/**
* Deletes all Place objects from the database.
*
* @return A Completable that completes once the deletion operation is done.
*/
@Query("DELETE FROM place")
public abstract void deleteAllSynchronous();
/**
* Deletes all Place objects asynchronously from the database.
*
* @return A Completable that completes once the deletion operation is done.
*/
public Completable deleteAll() {
return Completable
.fromAction(() -> {
deleteAllSynchronous();
});
}
}

View file

@ -36,4 +36,8 @@ public class PlacesLocalDataSource {
public Completable savePlace(Place place) {
return placeDao.save(place);
}
public Completable clearCache() {
return placeDao.deleteAll();
}
}

View file

@ -38,4 +38,7 @@ public class PlacesRepository {
return localDataSource.fetchPlace(entityID);
}
public Completable clearCache() {
return localDataSource.clearCache();
}
}

View file

@ -32,6 +32,7 @@ import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -319,6 +320,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
Timber.d("Reload: menuItem");
// REFRESH BUTTON FUNCTIONALITY HERE
emptyCache();
reloadMap();
@ -1130,7 +1132,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
/**
* Reloads the Nearby map
* Reloads the Nearby map.
* This method clears the existing markers, resets the map state, and repopulates the map with the latest data.
*/
private void reloadMap(){
@ -1141,7 +1144,13 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
* Empties the Nearby local cache
*/
private void emptyCache(){
Timber.d("Reload: emptyCache");
placesRepository.clearCache();
// Optionally, clear any in-memory cache or state
updatedPlacesList.clear();
updatedLatLng = null;
}
private void savePlacesAsKML() {