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

@ -1,66 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:layout_marginRight="@dimen/dashFavIconMargin"
android:orientation="vertical">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:layout_marginRight="@dimen/dashFavIconMargin"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/subHeaderMarginLeft"
android:layout_marginStart="@dimen/subHeaderMarginLeft"
android:orientation="horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/subHeaderMarginLeft"
android:layout_marginStart="@dimen/subHeaderMarginLeft"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/map_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:lines="1"
android:maxLines="1"
android:ellipsize="end"
tools:text="@string/lorem_ipsum" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/lorem_ipsum"/>
<TextView
android:id="@+id/map_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
tools:text="@string/lorem_ipsum" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
tools:text="@string/lorem_ipsum"/>
<ProgressBar
android:id="@+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
<ProgressBar
android:id="@+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
<ImageView
android:id="@+id/btn_download"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="center_vertical"
android:background="?attr/dashboard_button"
android:scaleType="center"
android:src="@drawable/ic_action_import"/>
</LinearLayout>
<ImageView
android:id="@+id/btn_download"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="center_vertical"
android:background="?attr/dashboard_button"
android:scaleType="center"
android:src="@drawable/ic_action_import"/>
</LinearLayout>
</LinearLayout>

View file

@ -48,6 +48,12 @@
android:textSize="@dimen/default_sub_text_size"
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>
@ -60,7 +66,9 @@
android:background="?attr/dashboard_button"
android:focusable="false"
android:focusableInTouchMode="false"
tools:src="@drawable/ic_action_import"/>
tools:src="@drawable/ic_action_import"
tools:visibility="visible"
android:visibility="gone"/>
</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()) + ", "
+ item.getSizeDescription(getMyApplication());
String eName = name.replace("\n", " ");
((TextView) view.findViewById(R.id.map_name)).setText(eName);
((TextView) view.findViewById(R.id.map_descr)).setText(d);
((TextView) view.findViewById(R.id.name)).setText(eName);
((TextView) view.findViewById(R.id.description)).setText(d);
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.ProgressBar);
View downloadButton = (view.findViewById(R.id.btn_download));
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));
View view = (View) cancelButton.getParent();
if (view != null && view.findViewById(R.id.map_descr) != null) {
view.findViewById(R.id.map_descr).setVisibility(View.GONE);
if (view != null && view.findViewById(R.id.description) != null) {
view.findViewById(R.id.description).setVisibility(View.GONE);
}
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -1,11 +1,14 @@
package net.osmand.plus.download;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.widget.Toast;
@ -27,10 +30,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by Denis
* on 25.11.2014.
*/
public class BaseDownloadActivity extends ActionBarProgressActivity {
protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
protected OsmandSettings settings;
@ -162,7 +161,8 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
if (Version.isFreeVersion(getMyApplication())) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
dialogToInstallPaid();
new InstallPaidVersionDialogFragment()
.show(getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG);
} else {
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() {
if (!getMyApplication().getSettings().isWifiConnected()) {
if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
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) {
downloadFilesPreCheckSpace();
}
});
builder.setNegativeButton(R.string.shared_string_no, null);
builder.show();
new ConfirmDownloadDialogFragment().show(getSupportFragmentManager(),
ConfirmDownloadDialogFragment.TAG);
} else {
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) {
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() {
if (Version.isFreeVersion(getMyApplication())) {
dialogToInstallPaid();
new InstallPaidVersionDialogFragment().show(getSupportFragmentManager(),
InstallPaidVersionDialogFragment.TAG);
} else {
Builder bld = new AlertDialog.Builder(this);
final List<IndexItem> wi = getWikipediaItems();

View file

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

View file

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