Update items
This commit is contained in:
parent
be38b19e88
commit
560206f476
4 changed files with 83 additions and 87 deletions
|
@ -52,15 +52,6 @@
|
|||
android:textSize="@dimen/default_sub_text_size"
|
||||
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
|
||||
|
|
|
@ -55,7 +55,6 @@ public class DownloadIndexesThread {
|
|||
|
||||
private DownloadResources indexes;
|
||||
|
||||
|
||||
public interface DownloadEvents {
|
||||
|
||||
void newDownloadIndexes();
|
||||
|
@ -75,7 +74,6 @@ public class DownloadIndexesThread {
|
|||
dbHelper = new DatabaseHelper(app);
|
||||
}
|
||||
|
||||
|
||||
/// UI notifications methods
|
||||
public void setUiActivity(BaseDownloadActivity uiActivity) {
|
||||
this.uiActivity = uiActivity;
|
||||
|
|
|
@ -24,7 +24,7 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
private List<IndexItem> rawResources;
|
||||
private List<IndexItem> itemsToUpdate = new ArrayList<>();
|
||||
//public static final String WORLD_BASEMAP_KEY = "world_basemap.obf.zip";
|
||||
public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap.obf.zip";
|
||||
public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap";
|
||||
|
||||
|
||||
public DownloadResources(OsmandApplication app) {
|
||||
|
|
|
@ -18,6 +18,8 @@ import net.osmand.plus.Version;
|
|||
import net.osmand.plus.WorldRegion;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
|
@ -36,9 +38,9 @@ public class ItemViewHolder {
|
|||
protected final ImageView rightImageButton;
|
||||
protected final Button rightButton;
|
||||
protected final ProgressBar progressBar;
|
||||
protected final TextView mapDateTextView;
|
||||
|
||||
private boolean srtmDisabled;
|
||||
private boolean srtmNeedsInstallation;
|
||||
private boolean nauticalPluginDisabled;
|
||||
private boolean freeVersion;
|
||||
|
||||
|
@ -46,10 +48,12 @@ public class ItemViewHolder {
|
|||
|
||||
private int textColorPrimary;
|
||||
private int textColorSecondary;
|
||||
private RightButtonAction rightButtonAction;
|
||||
private RightButtonAction clickAction;
|
||||
|
||||
|
||||
|
||||
private enum RightButtonAction {
|
||||
UNKNOWN,
|
||||
DOWNLOAD,
|
||||
ASK_FOR_SEAMARKS_PLUGIN,
|
||||
ASK_FOR_SRTM_PLUGIN_PURCHASE,
|
||||
ASK_FOR_SRTM_PLUGIN_ENABLE,
|
||||
|
@ -60,7 +64,6 @@ public class ItemViewHolder {
|
|||
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);
|
||||
|
@ -83,59 +86,52 @@ public class ItemViewHolder {
|
|||
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
|
||||
nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
|
||||
freeVersion = Version.isFreeVersion(context.getMyApplication());
|
||||
OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||
srtmNeedsInstallation = srtmPlugin == null || srtmPlugin.needsInstallation();
|
||||
}
|
||||
|
||||
// FIXME
|
||||
public void bindIndexItem(final IndexItem indexItem,
|
||||
boolean showTypeInTitle, boolean showTypeInDesc) {
|
||||
initAppStatusVariables();
|
||||
boolean disabled = false;
|
||||
rightButtonAction = RightButtonAction.UNKNOWN;
|
||||
boolean downloading = context.getDownloadThread().isDownloading(indexItem);
|
||||
boolean isDownloading = context.getDownloadThread().isDownloading(indexItem);
|
||||
int progress = -1;
|
||||
if (context.getDownloadThread().getCurrentDownloadingItem() == indexItem) {
|
||||
progress = context.getDownloadThread().getCurrentDownloadingItemProgress();
|
||||
}
|
||||
rightImageButton.setClickable(false);
|
||||
if (progress != -1) {
|
||||
rightImageButton.setClickable(true);
|
||||
rightImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
context.makeSureUserCancelDownload(indexItem);
|
||||
}
|
||||
});
|
||||
} else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
|
||||
nameTextView.setText(indexItem.getVisibleName(context,
|
||||
context.getMyApplication().getRegions(), false));
|
||||
boolean disabled = checkDisabledAndClickAction(indexItem);
|
||||
/// name and left item
|
||||
if (showTypeInTitle) {
|
||||
nameTextView.setText(indexItem.getType().getString(context));
|
||||
} else {
|
||||
if (indexItem.getSimplifiedFileName().equals(WORLD_SEAMARKS_KEY)
|
||||
&& nauticalPluginDisabled) {
|
||||
rightButtonAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN;
|
||||
disabled = true;
|
||||
}
|
||||
if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
|
||||
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
|
||||
OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||
if (srtmPlugin == null || srtmPlugin.needsInstallation()) {
|
||||
rightButtonAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_PURCHASE;
|
||||
} else if (!srtmPlugin.isActive()) {
|
||||
rightButtonAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
|
||||
}
|
||||
|
||||
disabled = true;
|
||||
} else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion) {
|
||||
rightButtonAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
|
||||
disabled = true;
|
||||
}
|
||||
if (showTypeInTitle) {
|
||||
nameTextView.setText(indexItem.getType().getString(context));
|
||||
} else {
|
||||
nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false));
|
||||
}
|
||||
nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false));
|
||||
}
|
||||
if (indexItem.isDownloaded()) {
|
||||
String date = indexItem.getLocalDate();
|
||||
boolean outdated = indexItem.isOutdated();
|
||||
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;
|
||||
final int color = context.getResources().getColor(colorId);
|
||||
mapDateTextView.setTextColor(color);
|
||||
leftImageView.setImageDrawable(getContentIcon(context,
|
||||
indexItem.getType().getIconResource(), color));
|
||||
nameTextView.setTextColor(textColorPrimary);
|
||||
} else if (disabled) {
|
||||
leftImageView.setImageDrawable(getContentIcon(context,
|
||||
indexItem.getType().getIconResource(), textColorSecondary));
|
||||
nameTextView.setTextColor(textColorSecondary);
|
||||
} else {
|
||||
leftImageView.setImageDrawable(getContentIcon(context,
|
||||
indexItem.getType().getIconResource()));
|
||||
nameTextView.setTextColor(textColorPrimary);
|
||||
}
|
||||
|
||||
if (progress == -1) {
|
||||
if (isDownloading) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
// FIXME mapDATETextView
|
||||
descrTextView.setVisibility(View.VISIBLE);
|
||||
if (!showTypeInTitle && (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
|
||||
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
|
||||
|
@ -145,44 +141,54 @@ public class ItemViewHolder {
|
|||
} else {
|
||||
descrTextView.setText(indexItem.getSizeDescription(context));
|
||||
}
|
||||
|
||||
rightImageButton.setVisibility(View.VISIBLE);
|
||||
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
Map<String,String> indexFileNames = context.getIndexFileNames();
|
||||
if (indexItem.isDownloaded()) {
|
||||
String date = indexItem.getLocalDate();
|
||||
boolean outdated = indexItem.isOutdated();
|
||||
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;
|
||||
final int color = context.getResources().getColor(colorId);
|
||||
mapDateTextView.setTextColor(color);
|
||||
leftImageView.setImageDrawable(getContentIcon(context,
|
||||
indexItem.getType().getIconResource(), color));
|
||||
nameTextView.setTextColor(textColorPrimary);
|
||||
} else if (disabled) {
|
||||
leftImageView.setImageDrawable(getContentIcon(context,
|
||||
indexItem.getType().getIconResource(), textColorSecondary));
|
||||
nameTextView.setTextColor(textColorSecondary);
|
||||
} else {
|
||||
leftImageView.setImageDrawable(getContentIcon(context,
|
||||
indexItem.getType().getIconResource()));
|
||||
nameTextView.setTextColor(textColorPrimary);
|
||||
}
|
||||
|
||||
} else {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
progressBar.setProgress(progress);
|
||||
rightImageButton.setImageDrawable(
|
||||
getContentIcon(context, R.drawable.ic_action_remove_dark));
|
||||
|
||||
descrTextView.setVisibility(View.GONE);
|
||||
|
||||
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark));
|
||||
rightImageButton.setClickable(true);
|
||||
rightImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
context.makeSureUserCancelDownload(indexItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (rightButtonAction != RightButtonAction.UNKNOWN) {
|
||||
|
||||
private boolean checkDisabledAndClickAction(final IndexItem indexItem) {
|
||||
boolean disabled = false;
|
||||
clickAction = RightButtonAction.DOWNLOAD;
|
||||
if (indexItem.getBasename().toLowerCase().equals(DownloadResources.WORLD_SEAMARKS_KEY)
|
||||
&& nauticalPluginDisabled) {
|
||||
clickAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN;
|
||||
disabled = true;
|
||||
} else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
|
||||
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
|
||||
if (srtmNeedsInstallation) {
|
||||
clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_PURCHASE;
|
||||
} else {
|
||||
clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
|
||||
}
|
||||
|
||||
disabled = true;
|
||||
} else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion) {
|
||||
clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
if (clickAction != RightButtonAction.DOWNLOAD) {
|
||||
rightButton.setText(R.string.get_plugin);
|
||||
rightButton.setVisibility(View.VISIBLE);
|
||||
rightImageButton.setVisibility(View.GONE);
|
||||
final RightButtonAction action = rightButtonAction;
|
||||
final RightButtonAction action = clickAction;
|
||||
|
||||
rightButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -210,16 +216,17 @@ public class ItemViewHolder {
|
|||
AccessibleToast.makeText(context,
|
||||
context.getString(R.string.activate_srtm_plugin), Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case UNKNOWN:
|
||||
case DOWNLOAD:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
rightButton.setVisibility(View.GONE);
|
||||
rightImageButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
return disabled;
|
||||
}
|
||||
|
||||
private Drawable getContentIcon(DownloadActivity context, int resourceId) {
|
||||
|
@ -231,6 +238,6 @@ public class ItemViewHolder {
|
|||
}
|
||||
|
||||
public boolean isItemAvailable() {
|
||||
return rightButtonAction == RightButtonAction.UNKNOWN;
|
||||
return clickAction == RightButtonAction.DOWNLOAD;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue