Skip to content

Commit 8891685

Browse files
committed
Make wifi rescan automatic and show progress
1 parent ef026d2 commit 8891685

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

app/src/main/java/com/adriantache/greatimagedownloader/domain/DownloadPhotosUseCaseImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class DownloadPhotosUseCaseImpl(
112112
scanningTimeoutJob?.cancel()
113113

114114
scanningTimeoutJob = scope.launch {
115-
delay(20.seconds)
115+
delay(30.seconds)
116116

117117
connectToWifi(isSoftTimeout = true)
118118
}

app/src/main/java/com/adriantache/greatimagedownloader/ui/view/StartView.kt

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
2525
import androidx.compose.material3.Button
2626
import androidx.compose.material3.ButtonDefaults
2727
import androidx.compose.material3.Icon
28+
import androidx.compose.material3.LinearProgressIndicator
2829
import androidx.compose.material3.MaterialTheme
2930
import androidx.compose.material3.Scaffold
3031
import androidx.compose.material3.SnackbarHost
@@ -33,6 +34,7 @@ import androidx.compose.material3.Text
3334
import androidx.compose.runtime.Composable
3435
import androidx.compose.runtime.LaunchedEffect
3536
import androidx.compose.runtime.getValue
37+
import androidx.compose.runtime.mutableIntStateOf
3638
import androidx.compose.runtime.mutableStateOf
3739
import androidx.compose.runtime.remember
3840
import androidx.compose.runtime.setValue
@@ -46,7 +48,9 @@ import androidx.compose.ui.tooling.preview.Preview
4648
import androidx.compose.ui.unit.dp
4749
import androidx.lifecycle.compose.LifecycleResumeEffect
4850
import com.adriantache.greatimagedownloader.R
51+
import com.adriantache.greatimagedownloader.domain.utils.model.delay
4952
import com.adriantache.greatimagedownloader.ui.util.KeepScreenOn
53+
import kotlinx.coroutines.launch
5054

5155
// TODO: rename this file and split it into a loading view and a start view
5256
// TODO: make some nice animations between the two states
@@ -146,6 +150,25 @@ fun StartView(
146150
}
147151

148152
AnimatedVisibility(isSoftWifiTimeout) {
153+
var waitingProgress by remember { mutableIntStateOf(0) }
154+
155+
LaunchedEffect(Unit) {
156+
val delayDurationMs = 5000
157+
158+
launch {
159+
val delayInterval = delayDurationMs / 100
160+
161+
while (true) {
162+
delay(delayInterval)
163+
waitingProgress = (++waitingProgress).coerceAtMost(100)
164+
}
165+
}
166+
167+
delay(delayDurationMs) // Give people time to read the message.
168+
169+
onSoftWifiTimeoutRetry()
170+
}
171+
149172
Column(
150173
modifier = Modifier
151174
.fillMaxWidth()
@@ -161,24 +184,13 @@ fun StartView(
161184
color = MaterialTheme.colorScheme.onSurfaceVariant,
162185
)
163186

164-
Box(
187+
Spacer(modifier = Modifier.height(4.dp))
188+
189+
LinearProgressIndicator(
165190
modifier = Modifier.fillMaxWidth(),
166-
contentAlignment = Alignment.Center,
167-
) {
168-
Button(
169-
onClick = onSoftWifiTimeoutRetry,
170-
colors = ButtonDefaults.filledTonalButtonColors(
171-
containerColor = MaterialTheme.colorScheme.secondary,
172-
contentColor = MaterialTheme.colorScheme.onSecondary,
173-
),
174-
) {
175-
Text(
176-
text = stringResource(R.string.wifi_soft_timeout_retry),
177-
style = MaterialTheme.typography.labelSmall,
178-
color = MaterialTheme.colorScheme.onSecondary,
179-
)
180-
}
181-
}
191+
progress = { waitingProgress.toFloat() / 100 },
192+
drawStopIndicator = { Unit }
193+
)
182194
}
183195
}
184196

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<string name="save">Save</string>
99
<string name="wifi_is_not_enabled">WiFi is not enabled!</string>
1010
<string name="connecting_to_camera">Connecting to camera…</string>
11-
<string name="wifi_soft_timeout">It seems that it\'s taking a long time to connect to the camera. Please check that the camera is turned on and that WiFi is enabled.</string>
12-
<string name="wifi_soft_timeout_retry">Force rescan</string>
11+
<string name="wifi_soft_timeout">It seems that it\'s taking a long time to connect to the camera. Please check that the camera is turned on and that WiFi is enabled. \n\nRescanning for WiFi networks…</string>
1312
<string name="wifi_hard_timeout">The system is limiting the amount of WiFi scans we can perform. The app will automatically retry the connection once possible.</string>
1413
</resources>

0 commit comments

Comments
 (0)