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.
|
* This method is called on confirmation of delete recent searches.
|
||||||
* It deletes latest 10 recent searches from the database
|
* It deletes all recent searches from the database
|
||||||
* @param recentSearchesStringList list of recent searches to be deleted
|
|
||||||
*/
|
*/
|
||||||
public void deleteAll(List<String> recentSearchesStringList) {
|
public void deleteAll() {
|
||||||
|
Cursor cursor = null;
|
||||||
ContentProviderClient db = clientProvider.get();
|
ContentProviderClient db = clientProvider.get();
|
||||||
for (String recentSearchName : recentSearchesStringList) {
|
try {
|
||||||
try {
|
cursor = db.query(
|
||||||
RecentSearch recentSearch = find(recentSearchName);
|
RecentSearchesContentProvider.BASE_URI,
|
||||||
if (recentSearch.getContentUri() == null) {
|
Table.ALL_FIELDS,
|
||||||
throw new RuntimeException("tried to delete item with no content URI");
|
null,
|
||||||
} else {
|
new String[]{},
|
||||||
Timber.d("QUERY_NAME %s - delete tried", recentSearch.getContentUri());
|
Table.COLUMN_LAST_USED + " DESC"
|
||||||
db.delete(recentSearch.getContentUri(), null, null);
|
);
|
||||||
Timber.d("QUERY_NAME %s - query deleted", recentSearch.getQuery());
|
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");
|
} catch (RemoteException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
db.release();
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
||||||
new AlertDialog.Builder(getContext())
|
new AlertDialog.Builder(getContext())
|
||||||
.setMessage(getString(R.string.delete_recent_searches_dialog))
|
.setMessage(getString(R.string.delete_recent_searches_dialog))
|
||||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||||
recentSearchesDao.deleteAll(recentSearches);
|
recentSearchesDao.deleteAll();
|
||||||
recent_searches_delete_button.setVisibility(View.GONE);
|
recent_searches_delete_button.setVisibility(View.GONE);
|
||||||
recent_searches_text_view.setText(R.string.no_recent_searches);
|
recent_searches_text_view.setText(R.string.no_recent_searches);
|
||||||
Toast.makeText(getContext(),getString(R.string.search_history_deleted),Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(),getString(R.string.search_history_deleted),Toast.LENGTH_SHORT).show();
|
||||||
|
|
@ -70,7 +70,7 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
||||||
});
|
});
|
||||||
currentThemeIsDark = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("theme", false);
|
currentThemeIsDark = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("theme", false);
|
||||||
setAdapterForThemes(getContext(), currentThemeIsDark);
|
setAdapterForThemes(getContext(), currentThemeIsDark);
|
||||||
|
|
||||||
recentSearchesList.setAdapter(adapter);
|
recentSearchesList.setAdapter(adapter);
|
||||||
recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
|
recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
|
||||||
(SearchActivity)getContext()).updateText(recentSearches.get(position)));
|
(SearchActivity)getContext()).updateText(recentSearches.get(position)));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue