forked from organicmaps/organicmaps
Merge pull request #3260 from trashkalmar/downloader-in-pp
[android][downloader] add: Downloader in place page.
This commit is contained in:
commit
5345bcaf16
13 changed files with 473 additions and 231 deletions
|
@ -267,6 +267,7 @@ static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
|
|||
static jfieldID const countryItemFieldTopmostParentName = env->GetFieldID(g_countryItemClass, "topmostParentName", "Ljava/lang/String;");
|
||||
static jfieldID const countryItemFieldDescription = env->GetFieldID(g_countryItemClass, "description", "Ljava/lang/String;");
|
||||
static jfieldID const countryItemFieldSize = env->GetFieldID(g_countryItemClass, "size", "J");
|
||||
static jfieldID const countryItemFieldEnqueuedSize = env->GetFieldID(g_countryItemClass, "enqueuedSize", "J");
|
||||
static jfieldID const countryItemFieldTotalSize = env->GetFieldID(g_countryItemClass, "totalSize", "J");
|
||||
static jfieldID const countryItemFieldChildCount = env->GetFieldID(g_countryItemClass, "childCount", "I");
|
||||
static jfieldID const countryItemFieldTotalChildCount = env->GetFieldID(g_countryItemClass, "totalChildCount", "I");
|
||||
|
@ -316,7 +317,8 @@ static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
|
|||
|
||||
// Sizes
|
||||
env->SetLongField(item, countryItemFieldSize, attrs.m_localMwmSize);
|
||||
env->SetLongField(item, countryItemFieldTotalSize, (attrs.m_downloadingMwmCounter ? attrs.m_downloadingMwmSize : attrs.m_mwmSize));
|
||||
env->SetLongField(item, countryItemFieldEnqueuedSize, attrs.m_downloadingMwmSize);
|
||||
env->SetLongField(item, countryItemFieldTotalSize, attrs.m_mwmSize);
|
||||
|
||||
// Child counts
|
||||
env->SetIntField(item, countryItemFieldChildCount, attrs.m_downloadingMwmCounter);
|
||||
|
@ -660,4 +662,12 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeEnableDownloadOn3g(JNIEnv *
|
|||
g_framework->EnableDownloadOn3g();
|
||||
}
|
||||
|
||||
// static @Nullable String nativeGetSelectedCountry();
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeGetSelectedCountry(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
storage::TCountryId const & res = g_framework->GetPlacePageInfo().m_countryId;
|
||||
return (res == storage::kInvalidCountryId ? nullptr : jni::ToJavaString(env, res));
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:wheel="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/height_item_multiline"
|
||||
|
@ -11,35 +10,13 @@
|
|||
android:background="?clickableBackground"
|
||||
tools:background="#200000FF">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/status_frame"
|
||||
<include
|
||||
android:id="@+id/downloader_status_frame"
|
||||
layout="@layout/downloader_status"
|
||||
android:layout_width="@dimen/downloader_status_size"
|
||||
android:layout_height="@dimen/downloader_status_size"
|
||||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:layout_centerVertical="true"
|
||||
tools:background="#20000FF0">
|
||||
<com.mapswithme.maps.widget.WheelProgressView
|
||||
android:id="@+id/progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?clickableBackground"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
wheel:wheelProgressColor="?colorAccent"
|
||||
wheel:wheelSecondaryColor="?dividerHorizontal"
|
||||
wheel:wheelThickness="@dimen/margin_eighth"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="center"
|
||||
android:background="?clickableBackground"
|
||||
android:duplicateParentState="false"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:src="@drawable/downloader_failed"/>
|
||||
</FrameLayout>
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/size"
|
||||
|
@ -58,7 +35,7 @@
|
|||
android:paddingBottom="@dimen/margin_base"
|
||||
android:orientation="vertical"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/status_frame"
|
||||
android:layout_toRightOf="@id/downloader_status_frame"
|
||||
android:layout_toLeftOf="@id/size">
|
||||
<TextView
|
||||
android:id="@+id/found_name"
|
||||
|
|
25
android/res/layout/downloader_status.xml
Normal file
25
android/res/layout/downloader_status.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:wheel="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="@dimen/downloader_status_size"
|
||||
android:layout_height="@dimen/downloader_status_size"
|
||||
tools:background="#20000FF0">
|
||||
<com.mapswithme.maps.widget.WheelProgressView
|
||||
android:id="@+id/progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?clickableBackground"
|
||||
wheel:wheelProgressColor="?colorAccent"
|
||||
wheel:wheelSecondaryColor="?dividerHorizontal"
|
||||
wheel:wheelThickness="@dimen/margin_eighth"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="center"
|
||||
android:background="?clickableBackground"
|
||||
tools:src="@drawable/downloader_failed"/>
|
||||
</FrameLayout>
|
|
@ -1,5 +1,102 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout style="@style/PlacePagePreview">
|
||||
<include layout="@layout/place_page_preview_common"/>
|
||||
</LinearLayout>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/margin_base">
|
||||
<TextView
|
||||
android:id="@+id/tv__straight_distance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.PlacePage.Accent"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
tools:text="2000 km"/>
|
||||
|
||||
<com.mapswithme.maps.widget.ArrowView
|
||||
android:id="@+id/av__direction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:padding="@dimen/margin_half"
|
||||
android:src="?ppArrowDrawable"
|
||||
android:layout_toLeftOf="@id/tv__straight_distance"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/downloader_status_frame"
|
||||
layout="@layout/downloader_status"
|
||||
android:layout_width="@dimen/downloader_status_size"
|
||||
android:layout_height="@dimen/downloader_status_size"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:layout_toRightOf="@id/downloader_status_frame"
|
||||
android:layout_toLeftOf="@id/av__direction"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:maxLines="@integer/pp_title_lines"
|
||||
android:textAppearance="@style/MwmTextAppearance.Title"
|
||||
android:ellipsize="end"
|
||||
tools:text="Title"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__subtitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:layout_below="@id/tv__title"
|
||||
android:layout_toRightOf="@id/downloader_status_frame"
|
||||
android:layout_toLeftOf="@id/av__direction"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
tools:text="Subtitle"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__downloader_details"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:layout_below="@id/tv__subtitle"
|
||||
android:layout_toRightOf="@id/downloader_status_frame"
|
||||
android:layout_toLeftOf="@id/av__direction"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
tools:text="2.4 GB • Maps: 1"/>
|
||||
|
||||
<!-- TODO set correct color when that block will be handled (now its hidden always) -->
|
||||
<TextView
|
||||
android:id="@+id/tv__opened_till"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:layout_below="@id/tv__downloader_details"
|
||||
android:layout_toLeftOf="@id/av__direction"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:visibility="gone"
|
||||
tools:text="Till 9 PM"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:layout_below="@id/tv__opened_till"
|
||||
android:layout_toLeftOf="@id/av__direction"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
tools:text="Lenina str, 10"/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
tools:background="@color/base_red">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:maxLines="@integer/pp_title_lines"
|
||||
android:textAppearance="@style/MwmTextAppearance.Title"
|
||||
tools:ignore="UnusedAttribute"
|
||||
tools:text="Title"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__subtitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
tools:text="Subtitle"/>
|
||||
|
||||
<!-- TODO set correct color when that block will be handled (now its hidden always) -->
|
||||
<TextView
|
||||
android:id="@+id/tv__opened_till"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:visibility="gone"
|
||||
tools:text="Till 9 PM"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
tools:text="Lenina str, 10"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.mapswithme.maps.widget.ArrowView
|
||||
android:id="@+id/av__direction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/margin_quarter"
|
||||
android:layout_marginRight="@dimen/margin_quarter"
|
||||
android:clickable="true"
|
||||
android:padding="@dimen/margin_half"
|
||||
android:src="?ppArrowDrawable"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__straight_distance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.PlacePage.Accent"/>
|
||||
</merge>
|
|
@ -1,13 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<style name="PlacePagePreview">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
<item name="android:orientation">horizontal</item>
|
||||
<item name="android:padding">@dimen/margin_base</item>
|
||||
</style>
|
||||
|
||||
<style name="PlacePageButtonText">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
@ -65,20 +57,6 @@
|
|||
<item name="android:visibility">gone</item>
|
||||
</style>
|
||||
|
||||
<style name="PlacePageMetadata">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:minHeight">@dimen/height_block_base</item>
|
||||
<item name="android:background">?clickableBackground</item>
|
||||
<item name="android:orientation">horizontal</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
<item name="android:clickable">true</item>
|
||||
<item name="android:paddingLeft">@dimen/margin_base</item>
|
||||
<item name="android:paddingStart" tools:targetApi="jelly_bean_mr1">@dimen/margin_base</item>
|
||||
<item name="android:paddingRight">@dimen/margin_base</item>
|
||||
<item name="android:paddingEnd" tools:targetApi="jelly_bean_mr1">@dimen/margin_base</item>
|
||||
</style>
|
||||
|
||||
<style name="PlacePageMetadataText">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
|
|
@ -42,6 +42,7 @@ public final class CountryItem implements Comparable<CountryItem>
|
|||
public String description;
|
||||
|
||||
public long size;
|
||||
public long enqueuedSize;
|
||||
public long totalSize;
|
||||
|
||||
public int childCount;
|
||||
|
@ -148,6 +149,7 @@ public final class CountryItem implements Comparable<CountryItem>
|
|||
", errorCode: " + errorCode +
|
||||
", headerId: " + headerId +
|
||||
", size: " + size +
|
||||
", enqueuedSize: " + enqueuedSize +
|
||||
", totalSize: " + totalSize +
|
||||
", childCount: " + childCount +
|
||||
", totalChildCount: " + totalChildCount +
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.location.Location;
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -17,11 +16,9 @@ import android.text.SpannableStringBuilder;
|
|||
import android.text.Spanned;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -38,10 +35,8 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.background.Notifier;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.maps.widget.WheelProgressView;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;
|
||||
|
@ -66,8 +61,6 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
private final SparseArray<String> mHeaders = new SparseArray<>();
|
||||
private final Stack<PathEntry> mPath = new Stack<>(); // Holds navigation history. The last element is the current level.
|
||||
|
||||
private final SparseIntArray mIconsCache = new SparseIntArray();
|
||||
|
||||
private int mListenerSlot;
|
||||
|
||||
private enum MenuItem
|
||||
|
@ -289,8 +282,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
|
||||
class ViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
private final WheelProgressView mProgress;
|
||||
private final ImageView mStatus;
|
||||
private final DownloaderStatusIcon mStatusIcon;
|
||||
private final TextView mName;
|
||||
private final TextView mSubtitle;
|
||||
private final TextView mFoundName;
|
||||
|
@ -417,8 +409,45 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
{
|
||||
super(frame);
|
||||
|
||||
mProgress = (WheelProgressView) frame.findViewById(R.id.progress);
|
||||
mStatus = (ImageView) frame.findViewById(R.id.status);
|
||||
mStatusIcon = new DownloaderStatusIcon(frame.findViewById(R.id.downloader_status_frame))
|
||||
{
|
||||
@Override
|
||||
protected int selectIcon(CountryItem country)
|
||||
{
|
||||
if (country.status == CountryItem.STATUS_DOWNLOADABLE || country.status == CountryItem.STATUS_PARTLY)
|
||||
{
|
||||
return (country.isExpandable() ? (mMyMapsMode ? R.attr.status_folder_done
|
||||
: R.attr.status_folder)
|
||||
: R.attr.status_downloadable);
|
||||
}
|
||||
|
||||
return super.selectIcon(country);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateIcon(CountryItem country)
|
||||
{
|
||||
super.updateIcon(country);
|
||||
mIcon.setFocusable(country.isExpandable() && country.status != CountryItem.STATUS_DONE);
|
||||
}
|
||||
}.setOnIconClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
processClick(true);
|
||||
}
|
||||
}).setOnCancelClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeCancel(mItem.id);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
|
||||
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
|
||||
}
|
||||
});
|
||||
|
||||
mName = (TextView) frame.findViewById(R.id.name);
|
||||
mSubtitle = (TextView) frame.findViewById(R.id.subtitle);
|
||||
mFoundName = (TextView) frame.findViewById(R.id.found_name);
|
||||
|
@ -445,75 +474,6 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mStatus.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
processClick(true);
|
||||
}
|
||||
});
|
||||
|
||||
mProgress.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeCancel(mItem.id);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
|
||||
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateStatus()
|
||||
{
|
||||
boolean pending = (mItem.status == CountryItem.STATUS_ENQUEUED);
|
||||
boolean inProgress = (mItem.status == CountryItem.STATUS_PROGRESS || pending);
|
||||
|
||||
UiUtils.showIf(inProgress, mProgress);
|
||||
UiUtils.showIf(!inProgress, mStatus);
|
||||
mProgress.setPending(pending);
|
||||
|
||||
if (inProgress)
|
||||
{
|
||||
if (!pending)
|
||||
mProgress.setProgress(mItem.progress);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean clickable = mItem.isExpandable();
|
||||
@AttrRes int iconAttr;
|
||||
|
||||
switch (mItem.status)
|
||||
{
|
||||
case CountryItem.STATUS_DONE:
|
||||
clickable = false;
|
||||
iconAttr = R.attr.status_done;
|
||||
break;
|
||||
|
||||
case CountryItem.STATUS_DOWNLOADABLE:
|
||||
case CountryItem.STATUS_PARTLY:
|
||||
iconAttr = (mItem.isExpandable() ? (mMyMapsMode ? R.attr.status_folder_done
|
||||
: R.attr.status_folder)
|
||||
: R.attr.status_downloadable);
|
||||
break;
|
||||
|
||||
case CountryItem.STATUS_FAILED:
|
||||
iconAttr = R.attr.status_failed;
|
||||
break;
|
||||
|
||||
case CountryItem.STATUS_UPDATABLE:
|
||||
iconAttr = R.attr.status_updatable;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Inappropriate item status: " + mItem.status);
|
||||
}
|
||||
|
||||
mStatus.setFocusable(clickable);
|
||||
mStatus.setImageResource(resolveIcon(iconAttr));
|
||||
}
|
||||
|
||||
void bind(CountryItem item)
|
||||
|
@ -554,8 +514,15 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
}
|
||||
|
||||
UiUtils.showIf(mSearchResultsMode, mFoundName);
|
||||
mSize.setText(StringUtils.getFileSizeString(mItem.totalSize));
|
||||
updateStatus();
|
||||
|
||||
long size;
|
||||
if (mItem.status == CountryItem.STATUS_ENQUEUED || mItem.status == CountryItem.STATUS_PROGRESS)
|
||||
size = mItem.enqueuedSize;
|
||||
else
|
||||
size = (mMyMapsMode ? mItem.size : mItem.totalSize);
|
||||
|
||||
mSize.setText(StringUtils.getFileSizeString(size));
|
||||
mStatusIcon.update(mItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -572,18 +539,6 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
}
|
||||
}
|
||||
|
||||
private @DrawableRes int resolveIcon(@AttrRes int iconAttr)
|
||||
{
|
||||
int res = mIconsCache.get(iconAttr);
|
||||
if (res == 0)
|
||||
{
|
||||
res = ThemeUtils.getResource(mActivity, R.attr.downloaderTheme, iconAttr);
|
||||
mIconsCache.put(iconAttr, res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private void collectHeaders()
|
||||
{
|
||||
mHeaders.clear();
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package com.mapswithme.maps.downloader;
|
||||
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.widget.WheelProgressView;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class DownloaderStatusIcon
|
||||
{
|
||||
private final View mFrame;
|
||||
protected final ImageView mIcon;
|
||||
private final WheelProgressView mProgress;
|
||||
|
||||
private static final SparseIntArray sIconsCache = new SparseIntArray();
|
||||
|
||||
public DownloaderStatusIcon(View frame)
|
||||
{
|
||||
mFrame = frame;
|
||||
mIcon = (ImageView) mFrame.findViewById(R.id.status);
|
||||
mProgress = (WheelProgressView) mFrame.findViewById(R.id.progress);
|
||||
}
|
||||
|
||||
public DownloaderStatusIcon setOnIconClickListener(View.OnClickListener listener)
|
||||
{
|
||||
mIcon.setOnClickListener(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DownloaderStatusIcon setOnCancelClickListener(View.OnClickListener listener)
|
||||
{
|
||||
mProgress.setOnClickListener(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected @AttrRes int selectIcon(CountryItem country)
|
||||
{
|
||||
switch (country.status)
|
||||
{
|
||||
case CountryItem.STATUS_DONE:
|
||||
return R.attr.status_done;
|
||||
|
||||
case CountryItem.STATUS_DOWNLOADABLE:
|
||||
case CountryItem.STATUS_PARTLY:
|
||||
return R.attr.status_downloadable;
|
||||
|
||||
case CountryItem.STATUS_FAILED:
|
||||
return R.attr.status_failed;
|
||||
|
||||
case CountryItem.STATUS_UPDATABLE:
|
||||
return R.attr.status_updatable;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Inappropriate item status: " + country.status);
|
||||
}
|
||||
}
|
||||
|
||||
private @DrawableRes int resolveIcon(@AttrRes int iconAttr)
|
||||
{
|
||||
int res = sIconsCache.get(iconAttr);
|
||||
if (res == 0)
|
||||
{
|
||||
res = ThemeUtils.getResource(mFrame.getContext(), R.attr.downloaderTheme, iconAttr);
|
||||
sIconsCache.put(iconAttr, res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void updateIcon(CountryItem country)
|
||||
{
|
||||
@AttrRes int iconAttr = selectIcon(country);
|
||||
@DrawableRes int icon = resolveIcon(iconAttr);
|
||||
|
||||
mIcon.setImageResource(icon);
|
||||
}
|
||||
|
||||
public void update(CountryItem country)
|
||||
{
|
||||
boolean pending = (country.status == CountryItem.STATUS_ENQUEUED);
|
||||
boolean inProgress = (country.status == CountryItem.STATUS_PROGRESS || pending);
|
||||
|
||||
UiUtils.showIf(inProgress, mProgress);
|
||||
UiUtils.showIf(!inProgress, mIcon);
|
||||
mProgress.setPending(pending);
|
||||
|
||||
if (inProgress)
|
||||
{
|
||||
if (!pending)
|
||||
mProgress.setProgress(country.progress);
|
||||
return;
|
||||
}
|
||||
|
||||
updateIcon(country);
|
||||
}
|
||||
|
||||
public void show(boolean show)
|
||||
{
|
||||
UiUtils.showIf(show, mFrame);
|
||||
}
|
||||
|
||||
public static void clearCache()
|
||||
{
|
||||
sIconsCache.clear();
|
||||
}
|
||||
}
|
|
@ -359,6 +359,7 @@ public final class MapManager
|
|||
* <li>topmostParentName;</li>
|
||||
* <li>description;</li>
|
||||
* <li>size;</li>
|
||||
* <li>enqueuedSize;</li>
|
||||
* <li>totalSize;</li>
|
||||
* <li>childCount;</li>
|
||||
* <li>totalChildCount;</li>
|
||||
|
@ -473,4 +474,9 @@ public final class MapManager
|
|||
* Sets flag which allows to download maps on 3G.
|
||||
*/
|
||||
public static native void nativeEnableDownloadOn3g();
|
||||
|
||||
/**
|
||||
* Returns country ID which the current PP object points to, or {@code null}.
|
||||
*/
|
||||
public static native @Nullable String nativeGetSelectedCountry();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class PlacePageBottomAnimationController extends BasePlacePageAnimationControlle
|
|||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
mPlacePage.setState(State.HIDDEN);
|
||||
mPlacePage.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class PlacePageBottomAnimationController extends BasePlacePageAnimationControlle
|
|||
if (!mIsGestureHandled)
|
||||
{
|
||||
if (distanceY < 0f)
|
||||
mPlacePage.setState(State.HIDDEN);
|
||||
mPlacePage.hide();
|
||||
else
|
||||
mPlacePage.setState(State.DETAILS);
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import android.widget.TextView;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
|
@ -54,6 +55,8 @@ import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
|
|||
import com.mapswithme.maps.bookmarks.data.Icon;
|
||||
import com.mapswithme.maps.bookmarks.data.MapObject;
|
||||
import com.mapswithme.maps.bookmarks.data.Metadata;
|
||||
import com.mapswithme.maps.downloader.CountryItem;
|
||||
import com.mapswithme.maps.downloader.DownloaderStatusIcon;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.editor.Editor;
|
||||
import com.mapswithme.maps.editor.OpeningHours;
|
||||
|
@ -136,6 +139,45 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
private MapObject mMapObject;
|
||||
private boolean mIsLatLonDms;
|
||||
|
||||
// Downloader`s stuff
|
||||
private DownloaderStatusIcon mDownloaderIcon;
|
||||
private TextView mDownloaderInfo;
|
||||
private int mStorageCallbackSlot;
|
||||
private CountryItem mCurrentCountry;
|
||||
|
||||
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
|
||||
{
|
||||
@Override
|
||||
public void onStatusChanged(List<MapManager.StorageCallbackData> data)
|
||||
{
|
||||
if (mCurrentCountry == null)
|
||||
return;
|
||||
|
||||
for (MapManager.StorageCallbackData item : data)
|
||||
if (mCurrentCountry.id.equals(item.countryId))
|
||||
{
|
||||
updateDownloader();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(String countryId, long localSize, long remoteSize)
|
||||
{
|
||||
if (mCurrentCountry != null && mCurrentCountry.id.equals(countryId))
|
||||
updateDownloader();
|
||||
}
|
||||
};
|
||||
|
||||
private final Runnable mDownloaderDeferredDetachProc = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
detachCountry();
|
||||
}
|
||||
};
|
||||
|
||||
public enum State
|
||||
{
|
||||
HIDDEN,
|
||||
|
@ -262,6 +304,39 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
mRouteButtonsFrame.findViewById(R.id.from).setOnClickListener(this);
|
||||
mRouteButtonsFrame.findViewById(R.id.to).setOnClickListener(this);
|
||||
|
||||
mDownloaderIcon = new DownloaderStatusIcon(mPreview.findViewById(R.id.downloader_status_frame))
|
||||
.setOnIconClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.warn3gAndDownload((MwmActivity) getContext(), mCurrentCountry.id, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
|
||||
Statistics.params().add(Statistics.EventParam.ACTION, "download")
|
||||
.add(Statistics.EventParam.FROM, "placepage")
|
||||
.add("is_auto", "false")
|
||||
.add("scenario", (mCurrentCountry.isExpandable() ? "download_group"
|
||||
: "download")));
|
||||
}
|
||||
});
|
||||
}
|
||||
}).setOnCancelClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeCancel(mCurrentCountry.id);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
|
||||
Statistics.params().add(Statistics.EventParam.FROM, "placepage"));
|
||||
}
|
||||
});
|
||||
|
||||
mDownloaderInfo = (TextView) mPreview.findViewById(R.id.tv__downloader_details);
|
||||
|
||||
mShadowController = new ScrollViewShadowController((ObservableScrollView) mDetails)
|
||||
.addBottomShadow()
|
||||
.attach();
|
||||
|
@ -371,6 +446,15 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
return;
|
||||
|
||||
mMapObject = mapObject;
|
||||
|
||||
detachCountry();
|
||||
if (mMapObject != null)
|
||||
{
|
||||
String country = MapManager.nativeGetSelectedCountry();
|
||||
if (country != null)
|
||||
attachCountry(country);
|
||||
}
|
||||
|
||||
refreshViews();
|
||||
}
|
||||
|
||||
|
@ -578,16 +662,14 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
|
||||
private void refreshDistanceToObject(Location l)
|
||||
{
|
||||
if (l != null)
|
||||
{
|
||||
mTvDistance.setVisibility(View.VISIBLE);
|
||||
final DistanceAndAzimut distanceAndAzimuth = Framework.nativeGetDistanceAndAzimuthFromLatLon(
|
||||
mMapObject.getLat(), mMapObject.getLon(),
|
||||
l.getLatitude(), l.getLongitude(), 0.0);
|
||||
mTvDistance.setText(distanceAndAzimuth.getDistance());
|
||||
}
|
||||
else
|
||||
mTvDistance.setVisibility(View.GONE);
|
||||
UiUtils.showIf(l != null, mTvDistance);
|
||||
if (l == null)
|
||||
return;
|
||||
|
||||
mTvDistance.setVisibility(View.VISIBLE);
|
||||
DistanceAndAzimut distanceAndAzimuth = Framework.nativeGetDistanceAndAzimuthFromLatLon(mMapObject.getLat(), mMapObject.getLon(),
|
||||
l.getLatitude(), l.getLongitude(), 0.0);
|
||||
mTvDistance.setText(distanceAndAzimuth.getDistance());
|
||||
}
|
||||
|
||||
private void refreshLatLon()
|
||||
|
@ -596,7 +678,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
final double lon = mMapObject.getLon();
|
||||
final String[] latLon = Framework.nativeFormatLatLonToArr(lat, lon, mIsLatLonDms);
|
||||
if (latLon.length == 2)
|
||||
mTvLatlon.setText(latLon[0] + ", " + latLon[1]);
|
||||
mTvLatlon.setText(String.format(Locale.US, "%1$s, %2$s", latLon[0], latLon[1]));
|
||||
}
|
||||
|
||||
private static void refreshMetadataOrHide(String metadata, View metaLayout, TextView metaTv)
|
||||
|
@ -941,13 +1023,13 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
return true;
|
||||
}
|
||||
|
||||
public int getDockedWidth()
|
||||
int getDockedWidth()
|
||||
{
|
||||
int res = getWidth();
|
||||
return (res == 0 ? getLayoutParams().width : res);
|
||||
}
|
||||
|
||||
public MwmActivity.LeftAnimationTrackListener getLeftAnimationTrackListener()
|
||||
MwmActivity.LeftAnimationTrackListener getLeftAnimationTrackListener()
|
||||
{
|
||||
return mLeftAnimationTrackListener;
|
||||
}
|
||||
|
@ -959,6 +1041,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
|
||||
public void hide()
|
||||
{
|
||||
detachCountry();
|
||||
setState(State.HIDDEN);
|
||||
}
|
||||
|
||||
|
@ -976,4 +1059,67 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isInvalidDownloaderStatus(int status)
|
||||
{
|
||||
return (status != CountryItem.STATUS_DOWNLOADABLE &&
|
||||
status != CountryItem.STATUS_ENQUEUED &&
|
||||
status != CountryItem.STATUS_FAILED &&
|
||||
status != CountryItem.STATUS_PARTLY &&
|
||||
status != CountryItem.STATUS_PROGRESS);
|
||||
}
|
||||
|
||||
private void updateDownloader(CountryItem country)
|
||||
{
|
||||
if (isInvalidDownloaderStatus(country.status))
|
||||
{
|
||||
if (mStorageCallbackSlot != 0)
|
||||
UiThread.runLater(mDownloaderDeferredDetachProc);
|
||||
return;
|
||||
}
|
||||
|
||||
mDownloaderIcon.update(country);
|
||||
|
||||
StringBuilder sb = new StringBuilder(StringUtils.getFileSizeString(country.totalSize));
|
||||
if (country.isExpandable())
|
||||
sb.append(String.format(Locale.US, " • %s: %d", getContext().getString(R.string.downloader_status_maps), country.totalChildCount));
|
||||
|
||||
mDownloaderInfo.setText(sb.toString());
|
||||
}
|
||||
|
||||
private void updateDownloader()
|
||||
{
|
||||
if (mCurrentCountry == null)
|
||||
return;
|
||||
|
||||
mCurrentCountry.update();
|
||||
updateDownloader(mCurrentCountry);
|
||||
}
|
||||
|
||||
private void attachCountry(String country)
|
||||
{
|
||||
CountryItem map = CountryItem.fill(country);
|
||||
if (isInvalidDownloaderStatus(map.status))
|
||||
return;
|
||||
|
||||
mCurrentCountry = map;
|
||||
if (mStorageCallbackSlot == 0)
|
||||
mStorageCallbackSlot = MapManager.nativeSubscribe(mStorageCallback);
|
||||
|
||||
mDownloaderIcon.show(true);
|
||||
UiUtils.show(mDownloaderInfo);
|
||||
updateDownloader(mCurrentCountry);
|
||||
}
|
||||
|
||||
private void detachCountry()
|
||||
{
|
||||
if (mStorageCallbackSlot == 0)
|
||||
return;
|
||||
|
||||
MapManager.nativeUnsubscribe(mStorageCallbackSlot);
|
||||
mStorageCallbackSlot = 0;
|
||||
mCurrentCountry = null;
|
||||
mDownloaderIcon.show(false);
|
||||
UiUtils.hide(mDownloaderInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.location.Location;
|
|||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.downloader.DownloaderStatusIcon;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
@ -88,6 +89,8 @@ public final class ThemeSwitcher
|
|||
// Changes will be applied in process of recreation.
|
||||
Framework.nativeMarkMapStyle(style);
|
||||
|
||||
DownloaderStatusIcon.clearCache();
|
||||
|
||||
Activity a = MwmApplication.backgroundTracker().getTopActivity();
|
||||
if (a != null && !a.isFinishing())
|
||||
a.recreate();
|
||||
|
|
Loading…
Add table
Reference in a new issue