forked from organicmaps/organicmaps
Merge pull request #2801 from trashkalmar/downloader-bottom-panel
[new downloader][android] fix: Show bottom panel instead of toolbar b…
This commit is contained in:
commit
ecb2bde4bc
9 changed files with 168 additions and 168 deletions
|
@ -373,6 +373,15 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeGetAttributes(JNIEnv * env,
|
|||
UpdateItem(env, item, attrs);
|
||||
}
|
||||
|
||||
// static void nativeGetStatus(String root);
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeGetStatus(JNIEnv * env, jclass clazz, jstring root)
|
||||
{
|
||||
NodeStatuses ns;
|
||||
GetStorage().GetNodeStatuses(jni::ToNativeString(env, root), ns);
|
||||
return static_cast<jint>(ns.m_status);
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/height_block_base"
|
||||
android:paddingLeft="@dimen/margin_half"
|
||||
android:background="?panel"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
@ -13,11 +12,12 @@
|
|||
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="@string/downloader_status_maps"/>
|
||||
tools:text="Maps: 10 (1024 MB)"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn__action"
|
||||
|
@ -28,5 +28,5 @@
|
|||
style="@style/MwmWidget.Button"
|
||||
android:textAppearance="@style/MwmTextAppearance.Button"
|
||||
android:textColor="?colorAccent"
|
||||
android:text="@string/downloader_update_all_button"/>
|
||||
tools:text="@string/downloader_update_all_button"/>
|
||||
</LinearLayout>
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<include layout="@layout/toolbar_downloader"/>
|
||||
<include layout="@layout/toolbar_with_search"/>
|
||||
|
||||
<include
|
||||
layout="@layout/recycler_default"
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?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">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:baselineAligned="false"
|
||||
android:layout_gravity="end|center_vertical">
|
||||
<include layout="@layout/toolbar_search_controls"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/download_all"
|
||||
android:layout_width="?actionBarSize"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:layout_gravity="end"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_download"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/update_all"
|
||||
style="@style/MwmWidget.Downloader.ToolbarButton"
|
||||
android:text="@string/downloader_update_all_button"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cancel_all"
|
||||
style="@style/MwmWidget.Downloader.ToolbarButton"
|
||||
android:text="@string/downloader_cancel_all"/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.Toolbar>
|
138
android/src/com/mapswithme/maps/downloader/BottomPanel.java
Normal file
138
android/src/com/mapswithme/maps/downloader/BottomPanel.java
Normal file
|
@ -0,0 +1,138 @@
|
|||
package com.mapswithme.maps.downloader;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
class BottomPanel
|
||||
{
|
||||
private final DownloaderFragment mFragment;
|
||||
private final View mFrame;
|
||||
private final TextView mText;
|
||||
private final Button mButton;
|
||||
|
||||
private final View.OnClickListener mDownloadListener = new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeDownload(mFragment.getAdapter().getCurrentParent());
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
|
||||
Statistics.params().add(Statistics.EventParam.ACTION, "download")
|
||||
.add(Statistics.EventParam.FROM, "downloader")
|
||||
.add("is_auto", "false")
|
||||
.add("scenario", "download_group"));
|
||||
}
|
||||
};
|
||||
|
||||
private final View.OnClickListener mUpdateListener = new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeUpdate(mFragment.getAdapter().getCurrentParent());
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
|
||||
Statistics.params().add(Statistics.EventParam.ACTION, "update")
|
||||
.add(Statistics.EventParam.FROM, "downloader")
|
||||
.add("is_auto", "false")
|
||||
.add("scenario", "update_all"));
|
||||
}
|
||||
};
|
||||
|
||||
private final View.OnClickListener mCancelListener = new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeCancel(mFragment.getAdapter().getCurrentParent());
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
|
||||
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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.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);
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
DownloaderAdapter adapter = mFragment.getAdapter();
|
||||
boolean search = adapter.isSearchResultsMode();
|
||||
|
||||
boolean show = !search;
|
||||
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
|
||||
{
|
||||
int status = MapManager.nativeGetStatus(root);
|
||||
switch (status)
|
||||
{
|
||||
case CountryItem.STATUS_DONE:
|
||||
show = false;
|
||||
break;
|
||||
|
||||
case CountryItem.STATUS_PROGRESS:
|
||||
case CountryItem.STATUS_ENQUEUED:
|
||||
setCancelState();
|
||||
break;
|
||||
|
||||
default:
|
||||
setDownloadAllState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UiUtils.showIf(show, mFrame);
|
||||
}
|
||||
}
|
|
@ -6,12 +6,9 @@ import android.os.Bundle;
|
|||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -19,17 +16,13 @@ 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.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class DownloaderFragment extends BaseMwmRecyclerFragment
|
||||
implements OnBackPressListener
|
||||
{
|
||||
private DownloaderToolbarController mToolbarController;
|
||||
|
||||
private View mBottomPanel;
|
||||
private Button mPanelAction;
|
||||
private TextView mPanelText;
|
||||
private BottomPanel mBottomPanel;
|
||||
private DownloaderAdapter mAdapter;
|
||||
|
||||
private long mCurrentSearch;
|
||||
|
@ -102,21 +95,8 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
|
|||
String rootName = mAdapter.getCurrentParentName();
|
||||
boolean onTop = (mAdapter.isSearchResultsMode() || rootName == null);
|
||||
|
||||
// Toolbar
|
||||
mToolbarController.update(onTop ? null : mAdapter.getCurrentParent(), onTop ? "" : rootName);
|
||||
|
||||
// Bottom panel
|
||||
boolean showBottom = (onTop && !mAdapter.isSearchResultsMode());
|
||||
if (showBottom)
|
||||
{
|
||||
UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
|
||||
showBottom = (info != null && info.filesCount > 0);
|
||||
|
||||
if (showBottom)
|
||||
mPanelText.setText(String.format(Locale.US, "%s: %d (%s)", getString(R.string.downloader_status_maps), info.filesCount, StringUtils.getFileSizeString(info.totalSize)));
|
||||
}
|
||||
|
||||
UiUtils.showIf(showBottom, mBottomPanel);
|
||||
mToolbarController.update(onTop ? "" : rootName);
|
||||
mBottomPanel.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -160,20 +140,9 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
|
|||
getRecyclerView().addOnScrollListener(mScrollListener);
|
||||
mAdapter.attach();
|
||||
|
||||
mBottomPanel = view.findViewById(R.id.bottom_panel);
|
||||
mPanelAction = (Button) mBottomPanel.findViewById(R.id.btn__action);
|
||||
mPanelText = (TextView) mBottomPanel.findViewById(R.id.tv__text);
|
||||
mBottomPanel = new BottomPanel(this, view.findViewById(R.id.bottom_panel));
|
||||
mToolbarController = new DownloaderToolbarController(view, getActivity(), this);
|
||||
|
||||
mPanelAction.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeUpdate(mAdapter.getCurrentParent());
|
||||
}
|
||||
});
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,90 +2,33 @@ 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;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
class DownloaderToolbarController extends SearchToolbarController
|
||||
{
|
||||
private final DownloaderFragment mFragment;
|
||||
|
||||
private final View mDownloadAll;
|
||||
private final View mUpdateAll;
|
||||
private final View mCancelAll;
|
||||
|
||||
DownloaderToolbarController(View root, Activity activity, DownloaderFragment fragment)
|
||||
{
|
||||
super(root, activity);
|
||||
mFragment = fragment;
|
||||
setHint(R.string.downloader_search_field_hint);
|
||||
|
||||
mDownloadAll = mToolbar.findViewById(R.id.download_all);
|
||||
mUpdateAll = mToolbar.findViewById(R.id.update_all);
|
||||
mCancelAll = mToolbar.findViewById(R.id.cancel_all);
|
||||
|
||||
mDownloadAll.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeDownload(mFragment.getAdapter().getCurrentParent());
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
|
||||
Statistics.params().add(Statistics.EventParam.ACTION, "download")
|
||||
.add(Statistics.EventParam.FROM, "downloader")
|
||||
.add("is_auto", "false")
|
||||
.add("scenario", "download_group"));
|
||||
}
|
||||
});
|
||||
|
||||
mUpdateAll.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeUpdate(mFragment.getAdapter().getCurrentParent());
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_ACTION,
|
||||
Statistics.params().add(Statistics.EventParam.ACTION, "update")
|
||||
.add(Statistics.EventParam.FROM, "downloader")
|
||||
.add("is_auto", "false")
|
||||
.add("scenario", "update_all"));
|
||||
}
|
||||
});
|
||||
|
||||
mCancelAll.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MapManager.nativeCancel(mFragment.getAdapter().getCurrentParent());
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_CANCEL,
|
||||
Statistics.params().add(Statistics.EventParam.FROM, "downloader"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTextChanged(String query)
|
||||
{
|
||||
if (!mFragment.isAdded())
|
||||
if (!mFragment.isAdded() || mFragment.getAdapter().canGoUpdwards())
|
||||
return;
|
||||
|
||||
if (TextUtils.isEmpty(query))
|
||||
{
|
||||
mFragment.cancelSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
mFragment.startSearch();
|
||||
else
|
||||
mFragment.startSearch();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,46 +38,16 @@ class DownloaderToolbarController extends SearchToolbarController
|
|||
super.onUpClick();
|
||||
}
|
||||
|
||||
public void update(@Nullable String currentRoot, String title)
|
||||
public void update(String title)
|
||||
{
|
||||
boolean search = hasQuery();
|
||||
boolean cancel = MapManager.nativeIsDownloading();
|
||||
|
||||
boolean update = (!search && !cancel);
|
||||
if (update)
|
||||
{
|
||||
UpdateInfo info = MapManager.nativeGetUpdateInfo(currentRoot);
|
||||
update = (info != null && info.filesCount > 0);
|
||||
}
|
||||
|
||||
boolean onTop = !mFragment.getAdapter().canGoUpdwards();
|
||||
|
||||
boolean download = (!search && !cancel && !update && !onTop);
|
||||
if (download)
|
||||
{
|
||||
CountryItem item = CountryItem.fill(currentRoot);
|
||||
download = (item.childCount < item.totalChildCount);
|
||||
}
|
||||
|
||||
UiUtils.showIf(cancel, mCancelAll);
|
||||
UiUtils.showIf(update, mUpdateAll);
|
||||
UiUtils.showIf(download, mDownloadAll);
|
||||
showControls(onTop);
|
||||
|
||||
showControls(!mFragment.getAdapter().canGoUpdwards());
|
||||
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
|
||||
protected int getVoiceInputPrompt()
|
||||
{
|
||||
return R.string.search_map;
|
||||
return R.string.downloader_search_field_hint;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -280,6 +280,11 @@ public final class MapManager
|
|||
*/
|
||||
public static native void nativeGetAttributes(CountryItem item);
|
||||
|
||||
/**
|
||||
* Returns status for given {@code root} node.
|
||||
*/
|
||||
public static native int nativeGetStatus(String root);
|
||||
|
||||
/**
|
||||
* Returns country ID corresponding to given coordinates or {@code null} on error.
|
||||
*/
|
||||
|
|
|
@ -192,6 +192,8 @@ public class SearchToolbarController extends ToolbarController
|
|||
public void showControls(boolean show)
|
||||
{
|
||||
UiUtils.showIf(show, mContainer);
|
||||
if (show)
|
||||
clear();
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
|
|
Loading…
Add table
Reference in a new issue