Remove useless stuff in SearchLayout
This commit is contained in:
1 parent
fe7f7529d1
commit
5da51bd984
7 files changed
+165
-373
No files matched your search
@@ -50,7 +50,8 @@ import com.hippo.widget.FloatingActionButton;
|
||||
|
||||
// TODO disable click action when animating
|
||||
public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
View.OnClickListener, FabLayout.OnCancelListener {
|
||||
View.OnClickListener, FabLayout.OnCancelListener,
|
||||
SearchLayout.SearhLayoutHelper {
|
||||
|
||||
private static final long ANIMATE_TIME = 300l;
|
||||
|
||||
@@ -72,7 +73,6 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
private ContentLayout mContentLayout;
|
||||
private RecyclerView mContentRecyclerView;
|
||||
private SearchLayout mSearchLayout;
|
||||
private RecyclerView mSearchRecyclerView;
|
||||
private FabLayout mFabLayout;
|
||||
private FloatingActionButton mCornerFab;
|
||||
private FloatingActionButton mRefreshFab;
|
||||
@@ -105,7 +105,6 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
mContentLayout = (ContentLayout) findViewById(R.id.content_layout);
|
||||
mContentRecyclerView = mContentLayout.getRecyclerView();
|
||||
mSearchLayout = (SearchLayout) findViewById(R.id.search_layout);
|
||||
mSearchRecyclerView = mSearchLayout.getRecyclerView();
|
||||
mFabLayout = (FabLayout) findViewById(R.id.fab_layout);
|
||||
mCornerFab = mFabLayout.getPrimaryFab();
|
||||
AssertUtils.assertEquals("FabLayout in GalleryListScene should contain " +
|
||||
@@ -115,12 +114,12 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
|
||||
mViewTransition = new ViewTransition(mContentLayout, mSearchLayout);
|
||||
|
||||
// Search Bar
|
||||
// Init
|
||||
mSearchBar.setHelper(this);
|
||||
ViewUtils.measureView(mSearchBar, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
SearchBarMoveHelper sbmHelper = new SearchBarMoveHelper();
|
||||
mContentRecyclerView.addOnScrollListener(sbmHelper);
|
||||
mSearchRecyclerView.addOnScrollListener(sbmHelper);
|
||||
mSearchLayout.addOnScrollListener(sbmHelper);
|
||||
mSearchBar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
@@ -130,9 +129,12 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
mSearchLayout.setFitPaddingTop(mSearchBar.getHeight() + mResources.getDimensionPixelOffset(R.dimen.search_bar_padding_vertical));
|
||||
}
|
||||
});
|
||||
mSearchLayout.setHelper(this);
|
||||
|
||||
// Fab Layout
|
||||
mFabLayout.setOnCancelListener(this);
|
||||
|
||||
// Secondary Fab
|
||||
mRefreshFab.setOnClickListener(this);
|
||||
mGoToFab.setOnClickListener(this);
|
||||
|
||||
@@ -304,7 +306,45 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
if (mState == STATE_NORMAL || mState == STATE_SIMPLE_SEARCH) {
|
||||
return mContentRecyclerView;
|
||||
} else {
|
||||
return mSearchRecyclerView;
|
||||
return mSearchLayout;
|
||||
}
|
||||
}
|
||||
|
||||
private void showSearchBar(boolean animation) {
|
||||
// Cancel old animator
|
||||
if (mSearchBarMoveAnimator != null) {
|
||||
mSearchBarMoveAnimator.cancel();
|
||||
}
|
||||
|
||||
int offset = mSearchBarOriginalTop - mSearchBar.getTop();
|
||||
if (offset != 0) {
|
||||
if (animation) {
|
||||
final ValueAnimator va = ValueAnimator.ofInt(0, offset);
|
||||
va.setDuration(ANIMATE_TIME);
|
||||
va.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mSearchBarMoveAnimator = null;
|
||||
}
|
||||
});
|
||||
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
int lastValue;
|
||||
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
int value = (Integer) animation.getAnimatedValue();
|
||||
int offsetStep = value - lastValue;
|
||||
lastValue = value;
|
||||
mSearchBar.offsetTopAndBottom(offsetStep);
|
||||
((OffsetLayout.LayoutParams) mSearchBar.getLayoutParams()).offsetY += offsetStep;
|
||||
}
|
||||
});
|
||||
mSearchBarMoveAnimator = va;
|
||||
va.start();
|
||||
} else {
|
||||
mSearchBar.offsetTopAndBottom(offset);
|
||||
((OffsetLayout.LayoutParams) mSearchBar.getLayoutParams()).offsetY += offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,6 +400,16 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeSearchMode() {
|
||||
showSearchBar(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSelectImage() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private class SearchBarMoveHelper extends RecyclerView.OnScrollListener {
|
||||
|
||||
@Override
|
||||
@@ -382,7 +432,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
|
||||
private boolean isVaildView(RecyclerView view) {
|
||||
return (mState == STATE_NORMAL && view == mContentRecyclerView) ||
|
||||
(mState == STATE_SEARCH && view == mSearchRecyclerView);
|
||||
(mState == STATE_SEARCH && view == mSearchLayout);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.scene.Scene;
|
||||
|
||||
public class SearchScene extends Scene implements SearchLayout.SearhLayoutHelper,
|
||||
Scene.ActivityResultListener{
|
||||
|
||||
private ContentActivity mActivity;
|
||||
private Resources mResources;
|
||||
|
||||
private SearchLayout mSearchLayout;
|
||||
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.scene_search);
|
||||
|
||||
mActivity = (ContentActivity) getStageActivity();
|
||||
mResources = mActivity.getResources();
|
||||
|
||||
mSearchLayout = (SearchLayout) findViewById(R.id.search_layout);
|
||||
|
||||
mSearchLayout.setHelper(this);
|
||||
}
|
||||
|
||||
protected void onGetFitPaddingBottom(int b) {
|
||||
mSearchLayout.setFitPaddingBottom(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSearch(ListUrlBuilder lub) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSelectImage() {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetResult(int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
Uri selectedImage = data.getData();
|
||||
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
||||
|
||||
Cursor cursor = mActivity.getContentResolver().query(selectedImage,
|
||||
filePathColumn, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String imagePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
if (imagePath != null) {
|
||||
mSearchLayout.onSelectImage(imagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,12 @@
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
@@ -37,14 +36,13 @@ import android.widget.TextView;
|
||||
|
||||
import com.hippo.effect.ripple.RippleSalon;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.scene.SimpleDialog;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.FloatLabelEditText;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
import com.hippo.widget.recyclerview.MonoRecyclerView;
|
||||
|
||||
// TODO requst returnSearchBarPosition when content of recycler changed
|
||||
public class SearchLayout extends FrameLayout implements CompoundButton.OnCheckedChangeListener,
|
||||
public class SearchLayout extends MonoRecyclerView implements CompoundButton.OnCheckedChangeListener,
|
||||
View.OnClickListener, SelectSearchImageLayout.SelectSearchImageLayoutHelper {
|
||||
|
||||
private static final String STATE_KEY_SUPER = "super";
|
||||
@@ -52,33 +50,29 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
private static final String STATE_KEY_ENABLE_ADVANCE = "enable_advance";
|
||||
|
||||
private static final int SEARCH_MODE_NORMAL = 0;
|
||||
private static final int SEARCH_MODE_TAG = 1;
|
||||
private static final int SEARCH_MODE_IMAGE = 2;
|
||||
private static final int SEARCH_MODE_IMAGE = 1;
|
||||
|
||||
private static final int ITEM_TYPE_NORMAL = 0;
|
||||
private static final int ITEM_TYPE_NORMAL_ADVANCE = 1;
|
||||
private static final int ITEM_TYPE_TAG = 2;
|
||||
private static final int ITEM_TYPE_IMAGE = 3;
|
||||
private static final int ITEM_TYPE_ACTION = 4;
|
||||
private static final int ITEM_TYPE_IMAGE = 2;
|
||||
private static final int ITEM_TYPE_ACTION = 3;
|
||||
|
||||
private static final int[] SEARCH_ITEM_COUNT_ARRAY = {
|
||||
3, 2, 2
|
||||
3, 2
|
||||
};
|
||||
|
||||
private static final int[][] SEARCH_ITEM_TYPE = {
|
||||
{ITEM_TYPE_NORMAL, ITEM_TYPE_NORMAL_ADVANCE, ITEM_TYPE_ACTION}, // SEARCH_TYPE_NORMAL
|
||||
{ITEM_TYPE_TAG, ITEM_TYPE_ACTION}, // SEARCH_TYPE_TAG
|
||||
{ITEM_TYPE_IMAGE, ITEM_TYPE_ACTION} // SEARCH_TYPE_IMAGE
|
||||
};
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
private int mSearchMode = SEARCH_MODE_NORMAL;
|
||||
private boolean mEnableAdvance = false;
|
||||
|
||||
private EasyRecyclerView mSearchContainer;
|
||||
|
||||
private View mNormalView;
|
||||
private CategoryTable mTableCategory;
|
||||
private CheckBox mCheckSpecifyAuthor;
|
||||
@@ -89,9 +83,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
private View mAdvanceView;
|
||||
private AdvanceSearchTable mTableAdvanceSearch;
|
||||
|
||||
private FloatLabelEditText mEditTextTag;
|
||||
|
||||
private SelectSearchImageLayout mImageView;
|
||||
private SelectSearchImageLayout mImageSearchView;
|
||||
|
||||
private View mActionView;
|
||||
private TextView mAction1;
|
||||
@@ -101,22 +93,11 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
private SearchAdapter mAdapter;
|
||||
private SearchItemAnimator mAnimator;
|
||||
|
||||
private SparseArray<Parcelable> mSavedInstanceState;
|
||||
|
||||
private SearhLayoutHelper mHelper;
|
||||
|
||||
private ListUrlBuilder mTempListUrlBuilder = new ListUrlBuilder();
|
||||
|
||||
private Bitmap mSearchImage;
|
||||
|
||||
private int mSearchPaddingTopOrigin;
|
||||
private int mSearchPaddingBottomOrigin;
|
||||
|
||||
public SearchLayout(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public SearchLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
@@ -127,50 +108,71 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
init(context);
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private void init(Context context) {
|
||||
mContext = context;
|
||||
mResources = mContext.getResources();
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.widget_search_layout, this);
|
||||
|
||||
mSearchContainer = (EasyRecyclerView) getChildAt(0);
|
||||
mInflater = LayoutInflater.from(mContext);
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(mContext);
|
||||
mAdapter = new SearchAdapter();
|
||||
mAnimator = new SearchItemAnimator(mSearchContainer);
|
||||
mSearchContainer.setLayoutManager(mLayoutManager);
|
||||
mSearchContainer.setAdapter(mAdapter);
|
||||
mSearchContainer.setHasFixedSize(true);
|
||||
mSearchContainer.setItemAnimator(mAnimator);
|
||||
mAnimator = new SearchItemAnimator(this);
|
||||
setLayoutManager(mLayoutManager);
|
||||
setAdapter(mAdapter);
|
||||
setHasFixedSize(true);
|
||||
setItemAnimator(mAnimator);
|
||||
|
||||
// Search Container
|
||||
mSearchPaddingTopOrigin = mSearchContainer.getPaddingTop();
|
||||
mSearchPaddingTopOrigin = getPaddingTop();
|
||||
// Original padding bottom and the padding bottom to make it above fab
|
||||
mSearchPaddingBottomOrigin = mSearchContainer.getPaddingBottom() +
|
||||
mSearchPaddingBottomOrigin = getPaddingBottom() +
|
||||
mResources.getDimensionPixelSize(R.dimen.content_padding_bottom);
|
||||
mSearchContainer.setPadding( mSearchContainer.getPaddingLeft(),
|
||||
mSearchContainer.getPaddingTop(),
|
||||
mSearchContainer.getPaddingRight(),
|
||||
mSearchPaddingBottomOrigin);
|
||||
}
|
||||
setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), mSearchPaddingBottomOrigin);
|
||||
|
||||
public EasyRecyclerView getRecyclerView() {
|
||||
return mSearchContainer;
|
||||
// Create normal view
|
||||
mNormalView = mInflater.inflate(R.layout.search_normal, null);
|
||||
mTableCategory = (CategoryTable) mNormalView.findViewById(R.id.search_category_table);
|
||||
mCheckSpecifyAuthor = (CheckBox) mNormalView.findViewById(R.id.search_specify_author);
|
||||
mCheckSpecifyTag = (CheckBox) mNormalView.findViewById(R.id.search_specify_tag);
|
||||
mSearchTagHelp = mNormalView.findViewById(R.id.search_tag_help);
|
||||
mSwitchEnableAdvance = (SwitchCompat) mNormalView.findViewById(R.id.search_enable_advance);
|
||||
|
||||
// Init normal view
|
||||
mCheckSpecifyAuthor.setOnCheckedChangeListener(SearchLayout.this);
|
||||
mSearchTagHelp.setOnClickListener(SearchLayout.this);
|
||||
mSwitchEnableAdvance.setOnCheckedChangeListener(SearchLayout.this);
|
||||
mSwitchEnableAdvance.setSwitchPadding(mResources.getDimensionPixelSize(R.dimen.switch_padding));
|
||||
|
||||
// Create advance view
|
||||
mAdvanceView = mInflater.inflate(R.layout.search_advance, null);
|
||||
mTableAdvanceSearch = (AdvanceSearchTable) mAdvanceView.findViewById(R.id.search_advance_search_table);
|
||||
|
||||
// Create image search view
|
||||
mImageSearchView = (SelectSearchImageLayout) mInflater.inflate(R.layout.search_image, null);
|
||||
|
||||
// Init image search view
|
||||
mImageSearchView.setHelper(SearchLayout.this);
|
||||
|
||||
// Create action view
|
||||
mActionView = mInflater.inflate(R.layout.search_action, null);
|
||||
mAction1 = (TextView) mActionView.findViewById(R.id.search_action_1);
|
||||
mAction2 = (TextView) mActionView.findViewById(R.id.search_action_2);
|
||||
|
||||
// Init action view
|
||||
mAction1.setText(mContext.getString(R.string.search_add));
|
||||
mAction2.setText(mContext.getString(R.string.search_mode));
|
||||
RippleSalon.addRipple(mAction1, false);
|
||||
RippleSalon.addRipple(mAction2, false);
|
||||
mAction1.setOnClickListener(SearchLayout.this);
|
||||
mAction2.setOnClickListener(SearchLayout.this);
|
||||
}
|
||||
|
||||
public void setFitPaddingTop(int fitPaddingTop) {
|
||||
mSearchContainer.setPadding(
|
||||
mSearchContainer.getPaddingLeft(),
|
||||
mSearchPaddingTopOrigin + fitPaddingTop,
|
||||
mSearchContainer.getPaddingRight(),
|
||||
mSearchContainer.getPaddingBottom());
|
||||
setPadding(getPaddingLeft(), mSearchPaddingTopOrigin + fitPaddingTop, getPaddingRight(), getPaddingBottom());
|
||||
}
|
||||
|
||||
public void setFitPaddingBottom(int fitPaddingBottom) {
|
||||
mSearchContainer.setPadding(
|
||||
mSearchContainer.getPaddingLeft(),
|
||||
mSearchContainer.getPaddingTop(),
|
||||
mSearchContainer.getPaddingRight(),
|
||||
setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
|
||||
mSearchPaddingBottomOrigin + fitPaddingBottom
|
||||
);
|
||||
}
|
||||
@@ -187,14 +189,20 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
protected void dispatchSaveInstanceState(@NonNull SparseArray<Parcelable> container) {
|
||||
super.dispatchSaveInstanceState(container);
|
||||
|
||||
mSavedInstanceState = null;
|
||||
mNormalView.saveHierarchyState(container);
|
||||
mAdvanceView.saveHierarchyState(container);
|
||||
mImageSearchView.saveHierarchyState(container);
|
||||
mActionView.saveHierarchyState(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchRestoreInstanceState(@NonNull SparseArray<Parcelable> container) {
|
||||
super.dispatchRestoreInstanceState(container);
|
||||
|
||||
mSavedInstanceState = container;
|
||||
mNormalView.restoreHierarchyState(container);
|
||||
mAdvanceView.restoreHierarchyState(container);
|
||||
mImageSearchView.restoreHierarchyState(container);
|
||||
mActionView.restoreHierarchyState(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,7 +241,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
}
|
||||
}
|
||||
|
||||
private void taggleSearchMode() {
|
||||
private void toggleSearchMode() {
|
||||
int oldItemCount = mAdapter.getItemCount();
|
||||
|
||||
mSearchMode++;
|
||||
@@ -245,6 +253,10 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
|
||||
mAdapter.notifyItemRangeRemoved(0, oldItemCount - 1);
|
||||
mAdapter.notifyItemRangeInserted(0, newItemCount - 1);
|
||||
|
||||
if (mHelper != null) {
|
||||
mHelper.onChangeSearchMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,7 +264,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
if (v == mAction1) {
|
||||
// TODO add quick search
|
||||
} else if (v == mAction2) {
|
||||
taggleSearchMode();
|
||||
toggleSearchMode();
|
||||
} else if (v == mSearchTagHelp) {
|
||||
int[] location = new int [2];
|
||||
ViewUtils.getLocationInAncestor(mSearchTagHelp, location, R.id.stage);
|
||||
@@ -264,7 +276,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
}
|
||||
|
||||
public void onSelectImage(@NonNull String imagePath) {
|
||||
mImageView.onSelectImage(imagePath);
|
||||
mImageSearchView.onSelectImage(imagePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,76 +286,14 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
}
|
||||
}
|
||||
|
||||
public ListUrlBuilder getListUrlBuilder(@Nullable ListUrlBuilder lub) {
|
||||
if (lub == null) {
|
||||
lub = mTempListUrlBuilder;
|
||||
}
|
||||
|
||||
switch (mSearchMode) {
|
||||
default:
|
||||
case SEARCH_MODE_NORMAL:
|
||||
lub.setMode(ListUrlBuilder.MODE_NORMAL);
|
||||
if (mTableCategory != null) {
|
||||
lub.setCategory(mTableCategory.getCategory());
|
||||
}
|
||||
// TODO
|
||||
if (mSwitchEnableAdvance.isChecked() && mTableAdvanceSearch != null) {
|
||||
lub.setAdvanceSearch(mTableAdvanceSearch.getAdvanceSearch());
|
||||
lub.setMinRating(mTableAdvanceSearch.getMinRating());
|
||||
} else {
|
||||
lub.setAdvanceSearch(-1);
|
||||
lub.setMinRating(-1);
|
||||
}
|
||||
break;
|
||||
case SEARCH_MODE_TAG:
|
||||
lub.setMode(ListUrlBuilder.MODE_TAG);
|
||||
if (mEditTextTag != null) {
|
||||
lub.setSearchTag(mEditTextTag.getText().toString());
|
||||
}
|
||||
break;
|
||||
case SEARCH_MODE_IMAGE:
|
||||
lub.setMode(ListUrlBuilder.MODE_IMAGE_SEARCH);
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
|
||||
return lub;
|
||||
}
|
||||
|
||||
private class SearchHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView title;
|
||||
public FrameLayout content;
|
||||
|
||||
public SearchHolder(View itemView) {
|
||||
private class SimpleHolder extends RecyclerView.ViewHolder {
|
||||
public SimpleHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
title = (TextView) itemView.findViewById(R.id.category_title);
|
||||
content = (FrameLayout) itemView.findViewById(R.id.category_content);
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView action1;
|
||||
private TextView action2;
|
||||
|
||||
public ActionHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
action1 = (TextView) itemView.findViewById(R.id.search_action_1);
|
||||
action2 = (TextView) itemView.findViewById(R.id.search_action_2);
|
||||
}
|
||||
}
|
||||
|
||||
private class SearchAdapter extends EasyRecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
LayoutInflater mInflater;
|
||||
|
||||
public SearchAdapter() {
|
||||
mInflater = LayoutInflater.from(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int count = SEARCH_ITEM_COUNT_ARRAY[mSearchMode];
|
||||
@@ -364,134 +314,38 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
RecyclerView.ViewHolder holder;
|
||||
View view;
|
||||
|
||||
if (viewType == ITEM_TYPE_ACTION) {
|
||||
View view = mInflater.inflate(R.layout.search_action, parent, false);
|
||||
holder = new ActionHolder(view);
|
||||
bindActionView((ActionHolder) holder);
|
||||
ViewUtils.removeFromParent(mActionView);
|
||||
mActionView.setLayoutParams(new RecyclerView.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
view = mActionView;
|
||||
} else {
|
||||
View view = mInflater.inflate(R.layout.search_category, parent, false);
|
||||
holder = new SearchHolder(view);
|
||||
view = mInflater.inflate(R.layout.search_category, parent, false);
|
||||
TextView title = (TextView) view.findViewById(R.id.category_title);
|
||||
FrameLayout content = (FrameLayout) view.findViewById(R.id.category_content);
|
||||
switch (viewType) {
|
||||
case ITEM_TYPE_NORMAL:{
|
||||
bindNormalView((SearchHolder) holder);
|
||||
case ITEM_TYPE_NORMAL:
|
||||
title.setText(R.string.search_normal);
|
||||
ViewUtils.removeFromParent(mNormalView);
|
||||
content.addView(mNormalView);
|
||||
break;
|
||||
}
|
||||
case ITEM_TYPE_NORMAL_ADVANCE: {
|
||||
bindAdvanceView((SearchHolder) holder);
|
||||
case ITEM_TYPE_NORMAL_ADVANCE:
|
||||
title.setText(R.string.search_advance);
|
||||
ViewUtils.removeFromParent(mAdvanceView);
|
||||
content.addView(mAdvanceView);
|
||||
break;
|
||||
}
|
||||
case ITEM_TYPE_TAG: {
|
||||
bindTagView((SearchHolder) holder);
|
||||
case ITEM_TYPE_IMAGE:
|
||||
title.setText(R.string.search_image);
|
||||
ViewUtils.removeFromParent(mImageSearchView);
|
||||
content.addView(mImageSearchView);
|
||||
break;
|
||||
}
|
||||
case ITEM_TYPE_IMAGE: {
|
||||
bindImageView((SearchHolder) holder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
private void bindNormalView(SearchHolder holder) {
|
||||
holder.title.setText(R.string.search_normal);
|
||||
|
||||
if (mNormalView == null) {
|
||||
mInflater.inflate(R.layout.search_normal, holder.content);
|
||||
mNormalView = holder.content.getChildAt(0);
|
||||
mTableCategory = (CategoryTable) mNormalView.findViewById(R.id.search_category_table);
|
||||
mCheckSpecifyAuthor = (CheckBox) mNormalView.findViewById(R.id.search_specify_author);
|
||||
mCheckSpecifyTag = (CheckBox) mNormalView.findViewById(R.id.search_specify_tag);
|
||||
mSearchTagHelp = mNormalView.findViewById(R.id.search_tag_help);
|
||||
mSwitchEnableAdvance = (SwitchCompat) mNormalView.findViewById(R.id.search_enable_advance);
|
||||
|
||||
// Restore state
|
||||
if (mSavedInstanceState != null) {
|
||||
holder.content.restoreHierarchyState(mSavedInstanceState);
|
||||
}
|
||||
|
||||
mCheckSpecifyAuthor.setOnCheckedChangeListener(SearchLayout.this);
|
||||
mSearchTagHelp.setOnClickListener(SearchLayout.this);
|
||||
mSwitchEnableAdvance.setOnCheckedChangeListener(SearchLayout.this);
|
||||
mSwitchEnableAdvance.setSwitchPadding(mResources.getDimensionPixelSize(R.dimen.switch_padding));
|
||||
} else {
|
||||
ViewUtils.removeFromParent(mNormalView);
|
||||
holder.content.removeAllViews();
|
||||
holder.content.addView(mNormalView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void bindAdvanceView(SearchHolder holder) {
|
||||
holder.title.setText(R.string.search_advance);
|
||||
|
||||
if (mAdvanceView == null) {
|
||||
mInflater.inflate(R.layout.search_advance, holder.content);
|
||||
mAdvanceView = holder.content.getChildAt(0);
|
||||
mTableAdvanceSearch = (AdvanceSearchTable) mAdvanceView.findViewById(R.id.search_advance_search_table);
|
||||
|
||||
// Restore state
|
||||
if (mSavedInstanceState != null) {
|
||||
holder.content.restoreHierarchyState(mSavedInstanceState);
|
||||
}
|
||||
|
||||
} else {
|
||||
ViewUtils.removeFromParent(mAdvanceView);
|
||||
holder.content.addView(mAdvanceView);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindTagView(SearchHolder holder) {
|
||||
holder.title.setText(R.string.search_tag);
|
||||
|
||||
if (mEditTextTag == null) {
|
||||
mInflater.inflate(R.layout.search_tag, holder.content);
|
||||
mEditTextTag = (FloatLabelEditText) holder.content.getChildAt(0);
|
||||
|
||||
// Restore state
|
||||
if (mSavedInstanceState != null) {
|
||||
holder.content.restoreHierarchyState(mSavedInstanceState);
|
||||
}
|
||||
} else {
|
||||
ViewUtils.removeFromParent(mEditTextTag);
|
||||
holder.content.addView(mEditTextTag);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindImageView(SearchHolder holder) {
|
||||
holder.title.setText(R.string.search_image);
|
||||
|
||||
if (mImageView == null) {
|
||||
mInflater.inflate(R.layout.search_image, holder.content);
|
||||
mImageView = (SelectSearchImageLayout) holder.content.getChildAt(0);
|
||||
|
||||
// Restore state
|
||||
if (mSavedInstanceState != null) {
|
||||
holder.content.restoreHierarchyState(mSavedInstanceState);
|
||||
}
|
||||
|
||||
mImageView.setHelper(SearchLayout.this);
|
||||
} else {
|
||||
ViewUtils.removeFromParent(mImageView);
|
||||
holder.content.addView(mImageView);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindActionView(ActionHolder holder) {
|
||||
mActionView = holder.itemView;
|
||||
mAction1 = holder.action1;
|
||||
mAction2 = holder.action2;
|
||||
|
||||
mAction1.setText(mContext.getString(R.string.search_add));
|
||||
mAction2.setText(mContext.getString(R.string.search_mode));
|
||||
RippleSalon.addRipple(mAction1, false);
|
||||
RippleSalon.addRipple(mAction2, false);
|
||||
|
||||
mAction1.setOnClickListener(SearchLayout.this);
|
||||
mAction2.setOnClickListener(SearchLayout.this);
|
||||
return new SimpleHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -501,8 +355,8 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
}
|
||||
|
||||
public interface SearhLayoutHelper {
|
||||
void onRequestSelectImage();
|
||||
void onChangeSearchMode();
|
||||
|
||||
void onRequestSearch(ListUrlBuilder lub);
|
||||
void onRequestSelectImage();
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,6 @@ public class SelectSearchImageLayout extends LinearLayout implements View.OnClic
|
||||
}
|
||||
|
||||
public interface SelectSearchImageLayoutHelper {
|
||||
public void onRequstSelectImage();
|
||||
void onRequstSelectImage();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user