光环助手V5.0.0-新社区展示功能(社区搜索页的搜索结果增加论坛tab) https://git.ghzs.com/pm/halo-app-issues/-/issues/1253
This commit is contained in:
@ -7,17 +7,20 @@ import android.widget.RelativeLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.gh.base.fragment.BaseFragment_TabLayout
|
||||
import com.gh.common.util.dip2px
|
||||
import com.gh.gamecenter.qa.dialog.ChooseForumContainerFragment
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
|
||||
class ForumOrUserSearchFragment : BaseFragment_TabLayout() {
|
||||
private var mSearchKey = ""
|
||||
|
||||
override fun initFragmentList(fragments: MutableList<Fragment>) {
|
||||
fragments.add(ChooseForumContainerFragment.getInstance(ChooseForumContainerFragment.ChooseForumType.SEARCH))
|
||||
fragments.add(ForumContentSearchListFragment())
|
||||
fragments.add(UserSearchListFragment())
|
||||
}
|
||||
|
||||
override fun initTabTitleList(tabTitleList: MutableList<String>) {
|
||||
tabTitleList.add("论坛")
|
||||
tabTitleList.add("内容")
|
||||
tabTitleList.add("用户")
|
||||
}
|
||||
@ -31,6 +34,9 @@ class ForumOrUserSearchFragment : BaseFragment_TabLayout() {
|
||||
|
||||
private fun setSearchKeyToChildFragment() {
|
||||
mFragmentsList.forEach {
|
||||
if (it is ChooseForumContainerFragment) {
|
||||
it.setSearchKey(mSearchKey)
|
||||
}
|
||||
if (it is ForumContentSearchListFragment) {
|
||||
it.setSearchKey(mSearchKey)
|
||||
}
|
||||
|
||||
@ -35,9 +35,7 @@ class ChooseForumActivity : BaseActivity() {
|
||||
switchUI(false)
|
||||
} else {
|
||||
switchUI(true)
|
||||
if (mSearchResultFragment != null && mSearchResultFragment?.isAdded == true) {
|
||||
mSearchResultFragment?.setSearchKey(binding.searchEt.text.toString())
|
||||
}
|
||||
mSearchResultFragment?.setSearchKey(binding.searchEt.text.toString())
|
||||
}
|
||||
}
|
||||
binding.closeIv.setOnClickListener { finish() }
|
||||
@ -70,7 +68,7 @@ class ChooseForumActivity : BaseActivity() {
|
||||
if (mSearchResultFragment == null || mSearchResultFragment?.isAdded == false) {
|
||||
val beginTransaction = supportFragmentManager.beginTransaction()
|
||||
mSearchResultFragment = supportFragmentManager.findFragmentByTag(ChooseForumContainerFragment::class.java.simpleName) as? ChooseForumContainerFragment
|
||||
?: ChooseForumContainerFragment.getInstance(ChooseForumContainerFragment.ChooseForumType.SEARCH, binding.searchEt.text.toString()) as ChooseForumContainerFragment
|
||||
?: ChooseForumContainerFragment.getInstance(ChooseForumContainerFragment.ChooseForumType.SEARCH) as ChooseForumContainerFragment
|
||||
beginTransaction.replace(binding.searchResultContainer.id, mSearchResultFragment!!, ChooseForumContainerFragment::class.java.simpleName)
|
||||
beginTransaction.commitAllowingStateLoss()
|
||||
}
|
||||
|
||||
@ -4,11 +4,15 @@ import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.util.HtmlUtils
|
||||
import com.gh.common.util.MtaHelper
|
||||
import com.gh.common.util.goneIf
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.databinding.ForumItemBinding
|
||||
import com.gh.gamecenter.entity.CommunityEntity
|
||||
@ -16,13 +20,38 @@ import com.gh.gamecenter.entity.ForumEntity
|
||||
import com.gh.gamecenter.forum.detail.ForumDetailActivity
|
||||
import com.gh.gamecenter.qa.entity.CommunitySelectEntity
|
||||
|
||||
class ChooseForumContainerAdapter(content: Context, val onSelectCallback: ((entity: CommunityEntity) -> Unit)? = null) : ListAdapter<ForumEntity>(content) {
|
||||
class ChooseForumContainerAdapter(content: Context, val type: String, val onSelectCallback: ((entity: CommunityEntity) -> Unit)? = null) : ListAdapter<ForumEntity>(content) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return ForumItemViewHolder(ForumItemBinding.inflate(LayoutInflater.from(mContext), parent, false))
|
||||
return when (viewType) {
|
||||
ItemViewType.ITEM_FOOTER -> {
|
||||
FooterViewHolder(mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false))
|
||||
}
|
||||
else -> {
|
||||
ForumItemViewHolder(ForumItemBinding.inflate(LayoutInflater.from(mContext), parent, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = mEntityList.size
|
||||
override fun getItemCount(): Int {
|
||||
return if (mEntityList.isNotEmpty()) {
|
||||
if (type == ChooseForumContainerFragment.ChooseForumType.SEARCH.value) {
|
||||
mEntityList.size + FOOTER_ITEM_COUNT
|
||||
} else {
|
||||
mEntityList.size
|
||||
}
|
||||
} else 0
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
if (type == ChooseForumContainerFragment.ChooseForumType.SEARCH.value) {
|
||||
if (position == itemCount - 1) return ItemViewType.ITEM_FOOTER
|
||||
return ItemViewType.ITEM_BODY
|
||||
} else {
|
||||
return ItemViewType.ITEM_BODY
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder is ForumItemViewHolder) {
|
||||
@ -34,6 +63,11 @@ class ChooseForumContainerAdapter(content: Context, val onSelectCallback: ((enti
|
||||
onSelectCallback?.invoke(CommunityEntity(forumEntity.id, HtmlUtils.stripHtml(forumEntity.name),
|
||||
game = forumEntity.game, icon = forumEntity.game.getIcon(), iconSubscript = forumEntity.game.iconSubscript))
|
||||
}
|
||||
} else if (holder is FooterViewHolder) {
|
||||
holder.initItemPadding()
|
||||
holder.initFooterViewHolder(mIsLoading, mIsNetworkError, mIsOver)
|
||||
holder.hint.textSize = 12f
|
||||
holder.hint.setTextColor(ContextCompat.getColor(mContext, R.color.aaaaaa))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,25 +11,27 @@ import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.baselist.ListFragment
|
||||
import com.gh.gamecenter.entity.CommunityEntity
|
||||
import com.gh.gamecenter.entity.ForumEntity
|
||||
import com.gh.gamecenter.forum.detail.ForumDetailActivity
|
||||
|
||||
class ChooseForumContainerFragment : ListFragment<ForumEntity, ChooseForumContainerViewModel>() {
|
||||
|
||||
private var mAdapter: ChooseForumContainerAdapter? = null
|
||||
private var type: String = ""
|
||||
private var searchKey: String = ""
|
||||
private var mSearchKey: String = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
type = arguments?.getString(EntranceUtils.KEY_CHOOSE_FORUM_TYPE) ?: ""
|
||||
searchKey = arguments?.getString(EntranceUtils.KEY_SEARCHKEY) ?: ""
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun shouldLoadMore(): Boolean = false
|
||||
|
||||
override fun provideListAdapter(): ListAdapter<*> {
|
||||
return mAdapter ?: ChooseForumContainerAdapter(requireContext()) {
|
||||
return mAdapter ?: ChooseForumContainerAdapter(requireContext(), type) {
|
||||
if (requireActivity() is ChooseForumActivity) {
|
||||
(requireActivity() as ChooseForumActivity).chooseSuccess(it)
|
||||
} else {
|
||||
requireActivity().startActivity(ForumDetailActivity.getIntent(requireContext(), it.id, "搜索论坛"))
|
||||
}
|
||||
}.apply {
|
||||
mAdapter = this
|
||||
@ -37,20 +39,28 @@ class ChooseForumContainerFragment : ListFragment<ForumEntity, ChooseForumContai
|
||||
}
|
||||
|
||||
override fun provideListViewModel(): ChooseForumContainerViewModel {
|
||||
return viewModelProvider(ChooseForumContainerViewModel.Factory(type, searchKey))
|
||||
return viewModelProvider(ChooseForumContainerViewModel.Factory(type, mSearchKey))
|
||||
}
|
||||
|
||||
fun setSearchKey(searchKey: String) {
|
||||
mSearchKey = searchKey
|
||||
mListViewModel?.setSearchKeyAndRefresh(searchKey)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
if (type == ChooseForumType.SEARCH.value) {
|
||||
mListViewModel?.setSearchKeyAndRefresh(mSearchKey)
|
||||
}
|
||||
}
|
||||
|
||||
override fun isAutomaticLoad(): Boolean = type != ChooseForumType.SEARCH.value
|
||||
|
||||
override fun getItemDecoration(): RecyclerView.ItemDecoration? = null
|
||||
|
||||
companion object {
|
||||
fun getInstance(type: ChooseForumType, searchKey: String = ""): Fragment {
|
||||
val bundle = bundleOf(EntranceUtils.KEY_CHOOSE_FORUM_TYPE to type.value, EntranceUtils.KEY_SEARCHKEY to searchKey)
|
||||
fun getInstance(type: ChooseForumType): Fragment {
|
||||
val bundle = bundleOf(EntranceUtils.KEY_CHOOSE_FORUM_TYPE to type.value)
|
||||
return ChooseForumContainerFragment().apply {
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
@ -16,11 +16,13 @@ import io.reactivex.Observable
|
||||
|
||||
class ChooseForumContainerViewModel(application: Application, val type: String, var searchKey: String) : ListViewModel<ForumEntity, ForumEntity>(application) {
|
||||
private val mApi: ApiService = RetrofitManager.getInstance(getApplication()).api
|
||||
|
||||
init {
|
||||
if (searchKey.isNotEmpty()) {
|
||||
if (type != ChooseForumContainerFragment.ChooseForumType.SEARCH.value) {
|
||||
load(LoadType.REFRESH)
|
||||
}
|
||||
}
|
||||
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<ForumEntity>> {
|
||||
return when (type) {
|
||||
ChooseForumContainerFragment.ChooseForumType.ATTENTION.value -> {
|
||||
|
||||
Reference in New Issue
Block a user