[new downloader][android] fix: Use fast node attrs getting.

fix: Incorrect downloader toolbar layouting.
fix: Update downloader toolbar buttons.
This commit is contained in:
Alexander Marchuk 2016-03-15 16:11:03 +03:00 committed by Sergey Yershov
parent 854321aeb9
commit 241c981ee6
6 changed files with 70 additions and 27 deletions

View file

@ -178,12 +178,13 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeGetDownloadedCount(JNIEnv *
return GetStorage().GetDownloadedFilesCount();
}
// static @Nullable UpdateInfo nativeGetUpdateInfo();
// static @Nullable UpdateInfo nativeGetUpdateInfo(@Nullable String root);
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetUpdateInfo(JNIEnv * env, jclass clazz)
Java_com_mapswithme_maps_downloader_MapManager_nativeGetUpdateInfo(JNIEnv * env, jclass clazz, jstring root)
{
Storage::UpdateInfo info;
if (!GetStorage().GetUpdateInfo(GetStorage().GetRootId(), info))
TCountryId const rootId = (root ? jni::ToNativeString(env, root) : GetStorage().GetRootId());
if (!GetStorage().GetUpdateInfo(rootId, info))
return nullptr;
static jclass const infoClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/downloader/UpdateInfo");
@ -194,6 +195,15 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeGetUpdateInfo(JNIEnv * env,
return env->NewObject(infoClass, ctor, info.m_numberOfMwmFilesToUpdate, info.m_totalUpdateSizeInBytes);
}
static void UpdateItemShort(JNIEnv * env, jobject item, NodeStatus const status, NodeErrorCode const error)
{
static jfieldID const countryItemFieldStatus = env->GetFieldID(g_countryItemClass, "status", "I");
static jfieldID const countryItemFieldErrorCode = env->GetFieldID(g_countryItemClass, "errorCode", "I");
env->SetIntField(item, countryItemFieldStatus, static_cast<jint>(status));
env->SetIntField(item, countryItemFieldErrorCode, static_cast<jint>(error));
}
static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
{
static jfieldID const countryItemFieldName = env->GetFieldID(g_countryItemClass, "name", "Ljava/lang/String;");
@ -203,8 +213,6 @@ static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
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");
static jfieldID const countryItemFieldStatus = env->GetFieldID(g_countryItemClass, "status", "I");
static jfieldID const countryItemFieldErrorCode = env->GetFieldID(g_countryItemClass, "errorCode", "I");
static jfieldID const countryItemFieldPresent = env->GetFieldID(g_countryItemClass, "present", "Z");
static jfieldID const countryItemFieldProgress = env->GetFieldID(g_countryItemClass, "progress", "I");
@ -238,8 +246,7 @@ static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
env->SetIntField(item, countryItemFieldTotalChildCount, attrs.m_mwmCounter);
// Status and error code
env->SetIntField(item, countryItemFieldStatus, static_cast<jint>(attrs.m_status));
env->SetIntField(item, countryItemFieldErrorCode, static_cast<jint>(attrs.m_error));
UpdateItemShort(env, item, attrs.m_status, attrs.m_error);
// Presence flag
env->SetBooleanField(item, countryItemFieldPresent, attrs.m_present);
@ -306,14 +313,30 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeGetAttributes(JNIEnv * env,
{
PrepareClassRefs(env);
NodeAttrs attrs;
static jfieldID countryItemFieldId = env->GetFieldID(g_countryItemClass, "id", "Ljava/lang/String;");
jstring id = static_cast<jstring>(env->GetObjectField(item, countryItemFieldId));
NodeAttrs attrs;
GetStorage().GetNodeAttrs(jni::ToNativeString(env, id), attrs);
UpdateItem(env, item, attrs);
}
// static void nativeGetShortAttributes(CountryItem item);
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetShortAttributes(JNIEnv * env, jclass clazz, jobject item)
{
PrepareClassRefs(env);
static jfieldID countryItemFieldId = env->GetFieldID(g_countryItemClass, "id", "Ljava/lang/String;");
jstring id = static_cast<jstring>(env->GetObjectField(item, countryItemFieldId));
NodeStatuses ns;
GetStorage().GetNodeStatuses(jni::ToNativeString(env, id), ns);
UpdateItemShort(env, item, ns.m_status, ns.m_error);
}
// 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)
@ -356,7 +379,8 @@ static void EndBatchingCallbacks(JNIEnv * env)
static jclass batchDataClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/downloader/MapManager$StorageCallbackData");
static jmethodID batchDataCtor = jni::GetConstructorID(env, batchDataClass, "(Ljava/lang/String;IIZ)V");
jni::TScopedLocalRef const item(env, env->NewObject(batchDataClass, batchDataCtor, jni::ToJavaString(env, dataItem.m_countryId),
jni::TScopedLocalRef const id(env, jni::ToJavaString(env, dataItem.m_countryId));
jni::TScopedLocalRef const item(env, env->NewObject(batchDataClass, batchDataCtor, id.get(),
static_cast<jint>(dataItem.m_newStatus),
static_cast<jint>(dataItem.m_errorCode),
dataItem.m_isLeaf));
@ -427,11 +451,10 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeShow(JNIEnv * env, jclass c
static void StatusChangedCallback(shared_ptr<jobject> const & listenerRef, TCountryId const & countryId)
{
// TODO: The core will do this itself
NodeAttrs attrs;
GetStorage().GetNodeAttrs(countryId, attrs);
NodeStatuses ns;
GetStorage().GetNodeStatuses(countryId, ns);
TBatchedData const data(countryId, attrs.m_status, attrs.m_error, (attrs.m_mwmCounter == 1));
TBatchedData const data(countryId, ns.m_status, ns.m_error, ns.m_groupNode);
g_batchedCallbackData[*listenerRef].push_back(move(data));
if (!g_isBatched)

View file

@ -7,11 +7,11 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:gravity="right|center_vertical">
android:layout_gravity="right|center_vertical">
<include layout="@layout/toolbar_search_controls"/>
<ImageView

View file

@ -107,15 +107,13 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
boolean onTop = (mAdapter.isSearchResultsMode() || rootName == null);
// Toolbar
mToolbarController.update();
if (!onTop)
mToolbarController.setTitle(rootName); // FIXME: Title not shown. Investigate this.
mToolbarController.update(onTop ? null : mAdapter.getCurrentParent(), onTop ? "" : rootName);
// Bottom panel
boolean showBottom = onTop;
if (showBottom)
{
UpdateInfo info = MapManager.nativeGetUpdateInfo();
UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
showBottom = (info != null && info.filesCount > 0);
if (showBottom)

View file

@ -2,8 +2,10 @@ package com.mapswithme.maps.downloader;
import android.app.Activity;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import com.mapswithme.maps.R;
import com.mapswithme.maps.widget.SearchToolbarController;
@ -92,7 +94,7 @@ class DownloaderToolbarController extends SearchToolbarController
super.onUpClick();
}
public void update()
public void update(@Nullable String currentRoot, String title)
{
boolean search = hasQuery();
boolean cancel = MapManager.nativeIsDownloading();
@ -100,8 +102,8 @@ class DownloaderToolbarController extends SearchToolbarController
boolean update = (!search && !cancel);
if (update)
{
// TODO (trashkalmar): Use appropriate function
update = false;
UpdateInfo info = MapManager.nativeGetUpdateInfo(currentRoot);
update = (info != null && info.filesCount > 0);
}
boolean onTop = !mFragment.getAdapter().canGoUpdwards();
@ -109,14 +111,23 @@ class DownloaderToolbarController extends SearchToolbarController
boolean download = (!search && !cancel && !update && !onTop);
if (download)
{
// TODO (trashkalmar): Use appropriate function
download = true;
CountryItem item = CountryItem.fill(currentRoot);
download = (item.childCount < item.totalChildCount);
}
UiUtils.showIf(cancel, mCancelAll);
UiUtils.showIf(update, mUpdateAll);
UiUtils.showIf(download, mDownloadAll);
showControls(onTop);
setTitle(title);
// Hack: Toolbar title is pressed out by controls. Resize frame to avoid this.
View frameParent = (View) mContainer.getParent();
ViewGroup.LayoutParams lp = frameParent.getLayoutParams();
lp.width = (onTop ? ViewGroup.LayoutParams.MATCH_PARENT
: ViewGroup.LayoutParams.WRAP_CONTENT);
frameParent.setLayoutParams(lp);
}
@Override

View file

@ -153,9 +153,9 @@ public final class MapManager
public static native int nativeGetDownloadedCount();
/**
* Returns info about updatable data or null on error.
* Returns info about updatable data under given {@code root} or null on error.
*/
public static native @Nullable UpdateInfo nativeGetUpdateInfo();
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.
@ -182,6 +182,17 @@ public final class MapManager
*/
public static native void nativeGetAttributes(CountryItem item);
/**
* Sets following attributes of the given {@code item}:
* <pre>
* <ul>
* <li>status;</li>
* <li>errorCode</li>
* </ul>
* </pre>
*/
public static native void nativeGetShortAttributes(CountryItem item);
/**
* Returns country ID corresponding to given coordinates or {@code null} on error.
*/

View file

@ -316,7 +316,7 @@ public class MainMenu
private void updateMarker()
{
UpdateInfo info = MapManager.nativeGetUpdateInfo();
UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
int count = (info == null ? 0 : info.filesCount);
boolean show = (MapManager.nativeIsLegacyMode() || count > 0) &&