pref: 修改搜索、搜吧界面 UI
This commit is contained in:
parent
7a2ec910f8
commit
80bc8db302
|
|
@ -0,0 +1,4 @@
|
|||
package com.huanchengfly.tieba.post.activities
|
||||
|
||||
class NewSearchActivity {
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package com.huanchengfly.tieba.post.adapters;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import com.huanchengfly.tieba.post.api.models.SearchForumBean;
|
||||
import com.huanchengfly.tieba.post.R;
|
||||
import com.huanchengfly.tieba.post.utils.ImageUtil;
|
||||
import com.huanchengfly.tieba.post.utils.NavigationHelper;
|
||||
import com.othershe.baseadapter.ViewHolder;
|
||||
import com.othershe.baseadapter.base.MultiBaseAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchForumAdapter extends MultiBaseAdapter<SearchForumBean.ForumInfoBean> {
|
||||
public static final int TYPE_EXACT = 0;
|
||||
public static final int TYPE_FUZZY = 1;
|
||||
private NavigationHelper navigationHelper;
|
||||
|
||||
public SearchForumAdapter(Context context) {
|
||||
super(context, null, true);
|
||||
navigationHelper = NavigationHelper.newInstance(context);
|
||||
}
|
||||
|
||||
public void setData(SearchForumBean.DataBean data) {
|
||||
List<SearchForumBean.ForumInfoBean> forumInfoBeans = new ArrayList<>();
|
||||
if (data.getExactMatch() != null && data.getExactMatch().getForumNameShow() != null) {
|
||||
forumInfoBeans.add(data.getExactMatch());
|
||||
}
|
||||
forumInfoBeans.addAll(data.getFuzzyMatch());
|
||||
setNewData(forumInfoBeans);
|
||||
}
|
||||
|
||||
private boolean canLoadGlide() {
|
||||
if (mContext instanceof Activity) {
|
||||
return !((Activity) mContext).isDestroyed();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(ViewHolder viewHolder, SearchForumBean.ForumInfoBean forumInfoBean, int position, int type) {
|
||||
viewHolder.setText(R.id.item_search_forum_title, forumInfoBean.getForumNameShow() + "吧");
|
||||
viewHolder.setOnClickListener(R.id.item_search_forum, (view) -> {
|
||||
navigationHelper.navigationByData(NavigationHelper.ACTION_FORUM, forumInfoBean.getForumName());
|
||||
});
|
||||
ImageUtil.load(viewHolder.getView(R.id.item_search_forum_avatar), ImageUtil.LOAD_TYPE_AVATAR, forumInfoBean.getAvatar());
|
||||
if (type == TYPE_EXACT) {
|
||||
SearchForumBean.ExactForumInfoBean exactForumInfoBean = (SearchForumBean.ExactForumInfoBean) forumInfoBean;
|
||||
viewHolder.setText(R.id.item_search_forum_subtitle, exactForumInfoBean.getSlogan());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemLayoutId(int type) {
|
||||
if (type == TYPE_EXACT) {
|
||||
return R.layout.item_search_forum_exact;
|
||||
}
|
||||
return R.layout.item_search_forum;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getViewType(int i, SearchForumBean.ForumInfoBean forumInfoBean) {
|
||||
if (forumInfoBean instanceof SearchForumBean.ExactForumInfoBean) {
|
||||
return TYPE_EXACT;
|
||||
}
|
||||
return TYPE_FUZZY;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.huanchengfly.tieba.post.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
|
||||
import com.huanchengfly.tieba.post.R
|
||||
import com.huanchengfly.tieba.post.adapters.base.BaseMultiTypeDelegateAdapter
|
||||
import com.huanchengfly.tieba.post.api.models.SearchForumBean
|
||||
import com.huanchengfly.tieba.post.api.models.SearchForumBean.ExactForumInfoBean
|
||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||
import com.huanchengfly.tieba.post.utils.ImageUtil
|
||||
import com.huanchengfly.tieba.post.utils.NavigationHelper
|
||||
import java.util.*
|
||||
|
||||
class SearchForumAdapter(context: Context?) : BaseMultiTypeDelegateAdapter<SearchForumBean.ForumInfoBean?>(context!!, LinearLayoutHelper()) {
|
||||
private val navigationHelper: NavigationHelper
|
||||
fun setData(data: SearchForumBean.DataBean) {
|
||||
val forumInfoBeans: MutableList<SearchForumBean.ForumInfoBean?> = ArrayList()
|
||||
if (data.exactMatch != null && data.exactMatch.forumNameShow != null) {
|
||||
forumInfoBeans.add(data.exactMatch)
|
||||
}
|
||||
forumInfoBeans.addAll(data.fuzzyMatch!!)
|
||||
setData(forumInfoBeans)
|
||||
}
|
||||
|
||||
protected override fun convert(viewHolder: MyViewHolder, forumInfoBean: SearchForumBean.ForumInfoBean, position: Int, type: Int) {
|
||||
viewHolder.setText(R.id.item_search_forum_title, forumInfoBean.forumNameShow + "吧")
|
||||
viewHolder.setOnClickListener(R.id.item_search_forum) { view: View? -> navigationHelper.navigationByData(NavigationHelper.ACTION_FORUM, forumInfoBean.forumName) }
|
||||
ImageUtil.load(viewHolder.getView(R.id.item_search_forum_avatar), ImageUtil.LOAD_TYPE_AVATAR, forumInfoBean.avatar)
|
||||
if (type == TYPE_EXACT) {
|
||||
val exactForumInfoBean = forumInfoBean as ExactForumInfoBean
|
||||
viewHolder.setText(R.id.item_search_forum_subtitle, exactForumInfoBean.slogan)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemLayoutId(type: Int): Int {
|
||||
return if (type == TYPE_EXACT) {
|
||||
R.layout.item_search_forum_exact
|
||||
} else R.layout.item_search_forum
|
||||
}
|
||||
|
||||
protected override fun getViewType(i: Int, forumInfoBean: SearchForumBean.ForumInfoBean): Int {
|
||||
return if (forumInfoBean is ExactForumInfoBean) {
|
||||
TYPE_EXACT
|
||||
} else TYPE_FUZZY
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TYPE_EXACT = 0
|
||||
const val TYPE_FUZZY = 1
|
||||
}
|
||||
|
||||
init {
|
||||
navigationHelper = NavigationHelper.newInstance(context)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.huanchengfly.tieba.post.adapters
|
||||
|
||||
import android.content.Context
|
||||
import com.huanchengfly.tieba.post.adapters.base.BaseSingleTypeAdapter
|
||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||
import com.huanchengfly.tieba.post.models.database.SearchHistory
|
||||
|
||||
class SearchHistoryAdapter(context: Context) : BaseSingleTypeAdapter<SearchHistory?>(context) {
|
||||
override fun getItemLayoutId(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
protected override fun convert(viewHolder: MyViewHolder, searchHistory: SearchHistory, position: Int) {}
|
||||
}
|
||||
|
|
@ -1,35 +1,50 @@
|
|||
package com.huanchengfly.tieba.post.adapters;
|
||||
package com.huanchengfly.tieba.post.adapters
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.View;
|
||||
import android.text.format.DateUtils
|
||||
import android.view.View
|
||||
import com.huanchengfly.tieba.post.R
|
||||
import com.huanchengfly.tieba.post.adapters.base.BaseSingleTypeAdapter
|
||||
import com.huanchengfly.tieba.post.api.models.SearchThreadBean
|
||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||
import com.huanchengfly.tieba.post.fragments.SearchThreadFragment
|
||||
import com.huanchengfly.tieba.post.utils.NavigationHelper
|
||||
import java.util.*
|
||||
|
||||
import com.allen.library.SuperTextView;
|
||||
import com.huanchengfly.tieba.post.api.SearchThreadFilter;
|
||||
import com.huanchengfly.tieba.post.api.SearchThreadOrder;
|
||||
import com.huanchengfly.tieba.post.api.models.SearchThreadBean;
|
||||
import com.huanchengfly.tieba.post.R;
|
||||
import com.huanchengfly.tieba.post.components.dialogs.SingleChooseDialog;
|
||||
import com.huanchengfly.tieba.post.fragments.SearchThreadFragment;
|
||||
import com.huanchengfly.tieba.post.utils.NavigationHelper;
|
||||
import com.huanchengfly.tieba.post.utils.Util;
|
||||
import com.othershe.baseadapter.ViewHolder;
|
||||
import com.othershe.baseadapter.base.CommonBaseAdapter;
|
||||
class SearchThreadAdapter(fragment: SearchThreadFragment) : BaseSingleTypeAdapter<SearchThreadBean.ThreadInfoBean?>(fragment.requireContext()) {
|
||||
private val navigationHelper: NavigationHelper
|
||||
private val order = 0
|
||||
private val filter = 0
|
||||
protected override fun convert(viewHolder: MyViewHolder, threadInfoBean: SearchThreadBean.ThreadInfoBean, position: Int) {
|
||||
viewHolder.setOnClickListener(R.id.item_search_thread) { view: View? ->
|
||||
val map: MutableMap<String, String?> = HashMap()
|
||||
map["tid"] = threadInfoBean.tid
|
||||
map["pid"] = threadInfoBean.pid
|
||||
navigationHelper.navigationByData(NavigationHelper.ACTION_THREAD, map)
|
||||
}
|
||||
viewHolder.setText(R.id.item_search_thread_title, threadInfoBean.title)
|
||||
viewHolder.setText(R.id.item_search_thread_content, threadInfoBean.content)
|
||||
viewHolder.setText(R.id.item_search_thread_user, threadInfoBean.user!!.userName)
|
||||
if (threadInfoBean.forumName == null) {
|
||||
viewHolder.setText(
|
||||
R.id.item_search_thread_info,
|
||||
DateUtils.getRelativeTimeSpanString(threadInfoBean.time!!.toLong() * 1000L)
|
||||
)
|
||||
} else {
|
||||
viewHolder.setText(
|
||||
R.id.item_search_thread_info,
|
||||
threadInfoBean.forumName + " " + DateUtils.getRelativeTimeSpanString(threadInfoBean.time!!.toLong() * 1000L)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
override fun getItemLayoutId(): Int {
|
||||
return R.layout.item_search_thread
|
||||
}
|
||||
|
||||
public class SearchThreadAdapter extends CommonBaseAdapter<SearchThreadBean.ThreadInfoBean> {
|
||||
private NavigationHelper navigationHelper;
|
||||
private int order;
|
||||
private int filter;
|
||||
|
||||
public SearchThreadAdapter(SearchThreadFragment fragment) {
|
||||
super(fragment.getContext(), null, true);
|
||||
order = 0;
|
||||
filter = 0;
|
||||
Context context = fragment.getContext();
|
||||
navigationHelper = NavigationHelper.newInstance(context);
|
||||
init {
|
||||
val context = fragment.requireContext()
|
||||
navigationHelper = NavigationHelper.newInstance(context)
|
||||
/*
|
||||
View headerView = Util.inflate(context, R.layout.layout_search_header);
|
||||
if (headerView != null) {
|
||||
SuperTextView orderTextView = headerView.findViewById(R.id.search_order);
|
||||
|
|
@ -73,28 +88,6 @@ public class SearchThreadAdapter extends CommonBaseAdapter<SearchThreadBean.Thre
|
|||
});
|
||||
addHeaderView(headerView);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(ViewHolder viewHolder, SearchThreadBean.ThreadInfoBean threadInfoBean, int position) {
|
||||
viewHolder.setOnClickListener(R.id.item_search_thread, (view) -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("tid", threadInfoBean.getTid());
|
||||
map.put("pid", threadInfoBean.getPid());
|
||||
navigationHelper.navigationByData(NavigationHelper.ACTION_THREAD, map);
|
||||
});
|
||||
viewHolder.setText(R.id.item_search_thread_title, threadInfoBean.getTitle());
|
||||
viewHolder.setText(R.id.item_search_thread_content, threadInfoBean.getContent());
|
||||
viewHolder.setText(R.id.item_search_thread_user, threadInfoBean.getUser().getUserName());
|
||||
if (threadInfoBean.getForumName() == null) {
|
||||
viewHolder.setText(R.id.item_search_thread_info, String.valueOf(DateUtils.getRelativeTimeSpanString(Long.valueOf(threadInfoBean.getTime()) * 1000L)));
|
||||
} else {
|
||||
viewHolder.setText(R.id.item_search_thread_info, threadInfoBean.getForumName() + " " + DateUtils.getRelativeTimeSpanString(Long.valueOf(threadInfoBean.getTime()) * 1000L));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemLayoutId() {
|
||||
return R.layout.item_search_thread;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.huanchengfly.tieba.post.adapters.base
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import com.alibaba.android.vlayout.DelegateAdapter
|
||||
import com.alibaba.android.vlayout.LayoutHelper
|
||||
import com.alibaba.android.vlayout.layout.SingleLayoutHelper
|
||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||
|
||||
abstract class BaseSingleLayoutAdapter(
|
||||
val context: Context,
|
||||
val itemView: View
|
||||
) : DelegateAdapter.Adapter<MyViewHolder>() {
|
||||
constructor(
|
||||
context: Context,
|
||||
@LayoutRes
|
||||
layoutResId: Int
|
||||
) : this(
|
||||
context,
|
||||
View.inflate(context, layoutResId, null)
|
||||
)
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
createViewFunction: () -> View
|
||||
) : this(
|
||||
context,
|
||||
createViewFunction()
|
||||
)
|
||||
|
||||
final override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder = MyViewHolder(itemView)
|
||||
|
||||
final override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||
convert(holder, itemView)
|
||||
}
|
||||
|
||||
final override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onCreateLayoutHelper(): LayoutHelper = SingleLayoutHelper()
|
||||
|
||||
abstract fun convert(holder: MyViewHolder, itemView: View)
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
package com.huanchengfly.tieba.post.adapters.base
|
||||
|
||||
import android.content.Context
|
||||
import com.alibaba.android.vlayout.DelegateAdapter
|
||||
import com.alibaba.android.vlayout.LayoutHelper
|
||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||
|
||||
abstract class BaseDelegateAdapter<Item>(
|
||||
val context: Context,
|
||||
val layoutHelper: LayoutHelper,
|
||||
items: List<Item>? = null
|
||||
) : DelegateAdapter.Adapter<MyViewHolder>() {
|
||||
private var itemList: MutableList<Item> = (items ?: emptyList()).toMutableList()
|
||||
|
||||
var onItemClickListener: OnItemClickListener<Item>? = null
|
||||
private set
|
||||
|
||||
var onItemLongClickListener: OnItemLongClickListener<Item>? = null
|
||||
private set
|
||||
|
||||
fun setOnItemClickListener(listener: OnItemClickListener<Item>?) {
|
||||
onItemClickListener = listener
|
||||
}
|
||||
|
||||
fun setOnItemClickListener(listener: ((viewHolder: MyViewHolder, item: Item, position: Int) -> Unit)?) {
|
||||
onItemClickListener = object : OnItemClickListener<Item> {
|
||||
override fun onClick(viewHolder: MyViewHolder, item: Item, position: Int) {
|
||||
if (listener != null) {
|
||||
listener(viewHolder, item, position)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnItemLongClickListener(listener: OnItemLongClickListener<Item>?) {
|
||||
onItemLongClickListener = listener
|
||||
}
|
||||
|
||||
fun setOnItemLongClickListener(listener: ((viewHolder: MyViewHolder, item: Item, position: Int) -> Boolean)?) {
|
||||
onItemLongClickListener = object : OnItemLongClickListener<Item> {
|
||||
override fun onLongClick(viewHolder: MyViewHolder, item: Item, position: Int): Boolean {
|
||||
if (listener != null) {
|
||||
return listener(viewHolder, item, position)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = getCount()
|
||||
|
||||
override fun onCreateLayoutHelper(): LayoutHelper = layoutHelper
|
||||
|
||||
fun getItem(position: Int): Item = itemList[position]
|
||||
|
||||
fun getItemList(): MutableList<Item> = itemList
|
||||
|
||||
fun getCount() = itemList.size
|
||||
|
||||
fun setData(items: List<Item>?) {
|
||||
itemList.clear()
|
||||
itemList.addAll(items ?: emptyList())
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
open fun remove(position: Int) {
|
||||
if (position < itemList.size && position >= 0) {
|
||||
itemList.removeAt(position)
|
||||
notifyItemRemoved(position)
|
||||
if (position != itemList.size) {
|
||||
this.notifyItemRangeChanged(position, itemList.size - position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open fun insert(items: List<Item>, position: Int) {
|
||||
if (position <= itemList.size && position >= 0) {
|
||||
itemList.addAll(position, items)
|
||||
notifyItemRangeInserted(position, items.size)
|
||||
this.notifyItemRangeChanged(position, itemList.size - position)
|
||||
}
|
||||
}
|
||||
|
||||
open fun insert(items: List<Item>) {
|
||||
insert(items, itemList.size)
|
||||
}
|
||||
|
||||
open fun insert(data: Item, position: Int) {
|
||||
if (position <= itemList.size && position >= 0) {
|
||||
itemList.add(position, data)
|
||||
notifyItemInserted(position)
|
||||
this.notifyItemRangeChanged(position, itemList.size - position)
|
||||
}
|
||||
}
|
||||
|
||||
open fun insert(data: Item) {
|
||||
this.insert(data, itemList.size)
|
||||
}
|
||||
|
||||
open fun reset() {
|
||||
itemList.clear()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
interface OnItemClickListener<Item> {
|
||||
fun onClick(viewHolder: MyViewHolder, item: Item, position: Int)
|
||||
}
|
||||
|
||||
interface OnItemLongClickListener<Item> {
|
||||
fun onLongClick(viewHolder: MyViewHolder, item: Item, position: Int): Boolean
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.huanchengfly.tieba.post.adapters.base
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.alibaba.android.vlayout.LayoutHelper
|
||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||
|
||||
abstract class BaseMultiTypeDelegateAdapter<Item>(
|
||||
context: Context,
|
||||
layoutHelper: LayoutHelper
|
||||
) : BaseDelegateAdapter<Item>(
|
||||
context, layoutHelper
|
||||
) {
|
||||
protected abstract fun getItemLayoutId(
|
||||
itemType: Int
|
||||
): Int
|
||||
|
||||
protected abstract fun getViewType(
|
||||
position: Int,
|
||||
item: Item
|
||||
): Int
|
||||
|
||||
final override fun getItemViewType(position: Int): Int {
|
||||
return getViewType(position, getItem(position))
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder = MyViewHolder(context, getItemLayoutId(viewType))
|
||||
|
||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||
holder.setItemOnClickListener(View.OnClickListener {
|
||||
onItemClickListener?.onClick(holder, getItem(position), position)
|
||||
})
|
||||
holder.setItemOnLongClickListener(View.OnLongClickListener {
|
||||
onItemLongClickListener?.onLongClick(holder, getItem(position), position) ?: false
|
||||
})
|
||||
convert(holder, getItem(position), position, getItemViewType(position))
|
||||
}
|
||||
|
||||
protected abstract fun convert(viewHolder: MyViewHolder, item: Item, position: Int, viewType: Int)
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.huanchengfly.tieba.post.adapters.base
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.alibaba.android.vlayout.LayoutHelper
|
||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||
|
||||
abstract class BaseSingleTypeDelegateAdapter<Item>(
|
||||
context: Context,
|
||||
layoutHelper: LayoutHelper
|
||||
) : BaseDelegateAdapter<Item>(
|
||||
context, layoutHelper
|
||||
) {
|
||||
protected abstract fun getItemLayoutId(): Int
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder = MyViewHolder(context, getItemLayoutId())
|
||||
|
||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||
holder.setItemOnClickListener(View.OnClickListener {
|
||||
onItemClickListener?.onClick(holder, getItem(position), position)
|
||||
})
|
||||
holder.setItemOnLongClickListener(View.OnLongClickListener {
|
||||
onItemLongClickListener?.onLongClick(holder, getItem(position), position) ?: false
|
||||
})
|
||||
convert(holder, getItem(position), position)
|
||||
}
|
||||
|
||||
protected abstract fun convert(viewHolder: MyViewHolder, item: Item, position: Int)
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
package com.huanchengfly.tieba.post.adapters.base
|
||||
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package com.huanchengfly.tieba.post.components;
|
||||
|
||||
public class AutoLineFeedLayoutManager {
|
||||
}
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
package com.huanchengfly.tieba.post.fragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.huanchengfly.tieba.post.api.TiebaApi;
|
||||
import com.huanchengfly.tieba.post.api.models.SearchForumBean;
|
||||
import com.huanchengfly.tieba.post.R;
|
||||
import com.huanchengfly.tieba.post.adapters.SearchForumAdapter;
|
||||
import com.huanchengfly.tieba.post.components.MyLinearLayoutManager;
|
||||
import com.huanchengfly.tieba.post.components.dividers.SearchDivider;
|
||||
import com.huanchengfly.tieba.post.utils.ThemeUtil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import butterknife.BindView;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SearchForumFragment extends BaseFragment {
|
||||
public static final String TAG = "SearchForumFragment";
|
||||
|
||||
public static final String ARG_KEYWORD = "keyword";
|
||||
@BindView(R.id.fragment_search_refresh_layout)
|
||||
SwipeRefreshLayout refreshLayout;
|
||||
@BindView(R.id.fragment_search_recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
private String keyword;
|
||||
private SearchForumAdapter mAdapter;
|
||||
|
||||
private SearchForumBean.DataBean mData;
|
||||
|
||||
public SearchForumFragment() {
|
||||
}
|
||||
|
||||
public static SearchForumFragment newInstance(String keyword) {
|
||||
SearchForumFragment forumFragment = new SearchForumFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(ARG_KEYWORD, keyword);
|
||||
forumFragment.setArguments(bundle);
|
||||
return forumFragment;
|
||||
}
|
||||
|
||||
public void setKeyword(String keyword, boolean refresh) {
|
||||
this.keyword = keyword;
|
||||
if (refresh) {
|
||||
refresh();
|
||||
} else {
|
||||
this.mData = null;
|
||||
mAdapter.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFragmentVisibleChange(boolean isVisible) {
|
||||
if (mData == null && isVisible) {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
keyword = getArguments().getString(ARG_KEYWORD);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
int getLayoutId() {
|
||||
return R.layout.fragment_search;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
recyclerView.setLayoutManager(new MyLinearLayoutManager(getAttachContext()));
|
||||
recyclerView.addItemDecoration(new SearchDivider(getAttachContext()));
|
||||
mAdapter = new SearchForumAdapter(getAttachContext());
|
||||
mAdapter.setLoadEndView(R.layout.layout_footer_loadend);
|
||||
mAdapter.setLoadFailedView(R.layout.layout_footer_load_failed);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
refreshLayout.setOnRefreshListener(this::refresh);
|
||||
ThemeUtil.setThemeForSwipeRefreshLayout(refreshLayout);
|
||||
}
|
||||
|
||||
private void setRefreshing(boolean refreshing) {
|
||||
if (refreshLayout != null) refreshLayout.setRefreshing(refreshing);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
setRefreshing(true);
|
||||
TiebaApi.getInstance().searchForum(keyword).enqueue(new Callback<SearchForumBean>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<SearchForumBean> call, @NotNull Response<SearchForumBean> response) {
|
||||
mData = response.body().getData();
|
||||
mAdapter.setData(mData);
|
||||
setRefreshing(false);
|
||||
mAdapter.loadEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<SearchForumBean> call, @NotNull Throwable t) {
|
||||
setRefreshing(false);
|
||||
Toast.makeText(getAttachContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFragmentFirstVisible() {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package com.huanchengfly.tieba.post.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import butterknife.BindView
|
||||
import com.alibaba.android.vlayout.VirtualLayoutManager
|
||||
import com.huanchengfly.tieba.post.R
|
||||
import com.huanchengfly.tieba.post.adapters.SearchForumAdapter
|
||||
import com.huanchengfly.tieba.post.api.TiebaApi.getInstance
|
||||
import com.huanchengfly.tieba.post.api.models.SearchForumBean
|
||||
import com.huanchengfly.tieba.post.interfaces.ISearchFragment
|
||||
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
||||
class SearchForumFragment : BaseFragment(), ISearchFragment {
|
||||
@BindView(R.id.fragment_search_refresh_layout)
|
||||
var refreshLayout: SwipeRefreshLayout? = null
|
||||
|
||||
@BindView(R.id.fragment_search_recycler_view)
|
||||
var recyclerView: RecyclerView? = null
|
||||
private var keyword: String? = null
|
||||
private var mAdapter: SearchForumAdapter? = null
|
||||
private var mData: SearchForumBean.DataBean? = null
|
||||
override fun setKeyword(
|
||||
keyword: String?,
|
||||
needRefresh: Boolean
|
||||
) {
|
||||
this.keyword = keyword
|
||||
if (mAdapter != null) {
|
||||
if (needRefresh) {
|
||||
refresh()
|
||||
} else {
|
||||
mData = null
|
||||
mAdapter!!.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFragmentVisibleChange(isVisible: Boolean) {
|
||||
if (mData == null && isVisible) {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (arguments != null) {
|
||||
keyword = arguments!!.getString(ARG_KEYWORD)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun getLayoutId(): Int {
|
||||
return R.layout.fragment_search
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
recyclerView!!.layoutManager = VirtualLayoutManager(attachContext)
|
||||
mAdapter = SearchForumAdapter(attachContext)
|
||||
recyclerView!!.adapter = mAdapter
|
||||
refreshLayout!!.setOnRefreshListener { refresh() }
|
||||
ThemeUtil.setThemeForSwipeRefreshLayout(refreshLayout)
|
||||
}
|
||||
|
||||
private fun setRefreshing(refreshing: Boolean) {
|
||||
if (refreshLayout != null) refreshLayout!!.isRefreshing = refreshing
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
if (keyword == null) {
|
||||
return
|
||||
}
|
||||
setRefreshing(true)
|
||||
getInstance().searchForum(keyword!!).enqueue(object : Callback<SearchForumBean> {
|
||||
override fun onResponse(call: Call<SearchForumBean>, response: Response<SearchForumBean>) {
|
||||
mData = response.body()!!.data
|
||||
reloadAdapters()
|
||||
setRefreshing(false)
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<SearchForumBean>, t: Throwable) {
|
||||
setRefreshing(false)
|
||||
Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun reloadAdapters() {}
|
||||
override fun onFragmentFirstVisible() {
|
||||
refresh()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "SearchForumFragment"
|
||||
const val ARG_KEYWORD = "keyword"
|
||||
@JvmOverloads
|
||||
fun newInstance(keyword: String? = null): SearchForumFragment {
|
||||
val forumFragment = SearchForumFragment()
|
||||
val bundle = Bundle()
|
||||
bundle.putString(ARG_KEYWORD, keyword)
|
||||
forumFragment.arguments = bundle
|
||||
return forumFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package com.huanchengfly.tieba.post.interfaces
|
||||
|
||||
interface ISearchFragment {
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.huanchengfly.tieba.post.widgets.theme
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatEditText
|
||||
import com.huanchengfly.tieba.post.R
|
||||
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable
|
||||
import com.huanchengfly.tieba.post.ui.theme.utils.ColorStateListUtils
|
||||
|
||||
class TintEditText @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.editTextStyle
|
||||
) : AppCompatEditText(context, attrs, defStyleAttr), Tintable {
|
||||
private var textColorResId: Int
|
||||
private var textColorHintResId: Int
|
||||
|
||||
init {
|
||||
if (isInEditMode || attrs == null) {
|
||||
textColorResId = 0
|
||||
textColorHintResId = 0
|
||||
} else {
|
||||
val array = getContext().obtainStyledAttributes(attrs, R.styleable.TintEditText, defStyleAttr, 0)
|
||||
textColorResId = array.getResourceId(R.styleable.TintEditText_textColor, 0)
|
||||
textColorHintResId = array.getResourceId(R.styleable.TintEditText_android_textColorHint, 0)
|
||||
array.recycle()
|
||||
}
|
||||
tint()
|
||||
}
|
||||
|
||||
override fun tint() {
|
||||
if (textColorResId != 0) {
|
||||
setTextColor(ColorStateListUtils.createColorStateList(context, textColorResId))
|
||||
}
|
||||
if (textColorHintResId != 0) {
|
||||
setHintTextColor(ColorStateListUtils.createColorStateList(context, textColorHintResId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?colorControlHighlight">
|
||||
<item android:drawable="@drawable/bg_top_radius_8dp" />
|
||||
</ripple>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:radius="8dp"/>
|
||||
<solid android:color="@color/white"/>
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</ripple>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:topLeftRadius="8dp"
|
||||
android:topRightRadius="8dp" />
|
||||
<solid android:color="@color/white" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9.29,6.71c-0.39,0.39 -0.39,1.02 0,1.41L13.17,12l-3.88,3.88c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.39 1.02,0.39 1.41,0l4.59,-4.59c0.39,-0.39 0.39,-1.02 0,-1.41L10.7,6.7c-0.38,-0.38 -1.02,-0.38 -1.41,0.01z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M8,18c0.55,0 1,-0.45 1,-1L9,7c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1v10c0,0.55 0.45,1 1,1zM12,22c0.55,0 1,-0.45 1,-1L13,3c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1v18c0,0.55 0.45,1 1,1zM4,14c0.55,0 1,-0.45 1,-1v-2c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1v2c0,0.55 0.45,1 1,1zM16,18c0.55,0 1,-0.45 1,-1L17,7c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1v10c0,0.55 0.45,1 1,1zM19,11v2c0,0.55 0.45,1 1,1s1,-0.45 1,-1v-2c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20,5L4,5c-1.1,0 -1.99,0.9 -1.99,2L2,17c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2zM11,8h2v2h-2L11,8zM11,11h2v2h-2v-2zM8,8h2v2L8,10L8,8zM8,11h2v2L8,13v-2zM7,13L5,13v-2h2v2zM7,10L5,10L5,8h2v2zM15,17L9,17c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1h6c0.55,0 1,0.45 1,1s-0.45,1 -1,1zM16,13h-2v-2h2v2zM16,10h-2L14,8h2v2zM19,13h-2v-2h2v2zM19,10h-2L17,8h2v2z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19,4h-4L7.11,16.63 4.5,12 9,4H5L0.5,12 5,20h4l7.89,-12.63L19.5,12 15,20h4l4.5,-8L19,4z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintCoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</com.huanchengfly.tieba.post.widgets.theme.TintCoordinatorLayout>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/classify_item"
|
||||
app:backgroundTint="@color/default_color_floor_card"
|
||||
android:background="@drawable/bg_radius_4dp"
|
||||
android:padding="6dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
android:gravity="center"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textStyle="bold"
|
||||
app:tint="@color/default_color_text_secondary"
|
||||
android:id="@+id/classify_text"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</com.huanchengfly.tieba.post.widgets.theme.TintRelativeLayout>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</menu>
|
||||
Loading…
Reference in New Issue