Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Jul 3, 2024
1 parent 5fb36d4 commit d2fe551
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,8 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
fragmentMyTeamsDetailBinding =
FragmentMyTeamsDetailBinding.inflate(inflater, container, false)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
fragmentMyTeamsDetailBinding = FragmentMyTeamsDetailBinding.inflate(inflater, container, false)
val v: View = fragmentMyTeamsDetailBinding.root
initializeViews(v)
dbService = DatabaseService(requireActivity())
Expand All @@ -90,18 +85,16 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
tvDescription = v.findViewById(R.id.description)
tabLayout = v.findViewById(R.id.tab_layout)
listContent = v.findViewById(R.id.list_content)
fragmentMyTeamsDetailBinding.btnInvite.visibility =
if (showBetaFeature(Constants.KEY_MEETUPS, requireContext())) {
View.VISIBLE
} else {
View.GONE
}
fragmentMyTeamsDetailBinding.btnLeave.visibility =
if (showBetaFeature(Constants.KEY_MEETUPS, requireContext())) {
View.VISIBLE
} else {
View.GONE
}
fragmentMyTeamsDetailBinding.btnInvite.visibility = if (showBetaFeature(Constants.KEY_MEETUPS, requireContext())) {
View.VISIBLE
} else {
View.GONE
}
fragmentMyTeamsDetailBinding.btnLeave.visibility = if (showBetaFeature(Constants.KEY_MEETUPS, requireContext())) {
View.VISIBLE
} else {
View.GONE
}
v.findViewById<View>(R.id.add_message).setOnClickListener { showAddMessage() }
}

Expand Down Expand Up @@ -144,22 +137,12 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
rvDiscussion.layoutManager = LinearLayoutManager(activity)
showRecyclerView(realmNewsList)
listContent.visibility = View.GONE
val courses = mRealm.where(RealmMyCourse::class.java)
.`in`("id", team?.courses?.toTypedArray<String>()).findAll()
libraries = mRealm.where(RealmMyLibrary::class.java)
.`in`("id", getResourceIds(teamId, mRealm).toTypedArray<String>()).findAll()
tabLayout.getTabAt(1)
?.setText(String.format(getString(R.string.joined_members_colon) + " (%s)", users.size))
tabLayout.getTabAt(3)
?.setText(String.format(getString(R.string.courses_colon) + " (%s)", courses.size))
tabLayout.getTabAt(2)?.setText(
String.format(
getString(R.string.requested_members_colon) + " (%s)",
reqUsers.size
)
)
tabLayout.getTabAt(4)
?.setText(String.format(getString(R.string.resources_colon) + " (%s)", libraries?.size))
val courses = mRealm.where(RealmMyCourse::class.java).`in`("id", team?.courses?.toTypedArray<String>()).findAll()
libraries = mRealm.where(RealmMyLibrary::class.java).`in`("id", getResourceIds(teamId, mRealm).toTypedArray<String>()).findAll()
tabLayout.getTabAt(1)?.setText(String.format(getString(R.string.joined_members_colon) + " (%s)", users.size))
tabLayout.getTabAt(3)?.setText(String.format(getString(R.string.courses_colon) + " (%s)", courses.size))
tabLayout.getTabAt(2)?.setText(String.format(getString(R.string.requested_members_colon) + " (%s)", reqUsers.size))
tabLayout.getTabAt(4)?.setText(String.format(getString(R.string.resources_colon) + " (%s)", libraries?.size))
if (!isMyTeam) {
try {
(tabLayout.getChildAt(0) as ViewGroup).getChildAt(0).visibility = View.GONE
Expand Down Expand Up @@ -188,22 +171,16 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
}

private fun showRecyclerView(realmNewsList: List<RealmNews?>?) {
val adapterNews = activity?.let {
realmNewsList?.let { it1 ->
AdapterNews(it, it1.toMutableList(), user, null)
}
}
val adapterNews = activity?.let { realmNewsList?.let { it1 ->
AdapterNews(it, it1.toMutableList(), user, null)
} }
adapterNews?.setmRealm(mRealm)
adapterNews?.setListener(this)
rvDiscussion.adapter = adapterNews
llRv.visibility = View.VISIBLE
}

private fun setTabListener(
users: List<RealmUserModel>,
courses: RealmResults<RealmMyCourse>,
reqUsers: List<RealmUserModel>
) {
private fun setTabListener(users: List<RealmUserModel>, courses: RealmResults<RealmMyCourse>, reqUsers: List<RealmUserModel>) {
tabLayout.addOnTabSelectedListener(object : OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
when (tab.position) {
Expand All @@ -212,24 +189,8 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
llRv.visibility = View.VISIBLE
}

1 -> setListContent(
tab,
String.format(
getString(R.string.joined_members_colon) + " (%s)",
users.size
),
users
)

2 -> setListContent(
tab,
String.format(
getString(R.string.requested_members_colon) + " (%s)",
reqUsers.size
),
reqUsers
)

1 -> setListContent(tab, String.format(getString(R.string.joined_members_colon) + " (%s)", users.size), users)
2 -> setListContent(tab, String.format(getString(R.string.requested_members_colon) + " (%s)", reqUsers.size), reqUsers)
3 -> setCourseList(tab, courses)
4 -> setLibraryList(tab)
}
Expand All @@ -242,19 +203,17 @@ class MyTeamsDetailFragment : BaseNewsFragment() {

private fun setLibraryList(tab: TabLayout.Tab) {
hideRv(tab, String.format(getString(R.string.resources_colon) + " (%s)", libraries?.size))
listContent.adapter =
ArrayAdapter(requireActivity(), android.R.layout.simple_list_item_1, libraries!!)
listContent.onItemClickListener =
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, i: Int, _: Long ->
if (homeItemClickListener != null) {
val f = ResourceDetailFragment()
val b = Bundle()
b.putString("libraryId", libraries!![i]?.id)
b.putString("openFrom", team?.teamType + "-" + team?.title)
f.arguments = b
homeItemClickListener?.openCallFragment(f)
}
listContent.adapter = ArrayAdapter(requireActivity(), android.R.layout.simple_list_item_1, libraries!!)
listContent.onItemClickListener = AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, i: Int, _: Long ->
if (homeItemClickListener != null) {
val f = ResourceDetailFragment()
val b = Bundle()
b.putString("libraryId", libraries!![i]?.id)
b.putString("openFrom", team?.teamType + "-" + team?.title)
f.arguments = b
homeItemClickListener?.openCallFragment(f)
}
}
}

private fun setCourseList(tab: TabLayout.Tab, courses: RealmResults<RealmMyCourse>) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
<string name="showing_reply_of">Showing reply of:</string>
<string name="open_date">Open Date</string>
<string name="my_survey">mySurvey</string>
<string name="visit_count">%s (%d %s)</string>

<string-array name="level">
<item></item>
Expand Down Expand Up @@ -1047,6 +1046,7 @@
<string name="checking_server">checking server</string>
<string name="below_min_apk">app is below allowed version. please update the app to the latest version.</string>
<string name="add_note">add a note (optional)</string>
<string name="visit_count">%s (%d %s)</string>
<string name="planet_name">%s\'s Planet</string>
<string name="no_submissions">submissions not available</string>
<string name="no_chats">no previous chats</string>
Expand Down

0 comments on commit d2fe551

Please sign in to comment.