Design fixes
This commit is contained in:
parent
e4b822ec3d
commit
6eb47c95f8
8 changed files with 331 additions and 240 deletions
25
OsmAnd/res/layout/list_group_title_with_switch.xml
Normal file
25
OsmAnd/res/layout/list_group_title_with_switch.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/section_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
tools:text="Live updates"/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.SwitchCompat
|
||||||
|
android:id="@+id/liveUpdatesSwitch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
</LinearLayout>
|
|
@ -2,22 +2,13 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="14dp"
|
android:layout_marginLeft="14dp"
|
||||||
android:layout_marginRight="14dp"
|
android:layout_marginRight="14dp"
|
||||||
android:layout_marginTop="14dp"
|
android:layout_marginTop="14dp"
|
||||||
android:background="?attr/bg_card"
|
android:background="?attr/bg_card"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical">
|
||||||
tools:showIn="@layout/fragment_live_updates">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -30,7 +21,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:text="Subscription status"
|
android:text="Subscription"
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
android:textSize="@dimen/default_desc_text_size"
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
app:typeface="@string/font_roboto_regular"/>
|
app:typeface="@string/font_roboto_regular"/>
|
||||||
|
@ -42,9 +33,10 @@
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:text="Work"
|
android:text="25 days left"
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
android:textSize="@dimen/default_desc_text_size"
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
app:textAllCapsCompat="true"
|
||||||
app:typeface="@string/font_roboto_medium"/>
|
app:typeface="@string/font_roboto_medium"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -120,26 +112,4 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout> -->
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="15dp"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
|
||||||
android:id="@+id/onOffTextView"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
tools:text="@string/shared_string_on"
|
|
||||||
app:textAllCapsCompat="true"/>
|
|
||||||
|
|
||||||
<android.support.v7.widget.SwitchCompat
|
|
||||||
android:id="@+id/liveUpdatesSwitch"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
64
OsmAnd/res/layout/local_index_live_updates_list_item.xml
Normal file
64
OsmAnd/res/layout/local_index_live_updates_list_item.xml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="72dp"
|
||||||
|
android:background="?attr/expandable_list_item_background"
|
||||||
|
android:descendantFocusability="blocksDescendants"
|
||||||
|
android:minHeight="@dimen/list_item_height"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="@dimen/list_content_padding">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="@dimen/favorites_icon_right_margin"
|
||||||
|
android:layout_marginTop="@dimen/favorites_icon_top_margin"
|
||||||
|
android:focusable="false"
|
||||||
|
android:src="@drawable/ic_map"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/nameTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
tools:text="Belarus"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/subheaderTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="7dp"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_sub_text_size"
|
||||||
|
tools:text="11.1 MB"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/descriptionTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="7dp"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_sub_text_size"
|
||||||
|
tools:text="Last Update: 1 Dec 2015"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/options"
|
||||||
|
android:layout_width="@dimen/list_item_height"
|
||||||
|
android:layout_height="@dimen/list_item_height"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:background="?attr/dashboard_button"
|
||||||
|
android:focusable="false"
|
||||||
|
android:src="@drawable/ic_overflow_menu_white"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -27,8 +27,7 @@ public class LocalIndexInfo implements Parcelable {
|
||||||
private boolean singleFile;
|
private boolean singleFile;
|
||||||
private int kbSize = -1;
|
private int kbSize = -1;
|
||||||
|
|
||||||
@NonNull
|
private WorldRegion worldRegion;
|
||||||
private final WorldRegion worldRegion;
|
|
||||||
|
|
||||||
// UI state expanded
|
// UI state expanded
|
||||||
private boolean expanded;
|
private boolean expanded;
|
||||||
|
@ -46,10 +45,6 @@ public class LocalIndexInfo implements Parcelable {
|
||||||
kbSize = (int) ((f.length() + 512) >> 10);
|
kbSize = (int) ((f.length() + 512) >> 10);
|
||||||
}
|
}
|
||||||
this.backupedData = backuped;
|
this.backupedData = backuped;
|
||||||
|
|
||||||
final String baseName = getBaseName().toLowerCase();
|
|
||||||
WorldRegion worldRegion = app.getRegions().getRegionDataByDownloadName(baseName);
|
|
||||||
this.worldRegion = worldRegion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatName(String name) {
|
private String formatName(String name) {
|
||||||
|
@ -66,10 +61,6 @@ public class LocalIndexInfo implements Parcelable {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
backupedData = backup;
|
backupedData = backup;
|
||||||
this.subfolder = subfolder;
|
this.subfolder = subfolder;
|
||||||
|
|
||||||
final String baseName = getBaseName().toLowerCase();
|
|
||||||
WorldRegion worldRegion = app.getRegions().getRegionDataByDownloadName(baseName);
|
|
||||||
this.worldRegion = worldRegion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCorrupted(boolean corrupted) {
|
public void setCorrupted(boolean corrupted) {
|
||||||
|
|
|
@ -25,6 +25,10 @@ import org.apache.commons.logging.Log;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.UpdateFrequency;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceDownloadViaWiFi;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
|
||||||
|
|
||||||
public class LiveUpdatesAlarmReceiver extends BroadcastReceiver {
|
public class LiveUpdatesAlarmReceiver extends BroadcastReceiver {
|
||||||
private static final Log LOG = PlatformUtil.getLog(LiveUpdatesAlarmReceiver.class);
|
private static final Log LOG = PlatformUtil.getLog(LiveUpdatesAlarmReceiver.class);
|
||||||
|
|
||||||
|
@ -93,10 +97,10 @@ public class LiveUpdatesAlarmReceiver extends BroadcastReceiver {
|
||||||
private static void tryRescheduleDownload(Context context, OsmandSettings settings,
|
private static void tryRescheduleDownload(Context context, OsmandSettings settings,
|
||||||
LocalIndexInfo localIndexInfo) {
|
LocalIndexInfo localIndexInfo) {
|
||||||
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
|
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
|
||||||
preferenceUpdateTimes(localIndexInfo, settings);
|
preferenceUpdateFrequency(localIndexInfo, settings);
|
||||||
final Integer frequencyOrdinal = updateFrequencyPreference.get();
|
final Integer frequencyOrdinal = updateFrequencyPreference.get();
|
||||||
if (LiveUpdatesSettingsDialogFragment.UpdateFrequencies.values()[frequencyOrdinal]
|
if (UpdateFrequency.values()[frequencyOrdinal]
|
||||||
== LiveUpdatesSettingsDialogFragment.UpdateFrequencies.HOURLY) {
|
== UpdateFrequency.HOURLY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Integer retriesLeft = settings.LIVE_UPDATES_RETRIES.get();
|
final Integer retriesLeft = settings.LIVE_UPDATES_RETRIES.get();
|
||||||
|
@ -118,19 +122,4 @@ public class LiveUpdatesAlarmReceiver extends BroadcastReceiver {
|
||||||
settings.LIVE_UPDATES_RETRIES.resetToDefault();
|
settings.LIVE_UPDATES_RETRIES.resetToDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OsmandSettings.CommonPreference<Boolean> preferenceDownloadViaWiFi(
|
|
||||||
LocalIndexInfo item, OsmandSettings settings) {
|
|
||||||
final String settingId = item.getFileName()
|
|
||||||
+ LiveUpdatesSettingsDialogFragment.DOWNLOAD_VIA_WIFI_POSTFIX;
|
|
||||||
return settings.registerBooleanPreference(settingId, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OsmandSettings.CommonPreference<Integer> preferenceUpdateTimes(
|
|
||||||
LocalIndexInfo item, OsmandSettings settings) {
|
|
||||||
final String settingId = item.getFileName()
|
|
||||||
+ LiveUpdatesSettingsDialogFragment.UPDATE_TIMES_POSTFIX;
|
|
||||||
return settings.registerIntPreference(settingId,
|
|
||||||
LiveUpdatesSettingsDialogFragment.UpdateFrequencies.HOURLY.ordinal());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,12 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.UpdateFrequency;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
|
||||||
|
|
||||||
public class LiveUpdatesFragment extends Fragment {
|
public class LiveUpdatesFragment extends Fragment {
|
||||||
public static final String TITILE = "Live Updates";
|
public static final String TITILE = "Live Updates";
|
||||||
public static final String LIVE_UPDATES_ON_POSTFIX = "_live_updates_on";
|
|
||||||
public static final Comparator<LocalIndexInfo> LOCAL_INDEX_INFO_COMPARATOR = new Comparator<LocalIndexInfo>() {
|
public static final Comparator<LocalIndexInfo> LOCAL_INDEX_INFO_COMPARATOR = new Comparator<LocalIndexInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) {
|
public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) {
|
||||||
|
@ -62,35 +65,18 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_live_updates, container, false);
|
View view = inflater.inflate(R.layout.fragment_live_updates, container, false);
|
||||||
listView = (ExpandableListView) view.findViewById(android.R.id.list);
|
listView = (ExpandableListView) view.findViewById(android.R.id.list);
|
||||||
View header = inflater.inflate(R.layout.live_updates_header, listView, false);
|
// View header = inflater.inflate(R.layout.live_updates_header, listView, false);
|
||||||
|
|
||||||
final OsmandSettings settings = getMyActivity().getMyApplication().getSettings();
|
|
||||||
|
|
||||||
final TextView onOffTextView = (TextView) header.findViewById(R.id.onOffTextView);
|
|
||||||
int liveUpdatesStateId = settings.IS_LIVE_UPDATES_ON.get()
|
|
||||||
? R.string.shared_string_on : R.string.shared_string_off;
|
|
||||||
onOffTextView.setText(liveUpdatesStateId);
|
|
||||||
|
|
||||||
SwitchCompat liveUpdatesSwitch = (SwitchCompat) header.findViewById(R.id.liveUpdatesSwitch);
|
|
||||||
liveUpdatesSwitch.setChecked(settings.IS_LIVE_UPDATES_ON.get());
|
|
||||||
liveUpdatesSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
settings.IS_LIVE_UPDATES_ON.set(isChecked);
|
|
||||||
int liveUpdatesStateId = isChecked ? R.string.shared_string_on
|
|
||||||
: R.string.shared_string_off;
|
|
||||||
onOffTextView.setText(liveUpdatesStateId);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
listView.addHeaderView(header);
|
|
||||||
adapter = new LocalIndexesAdapter(this);
|
adapter = new LocalIndexesAdapter(this);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
new LoadLocalIndexTask(adapter, this).execute();
|
new LoadLocalIndexTask(adapter, this).execute();
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OsmandSettings getSettings() {
|
||||||
|
return getMyActivity().getMyApplication().getSettings();
|
||||||
|
}
|
||||||
|
|
||||||
private AbstractDownloadActivity getMyActivity() {
|
private AbstractDownloadActivity getMyActivity() {
|
||||||
return (AbstractDownloadActivity) getActivity();
|
return (AbstractDownloadActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
@ -100,6 +86,8 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
|
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
|
public static final int SHOULD_UPDATE_GROUP_POSITION = 0;
|
||||||
|
public static final int SHOULD_NOT_UPDATE_GROUP_POSITION = 1;
|
||||||
final ArrayList<LocalIndexInfo> dataShouldUpdate = new ArrayList<>();
|
final ArrayList<LocalIndexInfo> dataShouldUpdate = new ArrayList<>();
|
||||||
final ArrayList<LocalIndexInfo> dataShouldNotUpdate = new ArrayList<>();
|
final ArrayList<LocalIndexInfo> dataShouldNotUpdate = new ArrayList<>();
|
||||||
final LiveUpdatesFragment fragment;
|
final LiveUpdatesFragment fragment;
|
||||||
|
@ -111,8 +99,8 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(LocalIndexInfo info) {
|
public void add(LocalIndexInfo info) {
|
||||||
OsmandSettings.CommonPreference<Boolean> preference =
|
OsmandSettings.CommonPreference<Boolean> preference = preferenceLiveUpdatesOn(info,
|
||||||
preferenceForLocalIndex(LIVE_UPDATES_ON_POSTFIX, info);
|
getSettings());
|
||||||
if (preference.get()) {
|
if (preference.get()) {
|
||||||
dataShouldUpdate.add(info);
|
dataShouldUpdate.add(info);
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,7 +112,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
Set<LocalIndexInfo> changedSet = new HashSet<>();
|
Set<LocalIndexInfo> changedSet = new HashSet<>();
|
||||||
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
|
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
|
||||||
OsmandSettings.CommonPreference<Boolean> preference =
|
OsmandSettings.CommonPreference<Boolean> preference =
|
||||||
preferenceForLocalIndex(LIVE_UPDATES_ON_POSTFIX, localIndexInfo);
|
preferenceLiveUpdatesOn(localIndexInfo, getSettings());
|
||||||
if (!preference.get()) {
|
if (!preference.get()) {
|
||||||
changedSet.add(localIndexInfo);
|
changedSet.add(localIndexInfo);
|
||||||
}
|
}
|
||||||
|
@ -134,7 +122,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
changedSet.clear();
|
changedSet.clear();
|
||||||
for (LocalIndexInfo localIndexInfo : dataShouldNotUpdate) {
|
for (LocalIndexInfo localIndexInfo : dataShouldNotUpdate) {
|
||||||
OsmandSettings.CommonPreference<Boolean> preference =
|
OsmandSettings.CommonPreference<Boolean> preference =
|
||||||
preferenceForLocalIndex(LIVE_UPDATES_ON_POSTFIX, localIndexInfo);
|
preferenceLiveUpdatesOn(localIndexInfo, getSettings());
|
||||||
if (preference.get()) {
|
if (preference.get()) {
|
||||||
changedSet.add(localIndexInfo);
|
changedSet.add(localIndexInfo);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +160,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
LocalFullMapsViewHolder viewHolder;
|
LocalFullMapsViewHolder viewHolder;
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(ctx);
|
LayoutInflater inflater = LayoutInflater.from(ctx);
|
||||||
convertView = inflater.inflate(R.layout.local_index_list_item, parent, false);
|
convertView = inflater.inflate(R.layout.local_index_live_updates_list_item, parent, false);
|
||||||
viewHolder = new LocalFullMapsViewHolder(convertView, fragment);
|
viewHolder = new LocalFullMapsViewHolder(convertView, fragment);
|
||||||
convertView.setTag(viewHolder);
|
convertView.setTag(viewHolder);
|
||||||
} else {
|
} else {
|
||||||
|
@ -182,7 +170,6 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getNameToDisplay(LocalIndexInfo child) {
|
private String getNameToDisplay(LocalIndexInfo child) {
|
||||||
String mapName = FileNameTranslationHelper.getFileName(ctx,
|
String mapName = FileNameTranslationHelper.getFileName(ctx,
|
||||||
fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(),
|
fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(),
|
||||||
|
@ -196,7 +183,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
String group = getGroup(groupPosition);
|
String group = getGroup(groupPosition);
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(ctx);
|
LayoutInflater inflater = LayoutInflater.from(ctx);
|
||||||
v = inflater.inflate(R.layout.download_item_list_section, parent, false);
|
v = inflater.inflate(R.layout.list_group_title_with_switch, parent, false);
|
||||||
}
|
}
|
||||||
TextView nameView = ((TextView) v.findViewById(R.id.section_name));
|
TextView nameView = ((TextView) v.findViewById(R.id.section_name));
|
||||||
nameView.setText(group);
|
nameView.setText(group);
|
||||||
|
@ -207,14 +194,32 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
Resources.Theme theme = ctx.getTheme();
|
Resources.Theme theme = ctx.getTheme();
|
||||||
theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
|
theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
|
||||||
v.setBackgroundColor(typedValue.data);
|
v.setBackgroundColor(typedValue.data);
|
||||||
|
|
||||||
|
SwitchCompat liveUpdatesSwitch = (SwitchCompat) v.findViewById(R.id.liveUpdatesSwitch);
|
||||||
|
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
|
||||||
|
liveUpdatesSwitch.setVisibility(View.VISIBLE);
|
||||||
|
OsmandApplication application = (OsmandApplication) ctx.getApplicationContext();
|
||||||
|
final OsmandSettings settings = application.getSettings();
|
||||||
|
liveUpdatesSwitch.setChecked(settings.IS_LIVE_UPDATES_ON.get());
|
||||||
|
liveUpdatesSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
settings.IS_LIVE_UPDATES_ON.set(isChecked);
|
||||||
|
int liveUpdatesStateId = isChecked ? R.string.shared_string_on
|
||||||
|
: R.string.shared_string_off;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
liveUpdatesSwitch.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChildrenCount(int groupPosition) {
|
public int getChildrenCount(int groupPosition) {
|
||||||
if (groupPosition == 0) {
|
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
|
||||||
return dataShouldUpdate.size();
|
return dataShouldUpdate.size();
|
||||||
} else if (groupPosition == 1) {
|
} else if (groupPosition == SHOULD_NOT_UPDATE_GROUP_POSITION) {
|
||||||
return dataShouldNotUpdate.size();
|
return dataShouldNotUpdate.size();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("unexpected group position:" + groupPosition);
|
throw new IllegalArgumentException("unexpected group position:" + groupPosition);
|
||||||
|
@ -223,9 +228,9 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGroup(int groupPosition) {
|
public String getGroup(int groupPosition) {
|
||||||
if (groupPosition == 0) {
|
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
|
||||||
return getString(R.string.live_updates_on);
|
return getString(R.string.live_updates_on);
|
||||||
} else if (groupPosition == 1) {
|
} else if (groupPosition == SHOULD_NOT_UPDATE_GROUP_POSITION) {
|
||||||
return getString(R.string.live_updates_off);
|
return getString(R.string.live_updates_off);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("unexpected group position:" + groupPosition);
|
throw new IllegalArgumentException("unexpected group position:" + groupPosition);
|
||||||
|
@ -252,14 +257,18 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(String idPostfix,
|
|
||||||
LocalIndexInfo item) {
|
}
|
||||||
|
|
||||||
|
private static OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(
|
||||||
|
String idPostfix,
|
||||||
|
LocalIndexInfo item,
|
||||||
|
LiveUpdatesFragment fragment) {
|
||||||
final OsmandApplication myApplication = fragment.getMyActivity().getMyApplication();
|
final OsmandApplication myApplication = fragment.getMyActivity().getMyApplication();
|
||||||
final OsmandSettings settings = myApplication.getSettings();
|
final OsmandSettings settings = myApplication.getSettings();
|
||||||
final String settingId = item.getFileName() + idPostfix;
|
final String settingId = item.getFileName() + idPostfix;
|
||||||
return settings.registerBooleanPreference(settingId, false);
|
return settings.registerBooleanPreference(settingId, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void expandAllGroups() {
|
private void expandAllGroups() {
|
||||||
for (int i = 0; i < adapter.getGroupCount(); i++) {
|
for (int i = 0; i < adapter.getGroupCount(); i++) {
|
||||||
|
@ -279,6 +288,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
private static class LocalFullMapsViewHolder {
|
private static class LocalFullMapsViewHolder {
|
||||||
private final ImageView icon;
|
private final ImageView icon;
|
||||||
private final TextView nameTextView;
|
private final TextView nameTextView;
|
||||||
|
private final TextView subheaderTextView;
|
||||||
private final TextView descriptionTextView;
|
private final TextView descriptionTextView;
|
||||||
private final ImageButton options;
|
private final ImageButton options;
|
||||||
private final LiveUpdatesFragment fragment;
|
private final LiveUpdatesFragment fragment;
|
||||||
|
@ -287,6 +297,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
private LocalFullMapsViewHolder(View view, LiveUpdatesFragment context) {
|
private LocalFullMapsViewHolder(View view, LiveUpdatesFragment context) {
|
||||||
icon = (ImageView) view.findViewById(R.id.icon);
|
icon = (ImageView) view.findViewById(R.id.icon);
|
||||||
nameTextView = (TextView) view.findViewById(R.id.nameTextView);
|
nameTextView = (TextView) view.findViewById(R.id.nameTextView);
|
||||||
|
subheaderTextView = (TextView) view.findViewById(R.id.subheaderTextView);
|
||||||
descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView);
|
descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView);
|
||||||
options = (ImageButton) view.findViewById(R.id.options);
|
options = (ImageButton) view.findViewById(R.id.options);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
@ -294,10 +305,21 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindLocalIndexInfo(final LocalIndexInfo item) {
|
public void bindLocalIndexInfo(final LocalIndexInfo item) {
|
||||||
nameTextView.setText(item.getName());
|
|
||||||
descriptionTextView.setText(item.getDescription());
|
|
||||||
OsmandApplication context = fragment.getMyActivity().getMyApplication();
|
OsmandApplication context = fragment.getMyActivity().getMyApplication();
|
||||||
|
final OsmandSettings.CommonPreference<Boolean> shouldUpdatePreference =
|
||||||
|
preferenceLiveUpdatesOn(item, fragment.getSettings());
|
||||||
|
|
||||||
|
nameTextView.setText(item.getName());
|
||||||
|
if (shouldUpdatePreference.get()) {
|
||||||
|
final Integer frequencyId = preferenceUpdateFrequency(item, fragment.getSettings()).get();
|
||||||
|
final UpdateFrequency frequency = UpdateFrequency.values()[frequencyId];
|
||||||
|
subheaderTextView.setText(frequency.toString());
|
||||||
|
} else {
|
||||||
|
subheaderTextView.setText(item.getSize() + "");
|
||||||
|
}
|
||||||
|
descriptionTextView.setText(item.getDescription());
|
||||||
icon.setImageDrawable(context.getIconsCache().getContentIcon(R.drawable.ic_map));
|
icon.setImageDrawable(context.getIconsCache().getContentIcon(R.drawable.ic_map));
|
||||||
|
|
||||||
final View.OnClickListener clickListener = new View.OnClickListener() {
|
final View.OnClickListener clickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package net.osmand.plus.liveupdates;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by GaidamakUA on 12/18/15.
|
||||||
|
*/
|
||||||
|
public class LiveUpdatesHelper {
|
||||||
|
private static final String UPDATE_TIMES_POSTFIX = "_update_times";
|
||||||
|
private static final String TIME_OF_DAY_TO_UPDATE_POSTFIX = "_time_of_day_to_update";
|
||||||
|
private static final String DOWNLOAD_VIA_WIFI_POSTFIX = "_download_via_wifi";
|
||||||
|
private static final String LIVE_UPDATES_ON_POSTFIX = "_live_updates_on";
|
||||||
|
|
||||||
|
|
||||||
|
public static OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(
|
||||||
|
LocalIndexInfo item, OsmandSettings settings) {
|
||||||
|
final String settingId = item.getFileName() + LIVE_UPDATES_ON_POSTFIX;
|
||||||
|
return settings.registerBooleanPreference(settingId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OsmandSettings.CommonPreference<Boolean> preferenceLiveUpdatesOn(
|
||||||
|
LocalIndexInfo item, OsmandSettings settings) {
|
||||||
|
final String settingId = item.getFileName() + LIVE_UPDATES_ON_POSTFIX;
|
||||||
|
return settings.registerBooleanPreference(settingId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OsmandSettings.CommonPreference<Boolean> preferenceDownloadViaWiFi(
|
||||||
|
LocalIndexInfo item, OsmandSettings settings) {
|
||||||
|
final String settingId = item.getFileName() + DOWNLOAD_VIA_WIFI_POSTFIX;
|
||||||
|
return settings.registerBooleanPreference(settingId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OsmandSettings.CommonPreference<Integer> preferenceUpdateFrequency(
|
||||||
|
LocalIndexInfo item, OsmandSettings settings) {
|
||||||
|
final String settingId = item.getFileName() + UPDATE_TIMES_POSTFIX;
|
||||||
|
return settings.registerIntPreference(settingId, UpdateFrequency.HOURLY.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OsmandSettings.CommonPreference<Integer> preferenceTimeOfDayToUpdate(
|
||||||
|
LocalIndexInfo item, OsmandSettings settings) {
|
||||||
|
final String settingId = item.getFileName() + TIME_OF_DAY_TO_UPDATE_POSTFIX;
|
||||||
|
return settings.registerIntPreference(settingId, TimesOfDay.NIGHT.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum TimesOfDay {
|
||||||
|
MORNING,
|
||||||
|
NIGHT
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum UpdateFrequency {
|
||||||
|
HOURLY,
|
||||||
|
DAILY,
|
||||||
|
WEEKLY
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,16 +27,21 @@ import net.osmand.util.Algorithms;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.TimesOfDay;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.UpdateFrequency;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceDownloadViaWiFi;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceForLocalIndex;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceTimeOfDayToUpdate;
|
||||||
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
|
||||||
|
|
||||||
public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
||||||
|
private static final String LOCAL_INDEX = "local_index";
|
||||||
public static final String LOCAL_INDEX_INFO = "local_index_info";
|
public static final String LOCAL_INDEX_INFO = "local_index_info";
|
||||||
|
|
||||||
private static final String LOCAL_INDEX = "local_index";
|
|
||||||
public static final String UPDATE_TIMES_POSTFIX = "_update_times";
|
|
||||||
private static final String TIME_OF_DAY_TO_UPDATE_POSTFIX = "_time_of_day_to_update";
|
|
||||||
private static final int MORNING_UPDATE_TIME = 8;
|
private static final int MORNING_UPDATE_TIME = 8;
|
||||||
private static final int NIGHT_UPDATE_TIME = 21;
|
private static final int NIGHT_UPDATE_TIME = 21;
|
||||||
private static final int SHIFT = 1000;
|
private static final int SHIFT = 1000;
|
||||||
public static final String DOWNLOAD_VIA_WIFI_POSTFIX = "_download_via_wifi";
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,13 +62,13 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
||||||
// countryNameTextView.setText(localIndexInfo.getWorldRegion().getLocaleName());
|
// countryNameTextView.setText(localIndexInfo.getWorldRegion().getLocaleName());
|
||||||
countryNameTextView.setVisibility(View.VISIBLE);
|
countryNameTextView.setVisibility(View.VISIBLE);
|
||||||
final OsmandSettings.CommonPreference<Boolean> liveUpdatePreference =
|
final OsmandSettings.CommonPreference<Boolean> liveUpdatePreference =
|
||||||
preferenceForLocalIndex(localIndexInfo);
|
preferenceForLocalIndex(localIndexInfo, getSettings());
|
||||||
final OsmandSettings.CommonPreference<Boolean> downloadViaWiFiPreference =
|
final OsmandSettings.CommonPreference<Boolean> downloadViaWiFiPreference =
|
||||||
preferenceDownloadViaWiFi(localIndexInfo);
|
preferenceDownloadViaWiFi(localIndexInfo, getSettings());
|
||||||
final OsmandSettings.CommonPreference<Integer> updateFrequencePreference =
|
final OsmandSettings.CommonPreference<Integer> updateFrequencePreference =
|
||||||
preferenceUpdateTimes(localIndexInfo);
|
preferenceUpdateFrequency(localIndexInfo, getSettings());
|
||||||
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
|
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
|
||||||
preferenceTimeOfDayToUpdate(localIndexInfo);
|
preferenceTimeOfDayToUpdate(localIndexInfo, getSettings());
|
||||||
liveUpdatesSwitch.setChecked(liveUpdatePreference.get());
|
liveUpdatesSwitch.setChecked(liveUpdatePreference.get());
|
||||||
downloadOverWiFiSwitch.setChecked(downloadViaWiFiPreference.get());
|
downloadOverWiFiSwitch.setChecked(downloadViaWiFiPreference.get());
|
||||||
|
|
||||||
|
@ -73,7 +78,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
final int updateFrequencyInt = updateFrequencySpinner.getSelectedItemPosition();
|
final int updateFrequencyInt = updateFrequencySpinner.getSelectedItemPosition();
|
||||||
updateFrequencePreference.set(updateFrequencyInt);
|
updateFrequencePreference.set(updateFrequencyInt);
|
||||||
UpdateFrequencies updateFrequency = UpdateFrequencies.values()[updateFrequencyInt];
|
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyInt];
|
||||||
|
|
||||||
AlarmManager alarmMgr = (AlarmManager) getActivity()
|
AlarmManager alarmMgr = (AlarmManager) getActivity()
|
||||||
.getSystemService(Context.ALARM_SERVICE);
|
.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
@ -129,7 +134,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
||||||
updateFrequencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
updateFrequencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
UpdateFrequencies updateFrequency = UpdateFrequencies.values()[position];
|
UpdateFrequency updateFrequency = UpdateFrequency.values()[position];
|
||||||
switch (updateFrequency) {
|
switch (updateFrequency) {
|
||||||
case HOURLY:
|
case HOURLY:
|
||||||
updateTimesOfDaySpinner.setVisibility(View.GONE);
|
updateTimesOfDaySpinner.setVisibility(View.GONE);
|
||||||
|
@ -166,26 +171,6 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
||||||
return (LiveUpdatesFragment) getParentFragment();
|
return (LiveUpdatesFragment) getParentFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
private OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(LocalIndexInfo item) {
|
|
||||||
final String settingId = item.getFileName() + LiveUpdatesFragment.LIVE_UPDATES_ON_POSTFIX;
|
|
||||||
return getSettings().registerBooleanPreference(settingId, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private OsmandSettings.CommonPreference<Boolean> preferenceDownloadViaWiFi(LocalIndexInfo item) {
|
|
||||||
final String settingId = item.getFileName() + DOWNLOAD_VIA_WIFI_POSTFIX;
|
|
||||||
return getSettings().registerBooleanPreference(settingId, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private OsmandSettings.CommonPreference<Integer> preferenceUpdateTimes(LocalIndexInfo item) {
|
|
||||||
final String settingId = item.getFileName() + UPDATE_TIMES_POSTFIX;
|
|
||||||
return getSettings().registerIntPreference(settingId, UpdateFrequencies.HOURLY.ordinal());
|
|
||||||
}
|
|
||||||
|
|
||||||
private OsmandSettings.CommonPreference<Integer> preferenceTimeOfDayToUpdate(LocalIndexInfo item) {
|
|
||||||
final String settingId = item.getFileName() + TIME_OF_DAY_TO_UPDATE_POSTFIX;
|
|
||||||
return getSettings().registerIntPreference(settingId, TimesOfDay.NIGHT.ordinal());
|
|
||||||
}
|
|
||||||
|
|
||||||
private OsmandSettings getSettings() {
|
private OsmandSettings getSettings() {
|
||||||
return getMyApplication().getSettings();
|
return getMyApplication().getSettings();
|
||||||
}
|
}
|
||||||
|
@ -201,15 +186,4 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum UpdateFrequencies {
|
|
||||||
HOURLY,
|
|
||||||
DAILY,
|
|
||||||
WEEKLY
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum TimesOfDay {
|
|
||||||
MORNING,
|
|
||||||
NIGHT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue