Skip to content
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

Disable download button on pan/zoom and while estimating size #1863

Merged
merged 8 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -171,7 +171,7 @@ constructor(
}

/** Called when the map starts to move by the user. */
fun onMapDragged() {
open fun onMapDragged() {
if (locationLock.value.getOrDefault(false)) {
Timber.d("User dragged map. Disabling location lock")
viewModelScope.launch { disableLocationLock() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,14 @@ internal constructor(
navigator.navigateUp()
}

override fun onMapDragged() {
onStartEstimatingDownloadSize()
super.onMapDragged()
}

override fun onMapCameraMoved(newCameraPosition: CameraPosition) {
super.onMapCameraMoved(newCameraPosition)

val bounds = newCameraPosition.bounds
val zoomLevel = newCameraPosition.zoomLevel
if (bounds == null || zoomLevel == null) return
Expand All @@ -125,12 +131,12 @@ internal constructor(
}

private fun onStartEstimatingDownloadSize() {
downloadButtonEnabled.postValue(false)
sizeOnDisk.postValue(resources.getString(R.string.offline_area_size_loading_symbol))
visibleBottomTextViewId.postValue(R.id.size_on_disk_text_view)
}

private suspend fun updateDownloadSize(bounds: Bounds) {
onStartEstimatingDownloadSize()
val sizeInMb = offlineAreaRepository.estimateSizeOnDisk(bounds) / (1024f * 1024f)
if (sizeInMb > MAX_AREA_DOWNLOAD_SIZE_MB) {
onLargeAreaSelected()
Expand Down
21 changes: 21 additions & 0 deletions ground/src/main/res/color/color_states_primary_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright 2023 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/md_theme_on_surface_disabled" android:state_enabled="false"/>
gino-m marked this conversation as resolved.
Show resolved Hide resolved
<item android:color="?attr/colorPrimary" />
</selector>
10 changes: 6 additions & 4 deletions ground/src/main/res/layout/offline_area_selector_frag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
app:layout_constraintTop_toBottomOf="@id/top_mask"
app:layout_constraintBottom_toTopOf="@id/bottom_mask"
app:layout_constraintLeft_toRightOf="@id/left_mask"
app:layout_constraintRight_toLeftOf="@id/right_mask"/>
app:layout_constraintRight_toLeftOf="@id/right_mask" />

<FrameLayout
android:id="@+id/bottom_mask"
Expand All @@ -113,7 +113,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blackMapOverlay"
android:alpha="0.4"/>
android:alpha="0.4" />

<TextView
android:id="@+id/size_on_disk_text_view"
Expand All @@ -125,7 +125,7 @@
android:textColor="@color/textOverMap"
android:layout_marginHorizontal="64dp"
android:visibility="@{viewModel.visibleBottomTextViewId == R.id.size_on_disk_text_view ? View.VISIBLE : View.GONE}"
android:text="@{@string/selected_offline_area_size(viewModel.sizeOnDisk)}"/>
android:text="@{@string/selected_offline_area_size(viewModel.sizeOnDisk)}" />

<TextView
android:id="@+id/area_too_large_text_view"
Expand All @@ -137,7 +137,7 @@
android:textColor="@color/textOverMap"
android:layout_marginHorizontal="64dp"
android:visibility="@{viewModel.visibleBottomTextViewId == R.id.area_too_large_text_view ? View.VISIBLE : View.GONE}"
android:text="@string/selected_offline_area_too_large"/>
android:text="@string/selected_offline_area_too_large" />
</FrameLayout>

<LinearLayout
Expand Down Expand Up @@ -170,6 +170,8 @@
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:enabled="@{viewModel.downloadButtonEnabled}"
android:clickable="@{viewModel.downloadButtonEnabled}"
android:onClick="@{() -> viewModel.onDownloadClick()}" />
</LinearLayout>

Expand Down
2 changes: 1 addition & 1 deletion ground/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
</style>

<style name="ChipButton" parent="Widget.MaterialComponents.Chip.Action">
<item name="chipBackgroundColor">?attr/colorPrimary</item>
<item name="chipBackgroundColor">@color/color_states_primary_button</item>
<item name="chipCornerRadius">@dimen/chip_button_corner_radius</item>
<item name="chipStartPadding">@dimen/chip_button_padding</item>
<item name="chipEndPadding">@dimen/chip_button_padding</item>
Expand Down