完成选择论坛-搜索论坛功能
This commit is contained in:
@ -35,7 +35,9 @@ class ChooseForumActivity : BaseActivity() {
|
||||
switchUI(false)
|
||||
} else {
|
||||
switchUI(true)
|
||||
mSearchResultFragment?.setSearchKey(binding.searchEt.text.toString())
|
||||
if (mSearchResultFragment != null && mSearchResultFragment?.isAdded == true) {
|
||||
mSearchResultFragment?.setSearchKey(binding.searchEt.text.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.closeIv.setOnClickListener { finish() }
|
||||
@ -68,7 +70,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) as ChooseForumContainerFragment
|
||||
?: ChooseForumContainerFragment.getInstance(ChooseForumContainerFragment.ChooseForumType.SEARCH, binding.searchEt.text.toString()) as ChooseForumContainerFragment
|
||||
beginTransaction.replace(binding.searchResultContainer.id, mSearchResultFragment!!, ChooseForumContainerFragment::class.java.simpleName)
|
||||
beginTransaction.commitAllowingStateLoss()
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.common.util.HtmlUtils
|
||||
import com.gh.common.util.MtaHelper
|
||||
import com.gh.common.util.goneIf
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
@ -30,7 +31,8 @@ class ChooseForumContainerAdapter(content: Context, val onSelectCallback: ((enti
|
||||
holder.binding.forumIcon.displayGameIcon(forumEntity.game.getIcon(), forumEntity.game.iconSubscript)
|
||||
holder.binding.followTv.visibility = View.GONE
|
||||
holder.itemView.setOnClickListener {
|
||||
onSelectCallback?.invoke(CommunityEntity(forumEntity.id, forumEntity.name, game = forumEntity.game, icon = forumEntity.game.getIcon(), iconSubscript = forumEntity.game.iconSubscript))
|
||||
onSelectCallback?.invoke(CommunityEntity(forumEntity.id, HtmlUtils.stripHtml(forumEntity.name),
|
||||
game = forumEntity.game, icon = forumEntity.game.getIcon(), iconSubscript = forumEntity.game.iconSubscript))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,9 +16,11 @@ class ChooseForumContainerFragment : ListFragment<ForumEntity, ChooseForumContai
|
||||
|
||||
private var mAdapter: ChooseForumContainerAdapter? = null
|
||||
private var type: String = ""
|
||||
private var searchKey: String = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
type = arguments?.getString(EntranceUtils.KEY_CHOOSE_FORUM_TYPE) ?: ""
|
||||
searchKey = arguments?.getString(EntranceUtils.KEY_SEARCHKEY) ?: ""
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
@ -35,11 +37,11 @@ class ChooseForumContainerFragment : ListFragment<ForumEntity, ChooseForumContai
|
||||
}
|
||||
|
||||
override fun provideListViewModel(): ChooseForumContainerViewModel {
|
||||
return viewModelProvider(ChooseForumContainerViewModel.Factory(type))
|
||||
return viewModelProvider(ChooseForumContainerViewModel.Factory(type, searchKey))
|
||||
}
|
||||
|
||||
fun setSearchKey(key: String) {
|
||||
|
||||
fun setSearchKey(searchKey: String) {
|
||||
mListViewModel?.setSearchKeyAndRefresh(searchKey)
|
||||
}
|
||||
|
||||
override fun isAutomaticLoad(): Boolean = type != ChooseForumType.SEARCH.value
|
||||
@ -47,8 +49,8 @@ class ChooseForumContainerFragment : ListFragment<ForumEntity, ChooseForumContai
|
||||
override fun getItemDecoration(): RecyclerView.ItemDecoration? = null
|
||||
|
||||
companion object {
|
||||
fun getInstance(type: ChooseForumType): Fragment {
|
||||
val bundle = bundleOf(EntranceUtils.KEY_CHOOSE_FORUM_TYPE to type.value)
|
||||
fun getInstance(type: ChooseForumType, searchKey: String = ""): Fragment {
|
||||
val bundle = bundleOf(EntranceUtils.KEY_CHOOSE_FORUM_TYPE to type.value, EntranceUtils.KEY_SEARCHKEY to searchKey)
|
||||
return ChooseForumContainerFragment().apply {
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.gh.common.exposure.ExposureSource
|
||||
import com.gh.gamecenter.baselist.ListViewModel
|
||||
import com.gh.gamecenter.baselist.LoadType
|
||||
import com.gh.gamecenter.category2.CategoryV2ListViewModel
|
||||
import com.gh.gamecenter.entity.ForumEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
@ -13,23 +14,39 @@ import com.gh.gamecenter.retrofit.service.ApiService
|
||||
import com.halo.assistant.HaloApp
|
||||
import io.reactivex.Observable
|
||||
|
||||
class ChooseForumContainerViewModel(application: Application, val type: String) : ListViewModel<ForumEntity, ForumEntity>(application) {
|
||||
class ChooseForumContainerViewModel(application: Application, val type: String, var searchKey: String) : ListViewModel<ForumEntity, ForumEntity>(application) {
|
||||
private val mApi: ApiService = RetrofitManager.getInstance(getApplication()).api
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<ForumEntity>> {
|
||||
return if (type == ChooseForumContainerFragment.ChooseForumType.ATTENTION.value) {
|
||||
mApi.getFollowsForum(UserManager.getInstance().userId)
|
||||
} else {
|
||||
mApi.hotForum
|
||||
init {
|
||||
if (searchKey.isNotEmpty()) {
|
||||
load(LoadType.REFRESH)
|
||||
}
|
||||
}
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<ForumEntity>> {
|
||||
return when (type) {
|
||||
ChooseForumContainerFragment.ChooseForumType.ATTENTION.value -> {
|
||||
mApi.getFollowsForum(UserManager.getInstance().userId)
|
||||
}
|
||||
ChooseForumContainerFragment.ChooseForumType.HOT.value -> {
|
||||
mApi.hotForum
|
||||
}
|
||||
else -> {
|
||||
mApi.searchBbs(searchKey, page)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setSearchKeyAndRefresh(searchKey: String) {
|
||||
this.searchKey = searchKey
|
||||
load(LoadType.REFRESH)
|
||||
}
|
||||
|
||||
override fun mergeResultLiveData() {
|
||||
mResultLiveData.addSource<List<ForumEntity>>(mListLiveData) { mResultLiveData.postValue(it) }
|
||||
}
|
||||
|
||||
class Factory(val type: String) : ViewModelProvider.NewInstanceFactory() {
|
||||
class Factory(val type: String, val searchKey: String) : ViewModelProvider.NewInstanceFactory() {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return ChooseForumContainerViewModel(HaloApp.getInstance().application, type) as T
|
||||
return ChooseForumContainerViewModel(HaloApp.getInstance().application, type, searchKey) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2648,6 +2648,12 @@ public interface ApiService {
|
||||
@GET("./bbses:hot")
|
||||
Observable<List<ForumEntity>> getHotForum();
|
||||
|
||||
/**
|
||||
* 搜索论坛
|
||||
*/
|
||||
@GET("./bbses:search_name")
|
||||
Observable<List<ForumEntity>> searchBbs(@Query("keyword") String keyword, @Query("page") int page);
|
||||
|
||||
/**
|
||||
* 热门论坛列表
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user