Colors for map items, fix for crash caused by missing string resources, cancel for downloading maps

This commit is contained in:
GaidamakUA 2015-10-12 17:49:16 +03:00
parent 873c7e7d18
commit adc20cb5d0
10 changed files with 222 additions and 161 deletions

View file

@ -414,21 +414,6 @@
<string name="system_locale">Stelsel</string>
<string name="preferred_locale_descr">Kies die taal vir die program</string>
<string name="preferred_locale">Vertoon taal</string>
<string name="tip_map_switch">Kaartbron</string>
<string name="tip_app_mode">Gebruikersprofiel</string>
<string name="tip_navigation">Navigasie</string>
<string name="tip_navigation_t">\tVoordat \'n navigasie begin moet jy \'n bestemming kies. Druk daarna \'kieslys\' -&gt; \'aanwysings\' op die kaart en kies die navigasie wyse.</string>
<string name="tip_search">op soek</string>
<string name="tip_search_t">"\tJy kan soek vir plekke op die kaart of van die soek skerm, deur adres, deur Ligging, as interessante plek, of as voorafgedefinieerde gunsteling.\n\tDeur \'Soek\' in die hoofkieslys te druk word die soek aktiwiteite begin. Vir al die resultate bied `n kieslys 2 keuses: \'Stel as bestemming \' of \' Wys op die kaart\'. "
</string>
<string name="tip_map_context_menu">Kaartinhoud kieslys</string>
<string name="tip_map_context_menu_t">\tDie kaart inhoud kieslys is beskikbaar deur te druk en te hou op die kaart of deur die trekbal-knoppie te druk.\n\tDit lewer \'n boks met punt koördinate. Om die kaart inhoud kieslys venster oop te maak, tik op dit. (Of druk en hou die boks om dit weer te versteek.)\n\tDie kaart inhoud kieslys bevat alle aksies met verwysing na \'n punt (ligging).
</string>
<string name="tip_initial_t">\tOsmAnd is \'n navigasietoepassing met baie funksies.\n\tAs \'n basiese inleiding, is sommige gebruikswenke en wyses beskikbaar in skakels vanaf die hoof kieslys skerm.
</string>
<string name="shared_string_next">Volgende</string>
<string name="shared_string_previous">Vorige</string>
<string name="unit_of_length_descr">Verander eenhede van lengte en spoed</string>

View file

@ -87,7 +87,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class,
-1, errorShouldShow, true, 3),
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class,
R.string.tip_navigation, 4),
R.string.shared_string_navigation, 4),
new DashFragmentData(DashWaypointsFragment.TAG, DashWaypointsFragment.class,
R.string.waypoints, 6),
new DashFragmentData(DashSearchFragment.TAG, DashSearchFragment.class,

View file

@ -1,6 +1,7 @@
package net.osmand.plus.dashboard.tools;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity;
@ -17,7 +18,7 @@ public final class DashFragmentData implements Comparable<DashFragmentData> {
public final String rowNumberTag;
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
int titleStringId, ShouldShowFunction shouldShowFunction,
@StringRes int titleStringId, ShouldShowFunction shouldShowFunction,
boolean customDeletionLogic, int position, String rowNumberTag) {
this.tag = tag;
this.fragmentClass = fragmentClass;

View file

@ -43,6 +43,8 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.ActiveDownloadsDialogFragment;
import net.osmand.plus.download.items.DialogDismissListener;
import net.osmand.plus.download.items.RegionDialogFragment;
import net.osmand.plus.download.items.SearchDialogFragment;
import net.osmand.plus.download.items.WorldItemsFragment;
@ -59,7 +61,7 @@ import java.util.Map;
import java.util.Set;
public class DownloadActivity extends BaseDownloadActivity implements RegionDialogFragment.DialogDismissListener {
public class DownloadActivity extends BaseDownloadActivity implements DialogDismissListener {
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
private String initialFilter = "";
@ -114,12 +116,12 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
getString(R.string.download_tab_local), LocalIndexesFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads,
getString(R.string.download_tab_downloads), WorldItemsFragment.class));
// mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads,
// getString(R.string.download_tab_downloads), DownloadIndexFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads,
getString(R.string.download_tab_downloads), DownloadIndexFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
getString(R.string.download_tab_local), LocalIndexesFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_updates,
getString(R.string.download_tab_updates), UpdatesIndexFragment.class));
@ -760,115 +762,4 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
}
}
}
public static class ActiveDownloadsDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new Builder(getActivity());
builder.setTitle(R.string.downloads).setNegativeButton(R.string.shared_string_cancel, null);
Collection<List<DownloadEntry>> vs =
DownloadActivity.downloadListIndexThread.getEntriesToDownload().values();
ArrayList<DownloadEntry> downloadEntries = new ArrayList<>();
for (List<DownloadEntry> list : vs) {
downloadEntries.addAll(list);
}
final DownloadEntryAdapter adapter = new DownloadEntryAdapter(getActivity(), downloadEntries);
builder.setAdapter(adapter, null);
((DownloadActivity) getActivity()).registerUpdateListener(adapter);
return builder.create();
}
private static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry> {
private final Drawable deleteDrawable;
private int itemInProgressPosition = -1;
private int progress = -1;
private final Set<Integer> downloadedItems = new HashSet<>();
private boolean isFinished;
public DownloadEntryAdapter(Context context, List<DownloadEntry> objects) {
super(context, R.layout.two_line_with_images_list_item, objects);
deleteDrawable = ((OsmandApplication) context.getApplicationContext()).getIconsCache()
.getPaintedContentIcon(R.drawable.ic_action_remove_dark,
context.getResources().getColor(R.color.dash_search_icon_dark));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
DownloadEntryViewHolder viewHolder =
new DownloadEntryViewHolder(convertView, deleteDrawable);
convertView.setTag(viewHolder);
}
DownloadEntryViewHolder viewHolder = (DownloadEntryViewHolder) convertView.getTag();
viewHolder.bindDownloadEntry(getItem(position));
if (position == itemInProgressPosition) {
viewHolder.progressBar.setIndeterminate(false);
viewHolder.progressBar.setProgress(progress);
} else if (isFinished || downloadedItems.contains(position)) {
viewHolder.progressBar.setIndeterminate(false);
viewHolder.progressBar.setProgress(viewHolder.progressBar.getMax());
}
return convertView;
}
public void setProgress(BasicProgressAsyncTask<?, ?, ?> task, Object tag) {
isFinished = task == null
|| task.getStatus() == AsyncTask.Status.FINISHED;
itemInProgressPosition = -1;
progress = -1;
if (isFinished) return;
if (tag instanceof DownloadEntry) {
progress = task.getProgressPercentage();
for (int i = 0; i < getCount(); i++) {
if (getItem(i).equals(tag)) {
itemInProgressPosition = i;
downloadedItems.add(i);
}
}
}
notifyDataSetChanged();
}
}
private static class DownloadEntryViewHolder {
private final TextView nameTextView;
private final TextView descrTextView;
private final ImageView leftImageView;
private final ImageView rightImageButton;
private final Button rightButton;
private final ProgressBar progressBar;
private final TextView mapDateTextView;
private final Drawable deleteDrawable;
private DownloadEntryViewHolder(View convertView, Drawable deleteDrawable) {
this.deleteDrawable = deleteDrawable;
nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
rightButton = (Button) convertView.findViewById(R.id.rightButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
mapDateTextView = (TextView) convertView.findViewById(R.id.mapDateTextView);
}
public void bindDownloadEntry(DownloadEntry downloadEntry) {
nameTextView.setText(downloadEntry.baseName);
descrTextView.setText(String.format("%1$s MBb from %2$s Mb", 123.440,
downloadEntry.sizeMB));
rightImageButton.setImageDrawable(deleteDrawable);
rightImageButton.setVisibility(View.VISIBLE);
rightImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
progressBar.setVisibility(View.VISIBLE);
progressBar.setIndeterminate(true);
}
}
}
}

View file

@ -364,7 +364,6 @@ public class DownloadIndexesThread {
String breakDownloadMessage = null;
downloadCycle:
while (!entriesToDownload.isEmpty()) {
Iterator<Entry<IndexItem, List<DownloadEntry>>> it = entriesToDownload.entrySet().iterator();
IndexItem file = null;
List<DownloadEntry> list = null;

View file

@ -161,20 +161,20 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
this.initializedName = initializedName;
}
@Override
public String toString() {
return "IndexItem{" +
"description='" + description + '\'' +
", fileName='" + fileName + '\'' +
", simplifiedFileName='" + simplifiedFileName + '\'' +
", size='" + size + '\'' +
", timestamp=" + timestamp +
", contentSize=" + contentSize +
", containerSize=" + containerSize +
", type=" + type.getTag() +
", extra=" + extra +
'}';
}
// @Override
// public String toString() {
// return "IndexItem{" +
// "description='" + description + '\'' +
// ", fileName='" + fileName + '\'' +
// ", simplifiedFileName='" + simplifiedFileName + '\'' +
// ", size='" + size + '\'' +
// ", timestamp=" + timestamp +
// ", contentSize=" + contentSize +
// ", containerSize=" + containerSize +
// ", type=" + type.getTag() +
// ", extra=" + extra +
// '}';
// }
@Override
public int describeContents() {

View file

@ -0,0 +1,180 @@
package net.osmand.plus.download.items;
import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadEntry;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ActiveDownloadsDialogFragment extends DialogFragment {
private final static Log LOG = PlatformUtil.getLog(ActiveDownloadsDialogFragment.class);
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.downloads).setNegativeButton(R.string.shared_string_cancel, null);
Collection<List<DownloadEntry>> vs =
DownloadActivity.downloadListIndexThread.getEntriesToDownload().values();
ArrayList<DownloadEntry> downloadEntries = new ArrayList<>();
for (List<DownloadEntry> list : vs) {
downloadEntries.addAll(list);
}
final DownloadEntryAdapter adapter = new DownloadEntryAdapter(
(DownloadActivity) getActivity(), downloadEntries);
builder.setAdapter(adapter, null);
((DownloadActivity) getActivity()).registerUpdateListener(adapter);
return builder.create();
}
public static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry> {
private final Drawable deleteDrawable;
private final DownloadActivity context;
private int itemInProgressPosition = -1;
private int progress = -1;
private final Set<Integer> downloadedItems = new HashSet<>();
private boolean isFinished;
public DownloadEntryAdapter(DownloadActivity context, List<DownloadEntry> objects) {
super(context, R.layout.two_line_with_images_list_item, objects);
this.context = context;
deleteDrawable = context.getMyApplication().getIconsCache()
.getPaintedContentIcon(R.drawable.ic_action_remove_dark,
context.getResources().getColor(R.color.dash_search_icon_dark));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
DownloadEntryViewHolder viewHolder =
new DownloadEntryViewHolder(convertView, deleteDrawable, context, this);
convertView.setTag(viewHolder);
}
DownloadEntryViewHolder viewHolder = (DownloadEntryViewHolder) convertView.getTag();
int localProgress = itemInProgressPosition == position ? progress : -1;
viewHolder.bindDownloadEntry(getItem(position), localProgress,
isFinished || downloadedItems.contains(position));
return convertView;
}
public void setProgress(BasicProgressAsyncTask<?, ?, ?> task, Object tag) {
isFinished = task == null
|| task.getStatus() == AsyncTask.Status.FINISHED;
itemInProgressPosition = -1;
progress = -1;
if (isFinished) return;
if (tag instanceof DownloadEntry) {
progress = task.getProgressPercentage();
for (int i = 0; i < getCount(); i++) {
if (getItem(i).equals(tag)) {
itemInProgressPosition = i;
downloadedItems.add(i);
}
}
}
notifyDataSetChanged();
}
}
private static class DownloadEntryViewHolder {
public final View.OnClickListener activeDownloadOnClickListener;
private final TextView nameTextView;
private final TextView descrTextView;
private final ImageView leftImageView;
private final ImageView rightImageButton;
private final Button rightButton;
private final ProgressBar progressBar;
private final TextView mapDateTextView;
private final Drawable deleteDrawable;
private final DownloadActivity context;
private final DownloadEntryAdapter adapter;
private DownloadEntryViewHolder(View convertView, Drawable deleteDrawable,
final DownloadActivity context,
DownloadEntryAdapter adapter) {
this.deleteDrawable = deleteDrawable;
this.context = context;
this.adapter = adapter;
nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
rightButton = (Button) convertView.findViewById(R.id.rightButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
mapDateTextView = (TextView) convertView.findViewById(R.id.mapDateTextView);
progressBar.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(deleteDrawable);
activeDownloadOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
context.makeSureUserCancelDownload();
}
};
}
public void bindDownloadEntry(final DownloadEntry downloadEntry, final int progress,
boolean isDownloaded) {
nameTextView.setText(downloadEntry.baseName);
rightImageButton.setVisibility(View.VISIBLE);
int localProgress = progress;
boolean isIndeterminate = true;
View.OnClickListener onClickListener = null;
if (progress != -1) {
// downloading
isIndeterminate = false;
onClickListener = activeDownloadOnClickListener;
double downloaded = downloadEntry.sizeMB * progress / 100;
descrTextView.setText(String.format("%.1f from %.1f MB", downloaded,
downloadEntry.sizeMB));
} else if (isDownloaded) {
// Downloaded
localProgress = progressBar.getMax();
descrTextView.setText(String.format("%.1f MB", downloadEntry.sizeMB));
} else {
// pending
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
context.getEntriesToDownload().remove(downloadEntry.item);
adapter.remove(downloadEntry);
}
};
descrTextView.setText(String.format("%.1f MB", downloadEntry.sizeMB));
}
rightImageButton.setOnClickListener(onClickListener);
progressBar.setIndeterminate(isIndeterminate);
progressBar.setProgress(localProgress);
}
}
}

View file

@ -0,0 +1,5 @@
package net.osmand.plus.download.items;
public interface DialogDismissListener {
void onDialogDismissed();
}

View file

@ -178,14 +178,6 @@ public class ItemViewHolder {
rightImageButton.setVisibility(View.VISIBLE);
}
if (disabled) {
leftImageView.setImageDrawable(getContextIcon(context, indexItem.getType().getIconResource(), textColorSecondary));
nameTextView.setTextColor(textColorSecondary);
} else {
leftImageView.setImageDrawable(getContextIcon(context, indexItem.getType().getIconResource()));
nameTextView.setTextColor(textColorPrimary);
}
if (indexFileNames != null && indexItem.isAlreadyDownloaded(indexFileNames)) {
boolean outdated = false;
String date;
@ -201,7 +193,19 @@ public class ItemViewHolder {
+ date;
mapDateTextView.setText(updateDescr);
int colorId = outdated ? R.color.color_distance : R.color.color_ok;
mapDateTextView.setTextColor(context.getResources().getColor(colorId));
final int color = context.getResources().getColor(colorId);
mapDateTextView.setTextColor(color);
leftImageView.setImageDrawable(getContextIcon(context,
indexItem.getType().getIconResource(), color));
nameTextView.setTextColor(textColorPrimary);
} else if (disabled) {
leftImageView.setImageDrawable(getContextIcon(context,
indexItem.getType().getIconResource(), textColorSecondary));
nameTextView.setTextColor(textColorSecondary);
} else {
leftImageView.setImageDrawable(getContextIcon(context,
indexItem.getType().getIconResource()));
nameTextView.setTextColor(textColorPrimary);
}
}

View file

@ -113,8 +113,4 @@ public class RegionDialogFragment extends DialogFragment{
public void setOnDismissListener(DialogDismissListener listener) {
this.dialogDismissListener = listener;
}
public interface DialogDismissListener {
void onDialogDismissed();
}
}