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

Fix intent filters #247

Merged
merged 8 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/calendar" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
Expand All @@ -103,6 +104,7 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CreateSubscriptionModel(application: Application) : AndroidViewModel(appli
val success = MutableLiveData(false)
val errorMessage = MutableLiveData<String?>(null)
val isCreating = MutableLiveData(false)
val showNextButton = MutableLiveData(false)

/**
* Creates a new subscription taking the data from the given models.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.res.stringResource
Expand All @@ -54,10 +51,10 @@ import at.bitfire.icsdroid.ui.ResourceInfo
import at.bitfire.icsdroid.ui.partials.ExtendedTopAppBar
import at.bitfire.icsdroid.ui.theme.lightblue
import at.bitfire.icsdroid.ui.theme.setContentThemed
import kotlinx.coroutines.launch
import okhttp3.HttpUrl.Companion.toHttpUrl
import java.net.URI
import java.net.URISyntaxException
import kotlinx.coroutines.launch
import okhttp3.HttpUrl.Companion.toHttpUrl

@OptIn(ExperimentalFoundationApi::class)
class AddCalendarActivity : AppCompatActivity() {
Expand All @@ -81,27 +78,13 @@ class AddCalendarActivity : AppCompatActivity() {
Intent.FLAG_GRANT_READ_URI_PERMISSION
)

subscriptionSettingsModel.url.value = uri.toString()
subscriptionSettingsModel.url.postValue(uri.toString())
}
}

override fun onCreate(inState: Bundle?) {
super.onCreate(inState)

if (inState == null) {
intent?.apply {
data?.let { uri ->
subscriptionSettingsModel.url.value = uri.toString()
}
getStringExtra(EXTRA_TITLE)?.let {
subscriptionSettingsModel.title.value = it
}
if (hasExtra(EXTRA_COLOR))
subscriptionSettingsModel.color.value =
getIntExtra(EXTRA_COLOR, LocalCalendar.DEFAULT_COLOR)
}
}

subscriptionModel.success.observe(this) { success ->
if (success) {
// success, show notification and close activity
Expand Down Expand Up @@ -135,28 +118,31 @@ class AddCalendarActivity : AppCompatActivity() {
val validationResult: ResourceInfo? by validationModel.result.observeAsState(null)

val isCreating: Boolean by subscriptionModel.isCreating.observeAsState(false)

var showNextButton by remember { mutableStateOf(false) }
val showNextButton by subscriptionModel.showNextButton.observeAsState(false)

LaunchedEffect(intent) {
if (inState == null) {
intent?.apply {
data?.toString()
?.let(subscriptionSettingsModel.url::postValue)
?.also { checkUrlIntroductionPage() }
getStringExtra(EXTRA_TITLE)
?.let(subscriptionSettingsModel.title::postValue)
takeIf { hasExtra(EXTRA_COLOR) }
?.getIntExtra(EXTRA_COLOR, LocalCalendar.DEFAULT_COLOR)
?.let(subscriptionSettingsModel.color::postValue)
}
}
}

// Receive updates for the URL introduction page
LaunchedEffect(url, requiresAuth, username, password, isVerifyingUrl) {
if (isVerifyingUrl) {
showNextButton = true
return@LaunchedEffect
}

val uri = validateUri()
val authOK =
if (requiresAuth)
!username.isNullOrEmpty() && !password.isNullOrEmpty()
else
true
showNextButton = uri != null && authOK
checkUrlIntroductionPage()
}

// Receive updates for the Details page
LaunchedEffect(title, color, ignoreAlerts, defaultAlarmMinutes, defaultAllDayAlarmMinutes) {
showNextButton = !subscriptionSettingsModel.title.value.isNullOrBlank()
subscriptionModel.showNextButton.postValue(!title.isNullOrBlank())
}

LaunchedEffect(validationResult) {
Expand Down Expand Up @@ -321,6 +307,21 @@ class AddCalendarActivity : AppCompatActivity() {
}
}

private fun checkUrlIntroductionPage() {
if (validationModel.isVerifyingUrl.value == true) {
subscriptionModel.showNextButton.postValue(true)
} else {
val uri = validateUri()
val authOK =
if (credentialsModel.requiresAuth.value == true)
!credentialsModel.username.value.isNullOrEmpty() &&
!credentialsModel.password.value.isNullOrEmpty()
else
true
subscriptionModel.showNextButton.postValue(uri != null && authOK)
}
}


/* dynamic changes */

Expand Down
Loading