Merge pull request #2916 from trashkalmar/downloader-refresh

[DNM][downloader][android] Downloader refresh.
This commit is contained in:
Dmitry Yunitsky 2016-04-21 12:29:27 +03:00
commit 1436719f36
127 changed files with 507 additions and 291 deletions

View file

@ -258,6 +258,7 @@ static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
static jfieldID const countryItemFieldTopmostParentId = env->GetFieldID(g_countryItemClass, "topmostParentId", "Ljava/lang/String;");
static jfieldID const countryItemFieldDirectParentName = env->GetFieldID(g_countryItemClass, "directParentName", "Ljava/lang/String;");
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 countryItemFieldTotalSize = env->GetFieldID(g_countryItemClass, "totalSize", "J");
static jfieldID const countryItemFieldChildCount = env->GetFieldID(g_countryItemClass, "childCount", "I");
@ -303,6 +304,9 @@ static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
env->SetObjectField(item, countryItemFieldTopmostParentName, nullptr);
}
// Description
env->SetObjectField(item, countryItemFieldDescription, jni::TScopedLocalRef(env, jni::ToJavaString(env, attrs.m_nodeLocalDescription)));
// Sizes
env->SetLongField(item, countryItemFieldSize, attrs.m_localMwmSize);
env->SetLongField(item, countryItemFieldTotalSize, (attrs.m_downloadingMwmCounter ? attrs.m_downloadingMwmSize : attrs.m_mwmSize));
@ -350,27 +354,29 @@ static void PutItemsToList(JNIEnv * env, jobject const list, TCountriesVec const
}
}
// static void nativeListItems(@Nullable String root, double lat, double lon, boolean hasLocation, List<CountryItem> result);
// static void nativeListItems(@Nullable String root, double lat, double lon, boolean hasLocation, boolean myMapsMode, List<CountryItem> result);
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeListItems(JNIEnv * env, jclass clazz, jstring parent, jdouble lat, jdouble lon, jboolean hasLocation, jobject result)
Java_com_mapswithme_maps_downloader_MapManager_nativeListItems(JNIEnv * env, jclass clazz, jstring parent, jdouble lat, jdouble lon, jboolean hasLocation, jboolean myMapsMode, jobject result)
{
PrepareClassRefs(env);
if (hasLocation)
if (hasLocation && !myMapsMode)
{
TCountriesVec near;
g_framework->NativeFramework()->CountryInfoGetter().GetRegionsCountryId(MercatorBounds::FromLatLon(lat, lon), near);
PutItemsToList(env, result, near, ItemCategory::NEAR_ME, [](TCountryId const & countryId, NodeAttrs const & attrs) -> bool
{
return (attrs.m_status == NodeStatus::NotDownloaded);
return !attrs.m_present;
});
}
TCountriesVec downloaded, available;
GetStorage().GetChildrenInGroups(GetRootId(env, parent), downloaded, available);
GetStorage().GetChildrenInGroups(GetRootId(env, parent), downloaded, available, true);
PutItemsToList(env, result, downloaded, ItemCategory::DOWNLOADED, nullptr);
PutItemsToList(env, result, available, ItemCategory::AVAILABLE, nullptr);
if (myMapsMode)
PutItemsToList(env, result, downloaded, ItemCategory::DOWNLOADED, nullptr);
else
PutItemsToList(env, result, available, ItemCategory::AVAILABLE, nullptr);
}
// static void nativeUpdateItem(CountryItem item);
@ -397,6 +403,22 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeGetStatus(JNIEnv * env, jcl
return static_cast<jint>(ns.m_status);
}
// static void nativeGetError(String root);
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetError(JNIEnv * env, jclass clazz, jstring root)
{
NodeStatuses ns;
GetStorage().GetNodeStatuses(jni::ToNativeString(env, root), ns);
return static_cast<jint>(ns.m_error);
}
// static String nativeGetName(String root);
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetName(JNIEnv * env, jclass clazz, jstring root)
{
return jni::ToJavaString(env, GetStorage().GetNodeLocalName(jni::ToNativeString(env, root)));
}
// static @Nullable String nativeFindCountry(double lat, double lon);
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeFindCountry(JNIEnv * env, jclass clazz, jdouble lat, jdouble lon)
@ -577,4 +599,14 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeHasUnsavedEditorChanges(JNI
return g_framework->NativeFramework()->HasUnsavedEdits(jni::ToNativeString(env, root));
}
// static void nativeGetPathTo(String root, List<String> result);
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetPathTo(JNIEnv * env, jclass clazz, jstring root, jobject result)
{
TCountriesVec path;
GetStorage().GetGroupNodePathToRoot(jni::ToNativeString(env, root), path);
for (TCountryId const & node : path)
env->CallBooleanMethod(result, g_listAddMethod, jni::TScopedLocalRef(env, jni::ToJavaString(env, node)).get());
}
} // extern "C"

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 310 B

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 469 B

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 478 B

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 338 B

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 B

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 B

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 B

After

Width:  |  Height:  |  Size: 1,013 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 975 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 795 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 363 B

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 467 B

After

Width:  |  Height:  |  Size: 948 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 838 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 849 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 434 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 526 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/base_accent"/>
</shape>
</item>
<item android:drawable="@drawable/ic_downloader_done"/>
</layer-list>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/base_accent_night"/>
</shape>
</item>
<item android:drawable="@drawable/ic_downloader_done_night"/>
</layer-list>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_downloader_download"/>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_downloader_download_night"/>

View file

@ -1,32 +0,0 @@
<?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/height_block_base"
android:background="?panel"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv__text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="@dimen/margin_half"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:textAppearance="@style/MwmTextAppearance.Body2"
tools:text="Maps: 10 (1024 MB)"/>
<Button
android:id="@+id/btn__action"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
style="@style/MwmWidget.Button"
android:textAppearance="@style/MwmTextAppearance.Button"
android:textColor="?colorAccent"
tools:text="@string/downloader_update_all_button"/>
</LinearLayout>

View file

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/height_item_oneline"
android:layout_height="wrap_content"
android:minHeight="@dimen/height_item_multiline"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:background="?clickableBackground"
@ -53,6 +54,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/margin_base"
android:paddingBottom="@dimen/margin_base"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/status_frame"

View file

@ -1,12 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
<FrameLayout
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:paddingLeft="@dimen/margin_base"
android:paddingTop="@dimen/margin_half"
android:paddingBottom="@dimen/margin_half"
android:textAppearance="@style/MwmTextAppearance.Caption"
android:background="?panel"
tools:text="Downloaded"/>
tools:background="#400000FF">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/margin_base"
android:paddingTop="@dimen/margin_half"
android:paddingBottom="@dimen/margin_half"
android:layout_marginRight="@dimen/margin_base"
android:background="?panel"
android:textAppearance="@style/MwmTextAppearance.Caption"
tools:text="Downloaded"
tools:background="#80FF0000"/>
</FrameLayout>

View file

@ -1,21 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/MwmWidget.Floating"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<include layout="@layout/toolbar_with_search"/>
<Button
android:id="@+id/action"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:layout_alignParentBottom="true"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
style="@style/MwmWidget.Button.Accent"
android:textAppearance="@style/MwmTextAppearance.Button"
android:textColor="?colorAccent"
tools:text="@string/downloader_update_all_button"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/action"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:src="?fabAdd"/>
<include
layout="@layout/recycler_default"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:layout_above="@id/action"/>
<include
android:id="@+id/bottom_panel"
layout="@layout/downloader_bottom_panel"
layout="@layout/placeholder"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"/>
</LinearLayout>
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:layout_above="@id/action"/>
</RelativeLayout>

View file

@ -34,7 +34,7 @@
android:layout_gravity="end|center_vertical"
android:background="?selectableItemBackgroundBorderless"
android:scaleType="centerInside"
android:src="@drawable/ic_downloader_done"/>
android:src="@drawable/ic_done"/>
</RelativeLayout>

View file

@ -53,43 +53,7 @@
android:background="?windowBackgroundForced">
<include layout="@layout/recycler_default"/>
<!-- "Nothing found" placeholder -->
<com.mapswithme.maps.widget.HeightLimitedFrameLayout
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_double"
android:layout_gravity="center_horizontal"
android:gravity="center">
<ImageView
android:layout_width="@dimen/placeholder_size"
android:layout_height="@dimen/placeholder_size"
android:src="@drawable/img_search_nothing_found_light"
android:layout_marginBottom="@dimen/margin_base_plus"
android:tag="@string/tag_height_limited"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:text="@string/search_not_found"
android:textAppearance="@style/MwmTextAppearance.Title"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_not_found_query"
android:textAppearance="@style/MwmTextAppearance.Body2"
android:gravity="center_horizontal"/>
</LinearLayout>
</com.mapswithme.maps.widget.HeightLimitedFrameLayout>
<include layout="@layout/placeholder"/>
</FrameLayout>
<!-- Country download suggest fragment -->

View file

@ -1,45 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/MwmWidget.FrameLayout.Elevation"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/recycler_default"/>
<com.mapswithme.maps.widget.HeightLimitedFrameLayout
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_double"
android:layout_gravity="center_horizontal"
android:gravity="center">
<ImageView
android:layout_width="@dimen/placeholder_size"
android:layout_height="@dimen/placeholder_size"
android:src="@drawable/img_search_empty_history_light"
android:layout_marginBottom="@dimen/margin_base_plus"
android:tag="@string/tag_height_limited"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:text="@string/search_history_title"
android:textAppearance="@style/MwmTextAppearance.Title"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_history_text"
android:textAppearance="@style/MwmTextAppearance.Body2"
android:gravity="center_horizontal"/>
</LinearLayout>
</com.mapswithme.maps.widget.HeightLimitedFrameLayout>
<include layout="@layout/placeholder"/>
</FrameLayout>

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mapswithme.maps.widget.HeightLimitedFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="@dimen/placeholder_size"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_double"
android:layout_gravity="center_horizontal"
android:gravity="center">
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/placeholder_size"
android:layout_height="@dimen/placeholder_size"
android:layout_marginBottom="@dimen/margin_base_plus"
android:tag="@string/tag_height_limited"
tools:src="@drawable/img_search_empty_history_light"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Title"
android:gravity="center_horizontal"
tools:text="Some long long long placeholder title"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body2"
android:gravity="center_horizontal"
tools:text="Some placeholder text"/>
</LinearLayout>
</com.mapswithme.maps.widget.HeightLimitedFrameLayout>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"/>

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
style="@style/MwmWidget.ToolbarStyle"
android:theme="@style/MwmWidget.ToolbarTheme"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
style="@style/MwmWidget.ToolbarStyle"
android:theme="@style/MwmWidget.ToolbarTheme"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<include layout="@layout/toolbar_search_controls"/>
</android.support.v7.widget.Toolbar>

View file

@ -48,6 +48,7 @@
<string name="marked_for_downloading">Поставлено в очередь на загрузку, нажмите для отмены</string>
<!-- Settings/Downloader - size string, only strings different from English should be translated -->
<string name="mb">МБ</string>
<string name="gb">ГБ</string>
<!-- Choose measurement on first launch alert - choose imperial system button -->
<string name="miles">Мили</string>
<!-- View and button titles for accessibility -->

View file

@ -47,7 +47,7 @@
<!-- Settings/Downloader - info for country in the download queue -->
<string name="marked_for_downloading">ทำเครื่องหมายสำหรับการดาวน์โหลดแล้ว แตะเพื่อยกเลิก</string>
<!-- Settings/Downloader - size string, only strings different from English should be translated -->
<string name="mb">เมกกะไบต์</string>
<string name="mb">MB</string>
<!-- Choose measurement on first launch alert - choose imperial system button -->
<string name="miles">ไมล์</string>
<!-- View and button titles for accessibility -->

View file

@ -48,6 +48,7 @@
<string name="marked_for_downloading">Поставлено в чергу на завантаження, натисніть для скасування</string>
<!-- Settings/Downloader - size string, only strings different from English should be translated -->
<string name="mb">МБ</string>
<string name="gb">ГБ</string>
<!-- Choose measurement on first launch alert - choose imperial system button -->
<string name="miles">Милі</string>
<!-- View and button titles for accessibility -->

View file

@ -30,6 +30,7 @@
<!-- base sizes -->
<dimen name="height_block_base">48dp</dimen>
<dimen name="height_item_oneline">56dp</dimen>
<dimen name="height_item_multiline">72dp</dimen>
<dimen name="height_item_edit_bookmark">72dp</dimen>
<dimen name="dialog_max_height">320dp</dimen>

View file

@ -48,6 +48,7 @@
<string name="marked_for_downloading">Marked for downloading, touch to cancel</string>
<!-- Settings/Downloader - size string, only strings different from English should be translated -->
<string name="mb">MB</string>
<string name="gb">GB</string>
<!-- Choose measurement on first launch alert - choose imperial system button -->
<string name="miles">Miles</string>
<!-- View and button titles for accessibility -->

View file

@ -46,6 +46,8 @@
<attr name="wheelPendingAnimation" format="reference"/>
<attr name="downloaderTheme" format="reference"/>
<attr name="fabAdd" format="reference"/>
</declare-styleable>
<declare-styleable name="ThemeAttrs.Downloader">
@ -53,5 +55,7 @@
<attr name="status_downloadable" format="reference"/>
<attr name="status_failed" format="reference"/>
<attr name="status_updatable" format="reference"/>
<attr name="status_folder" format="reference"/>
<attr name="status_folder_done" format="reference"/>
</declare-styleable>
</resources>

View file

@ -62,6 +62,8 @@
<item name="wheelPendingAnimation">@drawable/anim_spinner_pending</item>
<item name="downloaderTheme">@style/MwmTheme.Downloader</item>
<item name="fabAdd">@drawable/ic_fab_add</item>
</style>
<!-- Night theme -->
@ -126,5 +128,7 @@
<item name="wheelPendingAnimation">@drawable/anim_spinner_pending_night</item>
<item name="downloaderTheme">@style/MwmTheme.Downloader.Night</item>
<item name="fabAdd">@drawable/ic_fab_add_night</item>
</style>
</resources>

View file

@ -106,14 +106,18 @@
</style>
<style name="MwmTheme.Downloader">
<item name="status_done">@drawable/downloader_done</item>
<item name="status_downloadable">@drawable/downloader_download</item>
<item name="status_failed">@drawable/downloader_failed</item>
<item name="status_updatable">@drawable/downloader_update</item>
<item name="status_done">@drawable/ic_downloader_done</item>
<item name="status_downloadable">@drawable/ic_downloader_download</item>
<item name="status_failed">@drawable/ic_downloader_retry</item>
<item name="status_updatable">@drawable/ic_downloader_update</item>
<item name="status_folder">@drawable/ic_downloader_folder</item>
<item name="status_folder_done">@drawable/ic_downloader_folder_done</item>
</style>
<style name="MwmTheme.Downloader.Night">
<item name="status_done">@drawable/downloader_done_night</item>
<item name="status_downloadable">@drawable/downloader_download_night</item>
<item name="status_done">@drawable/ic_downloader_done_night</item>
<item name="status_downloadable">@drawable/ic_downloader_download_night</item>
<item name="status_folder">@drawable/ic_downloader_folder_night</item>
<item name="status_folder_done">@drawable/ic_downloader_folder_done_night</item>
</style>
</resources>

View file

@ -117,12 +117,13 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity
return;
}
CountryItem item = CountryItem.fill(mCurrentCountry);
int status = MapManager.nativeGetStatus(mCurrentCountry);
String name = MapManager.nativeGetName(mCurrentCountry);
UiUtils.show(mTvLocation);
if (item.status == CountryItem.STATUS_DONE)
mTvLocation.setText(String.format(getString(R.string.download_location_map_up_to_date), item.name));
if (status == CountryItem.STATUS_DONE)
mTvLocation.setText(String.format(getString(R.string.download_location_map_up_to_date), name));
else
{
final CheckBox checkBox = (CheckBox) findViewById(R.id.chb__download_country);
@ -131,15 +132,15 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity
String locationText;
String checkBoxText;
if (item.status == CountryItem.STATUS_UPDATABLE)
if (status == CountryItem.STATUS_UPDATABLE)
{
locationText = getString(R.string.download_location_update_map_proposal);
checkBoxText = String.format(getString(R.string.update_country_ask), item.name);
checkBoxText = String.format(getString(R.string.update_country_ask), name);
}
else
{
locationText = getString(R.string.download_location_map_proposal);
checkBoxText = String.format(getString(R.string.download_country_ask), item.name);
checkBoxText = String.format(getString(R.string.download_country_ask), name);
}
mTvLocation.setText(locationText);

View file

@ -66,9 +66,8 @@ public class MwmApplication extends Application
{
Notifier.cancelDownloadSuggest();
CountryItem country = CountryItem.fill(item.countryId);
Notifier.notifyDownloadFailed(country);
MapManager.sendErrorStat(Statistics.EventName.DOWNLOADER_ERROR, country.errorCode);
Notifier.notifyDownloadFailed(item.countryId, MapManager.nativeGetName(item.countryId));
MapManager.sendErrorStat(Statistics.EventName.DOWNLOADER_ERROR, MapManager.nativeGetError(item.countryId));
return;
}

View file

@ -10,7 +10,6 @@ import android.support.v4.app.NotificationCompat;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.downloader.CountryItem;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.statistics.Statistics;
@ -34,12 +33,12 @@ public final class Notifier
placeNotification(title, countriesName, pi, ID_UPDATE_AVAILABLE);
}
public static void notifyDownloadFailed(CountryItem country)
public static void notifyDownloadFailed(String id, String name)
{
String title = APP.getString(R.string.app_name);
String content = APP.getString(R.string.download_country_failed, country.name);
String content = APP.getString(R.string.download_country_failed, name);
PendingIntent pi = PendingIntent.getActivity(APP, 0, MwmActivity.createShowMapIntent(APP, country.id, false)
PendingIntent pi = PendingIntent.getActivity(APP, 0, MwmActivity.createShowMapIntent(APP, id, false)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
PendingIntent.FLAG_UPDATE_CURRENT);

View file

@ -143,11 +143,11 @@ public class WorkerService extends IntentService
return true;
}
CountryItem item = CountryItem.fill(country);
if (item.status != CountryItem.STATUS_DOWNLOADABLE)
if (MapManager.nativeGetStatus(country) != CountryItem.STATUS_DOWNLOADABLE)
return true;
Notifier.notifyDownloadSuggest(item.name, MwmApplication.get().getString(R.string.download_location_country, item.name), country);
String name = MapManager.nativeGetName(country);
Notifier.notifyDownloadSuggest(name, MwmApplication.get().getString(R.string.download_location_country, name), country);
PREFS.edit().putString(country, String.valueOf(System.currentTimeMillis())).apply();
return true;
}

View file

@ -17,7 +17,8 @@ import com.mapswithme.util.Utils;
public abstract class BaseMwmRecyclerFragment extends Fragment
{
private Toolbar mToolbar;
protected RecyclerView mRecycler;
private RecyclerView mRecycler;
private View mPlaceholder;
protected abstract RecyclerView.Adapter createAdapter();
@ -61,8 +62,12 @@ public abstract class BaseMwmRecyclerFragment extends Fragment
throw new IllegalStateException("RecyclerView not found in layout");
LinearLayoutManager manager = new LinearLayoutManager(view.getContext());
manager.setSmoothScrollbarEnabled(true);
mRecycler.setLayoutManager(manager);
mRecycler.setAdapter(createAdapter());
mPlaceholder = view.findViewById(R.id.placeholder);
setupPlaceholder(mPlaceholder);
}
public Toolbar getToolbar()
@ -90,8 +95,16 @@ public abstract class BaseMwmRecyclerFragment extends Fragment
org.alohalytics.Statistics.logEvent("$onPause", this.getClass().getSimpleName());
}
public BaseMwmFragmentActivity getMwmActivity()
protected void setupPlaceholder(View placeholder) {}
public void setupPlaceholder()
{
return (BaseMwmFragmentActivity) getActivity();
setupPlaceholder(mPlaceholder);
}
public void showPlaceholder(boolean show)
{
if (mPlaceholder != null)
UiUtils.showIf(show, mPlaceholder);
}
}

View file

@ -1,8 +1,8 @@
package com.mapswithme.maps.downloader;
import android.support.design.widget.FloatingActionButton;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Locale;
@ -14,8 +14,7 @@ import com.mapswithme.util.statistics.Statistics;
class BottomPanel
{
private final DownloaderFragment mFragment;
private final View mFrame;
private final TextView mText;
private final FloatingActionButton mFab;
private final Button mButton;
private final View.OnClickListener mDownloadListener = new View.OnClickListener()
@ -23,7 +22,7 @@ class BottomPanel
@Override
public void onClick(View v)
{
MapManager.warn3gAndDownload(mFragment.getActivity(), mFragment.getAdapter().getCurrentParent(), new Runnable()
MapManager.warn3gAndDownload(mFragment.getActivity(), mFragment.getCurrentRoot(), new Runnable()
{
@Override
public void run()
@ -43,7 +42,7 @@ class BottomPanel
@Override
public void onClick(View v)
{
final String country = mFragment.getAdapter().getCurrentParent();
final String country = mFragment.getCurrentRoot();
MapManager.warnOn3g(mFragment.getActivity(), country, new Runnable()
{
@Override
@ -66,7 +65,7 @@ class BottomPanel
@Override
public void onClick(View v)
{
MapManager.nativeCancel(mFragment.getAdapter().getCurrentParent());
MapManager.nativeCancel(mFragment.getCurrentRoot());
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
@ -76,30 +75,38 @@ class BottomPanel
BottomPanel(DownloaderFragment fragment, View frame)
{
mFragment = fragment;
mFrame = frame;
mText = (TextView) mFrame.findViewById(R.id.tv__text);
mButton = (Button) mFrame.findViewById(R.id.btn__action);
mFab = (FloatingActionButton) frame.findViewById(R.id.fab);
mFab.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
mFragment.getAdapter().setAvailableMapsMode();
update();
}
});
mButton = (Button) frame.findViewById(R.id.action);
UiUtils.updateAccentButton(mButton);
}
private void setUpdateAllState(UpdateInfo info)
{
UiUtils.setTextAndShow(mText, String.format(Locale.US, "%s: %d (%s)", mFragment.getString(R.string.downloader_status_maps),
info.filesCount,
StringUtils.getFileSizeString(info.totalSize)));
mButton.setText(R.string.downloader_update_all_button);
mButton.setText(String.format(Locale.US, "%s (%s)", mFragment.getString(R.string.downloader_update_all_button),
StringUtils.getFileSizeString(info.totalSize)));
mButton.setOnClickListener(mUpdateListener);
}
private void setDownloadAllState()
{
UiUtils.invisible(mText);
mButton.setText(R.string.downloader_download_all_button);
mButton.setOnClickListener(mDownloadListener);
}
private void setCancelState()
{
UiUtils.invisible(mText);
mButton.setText(R.string.downloader_cancel_all);
mButton.setOnClickListener(mCancelListener);
}
@ -110,28 +117,24 @@ class BottomPanel
boolean search = adapter.isSearchResultsMode();
boolean show = !search;
UiUtils.showIf(show && adapter.isMyMapsMode(), mFab);
if (show)
{
String root = adapter.getCurrentParent();
if (root == null)
{
if (MapManager.nativeIsDownloading())
setCancelState();
else
{
UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
show = (info != null && info.filesCount > 0);
if (show)
setUpdateAllState(info);
}
}
else
String root = adapter.getCurrentRoot();
if (adapter.isMyMapsMode())
{
int status = MapManager.nativeGetStatus(root);
switch (status)
{
case CountryItem.STATUS_UPDATABLE:
UpdateInfo info = MapManager.nativeGetUpdateInfo(root);
setUpdateAllState(info);
break;
case CountryItem.STATUS_DOWNLOADABLE: // Special case for "Countries" node when no maps currently downloaded.
case CountryItem.STATUS_DONE:
case CountryItem.STATUS_PARTLY:
show = false;
break;
@ -140,12 +143,43 @@ class BottomPanel
setCancelState();
break;
default:
case CountryItem.STATUS_FAILED:
setDownloadAllState();
break;
default:
throw new IllegalArgumentException("Inappropriate status for \"" + root + "\": " + status);
}
}
else
{
show = !CountryItem.isRoot(root);
if (show)
{
int status = MapManager.nativeGetStatus(root);
switch (status)
{
case CountryItem.STATUS_UPDATABLE:
UpdateInfo info = MapManager.nativeGetUpdateInfo(root);
setUpdateAllState(info);
break;
case CountryItem.STATUS_DONE:
show = false;
break;
case CountryItem.STATUS_PROGRESS:
case CountryItem.STATUS_ENQUEUED:
setCancelState();
break;
default:
setDownloadAllState();
}
}
}
}
UiUtils.showIf(show, mFrame);
UiUtils.showIf(show, mButton);
}
}

View file

@ -9,7 +9,7 @@ import android.text.TextUtils;
*/
public final class CountryItem implements Comparable<CountryItem>
{
private static String ROOT;
private static String sRootId;
// Must correspond to ItemCategory in MapManager.cpp
static final int CATEGORY_NEAR_ME = 0;
@ -39,6 +39,7 @@ public final class CountryItem implements Comparable<CountryItem>
public String name;
public String directParentName;
public String topmostParentName;
public String description;
public long size;
public long totalSize;
@ -59,6 +60,12 @@ public final class CountryItem implements Comparable<CountryItem>
// Internal field to store search result name
String searchResultName;
private static void ensureRootIdKnown()
{
if (sRootId == null)
sRootId = MapManager.nativeGetRoot();
}
public CountryItem(String id)
{
this.id = id;
@ -97,11 +104,9 @@ public final class CountryItem implements Comparable<CountryItem>
{
MapManager.nativeGetAttributes(this);
if (ROOT == null)
ROOT = MapManager.nativeGetRoot();
if (TextUtils.equals(ROOT, directParentName))
directParentName = "";
ensureRootIdKnown();
if (TextUtils.equals(sRootId, directParentId))
directParentId = "";
}
public static CountryItem fill(String countryId)
@ -111,6 +116,18 @@ public final class CountryItem implements Comparable<CountryItem>
return res;
}
public static boolean isRoot(String id)
{
ensureRootIdKnown();
return sRootId.equals(id);
}
public static String getRootId()
{
ensureRootIdKnown();
return sRootId;
}
public boolean isExpandable()
{
return (totalChildCount > 1);

View file

@ -7,6 +7,7 @@ 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;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
@ -14,7 +15,6 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.SparseArray;
import android.util.SparseIntArray;
@ -56,6 +56,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
private final DownloaderFragment mFragment;
private final StickyRecyclerHeadersDecoration mHeadersDecoration;
private boolean mMyMapsMode = true;
private boolean mSearchResultsMode;
private String mSearchQuery;
@ -63,7 +64,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
private final Map<String, CountryItem> mCountryIndex = new HashMap<>(); // Country.id -> Country
private final SparseArray<String> mHeaders = new SparseArray<>();
private final Stack<PathEntry> mPath = new Stack<>();
private final Stack<PathEntry> mPath = new Stack<>(); // Holds navigation history. The last element is the current level.
private final SparseIntArray mIconsCache = new SparseIntArray();
@ -215,16 +216,27 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
{
final String countryId;
final String name;
final boolean myMapsMode;
final int topPosition;
final int topOffset;
private PathEntry(String countryId, String name, int topPosition, int topOffset)
private PathEntry(String countryId, String name, boolean myMapsMode, int topPosition, int topOffset)
{
this.countryId = countryId;
this.name = name;
this.myMapsMode = myMapsMode;
this.topPosition = topPosition;
this.topOffset = topOffset;
}
@Override
public String toString()
{
return countryId + " (" + name + "), " +
"myMapsMode: " + myMapsMode +
", topPosition: " + topPosition +
", topOffset: " + topOffset;
}
}
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
@ -247,11 +259,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
{
ViewHolder vh = (ViewHolder)mRecycler.findViewHolderForAdapterPosition(i);
if (vh != null && vh.mItem.id.equals(countryId))
{
vh.bind(vh.mItem);
// No duplcates allowed in the list
return;
}
}
}
@ -424,7 +432,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
public void onClick(View v)
{
if (mItem.isExpandable())
goDeeper(mItem);
goDeeper(mItem.id, mItem.name, true);
else
processClick(false);
}
@ -489,7 +497,9 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
case CountryItem.STATUS_DOWNLOADABLE:
case CountryItem.STATUS_PARTLY:
iconAttr = R.attr.status_downloadable;
iconAttr = (mItem.isExpandable() ? (mMyMapsMode ? R.attr.status_folder_done
: R.attr.status_folder)
: R.attr.status_downloadable);
break;
case CountryItem.STATUS_FAILED:
@ -517,8 +527,6 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
mName.setMaxLines(1);
mName.setText(mItem.name);
UiUtils.show(mFoundName);
String found = mItem.searchResultName.toLowerCase();
SpannableStringBuilder builder = new SpannableStringBuilder(mItem.searchResultName);
int start = found.indexOf(mSearchQuery);
@ -534,12 +542,10 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
}
else
{
UiUtils.hide(mFoundName);
mName.setMaxLines(2);
mName.setText(mItem.name);
if (!mItem.isExpandable())
UiUtils.hide(mSubtitle);
UiUtils.setTextAndHideIfEmpty(mSubtitle, mItem.description);
}
if (mItem.isExpandable())
@ -549,18 +555,22 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
mItem.totalChildCount)));
}
UiUtils.showIf(mSearchResultsMode, mFoundName);
mSize.setText(StringUtils.getFileSizeString(mItem.totalSize));
updateStatus();
}
}
class HeaderViewHolder extends RecyclerView.ViewHolder {
private final TextView mTitle;
HeaderViewHolder(View frame) {
super(frame);
mTitle = (TextView) frame.findViewById(R.id.title);
}
void bind(int position) {
((TextView)itemView).setText(mHeaders.get(mItems.get(position).headerId));
mTitle.setText(mHeaders.get(mItems.get(position).headerId));
}
}
@ -620,19 +630,19 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
}
}
private void refreshData()
void refreshData()
{
mSearchResultsMode = false;
mSearchQuery = null;
mItems.clear();
String parent = getCurrentParent();
String parent = getCurrentRoot();
boolean hasLocation = false;
double lat = 0.0;
double lon = 0.0;
if (TextUtils.isEmpty(parent))
if (!mMyMapsMode && CountryItem.isRoot(parent))
{
Location loc = LocationHelper.INSTANCE.getSavedLocation();
hasLocation = (loc != null);
@ -643,7 +653,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
}
}
MapManager.nativeListItems(parent, lat, lon, hasLocation, mItems);
MapManager.nativeListItems(parent, lat, lon, hasLocation, mMyMapsMode, mItems);
processData();
}
@ -665,7 +675,9 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
private void processData()
{
Collections.sort(mItems);
if (!mSearchResultsMode)
Collections.sort(mItems);
collectHeaders();
mCountryIndex.clear();
@ -674,6 +686,11 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
mHeadersDecoration.invalidateHeaders();
notifyDataSetChanged();
if (mItems.isEmpty())
mFragment.setupPlaceholder();
mFragment.showPlaceholder(mItems.isEmpty());
}
DownloaderAdapter(DownloaderFragment fragment)
@ -683,7 +700,6 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
mRecycler = mFragment.getRecyclerView();
mHeadersDecoration = new StickyRecyclerHeadersDecoration(this);
mRecycler.addItemDecoration(mHeadersDecoration);
refreshData();
}
@Override
@ -722,54 +738,78 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
return mItems.size();
}
private void goDeeper(CountryItem child)
private void goDeeper(String childId, String childName, boolean refresh)
{
LinearLayoutManager lm = (LinearLayoutManager)mRecycler.getLayoutManager();
// Save scroll positions (top item + item`s offset) for current hierarchy level
int position = lm.findFirstVisibleItemPosition();
int offset = lm.findViewByPosition(position).getTop();
int offset;
if (position > -1)
offset = lm.findViewByPosition(position).getTop();
else
{
position = 0;
offset = 0;
}
boolean wasEmpty = mPath.isEmpty();
mPath.push(new PathEntry(child.id, child.name, position, offset));
mPath.push(new PathEntry(childId, childName, mMyMapsMode, position, offset));
if (wasEmpty)
mFragment.clearSearchQuery();
refreshData();
lm.scrollToPosition(0);
if (!refresh)
return;
refreshData();
mFragment.update();
}
boolean canGoUpdwards()
private boolean canGoUpwards()
{
return !mPath.isEmpty();
}
boolean goUpwards()
{
if (!canGoUpdwards())
if (!canGoUpwards())
return false;
final PathEntry entry = mPath.pop();
PathEntry entry = mPath.pop();
mMyMapsMode = entry.myMapsMode;
refreshData();
LinearLayoutManager lm = (LinearLayoutManager)mRecycler.getLayoutManager();
LinearLayoutManager lm = (LinearLayoutManager) mRecycler.getLayoutManager();
lm.scrollToPositionWithOffset(entry.topPosition, entry.topOffset);
mFragment.update();
return true;
}
@Nullable String getCurrentParent()
void setAvailableMapsMode()
{
return (canGoUpdwards() ? mPath.peek().countryId : null);
goDeeper(getCurrentRoot(), getCurrentRootName(), false);
mMyMapsMode = false;
refreshData();
}
@Nullable String getCurrentParentName()
@NonNull String getCurrentRoot()
{
return (canGoUpdwards() ? mPath.peek().name : null);
return (canGoUpwards() ? mPath.peek().countryId : CountryItem.getRootId());
}
@Nullable String getCurrentRootName()
{
return (canGoUpwards() ? mPath.peek().name : null);
}
boolean isMyMapsMode()
{
return mMyMapsMode;
}
void attach()

View file

@ -2,6 +2,7 @@ package com.mapswithme.maps.downloader;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
@ -15,6 +16,7 @@ import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.maps.search.NativeMapSearchListener;
import com.mapswithme.maps.search.SearchEngine;
import com.mapswithme.util.UiUtils;
public class DownloaderFragment extends BaseMwmRecyclerFragment
implements OnBackPressListener
@ -68,6 +70,11 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
}
};
boolean shouldShowSearch()
{
return CountryItem.isRoot(getCurrentRoot());
}
void startSearch()
{
mSearchRunning = true;
@ -99,10 +106,7 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
void update()
{
String rootName = mAdapter.getCurrentParentName();
boolean onTop = (mAdapter.isSearchResultsMode() || rootName == null);
mToolbarController.update(onTop ? "" : rootName);
mToolbarController.update();
mBottomPanel.update();
}
@ -126,9 +130,10 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
SearchEngine.INSTANCE.addMapListener(mSearchListener);
getRecyclerView().addOnScrollListener(mScrollListener);
mAdapter.refreshData();
mAdapter.attach();
mBottomPanel = new BottomPanel(this, view.findViewById(R.id.bottom_panel));
mBottomPanel = new BottomPanel(this, view);
mToolbarController = new DownloaderToolbarController(view, getActivity(), this);
update();
@ -197,4 +202,19 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
{
return mAdapter;
}
@NonNull String getCurrentRoot()
{
return mAdapter.getCurrentRoot();
}
@Override
protected void setupPlaceholder(View placeholder)
{
// TODO (trashkalmar): Set actual resources
if (mAdapter.isSearchResultsMode())
UiUtils.setupPlaceholder(placeholder, R.drawable.img_search_nothing_found_light, R.string.search_not_found, R.string.search_not_found_query);
else
UiUtils.setupPlaceholder(placeholder, R.drawable.img_search_no_maps, R.string.search_history_title, R.string.search_history_text);
}
}

View file

@ -22,7 +22,7 @@ class DownloaderToolbarController extends SearchToolbarController
@Override
protected void onTextChanged(String query)
{
if (!mFragment.isAdded() || mFragment.getAdapter().canGoUpdwards())
if (!mFragment.isAdded() || !mFragment.shouldShowSearch())
return;
if (TextUtils.isEmpty(query))
@ -31,16 +31,12 @@ class DownloaderToolbarController extends SearchToolbarController
mFragment.startSearch();
}
@Override
public void onUpClick()
public void update()
{
if (!mFragment.onBackPressed())
super.onUpClick();
}
boolean showSearch = mFragment.shouldShowSearch();
String title = (showSearch ? "" : mFragment.getAdapter().getCurrentRootName());
public void update(String title)
{
showControls(!mFragment.getAdapter().canGoUpdwards());
showControls(showSearch);
setTitle(title);
}

View file

@ -315,9 +315,10 @@ public final class MapManager
public static native @Nullable UpdateInfo nativeGetUpdateInfo(@Nullable String root);
/**
* Retrieves list of country items with its status info. Uses root as parent if {@code root} is null.
* Retrieves list of country items with its status info.
* if {@code root} is {@code null}, list of downloaded countries is returned.
*/
public static native void nativeListItems(@Nullable String root, double lat, double lon, boolean hasLocation, List<CountryItem> result);
public static native void nativeListItems(@Nullable String root, double lat, double lon, boolean hasLocation, boolean myMapsMode, List<CountryItem> result);
/**
* Sets following attributes of the given {@code item}:
@ -346,6 +347,16 @@ public final class MapManager
*/
public static native int nativeGetStatus(String root);
/**
* Returns downloading error for given {@code root} node.
*/
public static native int nativeGetError(String root);
/**
* Returns localized name for given {@code root} node.
*/
public static native String nativeGetName(String root);
/**
* Returns country ID corresponding to given coordinates or {@code null} on error.
*/
@ -406,4 +417,10 @@ public final class MapManager
* Determines if there are unsaved editor changes present for given {@code root}.
*/
public static native boolean nativeHasUnsavedEditorChanges(String root);
/**
* Fills given {@code result} list with intermediate nodes from the root node (including) to the given {@code root} (excluding).
* For instance, for {@code root == "Florida"} the resulting list is filled with values: {@code { "United States of America", "Countries" }}.
*/
public static native void nativeGetPathTo(String root, List<String> result);
}

View file

@ -232,6 +232,7 @@ public class SearchFragment extends BaseMwmFragment
RecyclerView results = (RecyclerView) mResultsFrame.findViewById(R.id.recycler);
setRecyclerScrollListener(results);
mResultsPlaceholder = mResultsFrame.findViewById(R.id.placeholder);
UiUtils.setupPlaceholder(mResultsPlaceholder, R.drawable.img_search_nothing_found_light, R.string.search_not_found, R.string.search_not_found_query);
if (mSearchAdapter == null)
{

View file

@ -36,6 +36,7 @@ public class SearchHistoryFragment extends BaseMwmRecyclerFragment
{
super.onViewCreated(view, savedInstanceState);
mPlaceHolder = view.findViewById(R.id.placeholder);
UiUtils.setupPlaceholder(mPlaceHolder, R.drawable.img_search_empty_history_light, R.string.search_history_title, R.string.search_history_text);
getAdapter().registerAdapterDataObserver(new RecyclerView.AdapterDataObserver()
{

View file

@ -9,6 +9,7 @@ public final class Constants
public static final int KB = 1024;
public static final int MB = 1024 * 1024;
public static final int GB = 1024 * 1024 * 1024;
public static class Url
{

View file

@ -29,22 +29,30 @@ public class StringUtils
* @return result text
*/
public static String removeEditTextHtmlTags(String text)
{
return text.replaceAll("</p>", "").replaceAll("<br>", "").replaceAll("<p dir=\"ltr\">", "");
}
/**
* Formats size in bytes to "x.x MB" or "x.x KB" format.
* Formats size in bytes to "x MB" or "x.x GB" format.
* Small values rounded to 1 MB without fractions.
*
* @param size size in bytes
* @return formatted string
*/
public static String getFileSizeString(long size)
{
boolean mb = (size >= Constants.MB);
float value = ((float)size / (mb ? Constants.MB : Constants.KB));
return formatUsingUsLocale("%1$.1f %2$s", value, MwmApplication.get().getString(mb ? R.string.mb : R.string.kb));
if (size < Constants.GB)
{
int value = (int)((float)size / Constants.MB + 0.5f);
if (value == 0)
value = 1;
return String.format(Locale.US, "%1$d %2$s", value, MwmApplication.get().getString(R.string.mb));
}
float value = ((float)size / Constants.GB);
return String.format(Locale.US, "%1$.1f %2$s", value, MwmApplication.get().getString(R.string.gb));
}
public static boolean isRtl()

View file

@ -11,8 +11,10 @@ import android.net.Uri;
import android.os.Build;
import android.support.annotation.AnyRes;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
@ -22,6 +24,7 @@ import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.mapswithme.maps.MwmApplication;
@ -291,6 +294,18 @@ public final class UiUtils
: R.attr.accentButtonTextColorDisabled));
}
public static void setupPlaceholder(View frame, @DrawableRes int imageRes, @StringRes int titleRes, @StringRes int subtitleRes)
{
ImageView image = (ImageView) frame.findViewById(R.id.image);
image.setImageResource(imageRes);
TextView title = (TextView) frame.findViewById(R.id.title);
title.setText(titleRes);
TextView subtitle = (TextView) frame.findViewById(R.id.subtitle);
subtitle.setText(subtitleRes);
}
public static Uri getUriToResId(@NonNull Context context, @AnyRes int resId)
{
final Resources resources = context.getResources();

View file

@ -73,6 +73,8 @@
/* Settings/Downloader - size string, only strings different from English should be translated */
"mb" = "م.ب.";
"gb" = "GB";
/* Choose measurement on first launch alert - choose imperial system button */
"miles" = "ميل";

Some files were not shown because too many files have changed in this diff Show more