Text with download date for maps.

This commit is contained in:
GaidamakUA 2015-10-08 10:06:42 +03:00
parent 3110862202
commit be51e45f43
7 changed files with 111 additions and 29 deletions

View file

@ -37,17 +37,31 @@
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="Germany"/> tools:text="Germany"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/description" android:id="@+id/description"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1"
android:gravity="center_vertical" android:layout_height="wrap_content"
android:maxLines="25" android:gravity="center_vertical"
android:textColor="?android:textColorSecondary" android:maxLines="25"
android:textSize="@dimen/default_sub_text_size" android:textColor="?android:textColorSecondary"
tools:text="Map, Contour Lines, Wikipedia" android:textSize="@dimen/default_sub_text_size"
tools:visibility="gone"/> tools:text="Contour Lines"/>
<TextView
android:id="@+id/mapDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:maxLines="25"
android:textSize="@dimen/default_sub_text_size"
tools:text="Local version: 10/3/2015"/>
</LinearLayout>
<ProgressBar <ProgressBar
android:id="@+id/progressBar" android:id="@+id/progressBar"
@ -65,10 +79,10 @@
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dashFavIconMargin" android:layout_marginLeft="@dimen/dashFavIconMargin"
android:background="?attr/dashboard_button" android:background="?attr/dashboard_button"
tools:src="@drawable/ic_action_import"
android:scaleType="center" android:scaleType="center"
tools:visibility="visible" android:visibility="gone"
android:visibility="gone"/> tools:src="@drawable/ic_action_import"
tools:visibility="visible"/>
<Button <Button
android:id="@+id/rightButton" android:id="@+id/rightButton"

View file

@ -2,6 +2,7 @@ package net.osmand.plus.download;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -9,6 +10,7 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
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.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
@ -26,7 +28,6 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -43,8 +44,6 @@ import net.osmand.plus.download.items.WorldItemsFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.controls.PagerSlidingTabStrip; import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import org.apache.commons.logging.Log;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
@ -566,8 +565,8 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
} }
public void initFreeVersionBanner(View header) { public void initFreeVersionBanner(View view) {
visibleBanner = new BannerAndDownloadFreeVersion(header, this); visibleBanner = new BannerAndDownloadFreeVersion(view, this);
updateProgress(true); updateProgress(true);
} }
@ -584,11 +583,13 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
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;
private final View freeVersionTitle;
private ToggleCollapseFreeVersionBanner(View freeVersionDescriptionTextView, private ToggleCollapseFreeVersionBanner(View freeVersionDescriptionTextView,
View buttonsLinearLayout) { View buttonsLinearLayout, View freeVersionTitle) {
this.freeVersionDescriptionTextView = freeVersionDescriptionTextView; this.freeVersionDescriptionTextView = freeVersionDescriptionTextView;
this.buttonsLinearLayout = buttonsLinearLayout; this.buttonsLinearLayout = buttonsLinearLayout;
this.freeVersionTitle = freeVersionTitle;
} }
@Override @Override
@ -599,6 +600,7 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
} else { } else {
freeVersionDescriptionTextView.setVisibility(View.VISIBLE); freeVersionDescriptionTextView.setVisibility(View.VISIBLE);
buttonsLinearLayout.setVisibility(View.VISIBLE); buttonsLinearLayout.setVisibility(View.VISIBLE);
freeVersionTitle.setVisibility(View.VISIBLE);
} }
} }
} }
@ -694,7 +696,8 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
} }
}); });
laterButton.setOnClickListener( laterButton.setOnClickListener(
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout)); new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout, freeVersionBannerTitle));
} }
private void updateFreeVersionBanner() { private void updateFreeVersionBanner() {
@ -712,7 +715,7 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft)); downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft));
// TODO review logic // TODO review logic
freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout)); buttonsLinearLayout, freeVersionBannerTitle));
} }
private void updateAvailableDownloads(int activeTasks) { private void updateAvailableDownloads(int activeTasks) {
@ -733,5 +736,4 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
} }
} }
} }
} }

View file

@ -23,6 +23,9 @@ import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.text.DateFormat;
import java.util.Map;
public class ItemViewHolder { public class ItemViewHolder {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldItemsFragment.class); private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
@ -32,6 +35,11 @@ public class ItemViewHolder {
private final ImageView rightImageButton; private final ImageView rightImageButton;
private final Button rightButton; private final Button rightButton;
private final ProgressBar progressBar; private final ProgressBar progressBar;
private final TextView mapDateTextView;
private final Map<String, String> indexFileNames;
private final Map<String, String> indexActivatedFileNames;
private final java.text.DateFormat dateFormat;
private boolean srtmDisabled; private boolean srtmDisabled;
private boolean nauticalPluginDisabled; private boolean nauticalPluginDisabled;
@ -48,13 +56,21 @@ public class ItemViewHolder {
ASK_FOR_FULL_VERSION_PURCHASE ASK_FOR_FULL_VERSION_PURCHASE
} }
public ItemViewHolder(View convertView) { public ItemViewHolder(View convertView,
DateFormat dateFormat,
Map<String, String> indexFileNames,
Map<String, String> indexActivatedFileNames) {
this.indexFileNames = indexFileNames;
this.indexActivatedFileNames = indexActivatedFileNames;
this.dateFormat = dateFormat;
nameTextView = (TextView) convertView.findViewById(R.id.name); nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description); descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView); leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton); rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
rightButton = (Button) convertView.findViewById(R.id.rightButton); rightButton = (Button) convertView.findViewById(R.id.rightButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar); progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
mapDateTextView = (TextView) convertView.findViewById(R.id.mapDateTextView);
;
TypedValue typedValue = new TypedValue(); TypedValue typedValue = new TypedValue();
Resources.Theme theme = convertView.getContext().getTheme(); Resources.Theme theme = convertView.getContext().getTheme();
@ -177,6 +193,26 @@ public class ItemViewHolder {
leftImageView.setImageDrawable(getContextIcon(context, indexItem.getType().getIconResource())); leftImageView.setImageDrawable(getContextIcon(context, indexItem.getType().getIconResource()));
nameTextView.setTextColor(textColorPrimary); nameTextView.setTextColor(textColorPrimary);
} }
if (indexFileNames != null && indexItem.isAlreadyDownloaded(indexFileNames)) {
boolean outdated = false;
String date = null;
if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
// TODO write logic for outdated
date = indexItem.getDate(dateFormat);
} else {
String sfName = indexItem.getTargetFileName();
final boolean updatableResource = indexActivatedFileNames.containsKey(sfName);
date = updatableResource ? indexActivatedFileNames.get(sfName) : indexFileNames.get(sfName);
outdated = DownloadActivity.downloadListIndexThread.checkIfItemOutdated(indexItem);
}
String updateDescr = context.getResources().getString(R.string.local_index_installed) + ": "
+ date;
mapDateTextView.setText(updateDescr);
int colorId = outdated ? R.color.color_distance : R.color.color_ok;
mapDateTextView.setTextColor(context.getResources().getColor(colorId));
}
} }
public void bindRegion(WorldRegion region, DownloadActivity context) { public void bindRegion(WorldRegion region, DownloadActivity context) {

View file

@ -120,6 +120,10 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
public DownloadActivity getMyActivity() {
return (DownloadActivity) getActivity();
}
private void fillRegionItemsAdapter(ItemsListBuilder builder) { private void fillRegionItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
@ -207,7 +211,10 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()) convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false); .inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView); viewHolder = new ItemViewHolder(convertView,
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
} else { } else {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();
@ -223,7 +230,10 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()) convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false); .inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView); viewHolder = new ItemViewHolder(convertView,
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
} else { } else {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();

View file

@ -110,6 +110,10 @@ public class SearchItemsFragment extends Fragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
public DownloadActivity getMyActivity() {
return (DownloadActivity) getActivity();
}
private void fillSearchItemsAdapter() { private void fillSearchItemsAdapter() {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
@ -191,7 +195,10 @@ public class SearchItemsFragment extends Fragment {
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()) convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false); .inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView); viewHolder = new ItemViewHolder(convertView,
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
} else { } else {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();

View file

@ -14,7 +14,6 @@ import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
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.BaseDownloadActivity;
@ -113,6 +112,10 @@ public class VoiceItemsFragment extends OsmandExpandableListFragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
public DownloadActivity getMyActivity() {
return (DownloadActivity) getActivity();
}
private void fillVoiceItemsAdapter(ItemsListBuilder builder) { private void fillVoiceItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
@ -181,7 +184,10 @@ public class VoiceItemsFragment extends OsmandExpandableListFragment {
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()) convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false); .inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView); viewHolder = new ItemViewHolder(convertView,
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
} else { } else {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();

View file

@ -92,6 +92,10 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
public DownloadActivity getMyActivity() {
return (DownloadActivity) getActivity();
}
private void fillWorldItemsAdapter(ItemsListBuilder builder) { private void fillWorldItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
@ -260,7 +264,10 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()) convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false); .inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView); viewHolder = new ItemViewHolder(convertView,
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
} else { } else {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();