diff --git a/OsmAnd/res/layout/dialog_live_updates_item_settings.xml b/OsmAnd/res/layout/dialog_live_updates_item_settings.xml
index cef79decc4..834a31c466 100644
--- a/OsmAnd/res/layout/dialog_live_updates_item_settings.xml
+++ b/OsmAnd/res/layout/dialog_live_updates_item_settings.xml
@@ -42,7 +42,7 @@
android:layout_row="1"
android:text="@string/live_update"/>
-
@@ -52,7 +52,7 @@
android:layout_row="2"
android:text="@string/only_download_over_wifi"/>
-
diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
index 1ed549d8de..b2089f32f5 100644
--- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
@@ -40,6 +40,7 @@ import java.util.List;
public class LiveUpdatesFragment extends Fragment {
public static final String TITILE = "Live Updates";
+ public static final String LIVE_UPDATES_ON_POSTFIX = "_live_updates_on";
public static final Comparator LOCAL_INDEX_INFO_COMPARATOR = new Comparator() {
@Override
public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) {
@@ -92,6 +93,10 @@ public class LiveUpdatesFragment extends Fragment {
return (AbstractDownloadActivity) getActivity();
}
+ public void notifyLiveUpdatesChanged() {
+ adapter.notifyLiveUpdatesChanged();
+ }
+
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
final ArrayList dataShouldUpdate = new ArrayList<>();
final ArrayList dataShouldNotUpdate = new ArrayList<>();
@@ -104,7 +109,33 @@ public class LiveUpdatesFragment extends Fragment {
}
public void add(LocalIndexInfo info) {
- dataShouldNotUpdate.add(info);
+ OsmandSettings.CommonPreference preference =
+ preferenceForLocalIndex(LIVE_UPDATES_ON_POSTFIX, info);
+ if (preference.get()) {
+ dataShouldUpdate.add(info);
+ } else {
+ dataShouldNotUpdate.add(info);
+ }
+ }
+
+ public void notifyLiveUpdatesChanged() {
+ for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
+ OsmandSettings.CommonPreference preference =
+ preferenceForLocalIndex(LIVE_UPDATES_ON_POSTFIX, localIndexInfo);
+ if (!preference.get()) {
+ dataShouldUpdate.remove(localIndexInfo);
+ dataShouldNotUpdate.add(localIndexInfo);
+ }
+ }
+ for (LocalIndexInfo localIndexInfo : dataShouldNotUpdate) {
+ OsmandSettings.CommonPreference preference =
+ preferenceForLocalIndex(LIVE_UPDATES_ON_POSTFIX, localIndexInfo);
+ if (preference.get()) {
+ dataShouldUpdate.add(localIndexInfo);
+ dataShouldNotUpdate.remove(localIndexInfo);
+ }
+ }
+ notifyDataSetChanged();
}
public void sort() {
@@ -215,6 +246,13 @@ public class LiveUpdatesFragment extends Fragment {
return true;
}
+ private OsmandSettings.CommonPreference preferenceForLocalIndex(String idPostfix,
+ LocalIndexInfo item) {
+ final OsmandApplication myApplication = fragment.getMyActivity().getMyApplication();
+ final OsmandSettings settings = myApplication.getSettings();
+ final String settingId = item.getFileName() + idPostfix;
+ return settings.registerBooleanPreference(settingId, false);
+ }
}
private void expandAllGroups() {
@@ -340,5 +378,4 @@ public class LiveUpdatesFragment extends Fragment {
adapter.sort();
}
}
-
}
diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/SettingsDialogFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/SettingsDialogFragment.java
index 0370c0a80f..c196316497 100644
--- a/OsmAnd/src/net/osmand/plus/liveupdates/SettingsDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/liveupdates/SettingsDialogFragment.java
@@ -6,10 +6,9 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
+import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.CompoundButton;
-import android.widget.ToggleButton;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@@ -24,11 +23,24 @@ public class SettingsDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ final LocalIndexInfo localIndexInfo = getArguments().getParcelable(LOCAL_INDEX);
+
View view = LayoutInflater.from(getActivity())
.inflate(R.layout.dialog_live_updates_item_settings, null);
- final LocalIndexInfo localIndexInfo = getArguments().getParcelable(LOCAL_INDEX);
+ final SwitchCompat liveUpdatesSwitch = (SwitchCompat) view.findViewById(R.id.liveUpdatesSwitch);
+
+ final OsmandSettings.CommonPreference liveUpdatePreference =
+ preferenceForLocalIndex(LiveUpdatesFragment.LIVE_UPDATES_ON_POSTFIX, localIndexInfo);
+ liveUpdatesSwitch.setChecked(liveUpdatePreference.get());
+
builder.setView(view)
- .setPositiveButton(R.string.shared_string_save, null)
+ .setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ liveUpdatePreference.set(liveUpdatesSwitch.isChecked());
+ getLiveUpdatesFragment().notifyLiveUpdatesChanged();
+ }
+ })
.setNegativeButton(R.string.shared_string_cancel, null)
.setNeutralButton(R.string.update_now, new DialogInterface.OnClickListener() {
@Override
@@ -43,20 +55,12 @@ public class SettingsDialogFragment extends DialogFragment {
return (LiveUpdatesFragment) getParentFragment();
}
- private void initSwitch(ToggleButton toggleButton, String idPostfix, LocalIndexInfo item) {
+ private OsmandSettings.CommonPreference preferenceForLocalIndex(String idPostfix,
+ LocalIndexInfo item) {
final OsmandApplication myApplication = ((OsmandActionBarActivity) this.getActivity()).getMyApplication();
final OsmandSettings settings = myApplication.getSettings();
final String settingId = item.getFileName() + idPostfix;
- final OsmandSettings.CommonPreference preference =
- settings.registerBooleanPreference(settingId, false);
- boolean initialValue = preference.get();
- toggleButton.setChecked(initialValue);
- toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- preference.set(isChecked);
- }
- });
+ return settings.registerBooleanPreference(settingId, false);
}
public static SettingsDialogFragment createInstance(LocalIndexInfo localIndexInfo) {