Skip to content

Commit

Permalink
Merge branch 'release/v3.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
android-sam committed Jun 19, 2023
2 parents 819acfe + 9c74a5a commit fdfd93c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
applicationId "com.samco.trackandgraph"
minSdkVersion 23
targetSdkVersion 33
versionCode 300500
versionName "3.5.0"
versionCode 300501
versionName "3.5.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

vectorDrawables {
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/com/samco/trackandgraph/group/GroupFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.navigation.findNavController
Expand Down Expand Up @@ -354,14 +355,17 @@ class GroupFragment : Fragment(),
}

private fun listenToViewModel() {
viewModel.loading.observe(viewLifecycleOwner) {
binding.loadingOverlay.visibility = if (it) View.VISIBLE else View.GONE
}
viewModel.hasTrackers.observe(viewLifecycleOwner) {}
viewModel.showEmptyGroupText.observe(viewLifecycleOwner) {
binding.emptyGroupText.visibility = if (it) View.VISIBLE else View.INVISIBLE
}
viewModel.allChildren.observe(viewLifecycleOwner) {
adapter.submitList(it, forceNextNotifyDataSetChanged)
if (forceNextNotifyDataSetChanged) forceNextNotifyDataSetChanged = false
forceNextNotifyDataSetChanged = false
updateShowQueueTrackButton()
binding.emptyGroupText.visibility =
if (it.isEmpty() && args.groupId == 0L) View.VISIBLE
else View.INVISIBLE
}
viewModel.showDurationInputDialog.observe(viewLifecycleOwner) {
if (it == null) return@observe
Expand Down
37 changes: 32 additions & 5 deletions app/src/main/java/com/samco/trackandgraph/group/GroupViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,20 @@ class GroupViewModel @Inject constructor(
private val _showDurationInputDialog = MutableLiveData<DurationInputDialogData?>()
val showDurationInputDialog: LiveData<DurationInputDialogData?> = _showDurationInputDialog

val hasTrackers: LiveData<Boolean> = dataInteractor
.hasAtLeastOneTracker()
private val hasTrackersFlow = dataInteractor.hasAtLeastOneTracker()

/**
* Show a loading screen until the database has been loaded in case we're in the middle of a
* heavy migration.
*/
private val databaseLoading = hasTrackersFlow
.map { false }
.flowOn(io)
.onStart { emit(true) }

val loading = databaseLoading.asLiveData(viewModelScope.coroutineContext)

val hasTrackers: LiveData<Boolean> = hasTrackersFlow
.asLiveData(viewModelScope.coroutineContext)

private val groupId = MutableSharedFlow<Long>(1, 1)
Expand Down Expand Up @@ -127,6 +139,7 @@ class GroupViewModel @Inject constructor(
DataUpdateType.GroupUpdated -> listOf(
UpdateType.Groups
)

DataUpdateType.TrackerUpdated -> listOf(
UpdateType.Trackers
)
Expand Down Expand Up @@ -183,7 +196,8 @@ class GroupViewModel @Inject constructor(
//graph deleted events. Graph deleted is more significant so we only emit that
if (types.size == 2
&& types.containsKey(UpdateType.GraphDeleted)
&& types.containsKey(UpdateType.DisplayIndices)) {
&& types.containsKey(UpdateType.DisplayIndices)
) {
yield(types[UpdateType.GraphDeleted])
}

Expand Down Expand Up @@ -222,6 +236,7 @@ class GroupViewModel @Inject constructor(
UpdateType.DisplayIndices, UpdateType.GraphDeleted -> {
mapNewGraphsToOldViewData(viewData, graphStats)
}

is UpdateType.Graph -> withUpdatedGraph(viewData, graphStats, type.graphId)
is UpdateType.GraphsForFeature ->
withUpdatedIfAffected(viewData, graphStats, type.featureId)
Expand Down Expand Up @@ -342,7 +357,7 @@ class GroupViewModel @Inject constructor(
.map { getGroupChildren(it.first) }
.flowOn(io)

val allChildren: LiveData<List<GroupChild>> =
private val allChildrenFlow: StateFlow<List<GroupChild>> =
combine(graphChildren, trackersChildren, groupChildren) { a, b, c -> Triple(a, b, c) }
//This debounce should be longer than the children debounce
.debounce(50L)
Expand All @@ -357,7 +372,19 @@ class GroupViewModel @Inject constructor(
}
.flowOn(io)
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
.asLiveData(viewModelScope.coroutineContext)

val allChildren = allChildrenFlow.asLiveData(viewModelScope.coroutineContext)

val showEmptyGroupText: LiveData<Boolean> = combine(
allChildrenFlow.map { it.isEmpty() },
databaseLoading,
groupId
) { childrenEmpty, loading, groupId ->
childrenEmpty && !loading && groupId == 0L
}
.onStart { emit(false) }
.distinctUntilChanged()
.asLiveData(viewModelScope.coroutineContext)

val trackers
get() = allChildren.value
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout/fragment_group.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />

<include
android:id="@+id/loadingOverlay"
layout="@layout/layout_loading_overlay"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
4 changes: 2 additions & 2 deletions base/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@
<string name="data_point_tutorial_page_3_description">Use labels if you want to group the data points</string>
<string name="data_point_tutorial_page_3_hint">(Hint: If you want to add more context or description use the note instead of the label field)</string>
<string name="help">Help</string>
<string name="faq_page_link" translatable="false">https://github.com/SamAmco/track-and-graph/blob/release/v3.5.0/docs/faq/index.md#faq</string>
<string name="faq_page_link_1" translatable="false">https://github.com/SamAmco/track-and-graph/blob/release/v3.5.0/docs/faq/faq_1.md#how-do-i-start-tracking-something</string>
<string name="faq_page_link" translatable="false">https://github.com/SamAmco/track-and-graph/blob/release/v3.5.1/docs/faq/index.md#faq</string>
<string name="faq_page_link_1" translatable="false">https://github.com/SamAmco/track-and-graph/blob/release/v3.5.1/docs/faq/faq_1.md#how-do-i-start-tracking-something</string>
<string name="advanced_options">Advanced options</string>
<string name="type_colon">"Type: "</string>
<string name="order_colon">"Order: "</string>
Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-GB/changelogs/300501.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Add loading state while database migrating


0 comments on commit fdfd93c

Please sign in to comment.