@@ -52,26 +52,41 @@ public void save(RecentSearch recentSearch) {
52
52
53
53
/**
54
54
* This method is called on confirmation of delete recent searches.
55
- * It deletes latest 10 recent searches from the database
56
- * @param recentSearchesStringList list of recent searches to be deleted
55
+ * It deletes all recent searches from the database
57
56
*/
58
- public void deleteAll (List <String > recentSearchesStringList ) {
57
+ public void deleteAll () {
58
+ Cursor cursor = null ;
59
59
ContentProviderClient db = clientProvider .get ();
60
- for (String recentSearchName : recentSearchesStringList ) {
61
- try {
62
- RecentSearch recentSearch = find (recentSearchName );
63
- if (recentSearch .getContentUri () == null ) {
64
- throw new RuntimeException ("tried to delete item with no content URI" );
65
- } else {
66
- Timber .d ("QUERY_NAME %s - delete tried" , recentSearch .getContentUri ());
67
- db .delete (recentSearch .getContentUri (), null , null );
68
- Timber .d ("QUERY_NAME %s - query deleted" , recentSearch .getQuery ());
60
+ try {
61
+ cursor = db .query (
62
+ RecentSearchesContentProvider .BASE_URI ,
63
+ Table .ALL_FIELDS ,
64
+ null ,
65
+ new String []{},
66
+ Table .COLUMN_LAST_USED + " DESC"
67
+ );
68
+ while (cursor != null && cursor .moveToNext ()) {
69
+ try {
70
+ RecentSearch recentSearch = find (fromCursor (cursor ).getQuery ());
71
+ if (recentSearch .getContentUri () == null ) {
72
+ throw new RuntimeException ("tried to delete item with no content URI" );
73
+ } else {
74
+ Timber .d ("QUERY_NAME %s - delete tried" , recentSearch .getContentUri ());
75
+ db .delete (recentSearch .getContentUri (), null , null );
76
+ Timber .d ("QUERY_NAME %s - query deleted" , recentSearch .getQuery ());
77
+ }
78
+ } catch (RemoteException e ) {
79
+ Timber .e (e , "query deleted" );
80
+ throw new RuntimeException (e );
81
+ } finally {
82
+ db .release ();
69
83
}
70
- } catch (RemoteException e ) {
71
- Timber .e (e , "query deleted" );
72
- throw new RuntimeException (e );
73
- } finally {
74
- db .release ();
84
+ }
85
+ } catch (RemoteException e ) {
86
+ throw new RuntimeException (e );
87
+ } finally {
88
+ if (cursor != null ) {
89
+ cursor .close ();
75
90
}
76
91
}
77
92
}
0 commit comments