Refactoring
This commit is contained in:
parent
9f44293c19
commit
9b53d737e4
15 changed files with 308 additions and 395 deletions
|
@ -11,6 +11,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.ActionBarProgressActivity;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
|
@ -24,7 +25,7 @@ import android.support.v4.app.DialogFragment;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class BaseDownloadActivity extends ActionBarProgressActivity {
|
||||
public class BaseDownloadActivity extends ActionBarProgressActivity implements DownloadEvents {
|
||||
protected OsmandSettings settings;
|
||||
private static DownloadIndexesThread downloadListIndexThread;
|
||||
protected Set<WeakReference<Fragment>> fragSet = new HashSet<>();
|
||||
|
|
|
@ -12,15 +12,11 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
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.base.BasicProgressAsyncTask;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
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.RegionItemsFragment;
|
||||
import net.osmand.plus.download.ui.SearchDialogFragment;
|
||||
import net.osmand.plus.download.ui.UpdatesIndexFragment;
|
||||
import net.osmand.plus.download.ui.WorldItemsFragment;
|
||||
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
|
||||
|
@ -38,14 +34,11 @@ import android.support.v4.view.ViewPager;
|
|||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class DownloadActivity extends BaseDownloadActivity implements DialogDismissListener {
|
||||
public class DownloadActivity extends BaseDownloadActivity {
|
||||
private List<LocalIndexInfo> localIndexInfos = new ArrayList<>();
|
||||
|
||||
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);
|
||||
|
||||
private BannerAndDownloadFreeVersion visibleBanner;
|
||||
private ActiveDownloadsDialogFragment activeDownloads;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getMyApplication().applyTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
if (!getDownloadThread().isDownloadedFromInternet()) {
|
||||
DownloadResources indexes = getDownloadThread().getIndexes();
|
||||
if (!indexes.isDownloadedFromInternet) {
|
||||
getDownloadThread().runReloadIndexFiles();
|
||||
}
|
||||
|
||||
|
@ -80,6 +72,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
currentTab = 2;
|
||||
}
|
||||
}
|
||||
visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this);
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
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 filterCat = intent.getExtras().getString(FILTER_CAT);
|
||||
}
|
||||
registerFreeVersionBanner(findViewById(R.id.mainLayout));
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,24 +135,16 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
@Override
|
||||
@UiThread
|
||||
public void downloadHasFinished() {
|
||||
|
||||
updateBannerInProgress();
|
||||
if(activeDownloads != null) {
|
||||
activeDownloads.notifyDataSetInvalidated();
|
||||
}
|
||||
visibleBanner.updateBannerInProgress();
|
||||
// FIXME
|
||||
//((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
|
||||
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
notifyUpdateDataSetChanged(f);
|
||||
if (f instanceof UpdatesIndexFragment) {
|
||||
if (f.isAdded()) {
|
||||
((UpdatesIndexFragment) f).updateItemsList();
|
||||
if (f.isAdded()) {
|
||||
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
|
||||
@UiThread
|
||||
public void downloadInProgress() {
|
||||
updateBannerInProgress();
|
||||
if(activeDownloads != null) {
|
||||
activeDownloads.notifyDataSetChanged();
|
||||
}
|
||||
visibleBanner.updateBannerInProgress();
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
notifyUpdateDataSetChanged(f);
|
||||
if(f instanceof RegionItemsFragment) {
|
||||
Fragment innerFragment = ((RegionItemsFragment)f).getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
|
||||
notifyUpdateDataSetChanged(innerFragment);
|
||||
if (f.isAdded()) {
|
||||
if(f instanceof DownloadEvents) {
|
||||
((DownloadEvents) f).downloadInProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateBannerInProgress() {
|
||||
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask = getDownloadThread().getCurrentRunningTask();
|
||||
if (visibleBanner != null) {
|
||||
final int countedDownloads = getDownloadThread().getCountedDownloads();
|
||||
visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@UiThread
|
||||
public void newDownloadIndexes() {
|
||||
visibleBanner.updateBannerInProgress();
|
||||
// FIXME
|
||||
//((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof WorldItemsFragment) {
|
||||
if (f.isAdded()) {
|
||||
((WorldItemsFragment) f).newDownloadIndexes();
|
||||
}
|
||||
} else if (f instanceof SearchDialogFragment) {
|
||||
if (f.isAdded()) {
|
||||
((SearchDialogFragment) f).newDownloadIndexes();
|
||||
}
|
||||
} else if (f instanceof LocalIndexesFragment) {
|
||||
if (f.isAdded()) {
|
||||
((LocalIndexesFragment) f).reloadData();
|
||||
if (f.isAdded()) {
|
||||
if(f instanceof DownloadEvents) {
|
||||
((DownloadEvents) f).newDownloadIndexes();
|
||||
}
|
||||
}
|
||||
}
|
||||
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() {
|
||||
return ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
|
||||
}
|
||||
|
||||
|
||||
public void registerFreeVersionBanner(View view) {
|
||||
visibleBanner = new BannerAndDownloadFreeVersion(view, this);
|
||||
updateBannerInProgress();
|
||||
}
|
||||
|
||||
|
||||
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
||||
fragment.show(activity.getSupportFragmentManager(), "dialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogDismissed() {
|
||||
registerFreeVersionBanner(findViewById(R.id.mainLayout));
|
||||
}
|
||||
|
||||
private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener {
|
||||
private final View freeVersionDescriptionTextView;
|
||||
private final View buttonsLinearLayout;
|
||||
|
@ -292,12 +230,12 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
private final TextView downloadsLeftTextView;
|
||||
private final View laterButton;
|
||||
|
||||
private final FragmentActivity ctx;
|
||||
private final DownloadActivity ctx;
|
||||
private final OsmandApplication application;
|
||||
private final boolean shouldShowFreeVersionBanner;
|
||||
private final View freeVersionBannerTitle;
|
||||
|
||||
public BannerAndDownloadFreeVersion(View view, final FragmentActivity ctx) {
|
||||
public BannerAndDownloadFreeVersion(View view, final DownloadActivity ctx) {
|
||||
this.ctx = ctx;
|
||||
application = (OsmandApplication) ctx.getApplicationContext();
|
||||
freeVersionBanner = view.findViewById(R.id.freeVersionBanner);
|
||||
|
@ -318,6 +256,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
|
||||
initFreeVersionBanner();
|
||||
updateFreeVersionBanner();
|
||||
updateBannerInProgress();
|
||||
downloadProgressLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -325,8 +264,14 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateBannerInProgress() {
|
||||
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask = ctx.getDownloadThread().getCurrentRunningTask();
|
||||
final int countedDownloads = ctx.getDownloadThread().getCountedDownloads();
|
||||
updateProgress(countedDownloads, basicProgressAsyncTask);
|
||||
}
|
||||
|
||||
public void updateProgress(int countedDownloads,
|
||||
private void updateProgress(int countedDownloads,
|
||||
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask) {
|
||||
final boolean isFinished = basicProgressAsyncTask == null
|
||||
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
|
||||
|
@ -379,13 +324,14 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
}
|
||||
|
||||
private void updateFreeVersionBanner() {
|
||||
if (!shouldShowFreeVersionBanner) return;
|
||||
if (!shouldShowFreeVersionBanner) {
|
||||
return;
|
||||
}
|
||||
setMinimizedFreeVersionBanner(false);
|
||||
OsmandSettings settings = application.getSettings();
|
||||
final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
downloadsLeftProgressBar.setProgress(mapsDownloaded);
|
||||
int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
||||
- mapsDownloaded;
|
||||
int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - mapsDownloaded;
|
||||
downloadsLeft = Math.max(downloadsLeft, 0);
|
||||
if (downloadsLeft <= 0) {
|
||||
laterButton.setVisibility(View.GONE);
|
||||
|
|
|
@ -54,6 +54,16 @@ public class DownloadIndexesThread {
|
|||
private int currentDownloadingItemProgress = 0;
|
||||
|
||||
private DownloadResources indexes;
|
||||
|
||||
|
||||
public interface DownloadEvents {
|
||||
|
||||
void newDownloadIndexes();
|
||||
|
||||
void downloadInProgress();
|
||||
|
||||
void downloadHasFinished();
|
||||
}
|
||||
|
||||
|
||||
public DownloadIndexesThread(Context ctx) {
|
||||
|
@ -166,10 +176,6 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
|
||||
public boolean isDownloadedFromInternet() {
|
||||
return indexes.isDownloadedFromInternet;
|
||||
}
|
||||
|
||||
public IndexItem getCurrentDownloadingItem() {
|
||||
return currentDownloadingItem;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,10 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
this.region = app.getWorldRegion();
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
public List<IndexItem> getItemsToUpdate() {
|
||||
return itemsToUpdate;
|
||||
}
|
||||
|
||||
public void initAlreadyLoadedFiles() {
|
||||
java.text.DateFormat dateFormat = app.getResourceManager().getDateFormat();
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
|
@ -16,7 +17,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
public class ActiveDownloadsDialogFragment extends DialogFragment {
|
||||
public class ActiveDownloadsDialogFragment extends DialogFragment implements DownloadEvents {
|
||||
|
||||
private IndexItemAdapter adapter;
|
||||
|
||||
|
@ -27,21 +28,20 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
|
|||
builder.setTitle(R.string.downloads).setNegativeButton(R.string.shared_string_dismiss, null);
|
||||
adapter = new IndexItemAdapter(getDownloadActivity());
|
||||
builder.setAdapter(adapter, null);
|
||||
getDownloadActivity().setActiveDownloads(this);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public void notifyDataSetInvalidated() {
|
||||
public void newDownloadIndexes() {
|
||||
adapter.refreshAllData();
|
||||
};
|
||||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
adapter.refreshAllData();
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
public void downloadInProgress() {
|
||||
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 IndexItemAdapter adapter;
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package net.osmand.plus.download.ui;
|
||||
|
||||
/**
|
||||
* Used to have smooth transition between dialogs
|
||||
*/
|
||||
public interface DialogDismissListener {
|
||||
|
||||
void onDialogDismissed();
|
||||
|
||||
}
|
|
@ -4,36 +4,46 @@ 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.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.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;
|
||||
|
||||
public class DownloadResourceGroupFragment extends DialogFragment {
|
||||
public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents {
|
||||
public static final String TAG = "RegionDialogFragment";
|
||||
private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
|
||||
private String regionId;
|
||||
private DialogDismissListener dialogDismissListener;
|
||||
private DialogDismissListener listener;
|
||||
private View view;
|
||||
private BannerAndDownloadFreeVersion banner;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
boolean isLightTheme = getMyApplication()
|
||||
.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
|
||||
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);
|
||||
|
@ -56,24 +66,37 @@ public class DownloadResourceGroupFragment extends DialogFragment {
|
|||
if (regionId.length() > 0) {
|
||||
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
|
||||
if (fragment == null) {
|
||||
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
|
||||
RegionItemsFragment.createInstance(regionId)).commit();
|
||||
getChildFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, DownloadResourceGroupListFragment.createInstance(regionId)).commit();
|
||||
}
|
||||
WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId);
|
||||
if (region != null) {
|
||||
toolbar.setTitle(region.getName());
|
||||
}
|
||||
}
|
||||
getDownloadActivity().registerFreeVersionBanner(view);
|
||||
listener = new DialogDismissListener() {
|
||||
@Override
|
||||
public void onDialogDismissed() {
|
||||
if (getDownloadActivity() != null)
|
||||
getDownloadActivity().registerFreeVersionBanner(view);
|
||||
}
|
||||
};
|
||||
banner = new BannerAndDownloadFreeVersion(view, (DownloadActivity) getActivity());
|
||||
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
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
|
@ -91,7 +114,6 @@ public class DownloadResourceGroupFragment extends DialogFragment {
|
|||
|
||||
public void onRegionSelected(String regionId) {
|
||||
final DownloadResourceGroupFragment regionDialogFragment = createInstance(regionId);
|
||||
regionDialogFragment.setOnDismissListener(listener);
|
||||
getDownloadActivity().showDialog(getActivity(), regionDialogFragment);
|
||||
}
|
||||
|
||||
|
@ -103,15 +125,124 @@ public class DownloadResourceGroupFragment extends DialogFragment {
|
|||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (dialogDismissListener != null)
|
||||
dialogDismissListener.onDialogDismissed();
|
||||
|
||||
// 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 void setOnDismissListener(DialogDismissListener listener) {
|
||||
this.dialogDismissListener = listener;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,8 +6,11 @@ import android.graphics.drawable.Drawable;
|
|||
import android.net.Uri;
|
||||
import android.util.TypedValue;
|
||||
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 net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -22,10 +25,19 @@ import net.osmand.plus.srtmplugin.SRTMPlugin;
|
|||
import java.text.DateFormat;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemViewHolder extends TwoLineWithImagesViewHolder {
|
||||
public class ItemViewHolder {
|
||||
|
||||
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 nauticalPluginDisabled;
|
||||
private boolean freeVersion;
|
||||
|
@ -40,10 +52,23 @@ public class ItemViewHolder extends TwoLineWithImagesViewHolder {
|
|||
ASK_FOR_SRTM_PLUGIN_ENABLE,
|
||||
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,
|
||||
DownloadActivity context) {
|
||||
super(convertView, context);
|
||||
this(convertView, context);
|
||||
|
||||
this.dateFormat = context.getMyApplication().getResourceManager().getDateFormat();
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ import net.osmand.plus.activities.OsmandExpandableListFragment;
|
|||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager;
|
||||
|
@ -71,7 +72,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
|
||||
public class LocalIndexesFragment extends OsmandExpandableListFragment {
|
||||
public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents {
|
||||
|
||||
private LoadLocalIndexTask asyncLoader;
|
||||
private LocalIndexesAdapter listAdapter;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,13 +10,13 @@ import android.view.ViewGroup;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.RelativeLayout.LayoutParams;
|
||||
import android.widget.SearchView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
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";
|
||||
private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key";
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.WorldRegion;
|
||||
import net.osmand.plus.download.BaseDownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
|
@ -28,7 +29,7 @@ import android.widget.Filter;
|
|||
import android.widget.Filterable;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class SearchItemsFragment extends Fragment {
|
||||
public class SearchItemsFragment extends Fragment implements DownloadEvents {
|
||||
public static final String TAG = "SearchItemsFragment";
|
||||
|
||||
private SearchItemsAdapter listAdapter;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,23 +1,19 @@
|
|||
package net.osmand.plus.download.ui;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmAndListFragment;
|
||||
import net.osmand.plus.download.BaseDownloadActivity;
|
||||
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 org.apache.commons.logging.Log;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
@ -33,19 +29,14 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class UpdatesIndexFragment extends OsmAndListFragment {
|
||||
private static final Log LOG = PlatformUtil.getLog(UpdateIndexAdapter.class);
|
||||
public class UpdatesIndexFragment extends OsmAndListFragment implements DownloadEvents {
|
||||
private static final int RELOAD_ID = 5;
|
||||
private UpdateIndexAdapter listAdapter;
|
||||
List<IndexItem> indexItems = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (BaseDownloadActivity.downloadListIndexThread != null) {
|
||||
indexItems = new ArrayList<>(DownloadActivity.downloadListIndexThread.getItemsToUpdate());
|
||||
}
|
||||
createListView();
|
||||
invalidateListView();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
|
@ -58,11 +49,27 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
public ArrayAdapter<?> getAdapter() {
|
||||
return listAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
invalidateListView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadInProgress() {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
invalidateListView();
|
||||
}
|
||||
|
||||
private void createListView() {
|
||||
updateUpdateAllButton();
|
||||
public void invalidateListView() {
|
||||
DownloadResources indexes = getMyActivity().getDownloadThread().getIndexes();
|
||||
List<IndexItem> indexItems = indexes.getItemsToUpdate();
|
||||
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));
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
});
|
||||
updateUpdateAllButton(indexes.getItemsToUpdate());
|
||||
setListAdapter(listAdapter);
|
||||
}
|
||||
|
||||
private void updateUpdateAllButton() {
|
||||
private void updateUpdateAllButton(final List<IndexItem> indexItems) {
|
||||
View view = getView();
|
||||
if (getView() == null) {
|
||||
return;
|
||||
|
@ -111,17 +119,6 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
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
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
final IndexItem e = (IndexItem) getListAdapter().getItem(position);
|
||||
|
@ -132,9 +129,9 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
return (DownloadActivity) getActivity();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
updateUpdateAllButton();
|
||||
ActionBar actionBar = getMyActivity().getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
|
||||
|
@ -153,7 +150,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == RELOAD_ID) {
|
||||
// re-create the thread
|
||||
DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
|
||||
getMyActivity().getDownloadThread().runReloadIndexFiles();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -167,42 +164,23 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
this.items = items;
|
||||
}
|
||||
|
||||
public List<IndexItem> getIndexFiles() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, final View convertView, final ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
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()));
|
||||
}
|
||||
UpdateViewHolder holder = (UpdateViewHolder) v.getTag();
|
||||
holder.bindUpdatesIndexItem(items.get(position));
|
||||
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 UpdateViewHolder(View convertView,
|
||||
final DownloadActivity context) {
|
||||
super(convertView, context);
|
||||
|
@ -245,6 +223,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
}
|
||||
|
||||
|
||||
// FIXME general method for all maps
|
||||
private String getMapDescription(IndexItem item) {
|
||||
String typeName = getTypeName(item, item.getType().getStringResource());
|
||||
String date = item.getDate(format);
|
||||
|
|
|
@ -9,9 +9,9 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.WorldRegion;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
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.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.DownloadResourceGroup;
|
||||
import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
|
@ -32,7 +32,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.ExpandableListView;
|
||||
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 int RELOAD_ID = 0;
|
||||
|
@ -69,6 +69,23 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
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() {
|
||||
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
|
||||
|
@ -89,12 +106,11 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
|
|||
Object child = listAdapter.getChild(groupPosition, childPosition);
|
||||
if (child instanceof DownloadResourceGroup) {
|
||||
final DownloadResourceGroupFragment regionDialogFragment = DownloadResourceGroupFragment.createInstance(((DownloadResourceGroup) child).getUniqueId());
|
||||
regionDialogFragment.setOnDismissListener(getDownloadActivity());
|
||||
getDownloadActivity().showDialog(getActivity(), regionDialogFragment);
|
||||
((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
|
||||
return true;
|
||||
} else if (child instanceof IndexItem) {
|
||||
IndexItem indexItem = (IndexItem) child;
|
||||
((BaseDownloadActivity) getActivity()).startDownload(indexItem);
|
||||
((DownloadActivity) getActivity()).startDownload(indexItem);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -132,11 +148,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
|
|||
return (DownloadActivity) getActivity();
|
||||
}
|
||||
|
||||
public void newDownloadIndexes() {
|
||||
DownloadResources indexes = getDownloadActivity().getDownloadThread().getIndexes();
|
||||
listAdapter.update(indexes);
|
||||
expandAllGroups();
|
||||
}
|
||||
|
||||
|
||||
public static class DownloadResourceGroupAdapter extends OsmandBaseExpandableListAdapter {
|
||||
|
||||
|
|
Loading…
Reference in a new issue