Update fragment
This commit is contained in:
parent
9b53d737e4
commit
3cc2d941e5
3 changed files with 111 additions and 128 deletions
|
@ -28,8 +28,15 @@
|
|||
|
||||
<include layout="@layout/progress_with_two_texts"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragmentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<ExpandableListView
|
||||
android:id="@android:id/list"
|
||||
style="@style/OsmandListView"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginLeft="0dp"
|
||||
android:layout_marginRight="0dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_weight="1"
|
||||
android:groupIndicator="@android:color/transparent"/>
|
||||
</LinearLayout>
|
|
@ -3,12 +3,9 @@ package net.osmand.plus.download.ui;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.WorldRegion;
|
||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.download.BaseDownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadActivity.BannerAndDownloadFreeVersion;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.DownloadResourceGroup;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
|
@ -18,20 +15,25 @@ import android.content.DialogInterface;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ExpandableListView.OnChildClickListener;
|
||||
|
||||
public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents {
|
||||
public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents, OnChildClickListener {
|
||||
public static final String TAG = "RegionDialogFragment";
|
||||
private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
|
||||
private String regionId;
|
||||
private String groupId;
|
||||
private View view;
|
||||
private BannerAndDownloadFreeVersion banner;
|
||||
protected ExpandableListView listView;
|
||||
protected WorldItemsFragment.DownloadResourceGroupAdapter listAdapter;
|
||||
private DownloadResourceGroup group;
|
||||
private DownloadActivity activity;
|
||||
private Toolbar toolbar;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -39,22 +41,24 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
|
|||
boolean isLightTheme = getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
|
||||
setStyle(STYLE_NO_FRAME, themeId);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
regionId = savedInstanceState.getString(REGION_ID_DLG_KEY);
|
||||
groupId = savedInstanceState.getString(REGION_ID_DLG_KEY);
|
||||
}
|
||||
if (regionId == null) {
|
||||
regionId = getArguments().getString(REGION_ID_DLG_KEY);
|
||||
if (groupId == null) {
|
||||
groupId = getArguments().getString(REGION_ID_DLG_KEY);
|
||||
}
|
||||
if (regionId == null)
|
||||
regionId = "";
|
||||
if (groupId == null) {
|
||||
groupId = "";
|
||||
}
|
||||
activity = (DownloadActivity) getActivity();
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -63,44 +67,91 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
|
|||
}
|
||||
});
|
||||
|
||||
if (regionId.length() > 0) {
|
||||
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
|
||||
if (fragment == null) {
|
||||
getChildFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, DownloadResourceGroupListFragment.createInstance(regionId)).commit();
|
||||
}
|
||||
WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId);
|
||||
if (region != null) {
|
||||
toolbar.setTitle(region.getName());
|
||||
}
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
banner = new BannerAndDownloadFreeVersion(view, (DownloadActivity) getActivity());
|
||||
|
||||
listView = (ExpandableListView) view.findViewById(android.R.id.list);
|
||||
listView.setOnChildClickListener(this);
|
||||
listAdapter = new WorldItemsFragment.DownloadResourceGroupAdapter(activity);
|
||||
listView.setAdapter(listAdapter);
|
||||
|
||||
reloadData();
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
private void reloadData() {
|
||||
DownloadResources indexes = activity.getDownloadThread().getIndexes();
|
||||
group = indexes.getGroupById(groupId);
|
||||
if (group != null) {
|
||||
listAdapter.update(group);
|
||||
if (group.getRegion() != null) {
|
||||
toolbar.setTitle(group.getRegion().getName());
|
||||
}
|
||||
}
|
||||
expandAllGroups();
|
||||
}
|
||||
|
||||
private void expandAllGroups() {
|
||||
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
|
||||
listView.expandGroup(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
listView.setBackgroundColor(getResources().getColor(
|
||||
getMyApplication().getSettings().isLightContent() ? R.color.bg_color_light : R.color.bg_color_dark));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
banner.updateBannerInProgress();
|
||||
// FIXME call inner fragment
|
||||
reloadData();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
banner.updateBannerInProgress();
|
||||
// FIXME call inner fragment
|
||||
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadInProgress() {
|
||||
banner.updateBannerInProgress();
|
||||
// FIXME call inner fragment
|
||||
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
Object child = listAdapter.getChild(groupPosition, childPosition);
|
||||
if (child instanceof DownloadResourceGroup) {
|
||||
String uniqueId = ((DownloadResourceGroup) child).getUniqueId();
|
||||
final DownloadResourceGroupFragment regionDialogFragment = DownloadResourceGroupFragment
|
||||
.createInstance(uniqueId);
|
||||
((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
|
||||
return true;
|
||||
} else if (child instanceof IndexItem) {
|
||||
IndexItem indexItem = (IndexItem) child;
|
||||
if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
|
||||
// FIXME
|
||||
// if (regularMap.getType() == DownloadActivityType.NORMAL_FILE
|
||||
// && regularMap.isAlreadyDownloaded(getMyActivity().getIndexFileNames())) {
|
||||
// ConfirmDownloadUnneededMapDialogFragment.createInstance(indexItem)
|
||||
// .show(getChildFragmentManager(), "dialog");
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
((DownloadActivity) getActivity()).startDownload(indexItem);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString(REGION_ID_DLG_KEY, regionId);
|
||||
outState.putString(REGION_ID_DLG_KEY, groupId);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
@ -125,96 +176,6 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
|
|||
return fragment;
|
||||
}
|
||||
|
||||
|
||||
// FIXME why do we need fragment in fragment???
|
||||
public static class DownloadResourceGroupListFragment extends OsmandExpandableListFragment {
|
||||
public static final String TAG = "RegionItemsFragment";
|
||||
private static final String REGION_ID_KEY = "world_region_id_key";
|
||||
private String regionId;
|
||||
private WorldItemsFragment.DownloadResourceGroupAdapter listAdapter;
|
||||
private DownloadActivity activity;
|
||||
private DownloadResourceGroup group;
|
||||
|
||||
public static DownloadResourceGroupListFragment createInstance(String regionId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(REGION_ID_KEY, regionId);
|
||||
DownloadResourceGroupListFragment fragment = new DownloadResourceGroupListFragment();
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.download_items_fragment, container, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
regionId = savedInstanceState.getString(REGION_ID_KEY);
|
||||
}
|
||||
if (regionId == null) {
|
||||
regionId = getArguments().getString(REGION_ID_KEY);
|
||||
}
|
||||
if (regionId == null)
|
||||
regionId = "";
|
||||
|
||||
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
|
||||
activity = (DownloadActivity) getActivity();
|
||||
DownloadResources indexes = activity.getDownloadThread().getIndexes();
|
||||
group = indexes.getGroupById(regionId);
|
||||
listAdapter = new WorldItemsFragment.DownloadResourceGroupAdapter(activity);
|
||||
listView.setAdapter(listAdapter);
|
||||
setListView(listView);
|
||||
if (group != null) {
|
||||
listAdapter.update(group);
|
||||
}
|
||||
expandAllGroups();
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString(REGION_ID_KEY, regionId);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
Object child = listAdapter.getChild(groupPosition, childPosition);
|
||||
if (child instanceof DownloadResourceGroup) {
|
||||
String uniqueId = ((DownloadResourceGroup) child).getUniqueId();
|
||||
final DownloadResourceGroupFragment regionDialogFragment = DownloadResourceGroupFragment.createInstance(uniqueId);
|
||||
((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
|
||||
return true;
|
||||
} else if (child instanceof IndexItem) {
|
||||
IndexItem indexItem = (IndexItem) child;
|
||||
if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
|
||||
// FIXME
|
||||
// if (regularMap.getType() == DownloadActivityType.NORMAL_FILE
|
||||
// && regularMap.isAlreadyDownloaded(getMyActivity().getIndexFileNames())) {
|
||||
// ConfirmDownloadUnneededMapDialogFragment.createInstance(indexItem)
|
||||
// .show(getChildFragmentManager(), "dialog");
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
((DownloadActivity) getActivity()).startDownload(indexItem);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void expandAllGroups() {
|
||||
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
|
||||
getExpandableListView().expandGroup(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ConfirmDownloadUnneededMapDialogFragment extends DialogFragment {
|
||||
private static final String INDEX_ITEM = "index_item";
|
||||
private static IndexItem item = null;
|
||||
|
|
|
@ -162,6 +162,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
asyncLoader = new LoadLocalIndexTask();
|
||||
asyncLoader.execute(getActivity());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void showContextMenu(final LocalIndexInfo info) {
|
||||
|
@ -450,6 +452,19 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
reloadData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadInProgress() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue