Aidl fixes
This commit is contained in:
parent
86077b2d65
commit
937b1b5120
3 changed files with 50 additions and 20 deletions
|
@ -111,6 +111,7 @@ import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
@ -243,6 +244,7 @@ public class OsmandAidlApi {
|
||||||
|
|
||||||
public void onDestroyMapActivity(MapActivity mapActivity) {
|
public void onDestroyMapActivity(MapActivity mapActivity) {
|
||||||
app.getAppCustomization().removeListener(mapActivity);
|
app.getAppCustomization().removeListener(mapActivity);
|
||||||
|
aMapPointUpdateListener = null;
|
||||||
mapActivityActive = false;
|
mapActivityActive = false;
|
||||||
for (BroadcastReceiver b : receivers.values()) {
|
for (BroadcastReceiver b : receivers.values()) {
|
||||||
if(b == null) {
|
if(b == null) {
|
||||||
|
@ -1819,9 +1821,10 @@ public class OsmandAidlApi {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean switchEnabled(@NonNull ConnectedApp app) {
|
public boolean switchEnabled(@NonNull ConnectedApp connectedApp) {
|
||||||
app.enabled = !app.enabled;
|
connectedApp.enabled = !connectedApp.enabled;
|
||||||
return saveConnectedApps();
|
ApplicationMode selectedAppMode = app.getSettings().APPLICATION_MODE.get();
|
||||||
|
return saveConnectedApps(selectedAppMode, connectedApps);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAppEnabled(@NonNull String pack) {
|
boolean isAppEnabled(@NonNull String pack) {
|
||||||
|
@ -1829,12 +1832,22 @@ public class OsmandAidlApi {
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
app = new ConnectedApp(pack, true);
|
app = new ConnectedApp(pack, true);
|
||||||
connectedApps.put(pack, app);
|
connectedApps.put(pack, app);
|
||||||
saveConnectedApps();
|
saveNewConnectedApp(app);
|
||||||
}
|
}
|
||||||
return app.enabled;
|
return app.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean saveConnectedApps() {
|
private void saveNewConnectedApp(ConnectedApp connectedApp) {
|
||||||
|
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
|
||||||
|
Map<String, ConnectedApp> connectedApps = loadConnectedAppsForMode(mode);
|
||||||
|
if (!connectedApps.containsKey(connectedApp.pack)) {
|
||||||
|
connectedApps.put(connectedApp.pack, connectedApp);
|
||||||
|
saveConnectedApps(mode, connectedApps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveConnectedApps(ApplicationMode mode, Map<String, ConnectedApp> connectedApps) {
|
||||||
try {
|
try {
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
for (ConnectedApp app : connectedApps.values()) {
|
for (ConnectedApp app : connectedApps.values()) {
|
||||||
|
@ -1843,7 +1856,7 @@ public class OsmandAidlApi {
|
||||||
obj.put(ConnectedApp.PACK_KEY, app.pack);
|
obj.put(ConnectedApp.PACK_KEY, app.pack);
|
||||||
array.put(obj);
|
array.put(obj);
|
||||||
}
|
}
|
||||||
return app.getSettings().API_CONNECTED_APPS_JSON.set(array.toString());
|
return app.getSettings().API_CONNECTED_APPS_JSON.setModeValue(mode, array.toString());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1851,9 +1864,16 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConnectedApps() {
|
public void loadConnectedApps() {
|
||||||
|
ApplicationMode selectedAppMode = app.getSettings().APPLICATION_MODE.get();
|
||||||
|
Map<String, ConnectedApp> appsForMode = loadConnectedAppsForMode(selectedAppMode);
|
||||||
|
connectedApps.clear();
|
||||||
|
connectedApps.putAll(appsForMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, ConnectedApp> loadConnectedAppsForMode(ApplicationMode mode) {
|
||||||
|
Map<String, ConnectedApp> connectedApps = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
connectedApps.clear();
|
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.getModeValue(mode));
|
||||||
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.get());
|
|
||||||
for (int i = 0; i < array.length(); i++) {
|
for (int i = 0; i < array.length(); i++) {
|
||||||
JSONObject obj = array.getJSONObject(i);
|
JSONObject obj = array.getJSONObject(i);
|
||||||
String pack = obj.optString(ConnectedApp.PACK_KEY, "");
|
String pack = obj.optString(ConnectedApp.PACK_KEY, "");
|
||||||
|
@ -1863,6 +1883,7 @@ public class OsmandAidlApi {
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return connectedApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean setNavDrawerLogo(@Nullable String uri) {
|
boolean setNavDrawerLogo(@Nullable String uri) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.aidl.OsmandAidlApi;
|
||||||
import net.osmand.aidl.customization.CustomizationInfoParams;
|
import net.osmand.aidl.customization.CustomizationInfoParams;
|
||||||
import net.osmand.aidl.customization.OsmandSettingsParams;
|
import net.osmand.aidl.customization.OsmandSettingsParams;
|
||||||
import net.osmand.aidl.customization.SetWidgetsParams;
|
import net.osmand.aidl.customization.SetWidgetsParams;
|
||||||
|
@ -524,18 +525,21 @@ public class OsmAndAppCustomization {
|
||||||
JSONObject allItems = new JSONObject(app.getSettings().API_NAV_DRAWER_ITEMS_JSON.get());
|
JSONObject allItems = new JSONObject(app.getSettings().API_NAV_DRAWER_ITEMS_JSON.get());
|
||||||
for (Iterator<?> it = allItems.keys(); it.hasNext(); ) {
|
for (Iterator<?> it = allItems.keys(); it.hasNext(); ) {
|
||||||
String appPackage = (String) it.next();
|
String appPackage = (String) it.next();
|
||||||
JSONArray jArray = allItems.getJSONArray(appPackage);
|
OsmandAidlApi.ConnectedApp connectedApp = app.getAidlApi().getConnectedApp(appPackage);
|
||||||
List<NavDrawerItem> list = new ArrayList<>();
|
if (connectedApp != null && connectedApp.isEnabled()) {
|
||||||
for (int i = 0; i < jArray.length(); i++) {
|
JSONArray jArray = allItems.getJSONArray(appPackage);
|
||||||
JSONObject obj = jArray.getJSONObject(i);
|
List<NavDrawerItem> list = new ArrayList<>();
|
||||||
list.add(new NavDrawerItem(
|
for (int i = 0; i < jArray.length(); i++) {
|
||||||
obj.optString(NavDrawerItem.NAME_KEY),
|
JSONObject obj = jArray.getJSONObject(i);
|
||||||
obj.optString(NavDrawerItem.URI_KEY),
|
list.add(new NavDrawerItem(
|
||||||
obj.optString(NavDrawerItem.ICON_NAME_KEY),
|
obj.optString(NavDrawerItem.NAME_KEY),
|
||||||
obj.optInt(NavDrawerItem.FLAGS_KEY, -1)
|
obj.optString(NavDrawerItem.URI_KEY),
|
||||||
));
|
obj.optString(NavDrawerItem.ICON_NAME_KEY),
|
||||||
|
obj.optInt(NavDrawerItem.FLAGS_KEY, -1)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
res.put(appPackage, list);
|
||||||
}
|
}
|
||||||
res.put(appPackage, list);
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -922,7 +922,12 @@ public class OsmandSettings {
|
||||||
public final CommonPreference<Boolean> SHOW_OSMAND_WELCOME_SCREEN = new BooleanPreference("show_osmand_welcome_screen", true).makeGlobal();
|
public final CommonPreference<Boolean> SHOW_OSMAND_WELCOME_SCREEN = new BooleanPreference("show_osmand_welcome_screen", true).makeGlobal();
|
||||||
|
|
||||||
public final CommonPreference<String> API_NAV_DRAWER_ITEMS_JSON = new StringPreference("api_nav_drawer_items_json", "{}").makeGlobal();
|
public final CommonPreference<String> API_NAV_DRAWER_ITEMS_JSON = new StringPreference("api_nav_drawer_items_json", "{}").makeGlobal();
|
||||||
public final CommonPreference<String> API_CONNECTED_APPS_JSON = new StringPreference("api_connected_apps_json", "[]").makeProfile();
|
public final CommonPreference<String> API_CONNECTED_APPS_JSON = new StringPreference("api_connected_apps_json", "[]") {
|
||||||
|
@Override
|
||||||
|
public String getModeValue(ApplicationMode mode) {
|
||||||
|
return getValue(getProfilePreferences(mode), "[]");
|
||||||
|
}
|
||||||
|
}.makeProfile();
|
||||||
|
|
||||||
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
|
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue