Buttons for banner, second line removed
This commit is contained in:
parent
0d207ce241
commit
fc769ce8db
3 changed files with 64 additions and 49 deletions
|
@ -46,7 +46,8 @@
|
||||||
android:maxLines="25"
|
android:maxLines="25"
|
||||||
android:textColor="?android:textColorSecondary"
|
android:textColor="?android:textColorSecondary"
|
||||||
android:textSize="@dimen/default_sub_text_size"
|
android:textSize="@dimen/default_sub_text_size"
|
||||||
tools:text="Map, Contour Lines, Wikipedia"/>
|
tools:text="Map, Contour Lines, Wikipedia"
|
||||||
|
tools:visibility="gone"/>
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
private TextView progressMessage;
|
private TextView progressMessage;
|
||||||
private TextView progressPercent;
|
private TextView progressPercent;
|
||||||
private ImageView cancel;
|
private ImageView cancel;
|
||||||
|
|
||||||
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
|
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
|
||||||
|
|
||||||
private String initialFilter = "";
|
private String initialFilter = "";
|
||||||
|
@ -265,27 +265,27 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
boolean indeterminate = true;
|
boolean indeterminate = true;
|
||||||
int percent = 0;
|
int percent = 0;
|
||||||
String message = "";
|
String message = "";
|
||||||
if(!isFinished) {
|
if (!isFinished) {
|
||||||
indeterminate = basicProgressAsyncTask.isIndeterminate();
|
indeterminate = basicProgressAsyncTask.isIndeterminate();
|
||||||
message = basicProgressAsyncTask.getDescription();
|
message = basicProgressAsyncTask.getDescription();
|
||||||
if(!indeterminate) {
|
if (!indeterminate) {
|
||||||
percent = basicProgressAsyncTask.getProgressPercentage();
|
percent = basicProgressAsyncTask.getProgressPercentage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(visibleBanner != null) {
|
if (visibleBanner != null) {
|
||||||
visibleBanner.updateProgress(isFinished, indeterminate, percent, message);
|
visibleBanner.updateProgress(isFinished, indeterminate, percent, message);
|
||||||
}
|
}
|
||||||
if(!updateOnlyProgress) {
|
if (!updateOnlyProgress) {
|
||||||
updateDownloadButton();
|
updateDownloadButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO delete after refactoring!
|
// TODO delete after refactoring!
|
||||||
//needed when rotation is performed and progress can be null
|
//needed when rotation is performed and progress can be null
|
||||||
if (progressView == null) {
|
if (progressView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateOnlyProgress) {
|
if (updateOnlyProgress) {
|
||||||
if (basicProgressAsyncTask != null && !basicProgressAsyncTask.isIndeterminate()) {
|
if (basicProgressAsyncTask != null && !basicProgressAsyncTask.isIndeterminate()) {
|
||||||
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
|
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
|
||||||
|
@ -356,6 +356,13 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean startDownload(IndexItem item) {
|
||||||
|
final boolean b = super.startDownload(item);
|
||||||
|
visibleBanner.initFreeVersionBanner();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadedIndexes() {
|
public void downloadedIndexes() {
|
||||||
for (WeakReference<Fragment> ref : fragSet) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
|
@ -612,14 +619,14 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void initFreeVersionBanner(View header) {
|
public void initFreeVersionBanner(View header) {
|
||||||
visibleBanner = new BannerAndDownloadFreeVersion(header, this);
|
visibleBanner = new BannerAndDownloadFreeVersion(header, this);
|
||||||
updateProgress(true);
|
updateProgress(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
||||||
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
||||||
Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
|
Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
|
||||||
|
@ -653,14 +660,19 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BannerAndDownloadFreeVersion {
|
public static class BannerAndDownloadFreeVersion {
|
||||||
private final View freeVersionBanner;
|
private final View freeVersionBanner;
|
||||||
private final View downloadProgressLayout;
|
private final View downloadProgressLayout;
|
||||||
private final ProgressBar progressBar;
|
private final ProgressBar progressBar;
|
||||||
private final TextView leftTextView;
|
private final TextView leftTextView;
|
||||||
private final TextView rightTextView;
|
private final TextView rightTextView;
|
||||||
private final Context ctx;
|
private final Context ctx;
|
||||||
|
private final boolean shouldShowFreeVersionBanner;
|
||||||
|
private final ProgressBar downloadsLeftProgressBar;
|
||||||
|
private final View buttonsLinearLayout;
|
||||||
|
private final TextView freeVersionDescriptionTextView;
|
||||||
private OsmandApplication application;
|
private OsmandApplication application;
|
||||||
|
private final TextView downloadsLeftTextView;
|
||||||
|
|
||||||
public BannerAndDownloadFreeVersion(View view, Context ctx) {
|
public BannerAndDownloadFreeVersion(View view, Context ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
|
@ -669,21 +681,30 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||||
leftTextView = (TextView) view.findViewById(R.id.leftTextView);
|
leftTextView = (TextView) view.findViewById(R.id.leftTextView);
|
||||||
rightTextView = (TextView) view.findViewById(R.id.rightTextView);
|
rightTextView = (TextView) view.findViewById(R.id.rightTextView);
|
||||||
application = (OsmandApplication) ctx.getApplicationContext();
|
application = (OsmandApplication) ctx.getApplicationContext();
|
||||||
onCreateBanner(view);
|
shouldShowFreeVersionBanner = Version.isFreeVersion(application)
|
||||||
|
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
|
||||||
|
initFreeVersionBanner();
|
||||||
|
downloadsLeftTextView = (TextView) freeVersionBanner.findViewById(R.id.downloadsLeftTextView);
|
||||||
|
downloadsLeftProgressBar = (ProgressBar) freeVersionBanner.findViewById(R.id.downloadsLeftProgressBar);
|
||||||
|
buttonsLinearLayout = freeVersionBanner.findViewById(R.id.buttonsLinearLayout);
|
||||||
|
freeVersionDescriptionTextView = (TextView) freeVersionBanner
|
||||||
|
.findViewById(R.id.freeVersionDescriptionTextView);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProgress(boolean isFinished, boolean indeterminate, int percent, String message) {
|
public void updateProgress(boolean isFinished, boolean indeterminate, int percent, String message) {
|
||||||
if(isFinished) {
|
if (isFinished) {
|
||||||
downloadProgressLayout.setVisibility(View.GONE);
|
downloadProgressLayout.setVisibility(View.GONE);
|
||||||
freeVersionBanner.setVisibility(View.VISIBLE);
|
// TODO
|
||||||
|
// freeVersionBanner.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
|
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
|
||||||
freeVersionBanner.setVisibility(View.GONE);
|
freeVersionBanner.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
downloadProgressLayout.setVisibility(View.VISIBLE);
|
downloadProgressLayout.setVisibility(View.VISIBLE);
|
||||||
progressBar.setIndeterminate(indeterminate);
|
progressBar.setIndeterminate(indeterminate);
|
||||||
if(indeterminate) {
|
if (indeterminate) {
|
||||||
// TODO
|
// TODO
|
||||||
leftTextView.setText(message);
|
leftTextView.setText(message);
|
||||||
} else {
|
} else {
|
||||||
|
@ -694,36 +715,18 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
rightTextView.setText(percent + "%");
|
rightTextView.setText(percent + "%");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCreateBanner(View view) {
|
private void initFreeVersionBanner() {
|
||||||
OsmandSettings settings = application.getSettings();
|
if (!shouldShowFreeVersionBanner) {
|
||||||
if (!Version.isFreeVersion(application) && !settings.SHOULD_SHOW_FREE_VERSION_BANNER.get()) {
|
|
||||||
freeVersionBanner.setVisibility(View.GONE);
|
freeVersionBanner.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
downloadsLeftProgressBar.setMax(BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS);
|
||||||
TextView downloadsLeftTextView = (TextView) view.findViewById(R.id.downloadsLeftTextView);
|
|
||||||
final int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
|
||||||
- settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
|
||||||
downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft));
|
|
||||||
|
|
||||||
|
|
||||||
final TextView freeVersionDescriptionTextView = (TextView) view
|
|
||||||
.findViewById(R.id.freeVersionDescriptionTextView);
|
|
||||||
freeVersionDescriptionTextView.setText(ctx.getString(R.string.free_version_message,
|
freeVersionDescriptionTextView.setText(ctx.getString(R.string.free_version_message,
|
||||||
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
|
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
|
||||||
|
freeVersionBanner.findViewById(R.id.getFullVersionButton).setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
View buttonsLinearLayout = view.findViewById(R.id.buttonsLinearLayout);
|
|
||||||
freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
|
|
||||||
buttonsLinearLayout));
|
|
||||||
|
|
||||||
ProgressBar downloadsLeftProgressBar = (ProgressBar) view.findViewById(R.id.downloadsLeftProgressBar);
|
|
||||||
downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get());
|
|
||||||
|
|
||||||
view.findViewById(R.id.getFullVersionButton).setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
BaseDownloadActivity context = (BaseDownloadActivity) v.getContext();
|
BaseDownloadActivity context = (BaseDownloadActivity) v.getContext();
|
||||||
|
@ -735,9 +738,21 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
view.findViewById(R.id.laterButton).setOnClickListener(
|
freeVersionBanner.findViewById(R.id.laterButton).setOnClickListener(
|
||||||
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout));
|
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFreeVersionBanner() {
|
||||||
|
if (!shouldShowFreeVersionBanner) return;
|
||||||
|
OsmandSettings settings = application.getSettings();
|
||||||
|
downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get());
|
||||||
|
final int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
||||||
|
- settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||||
|
downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft));
|
||||||
|
// TODO review logic
|
||||||
|
freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
|
||||||
|
buttonsLinearLayout));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class ItemViewHolder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
descrTextView.setVisibility(View.VISIBLE);
|
||||||
if (!showTypeInTitle && (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
|
if (!showTypeInTitle && (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
|
||||||
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
|
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
|
||||||
descrTextView.setText(indexItem.getType().getString(context));
|
descrTextView.setText(indexItem.getType().getString(context));
|
||||||
|
@ -188,10 +189,8 @@ public class ItemViewHolder {
|
||||||
}
|
}
|
||||||
stringBuilder.append(activityType.getString(context));
|
stringBuilder.append(activityType.getString(context));
|
||||||
}
|
}
|
||||||
descrTextView.setText(stringBuilder.toString());
|
|
||||||
} else {
|
|
||||||
descrTextView.setText(R.string.shared_string_others);
|
|
||||||
}
|
}
|
||||||
|
descrTextView.setVisibility(View.GONE);
|
||||||
leftImageView.setImageDrawable(getContextIcon(context, R.drawable.ic_map));
|
leftImageView.setImageDrawable(getContextIcon(context, R.drawable.ic_map));
|
||||||
rightImageButton.setVisibility(View.GONE);
|
rightImageButton.setVisibility(View.GONE);
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
|
Loading…
Reference in a new issue