Skip to content

refractor: Replace all hard-coded string messages #1272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import androidx.lifecycle.ViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.common.SingleLiveEvent
import org.fossasia.openevent.general.data.Resource
import org.fossasia.openevent.general.event.Event
import org.fossasia.openevent.general.event.EventService
import timber.log.Timber

class AboutEventViewModel(private val eventService: EventService) : ViewModel() {
class AboutEventViewModel(private val eventService: EventService, private val resource: Resource) : ViewModel() {

private val compositeDisposable = CompositeDisposable()

Expand All @@ -24,7 +26,7 @@ class AboutEventViewModel(private val eventService: EventService) : ViewModel()

fun loadEvent(id: Long) {
if (id.equals(-1)) {
mutableError.value = "Error fetching event"
mutableError.value = Resource().getString(R.string.error_fetching_event_message)
return
}
compositeDisposable.add(eventService.getEvent(id)
Expand All @@ -37,7 +39,7 @@ class AboutEventViewModel(private val eventService: EventService) : ViewModel()
}.subscribe({ eventList ->
mutableEvent.value = eventList
}, {
mutableError.value = "Error fetching event"
mutableError.value = resource.getString(R.string.error_fetching_event_message)
Timber.e(it, "Error fetching event %d", id)
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class AttendeeFragment : Fragment() {
private var selectedPaymentOption: Int = -1
private lateinit var paymentCurrency: String
private var expiryMonth: Int = -1
private lateinit var expiryYear: String
private lateinit var cardBrand: String
private var expiryYear: String? = null
private var cardBrand: String? = null
private lateinit var API_KEY: String
private var singleTicket = false
private var identifierList = ArrayList<String>()
Expand Down Expand Up @@ -316,11 +316,14 @@ class AttendeeFragment : Fragment() {
})

rootView.view.setOnClickListener {
val currentVisibility: Boolean? = attendeeViewModel.ticketDetailsVisibility.value
if (currentVisibility == null) {
attendeeViewModel.ticketDetailsVisibility.value = false
val currentVisibility: Boolean = attendeeViewModel.ticketDetailsVisibility.value ?: false
if (rootView.view.text == context?.getString(R.string.view)) {
rootView.ticketDetails.visibility = View.VISIBLE
rootView.view.text = context?.getString(R.string.hide)
} else {
attendeeViewModel.ticketDetailsVisibility.value = !currentVisibility
rootView.ticketDetails.visibility = View.GONE
rootView.view.text = context?.getString(R.string.view)
}
}

Expand Down Expand Up @@ -432,12 +435,13 @@ class AttendeeFragment : Fragment() {

rootView.register.setOnClickListener {
if (!isNetworkConnected(context)) {
Snackbar.make(rootView.attendeeScrollView, "No internet connection!", Snackbar.LENGTH_LONG).show()
Snackbar.make(rootView.attendeeScrollView, getString(R.string.no_internet_connection_message),
Snackbar.LENGTH_LONG).show()
return@setOnClickListener
}
if (!rootView.acceptCheckbox.isChecked) {
Snackbar.make(rootView.attendeeScrollView,
"Please accept the terms and conditions!", Snackbar.LENGTH_LONG).show()
getString(R.string.term_and_conditions), Snackbar.LENGTH_LONG).show()
return@setOnClickListener
}

Expand Down Expand Up @@ -473,7 +477,10 @@ class AttendeeFragment : Fragment() {
sendToken()
}
})
} else Snackbar.make(rootView.attendeeScrollView, "Invalid email address!", Snackbar.LENGTH_LONG).show()
} else {
Snackbar.make(rootView.attendeeScrollView,
getString(R.string.invalid_email_address_message), Snackbar.LENGTH_LONG).show()
}
}

builder.setNegativeButton(android.R.string.no) { dialog, which ->
Expand Down Expand Up @@ -508,7 +515,7 @@ class AttendeeFragment : Fragment() {
}

private fun sendToken() {
val card = Card(cardNumber.text.toString(), expiryMonth, expiryYear.toInt(), cvc.text.toString())
val card = Card(cardNumber.text.toString(), expiryMonth, expiryYear?.toInt(), cvc.text.toString())
card.addressCountry = rootView.countryPicker.selectedItem.toString()
card.addressZip = postalCode.text.toString()

Expand All @@ -518,7 +525,7 @@ class AttendeeFragment : Fragment() {
val validDetails: Boolean? = card.validateCard()
if (validDetails != null && !validDetails)
Snackbar.make(
rootView, "Invalid card data", Snackbar.LENGTH_SHORT
rootView, getString(R.string.invalid_card_data_message), Snackbar.LENGTH_SHORT
).show()
else
Stripe(requireContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import androidx.lifecycle.ViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.attendees.forms.CustomForm
import org.fossasia.openevent.general.auth.AuthHolder
import org.fossasia.openevent.general.auth.AuthService
import org.fossasia.openevent.general.auth.User
import org.fossasia.openevent.general.common.SingleLiveEvent
import org.fossasia.openevent.general.data.Resource
import org.fossasia.openevent.general.event.Event
import org.fossasia.openevent.general.event.EventId
import org.fossasia.openevent.general.event.EventService
Expand All @@ -31,7 +33,8 @@ class AttendeeViewModel(
private val eventService: EventService,
private val orderService: OrderService,
private val ticketService: TicketService,
private val authService: AuthService
private val authService: AuthService,
private val resource: Resource
) : ViewModel() {

private val compositeDisposable = CompositeDisposable()
Expand Down Expand Up @@ -65,10 +68,10 @@ class AttendeeViewModel(
private val mutableIsAttendeeCreated = MutableLiveData<Boolean>()
val isAttendeeCreated: LiveData<Boolean> = mutableIsAttendeeCreated

val month = ArrayList<String>()
val year = ArrayList<String>()
val month = ArrayList<String?>()
val year = ArrayList<String?>()
val attendees = ArrayList<Attendee>()
val cardType = ArrayList<String>()
val cardType = ArrayList<String?>()
var isAllDetailsFilled = true

private var createAttendeeIterations = 0
Expand All @@ -83,36 +86,36 @@ class AttendeeViewModel(

fun initializeSpinner() {
// initialize months
month.add("Month")
month.add("January")
month.add("February")
month.add("March")
month.add("April")
month.add("May")
month.add("June")
month.add("July")
month.add("August")
month.add("September")
month.add("October")
month.add("November")
month.add("December")
month.add(resource.getString(R.string.month_string))
month.add(resource.getString(R.string.january))
month.add(resource.getString(R.string.february))
month.add(resource.getString(R.string.march))
month.add(resource.getString(R.string.april))
month.add(resource.getString(R.string.may))
month.add(resource.getString(R.string.june))
month.add(resource.getString(R.string.july))
month.add(resource.getString(R.string.august))
month.add(resource.getString(R.string.september))
month.add(resource.getString(R.string.october))
month.add(resource.getString(R.string.november))
month.add(resource.getString(R.string.december))

// initialize years
val currentYear = Calendar.getInstance().get(Calendar.YEAR)
year.add("Year")
year.add(resource.getString(R.string.year_string))
val a = currentYear + 20
for (i in currentYear..a) {
year.add(i.toString())
}

// initialize card types
cardType.add("Select a card type")
cardType.add("Pay by American Express")
cardType.add("Pay by MasterCard")
cardType.add("Pay by Visa")
cardType.add("Pay by Discover")
cardType.add("Pay by Diners Club")
cardType.add("Pay by UnionPay")
cardType.add(resource.getString(R.string.select_card))
cardType.add(resource.getString(R.string.american_express_pay_message))
cardType.add(resource.getString(R.string.mastercard_pay_message))
cardType.add(resource.getString(R.string.visa_pay_message))
cardType.add(resource.getString(R.string.discover_pay_message))
cardType.add(resource.getString(R.string.diners_pay_message))
cardType.add(resource.getString(R.string.unionpay_pay_message))
}

fun updatePaymentSelectorVisibility(ticketIdAndQty: List<Pair<Int, Int>>?) {
Expand Down Expand Up @@ -181,15 +184,15 @@ class AttendeeViewModel(
if (attendees.size == totalAttendee) {
loadTicketsAndCreateOrder()
mutableIsAttendeeCreated.value = true
mutableMessage.value = "Attendees created successfully!"
mutableMessage.value = resource.getString(R.string.create_attendee_success_message)
}
Timber.d("Success! %s", attendees.toList().toString())
}, {
if (createAttendeeIterations + 1 == totalAttendee)
if (it.message.equals(HttpErrors.CONFLICT)) {
mutableTicketSoldOut.value = true
} else {
mutableMessage.value = "Unable to create Attendee!"
mutableMessage.value = resource.getString(R.string.create_attendee_fail_message)
Timber.d(it, "Failed")
mutableTicketSoldOut.value = false
}
Expand All @@ -206,7 +209,7 @@ class AttendeeViewModel(
attendees.forEach {
if (it.email.isNullOrBlank() || it.firstname.isNullOrBlank() || it.lastname.isNullOrBlank()) {
if (isAllDetailsFilled)
mutableMessage.value = "Please fill in all the fields"
mutableMessage.value = resource.getString(R.string.fill_all_fields_message)
mutableIsAttendeeCreated.value = false
isAllDetailsFilled = false
return
Expand Down Expand Up @@ -252,9 +255,9 @@ class AttendeeViewModel(
private fun createOrder() {
val attendeeList = attendees.map { AttendeeId(it.id) }.toList()
var amount = totalAmount.value
var paymentMode = paymentOption.toLowerCase()
var paymentMode: String? = paymentOption.toLowerCase()
if (amount == null || amount <= 0) {
paymentMode = "free"
paymentMode = resource.getString(R.string.free)
amount = null
}
val eventId = event.value?.id
Expand All @@ -273,18 +276,18 @@ class AttendeeViewModel(
}.subscribe({
orderIdentifier = it.identifier.toString()
Timber.d("Success placing order!")
if (it.paymentMode == "free") {
if (it.paymentMode == resource.getString(R.string.free)) {
confirmOrder = ConfirmOrder(it.id.toString(), "completed")
confirmOrderStatus(it.identifier.toString(), confirmOrder)
} else mutableMessage.value = "Order created successfully!"
} else mutableMessage.value = resource.getString(R.string.order_success_message)
}, {
mutableMessage.value = "Unable to create Order!"
mutableMessage.value = resource.getString(R.string.order_fail_message)
Timber.d(it, "Failed creating Order")
deleteAttendees(order.attendees)
})
)
} else {
mutableMessage.value = "Unable to create Order!"
mutableMessage.value = resource.getString(R.string.order_fail_message)
}
}

Expand All @@ -297,11 +300,11 @@ class AttendeeViewModel(
}.doFinally {
mutableProgress.value = false
}.subscribe({
mutableMessage.value = "Order created successfully!"
mutableMessage.value = resource.getString(R.string.order_success_message)
Timber.d("Updated order status successfully !")
paymentCompleted.value = true
}, {
mutableMessage.value = "Unable to create Order!"
mutableMessage.value = resource.getString(R.string.order_fail_message)
Timber.d(it, "Failed updating order status")
})
)
Expand Down Expand Up @@ -356,7 +359,7 @@ class AttendeeViewModel(
Timber.d("Failed charging the user")
}
}, {
mutableMessage.value = "Payment not completed!"
mutableMessage.value = resource.getString(R.string.payment_not_complete_message)
Timber.d(it, "Failed charging the user")
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class EditProfileFragment : Fragment() {
.nonNull()
.observe(viewLifecycleOwner, Observer {
Snackbar.make(rootView.editProfileCoordinatorLayout, it, Snackbar.LENGTH_LONG).show()
if (it == USER_UPDATED) {
if (it == getString(R.string.user_update_success_message)) {
val thisActivity = activity
if (thisActivity is MainActivity) thisActivity.onSuperBackPressed()
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class EditProfileFragment : Fragment() {
val intent = Intent()
intent.type = "image/*"
intent.action = Intent.ACTION_GET_CONTENT
startActivityForResult(Intent.createChooser(intent, "Select Image"), PICK_IMAGE_REQUEST)
startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)), PICK_IMAGE_REQUEST)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
Expand All @@ -182,7 +182,7 @@ class EditProfileFragment : Fragment() {
override fun onResume() {
val activity = activity as? AppCompatActivity
activity?.supportActionBar?.setDisplayHomeAsUpEnabled(true)
activity?.supportActionBar?.title = "Edit Profile"
activity?.supportActionBar?.title = getString(R.string.edit_profile)
setHasOptionsMenu(true)
super.onResume()
}
Expand All @@ -196,12 +196,12 @@ class EditProfileFragment : Fragment() {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionGranted = true
Snackbar.make(
rootView.editProfileCoordinatorLayout, "Permission to Access External Storage Granted !",
rootView.editProfileCoordinatorLayout, getString(R.string.storage_permission_granted_message),
Snackbar.LENGTH_SHORT).show()
showFileChooser()
} else {
Snackbar.make(
rootView.editProfileCoordinatorLayout, "Permission to Access External Storage Denied :(",
rootView.editProfileCoordinatorLayout, getString(R.string.storage_permission_denied_message),
Snackbar.LENGTH_SHORT).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import androidx.lifecycle.ViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.common.SingleLiveEvent
import org.fossasia.openevent.general.data.Resource
import timber.log.Timber

const val USER_UPDATED = "User updated successfully!"

class EditProfileViewModel(
private val authService: AuthService,
private val authHolder: AuthHolder
private val authHolder: AuthHolder,
private val resource: Resource
) : ViewModel() {

private val compositeDisposable = CompositeDisposable()
Expand Down Expand Up @@ -43,18 +44,18 @@ class EditProfileViewModel(
}
.subscribe({
updateUser(it.url, firstName, lastName)
mutableMessage.value = "Image uploaded successfully!"
mutableMessage.value = resource.getString(R.string.image_upload_success_message)
Timber.d("Image uploaded " + it.url)
}) {
mutableMessage.value = "Error uploading image!"
mutableMessage.value = resource.getString(R.string.image_upload_error_message)
Timber.e(it, "Error uploading user!")
})
}

fun updateUser(url: String?, firstName: String, lastName: String) {
val id = authHolder.getId()
if (firstName.isEmpty() || lastName.isEmpty()) {
mutableMessage.value = "Please provide first name and last name!"
mutableMessage.value = resource.getString(R.string.provide_name_message)
return
}
compositeDisposable.add(authService.updateUser(
Expand All @@ -74,10 +75,10 @@ class EditProfileViewModel(
mutableProgress.value = false
}
.subscribe({
mutableMessage.value = USER_UPDATED
mutableMessage.value = resource.getString(R.string.user_update_success_message)
Timber.d("User updated")
}) {
mutableMessage.value = "Error updating user!"
mutableMessage.value = resource.getString(R.string.user_update_error_message)
Timber.e(it, "Error updating user!")
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LoginFragment : Fragment() {
val progressDialog = progressDialog(context)
val thisActivity = activity
if (thisActivity is AppCompatActivity) {
thisActivity.supportActionBar?.title = "Login"
thisActivity.supportActionBar?.title = getString(R.string.login)
thisActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
setHasOptionsMenu(true)
Expand Down
Loading