Skip to content

Commit 6a20b94

Browse files
anhanh11001iamareebjamal
authored andcommitted
refactor: Add string format (#2181)
Details: - Add string format - Use Koitlin isVisible Fixes: #2180
1 parent c5bc854 commit 6a20b94

File tree

9 files changed

+57
-34
lines changed

9 files changed

+57
-34
lines changed

app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
306306
}
307307

308308
private fun setupTicketDetailTable() {
309-
rootView.qty.text = "${attendeeViewModel.ticketIdAndQty?.map { it.second }?.sum()} items"
309+
attendeeViewModel.ticketIdAndQty?.map { it.second }?.sum()?.let {
310+
rootView.qty.text = resources.getQuantityString(R.plurals.order_quantity_item, it, it)
311+
}
310312
rootView.ticketsRecycler.layoutManager = LinearLayoutManager(activity)
311313
rootView.ticketsRecycler.adapter = ticketsRecyclerAdapter
312314
rootView.ticketsRecycler.isNestedScrollingEnabled = false
@@ -809,13 +811,13 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
809811
rootView.eventName.text = event.name
810812
val total = if (safeArgs.amount > 0) "${attendeeViewModel.paymentCurrency} ${"%.2f".format(safeArgs.amount)}"
811813
else getString(R.string.free)
812-
rootView.amount.text = "Total: $total"
814+
rootView.amount.text = getString(R.string.total_amount, total)
813815

814816
rootView.time.text = EventUtils.getFormattedDateTimeRangeDetailed(startsAt, endsAt)
815817
}
816818

817819
private fun loadUserUI(user: User) {
818-
rootView.helloUser.text = "Hello ${user.firstName.nullToEmpty()}"
820+
rootView.helloUser.text = getString(R.string.hello_user, user.firstName.nullToEmpty())
819821
rootView.firstName.text = SpannableStringBuilder(user.firstName.nullToEmpty())
820822
rootView.lastName.text = SpannableStringBuilder(user.lastName.nullToEmpty())
821823
rootView.email.text = SpannableStringBuilder(user.email.nullToEmpty())

app/src/main/java/org/fossasia/openevent/general/event/EventDetailsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ class EventDetailsFragment : Fragment() {
753753
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = true
754754
layout.feedbackTextInputLayout.isErrorEnabled = false
755755
} else {
756-
layout.feedbackTextInputLayout.error = "Can't be Empty"
756+
layout.feedbackTextInputLayout.error = getString(R.string.cant_be_empty)
757757
}
758758
}
759759

app/src/main/java/org/fossasia/openevent/general/favorite/FavoriteFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class FavoriteFragment : Fragment(), BottomIconDoubleClick {
9191
.nonNull()
9292
.observe(viewLifecycleOwner, Observer { list ->
9393
favoriteEventsRecyclerAdapter.submitList(list.sortedBy { getEventDateTime(it.startsAt, it.timezone) })
94-
rootView.likesNumber.text = "${list.size} likes"
94+
rootView.likesNumber.text = resources.getQuantityString(R.plurals.likes_number, list.size, list.size)
9595
showEmptyMessage(list.size)
9696
Timber.d("Fetched events of size %s", list.size)
9797
})

app/src/main/java/org/fossasia/openevent/general/search/SearchFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ class SearchFragment : Fragment(), ComplexBackPressFragment, BottomIconDoubleCli
145145
override fun removeSearch(position: Int, recentSearch: Pair<String, String>) {
146146
adapter.removeRecentSearchAt(position)
147147
searchViewModel.removeRecentSearch(position)
148-
rootView.snackbar("Removed recent search ${recentSearch.first}", getString(R.string.undo)) {
148+
rootView.snackbar(getString(R.string.removed_recent_search, recentSearch.first),
149+
getString(R.string.undo)) {
149150
adapter.addRecentSearch(position, recentSearch)
150151
searchViewModel.saveRecentSearch(recentSearch.first, recentSearch.second, position)
151152
}

app/src/main/java/org/fossasia/openevent/general/search/type/SearchTypeFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SearchTypeFragment : Fragment() {
2828
private val searchTypeViewModel by viewModel<SearchTypeViewModel>()
2929
private val safeArgs: SearchTypeFragmentArgs by navArgs()
3030
private lateinit var rootView: View
31-
private val eventTypesList: MutableList<String> = arrayListOf("Anything")
31+
private val eventTypesList: MutableList<String> = arrayListOf(getString(R.string.anything))
3232

3333
override fun onCreateView(
3434
inflater: LayoutInflater,

app/src/main/java/org/fossasia/openevent/general/sessions/SessionFragment.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.view.LayoutInflater
99
import android.view.MenuItem
1010
import android.view.View
1111
import android.view.ViewGroup
12+
import androidx.core.view.isVisible
1213
import androidx.fragment.app.Fragment
1314
import androidx.lifecycle.Observer
1415
import androidx.navigation.fragment.navArgs
@@ -70,7 +71,7 @@ class SessionFragment : Fragment() {
7071
.observe(viewLifecycleOwner, Observer {
7172
rootView.snackbar(it)
7273
if (it == getString(R.string.error_fetching_speakers_for_session)) {
73-
rootView.sessionDetailSpeakersContainer.visibility = View.GONE
74+
rootView.sessionDetailSpeakersContainer.isVisible = false
7475
}
7576
})
7677

@@ -83,18 +84,18 @@ class SessionFragment : Fragment() {
8384
sessionViewModel.progress
8485
.nonNull()
8586
.observe(viewLifecycleOwner, Observer {
86-
rootView.progressBar.visibility = if (it) View.VISIBLE else View.GONE
87-
rootView.sessionDetailContainer.visibility = if (it) View.GONE else View.VISIBLE
87+
rootView.progressBar.isVisible = it
88+
rootView.sessionDetailContainer.isVisible = !it
8889
})
8990

9091
sessionViewModel.speakersUnderSession
9192
.nonNull()
9293
.observe(viewLifecycleOwner, Observer {
9394
speakersAdapter.addAll(it)
9495
if (it.isEmpty())
95-
rootView.sessionDetailSpeakersContainer.visibility = View.GONE
96+
rootView.sessionDetailSpeakersContainer.isVisible = false
9697
else
97-
rootView.speakersProgressBar.visibility = View.GONE
98+
rootView.speakersProgressBar.isVisible = false
9899
})
99100

100101
sessionViewModel.loadSession(safeArgs.sessionId)
@@ -104,9 +105,9 @@ class SessionFragment : Fragment() {
104105
else {
105106
speakersAdapter.addAll(currentSpeakers)
106107
if (currentSpeakers.isEmpty())
107-
rootView.sessionDetailSpeakersContainer.visibility = View.GONE
108+
rootView.sessionDetailSpeakersContainer.isVisible = false
108109
else
109-
rootView.speakersProgressBar.visibility = View.GONE
110+
rootView.speakersProgressBar.isVisible = false
110111
}
111112

112113
val layoutManager = LinearLayoutManager(context)
@@ -152,7 +153,7 @@ class SessionFragment : Fragment() {
152153

153154
private fun makeSessionView(session: Session) {
154155
when (session.title.isNullOrBlank()) {
155-
true -> rootView.sessionDetailName.visibility = View.GONE
156+
true -> rootView.sessionDetailName.isVisible = false
156157
false -> {
157158
rootView.sessionDetailName.text = session.title
158159
setToolbar(activity, session.title)
@@ -161,20 +162,20 @@ class SessionFragment : Fragment() {
161162

162163
val type = session.sessionType
163164
if (type == null) {
164-
rootView.sessionDetailType.visibility = View.GONE
165+
rootView.sessionDetailType.isVisible = false
165166
} else {
166-
rootView.sessionDetailType.text = "Type: ${type.name}"
167+
rootView.sessionDetailType.text = getString(R.string.type_name, type.name)
167168
}
168169

169170
val locationInfo = session.microlocation
170171
if (locationInfo == null) {
171-
rootView.sessionDetailLocationInfoContainer.visibility = View.GONE
172-
rootView.sessionDetailLocationContainer.visibility = View.GONE
172+
rootView.sessionDetailLocationInfoContainer.isVisible = false
173+
rootView.sessionDetailLocationContainer.isVisible = false
173174
} else {
174175
rootView.sessionDetailInfoLocation.text = locationInfo.name
175176
rootView.sessionDetailLocation.text = locationInfo.name
176177
if (locationInfo.latitude.isNullOrBlank() || locationInfo.longitude.isNullOrBlank()) {
177-
rootView.sessionDetailLocationImageMap.visibility = View.GONE
178+
rootView.sessionDetailLocationImageMap.isVisible = false
178179
} else {
179180
rootView.sessionDetailLocationContainer.setOnClickListener {
180181
startMap(locationInfo.latitude, locationInfo.longitude)
@@ -191,12 +192,12 @@ class SessionFragment : Fragment() {
191192
}
192193

193194
when (session.language.isNullOrBlank()) {
194-
true -> rootView.sessionDetailLanguageContainer.visibility = View.GONE
195+
true -> rootView.sessionDetailLanguageContainer.isVisible = false
195196
false -> rootView.sessionDetailLanguage.text = session.language
196197
}
197198

198199
when (session.startsAt.isNullOrBlank()) {
199-
true -> rootView.sessionDetailStartTime.visibility = View.GONE
200+
true -> rootView.sessionDetailStartTime.isVisible = false
200201
false -> {
201202
val formattedStartTime = EventUtils.getEventDateTime(session.startsAt, "")
202203
val formattedTime = EventUtils.getFormattedTime(formattedStartTime)
@@ -206,7 +207,7 @@ class SessionFragment : Fragment() {
206207
}
207208
}
208209
when (session.endsAt.isNullOrBlank()) {
209-
true -> rootView.sessionDetailEndTime.visibility = View.GONE
210+
true -> rootView.sessionDetailEndTime.isVisible = false
210211
false -> {
211212
val formattedEndTime = EventUtils.getEventDateTime(session.endsAt, "")
212213
val formattedTime = EventUtils.getFormattedTime(formattedEndTime)
@@ -216,15 +217,15 @@ class SessionFragment : Fragment() {
216217
}
217218
}
218219
if (session.startsAt.isNullOrBlank() && session.endsAt.isNullOrBlank())
219-
rootView.sessionDetailTimeContainer.visibility = View.GONE
220+
rootView.sessionDetailTimeContainer.isVisible = false
220221
else
221222
rootView.sessionDetailTimeContainer.setOnClickListener {
222223
saveSessionToCalendar(session)
223224
}
224225

225226
val description = session.longAbstract ?: session.shortAbstract
226227
when (description.isNullOrBlank()) {
227-
true -> rootView.sessionDetailAbstractContainer.visibility = View.GONE
228+
true -> rootView.sessionDetailAbstractContainer.isVisible = false
228229
false -> {
229230
rootView.sessionDetailAbstract.text = description.stripHtml()
230231
val sessionAbstractClickListener = View.OnClickListener {
@@ -240,7 +241,7 @@ class SessionFragment : Fragment() {
240241

241242
rootView.sessionDetailAbstract.post {
242243
if (rootView.sessionDetailAbstract.lineCount > LINE_COUNT_ABSTRACT) {
243-
rootView.sessionDetailAbstractSeeMore.visibility = View.VISIBLE
244+
rootView.sessionDetailAbstractSeeMore.isVisible = true
244245
rootView.sessionDetailAbstractContainer.setOnClickListener(sessionAbstractClickListener)
245246
}
246247
}
@@ -249,7 +250,7 @@ class SessionFragment : Fragment() {
249250

250251
val track = session.track
251252
when (track == null) {
252-
true -> rootView.sessionDetailTrackContainer.visibility = View.GONE
253+
true -> rootView.sessionDetailTrackContainer.isVisible = false
253254
false -> {
254255
rootView.sessionDetailTrack.text = track.name
255256
val trackColor = Color.parseColor(track.color)
@@ -259,7 +260,7 @@ class SessionFragment : Fragment() {
259260
}
260261

261262
when (session.signupUrl.isNullOrBlank()) {
262-
true -> rootView.sessionDetailSignUpButton.visibility = View.GONE
263+
true -> rootView.sessionDetailSignUpButton.isVisible = false
263264
false -> rootView.sessionDetailSignUpButton.setOnClickListener {
264265
context?.let { Utils.openUrl(it, session.signupUrl) }
265266
}

app/src/main/java/org/fossasia/openevent/general/speakers/SpeakerFragment.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ class SpeakerFragment : Fragment() {
8383
else {
8484
when (speaker.email.isNullOrBlank()) {
8585
true -> rootView.email.isVisible = false
86-
false -> rootView.email.text = "Email: ${speaker.email}"
86+
false -> rootView.email.text = getString(R.string.email_name, speaker.email)
8787
}
8888

8989
when (speaker.mobile.isNullOrBlank()) {
9090
true -> rootView.mobile.isVisible = false
91-
false -> rootView.mobile.text = "Phone Number: ${speaker.mobile}"
91+
false -> rootView.mobile.text = getString(R.string.phone_number_name, speaker.mobile)
9292
}
9393

9494
when {
9595
speaker.country.isNullOrBlank() && speaker.country.isNullOrBlank() -> rootView.from.isVisible = false
96-
speaker.country.isNullOrBlank() -> rootView.from.text = "From: ${speaker.city}"
97-
speaker.city.isNullOrBlank() -> rootView.from.text = "From: ${speaker.country}"
98-
else -> rootView.from.text = "From: ${speaker.city}, ${speaker.country}"
96+
speaker.country.isNullOrBlank() -> rootView.from.text = getString(R.string.from_place, speaker.city)
97+
speaker.city.isNullOrBlank() -> rootView.from.text = getString(R.string.from_place, speaker.country)
98+
else -> rootView.from.text = getString(R.string.from_places, speaker.city, speaker.country)
9999
}
100100

101101
when (speaker.website.isNullOrBlank()) {

app/src/main/java/org/fossasia/openevent/general/ticket/TicketsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class TicketsFragment : Fragment() {
257257
rootView.organizerName.isVisible = false
258258
} else {
259259
rootView.organizerName.isVisible = true
260-
rootView.organizerName.text = "by $organizerName"
260+
rootView.organizerName.text = getString(R.string.by_organizer_name, organizerName)
261261
}
262262
val startsAt = EventUtils.getEventDateTime(event.startsAt, event.timezone)
263263
val endsAt = EventUtils.getEventDateTime(event.endsAt, event.timezone)

app/src/main/res/values/strings.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,5 +495,24 @@
495495
<string name="language">Language</string>
496496
<string name="no_sessions_created_message">You haven\'t created any sessions for this speaker</string>
497497
<string name="proposal_creaed_updated_message">Proposal created/updated successfully</string>
498+
<string name="total_amount">Total: %1$s</string>
499+
<plurals name="order_quantity_item">
500+
<item quantity="one"> — %1$s item</item>
501+
<item quantity="other"> — %1$s items</item>
502+
</plurals>
503+
<string name="hello_user">Hello %1$s</string>
504+
<string name="cant_be_empty">Can\'t be Empty</string>
505+
<plurals name="likes_number">
506+
<item quantity="zero">No likes</item>
507+
<item quantity="one">%1$s like</item>
508+
<item quantity="other">%1$s likes</item>
509+
</plurals>
510+
<string name="removed_recent_search">Removed recent search %1$s</string>
511+
<string name="type_name">Type: %1$s</string>
512+
<string name="email_name">Email: %1$s</string>
513+
<string name="phone_number_name">Phone Number: %1$s</string>
514+
<string name="from_place">From: %1$s</string>
515+
<string name="from_places">From: %1$s, %2$s</string>
516+
<string name="by_organizer_name">by %1$s</string>
498517

499518
</resources>

0 commit comments

Comments
 (0)