Improve search layout
This commit is contained in:
6 files changed
+123
-100
No files matched your search
@@ -100,6 +100,7 @@ import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.AppHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.BringOutTransition;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.FabLayout;
|
||||
@@ -558,7 +559,7 @@ public final class GalleryListScene extends BaseScene
|
||||
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
|
||||
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
|
||||
|
||||
mViewTransition = new ViewTransition(contentLayout, mSearchLayout);
|
||||
mViewTransition = new BringOutTransition(contentLayout, mSearchLayout);
|
||||
|
||||
mHelper = new GalleryListHelper();
|
||||
contentLayout.setHelper(mHelper);
|
||||
|
||||
@@ -39,6 +39,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -51,7 +52,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnCheckedChangeListener,
|
||||
View.OnClickListener, ImageSearchLayout.Helper {
|
||||
View.OnClickListener, ImageSearchLayout.Helper, TabLayout.OnTabSelectedListener {
|
||||
|
||||
public static final int SEARCH_MODE_NORMAL = 0;
|
||||
public static final int SEARCH_MODE_IMAGE = 1;
|
||||
@@ -70,6 +71,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
{ITEM_TYPE_IMAGE, ITEM_TYPE_ACTION}, // SEARCH_MODE_IMAGE
|
||||
};
|
||||
private LayoutInflater mInflater;
|
||||
@SearchMode
|
||||
private int mSearchMode = SEARCH_MODE_NORMAL;
|
||||
private boolean mEnableAdvance = false;
|
||||
private View mNormalView;
|
||||
@@ -81,7 +83,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
private AdvanceSearchTable mTableAdvanceSearch;
|
||||
private ImageSearchLayout mImageView;
|
||||
private View mActionView;
|
||||
private TextView mAction;
|
||||
private TabLayout mAction;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private SearchAdapter mAdapter;
|
||||
private Helper mHelper;
|
||||
@@ -137,7 +139,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
// Create action view
|
||||
mActionView = mInflater.inflate(R.layout.search_action, null);
|
||||
mAction = mActionView.findViewById(R.id.action);
|
||||
mAction.setOnClickListener(this);
|
||||
mAction.addOnTabSelectedListener(this);
|
||||
}
|
||||
|
||||
public void setHelper(Helper helper) {
|
||||
@@ -220,6 +222,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
public void formatListUrlBuilder(ListUrlBuilder urlBuilder, String query) throws EhException {
|
||||
urlBuilder.reset();
|
||||
|
||||
@@ -257,26 +260,17 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
}
|
||||
}
|
||||
|
||||
public void setSearchMode(@SearchMode int searchMode, boolean animation) {
|
||||
if (mSearchMode != searchMode) {
|
||||
int oldItemCount = mAdapter.getItemCount();
|
||||
mSearchMode = searchMode;
|
||||
int newItemCount = mAdapter.getItemCount();
|
||||
|
||||
if (animation) {
|
||||
mAdapter.notifyItemRangeRemoved(0, oldItemCount - 1);
|
||||
mAdapter.notifyItemRangeInserted(0, newItemCount - 1);
|
||||
} else {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (mHelper != null) {
|
||||
mHelper.onChangeSearchMode();
|
||||
}
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mNormalSearchModeHelp == v) {
|
||||
new MaterialAlertDialogBuilder(getContext())
|
||||
.setMessage(R.string.search_tip)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleSearchMode() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
int oldItemCount = mAdapter.getItemCount();
|
||||
|
||||
mSearchMode++;
|
||||
@@ -289,18 +283,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
mAdapter.notifyItemRangeRemoved(0, oldItemCount - 1);
|
||||
mAdapter.notifyItemRangeInserted(0, newItemCount - 1);
|
||||
|
||||
// Update action text
|
||||
int resId;
|
||||
switch (mSearchMode) {
|
||||
default:
|
||||
case SEARCH_MODE_NORMAL:
|
||||
resId = R.string.image_search;
|
||||
break;
|
||||
case SEARCH_MODE_IMAGE:
|
||||
resId = R.string.keyword_search;
|
||||
break;
|
||||
}
|
||||
mAction.setText(resId);
|
||||
mSearchMode = tab.getPosition();
|
||||
|
||||
if (mHelper != null) {
|
||||
mHelper.onChangeSearchMode();
|
||||
@@ -308,14 +291,13 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mNormalSearchModeHelp == v) {
|
||||
new MaterialAlertDialogBuilder(getContext())
|
||||
.setMessage(R.string.search_tip)
|
||||
.show();
|
||||
} else if (mAction == v) {
|
||||
toggleSearchMode();
|
||||
}
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
|
||||
@IntDef({SEARCH_MODE_NORMAL, SEARCH_MODE_IMAGE})
|
||||
@@ -329,13 +311,13 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
void onSelectImage();
|
||||
}
|
||||
|
||||
private class SimpleHolder extends RecyclerView.ViewHolder {
|
||||
private static class SimpleHolder extends RecyclerView.ViewHolder {
|
||||
public SimpleHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
private class SearchAdapter extends EasyRecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private class SearchAdapter extends EasyRecyclerView.Adapter<SimpleHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
@@ -355,8 +337,9 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
return type;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public SimpleHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
|
||||
if (viewType == ITEM_TYPE_ACTION) {
|
||||
@@ -364,17 +347,6 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
mActionView.setLayoutParams(new RecyclerView.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
int resId;
|
||||
switch (mSearchMode) {
|
||||
default:
|
||||
case SEARCH_MODE_NORMAL:
|
||||
resId = R.string.image_search;
|
||||
break;
|
||||
case SEARCH_MODE_IMAGE:
|
||||
resId = R.string.keyword_search;
|
||||
break;
|
||||
}
|
||||
mAction.setText(resId);
|
||||
view = mActionView;
|
||||
} else {
|
||||
view = mInflater.inflate(R.layout.search_category, parent, false);
|
||||
@@ -403,8 +375,10 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
// Empty, bind view in create view
|
||||
public void onBindViewHolder(SimpleHolder holder, int position) {
|
||||
if (holder.getItemViewType() == ITEM_TYPE_ACTION) {
|
||||
mAction.selectTab(mAction.getTabAt(mSearchMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* 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.view;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.widget.ContentLayout;
|
||||
|
||||
public class BringOutTransition extends ViewTransition {
|
||||
|
||||
public BringOutTransition(ContentLayout contentLayout, SearchLayout mSearchLayout) {
|
||||
super(contentLayout, mSearchLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startAnimations(final View hiddenView, final View shownView) {
|
||||
mAnimator1 = hiddenView.animate().alpha(0).scaleY(0.7f).scaleX(0.7f);
|
||||
mAnimator1.setDuration(ANIMATE_TIME).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (hiddenView != null) {
|
||||
hiddenView.setVisibility(View.GONE);
|
||||
}
|
||||
mAnimator1 = null;
|
||||
}
|
||||
}).start();
|
||||
|
||||
shownView.setAlpha(0);
|
||||
shownView.setScaleX(0.7f);
|
||||
shownView.setScaleY(0.7f);
|
||||
shownView.setVisibility(View.VISIBLE);
|
||||
mAnimator2 = shownView.animate().alpha(1f).scaleX(1).scaleY(1);
|
||||
mAnimator2.setDuration(ANIMATE_TIME).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAnimator2 = null;
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
@@ -17,21 +17,20 @@
|
||||
package com.hippo.view;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
|
||||
public class ViewTransition {
|
||||
|
||||
private static final long ANIMATE_TIME = 300L;
|
||||
protected static final long ANIMATE_TIME = 300L;
|
||||
|
||||
private final View[] mViews;
|
||||
|
||||
private int mShownView = -1;
|
||||
|
||||
private Animator mAnimator1;
|
||||
private Animator mAnimator2;
|
||||
protected ViewPropertyAnimator mAnimator1;
|
||||
protected ViewPropertyAnimator mAnimator2;
|
||||
|
||||
private OnShowViewListener mOnShowViewListener;
|
||||
|
||||
@@ -82,13 +81,6 @@ public class ViewTransition {
|
||||
}
|
||||
|
||||
if (animation) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (i != oldShownView && i != shownView) {
|
||||
View v = views[i];
|
||||
v.setAlpha(0f);
|
||||
v.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
startAnimations(views[oldShownView], views[shownView]);
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
@@ -113,30 +105,27 @@ public class ViewTransition {
|
||||
}
|
||||
}
|
||||
|
||||
private void startAnimations(final View hiddenView, final View shownView) {
|
||||
ObjectAnimator oa1 = ObjectAnimator.ofFloat(hiddenView, "alpha", 0f);
|
||||
oa1.setDuration(ANIMATE_TIME);
|
||||
oa1.addListener(new SimpleAnimatorListener() {
|
||||
protected void startAnimations(final View hiddenView, final View shownView) {
|
||||
mAnimator1 = hiddenView.animate().alpha(0);
|
||||
mAnimator1.setDuration(ANIMATE_TIME).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
hiddenView.setVisibility(View.GONE);
|
||||
if (hiddenView != null) {
|
||||
hiddenView.setVisibility(View.GONE);
|
||||
}
|
||||
mAnimator1 = null;
|
||||
}
|
||||
});
|
||||
oa1.start();
|
||||
mAnimator1 = oa1;
|
||||
}).start();
|
||||
|
||||
shownView.setAlpha(0);
|
||||
shownView.setVisibility(View.VISIBLE);
|
||||
ObjectAnimator oa2 = ObjectAnimator.ofFloat(shownView, "alpha", 1f);
|
||||
oa2.setDuration(ANIMATE_TIME);
|
||||
oa2.addListener(new SimpleAnimatorListener() {
|
||||
mAnimator2 = shownView.animate().alpha(1);
|
||||
mAnimator2.setDuration(ANIMATE_TIME).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAnimator2 = null;
|
||||
}
|
||||
});
|
||||
oa2.start();
|
||||
mAnimator2 = oa2;
|
||||
}).start();
|
||||
}
|
||||
|
||||
public interface OnShowViewListener {
|
||||
|
||||
Reference in new issue
Block a user