Skip to content

Commit

Permalink
Reformat source with Ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
PatilShreyas committed Aug 6, 2021
1 parent 7ce1cb3 commit deb3c79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,24 @@ fun NotesScreen(navController: NavHostController, viewModel: NotesViewModel) {
content = {
var isSynced by rememberSaveable { mutableStateOf(false) }

val notesState = viewModel.notes.collectAsState(initial = UIDataState.loading()).value
val syncState = viewModel.syncState.collectAsState(initial = UIDataState.loading()).value
val notes = viewModel.notes.collectAsState(UIDataState.loading()).value
val syncState = viewModel.syncState.collectAsState(UIDataState.loading()).value

// Check whether it's already synced in the past composition
// Or also check whether current state is also successful or not
isSynced = isSynced || syncState is UIDataState.Success

val isRefreshing = (notesState is UIDataState.Loading) or (syncState is UIDataState.Loading)
val isRefreshing = (notes is UIDataState.Loading) or (syncState is UIDataState.Loading)

SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing),
onRefresh = { viewModel.syncNotes() }
) {
when (notesState) {
is UIDataState.Success -> NotesList(notesState.data) { note ->
when (notes) {
is UIDataState.Success -> NotesList(notes.data) { note ->
navController.navigate(Screen.NotesDetail.route(note.id))
}
is UIDataState.Failed -> FailureDialog(notesState.message)
is UIDataState.Failed -> FailureDialog(notes.message)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ package dev.shreyaspatil.noty.simpleapp.view.notes
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.os.Bundle
import android.view.*
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.asLiveData
Expand All @@ -33,11 +38,12 @@ import dev.shreyaspatil.noty.simpleapp.databinding.NotesFragmentBinding
import dev.shreyaspatil.noty.simpleapp.view.base.BaseFragment
import dev.shreyaspatil.noty.simpleapp.view.hiltNotyMainNavGraphViewModels
import dev.shreyaspatil.noty.simpleapp.view.notes.adapter.NotesListAdapter
import dev.shreyaspatil.noty.utils.*
import dev.shreyaspatil.noty.utils.ConnectionState
import dev.shreyaspatil.noty.utils.ext.hide
import dev.shreyaspatil.noty.utils.ext.setDrawableLeft
import dev.shreyaspatil.noty.utils.ext.shareWhileObserved
import dev.shreyaspatil.noty.utils.ext.show
import dev.shreyaspatil.noty.utils.observeConnectivityAsFlow
import dev.shreyaspatil.noty.view.viewmodel.NotesViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -91,9 +97,9 @@ class NotesFragment : BaseFragment<NotesFragmentBinding, NotesViewModel>() {

private fun loadNotes() {
viewLifecycleOwner.lifecycleScope.launchWhenStarted {
viewModel.notes.first().let { notesState ->
viewModel.notes.first().let { notes ->
when {
notesState is UIDataState.Success -> notesListAdapter.submitList(notesState.data)
notes is UIDataState.Success -> notesListAdapter.submitList(notes.data)
notesListAdapter.itemCount == 0 -> syncNotes()
}
}
Expand Down

0 comments on commit deb3c79

Please sign in to comment.