Skip to content

Commit

Permalink
avoid concatenating text
Browse files Browse the repository at this point in the history
  • Loading branch information
rlam20 committed Jul 2, 2024
1 parent dfb4aa4 commit ba4eb9e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ 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 @@ -85,16 +90,18 @@ 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 @@ -137,12 +144,22 @@ 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 @@ -171,25 +188,48 @@ 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) {
0 -> {
listContent.visibility = View.GONE
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 @@ -202,27 +242,31 @@ 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>) {
hideRv(tab, String.format(getString(R.string.courses_colon) + " (%s)", courses.size))
listContent.adapter = ArrayAdapter(requireActivity(), android.R.layout.simple_list_item_1, courses)
listContent.onItemClickListener = AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, i: Int, _: Long ->
if (homeItemClickListener != null) {
openFragment(courses[i]?.courseId, TakeCourseFragment())
listContent.adapter =
ArrayAdapter(requireActivity(), android.R.layout.simple_list_item_1, courses)
listContent.onItemClickListener =
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, i: Int, _: Long ->
if (homeItemClickListener != null) {
openFragment(courses[i]?.courseId, TakeCourseFragment())
}
}
}
}

private fun hideRv(tab: TabLayout.Tab, s: String) {
Expand All @@ -236,14 +280,15 @@ class MyTeamsDetailFragment : BaseNewsFragment() {
llRv.visibility = View.GONE
tab.setText(s)
listContent.adapter = object : ArrayAdapter<RealmUserModel?>(requireActivity(), android.R.layout.simple_list_item_1, data) {
override fun getView(position: Int, convert_View: View?, parent: ViewGroup): View {
var convertView = convert_View
override fun getView(position: Int, viewConverted: View?, parent: ViewGroup): View {
var convertView = viewConverted
if (convertView == null) {
convertView = LayoutInflater.from(activity)
.inflate(android.R.layout.simple_list_item_1, parent, false)
}
val tv = convertView!!.findViewById<TextView>(android.R.id.text1)
tv.text = getItem(position)?.name + " (" + getVisitCount(mRealm, getItem(position)?.name, teamId) + getString(R.string.visits) + ")"
val formattedText = getString(R.string.visit_count, getItem(position)?.name ?: "", getVisitCount(mRealm, getItem(position)?.name, teamId), getString(R.string.visits))
tv.text = formattedText
return convertView
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,7 @@
<string name="checking_server">جارٍ فحص الخادم</string>
<string name="below_min_apk">إصدار Apk أقل من المسموح. يرجى تحديث التطبيق إلى أحدث إصدار.</string>
<string name="add_note">إضافة ملاحظة (اختياري)</string>
<string name="visit_count">%s (%d %s)</string>
<string name="visit_count">%s (%d %s)</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,7 @@
<string name="checking_server">verificando el servidor</string>
<string name="below_min_apk">la versión de la aplicación está por debajo de la permitida. Actualice la aplicación a la última versión.</string>
<string name="add_note">Agregar una nota (opcional)</string>
<string name="visit_count">%s (%d %s)</string>
<string name="visit_count">%s (%d %s)</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,7 @@
<string name="checking_server">vérification du serveur</string>
<string name="below_min_apk">la version de l\'app est inférieure à celle autorisée. veuillez mettre à jour l\'application vers la dernière version.</string>
<string name="add_note">Ajouter une note (optionnel)</string>
<string name="visit_count">%s (%d %s)</string>
<string name="visit_count">%s (%d %s)</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,6 @@
<string name="checking_server">सर्भर जाँच गर्दै</string>
<string name="below_min_apk">एप संस्करण अनुमत संस्करणभन्दा कम छ। कृपया अनुप्रयोगलाई नवीनतम संस्करणमा अद्यावधिक गर्नुहोस्।</string>
<string name="add_note">नोट थप्नुहोस् (वैकल्पिक)</string>
<string name="visit_count">%s (%d %s)</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-so/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,7 @@
<string name="checking_server">hubinta server-ka</string>
<string name="below_min_apk">nooca app-ga waa ka hooseeyaa kan la oggol yahay. fadlan cusbooneysii app-ka nooca ugu dambeeya.</string>
<string name="add_note">Ku dar falanqeey (ixtiyaacsi ah)</string>
<string name="visit_count">%s (%d %s)</string>
<string name="visit_count">%s (%d %s)</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<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

0 comments on commit ba4eb9e

Please sign in to comment.