From 415633d78804a75da43be23d6a9b6e22c5cb02e9 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Tue, 8 Dec 2015 20:09:32 +0200 Subject: [PATCH] Live updates in progress: draught of UI is done --- OsmAnd/res/layout/activity_livie_updates.xml | 3 +- .../dialog_live_updates_item_settings.xml | 63 ++++++++ OsmAnd/res/layout/fragment_live_updates.xml | 19 +-- OsmAnd/res/layout/live_updates_header.xml | 9 +- .../plus/LiveUpdates/LiveUpdatesFragment.java | 143 ++++++++++++++++-- .../LiveUpdates/LivieUpdatesActivity.java | 6 +- .../activities/ActionBarProgressActivity.java | 4 - .../plus/activities/LocalIndexHelper.java | 23 ++- .../activities/OsmandActionBarActivity.java | 4 + .../plus/download/DownloadActivity.java | 4 - .../ui/AbstractLoadLocalIndexTask.java | 7 + .../download/ui/LocalIndexesFragment.java | 4 +- 12 files changed, 243 insertions(+), 46 deletions(-) create mode 100644 OsmAnd/res/layout/dialog_live_updates_item_settings.xml create mode 100644 OsmAnd/src/net/osmand/plus/download/ui/AbstractLoadLocalIndexTask.java diff --git a/OsmAnd/res/layout/activity_livie_updates.xml b/OsmAnd/res/layout/activity_livie_updates.xml index 2126b7c031..a728c4327c 100644 --- a/OsmAnd/res/layout/activity_livie_updates.xml +++ b/OsmAnd/res/layout/activity_livie_updates.xml @@ -22,7 +22,6 @@ + android:layout_height="match_parent"/> diff --git a/OsmAnd/res/layout/dialog_live_updates_item_settings.xml b/OsmAnd/res/layout/dialog_live_updates_item_settings.xml new file mode 100644 index 0000000000..ab5aba7fa7 --- /dev/null +++ b/OsmAnd/res/layout/dialog_live_updates_item_settings.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_live_updates.xml b/OsmAnd/res/layout/fragment_live_updates.xml index 36bbc04b70..3a254030a0 100644 --- a/OsmAnd/res/layout/fragment_live_updates.xml +++ b/OsmAnd/res/layout/fragment_live_updates.xml @@ -1,12 +1,7 @@ - - - - + diff --git a/OsmAnd/res/layout/live_updates_header.xml b/OsmAnd/res/layout/live_updates_header.xml index f986ed8310..aac6f46050 100644 --- a/OsmAnd/res/layout/live_updates_header.xml +++ b/OsmAnd/res/layout/live_updates_header.xml @@ -1,8 +1,11 @@ - + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> - \ No newline at end of file + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/LiveUpdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/LiveUpdates/LiveUpdatesFragment.java index bfd3e2d9d4..fd0d328788 100644 --- a/OsmAnd/src/net/osmand/plus/LiveUpdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/LiveUpdates/LiveUpdatesFragment.java @@ -1,22 +1,34 @@ package net.osmand.plus.liveupdates; -import android.content.Context; +import android.app.Dialog; +import android.os.AsyncTask; 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.FragmentManager; +import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.ListView; +import android.widget.TextView; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.activities.ActionBarProgressActivity; +import net.osmand.plus.activities.LocalIndexHelper; +import net.osmand.plus.activities.LocalIndexInfo; +import net.osmand.plus.activities.OsmandActionBarActivity; +import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; + +import java.util.Comparator; +import java.util.List; -/** - * A simple {@link Fragment} subclass. - * Use the {@link LiveUpdatesFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class LiveUpdatesFragment extends Fragment { public static final String TITILE = "Live Updates"; @@ -32,13 +44,126 @@ public class LiveUpdatesFragment extends Fragment { ListView listView = (ListView) view.findViewById(android.R.id.list); View header = inflater.inflate(R.layout.live_updates_header, listView, false); listView.addHeaderView(header); + LiveUpdatesAdapter adapter = new LiveUpdatesAdapter(this); + listView.setAdapter(adapter); + new LoadLocalIndexTask(adapter, (ActionBarProgressActivity) getActivity()).execute(); return view; } - private static class LiveUpdatesAdapter extends ArrayAdapter { + private OsmandActionBarActivity getMyActivity() { + return (OsmandActionBarActivity) getActivity(); + } - public LiveUpdatesAdapter(Context context, int resource, Object[] objects) { - super(context, resource, objects); + private static class LiveUpdatesAdapter extends ArrayAdapter { + final LiveUpdatesFragment fragment; + public LiveUpdatesAdapter(LiveUpdatesFragment fragment) { + super(fragment.getActivity(), R.layout.local_index_list_item, R.id.nameTextView); + this.fragment = fragment; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view = convertView; + if (view == null) { + LayoutInflater inflater = LayoutInflater.from(getContext()); + view = inflater.inflate(R.layout.local_index_list_item, parent, false); + view.setTag(new LocalFullMapsViewHolder(view, fragment)); + } + LocalFullMapsViewHolder viewHolder = (LocalFullMapsViewHolder) view.getTag(); + viewHolder.bindLocalIndexInfo(getItem(position)); + return view; + } + } + + private static class LocalFullMapsViewHolder { + private final ImageView icon; + private final TextView nameTextView; + private final TextView descriptionTextView; + private final ImageButton options; + private final LiveUpdatesFragment fragment; + + private LocalFullMapsViewHolder(View view, LiveUpdatesFragment context) { + icon = (ImageView) view.findViewById(R.id.icon); + nameTextView = (TextView) view.findViewById(R.id.nameTextView); + descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView); + options = (ImageButton) view.findViewById(R.id.options); + this.fragment = context; + } + + public void bindLocalIndexInfo(LocalIndexInfo item) { + nameTextView.setText(item.getName()); + descriptionTextView.setText(item.getDescription()); + OsmandApplication context = fragment.getMyActivity().getMyApplication(); + icon.setImageDrawable(context.getIconsCache().getContentIcon(R.drawable.ic_map)); + options.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final FragmentManager fragmentManager = fragment.getChildFragmentManager(); + new SettingsDialogFragment().show(fragmentManager, "settings"); + } + }); + } + } + + public static class LoadLocalIndexTask + extends AsyncTask> + implements AbstractLoadLocalIndexTask { + + private List result; + private ArrayAdapter adapter; + private ActionBarProgressActivity activity; + + public LoadLocalIndexTask(ArrayAdapter adapter, + ActionBarProgressActivity activity) { + this.adapter = adapter; + this.activity = activity; + } + + @Override + protected List doInBackground(Void... params) { + LocalIndexHelper helper = new LocalIndexHelper(activity.getMyApplication()); + return helper.getLocalIndexData(this); + } + + @Override + public void loadFile(LocalIndexInfo... loaded) { + publishProgress(loaded); + } + + @Override + protected void onProgressUpdate(LocalIndexInfo... values) { + for (LocalIndexInfo localIndexInfo : values) { + if (localIndexInfo.getType() == LocalIndexHelper.LocalIndexType.MAP_DATA) { + adapter.add(localIndexInfo); + } + } + adapter.notifyDataSetChanged(); + } + + @Override + protected void onPostExecute(List result) { + this.result = result; + adapter.sort(new Comparator() { + @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(); } } } diff --git a/OsmAnd/src/net/osmand/plus/LiveUpdates/LivieUpdatesActivity.java b/OsmAnd/src/net/osmand/plus/LiveUpdates/LivieUpdatesActivity.java index 954af1ef0b..267b36b3a9 100644 --- a/OsmAnd/src/net/osmand/plus/LiveUpdates/LivieUpdatesActivity.java +++ b/OsmAnd/src/net/osmand/plus/LiveUpdates/LivieUpdatesActivity.java @@ -8,9 +8,9 @@ import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import net.osmand.plus.R; -import net.osmand.plus.activities.OsmandActionBarActivity; +import net.osmand.plus.activities.ActionBarProgressActivity; -public class LivieUpdatesActivity extends OsmandActionBarActivity { +public class LivieUpdatesActivity extends ActionBarProgressActivity { @Override protected void onCreate(Bundle savedInstanceState) { @@ -30,7 +30,7 @@ public class LivieUpdatesActivity extends OsmandActionBarActivity { public static class MyAdapter extends FragmentPagerAdapter { 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) { super(fm); diff --git a/OsmAnd/src/net/osmand/plus/activities/ActionBarProgressActivity.java b/OsmAnd/src/net/osmand/plus/activities/ActionBarProgressActivity.java index 056a5e222e..cf361ad8f5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ActionBarProgressActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ActionBarProgressActivity.java @@ -7,10 +7,6 @@ import android.widget.ProgressBar; import net.osmand.plus.R; -/** - * Created by Denis - * on 23.01.15. - */ public class ActionBarProgressActivity extends OsmandActionBarActivity { @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java index 29d4799793..d6e4a16d20 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java @@ -12,7 +12,7 @@ import net.osmand.map.TileSourceManager; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; -import net.osmand.plus.download.ui.LocalIndexesFragment.LoadLocalIndexTask; +import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.voice.MediaCommandPlayerImpl; import net.osmand.plus.voice.TTSCommandPlayerImpl; @@ -90,7 +90,7 @@ public class LocalIndexHelper { } - public List getLocalIndexData(LoadLocalIndexTask loadTask){ + public List getLocalIndexData(AbstractLoadLocalIndexTask loadTask){ Map loadedMaps = app.getResourceManager().getIndexFileNames(); List result = new ArrayList<>(); @@ -105,9 +105,16 @@ public class LocalIndexHelper { return result; } - - private void loadVoiceData(File voiceDir, List result, boolean backup, LoadLocalIndexTask loadTask) { + public List getLocalFullMaps(AbstractLoadLocalIndexTask loadTask) { + Map loadedMaps = app.getResourceManager().getIndexFileNames(); + List result = new ArrayList<>(); + loadObfData(app.getAppPath(IndexConstants.MAPS_PATH), result, false, loadTask, loadedMaps); + + return result; + } + + private void loadVoiceData(File voiceDir, List result, boolean backup, AbstractLoadLocalIndexTask loadTask) { if (voiceDir.canRead()) { //First list TTS files, they are preferred for (File voiceF : listFilesSorted(voiceDir)) { @@ -139,7 +146,7 @@ public class LocalIndexHelper { } } - private void loadTilesData(File tilesPath, List result, boolean backup, LoadLocalIndexTask loadTask) { + private void loadTilesData(File tilesPath, List result, boolean backup, AbstractLoadLocalIndexTask loadTask) { if (tilesPath.canRead()) { for (File tileFile : listFilesSorted(tilesPath)) { if (tileFile.isFile() && tileFile.getName().endsWith(SQLiteTileSource.EXT)) { @@ -171,7 +178,7 @@ public class LocalIndexHelper { } - private void loadSrtmData(File mapPath, List result, LoadLocalIndexTask loadTask) { + private void loadSrtmData(File mapPath, List result, AbstractLoadLocalIndexTask loadTask) { if (mapPath.canRead()) { for (File mapFile : listFilesSorted(mapPath)) { if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { @@ -184,7 +191,7 @@ public class LocalIndexHelper { } } - private void loadWikiData(File mapPath, List result, LoadLocalIndexTask loadTask) { + private void loadWikiData(File mapPath, List result, AbstractLoadLocalIndexTask loadTask) { if (mapPath.canRead()) { for (File mapFile : listFilesSorted(mapPath)) { if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { @@ -197,7 +204,7 @@ public class LocalIndexHelper { } } - private void loadObfData(File mapPath, List result, boolean backup, LoadLocalIndexTask loadTask, Map loadedMaps) { + private void loadObfData(File mapPath, List result, boolean backup, AbstractLoadLocalIndexTask loadTask, Map loadedMaps) { if (mapPath.canRead()) { for (File mapFile : listFilesSorted(mapPath)) { if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java index d17ea79d47..f30f67fc44 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java @@ -50,4 +50,8 @@ public class OsmandActionBarActivity extends AppCompatActivity { setupHomeButton(); } } + + public OsmandApplication getMyApplication() { + return (OsmandApplication) getApplication(); + } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index ab5ed943d1..69088ae2ec 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -208,10 +208,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl return localIndexInfos; } - public OsmandApplication getMyApplication() { - return (OsmandApplication) getApplication(); - } - @Override public void onPause() { super.onPause(); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/AbstractLoadLocalIndexTask.java b/OsmAnd/src/net/osmand/plus/download/ui/AbstractLoadLocalIndexTask.java new file mode 100644 index 0000000000..f1f96ba6e3 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/ui/AbstractLoadLocalIndexTask.java @@ -0,0 +1,7 @@ +package net.osmand.plus.download.ui; + +import net.osmand.plus.activities.LocalIndexInfo; + +public interface AbstractLoadLocalIndexTask { + void loadFile(LocalIndexInfo... loaded); +} diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 249ef2f13c..7da6bdfec4 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -277,7 +277,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } - public class LoadLocalIndexTask extends AsyncTask> { + public class LoadLocalIndexTask extends AsyncTask> + implements AbstractLoadLocalIndexTask { private List result; @@ -287,6 +288,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement return helper.getLocalIndexData(this); } + @Override public void loadFile(LocalIndexInfo... loaded) { publishProgress(loaded); }