Skip to content

Commit

Permalink
fix:Use viewLifeCycleOwner for livedata observation. This addresses #73
Browse files Browse the repository at this point in the history
  • Loading branch information
wangerekaharun committed Jan 16, 2020
1 parent 5ba93bd commit 0c39597
Show file tree
Hide file tree
Showing 27 changed files with 41 additions and 77 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:theme="@style/AppTheme.NoActionBar">

<activity
android:name="com.android254.droidconke19.HomeActivity"
android:name="com.android254.droidconke19.ui.home.HomeActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.Launch">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.AboutDetailsModel
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.AgendaModel
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.Announcement
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ktx.toObjects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.UserEventFeedback
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.EventTypeModel
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.RoomModel
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.SessionsModel
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.SessionsUserFeedback
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.SessionsModel
import com.android254.droidconke19.models.SpeakersModel
import com.google.firebase.firestore.FirebaseFirestore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.SpeakersModel
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ktx.toObjects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.utils.runCatching
import com.android254.droidconke19.models.WifiDetailsModel
import com.android254.droidconke19.models.utils.WifiDetailsModelFactory
import com.android254.droidconke19.utils.WifiDetailsModelFactory
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlinx.coroutines.tasks.await

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ class AboutFragment : Fragment() {
}

private fun observeLiveData() {
aboutViewModel.getAboutDetailsResponse().observe(this, Observer { aboutDetailsList ->
aboutViewModel.getAboutDetailsResponse().observe(viewLifecycleOwner, Observer { aboutDetailsList ->
handleFetchAboutDetails(aboutDetailsList)
})
aboutViewModel.getFirebaseError().observe(this, Observer { firebaseError ->
aboutViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { firebaseError ->
handleDatabaseError(firebaseError)
})
aboutViewModel.getOrganizersResponse().observe(this, Observer {
aboutViewModel.getOrganizersResponse().observe(viewLifecycleOwner, Observer {
handleGetOrganizersResponse(it)
})
aboutViewModel.getSponsorsResponse().observe(this, Observer {
aboutViewModel.getSponsorsResponse().observe(viewLifecycleOwner, Observer {
handleSponsorsResponse(it)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class AgendaFragment : Fragment() {
}

private fun observeLiveData() {
agendaViewModel.getAgendasResponse().observe(this, Observer {
agendaViewModel.getAgendasResponse().observe(viewLifecycleOwner, Observer {
handleAgendaResponse(it, agendaRv)
})
agendaViewModel.getFirebaseError().observe(this, Observer {
agendaViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDatabaseError(it)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class AnnouncementFragment : Fragment() {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class EventFragment : Fragment() {
}

private fun observeLiveData() {
eventTypeViewModel.getWifiDetailsResponse().observe(this, Observer {
eventTypeViewModel.getWifiDetailsResponse().observe(viewLifecycleOwner, Observer {
handleFetchEventsResponse(it, eventTypesRv)
})
eventTypeViewModel.getFirebaseError().observe(this, Observer {
eventTypeViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDatabaseError(it)
})
eventTypeViewModel.wifiDetails.observe(viewLifecycleOwner, Observer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class EventFeedbackFragment : Fragment() {
}

private fun observeLiveData() {
feedBackViewModel.getEventFeedBackResponse().observe(this, Observer {
feedBackViewModel.getEventFeedBackResponse().observe(viewLifecycleOwner, Observer {
handleFeedbackResponse(it)
})
feedBackViewModel.getFirebaseError().observe(this, Observer {
feedBackViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDataError(it)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class SessionFeedbackFragment : Fragment() {
}

private fun observeLiveData() {
sessionDataViewModel.getSessionFeedBackResponse().observe(this, Observer{
sessionDataViewModel.getSessionFeedBackResponse().observe(viewLifecycleOwner, Observer{
handleFeedbackResponse(it)
})
sessionDataViewModel.getFirebaseError().observe(this, Observer {
sessionDataViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer {
handleDatabaseError(it)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.android254.droidconke19
package com.android254.droidconke19.ui.home

import android.content.SharedPreferences
import android.os.Bundle
Expand All @@ -12,6 +12,8 @@ import androidx.navigation.Navigation
import androidx.navigation.findNavController
import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.onNavDestinationSelected
import com.android254.droidconke19.BuildConfig
import com.android254.droidconke19.R
import com.android254.droidconke19.utils.isSignedIn
import com.android254.droidconke19.viewmodels.SessionDetailsViewModel
import com.google.android.material.appbar.AppBarLayout
Expand All @@ -25,7 +27,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf

class HomeActivity : AppCompatActivity() {
val sharedPreferences: SharedPreferences by inject { parametersOf(this) }
private val sharedPreferences: SharedPreferences by inject { parametersOf(this) }
private val firebaseRemoteConfig: FirebaseRemoteConfig by inject()
private val firebaseMessaging: FirebaseMessaging by inject()
private val firebaseAuth: FirebaseAuth by inject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SessionDetailsFragment : Fragment() {
}

private fun observeLiveData() {
sessionDetailsViewModel.getReserveSeatResponse().observe(this, Observer {
sessionDetailsViewModel.getReserveSeatResponse().observe(viewLifecycleOwner, Observer {
handleReserveSeatResponse(it)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class SessionDayFragment : Fragment() {
}

private fun observeLiveData() {
sessionsViewModel.getSessionsResponse().observe(this, Observer { sessionList ->
sessionsViewModel.getSessionsResponse().observe(viewLifecycleOwner, Observer { sessionList ->
updateAdapterWithList(sessionList)
})
sessionsViewModel.getFirebaseError().observe(this, Observer { databaseError ->
sessionsViewModel.getFirebaseError().observe(viewLifecycleOwner, Observer { databaseError ->
handleError(databaseError)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class MapFragment : Fragment(), OnMapReadyCallback {

//collapse bottom sheet
view.collapseBottomSheetImg.setOnClickListener {
when {
bottomSheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED -> bottomSheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
when (bottomSheetBehavior?.state) {
BottomSheetBehavior.STATE_EXPANDED -> bottomSheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android254.droidconke19.datastates
package com.android254.droidconke19.utils

import com.android254.droidconke19.datastates.FirebaseResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.android254.droidconke19.models.utils
package com.android254.droidconke19.utils

import com.android254.droidconke19.models.WifiDetailsModel
import com.android254.droidconke19.models.isPropertiesNotEmpty
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/home_fragment_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:layout_height="match_parent"
android:background="@color/colorWhite"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.android254.droidconke19.HomeActivity"
tools:context="com.android254.droidconke19.ui.home.HomeActivity"
tools:showIn="@layout/activity_home">


Expand Down

0 comments on commit 0c39597

Please sign in to comment.