Skip to content
Closed
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 @@ -38,9 +38,11 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.instructure.horizon.R
import com.instructure.horizon.horizonui.foundation.HorizonColors
import com.instructure.horizon.horizonui.foundation.HorizonCornerRadius
import com.instructure.horizon.horizonui.foundation.HorizonSpace
Expand Down Expand Up @@ -80,7 +82,12 @@ fun AccountScreen(
}

@Composable
private fun AccountContentScreen(state: AccountUiState, navController: NavController, onLogout: () -> Unit, switchExperience: () -> Unit) {
private fun AccountContentScreen(
state: AccountUiState,
navController: NavController,
onLogout: () -> Unit,
switchExperience: () -> Unit
) {
LazyColumn(
contentPadding = PaddingValues(24.dp)
) {
Expand Down Expand Up @@ -135,6 +142,7 @@ private fun AccountContentScreen(state: AccountUiState, navController: NavContro
navController,
onLogout,
switchExperience,
state.onShowSnackbar,
clipModifier
)

Expand All @@ -155,7 +163,16 @@ private fun AccountContentScreen(state: AccountUiState, navController: NavContro
}

@Composable
private fun AccountItem(item: AccountItemState, navController: NavController, onLogout: () -> Unit, switchExperience: () -> Unit, modifier: Modifier = Modifier) {
private fun AccountItem(
item: AccountItemState,
navController: NavController,
onLogout: () -> Unit,
switchExperience: () -> Unit,
onShowSnackbar: (String) -> Unit,
modifier: Modifier = Modifier
) {
val uriHandler = LocalUriHandler.current
val context = LocalContext.current
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
Expand All @@ -165,7 +182,13 @@ private fun AccountItem(item: AccountItemState, navController: NavController, on
when (item.type) {
is AccountItemType.Open -> navController.navigate(item.type.route.route)

is AccountItemType.OpenExternal -> navController.navigate(item.type.route.route)
is AccountItemType.OpenExternal -> {
try {
uriHandler.openUri(item.type.url)
} catch (_: Exception) {
onShowSnackbar(context.getString(R.string.accountFailedtoOpenLinkMessage))
}
}

is AccountItemType.LogOut -> {
onLogout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data class AccountUiState(
val updateUserName: (String) -> Unit = {},
val performLogout: () -> Unit = {},
val switchExperience: () -> Unit = {},
val onShowSnackbar: (String) -> Unit = {},
val restartApp: Boolean = false,
)

Expand All @@ -44,7 +45,7 @@ data class AccountItemState(

sealed class AccountItemType(@DrawableRes val icon: Int) {
data class Open(val route: AccountRoute) : AccountItemType(R.drawable.arrow_forward)
data class OpenExternal(val route: AccountRoute) : AccountItemType(R.drawable.open_in_new)
data class OpenExternal(val url: String) : AccountItemType(R.drawable.open_in_new)
data object LogOut : AccountItemType(R.drawable.logout)
data object SwitchExperience : AccountItemType(R.drawable.swap_horiz)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class AccountViewModel @Inject constructor(
),
updateUserName = ::updateUserName,
performLogout = ::performLogout,
switchExperience = ::switchExperience
switchExperience = ::switchExperience,
onShowSnackbar = ::onShowSnackbar
)
)
val uiState = _uiState.asStateFlow()
Expand Down Expand Up @@ -119,7 +120,7 @@ class AccountViewModel @Inject constructor(
items = listOf(
AccountItemState(
title = context.getString(R.string.accountReportABug),
type = AccountItemType.OpenExternal(AccountRoute.BugReportWebView)
type = AccountItemType.OpenExternal("https://community.canvaslms.com/t5/Canvas-Career/Report-an-issue/td-p/662564")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting this URL to a constant or configuration file instead of hardcoding it in the ViewModel. This would make it easier to update the URL in the future and improve testability.

companion object {
    private const val BUG_REPORT_URL = "https://community.canvaslms.com/t5/Canvas-Career/Report-an-issue/td-p/662564"
}

)
)
)
Expand Down Expand Up @@ -172,6 +173,12 @@ class AccountViewModel @Inject constructor(
}
}

private fun onShowSnackbar(message: String) {
_uiState.update {
it.copy(screenState = it.screenState.copy(snackbarMessage = message))
}
}

private fun updateUserName(value: String) {
_uiState.update {
it.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.instructure.horizon.features.account.notifications.AccountNotificatio
import com.instructure.horizon.features.account.password.AccountPasswordScreen
import com.instructure.horizon.features.account.profile.AccountProfileScreen
import com.instructure.horizon.features.account.profile.AccountProfileViewModel
import com.instructure.horizon.features.account.reportabug.ReportABugWebView
import com.instructure.horizon.features.home.HomeNavigationRoute
import com.instructure.horizon.horizonui.animation.enterTransition
import com.instructure.horizon.horizonui.animation.exitTransition
Expand Down Expand Up @@ -91,10 +90,6 @@ fun NavGraphBuilder.accountNavigation(
val uiState by viewModel.uiState.collectAsState()
AccountAdvancedScreen(uiState, navController)
}

composable(AccountRoute.BugReportWebView.route) {
ReportABugWebView(navController)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ sealed class AccountRoute(val route: String) {
data object Notifications : AccountRoute("notifications")
data object CalendarFeed : AccountRoute("calendar_feed")
data object Advanced : AccountRoute("advanced")
data object BugReportWebView : AccountRoute("report_a_bug")
}

This file was deleted.

1 change: 1 addition & 0 deletions libs/horizon/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
<string name="a11y_dashboardNextItemContentDescription">Next item</string>
<string name="a11y_dashboardPreviousItemContentDescription">Previous item</string>
<string name="dashboardPaginatedWidgetPagerMessage">%1$d of %2$d</string>
<string name="accountFailedtoOpenLinkMessage">Failed to open</string>
<string name="dashboardCourseCardModuleItemNoDueDateLabel">No due date</string>
<string name="dashboardCourseCardProgramPrefix">Part of:</string>
<string name="dashboardCourseCardEnrolledCoursesMessage">You’re enrolled in %1$d courses.</string>
Expand Down
Loading