Add the ability to clear all nav drawer items for appPackage

This commit is contained in:
Alex Sytnyk 2018-07-31 21:43:21 +03:00
parent dc0ec000de
commit 87e9f06711

View file

@ -1202,7 +1202,11 @@ public class OsmandAidlApi {
} }
boolean setNavDrawerItems(String appPackage, List<net.osmand.aidl.navdrawer.NavDrawerItem> items) { boolean setNavDrawerItems(String appPackage, List<net.osmand.aidl.navdrawer.NavDrawerItem> items) {
if (!TextUtils.isEmpty(appPackage) && items != null && !items.isEmpty()) { if (!TextUtils.isEmpty(appPackage) && items != null) {
if (items.isEmpty()) {
clearNavDrawerItems(appPackage);
return true;
}
List<NavDrawerItem> newItems = new ArrayList<>(MAX_NAV_DRAWER_ITEMS_PER_APP); List<NavDrawerItem> newItems = new ArrayList<>(MAX_NAV_DRAWER_ITEMS_PER_APP);
boolean success = true; boolean success = true;
for (int i = 0; i < items.size() && i <= MAX_NAV_DRAWER_ITEMS_PER_APP; i++) { for (int i = 0; i < items.size() && i <= MAX_NAV_DRAWER_ITEMS_PER_APP; i++) {
@ -1262,6 +1266,16 @@ public class OsmandAidlApi {
return -1; return -1;
} }
private void clearNavDrawerItems(String appPackage) {
try {
JSONObject allItems = new JSONObject(app.getSettings().API_NAV_DRAWER_ITEMS_JSON.get());
allItems.put(appPackage, null);
app.getSettings().API_NAV_DRAWER_ITEMS_JSON.set(allItems.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
private void saveNavDrawerItems(String appPackage, List<NavDrawerItem> items) { private void saveNavDrawerItems(String appPackage, List<NavDrawerItem> items) {
try { try {
JSONArray jArray = new JSONArray(); JSONArray jArray = new JSONArray();