Skip to content

Commit

Permalink
tag prediction autofill prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
danielyrovas committed Apr 23, 2024
1 parent f39582b commit 2577a7a
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 93 deletions.
21 changes: 15 additions & 6 deletions app/src/main/java/org/yrovas/linklater/ui/activity/AppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package org.yrovas.linklater.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.StrictMode
import android.os.StrictMode.VmPolicy
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.SnackbarHostState
import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope
import com.ramcosta.composedestinations.generated.navgraphs.RootNavGraph
import com.ramcosta.composedestinations.spec.NavHostGraphSpec
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
Expand All @@ -26,6 +29,8 @@ fun Context.launch(

abstract class AppActivity : ComponentActivity() {

abstract val navGraph: NavHostGraphSpec

private val component by lazy(LazyThreadSafetyMode.NONE) {
AppComponent::class.create(this)
}
Expand All @@ -40,15 +45,19 @@ abstract class AppActivity : ComponentActivity() {
launch { snackState.showSnackbar(message) }
}

protected fun setContent(navGraph: NavHostGraphSpec) {
StrictMode.setVmPolicy(
VmPolicy.Builder(StrictMode.getVmPolicy())
.detectLeakedClosableObjects()
.build()
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// StrictMode.setVmPolicy(
// VmPolicy.Builder(StrictMode.getVmPolicy())
// .detectLeakedClosableObjects()
// .build()
// )

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

// https://stackoverflow.com/questions/73331594/how-can-i-show-a-composable-on-top-of-the-visible-keyboard
WindowCompat.setDecorFitsSystemWindows(window, false)

val destinationHost = component.destinationHost
launch {
// setup code that runs on first boot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.yrovas.linklater.ui.activity

import android.os.Bundle
import com.ramcosta.composedestinations.generated.navgraphs.RootNavGraph
import com.ramcosta.composedestinations.spec.NavHostGraphSpec
import me.tatarka.inject.annotations.Inject

@Inject
class MainActivity : AppActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent(RootNavGraph)
}
override val navGraph: NavHostGraphSpec = RootNavGraph
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.yrovas.linklater.ui.activity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import com.ramcosta.composedestinations.annotation.NavHostGraph
import com.ramcosta.composedestinations.generated.navgraphs.SaveBookmarkActivityNavGraph
import com.ramcosta.composedestinations.spec.NavHostGraphSpec

@NavHostGraph
annotation class SaveBookmarkActivityGraph

class SaveBookmarkActivity : AppActivity() {
override val navGraph: NavHostGraphSpec = SaveBookmarkActivityNavGraph

fun extractURL(): String {
var s = intent.data.toString()
if (s.isNotBlank() && s != "null") {
Expand All @@ -28,9 +30,4 @@ class SaveBookmarkActivity : AppActivity() {
}
return ""
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent(SaveBookmarkActivityNavGraph)
}
}
46 changes: 32 additions & 14 deletions app/src/main/java/org/yrovas/linklater/ui/common/Frame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
Expand All @@ -20,11 +24,15 @@ fun Frame(
back: (() -> Unit),
fab: (@Composable () -> Unit)? = null,
snackState: SnackbarHostState,
globalContent: @Composable () -> Unit = {},
content: @Composable () -> Unit,
) {
Frame(appBar = { AppBar(page, back)},
Frame(
appBar = { AppBar(page, back) },
fab = fab,
snackState = snackState) {
snackState = snackState,
globalContent = globalContent,
) {
content()
}
}
Expand All @@ -34,26 +42,36 @@ fun Frame(
appBar: @Composable () -> Unit,
fab: (@Composable () -> Unit)? = null,
snackState: SnackbarHostState,
globalContent: @Composable () -> Unit = {},
content: @Composable () -> Unit,
) {
Surface(
modifier = Modifier.fillMaxSize(),
color = colorScheme.background,
contentColor = colorScheme.onBackground
) {
Box(modifier = Modifier.fillMaxSize()) {
Column {
appBar()
content()
}
Column(modifier = Modifier.align(Alignment.BottomStart)) {
fab?.let {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) { fab() }
Box(
modifier = Modifier
.fillMaxSize()
// we set WindowCompat.setDecorFitsSystemWindows(window, false)
// so we now must include the window padding values
.padding(WindowInsets.systemBars.asPaddingValues())
) {
Box(modifier = Modifier.fillMaxSize()) {
globalContent()
Column {
appBar()
content()
}
Column(modifier = Modifier.align(Alignment.BottomStart)) {
fab?.let {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) { fab() }
}
SnackbarHost(hostState = snackState)
}
SnackbarHost(hostState = snackState)
}
}
}
Expand Down
67 changes: 67 additions & 0 deletions app/src/main/java/org/yrovas/linklater/ui/common/KeyboardRow.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.yrovas.linklater.ui.common

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.isImeVisible
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.zIndex

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun KeyboardRow(content: @Composable () -> Unit) {
val isImeVisible = WindowInsets.isImeVisible
val density = LocalDensity.current
val offsetY =
WindowInsets.ime.getBottom(density) - WindowInsets.systemBars.getBottom(
density
)

var previousOffset by remember { mutableStateOf(0) }

val isKeyboardGoingDown by remember(offsetY) {
derivedStateOf {
val isGoingDown = previousOffset - offsetY > 0
previousOffset = offsetY
isGoingDown
}
}
val showKeyboardRow by remember(
isImeVisible, isKeyboardGoingDown, offsetY
) {
mutableStateOf(isImeVisible && !isKeyboardGoingDown && offsetY != 0)
}

if (showKeyboardRow) {
Box(
modifier = Modifier
.fillMaxSize()
.zIndex(3f),
contentAlignment = Alignment.BottomStart
) {
Box(modifier = Modifier
.offset {
IntOffset(0, -offsetY)
}
// .height(100.dp)
// .border(5.dp, colorScheme.tertiaryContainer)
.fillMaxWidth()) {
content()
}
}
}
}
Loading

0 comments on commit 2577a7a

Please sign in to comment.