[downloader][android] refactor: Placeholder extracted to separate layout.

This commit is contained in:
Alexander Marchuk 2016-04-18 17:54:39 +03:00
parent 81c6445110
commit 8501f8e896
16 changed files with 143 additions and 110 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

View file

@ -1,43 +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="@drawable/ic_add_place"/>
<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"/>
<LinearLayout
android:id="@+id/bottom_panel"
<include
layout="@layout/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:src="@drawable/ic_add_place"/>
<Button
android:id="@+id/action"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
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"/>
</LinearLayout>
</LinearLayout>
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:layout_above="@id/action"/>
</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

@ -18,6 +18,7 @@ public abstract class BaseMwmRecyclerFragment extends Fragment
{
private Toolbar mToolbar;
private RecyclerView mRecycler;
private View mPlaceholder;
protected abstract RecyclerView.Adapter createAdapter();
@ -64,6 +65,9 @@ public abstract class BaseMwmRecyclerFragment extends Fragment
manager.setSmoothScrollbarEnabled(true);
mRecycler.setLayoutManager(manager);
mRecycler.setAdapter(createAdapter());
mPlaceholder = view.findViewById(R.id.placeholder);
setupPlaceholder(mPlaceholder);
}
public Toolbar getToolbar()
@ -90,4 +94,17 @@ public abstract class BaseMwmRecyclerFragment extends Fragment
super.onPause();
org.alohalytics.Statistics.logEvent("$onPause", this.getClass().getSimpleName());
}
protected void setupPlaceholder(View placeholder) {}
public void setupPlaceholder()
{
setupPlaceholder(mPlaceholder);
}
public void showPlaceholder(boolean show)
{
if (mPlaceholder != null)
UiUtils.showIf(show, mPlaceholder);
}
}

View file

@ -132,6 +132,7 @@ class BottomPanel
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;

View file

@ -622,7 +622,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
}
}
private void refreshData()
void refreshData()
{
mSearchResultsMode = false;
mSearchQuery = null;
@ -678,6 +678,11 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
mHeadersDecoration.invalidateHeaders();
notifyDataSetChanged();
if (mItems.isEmpty())
mFragment.setupPlaceholder();
mFragment.showPlaceholder(mItems.isEmpty());
}
DownloaderAdapter(DownloaderFragment fragment)
@ -687,7 +692,6 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
mRecycler = mFragment.getRecyclerView();
mHeadersDecoration = new StickyRecyclerHeadersDecoration(this);
mRecycler.addItemDecoration(mHeadersDecoration);
refreshData();
}
@Override
@ -732,7 +736,15 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
// 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(childId, childName, mMyMapsMode, position, offset));

View file

@ -16,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
@ -129,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();
@ -201,8 +203,18 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
return mAdapter;
}
@NonNull public String getCurrentRoot()
@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

@ -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

@ -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();