Skip to content

Commit ab67445

Browse files
authored
Clear form when launching AddSubscriptionScreen (#705)
Signed-off-by: Arnau Mora <[email protected]>
1 parent 9489669 commit ab67445

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

app/src/main/java/at/bitfire/icsdroid/model/SubscriptionSettingsUseCase.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ class SubscriptionSettingsUseCase @Inject constructor() {
9898
)
9999
}
100100

101+
/**
102+
* Set initial values when creating a new subscription.
103+
*
104+
* Note that all values will be overwritten, so call this method before changing any individual
105+
* value, or when you want to reset the form to an initial state.
106+
*/
107+
fun setInitialValues(
108+
title: String?,
109+
color: Int?,
110+
url: String?,
111+
) {
112+
uiState = UiState(
113+
title = title,
114+
color = color,
115+
url = url,
116+
)
117+
}
118+
101119
fun equalsSubscription(subscription: Subscription) =
102120
uiState.url == subscription.url.toString()
103121
&& uiState.title == subscription.displayName

app/src/main/java/at/bitfire/icsdroid/ui/screen/AddSubscriptionScreen.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ fun AddSubscriptionScreen(
7878
}
7979
}
8080

81-
LaunchedEffect(Unit) {
82-
title?.let(model.subscriptionSettingsUseCase::setTitle)
83-
color?.let(model.subscriptionSettingsUseCase::setColor)
84-
url?.let {
85-
model.subscriptionSettingsUseCase.setUrl(it)
81+
LaunchedEffect(title, color, url) {
82+
model.subscriptionSettingsUseCase.setInitialValues(title, color, url)
83+
84+
if (url != null) {
8685
model.checkUrlIntroductionPage()
8786
}
8887
}
@@ -110,28 +109,26 @@ fun AddSubscriptionScreen(
110109

111110
Box(modifier = Modifier.imePadding()) {
112111
AddSubscriptionScreen(
112+
model = model,
113113
onPickFileRequested = { pickFile.launch(arrayOf("text/calendar")) },
114-
finish = onBackRequested,
115-
checkUrlIntroductionPage = model::checkUrlIntroductionPage
114+
finish = onBackRequested
116115
)
117116
}
118117
}
119118

120119
@Composable
121120
fun AddSubscriptionScreen(
121+
model: AddSubscriptionModel,
122122
onPickFileRequested: () -> Unit,
123-
checkUrlIntroductionPage: () -> Unit,
124123
finish: () -> Unit
125124
) {
126125
val scope = rememberCoroutineScope()
127126
val pagerState = rememberPagerState { 2 }
128127

129-
val model: AddSubscriptionModel = hiltViewModel()
130-
131128
// Receive updates for the URL introduction page
132129
with(model.subscriptionSettingsUseCase.uiState) {
133130
LaunchedEffect(url, requiresAuth, username, password) {
134-
checkUrlIntroductionPage()
131+
model.checkUrlIntroductionPage()
135132
}
136133
}
137134

0 commit comments

Comments
 (0)