From 15c1fc8ee4090af334c3d228ef271814d5e39969 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 7 Nov 2019 12:55:57 +0100 Subject: [PATCH] change guild overview view binding --- .../res/layout/fragment_guilds_overview.xml | 7 +-- .../social/GuildsOverviewFragment.kt | 51 +++++++------------ 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/Habitica/res/layout/fragment_guilds_overview.xml b/Habitica/res/layout/fragment_guilds_overview.xml index caf6e3316..e16c5052f 100644 --- a/Habitica/res/layout/fragment_guilds_overview.xml +++ b/Habitica/res/layout/fragment_guilds_overview.xml @@ -2,7 +2,7 @@ @@ -12,16 +12,13 @@ - + android:orientation="vertical"> - ? = null private var guildIDs: ArrayList? = null @@ -46,7 +40,8 @@ class GuildsOverviewFragment : BaseMainFragment(), View.OnClickListener, android override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { super.onCreateView(inflater, container, savedInstanceState) - return container?.inflate(R.layout.fragment_guilds_overview) + binding = FragmentGuildsOverviewBinding.inflate(inflater, container, false) + return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -54,8 +49,10 @@ class GuildsOverviewFragment : BaseMainFragment(), View.OnClickListener, android resetViews() - swipeRefreshLayout?.setOnRefreshListener(this) - this.publicGuildsButton?.setOnClickListener(this) + binding?.refreshLayout?.setOnRefreshListener(this) + binding?.publicGuildsButton?.setOnClickListener { + MainNavigationController.navigate(GuildsOverviewFragmentDirections.openPublicGuilds()) + } compositeSubscription.add(socialRepository.getUserGroups().subscribe(Consumer { this.setGuilds(it) }, RxErrorHandler.handleEmptyError())) } override fun onDestroy() { @@ -69,45 +66,33 @@ class GuildsOverviewFragment : BaseMainFragment(), View.OnClickListener, android } override fun onRefresh() { - if (swipeRefreshLayout != null) { - swipeRefreshLayout?.isRefreshing = true - } + binding?.refreshLayout?.isRefreshing = true fetchGuilds() } private fun fetchGuilds() { compositeSubscription.add(this.socialRepository.retrieveGroups("guilds") .subscribe(Consumer { - swipeRefreshLayout?.isRefreshing = false + binding?.refreshLayout?.isRefreshing = false }, RxErrorHandler.handleEmptyError())) } private fun setGuilds(guilds: RealmResults) { this.guilds = guilds - if (this.guildsListView == null) { + if (binding?.myGuildsListview == null) { return } this.guildIDs = ArrayList() - this.guildsListView?.removeAllViewsInLayout() + binding?.myGuildsListview?.removeAllViewsInLayout() val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater for (guild in guilds) { - val entry = inflater?.inflate(R.layout.plain_list_item, this.guildsListView, false) as? TextView + val entry = inflater?.inflate(R.layout.plain_list_item, binding?.myGuildsListview, false) as? TextView entry?.text = guild.name - entry?.setOnClickListener(this) - this.guildsListView?.addView(entry) + entry?.setOnClickListener { + MainNavigationController.navigate(GuildsOverviewFragmentDirections.openGuildDetail(guild.id)) + } + binding?.myGuildsListview?.addView(entry) this.guildIDs?.add(guild.id) } } - - override fun onClick(v: View) { - if (v === this.publicGuildsButton) { - MainNavigationController.navigate(GuildsOverviewFragmentDirections.openPublicGuilds()) - } else { - val guildIndex = (v.parent as? ViewGroup)?.indexOfChild(v) - val guildId = this.guilds?.get(guildIndex ?: 0)?.id ?: return - MainNavigationController.navigate(GuildsOverviewFragmentDirections.openGuildDetail(guildId)) - } - } - - }