1.问答模块增加提问悬浮按钮
2.问答搜索增加默认搜索文案 3.问答搜索增加热门搜索区域
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.gh.gamecenter.qa
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.arch.lifecycle.Observer
|
||||
@ -23,6 +24,7 @@ import com.gh.base.adapter.FragmentAdapter
|
||||
import com.gh.base.fragment.BaseFragment
|
||||
import com.gh.base.onDoubleTapListener
|
||||
import com.gh.common.util.MtaHelper
|
||||
import com.gh.common.util.addOnPageChangeListener
|
||||
import com.gh.gamecenter.MainActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.entity.ResultEntity
|
||||
@ -33,6 +35,7 @@ import com.gh.gamecenter.qa.column.AskColumnFragment
|
||||
import com.gh.gamecenter.qa.column.AskColumnViewModel
|
||||
import com.gh.gamecenter.qa.follow.AskFollowFragment
|
||||
import com.gh.gamecenter.qa.newest.AskQuestionsNewFragment
|
||||
import com.gh.gamecenter.qa.questions.edit.QuestionEditActivity
|
||||
import com.gh.gamecenter.qa.recommends.AskRecommendWrapperFragment
|
||||
import com.gh.gamecenter.qa.search.AskSearchActivity
|
||||
import com.gh.gamecenter.qa.select.CommunitiesSelectActivity
|
||||
@ -52,20 +55,17 @@ class AskFragment : BaseFragment<Any>() {
|
||||
const val INDEX_QUESTIONS = 3 // communities
|
||||
const val COMMUNITIES_SELECT_REQUEST = 103
|
||||
|
||||
const val SP_KEY_CLICKED_SELECT_GAME = "has_clicked_select_game"
|
||||
|
||||
const val EB_SELECT_KEY = "EB_SELECT_KEY"
|
||||
const val EB_RETRY_PAGE = "EB_RETRY_PAGE"
|
||||
|
||||
const val EB_HIDE_FOLLOW_HINT = "EB_HIDE_FOLLOW_HINT"
|
||||
|
||||
const val SCROLL_RECOMMEND_TO_TOP = "SCROLL_RECOMMEND_TO_TOP"
|
||||
const val SP_KEY_CLICKED_SELECT_GAME = "has_clicked_select_game"
|
||||
}
|
||||
|
||||
@BindView(R.id.ask_selectgame)
|
||||
lateinit var mAskSelectgame: ImageView
|
||||
@BindView(R.id.ask_gamename)
|
||||
lateinit var mAskGamename: TextView
|
||||
@BindView(R.id.ask_select_community)
|
||||
lateinit var mAskSelectCommunity: ImageView
|
||||
@BindView(R.id.ask_community_name)
|
||||
lateinit var mAskCommunityName: TextView
|
||||
@BindView(R.id.ask_search)
|
||||
lateinit var mAskSearch: ImageView
|
||||
@BindView(R.id.ask_follow)
|
||||
@ -92,6 +92,8 @@ class AskFragment : BaseFragment<Any>() {
|
||||
lateinit var mColumnLine: View
|
||||
@BindView(R.id.follow_hint)
|
||||
lateinit var mFollowHint: View
|
||||
@BindView(R.id.ask_put_questions)
|
||||
lateinit var mPutQuestions: View
|
||||
|
||||
private lateinit var mRecommendsFragment: AskRecommendWrapperFragment
|
||||
|
||||
@ -137,10 +139,10 @@ class AskFragment : BaseFragment<Any>() {
|
||||
|| TextUtils.isEmpty(UserManager.getInstance().community.id)) {
|
||||
showCommunitySelectFragment()
|
||||
} else {
|
||||
mAskGamename.text = UserManager.getInstance().community.name
|
||||
mAskCommunityName.text = UserManager.getInstance().community.name
|
||||
showAvailableInfo()
|
||||
initViewPager()
|
||||
setTabbarPosition(INDEX_HOT)
|
||||
setTabBarPosition(INDEX_HOT)
|
||||
|
||||
if (mOpenedFragment != null) hideCommunitySelectFragmentAndShowCommunityWithHint()
|
||||
|
||||
@ -159,7 +161,7 @@ class AskFragment : BaseFragment<Any>() {
|
||||
if ((it == null || it.isEmpty()) && mAskColumn.visibility == View.VISIBLE) {
|
||||
mAskColumn.visibility = View.GONE
|
||||
mColumnLine.visibility = View.GONE
|
||||
if (mAskColumn.isChecked) setTabbarPosition(INDEX_HOT)
|
||||
if (mAskColumn.isChecked) setTabBarPosition(INDEX_HOT)
|
||||
} else if (it != null && !it.isEmpty() && mAskColumn.visibility == View.GONE) {
|
||||
mAskColumn.visibility = View.VISIBLE
|
||||
mColumnLine.visibility = View.VISIBLE
|
||||
@ -187,25 +189,26 @@ class AskFragment : BaseFragment<Any>() {
|
||||
|
||||
// 社区没有被隐藏,正常显示社区信息
|
||||
private fun showAvailableInfo() {
|
||||
mAskGamename.text = UserManager.getInstance().community.name
|
||||
mAskCommunityName.text = UserManager.getInstance().community.name
|
||||
mAskSearch.visibility = View.VISIBLE
|
||||
mAskTabBar.visibility = View.VISIBLE
|
||||
mAskViewpager.visibility = View.VISIBLE
|
||||
mAskSelectgame.visibility = View.VISIBLE
|
||||
mAskSelectCommunity.visibility = View.VISIBLE
|
||||
mCommunitiesSelectLayout.visibility = View.GONE
|
||||
mLoading.visibility = View.GONE
|
||||
}
|
||||
|
||||
@OnClick(R.id.ask_selectgame,
|
||||
@OnClick(R.id.ask_select_community,
|
||||
R.id.ask_search,
|
||||
R.id.ask_hot,
|
||||
R.id.ask_follow,
|
||||
R.id.ask_questions,
|
||||
R.id.ask_column,
|
||||
R.id.reuse_no_connection)
|
||||
R.id.reuse_no_connection,
|
||||
R.id.ask_put_questions)
|
||||
fun onViewClicked(view: View) {
|
||||
when (view.id) {
|
||||
R.id.ask_selectgame -> {
|
||||
R.id.ask_select_community -> {
|
||||
if (!mHasClickedSelectGame) {
|
||||
mHasClickedSelectGame = true
|
||||
sp.edit().putBoolean(SP_KEY_CLICKED_SELECT_GAME, mHasClickedSelectGame).apply()
|
||||
@ -223,7 +226,7 @@ class AskFragment : BaseFragment<Any>() {
|
||||
startActivity(AskSearchActivity.getIntent(context, "(首页-问答)"))
|
||||
}
|
||||
R.id.ask_follow -> {
|
||||
setTabbarPosition(INDEX_FOLLOW)
|
||||
setTabBarPosition(INDEX_FOLLOW)
|
||||
// 关注 tab 存在未读红点,刷新一下
|
||||
val isRefreshing = mAskFollowFragment.load()
|
||||
if (mFollowHint.visibility == View.VISIBLE &&
|
||||
@ -233,24 +236,28 @@ class AskFragment : BaseFragment<Any>() {
|
||||
MtaHelper.onEvent("问答页面", UserManager.getInstance().community.name, "关注Tab")
|
||||
}
|
||||
R.id.ask_hot -> {
|
||||
setTabbarPosition(INDEX_HOT)
|
||||
setTabBarPosition(INDEX_HOT)
|
||||
MtaHelper.onEvent("问答页面", UserManager.getInstance().community.name, "推荐Tab")
|
||||
}
|
||||
R.id.ask_questions -> {
|
||||
setTabbarPosition(INDEX_QUESTIONS)
|
||||
setTabBarPosition(INDEX_QUESTIONS)
|
||||
MtaHelper.onEvent("问答页面", UserManager.getInstance().community.name, "问题Tab")
|
||||
}
|
||||
R.id.ask_column -> {
|
||||
setTabbarPosition(INDEX_COLUMN)
|
||||
setTabBarPosition(INDEX_COLUMN)
|
||||
MtaHelper.onEvent("问答页面", UserManager.getInstance().community.name, "专栏Tab")
|
||||
}
|
||||
R.id.reuse_no_connection -> {
|
||||
mNoConn.visibility = View.GONE
|
||||
mLoading.visibility = View.VISIBLE
|
||||
}
|
||||
R.id.ask_put_questions -> {
|
||||
startActivity(QuestionEditActivity.getIntent(context!!))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun initViewPager() {
|
||||
val fragmentList = ArrayList<Fragment>()
|
||||
mRecommendsFragment = AskRecommendWrapperFragment()
|
||||
@ -262,7 +269,15 @@ class AskFragment : BaseFragment<Any>() {
|
||||
mAskViewpager.setScrollable(false)
|
||||
mAskViewpager.offscreenPageLimit = fragmentList.size
|
||||
|
||||
mAskGamename.setOnTouchListener(object : onDoubleTapListener(context) {
|
||||
mAskViewpager.addOnPageChangeListener(onSelected = {
|
||||
mPutQuestions.visibility = if (fragmentList[it] is AskColumnFragment) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
}
|
||||
})
|
||||
|
||||
mAskCommunityName.setOnTouchListener(object : onDoubleTapListener(context) {
|
||||
override fun onDoubleTap() {
|
||||
when (mAskViewpager.currentItem) {
|
||||
INDEX_FOLLOW -> {
|
||||
@ -275,7 +290,7 @@ class AskFragment : BaseFragment<Any>() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun setTabbarPosition(index: Int) {
|
||||
private fun setTabBarPosition(index: Int) {
|
||||
when (index) {
|
||||
INDEX_FOLLOW -> {
|
||||
mAskFollow.isChecked = true
|
||||
@ -333,9 +348,10 @@ class AskFragment : BaseFragment<Any>() {
|
||||
}
|
||||
|
||||
private fun showCommunitySelectFragment() {
|
||||
mAskSelectgame.visibility = View.INVISIBLE
|
||||
mPutQuestions.visibility = View.GONE
|
||||
mAskSelectCommunity.visibility = View.INVISIBLE
|
||||
mAskSearch.visibility = View.INVISIBLE
|
||||
mAskGamename.text = "选择游戏"
|
||||
mAskCommunityName.text = "选择游戏"
|
||||
mAskTabBar.visibility = View.GONE
|
||||
mLoading.visibility = View.GONE
|
||||
mCommunitiesSelectLayout.visibility = View.VISIBLE
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
package com.gh.gamecenter.qa.entity
|
||||
|
||||
class CommunityHotSearch(val title: String,
|
||||
val introduction: String,
|
||||
val keyword: String)
|
||||
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.Editable;
|
||||
@ -27,16 +28,22 @@ import com.gh.gamecenter.eventbus.EBSearch;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.qa.questions.edit.QuestionEditActivity;
|
||||
import com.gh.gamecenter.qa.search.history.HistoryFragment;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.lightgame.utils.Util_System_Keyboard;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
/**
|
||||
* Created by khy on 8/12/17.
|
||||
@ -46,7 +53,7 @@ public class AskSearchActivity extends BaseActivity {
|
||||
|
||||
private static final int POST_SEARCH_WHAT = 2;
|
||||
private static final int QUESTION_REQUEST_CODE = 2;
|
||||
private static final String ASK_SEARCH_EB_TYPE = "askHistory";
|
||||
public static final String ASK_SEARCH_EB_TYPE = "invoke_search";
|
||||
|
||||
@BindView(R.id.bar_search_edit)
|
||||
EditText mSearchEt;
|
||||
@ -63,9 +70,9 @@ public class AskSearchActivity extends BaseActivity {
|
||||
|
||||
private String mSearchKey;
|
||||
private String mPostedKey;
|
||||
|
||||
private String mColumnId;
|
||||
private String mQuestionTag;
|
||||
private String mDefaultSearchKey;
|
||||
|
||||
public static Intent getIntent(Context context, String entrance) {
|
||||
Intent intent = new Intent(context, AskSearchActivity.class);
|
||||
@ -125,6 +132,7 @@ public class AskSearchActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
getCommunityDefaultSearch();
|
||||
changeFragment();
|
||||
|
||||
mSearchEt.setOnEditorActionListener((v, actionId, event) -> {
|
||||
@ -176,28 +184,44 @@ public class AskSearchActivity extends BaseActivity {
|
||||
startActivityForResult(QuestionEditActivity.Companion.getIntent(this, mSearchKey), QUESTION_REQUEST_CODE);
|
||||
});
|
||||
} else if (v.getId() == R.id.bar_question_btn) {
|
||||
if (!TextUtils.isEmpty(mColumnId) || !TextUtils.isEmpty(mQuestionTag)) {
|
||||
search();
|
||||
mDao.add(mSearchKey, UserManager.getInstance().getCommunity().getId());
|
||||
Util_System_Keyboard.hideSoftKeyboard(this, mSearchEt);
|
||||
} else {
|
||||
String entrance;
|
||||
if (!TextUtils.isEmpty(mColumnId)) {
|
||||
entrance = "专栏详情-搜索-点我提问";
|
||||
} else if (!TextUtils.isEmpty(mQuestionTag)) {
|
||||
entrance = "问题标签详情-搜索-点我提问";
|
||||
} else {
|
||||
entrance = "问答-搜索-点我提问";
|
||||
String key = mSearchEt.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
if (!TextUtils.isEmpty(mDefaultSearchKey)) {
|
||||
mSearchEt.setText(mDefaultSearchKey);
|
||||
mDao.add(mDefaultSearchKey, UserManager.getInstance().getCommunity().getId());
|
||||
Util_System_Keyboard.hideSoftKeyboard(this, mSearchEt);
|
||||
}
|
||||
CheckLoginUtils.checkLogin(this, entrance, () -> {
|
||||
startActivityForResult(QuestionEditActivity.Companion.getIntent(this, mSearchKey), QUESTION_REQUEST_CODE);
|
||||
});
|
||||
} else {
|
||||
mDao.add(mSearchKey, UserManager.getInstance().getCommunity().getId());
|
||||
}
|
||||
} else if (v.getId() == R.id.bar_back) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void getCommunityDefaultSearch() {
|
||||
RetrofitManager
|
||||
.getInstance(this)
|
||||
.getApi()
|
||||
.getCommunityDefaultSearch(UserManager.getInstance().getCommunity().getId())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(@Nullable ResponseBody response) {
|
||||
try {
|
||||
JSONArray array = new JSONArray(response.string());
|
||||
if (array.length() > 0) {
|
||||
mDefaultSearchKey = (String) array.get(0);
|
||||
mSearchEt.setHint(mDefaultSearchKey);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void search() {
|
||||
if (mSearchKey == null) return;
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.gh.gamecenter.qa.search.history
|
||||
|
||||
import android.arch.lifecycle.Observer
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
@ -14,20 +16,39 @@ import kotterknife.bindView
|
||||
class HistoryFragment : BaseFragment<Any>() {
|
||||
|
||||
private val mRecyclerView by bindView<RecyclerView>(R.id.search_history_list)
|
||||
private val mHotRecyclerView by bindView<RecyclerView>(R.id.search_hot_rv)
|
||||
private val mHistoryContainer by bindView<View>(R.id.search_history_container)
|
||||
private val mCleanBtn by bindView<View>(R.id.search_history_clean)
|
||||
private val mHotContainer by bindView<View>(R.id.search_hot_container)
|
||||
|
||||
private var dao: AskSearchHistoryDao? = null
|
||||
private var mHistoryAdapter: HistoryFragmentAdapter? = null
|
||||
|
||||
private lateinit var mViewModel: HistoryViewModel
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.fragment_ask_search_history
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mViewModel = ViewModelProviders.of(this).get(HistoryViewModel::class.java)
|
||||
mViewModel.hotSearchLiveData.observe(this, Observer {
|
||||
if (it?.size!! > 0) {
|
||||
mHotRecyclerView.adapter = HotFragmentAdapter(context!!, it)
|
||||
mHotContainer.visibility = View.VISIBLE
|
||||
} else {
|
||||
mHotContainer.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
|
||||
dao = AskSearchHistoryDao(context)
|
||||
mRecyclerView.layoutManager = object : GridLayoutManager(activity, 3) {
|
||||
mRecyclerView.layoutManager = object : GridLayoutManager(activity, 2) {
|
||||
override fun canScrollVertically(): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
mHotRecyclerView.layoutManager = object : GridLayoutManager(activity, 2) {
|
||||
override fun canScrollVertically(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -1,25 +1,20 @@
|
||||
package com.gh.gamecenter.qa.search.history
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.gh.common.util.DisplayUtils
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.databinding.CommunitySearchHistoryItemBinding
|
||||
import com.gh.gamecenter.db.AskSearchHistoryDao
|
||||
import com.gh.gamecenter.eventbus.EBSearch
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.qa.search.AskSearchActivity
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter
|
||||
import com.lightgame.utils.Util_System_Keyboard
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class HistoryFragmentAdapter(context: Context, dao: AskSearchHistoryDao, historyEmptyCallback: () -> Unit) :
|
||||
BaseRecyclerAdapter<HistoryFragmentAdapter.TextViewHolder>(context) {
|
||||
BaseRecyclerAdapter<HistoryFragmentAdapter.HistoryViewHolder>(context) {
|
||||
|
||||
private val mDao: AskSearchHistoryDao = dao
|
||||
|
||||
@ -31,39 +26,30 @@ class HistoryFragmentAdapter(context: Context, dao: AskSearchHistoryDao, history
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TextViewHolder {
|
||||
val textView = TextView(mContext)
|
||||
textView.setSingleLine()
|
||||
textView.ellipsize = TextUtils.TruncateAt.END
|
||||
textView.textSize = 13f
|
||||
textView.setPadding(DisplayUtils.dip2px(mContext, 10f), 0, DisplayUtils.dip2px(mContext, 10f), 0)
|
||||
textView.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(mContext, 32f))
|
||||
textView.gravity = Gravity.CENTER_VERTICAL
|
||||
textView.setBackgroundResource(R.drawable.reuse_listview_item_style)
|
||||
return TextViewHolder(textView)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryViewHolder {
|
||||
val view = mLayoutInflater.inflate(R.layout.community_search_history_item, parent, false)
|
||||
return HistoryViewHolder(CommunitySearchHistoryItemBinding.bind(view))
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return mHistoryList.size
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: TextViewHolder, position: Int) {
|
||||
holder.textView.text = mHistoryList[position]
|
||||
holder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.title))
|
||||
override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) {
|
||||
val key = mHistoryList[position]
|
||||
holder.binding.key = key
|
||||
holder.itemView.setOnClickListener { v ->
|
||||
val key = holder.textView.text.toString()
|
||||
mDao.add(key, UserManager.getInstance().community.id)
|
||||
EventBus.getDefault().post(EBSearch("askHistory", key))
|
||||
EventBus.getDefault().post(EBSearch(AskSearchActivity.ASK_SEARCH_EB_TYPE, key))
|
||||
Util_System_Keyboard.hideSoftKeyboardByIBinder(mContext, v.windowToken)
|
||||
}
|
||||
}
|
||||
|
||||
class TextViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val textView: TextView = itemView as TextView
|
||||
}
|
||||
|
||||
fun clearSearchResult() {
|
||||
mHistoryList.clear()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
class HistoryViewHolder(val binding: CommunitySearchHistoryItemBinding) : BaseRecyclerViewHolder<Any>(binding.root)
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.gh.gamecenter.qa.search.history
|
||||
|
||||
import android.app.Application
|
||||
import android.arch.lifecycle.AndroidViewModel
|
||||
import android.arch.lifecycle.MutableLiveData
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.qa.entity.CommunityHotSearch
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class HistoryViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
val hotSearchLiveData = MutableLiveData<List<CommunityHotSearch>>()
|
||||
|
||||
init {
|
||||
getHotSearch()
|
||||
}
|
||||
|
||||
private fun getHotSearch() {
|
||||
RetrofitManager.getInstance(getApplication()).api
|
||||
.getCommunityHotSearch(UserManager.getInstance().community.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<List<CommunityHotSearch>>() {
|
||||
override fun onResponse(response: List<CommunityHotSearch>?) {
|
||||
if (response != null) hotSearchLiveData.postValue(response)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.gh.gamecenter.qa.search.history
|
||||
|
||||
import android.content.Context
|
||||
import android.view.ViewGroup
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.databinding.CommunitySearchHotItemBinding
|
||||
import com.gh.gamecenter.eventbus.EBSearch
|
||||
import com.gh.gamecenter.qa.entity.CommunityHotSearch
|
||||
import com.gh.gamecenter.qa.search.AskSearchActivity
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter
|
||||
import com.lightgame.utils.Util_System_Keyboard
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class HotFragmentAdapter(context: Context, val list: List<CommunityHotSearch>)
|
||||
: BaseRecyclerAdapter<HotFragmentAdapter.HotViewHolder>(context) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HotFragmentAdapter.HotViewHolder {
|
||||
val view = mLayoutInflater.inflate(R.layout.community_search_hot_item, parent, false)
|
||||
return HotViewHolder(CommunitySearchHotItemBinding.bind(view))
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return list.size
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: HotFragmentAdapter.HotViewHolder, position: Int) {
|
||||
val data = list[position]
|
||||
holder.binding.setPosition(position + 1)
|
||||
holder.binding.data = data
|
||||
holder.itemView.setOnClickListener { v ->
|
||||
EventBus.getDefault().post(EBSearch(AskSearchActivity.ASK_SEARCH_EB_TYPE, data.keyword))
|
||||
Util_System_Keyboard.hideSoftKeyboardByIBinder(mContext, v.windowToken)
|
||||
}
|
||||
}
|
||||
|
||||
class HotViewHolder(val binding: CommunitySearchHotItemBinding) : BaseRecyclerViewHolder<Any>(binding.root)
|
||||
}
|
||||
@ -49,6 +49,7 @@ import com.gh.gamecenter.qa.entity.AskGameSelectEntity;
|
||||
import com.gh.gamecenter.qa.entity.AskSearchEntity;
|
||||
import com.gh.gamecenter.qa.entity.AskSubjectEntity;
|
||||
import com.gh.gamecenter.qa.entity.AskTagGroupsEntity;
|
||||
import com.gh.gamecenter.qa.entity.CommunityHotSearch;
|
||||
import com.gh.gamecenter.qa.entity.InviteEntity;
|
||||
import com.gh.gamecenter.qa.entity.QuestionHistoryDetailEntity;
|
||||
import com.gh.gamecenter.qa.entity.QuestionHistoryEntity;
|
||||
@ -1518,4 +1519,16 @@ public interface ApiService {
|
||||
*/
|
||||
@GET("communities/{community_id}")
|
||||
Observable<AskGameSelectEntity> getCommunityDesc(@Path("community_id") String community_id);
|
||||
|
||||
/**
|
||||
* 获取社区默认搜索文案
|
||||
*/
|
||||
@GET("communities/{community_id}/default_search")
|
||||
Observable<ResponseBody> getCommunityDefaultSearch(@Path("community_id") String communityId);
|
||||
|
||||
/**
|
||||
* 获取默认社区们搜索文案
|
||||
*/
|
||||
@GET("communities/{community_id}/hot_search")
|
||||
Observable<List<CommunityHotSearch>> getCommunityHotSearch(@Path("community_id") String communityId);
|
||||
}
|
||||
Reference in New Issue
Block a user