Downdload progress bar in progress. Dialogs refactored as DialogFragments.

This commit is contained in:
GaidamakUA 2015-09-30 11:06:51 +03:00
parent 8a1198611a
commit 09aa80570b
8 changed files with 182 additions and 119 deletions

View file

@ -9,6 +9,7 @@
android:orientation="vertical"> android:orientation="vertical">
<View <View
android:id="@+id/divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:background="?attr/dashboard_divider"/> android:background="?attr/dashboard_divider"/>
@ -28,18 +29,18 @@
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/map_name" android:id="@+id/name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary" android:ellipsize="end"
android:textSize="@dimen/default_list_text_size"
android:lines="1" android:lines="1"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/lorem_ipsum"/> tools:text="@string/lorem_ipsum"/>
<TextView <TextView
android:id="@+id/map_descr" android:id="@+id/description"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"

View file

@ -48,6 +48,12 @@
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"/>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout> </LinearLayout>
@ -60,7 +66,9 @@
android:background="?attr/dashboard_button" android:background="?attr/dashboard_button"
android:focusable="false" android:focusable="false"
android:focusableInTouchMode="false" android:focusableInTouchMode="false"
tools:src="@drawable/ic_action_import"/> tools:src="@drawable/ic_action_import"
tools:visibility="visible"
android:visibility="gone"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="index_item" type="id"/>
<item name="fragment" type="id"/>
</resources>

View file

@ -117,8 +117,8 @@ public class DashUpdatesFragment extends DashBaseFragment {
String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", " String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", "
+ item.getSizeDescription(getMyApplication()); + item.getSizeDescription(getMyApplication());
String eName = name.replace("\n", " "); String eName = name.replace("\n", " ");
((TextView) view.findViewById(R.id.map_name)).setText(eName); ((TextView) view.findViewById(R.id.name)).setText(eName);
((TextView) view.findViewById(R.id.map_descr)).setText(d); ((TextView) view.findViewById(R.id.description)).setText(d);
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.ProgressBar); final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.ProgressBar);
View downloadButton = (view.findViewById(R.id.btn_download)); View downloadButton = (view.findViewById(R.id.btn_download));
downloadButton.setOnClickListener(new View.OnClickListener() { downloadButton.setOnClickListener(new View.OnClickListener() {
@ -170,8 +170,8 @@ public class DashUpdatesFragment extends DashBaseFragment {
} }
cancelButton.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_remove_dark)); cancelButton.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_remove_dark));
View view = (View) cancelButton.getParent(); View view = (View) cancelButton.getParent();
if (view != null && view.findViewById(R.id.map_descr) != null) { if (view != null && view.findViewById(R.id.description) != null) {
view.findViewById(R.id.map_descr).setVisibility(View.GONE); view.findViewById(R.id.description).setVisibility(View.GONE);
} }
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@Override @Override

View file

@ -1,11 +1,14 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.widget.Toast; import android.widget.Toast;
@ -27,10 +30,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
/**
* Created by Denis
* on 25.11.2014.
*/
public class BaseDownloadActivity extends ActionBarProgressActivity { public class BaseDownloadActivity extends ActionBarProgressActivity {
protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE; protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
protected OsmandSettings settings; protected OsmandSettings settings;
@ -162,7 +161,8 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
if (Version.isFreeVersion(getMyApplication())) { if (Version.isFreeVersion(getMyApplication())) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get(); int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) { if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
dialogToInstallPaid(); new InstallPaidVersionDialogFragment()
.show(getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG);
} else { } else {
downloadFilesCheckInternet(); downloadFilesCheckInternet();
} }
@ -171,44 +171,11 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
} }
} }
protected void dialogToInstallPaid() {
String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
AlertDialog.Builder msg = new AlertDialog.Builder(this);
msg.setTitle(R.string.free_version_title);
msg.setMessage(msgTx);
if (Version.isMarketEnabled(getMyApplication())) {
msg.setPositiveButton(R.string.install_paid, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(getMyApplication())
+ "net.osmand.plus"));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
msg.setNegativeButton(R.string.shared_string_cancel, null);
} else {
msg.setNeutralButton(R.string.shared_string_ok, null);
}
msg.show();
}
protected void downloadFilesCheckInternet() { protected void downloadFilesCheckInternet() {
if (!getMyApplication().getSettings().isWifiConnected()) { if (!getMyApplication().getSettings().isWifiConnected()) {
if (getMyApplication().getSettings().isInternetConnectionAvailable()) { if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); new ConfirmDownloadDialogFragment().show(getSupportFragmentManager(),
builder.setMessage(getString(R.string.download_using_mobile_internet)); ConfirmDownloadDialogFragment.TAG);
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadFilesPreCheckSpace();
}
});
builder.setNegativeButton(R.string.shared_string_no, null);
builder.show();
} else { } else {
AccessibleToast.makeText(this, R.string.no_index_file_to_download, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(this, R.string.no_index_file_to_download, Toast.LENGTH_LONG).show();
} }
@ -289,5 +256,58 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
public void removeFromQueue(IndexItem item) { public void removeFromQueue(IndexItem item) {
downloadQueue.remove(item); downloadQueue.remove(item);
} }
public static class InstallPaidVersionDialogFragment extends DialogFragment {
public static final String TAG = "InstallPaidVersionDialogFragment";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
AlertDialog.Builder msg = new AlertDialog.Builder(getActivity());
msg.setTitle(R.string.free_version_title);
msg.setMessage(msgTx);
if (Version.isMarketEnabled(getMyApplication())) {
msg.setPositiveButton(R.string.install_paid, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(Version.marketPrefix(getMyApplication())
+ "net.osmand.plus"));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
msg.setNegativeButton(R.string.shared_string_cancel, null);
} else {
msg.setNeutralButton(R.string.shared_string_ok, null);
}
return msg.create();
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
}
public static class ConfirmDownloadDialogFragment extends DialogFragment {
public static final String TAG = "ConfirmDownloadDialogFragment";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.download_using_mobile_internet));
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((BaseDownloadActivity) getActivity()).downloadFilesPreCheckSpace();
}
});
builder.setNegativeButton(R.string.shared_string_no, null);
return builder.create();
}
}
} }

View file

@ -360,7 +360,8 @@ public class DownloadActivity extends BaseDownloadActivity {
protected void downloadWikiFiles() { protected void downloadWikiFiles() {
if (Version.isFreeVersion(getMyApplication())) { if (Version.isFreeVersion(getMyApplication())) {
dialogToInstallPaid(); new InstallPaidVersionDialogFragment().show(getSupportFragmentManager(),
InstallPaidVersionDialogFragment.TAG);
} else { } else {
Builder bld = new AlertDialog.Builder(this); Builder bld = new AlertDialog.Builder(this);
final List<IndexItem> wi = getWikipediaItems(); final List<IndexItem> wi = getWikipediaItems();

View file

@ -7,6 +7,7 @@ import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -61,8 +62,9 @@ public class MapsInCategoryFragment extends DialogFragment {
createInstance(category).show(getChildFragmentManager(), TAG); createInstance(category).show(getChildFragmentManager(), TAG);
} }
public void onIndexItemSelected(@NonNull IndexItem indexItem) { public void startMapDownload(@NonNull IndexItem indexItem,
LOG.debug("onIndexItemSelected()"); @NonNull ProgressBar progressBar) {
LOG.debug("startMapDownload()");
((DownloadActivity) getActivity()).startDownload(indexItem); ((DownloadActivity) getActivity()).startDownload(indexItem);
} }

View file

@ -2,6 +2,7 @@ package net.osmand.plus.download.newimplementation;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -13,6 +14,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -34,7 +36,8 @@ public class SubcategoriesFragment extends Fragment {
ListView listView = new ListView(getActivity()); ListView listView = new ListView(getActivity());
final OsmandApplication application = (OsmandApplication) getActivity().getApplication(); final OsmandApplication application = (OsmandApplication) getActivity().getApplication();
final MapFilesAdapter mAdapter = new MapFilesAdapter(getActivity()); final MapFilesAdapter mAdapter = new MapFilesAdapter(getActivity(),
(MapsInCategoryFragment) getParentFragment());
listView.setAdapter(mAdapter); listView.setAdapter(mAdapter);
mAdapter.addAll(category.items); mAdapter.addAll(category.items);
mAdapter.addAll(category.subcats); mAdapter.addAll(category.subcats);
@ -50,9 +53,6 @@ public class SubcategoriesFragment extends Fragment {
if (item instanceof IndexItemCategoryWithSubcat) { if (item instanceof IndexItemCategoryWithSubcat) {
((MapsInCategoryFragment) getParentFragment()) ((MapsInCategoryFragment) getParentFragment())
.onCategorySelected((IndexItemCategoryWithSubcat) item); .onCategorySelected((IndexItemCategoryWithSubcat) item);
} else if (item instanceof IndexItem) {
((MapsInCategoryFragment) getParentFragment())
.onIndexItemSelected((IndexItem) item);
} }
} }
}); });
@ -71,8 +71,11 @@ public class SubcategoriesFragment extends Fragment {
private static class MapFilesAdapter extends ArrayAdapter<HasName> { private static class MapFilesAdapter extends ArrayAdapter<HasName> {
public MapFilesAdapter(Context context) { final MapsInCategoryFragment fragment;
public MapFilesAdapter(Context context, MapsInCategoryFragment fragment) {
super(context, R.layout.two_line_with_images_list_item); super(context, R.layout.two_line_with_images_list_item);
this.fragment = fragment;
} }
@Override @Override
@ -91,7 +94,8 @@ public class SubcategoriesFragment extends Fragment {
viewHolder.bindCategory((IndexItemCategoryWithSubcat) item, viewHolder.bindCategory((IndexItemCategoryWithSubcat) item,
(DownloadActivity) getContext()); (DownloadActivity) getContext());
} else if (item instanceof IndexItem) { } else if (item instanceof IndexItem) {
viewHolder.bindIndexItem((IndexItem) item, (DownloadActivity) getContext()); viewHolder.bindIndexItem((IndexItem) item, (DownloadActivity) getContext(),
fragment);
} else { } else {
throw new IllegalArgumentException("Item must be of type IndexItem or " + throw new IllegalArgumentException("Item must be of type IndexItem or " +
"IndexItemCategory but is of type:" + item.getClass()); "IndexItemCategory but is of type:" + item.getClass());
@ -100,19 +104,22 @@ public class SubcategoriesFragment extends Fragment {
} }
private static class ViewHolder { private static class ViewHolder {
TextView nameTextView; private final TextView nameTextView;
TextView descrTextView; private final TextView descrTextView;
ImageView leftImageView; private final ImageView leftImageView;
ImageView rightImageButton; private final ImageView rightImageButton;
private final ProgressBar progressBar;
public ViewHolder(View convertView) { public ViewHolder(View convertView) {
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);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
} }
public void bindIndexItem(IndexItem indexItem, DownloadActivity context) { public void bindIndexItem(final IndexItem indexItem, DownloadActivity context,
MapsInCategoryFragment fragment) {
if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
nameTextView.setText(indexItem.getVisibleName(context, nameTextView.setText(indexItem.getVisibleName(context,
context.getMyApplication().getRegions())); context.getMyApplication().getRegions()));
@ -120,8 +127,22 @@ public class SubcategoriesFragment extends Fragment {
nameTextView.setText(indexItem.getType().getString(context)); nameTextView.setText(indexItem.getType().getString(context));
} }
descrTextView.setText(indexItem.getSizeDescription(context)); descrTextView.setText(indexItem.getSizeDescription(context));
leftImageView.setImageDrawable(context.getMyApplication() leftImageView.setImageDrawable(getContextIcon(context,
.getIconsCache().getContentIcon(indexItem.getType().getIconResource())); indexItem.getType().getIconResource()));
rightImageButton.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(getContextIcon(context,
R.drawable.ic_action_import));
rightImageButton.setTag(R.id.index_item, indexItem);
rightImageButton.setTag(R.id.fragment, fragment);
rightImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((MapsInCategoryFragment) v.getTag(R.id.fragment))
.startMapDownload((IndexItem) v.getTag(R.id.index_item), progressBar);
progressBar.setVisibility(View.VISIBLE);
}
});
progressBar.setVisibility(View.GONE);
} }
public void bindCategory(IndexItemCategoryWithSubcat category, public void bindCategory(IndexItemCategoryWithSubcat category,
@ -139,8 +160,13 @@ public class SubcategoriesFragment extends Fragment {
} else { } else {
descrTextView.setText(R.string.shared_string_others); descrTextView.setText(R.string.shared_string_others);
} }
leftImageView.setImageDrawable(context.getMyApplication() leftImageView.setImageDrawable(getContextIcon(context, R.drawable.ic_map));
.getIconsCache().getContentIcon(R.drawable.ic_map)); rightImageButton.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
}
private Drawable getContextIcon(DownloadActivity context, int resourceId) {
return context.getMyApplication().getIconsCache().getContentIcon(resourceId);
} }
} }
} }