Refactoring

This commit is contained in:
Victor Shcherb 2015-10-19 02:09:36 +02:00
parent 9f44293c19
commit 9b53d737e4
15 changed files with 308 additions and 395 deletions

View file

@ -11,6 +11,7 @@ import net.osmand.plus.OsmandSettings;
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.ActionBarProgressActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
@ -24,7 +25,7 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.widget.Toast; import android.widget.Toast;
public class BaseDownloadActivity extends ActionBarProgressActivity { public class BaseDownloadActivity extends ActionBarProgressActivity implements DownloadEvents {
protected OsmandSettings settings; protected OsmandSettings settings;
private static DownloadIndexesThread downloadListIndexThread; private static DownloadIndexesThread downloadListIndexThread;
protected Set<WeakReference<Fragment>> fragSet = new HashSet<>(); protected Set<WeakReference<Fragment>> fragSet = new HashSet<>();

View file

@ -12,15 +12,11 @@ import net.osmand.plus.OsmandSettings;
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.LocalIndexInfo; import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.TabActivity; import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.ui.ActiveDownloadsDialogFragment; import net.osmand.plus.download.ui.ActiveDownloadsDialogFragment;
import net.osmand.plus.download.ui.DialogDismissListener;
import net.osmand.plus.download.ui.LocalIndexesFragment; import net.osmand.plus.download.ui.LocalIndexesFragment;
import net.osmand.plus.download.ui.RegionItemsFragment;
import net.osmand.plus.download.ui.SearchDialogFragment;
import net.osmand.plus.download.ui.UpdatesIndexFragment; import net.osmand.plus.download.ui.UpdatesIndexFragment;
import net.osmand.plus.download.ui.WorldItemsFragment; import net.osmand.plus.download.ui.WorldItemsFragment;
import net.osmand.plus.views.controls.PagerSlidingTabStrip; import net.osmand.plus.views.controls.PagerSlidingTabStrip;
@ -38,14 +34,11 @@ import android.support.v4.view.ViewPager;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
public class DownloadActivity extends BaseDownloadActivity implements DialogDismissListener { public class DownloadActivity extends BaseDownloadActivity {
private List<LocalIndexInfo> localIndexInfos = new ArrayList<>(); private List<LocalIndexInfo> localIndexInfos = new ArrayList<>();
List<TabActivity.TabItem> mTabs = new ArrayList<TabActivity.TabItem>(); List<TabActivity.TabItem> mTabs = new ArrayList<TabActivity.TabItem>();
@ -59,14 +52,13 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
public static final MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US); public static final MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
private BannerAndDownloadFreeVersion visibleBanner; private BannerAndDownloadFreeVersion visibleBanner;
private ActiveDownloadsDialogFragment activeDownloads;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
getMyApplication().applyTheme(this); getMyApplication().applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!getDownloadThread().isDownloadedFromInternet()) { DownloadResources indexes = getDownloadThread().getIndexes();
if (!indexes.isDownloadedFromInternet) {
getDownloadThread().runReloadIndexFiles(); getDownloadThread().runReloadIndexFiles();
} }
@ -80,6 +72,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
currentTab = 2; currentTab = 2;
} }
} }
visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager); ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs); PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
@ -102,7 +95,6 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
final String filter = intent.getExtras().getString(FILTER_KEY); final String filter = intent.getExtras().getString(FILTER_KEY);
final String filterCat = intent.getExtras().getString(FILTER_CAT); final String filterCat = intent.getExtras().getString(FILTER_CAT);
} }
registerFreeVersionBanner(findViewById(R.id.mainLayout));
} }
@ -143,24 +135,16 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
@Override @Override
@UiThread @UiThread
public void downloadHasFinished() { public void downloadHasFinished() {
visibleBanner.updateBannerInProgress();
updateBannerInProgress();
if(activeDownloads != null) {
activeDownloads.notifyDataSetInvalidated();
}
// FIXME // FIXME
//((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView()); //((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
for (WeakReference<Fragment> ref : fragSet) { for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get(); Fragment f = ref.get();
notifyUpdateDataSetChanged(f);
if (f instanceof UpdatesIndexFragment) {
if (f.isAdded()) { if (f.isAdded()) {
((UpdatesIndexFragment) f).updateItemsList(); if(f instanceof DownloadEvents) {
((DownloadEvents) f).downloadHasFinished();
} }
} else if(f instanceof RegionItemsFragment) {
Fragment innerFragment = ((RegionItemsFragment)f).getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
notifyUpdateDataSetChanged(innerFragment);
} }
} }
} }
@ -168,93 +152,47 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
@Override @Override
@UiThread @UiThread
public void downloadInProgress() { public void downloadInProgress() {
updateBannerInProgress(); visibleBanner.updateBannerInProgress();
if(activeDownloads != null) {
activeDownloads.notifyDataSetChanged();
}
for (WeakReference<Fragment> ref : fragSet) { for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get(); Fragment f = ref.get();
notifyUpdateDataSetChanged(f); if (f.isAdded()) {
if(f instanceof RegionItemsFragment) { if(f instanceof DownloadEvents) {
Fragment innerFragment = ((RegionItemsFragment)f).getChildFragmentManager().findFragmentById(R.id.fragmentContainer); ((DownloadEvents) f).downloadInProgress();
notifyUpdateDataSetChanged(innerFragment); }
} }
} }
} }
private void updateBannerInProgress() {
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask = getDownloadThread().getCurrentRunningTask();
if (visibleBanner != null) {
final int countedDownloads = getDownloadThread().getCountedDownloads();
visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask);
}
}
@Override @Override
@UiThread @UiThread
public void newDownloadIndexes() { public void newDownloadIndexes() {
visibleBanner.updateBannerInProgress();
// FIXME
//((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
for (WeakReference<Fragment> ref : fragSet) { for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get(); Fragment f = ref.get();
if (f instanceof WorldItemsFragment) {
if (f.isAdded()) { if (f.isAdded()) {
((WorldItemsFragment) f).newDownloadIndexes(); if(f instanceof DownloadEvents) {
} ((DownloadEvents) f).newDownloadIndexes();
} else if (f instanceof SearchDialogFragment) {
if (f.isAdded()) {
((SearchDialogFragment) f).newDownloadIndexes();
}
} else if (f instanceof LocalIndexesFragment) {
if (f.isAdded()) {
((LocalIndexesFragment) f).reloadData();
} }
} }
} }
downloadHasFinished(); downloadHasFinished();
} }
public void setActiveDownloads(ActiveDownloadsDialogFragment activeDownloads) {
this.activeDownloads = activeDownloads;
}
private void notifyUpdateDataSetChanged(Fragment f) {
if (f != null && f.isAdded()) {
if(f instanceof OsmandExpandableListFragment) {
ExpandableListAdapter adapter = ((OsmandExpandableListFragment) f).getAdapter();
if(adapter instanceof BaseExpandableListAdapter) {
((BaseExpandableListAdapter)adapter).notifyDataSetChanged();
}
}
if(f instanceof OsmAndListFragment) {
ArrayAdapter<?> adapter = ((OsmAndListFragment) f).getAdapter();
if(adapter != null) {
adapter.notifyDataSetChanged();
}
}
}
}
public boolean isLightActionBar() { public boolean isLightActionBar() {
return ((OsmandApplication) getApplication()).getSettings().isLightActionBar(); return ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
} }
public void registerFreeVersionBanner(View view) {
visibleBanner = new BannerAndDownloadFreeVersion(view, this);
updateBannerInProgress();
}
public void showDialog(FragmentActivity activity, DialogFragment fragment) { public void showDialog(FragmentActivity activity, DialogFragment fragment) {
fragment.show(activity.getSupportFragmentManager(), "dialog"); fragment.show(activity.getSupportFragmentManager(), "dialog");
} }
@Override
public void onDialogDismissed() {
registerFreeVersionBanner(findViewById(R.id.mainLayout));
}
private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener { private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener {
private final View freeVersionDescriptionTextView; private final View freeVersionDescriptionTextView;
private final View buttonsLinearLayout; private final View buttonsLinearLayout;
@ -292,12 +230,12 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
private final TextView downloadsLeftTextView; private final TextView downloadsLeftTextView;
private final View laterButton; private final View laterButton;
private final FragmentActivity ctx; private final DownloadActivity ctx;
private final OsmandApplication application; private final OsmandApplication application;
private final boolean shouldShowFreeVersionBanner; private final boolean shouldShowFreeVersionBanner;
private final View freeVersionBannerTitle; private final View freeVersionBannerTitle;
public BannerAndDownloadFreeVersion(View view, final FragmentActivity ctx) { public BannerAndDownloadFreeVersion(View view, final DownloadActivity ctx) {
this.ctx = ctx; this.ctx = ctx;
application = (OsmandApplication) ctx.getApplicationContext(); application = (OsmandApplication) ctx.getApplicationContext();
freeVersionBanner = view.findViewById(R.id.freeVersionBanner); freeVersionBanner = view.findViewById(R.id.freeVersionBanner);
@ -318,6 +256,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
initFreeVersionBanner(); initFreeVersionBanner();
updateFreeVersionBanner(); updateFreeVersionBanner();
updateBannerInProgress();
downloadProgressLayout.setOnClickListener(new View.OnClickListener() { downloadProgressLayout.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -326,7 +265,13 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
}); });
} }
public void updateProgress(int countedDownloads, public void updateBannerInProgress() {
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask = ctx.getDownloadThread().getCurrentRunningTask();
final int countedDownloads = ctx.getDownloadThread().getCountedDownloads();
updateProgress(countedDownloads, basicProgressAsyncTask);
}
private void updateProgress(int countedDownloads,
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask) { BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask) {
final boolean isFinished = basicProgressAsyncTask == null final boolean isFinished = basicProgressAsyncTask == null
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED; || basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
@ -379,13 +324,14 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
} }
private void updateFreeVersionBanner() { private void updateFreeVersionBanner() {
if (!shouldShowFreeVersionBanner) return; if (!shouldShowFreeVersionBanner) {
return;
}
setMinimizedFreeVersionBanner(false); setMinimizedFreeVersionBanner(false);
OsmandSettings settings = application.getSettings(); OsmandSettings settings = application.getSettings();
final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get(); final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get();
downloadsLeftProgressBar.setProgress(mapsDownloaded); downloadsLeftProgressBar.setProgress(mapsDownloaded);
int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - mapsDownloaded;
- mapsDownloaded;
downloadsLeft = Math.max(downloadsLeft, 0); downloadsLeft = Math.max(downloadsLeft, 0);
if (downloadsLeft <= 0) { if (downloadsLeft <= 0) {
laterButton.setVisibility(View.GONE); laterButton.setVisibility(View.GONE);

View file

@ -56,6 +56,16 @@ public class DownloadIndexesThread {
private DownloadResources indexes; private DownloadResources indexes;
public interface DownloadEvents {
void newDownloadIndexes();
void downloadInProgress();
void downloadHasFinished();
}
public DownloadIndexesThread(Context ctx) { public DownloadIndexesThread(Context ctx) {
this.ctx = ctx; this.ctx = ctx;
app = (OsmandApplication) ctx.getApplicationContext(); app = (OsmandApplication) ctx.getApplicationContext();
@ -166,10 +176,6 @@ public class DownloadIndexesThread {
} }
public boolean isDownloadedFromInternet() {
return indexes.isDownloadedFromInternet;
}
public IndexItem getCurrentDownloadingItem() { public IndexItem getCurrentDownloadingItem() {
return currentDownloadingItem; return currentDownloadingItem;
} }

View file

@ -33,6 +33,10 @@ public class DownloadResources extends DownloadResourceGroup {
this.app = app; this.app = app;
} }
public List<IndexItem> getItemsToUpdate() {
return itemsToUpdate;
}
public void initAlreadyLoadedFiles() { public void initAlreadyLoadedFiles() {
java.text.DateFormat dateFormat = app.getResourceManager().getDateFormat(); java.text.DateFormat dateFormat = app.getResourceManager().getDateFormat();
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames(); Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
@ -16,7 +17,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
public class ActiveDownloadsDialogFragment extends DialogFragment { public class ActiveDownloadsDialogFragment extends DialogFragment implements DownloadEvents {
private IndexItemAdapter adapter; private IndexItemAdapter adapter;
@ -27,21 +28,20 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
builder.setTitle(R.string.downloads).setNegativeButton(R.string.shared_string_dismiss, null); builder.setTitle(R.string.downloads).setNegativeButton(R.string.shared_string_dismiss, null);
adapter = new IndexItemAdapter(getDownloadActivity()); adapter = new IndexItemAdapter(getDownloadActivity());
builder.setAdapter(adapter, null); builder.setAdapter(adapter, null);
getDownloadActivity().setActiveDownloads(this);
return builder.create(); return builder.create();
} }
public void notifyDataSetInvalidated() { public void newDownloadIndexes() {
adapter.refreshAllData();
};
@Override
public void downloadHasFinished() {
adapter.refreshAllData(); adapter.refreshAllData();
} }
public void notifyDataSetChanged() { public void downloadInProgress() {
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
}
public void onDetach() {
super.onDetach();
getDownloadActivity().setActiveDownloads(null);
}; };
@ -87,7 +87,9 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
} }
private static class DownloadEntryViewHolder extends TwoLineWithImagesViewHolder {
// FIXME review view holder
private static class DownloadEntryViewHolder extends ItemViewHolder {
private final Drawable deleteDrawable; private final Drawable deleteDrawable;
private final IndexItemAdapter adapter; private final IndexItemAdapter adapter;

View file

@ -1,10 +0,0 @@
package net.osmand.plus.download.ui;
/**
* Used to have smooth transition between dialogs
*/
public interface DialogDismissListener {
void onDialogDismissed();
}

View file

@ -4,36 +4,46 @@ 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.WorldRegion; 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.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadActivity.BannerAndDownloadFreeVersion;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadResourceGroup;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem;
import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
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.ExpandableListView;
public class DownloadResourceGroupFragment extends DialogFragment { public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents {
public static final String TAG = "RegionDialogFragment"; public static final String TAG = "RegionDialogFragment";
private static final String REGION_ID_DLG_KEY = "world_region_dialog_key"; private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
private String regionId; private String regionId;
private DialogDismissListener dialogDismissListener; private View view;
private DialogDismissListener listener; private BannerAndDownloadFreeVersion banner;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
boolean isLightTheme = getMyApplication() boolean isLightTheme = getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
setStyle(STYLE_NO_FRAME, themeId); setStyle(STYLE_NO_FRAME, themeId);
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle savedInstanceState) { view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
if (savedInstanceState != null) { if (savedInstanceState != null) {
regionId = savedInstanceState.getString(REGION_ID_DLG_KEY); regionId = savedInstanceState.getString(REGION_ID_DLG_KEY);
@ -56,25 +66,38 @@ public class DownloadResourceGroupFragment extends DialogFragment {
if (regionId.length() > 0) { if (regionId.length() > 0) {
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer); Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
if (fragment == null) { if (fragment == null) {
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer, getChildFragmentManager().beginTransaction()
RegionItemsFragment.createInstance(regionId)).commit(); .add(R.id.fragmentContainer, DownloadResourceGroupListFragment.createInstance(regionId)).commit();
} }
WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId); WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId);
if (region != null) { if (region != null) {
toolbar.setTitle(region.getName()); toolbar.setTitle(region.getName());
} }
} }
getDownloadActivity().registerFreeVersionBanner(view); banner = new BannerAndDownloadFreeVersion(view, (DownloadActivity) getActivity());
listener = new DialogDismissListener() {
@Override
public void onDialogDismissed() {
if (getDownloadActivity() != null)
getDownloadActivity().registerFreeVersionBanner(view);
}
};
return view; return view;
} }
@Override
public void newDownloadIndexes() {
banner.updateBannerInProgress();
// FIXME call inner fragment
}
@Override
public void downloadHasFinished() {
banner.updateBannerInProgress();
// FIXME call inner fragment
}
@Override
public void downloadInProgress() {
banner.updateBannerInProgress();
// FIXME call inner fragment
}
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putString(REGION_ID_DLG_KEY, regionId); outState.putString(REGION_ID_DLG_KEY, regionId);
@ -91,7 +114,6 @@ public class DownloadResourceGroupFragment extends DialogFragment {
public void onRegionSelected(String regionId) { public void onRegionSelected(String regionId) {
final DownloadResourceGroupFragment regionDialogFragment = createInstance(regionId); final DownloadResourceGroupFragment regionDialogFragment = createInstance(regionId);
regionDialogFragment.setOnDismissListener(listener);
getDownloadActivity().showDialog(getActivity(), regionDialogFragment); getDownloadActivity().showDialog(getActivity(), regionDialogFragment);
} }
@ -103,15 +125,124 @@ public class DownloadResourceGroupFragment extends DialogFragment {
return fragment; 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 @Override
public void onDismiss(DialogInterface dialog) { public void onCreate(Bundle savedInstanceState) {
super.onDismiss(dialog); super.onCreate(savedInstanceState);
if (dialogDismissListener != null) setHasOptionsMenu(true);
dialogDismissListener.onDialogDismissed();
} }
public void setOnDismissListener(DialogDismissListener listener) { @Override
this.dialogDismissListener = listener; 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;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final IndexItem indexItem = item;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.are_you_sure);
builder.setMessage(R.string.confirm_download_roadmaps);
builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton(
R.string.shared_string_download, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (indexItem != null) {
((DownloadActivity) getActivity()).startDownload(indexItem);
}
}
});
return builder.create();
}
public static ConfirmDownloadUnneededMapDialogFragment createInstance(@NonNull IndexItem indexItem) {
ConfirmDownloadUnneededMapDialogFragment fragment = new ConfirmDownloadUnneededMapDialogFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
}
} }

View file

@ -6,8 +6,11 @@ import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -22,10 +25,19 @@ import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Map; import java.util.Map;
public class ItemViewHolder extends TwoLineWithImagesViewHolder { public class ItemViewHolder {
private final java.text.DateFormat dateFormat; private final java.text.DateFormat dateFormat;
protected final TextView nameTextView;
protected final TextView descrTextView;
protected final ImageView leftImageView;
protected final ImageView rightImageButton;
protected final Button rightButton;
protected final ProgressBar progressBar;
protected final TextView mapDateTextView;
protected final DownloadActivity context;
private boolean srtmDisabled; private boolean srtmDisabled;
private boolean nauticalPluginDisabled; private boolean nauticalPluginDisabled;
private boolean freeVersion; private boolean freeVersion;
@ -41,9 +53,22 @@ public class ItemViewHolder extends TwoLineWithImagesViewHolder {
ASK_FOR_FULL_VERSION_PURCHASE ASK_FOR_FULL_VERSION_PURCHASE
} }
public ItemViewHolder(View view, DownloadActivity context) {
this.context = context;
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
mapDateTextView = (TextView) view.findViewById(R.id.mapDateTextView);
rightButton = (Button) view.findViewById(R.id.rightButton);
leftImageView = (ImageView) view.findViewById(R.id.leftImageView);
descrTextView = (TextView) view.findViewById(R.id.description);
rightImageButton = (ImageView) view.findViewById(R.id.rightImageButton);
nameTextView = (TextView) view.findViewById(R.id.name);
}
public ItemViewHolder(View convertView, public ItemViewHolder(View convertView,
DownloadActivity context) { DownloadActivity context) {
super(convertView, context); this(convertView, context);
this.dateFormat = context.getMyApplication().getResourceManager().getDateFormat(); this.dateFormat = context.getMyApplication().getResourceManager().getDateFormat();

View file

@ -50,6 +50,7 @@ import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.resources.IncrementalChangesManager; import net.osmand.plus.resources.IncrementalChangesManager;
@ -71,7 +72,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
public class LocalIndexesFragment extends OsmandExpandableListFragment { public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents {
private LoadLocalIndexTask asyncLoader; private LoadLocalIndexTask asyncLoader;
private LocalIndexesAdapter listAdapter; private LocalIndexesAdapter listAdapter;

View file

@ -1,152 +0,0 @@
package net.osmand.plus.download.ui;
import net.osmand.plus.OsmandApplication;
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.DownloadResourceGroup;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem;
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.view.ViewGroup;
import android.widget.ExpandableListView;
public class RegionItemsFragment 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 RegionItemsFragment createInstance(String regionId) {
Bundle bundle = new Bundle();
bundle.putString(REGION_ID_KEY, regionId);
RegionItemsFragment fragment = new RegionItemsFragment();
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();
regionDialogFragment.setOnDismissListener(getDownloadActivity());
getDownloadActivity().showDialog(getActivity(), regionDialogFragment);
((DownloadResourceGroupFragment) getParentFragment()).onRegionSelected(uniqueId);
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;
// }
}
((BaseDownloadActivity) getActivity()).startDownload(indexItem);
return true;
}
return false;
}
private void expandAllGroups() {
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
getExpandableListView().expandGroup(i);
}
}
private DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity();
}
public static class ConfirmDownloadUnneededMapDialogFragment extends DialogFragment {
private static final String INDEX_ITEM = "index_item";
private static IndexItem item = null;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final IndexItem indexItem = item;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.are_you_sure);
builder.setMessage(R.string.confirm_download_roadmaps);
builder.setNegativeButton(R.string.shared_string_cancel, null)
.setPositiveButton(R.string.shared_string_download,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(indexItem != null) {
((DownloadActivity) getActivity()).startDownload(indexItem);
}
}
});
return builder.create();
}
public static ConfirmDownloadUnneededMapDialogFragment createInstance(@NonNull IndexItem indexItem) {
ConfirmDownloadUnneededMapDialogFragment fragment =
new ConfirmDownloadUnneededMapDialogFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
}
}

View file

@ -10,13 +10,13 @@ import android.view.ViewGroup;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams; import android.widget.RelativeLayout.LayoutParams;
import android.widget.SearchView; import android.widget.SearchView;
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.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
public class SearchDialogFragment extends DialogFragment { public class SearchDialogFragment extends DialogFragment implements DownloadEvents {
public static final String TAG = "SearchDialogFragment"; public static final String TAG = "SearchDialogFragment";
private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key"; private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key";

View file

@ -14,6 +14,7 @@ import net.osmand.plus.R;
import net.osmand.plus.WorldRegion; import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.BaseDownloadActivity; import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@ -28,7 +29,7 @@ import android.widget.Filter;
import android.widget.Filterable; import android.widget.Filterable;
import android.widget.ListView; import android.widget.ListView;
public class SearchItemsFragment extends Fragment { public class SearchItemsFragment extends Fragment implements DownloadEvents {
public static final String TAG = "SearchItemsFragment"; public static final String TAG = "SearchItemsFragment";
private SearchItemsAdapter listAdapter; private SearchItemsAdapter listAdapter;

View file

@ -1,33 +0,0 @@
package net.osmand.plus.download.ui;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
*/
public class TwoLineWithImagesViewHolder {
protected final TextView nameTextView;
protected final TextView descrTextView;
protected final ImageView leftImageView;
protected final ImageView rightImageButton;
protected final Button rightButton;
protected final ProgressBar progressBar;
protected final TextView mapDateTextView;
protected final DownloadActivity context;
public TwoLineWithImagesViewHolder(View view, DownloadActivity context) {
this.context = context;
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
mapDateTextView = (TextView) view.findViewById(R.id.mapDateTextView);
rightButton = (Button) view.findViewById(R.id.rightButton);
leftImageView = (ImageView) view.findViewById(R.id.leftImageView);
descrTextView = (TextView) view.findViewById(R.id.description);
rightImageButton = (ImageView) view.findViewById(R.id.rightImageButton);
nameTextView = (TextView) view.findViewById(R.id.name);
}
}

View file

@ -1,23 +1,19 @@
package net.osmand.plus.download.ui; package net.osmand.plus.download.ui;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.OsmAndListFragment; import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import org.apache.commons.logging.Log;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
@ -33,19 +29,14 @@ import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
public class UpdatesIndexFragment extends OsmAndListFragment { public class UpdatesIndexFragment extends OsmAndListFragment implements DownloadEvents {
private static final Log LOG = PlatformUtil.getLog(UpdateIndexAdapter.class);
private static final int RELOAD_ID = 5; private static final int RELOAD_ID = 5;
private UpdateIndexAdapter listAdapter; private UpdateIndexAdapter listAdapter;
List<IndexItem> indexItems = new ArrayList<>();
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (BaseDownloadActivity.downloadListIndexThread != null) { invalidateListView();
indexItems = new ArrayList<>(DownloadActivity.downloadListIndexThread.getItemsToUpdate());
}
createListView();
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@ -59,10 +50,26 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
return listAdapter; return listAdapter;
} }
private void createListView() { @Override
updateUpdateAllButton(); public void downloadHasFinished() {
invalidateListView();
}
@Override
public void downloadInProgress() {
listAdapter.notifyDataSetChanged();
}
@Override
public void newDownloadIndexes() {
invalidateListView();
}
public void invalidateListView() {
DownloadResources indexes = getMyActivity().getDownloadThread().getIndexes();
List<IndexItem> indexItems = indexes.getItemsToUpdate();
if (indexItems.size() == 0) { if (indexItems.size() == 0) {
if (DownloadActivity.downloadListIndexThread.isDownloadedFromInternet()) { if (indexes.isDownloadedFromInternet) {
indexItems.add(new IndexItem(getString(R.string.everything_up_to_date), "", 0, "", 0, 0, null)); indexItems.add(new IndexItem(getString(R.string.everything_up_to_date), "", 0, "", 0, 0, null));
} else { } else {
indexItems.add(new IndexItem(getString(R.string.no_index_file_to_download), "", 0, "", 0, 0, null)); indexItems.add(new IndexItem(getString(R.string.no_index_file_to_download), "", 0, "", 0, 0, null));
@ -78,10 +85,11 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
.compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions)); .compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions));
} }
}); });
updateUpdateAllButton(indexes.getItemsToUpdate());
setListAdapter(listAdapter); setListAdapter(listAdapter);
} }
private void updateUpdateAllButton() { private void updateUpdateAllButton(final List<IndexItem> indexItems) {
View view = getView(); View view = getView();
if (getView() == null) { if (getView() == null) {
return; return;
@ -111,17 +119,6 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
super.onResume(); super.onResume();
} }
public void updateItemsList() {
if (listAdapter == null) {
return;
}
List<IndexItem> items = BaseDownloadActivity.downloadListIndexThread.getItemsToUpdate();
if(items != null) {
indexItems = new ArrayList<IndexItem>(items);
createListView();
}
}
@Override @Override
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
final IndexItem e = (IndexItem) getListAdapter().getItem(position); final IndexItem e = (IndexItem) getListAdapter().getItem(position);
@ -132,9 +129,9 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
return (DownloadActivity) getActivity(); return (DownloadActivity) getActivity();
} }
@SuppressWarnings("deprecation")
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
updateUpdateAllButton();
ActionBar actionBar = getMyActivity().getSupportActionBar(); ActionBar actionBar = getMyActivity().getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
@ -153,7 +150,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) { if (item.getItemId() == RELOAD_ID) {
// re-create the thread // re-create the thread
DownloadActivity.downloadListIndexThread.runReloadIndexFiles(); getMyActivity().getDownloadThread().runReloadIndexFiles();
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -167,42 +164,23 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
this.items = items; this.items = items;
} }
public List<IndexItem> getIndexFiles() {
return items;
}
@Override @Override
public View getView(final int position, final View convertView, final ViewGroup parent) { public View getView(final int position, final View convertView, final ViewGroup parent) {
View v = convertView; View v = convertView;
if (v == null) { if (v == null) {
LayoutInflater inflater = LayoutInflater.from(getMyActivity()); LayoutInflater inflater = LayoutInflater.from(getMyActivity());
v = inflater.inflate(R.layout.two_line_with_images_list_item, null); v = inflater.inflate(R.layout.two_line_with_images_list_item, parent, false);
v.setTag(new UpdateViewHolder(v, getMyActivity())); v.setTag(new UpdateViewHolder(v, getMyActivity()));
} }
UpdateViewHolder holder = (UpdateViewHolder) v.getTag(); UpdateViewHolder holder = (UpdateViewHolder) v.getTag();
holder.bindUpdatesIndexItem(items.get(position)); holder.bindUpdatesIndexItem(items.get(position));
return v; return v;
} }
public void setIndexFiles(List<IndexItem> filtered) {
clear();
for (IndexItem item : filtered) {
add(item);
}
final OsmandRegions osmandRegions =
getMyApplication().getResourceManager().getOsmandRegions();
sort(new Comparator<IndexItem>() {
@Override
public int compare(IndexItem indexItem, IndexItem indexItem2) {
return indexItem.getVisibleName(getMyApplication(), osmandRegions).compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions));
}
});
}
} }
private static class UpdateViewHolder extends TwoLineWithImagesViewHolder { // FIXME review and delete if duplicate
private static class UpdateViewHolder extends ItemViewHolder {
private final java.text.DateFormat format; private final java.text.DateFormat format;
private UpdateViewHolder(View convertView, private UpdateViewHolder(View convertView,
final DownloadActivity context) { final DownloadActivity context) {
super(convertView, context); super(convertView, context);
@ -245,6 +223,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
} }
// FIXME general method for all maps
private String getMapDescription(IndexItem item) { private String getMapDescription(IndexItem item) {
String typeName = getTypeName(item, item.getType().getStringResource()); String typeName = getTypeName(item, item.getType().getStringResource());
String date = item.getDate(format); String date = item.getDate(format);

View file

@ -9,9 +9,9 @@ import net.osmand.plus.R;
import net.osmand.plus.WorldRegion; import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadResourceGroup; import net.osmand.plus.download.DownloadResourceGroup;
import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType; import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
@ -32,7 +32,7 @@ import android.view.ViewGroup;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.TextView; import android.widget.TextView;
public class WorldItemsFragment extends OsmandExpandableListFragment { public class WorldItemsFragment extends OsmandExpandableListFragment implements DownloadEvents {
public static final String TAG = "WorldItemsFragment"; public static final String TAG = "WorldItemsFragment";
public static final int RELOAD_ID = 0; public static final int RELOAD_ID = 0;
@ -70,6 +70,23 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
@Override
public void downloadHasFinished() {
listAdapter.notifyDataSetChanged();
}
@Override
public void downloadInProgress() {
listAdapter.notifyDataSetChanged();
}
@Override
public void newDownloadIndexes() {
DownloadResources indexes = getDownloadActivity().getDownloadThread().getIndexes();
listAdapter.update(indexes);
expandAllGroups();
}
private void expandAllGroups() { private void expandAllGroups() {
for (int i = 0; i < listAdapter.getGroupCount(); i++) { for (int i = 0; i < listAdapter.getGroupCount(); i++) {
getExpandableListView().expandGroup(i); getExpandableListView().expandGroup(i);
@ -89,12 +106,11 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
Object child = listAdapter.getChild(groupPosition, childPosition); Object child = listAdapter.getChild(groupPosition, childPosition);
if (child instanceof DownloadResourceGroup) { if (child instanceof DownloadResourceGroup) {
final DownloadResourceGroupFragment regionDialogFragment = DownloadResourceGroupFragment.createInstance(((DownloadResourceGroup) child).getUniqueId()); final DownloadResourceGroupFragment regionDialogFragment = DownloadResourceGroupFragment.createInstance(((DownloadResourceGroup) child).getUniqueId());
regionDialogFragment.setOnDismissListener(getDownloadActivity()); ((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
getDownloadActivity().showDialog(getActivity(), regionDialogFragment);
return true; return true;
} else if (child instanceof IndexItem) { } else if (child instanceof IndexItem) {
IndexItem indexItem = (IndexItem) child; IndexItem indexItem = (IndexItem) child;
((BaseDownloadActivity) getActivity()).startDownload(indexItem); ((DownloadActivity) getActivity()).startDownload(indexItem);
return true; return true;
} }
return false; return false;
@ -132,11 +148,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
return (DownloadActivity) getActivity(); return (DownloadActivity) getActivity();
} }
public void newDownloadIndexes() {
DownloadResources indexes = getDownloadActivity().getDownloadThread().getIndexes();
listAdapter.update(indexes);
expandAllGroups();
}
public static class DownloadResourceGroupAdapter extends OsmandBaseExpandableListAdapter { public static class DownloadResourceGroupAdapter extends OsmandBaseExpandableListAdapter {