rename flow activity to save activity
This commit is contained in:
@ -29,7 +29,7 @@
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.save.NewFlowActivity"
|
||||
android:name=".ui.save.SaveSheetActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.AppCompat.Translucent">
|
||||
<intent-filter>
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
package app.omnivore.omnivore.ui.save
|
||||
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import app.omnivore.omnivore.ui.save.SaveSheetActivity
|
||||
|
||||
// Not sure why we need this class, but directly opening SaveSheetActivity
|
||||
// causes the app to crash.
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
class NewFlowActivity : SaveSheetActivity() {
|
||||
|
||||
}
|
||||
@ -23,148 +23,150 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
// Not sure why we need this class, but directly opening SaveSheetActivity
|
||||
// causes the app to crash.
|
||||
class SaveSheetActivity : SaveSheetActivityBase() {}
|
||||
|
||||
@AndroidEntryPoint
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
abstract class SaveSheetActivity: AppCompatActivity() {
|
||||
abstract class SaveSheetActivityBase: AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val viewModel: SaveViewModel by viewModels()
|
||||
var extractedText: String? = null
|
||||
|
||||
val viewModel: SaveViewModel by viewModels()
|
||||
var extractedText: String? = null
|
||||
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_SEND -> {
|
||||
if (intent.type?.startsWith("text/plain") == true) {
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||
Log.d(ContentValues.TAG, "Extracted text: $extractedText")
|
||||
extractedText = it
|
||||
viewModel.saveURL(it)
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.type?.startsWith("text/html") == true) {
|
||||
intent.getStringExtra(Intent.EXTRA_HTML_TEXT)?.let {
|
||||
extractedText = it
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
// Handle other intents, such as being started from the home screen
|
||||
}
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_SEND -> {
|
||||
if (intent.type?.startsWith("text/plain") == true) {
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||
Log.d(ContentValues.TAG, "Extracted text: $extractedText")
|
||||
extractedText = it
|
||||
viewModel.saveURL(it)
|
||||
}
|
||||
}
|
||||
|
||||
setContent {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val modalBottomSheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
|
||||
val isSheetOpened = remember { mutableStateOf(false) }
|
||||
|
||||
ModalBottomSheetLayout(
|
||||
sheetBackgroundColor = Color.Transparent,
|
||||
sheetState = modalBottomSheetState,
|
||||
sheetContent = {
|
||||
BottomSheetUI {
|
||||
ScreenContent(viewModel, modalBottomSheetState)
|
||||
}
|
||||
}
|
||||
) {}
|
||||
|
||||
BackHandler {
|
||||
onFinish(coroutineScope, modalBottomSheetState)
|
||||
}
|
||||
|
||||
// Take action based on hidden state
|
||||
LaunchedEffect(modalBottomSheetState.currentValue) {
|
||||
when (modalBottomSheetState.currentValue) {
|
||||
ModalBottomSheetValue.Hidden -> {
|
||||
handleBottomSheetAtHiddenState(
|
||||
isSheetOpened,
|
||||
modalBottomSheetState
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
Log.i(TAG, "Bottom sheet ${modalBottomSheetState.currentValue} state")
|
||||
}
|
||||
}
|
||||
}
|
||||
if (intent.type?.startsWith("text/html") == true) {
|
||||
intent.getStringExtra(Intent.EXTRA_HTML_TEXT)?.let {
|
||||
extractedText = it
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
// Handle other intents, such as being started from the home screen
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BottomSheetUI(content: @Composable () -> Unit) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.wrapContentHeight()
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(topEnd = 20.dp, topStart = 20.dp))
|
||||
.background(Color.White)
|
||||
.statusBarsPadding()
|
||||
) {
|
||||
content()
|
||||
setContent {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val modalBottomSheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
|
||||
val isSheetOpened = remember { mutableStateOf(false) }
|
||||
|
||||
Divider(
|
||||
color = Color.Gray,
|
||||
thickness = 5.dp,
|
||||
modifier = Modifier
|
||||
.padding(top = 15.dp)
|
||||
.align(TopCenter)
|
||||
.width(80.dp)
|
||||
.clip(RoundedCornerShape(50.dp))
|
||||
ModalBottomSheetLayout(
|
||||
sheetBackgroundColor = Color.Transparent,
|
||||
sheetState = modalBottomSheetState,
|
||||
sheetContent = {
|
||||
BottomSheetUI {
|
||||
ScreenContent(viewModel, modalBottomSheetState)
|
||||
}
|
||||
}
|
||||
) {}
|
||||
|
||||
BackHandler {
|
||||
onFinish(coroutineScope, modalBottomSheetState)
|
||||
}
|
||||
|
||||
// Take action based on hidden state
|
||||
LaunchedEffect(modalBottomSheetState.currentValue) {
|
||||
when (modalBottomSheetState.currentValue) {
|
||||
ModalBottomSheetValue.Hidden -> {
|
||||
handleBottomSheetAtHiddenState(
|
||||
isSheetOpened,
|
||||
modalBottomSheetState
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
Log.i(TAG, "Bottom sheet ${modalBottomSheetState.currentValue} state")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
private suspend fun handleBottomSheetAtHiddenState(
|
||||
isSheetOpened: MutableState<Boolean>,
|
||||
modalBottomSheetState: ModalBottomSheetState
|
||||
@Composable
|
||||
private fun BottomSheetUI(content: @Composable () -> Unit) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.wrapContentHeight()
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(topEnd = 20.dp, topStart = 20.dp))
|
||||
.background(Color.White)
|
||||
.statusBarsPadding()
|
||||
) {
|
||||
when {
|
||||
!isSheetOpened.value -> initializeModalLayout(isSheetOpened, modalBottomSheetState)
|
||||
else -> exit()
|
||||
}
|
||||
}
|
||||
content()
|
||||
|
||||
private suspend fun initializeModalLayout(
|
||||
isSheetOpened: MutableState<Boolean>,
|
||||
modalBottomSheetState: ModalBottomSheetState
|
||||
) {
|
||||
isSheetOpened.value = true
|
||||
modalBottomSheetState.show()
|
||||
Divider(
|
||||
color = Color.Gray,
|
||||
thickness = 5.dp,
|
||||
modifier = Modifier
|
||||
.padding(top = 15.dp)
|
||||
.align(TopCenter)
|
||||
.width(80.dp)
|
||||
.clip(RoundedCornerShape(50.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
open fun exit() = finish()
|
||||
|
||||
private fun onFinish(
|
||||
coroutineScope: CoroutineScope,
|
||||
modalBottomSheetState: ModalBottomSheetState,
|
||||
withResults: Boolean = false,
|
||||
result: Intent? = null
|
||||
) {
|
||||
coroutineScope.launch {
|
||||
if (withResults) setResult(RESULT_OK)
|
||||
result?.let { intent = it}
|
||||
modalBottomSheetState.hide() // will trigger the LaunchedEffect
|
||||
}
|
||||
// Helper methods
|
||||
private suspend fun handleBottomSheetAtHiddenState(
|
||||
isSheetOpened: MutableState<Boolean>,
|
||||
modalBottomSheetState: ModalBottomSheetState
|
||||
) {
|
||||
when {
|
||||
!isSheetOpened.value -> initializeModalLayout(isSheetOpened, modalBottomSheetState)
|
||||
else -> exit()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ScreenContent(
|
||||
viewModel: SaveViewModel,
|
||||
modalBottomSheetState: ModalBottomSheetState
|
||||
) {
|
||||
Box(modifier = Modifier.height(300.dp).background(Color.White)) {
|
||||
SaveContent(viewModel, modalBottomSheetState, modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
private suspend fun initializeModalLayout(
|
||||
isSheetOpened: MutableState<Boolean>,
|
||||
modalBottomSheetState: ModalBottomSheetState
|
||||
) {
|
||||
isSheetOpened.value = true
|
||||
modalBottomSheetState.show()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
open fun exit() = finish()
|
||||
|
||||
companion object {
|
||||
private val TAG = SaveSheetActivity::class.java.simpleName
|
||||
private fun onFinish(
|
||||
coroutineScope: CoroutineScope,
|
||||
modalBottomSheetState: ModalBottomSheetState,
|
||||
withResults: Boolean = false,
|
||||
result: Intent? = null
|
||||
) {
|
||||
coroutineScope.launch {
|
||||
if (withResults) setResult(RESULT_OK)
|
||||
result?.let { intent = it}
|
||||
modalBottomSheetState.hide() // will trigger the LaunchedEffect
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ScreenContent(
|
||||
viewModel: SaveViewModel,
|
||||
modalBottomSheetState: ModalBottomSheetState
|
||||
) {
|
||||
Box(modifier = Modifier.height(300.dp).background(Color.White)) {
|
||||
SaveContent(viewModel, modalBottomSheetState, modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = SaveSheetActivity::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user