Skip to content

Commit

Permalink
Fix: Added labels in all lambdas instead of using the implicit it. Th…
Browse files Browse the repository at this point in the history
…is addresses #73
  • Loading branch information
wangerekaharun committed Jan 16, 2020
1 parent 49f0941 commit 5f8c4ad
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings

object FirebaseRemoteConfigFactory {

fun create(): FirebaseRemoteConfig = FirebaseRemoteConfig.getInstance().also {
fun create(): FirebaseRemoteConfig = FirebaseRemoteConfig.getInstance().also { firebaseRemoteConfig ->
val fetchInterval = if (BuildConfig.DEBUG) 0L else 3600L

val configSettings = FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(fetchInterval)
.build()

it.setConfigSettingsAsync(configSettings)
it.setDefaultsAsync(R.xml.remote_config_defaults)
firebaseRemoteConfig.setConfigSettingsAsync(configSettings)
firebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class SessionDataRepoImpl(private val firestore: FirebaseFirestore) : SessionDat
} else {
println("Found ${snapshot.size()} starred session(s)")
}
snapshot.forEach {
val slug = it["slug"] as String?
slug?.let {
slugs.add(it)
snapshot.forEach { queryDocumentSnaphsot ->
val slug = queryDocumentSnaphsot["slug"] as String?
slug?.let { slugString ->
slugs.add(slugString)
} ?: run {
println("No slug found")
}
Expand All @@ -74,7 +74,7 @@ class SessionDataRepoImpl(private val firestore: FirebaseFirestore) : SessionDat
}

override suspend fun starrSession(dayNumber: String, sessionId: Int, userId: String, slug: String): FirebaseResult<String> {
return if(!isSessionStarred(dayNumber, sessionId, userId)) {
return if (!isSessionStarred(dayNumber, sessionId, userId)) {
runCatching {
val data = hashMapOf(
"day" to dayNumber,
Expand Down Expand Up @@ -113,8 +113,8 @@ class SessionDataRepoImpl(private val firestore: FirebaseFirestore) : SessionDat
.get()
.await()
val batch = firestore.batch()
snapshot.forEach {
batch.delete(it.reference)
snapshot.forEach { queryDocumentSnapshot ->
batch.delete(queryDocumentSnapshot.reference)
}
batch.commit().await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ class AboutFragment : Fragment(R.layout.fragment_about) {
aboutViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { firebaseError ->
handleDatabaseError(firebaseError)
})
aboutViewModel.getOrganizersResponse().observe(viewLifecycleOwner, Observer {
handleGetOrganizersResponse(it)
aboutViewModel.getOrganizersResponse().observe(viewLifecycleOwner, Observer { aboutDetailsModelList ->
handleGetOrganizersResponse(aboutDetailsModelList)
})
aboutViewModel.getSponsorsResponse().observe(viewLifecycleOwner, Observer {
handleSponsorsResponse(it)
aboutViewModel.getSponsorsResponse().observe(viewLifecycleOwner, Observer { aboutDetailsModelList ->
handleSponsorsResponse(aboutDetailsModelList)
})
}

private fun handleSponsorsResponse(it: List<AboutDetailsModel>) {
private fun handleSponsorsResponse(aboutDetailsModelList: List<AboutDetailsModel>) {
hideProgressBar()
sponsorsRv.adapter = AboutDetailsAdapter(it) {}
sponsorsRv.adapter = AboutDetailsAdapter(aboutDetailsModelList) {}

}

private fun handleGetOrganizersResponse(it: List<AboutDetailsModel>) {
private fun handleGetOrganizersResponse(aboutDetailsModelList: List<AboutDetailsModel>) {
hideProgressBar()
initView(it)
initView(aboutDetailsModelList)
}

private fun handleDatabaseError(databaseError: String) {
Expand All @@ -76,9 +76,9 @@ class AboutFragment : Fragment(R.layout.fragment_about) {

private fun handleFetchAboutDetails(aboutDetailsList: List<AboutDetailsModel>) {
hideProgressBar()
aboutDetailsList.forEach {
droidconDescText.text = it.bio
eventImg.loadImage(it.logoUrl, R.drawable.splash)
aboutDetailsList.forEach { aboutDetailsModel ->
droidconDescText.text = aboutDetailsModel.bio
eventImg.loadImage(aboutDetailsModel.logoUrl, R.drawable.splash)
}
}

Expand All @@ -89,7 +89,7 @@ class AboutFragment : Fragment(R.layout.fragment_about) {
}

private fun fetchAboutDetails(aboutType: String?) {
aboutType?.let { aboutType -> aboutViewModel.fetchAboutDetails(aboutType) }
aboutType?.let { aboutTypeString -> aboutViewModel.fetchAboutDetails(aboutTypeString) }
}

private fun showProgressBar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class AgendaFragment : Fragment(R.layout.fragment_agenda) {
}

private fun observeLiveData() {
agendaViewModel.getAgendasResponse().observe(viewLifecycleOwner, Observer {
handleAgendaResponse(it, agendaRv)
agendaViewModel.getAgendasResponse().observe(viewLifecycleOwner, Observer { agendaModelList ->
handleAgendaResponse(agendaModelList, agendaRv)
})
agendaViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDatabaseError(it)
agendaViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { firebaseError ->
handleDatabaseError(firebaseError)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ class AnnouncementFragment : Fragment(R.layout.fragment_announcements) {
}

private fun observeLiveData() {
announcementViewModel.getAnnouncementsResponse().observe(viewLifecycleOwner, Observer {
announcementViewModel.getAnnouncementsResponse().observe(viewLifecycleOwner, Observer { announcementsList ->
hideProgressBar()
announcementAdapter.setAnnouncements(it)
announcementAdapter.setAnnouncements(announcementsList)
})
announcementViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleError(it)
announcementViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { firebaseError ->
handleError(firebaseError)
})

}
Expand All @@ -69,13 +69,13 @@ class AnnouncementFragment : Fragment(R.layout.fragment_announcements) {
menu.findItem(R.id.eventFeedbackFragment)?.isVisible = false
}

private fun showProgressBar(){
private fun showProgressBar() {
progressBar.visibility = View.VISIBLE
announcementsRv.visibility = View.GONE

}

private fun hideProgressBar(){
private fun hideProgressBar() {
progressBar.visibility = View.GONE
announcementsRv.visibility = View.VISIBLE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class SignInDialogFragment : DialogFragment() {
dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
signInBtn.setOnClickListener {
makeSignIntent()?.let {
startActivityForResult(it, RC_SIGN_IN)
makeSignIntent()?.let { signInIntent ->
startActivityForResult(signInIntent, RC_SIGN_IN)
}
}
cancelText.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class EventFragment : Fragment(R.layout.fragment_event) {
}

private fun observeLiveData() {
eventTypeViewModel.getWifiDetailsResponse().observe(viewLifecycleOwner, Observer {
handleFetchEventsResponse(it, eventTypesRv)
eventTypeViewModel.getWifiDetailsResponse().observe(viewLifecycleOwner, Observer { eventTypeModelList ->
handleFetchEventsResponse(eventTypeModelList, eventTypesRv)
})
eventTypeViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDatabaseError(it)
eventTypeViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { firebaseError ->
handleDatabaseError(firebaseError)
})
eventTypeViewModel.wifiDetails.observe(viewLifecycleOwner, Observer {
handleWifiDetails(it)
eventTypeViewModel.wifiDetails.observe(viewLifecycleOwner, Observer { wifiDetailsResult ->
handleWifiDetails(wifiDetailsResult)
})
}

Expand All @@ -72,7 +72,7 @@ class EventFragment : Fragment(R.layout.fragment_event) {
private fun handleWifiDetails(wifiDetails: FirebaseResult<WifiDetailsModel>) {
if (wifiDetails is FirebaseResult.Success) {
updateWifiDetailsOnUI(wifiDetails.data)
} else if (wifiDetails is FirebaseResult.Error){
} else if (wifiDetails is FirebaseResult.Error) {
handleWifiDetailsError(wifiDetails.exception)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ class EventFeedbackFragment : Fragment() {
}

private fun observeLiveData() {
feedBackViewModel.getEventFeedBackResponse().observe(viewLifecycleOwner, Observer {
handleFeedbackResponse(it)
feedBackViewModel.getEventFeedBackResponse().observe(viewLifecycleOwner, Observer { eventFeedbackResponse ->
handleFeedbackResponse(eventFeedbackResponse)
})
feedBackViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDataError(it)
feedBackViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { firebaseError ->
handleDataError(firebaseError)
})
}

private fun handleDataError(it: String) {
private fun handleDataError(firebaseError: String) {
hideProgressBar()
activity?.toast(it)
activity?.toast(firebaseError)
}

private fun handleFeedbackResponse(feedback: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class SessionFeedbackFragment : Fragment() {
}

private fun observeLiveData() {
sessionDataViewModel.getSessionFeedBackResponse().observe(viewLifecycleOwner, Observer{
handleFeedbackResponse(it)
sessionDataViewModel.getSessionFeedBackResponse().observe(viewLifecycleOwner, Observer { sessionFeedbackResponse ->
handleFeedbackResponse(sessionFeedbackResponse)
})
sessionDataViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDatabaseError(it)
sessionDataViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { firebaseError ->
handleDatabaseError(firebaseError)
})

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.android.synthetic.main.fragment_filter.*

class FilterFragment : RoundedBottomSheetFragment() {
private val filterStore = FilterStore.instance

private var onFilterChanged: (Filter) -> Unit = {}

override fun onCreateView(
Expand All @@ -40,7 +39,10 @@ class FilterFragment : RoundedBottomSheetFragment() {
chip.isChecked = false
}

val stages = Stage.values().toList().minus(Stage.None).map { it.value }
val stages = Stage.values().toList().minus(Stage.None).map { stage ->
stage.value
}

val stageChips = getChips(stages)
stageChips.forEachIndexed { index, chip ->
chip.isChecked = filterStore.filter.stages.contains(Stage.values()[index])
Expand All @@ -52,14 +54,16 @@ class FilterFragment : RoundedBottomSheetFragment() {
filterStore.toggleStage(Stage.values()[index])
onFilterChanged(filterStore.filter)
}
chip.setOnCloseIconClickListener {
val c = it as Chip
chip.setOnCloseIconClickListener { view ->
val c = view as Chip
c.isChecked = false
}
stagesChipGroup.addView(chip)
}

val types = Type.values().toList().minus(Type.None).map { it.value }
val types = Type.values().toList().minus(Type.None).map { type ->
type.value
}
val typeChips = getChips(types)
typeChips.forEachIndexed { index, chip ->
chip.isChecked = filterStore.filter.types.contains(Type.values()[index])
Expand All @@ -71,14 +75,16 @@ class FilterFragment : RoundedBottomSheetFragment() {
filterStore.toggleType(Type.values()[index])
onFilterChanged(filterStore.filter)
}
chip.setOnCloseIconClickListener {
val c = it as Chip
chip.setOnCloseIconClickListener { view ->
val c = view as Chip
c.isChecked = false
}
typesChipGroup.addView(chip)
}

val levels = Level.values().toList().minus(Level.None).map { it.name }
val levels = Level.values().toList().minus(Level.None).map { level ->
level.name
}
val levelChips = getChips(levels)
levelChips.forEachIndexed { index, chip ->
chip.isChecked = filterStore.filter.levels.contains(Level.values()[index])
Expand All @@ -90,8 +96,8 @@ class FilterFragment : RoundedBottomSheetFragment() {
filterStore.toggleLevel(Level.values()[index])
onFilterChanged(filterStore.filter)
}
chip.setOnCloseIconClickListener {
val c = it as Chip
chip.setOnCloseIconClickListener { view ->
val c = view as Chip
c.isChecked = false
}
levelChipGroup.addView(chip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ data class Filter(
results += context.getString(R.string.my_favorites)
}

results += stages.map { it.value }
results += types.map { it.value }
results += levels.map { it.name }
results += stages.map { stage ->
stage.value
}
results += types.map { type ->
type.value
}
results += levels.map {level ->
level.name
}

return results
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class HomeActivity : AppCompatActivity() {
}

private fun unsubscribeNotifications() = lifecycleScope.launch {
firebaseAuth.currentUser?.let {
sessionDetailsViewModel.removeAllFavourites(sharedPreferences, it.uid)
firebaseAuth.currentUser?.let { firebaseUser ->
sessionDetailsViewModel.removeAllFavourites(sharedPreferences, firebaseUser.uid)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import com.android254.droidconke19.ui.traveldetails.TravelFragment
import kotlinx.android.synthetic.main.fragment_info.*
import java.util.*

class InfoFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_info, container, false)

}
class InfoFragment : Fragment(R.layout.fragment_info) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class ScheduleFragment : Fragment(R.layout.fragment_schedule) {
val chips = items
.map { FilterChip(requireContext()).apply { text = it } }

chips.forEach {
it.disable()
activeFiltersChipGroup.addView(it)
chips.forEach { filterChip ->
filterChip.disable()
activeFiltersChipGroup.addView(filterChip)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ class SessionDetailsFragment : Fragment(R.layout.fragment_session_details) {
}

private fun observeLiveData() {
sessionDetailsViewModel.getReserveSeatResponse().observe(viewLifecycleOwner, Observer {
handleReserveSeatResponse(it)
sessionDetailsViewModel.getReserveSeatResponse().observe(viewLifecycleOwner, Observer { reserveSeatResponse ->
handleReserveSeatResponse(reserveSeatResponse)
})
}

private fun handleReserveSeatResponse(it: String) {
private fun handleReserveSeatResponse(reserveSeatResponse: String) {
progress_bar.visibility = View.GONE
activity?.toast(it)
activity?.toast(reserveSeatResponse)
}

private fun setupViews(sessionModel: SessionsModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class SessionDayFragment : Fragment(R.layout.fragment_day_session) {
}
}

private fun redirectToSessionDetails(it: SessionsModel) {
findNavController().navigate(ScheduleFragmentDirections.actionScheduleFragmentToSessionDetailsFragment(it, it.title))
private fun redirectToSessionDetails(sessionsModel: SessionsModel) {
findNavController().navigate(ScheduleFragmentDirections.actionScheduleFragmentToSessionDetailsFragment(sessionsModel, sessionsModel.title))
}

private fun observeLiveData() {
Expand Down
Loading

0 comments on commit 5f8c4ad

Please sign in to comment.