mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
* Updated deleteAll() method to remove all searches insetead of 10 (#2181) * Updated deleteAll() method to delete all searches instead of 10 (#2181) * some minor chages
This commit is contained in:
parent
aec1e51339
commit
a3b33736b3
2 changed files with 34 additions and 19 deletions
|
|
@ -52,26 +52,41 @@ public class RecentSearchesDao {
|
|||
|
||||
/**
|
||||
* This method is called on confirmation of delete recent searches.
|
||||
* It deletes latest 10 recent searches from the database
|
||||
* @param recentSearchesStringList list of recent searches to be deleted
|
||||
* It deletes all recent searches from the database
|
||||
*/
|
||||
public void deleteAll(List<String> recentSearchesStringList) {
|
||||
public void deleteAll() {
|
||||
Cursor cursor = null;
|
||||
ContentProviderClient db = clientProvider.get();
|
||||
for (String recentSearchName : recentSearchesStringList) {
|
||||
try {
|
||||
RecentSearch recentSearch = find(recentSearchName);
|
||||
if (recentSearch.getContentUri() == null) {
|
||||
throw new RuntimeException("tried to delete item with no content URI");
|
||||
} else {
|
||||
Timber.d("QUERY_NAME %s - delete tried", recentSearch.getContentUri());
|
||||
db.delete(recentSearch.getContentUri(), null, null);
|
||||
Timber.d("QUERY_NAME %s - query deleted", recentSearch.getQuery());
|
||||
try {
|
||||
cursor = db.query(
|
||||
RecentSearchesContentProvider.BASE_URI,
|
||||
Table.ALL_FIELDS,
|
||||
null,
|
||||
new String[]{},
|
||||
Table.COLUMN_LAST_USED + " DESC"
|
||||
);
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
try {
|
||||
RecentSearch recentSearch = find(fromCursor(cursor).getQuery());
|
||||
if (recentSearch.getContentUri() == null) {
|
||||
throw new RuntimeException("tried to delete item with no content URI");
|
||||
} else {
|
||||
Timber.d("QUERY_NAME %s - delete tried", recentSearch.getContentUri());
|
||||
db.delete(recentSearch.getContentUri(), null, null);
|
||||
Timber.d("QUERY_NAME %s - query deleted", recentSearch.getQuery());
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Timber.e(e, "query deleted");
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
db.release();
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Timber.e(e, "query deleted");
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
db.release();
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
|||
new AlertDialog.Builder(getContext())
|
||||
.setMessage(getString(R.string.delete_recent_searches_dialog))
|
||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||
recentSearchesDao.deleteAll(recentSearches);
|
||||
recentSearchesDao.deleteAll();
|
||||
recent_searches_delete_button.setVisibility(View.GONE);
|
||||
recent_searches_text_view.setText(R.string.no_recent_searches);
|
||||
Toast.makeText(getContext(),getString(R.string.search_history_deleted),Toast.LENGTH_SHORT).show();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue