Creaded abstract downloads activity with download functionality. ListView replaced with ExpandableListView. Grouping isn't working correctly yet.
This commit is contained in:
parent
2a75315b62
commit
b4d81d1667
7 changed files with 366 additions and 102 deletions
|
@ -1,7 +1,9 @@
|
||||||
<ListView android:id="@android:id/list"
|
<ExpandableListView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:id="@android:id/list"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical"
|
android:layout_height="match_parent"
|
||||||
tools:context=".liveupdates.LiveUpdatesFragment"/>
|
android:groupIndicator="@null"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context=".liveupdates.LiveUpdatesFragment"/>
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package net.osmand.plus.activities;
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
import java.io.File;
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||||
|
|
||||||
public class LocalIndexInfo {
|
import java.io.File;
|
||||||
|
|
||||||
|
public class LocalIndexInfo implements Parcelable {
|
||||||
|
|
||||||
private LocalIndexType type;
|
private LocalIndexType type;
|
||||||
private String description = "";
|
private String description = "";
|
||||||
|
@ -155,4 +158,52 @@ public class LocalIndexInfo {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(this.type == null ? -1 : this.type.ordinal());
|
||||||
|
dest.writeString(this.description);
|
||||||
|
dest.writeString(this.name);
|
||||||
|
dest.writeByte(backupedData ? (byte) 1 : (byte) 0);
|
||||||
|
dest.writeByte(corrupted ? (byte) 1 : (byte) 0);
|
||||||
|
dest.writeByte(notSupported ? (byte) 1 : (byte) 0);
|
||||||
|
dest.writeByte(loaded ? (byte) 1 : (byte) 0);
|
||||||
|
dest.writeString(this.subfolder);
|
||||||
|
dest.writeString(this.pathToData);
|
||||||
|
dest.writeString(this.fileName);
|
||||||
|
dest.writeByte(singleFile ? (byte) 1 : (byte) 0);
|
||||||
|
dest.writeInt(this.kbSize);
|
||||||
|
dest.writeByte(expanded ? (byte) 1 : (byte) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected LocalIndexInfo(Parcel in) {
|
||||||
|
int tmpType = in.readInt();
|
||||||
|
this.type = tmpType == -1 ? null : LocalIndexType.values()[tmpType];
|
||||||
|
this.description = in.readString();
|
||||||
|
this.name = in.readString();
|
||||||
|
this.backupedData = in.readByte() != 0;
|
||||||
|
this.corrupted = in.readByte() != 0;
|
||||||
|
this.notSupported = in.readByte() != 0;
|
||||||
|
this.loaded = in.readByte() != 0;
|
||||||
|
this.subfolder = in.readString();
|
||||||
|
this.pathToData = in.readString();
|
||||||
|
this.fileName = in.readString();
|
||||||
|
this.singleFile = in.readByte() != 0;
|
||||||
|
this.kbSize = in.readInt();
|
||||||
|
this.expanded = in.readByte() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<LocalIndexInfo> CREATOR = new Parcelable.Creator<LocalIndexInfo>() {
|
||||||
|
public LocalIndexInfo createFromParcel(Parcel source) {
|
||||||
|
return new LocalIndexInfo(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalIndexInfo[] newArray(int size) {
|
||||||
|
return new LocalIndexInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package net.osmand.plus.download;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import net.osmand.plus.activities.ActionBarProgressActivity;
|
||||||
|
|
||||||
|
public class AbstractDownloadActivity extends ActionBarProgressActivity {
|
||||||
|
protected DownloadValidationManager downloadValidationManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
downloadValidationManager = new DownloadValidationManager(getMyApplication());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startDownload(IndexItem... indexItem) {
|
||||||
|
downloadValidationManager.startDownload(this, indexItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void makeSureUserCancelDownload(IndexItem item) {
|
||||||
|
downloadValidationManager.makeSureUserCancelDownload(this, item);
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,7 +41,6 @@ import net.osmand.plus.OsmandSettings.DrivingRegion;
|
||||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
import net.osmand.plus.activities.ActionBarProgressActivity;
|
|
||||||
import net.osmand.plus.activities.LocalIndexInfo;
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.TabActivity;
|
import net.osmand.plus.activities.TabActivity;
|
||||||
|
@ -68,7 +67,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DownloadActivity extends ActionBarProgressActivity implements DownloadEvents {
|
public class DownloadActivity extends AbstractDownloadActivity implements DownloadEvents {
|
||||||
private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class);
|
private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class);
|
||||||
|
|
||||||
public static final int UPDATES_TAB_NUMBER = 2;
|
public static final int UPDATES_TAB_NUMBER = 2;
|
||||||
|
@ -98,7 +97,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
|
||||||
private String filterGroup;
|
private String filterGroup;
|
||||||
protected Set<WeakReference<Fragment>> fragSet = new HashSet<>();
|
protected Set<WeakReference<Fragment>> fragSet = new HashSet<>();
|
||||||
private DownloadIndexesThread downloadThread;
|
private DownloadIndexesThread downloadThread;
|
||||||
private DownloadValidationManager downloadValidationManager;
|
|
||||||
protected WorldRegion downloadItem;
|
protected WorldRegion downloadItem;
|
||||||
|
|
||||||
private boolean srtmDisabled;
|
private boolean srtmDisabled;
|
||||||
|
@ -110,7 +108,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
getMyApplication().applyTheme(this);
|
getMyApplication().applyTheme(this);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
downloadValidationManager = new DownloadValidationManager(getMyApplication());
|
|
||||||
downloadThread = getMyApplication().getDownloadThread();
|
downloadThread = getMyApplication().getDownloadThread();
|
||||||
DownloadResources indexes = getDownloadThread().getIndexes();
|
DownloadResources indexes = getDownloadThread().getIndexes();
|
||||||
if (!indexes.isDownloadedFromInternet) {
|
if (!indexes.isDownloadedFromInternet) {
|
||||||
|
@ -165,14 +162,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
|
||||||
return downloadThread;
|
return downloadThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDownload(IndexItem... indexItem) {
|
|
||||||
downloadValidationManager.startDownload(this, indexItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void makeSureUserCancelDownload(IndexItem item) {
|
|
||||||
downloadValidationManager.makeSureUserCancelDownload(this, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachFragment(Fragment fragment) {
|
public void onAttachFragment(Fragment fragment) {
|
||||||
fragSet.add(new WeakReference<Fragment>(fragment));
|
fragSet.add(new WeakReference<Fragment>(fragment));
|
||||||
|
|
|
@ -8,9 +8,9 @@ import android.support.v4.app.FragmentPagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.ActionBarProgressActivity;
|
import net.osmand.plus.download.AbstractDownloadActivity;
|
||||||
|
|
||||||
public class LiveUpdatesActivity extends ActionBarProgressActivity {
|
public class LiveUpdatesActivity extends AbstractDownloadActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -18,9 +18,8 @@ public class LiveUpdatesActivity extends ActionBarProgressActivity {
|
||||||
setContentView(R.layout.activity_livie_updates);
|
setContentView(R.layout.activity_livie_updates);
|
||||||
|
|
||||||
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
|
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
|
||||||
String basicTitle = getResources().getString(R.string.tab_title_basic);
|
final LiveUpdatesFragmentPagerAdapter pagerAdapter =
|
||||||
String extendedTitle = getResources().getString(R.string.tab_title_advanced);
|
new LiveUpdatesFragmentPagerAdapter(getSupportFragmentManager());
|
||||||
final MyAdapter pagerAdapter = new MyAdapter(getSupportFragmentManager());
|
|
||||||
viewPager.setAdapter(pagerAdapter);
|
viewPager.setAdapter(pagerAdapter);
|
||||||
|
|
||||||
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
||||||
|
@ -28,11 +27,11 @@ public class LiveUpdatesActivity extends ActionBarProgressActivity {
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MyAdapter extends FragmentPagerAdapter {
|
public static class LiveUpdatesFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||||
private final Fragment[] fragments = new Fragment[]{new LiveUpdatesFragment()};
|
private final Fragment[] fragments = new Fragment[]{new LiveUpdatesFragment()};
|
||||||
private final String[] titles = new String[]{LiveUpdatesFragment.TITILE};
|
private final String[] titles = new String[]{LiveUpdatesFragment.TITILE};
|
||||||
|
|
||||||
public MyAdapter(FragmentManager fm) {
|
public LiveUpdatesFragmentPagerAdapter(FragmentManager fm) {
|
||||||
super(fm);
|
super(fm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +49,5 @@ public class LiveUpdatesActivity extends ActionBarProgressActivity {
|
||||||
public CharSequence getPageTitle(int position) {
|
public CharSequence getPageTitle(int position) {
|
||||||
return titles[position];
|
return titles[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +1,53 @@
|
||||||
package net.osmand.plus.liveupdates;
|
package net.osmand.plus.liveupdates;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.app.Dialog;
|
import android.content.res.Resources;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.ExpandableListView;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.ActionBarProgressActivity;
|
|
||||||
import net.osmand.plus.activities.LocalIndexHelper;
|
import net.osmand.plus.activities.LocalIndexHelper;
|
||||||
import net.osmand.plus.activities.LocalIndexInfo;
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||||
|
import net.osmand.plus.download.AbstractDownloadActivity;
|
||||||
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
|
import net.osmand.plus.download.IndexItem;
|
||||||
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
|
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
|
||||||
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
|
import net.osmand.plus.resources.IncrementalChangesManager;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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 Comparator<LocalIndexInfo> LOCAL_INDEX_INFO_COMPARATOR = new Comparator<LocalIndexInfo>() {
|
||||||
|
@Override
|
||||||
|
public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) {
|
||||||
|
return lhs.getName().compareTo(rhs.getName());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private ExpandableListView listView;
|
||||||
|
private LocalIndexesAdapter adapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -45,7 +58,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
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 listView = (ListView) 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 OsmandSettings settings = getMyActivity().getMyApplication().getSettings();
|
||||||
|
@ -69,35 +82,190 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
});
|
});
|
||||||
|
|
||||||
listView.addHeaderView(header);
|
listView.addHeaderView(header);
|
||||||
LiveUpdatesAdapter adapter = new LiveUpdatesAdapter(this);
|
adapter = new LocalIndexesAdapter(this);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
new LoadLocalIndexTask(adapter, (ActionBarProgressActivity) getActivity()).execute();
|
new LoadLocalIndexTask(adapter, this).execute();
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OsmandActionBarActivity getMyActivity() {
|
private AbstractDownloadActivity getMyActivity() {
|
||||||
return (OsmandActionBarActivity) getActivity();
|
return (AbstractDownloadActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LiveUpdatesAdapter extends ArrayAdapter<LocalIndexInfo> {
|
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
|
final ArrayList<LocalIndexInfo> dataShouldUpdate = new ArrayList<>();
|
||||||
|
final ArrayList<LocalIndexInfo> dataShouldNotUpdate = new ArrayList<>();
|
||||||
final LiveUpdatesFragment fragment;
|
final LiveUpdatesFragment fragment;
|
||||||
public LiveUpdatesAdapter(LiveUpdatesFragment fragment) {
|
final Context ctx;
|
||||||
super(fragment.getActivity(), R.layout.local_index_list_item, R.id.nameTextView);
|
|
||||||
|
public LocalIndexesAdapter(LiveUpdatesFragment fragment) {
|
||||||
this.fragment = fragment;
|
this.fragment = fragment;
|
||||||
|
ctx = fragment.getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(LocalIndexInfo info) {
|
||||||
|
dataShouldNotUpdate.add(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort() {
|
||||||
|
Collections.sort(dataShouldUpdate, LOCAL_INDEX_INFO_COMPARATOR);
|
||||||
|
Collections.sort(dataShouldNotUpdate, LOCAL_INDEX_INFO_COMPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public LocalIndexInfo getChild(int groupPosition, int childPosition) {
|
||||||
View view = convertView;
|
if (groupPosition == 0) {
|
||||||
if (view == null) {
|
return dataShouldUpdate.get(childPosition);
|
||||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
} else if (groupPosition == 1) {
|
||||||
view = inflater.inflate(R.layout.local_index_list_item, parent, false);
|
return dataShouldNotUpdate.get(childPosition);
|
||||||
view.setTag(new LocalFullMapsViewHolder(view, fragment));
|
} else {
|
||||||
|
throw new IllegalArgumentException("unexpected group position:" + groupPosition);
|
||||||
}
|
}
|
||||||
LocalFullMapsViewHolder viewHolder = (LocalFullMapsViewHolder) view.getTag();
|
|
||||||
viewHolder.bindLocalIndexInfo(getItem(position));
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getChildId(int groupPosition, int childPosition) {
|
||||||
|
// it would be unusable to have 10000 local indexes
|
||||||
|
return groupPosition * 10000 + childPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getChildView(final int groupPosition, final int childPosition,
|
||||||
|
boolean isLastChild, View convertView, ViewGroup parent) {
|
||||||
|
LocalFullMapsViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(ctx);
|
||||||
|
convertView = inflater.inflate(R.layout.local_index_list_item, parent, false);
|
||||||
|
viewHolder = new LocalFullMapsViewHolder(convertView, fragment);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (LocalFullMapsViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
viewHolder.bindLocalIndexInfo(getChild(groupPosition, childPosition));
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getNameToDisplay(LocalIndexInfo child) {
|
||||||
|
String mapName = FileNameTranslationHelper.getFileName(ctx,
|
||||||
|
fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(),
|
||||||
|
child.getFileName());
|
||||||
|
return mapName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
|
||||||
|
View v = convertView;
|
||||||
|
String group = getGroup(groupPosition);
|
||||||
|
if (v == null) {
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(ctx);
|
||||||
|
v = inflater.inflate(R.layout.download_item_list_section, parent, false);
|
||||||
|
}
|
||||||
|
TextView nameView = ((TextView) v.findViewById(R.id.section_name));
|
||||||
|
nameView.setText(group);
|
||||||
|
|
||||||
|
v.setOnClickListener(null);
|
||||||
|
|
||||||
|
TypedValue typedValue = new TypedValue();
|
||||||
|
Resources.Theme theme = ctx.getTheme();
|
||||||
|
theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
|
||||||
|
v.setBackgroundColor(typedValue.data);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getChildrenCount(int groupPosition) {
|
||||||
|
if (groupPosition == 0) {
|
||||||
|
return dataShouldUpdate.size();
|
||||||
|
} else if (groupPosition == 1) {
|
||||||
|
return dataShouldNotUpdate.size();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("unexpected group position:" + groupPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroup(int groupPosition) {
|
||||||
|
if (groupPosition == 0) {
|
||||||
|
return "Live updates on";
|
||||||
|
} else if (groupPosition == 1) {
|
||||||
|
return "Love updates off";
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("unexpected group position:" + groupPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getGroupCount() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getGroupId(int groupPosition) {
|
||||||
|
return groupPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasStableIds() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChildSelectable(int groupPosition, int childPosition) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expandAllGroups() {
|
||||||
|
for (int i = 0; i < adapter.getGroupCount(); i++) {
|
||||||
|
listView.expandGroup(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void runLiveUpdate(final LocalIndexInfo info) {
|
||||||
|
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName()));
|
||||||
|
new AsyncTask<Object, Object, IncrementalChangesManager.IncrementalUpdateList>() {
|
||||||
|
|
||||||
|
protected void onPreExecute() {
|
||||||
|
getMyActivity().setSupportProgressBarIndeterminateVisibility(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IncrementalChangesManager.IncrementalUpdateList doInBackground(Object... params) {
|
||||||
|
final OsmandApplication myApplication = getMyActivity().getMyApplication();
|
||||||
|
IncrementalChangesManager cm = myApplication.getResourceManager().getChangesManager();
|
||||||
|
return cm.getUpdatesByMonth(fnExt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPostExecute(IncrementalChangesManager.IncrementalUpdateList result) {
|
||||||
|
getMyActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||||
|
if (result.errorMessage != null) {
|
||||||
|
Toast.makeText(getActivity(), result.errorMessage, Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
List<IncrementalChangesManager.IncrementalUpdate> ll = result.getItemsForUpdate();
|
||||||
|
if (ll.isEmpty()) {
|
||||||
|
Toast.makeText(getActivity(), R.string.no_updates_available, Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
int i = 0;
|
||||||
|
IndexItem[] is = new IndexItem[ll.size()];
|
||||||
|
for (IncrementalChangesManager.IncrementalUpdate iu : ll) {
|
||||||
|
IndexItem ii = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText,
|
||||||
|
iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
|
||||||
|
is[i++] = ii;
|
||||||
|
}
|
||||||
|
getMyActivity().startDownload(is);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}.execute(new Object[]{fnExt});
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalIndexInfo getLocalIndexInfo(int groupPosition, int childPosition) {
|
||||||
|
return adapter.getChild(groupPosition, childPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LocalFullMapsViewHolder {
|
private static class LocalFullMapsViewHolder {
|
||||||
|
@ -115,7 +283,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
this.fragment = context;
|
this.fragment = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindLocalIndexInfo(LocalIndexInfo item) {
|
public void bindLocalIndexInfo(final LocalIndexInfo item) {
|
||||||
nameTextView.setText(item.getName());
|
nameTextView.setText(item.getName());
|
||||||
descriptionTextView.setText(item.getDescription());
|
descriptionTextView.setText(item.getDescription());
|
||||||
OsmandApplication context = fragment.getMyActivity().getMyApplication();
|
OsmandApplication context = fragment.getMyActivity().getMyApplication();
|
||||||
|
@ -124,7 +292,7 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final FragmentManager fragmentManager = fragment.getChildFragmentManager();
|
final FragmentManager fragmentManager = fragment.getChildFragmentManager();
|
||||||
new SettingsDialogFragment().show(fragmentManager, "settings");
|
SettingsDialogFragment.createInstance(item).show(fragmentManager, "settings");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -135,18 +303,18 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
implements AbstractLoadLocalIndexTask {
|
implements AbstractLoadLocalIndexTask {
|
||||||
|
|
||||||
private List<LocalIndexInfo> result;
|
private List<LocalIndexInfo> result;
|
||||||
private ArrayAdapter<LocalIndexInfo> adapter;
|
private LocalIndexesAdapter adapter;
|
||||||
private ActionBarProgressActivity activity;
|
private LiveUpdatesFragment fragment;
|
||||||
|
|
||||||
public LoadLocalIndexTask(ArrayAdapter<LocalIndexInfo> adapter,
|
public LoadLocalIndexTask(LocalIndexesAdapter adapter,
|
||||||
ActionBarProgressActivity activity) {
|
LiveUpdatesFragment fragment) {
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
this.activity = activity;
|
this.fragment = fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<LocalIndexInfo> doInBackground(Void... params) {
|
protected List<LocalIndexInfo> doInBackground(Void... params) {
|
||||||
LocalIndexHelper helper = new LocalIndexHelper(activity.getMyApplication());
|
LocalIndexHelper helper = new LocalIndexHelper(fragment.getMyActivity().getMyApplication());
|
||||||
return helper.getLocalIndexData(this);
|
return helper.getLocalIndexData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,49 +331,14 @@ public class LiveUpdatesFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
|
fragment.expandAllGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(List<LocalIndexInfo> result) {
|
protected void onPostExecute(List<LocalIndexInfo> result) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
adapter.sort(new Comparator<LocalIndexInfo>() {
|
adapter.sort();
|
||||||
@Override
|
|
||||||
public int compare(@NonNull LocalIndexInfo lhs, @NonNull LocalIndexInfo rhs) {
|
|
||||||
return lhs.getName().compareTo(rhs.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SettingsDialogFragment extends DialogFragment {
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
||||||
View view = LayoutInflater.from(getActivity())
|
|
||||||
.inflate(R.layout.dialog_live_updates_item_settings, null);
|
|
||||||
|
|
||||||
builder.setView(view)
|
|
||||||
.setPositiveButton("SAVE", null)
|
|
||||||
.setNegativeButton("CANCEL", null)
|
|
||||||
.setNeutralButton("UPDATE NOW", null);
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initSwitch(ToggleButton toggleButton, 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<Boolean> 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package net.osmand.plus.liveupdates;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
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;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
|
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||||
|
|
||||||
|
public class SettingsDialogFragment extends DialogFragment {
|
||||||
|
public static final String LOCAL_INDEX = "local_index";
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
View view = LayoutInflater.from(getActivity())
|
||||||
|
.inflate(R.layout.dialog_live_updates_item_settings, null);
|
||||||
|
final LocalIndexInfo localIndexInfo = getArguments().getParcelable(LOCAL_INDEX);
|
||||||
|
builder.setView(view)
|
||||||
|
.setPositiveButton("SAVE", null)
|
||||||
|
.setNegativeButton("CANCEL", null)
|
||||||
|
.setNeutralButton("UPDATE NOW", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
getLiveUpdatesFragment().runLiveUpdate(localIndexInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private LiveUpdatesFragment getLiveUpdatesFragment() {
|
||||||
|
return (LiveUpdatesFragment) getParentFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initSwitch(ToggleButton toggleButton, 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<Boolean> 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SettingsDialogFragment createInstance(LocalIndexInfo localIndexInfo) {
|
||||||
|
SettingsDialogFragment fragment = new SettingsDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable(LOCAL_INDEX, localIndexInfo);
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue