Skip to content

Commit

Permalink
Document ui/activity and ui/components
Browse files Browse the repository at this point in the history
  • Loading branch information
wingio committed Dec 5, 2023
1 parent b46dbe7 commit 8d1b7e0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
14 changes: 8 additions & 6 deletions app/src/main/java/xyz/wingio/dimett/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.transitions.SlideTransition
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.android.ext.android.get
import xyz.wingio.dimett.domain.manager.AccountManager
import xyz.wingio.dimett.ui.screens.auth.LoginScreen
import xyz.wingio.dimett.ui.screens.main.MainScreen
import xyz.wingio.dimett.ui.theme.DimettTheme

class MainActivity : ComponentActivity(), KoinComponent {

private val accountManager: AccountManager by inject()
class MainActivity : ComponentActivity() {

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

WindowCompat.setDecorFitsSystemWindows(window, false)
val accountManager: AccountManager = get()
WindowCompat.setDecorFitsSystemWindows(window, false) // Support edge to edge

setContent {
DimettTheme {
Surface(
modifier = Modifier.fillMaxSize()
) {
/*
* Loading accounts takes some time, not very much but it can cause issues.
* As such we wait until its done before showing the ui
*/
if (accountManager.isInitialized) {
val isSignedIn = accountManager.current != null
val startScreen = if (isSignedIn) MainScreen() else LoginScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

// Credit to Xinto (github.com/X1nto)
/**
* Overlays a [badge] component on top of some [content] with a cutout
*
* @param badge The component to display over the content
* @param modifier Modifiers for the BadgedItem
* @param badgeAlignment How to align the badge relative to the content
*/
// Credit to Xinto (https://github.com/X1nto)
@Composable
fun BadgedItem(
badge: @Composable (() -> Unit)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xyz.wingio.dimett.ui.components

import android.content.Intent
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
Expand All @@ -11,6 +12,12 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.core.util.Consumer

/**
* An effect for handling incoming [Intent]s
*
* @param enabled Whether or not intents are sent to the callback
* @param onIntent Callback that gets sent all incoming [Intent]s received by the root [ComponentActivity]
*/
@Composable
fun IntentHandler(enabled: Boolean = true, onIntent: (intent: Intent) -> Unit) {
val activity = LocalContext.current as? ComponentActivity ?: return // Make sure we are actually in a `ComponentActivity`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import androidx.compose.ui.unit.dp
import dev.materii.pullrefresh.PullRefreshIndicator
import dev.materii.pullrefresh.PullRefreshState

/**
* Wrapper around [PullRefreshIndicator] that adds Material 3 theming
*
* @param refreshing A boolean representing whether a refresh is occurring
* @param state The [PullRefreshState] which controls where and how the indicator will be drawn.
*/
@Composable
fun BoxScope.RefreshIndicator(
refreshing: Boolean,
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/xyz/wingio/dimett/ui/components/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import xyz.wingio.dimett.utils.inlineContent
import xyz.wingio.dimett.utils.toAnnotatedString
import xyz.wingio.syntakts.compose.material3.clickable.ClickableText

/**
* Custom version of the Material 3 Text component that lets us deal with styled text much more easily
*/
@Composable
fun Text(
text: String,
Expand Down Expand Up @@ -55,6 +58,9 @@ fun Text(
modifier = modifier
)

/**
* Custom version of the Material 3 Text component that lets us deal with styled text much more easily
*/
@Composable
fun Text(
text: AnnotatedString,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/xyz/wingio/dimett/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fun processPostContent(post: Post): String {
if (repliedTo != null)
this
.replaceFirst("@${repliedTo.username} ", "") // @username
.replaceFirst("@${repliedTo.acct}", "") // @[email protected]
.replaceFirst("@${repliedTo.acct} ", "") // @[email protected]
else
this
} ?: ""
Expand Down

0 comments on commit 8d1b7e0

Please sign in to comment.