mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
parent
b46ea0aba8
commit
cbf625d3f9
3 changed files with 39 additions and 0 deletions
|
|
@ -91,6 +91,26 @@ public class RecentSearchesDao {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a recent search from the database
|
||||
*/
|
||||
public void delete(RecentSearch recentSearch) {
|
||||
|
||||
ContentProviderClient db = clientProvider.get();
|
||||
try {
|
||||
if (recentSearch.getContentUri() == null) {
|
||||
throw new RuntimeException("tried to delete item with no content URI");
|
||||
} else {
|
||||
db.delete(recentSearch.getContentUri(), null, null);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
db.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find persisted search query in database, based on its name.
|
||||
* @param name Search query Ex- "butterfly"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.support.v7.app.AlertDialog;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
|
|
@ -70,6 +71,22 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
|||
recentSearchesList.setAdapter(adapter);
|
||||
recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
|
||||
(SearchActivity)getContext()).updateText(recentSearches.get(position)));
|
||||
recentSearchesList.setOnItemLongClickListener((parent, view, position, id) -> {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setMessage(R.string.delete_search_dialog)
|
||||
.setPositiveButton(R.string.delete,((dialog, which) -> {
|
||||
recentSearchesDao.delete(recentSearchesDao.find(recentSearches.get(position)));
|
||||
recentSearches = recentSearchesDao.recentSearches(10);
|
||||
adapter = new ArrayAdapter<>(getContext(), R.layout.item_recent_searches, recentSearches);
|
||||
recentSearchesList.setAdapter(adapter);
|
||||
adapter.notifyDataSetChanged();
|
||||
dialog.dismiss();
|
||||
}))
|
||||
.setNegativeButton(android.R.string.cancel,null)
|
||||
.create()
|
||||
.show();
|
||||
return true;
|
||||
});
|
||||
updateRecentSearches();
|
||||
return rootView;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -349,8 +349,10 @@
|
|||
|
||||
<string name="no_recent_searches">No recent searches</string>
|
||||
<string name="delete_recent_searches_dialog">Are you sure you want to clear your search history?</string>
|
||||
<string name="delete_search_dialog">Do you want to delete this search?</string>
|
||||
<string name="search_history_deleted">Search history deleted</string>
|
||||
<string name="nominate_delete">Nominate For Deletion</string>
|
||||
<string name="delete">DELETE</string>
|
||||
|
||||
<string name="Achievements">Achievements</string>
|
||||
<string name="statistics">STATISTICS</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue