Skip to content

Commit

Permalink
feat: Improve BookmarkEditorActivity to handle invalid shared links
Browse files Browse the repository at this point in the history
- Show toast and finish activity for invalid shared links.
- Check user session before displaying the bookmark editor.
- Auto-add bookmark without editor screen if enabled.
- Handle cases with no shared URL.
  • Loading branch information
DesarrolloAntonio committed Aug 8, 2024
1 parent e3998e4 commit d399f5e
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package com.desarrollodroide.pagekeeper.extensions
*/
fun String.isRTLText(): Boolean {
// Take the first 20 characters of the string
val textSample = this.take(20)
val textSample = this.take(100)

// Count the number of Arabic characters in the sample
val arabicCount = textSample.count { char ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class BookmarkEditorActivity : ComponentActivity() {
sharedUrl = it
Log.v("Shared link", it)
}
} else {
Toast.makeText(this, "Invalid shared link", Toast.LENGTH_LONG).show()
finish()
}
}
lifecycleScope.launch {
Expand All @@ -42,36 +45,45 @@ class BookmarkEditorActivity : ComponentActivity() {
}
}
lifecycleScope.launch {
if (bookmarkViewModel.getAutoAddBookmark()) {
bookmarkViewModel.autoAddBookmark(sharedUrl)
} else {
setContent {
ShioriTheme {
if (bookmarkViewModel.userHasSession()) {
Surface(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.inverseOnSurface)
) {
BookmarkEditorScreen(
title = "Add",
bookmarkEditorType = BookmarkEditorType.ADD,
bookmark = Bookmark(
url = sharedUrl,
tags = emptyList(),
public = if (bookmarkViewModel.getMakeArchivePublic()) 1 else 0,
createArchive = bookmarkViewModel.getCreateArchive(),
createEbook = bookmarkViewModel.getCreateEbook()
),
onBack = { finish() },
updateBookmark = { finish() },
showToast = { message ->
Toast.makeText(this@BookmarkEditorActivity, message, Toast.LENGTH_LONG).show()
},
startMainActivity = { startMainActivity() }
)
if (sharedUrl.isNotEmpty()) {
if (bookmarkViewModel.userHasSession()) {
if (bookmarkViewModel.getAutoAddBookmark()) {
// Auto-add bookmark without showing the editor screen
bookmarkViewModel.autoAddBookmark(sharedUrl)
} else {
// Show the bookmark editor screen
setContent {
ShioriTheme {
Surface(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.inverseOnSurface)
) {
BookmarkEditorScreen(
title = "Add",
bookmarkEditorType = BookmarkEditorType.ADD,
bookmark = Bookmark(
url = sharedUrl,
tags = emptyList(),
public = if (bookmarkViewModel.getMakeArchivePublic()) 1 else 0,
createArchive = bookmarkViewModel.getCreateArchive(),
createEbook = bookmarkViewModel.getCreateEbook()
),
onBack = { finish() },
updateBookmark = { finish() },
showToast = { message ->
Toast.makeText(this@BookmarkEditorActivity, message, Toast.LENGTH_LONG).show()
},
startMainActivity = { startMainActivity() }
)
}
}
} else {
}
}
} else {
// User doesn't have a session, show login screen
setContent {
ShioriTheme {
NotSessionScreen(
onClickLogin = {
startMainActivity()
Expand All @@ -80,6 +92,10 @@ class BookmarkEditorActivity : ComponentActivity() {
}
}
}
} else {
// No shared URL, finish the activity
Toast.makeText(this@BookmarkEditorActivity, "No shared URL found", Toast.LENGTH_LONG).show()
finish()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.desarrollodroide.pagekeeper.ui.bookmarkeditor

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun ProgressButton(
progress: Float,
onClick: () -> Unit
) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(48.dp)
.clip(RoundedCornerShape(24.dp))
.background(MaterialTheme.colorScheme.primaryContainer)
.clickable(onClick = onClick)
) {
Box(
modifier = Modifier
.fillMaxHeight()
.fillMaxWidth(progress)
.background(MaterialTheme.colorScheme.primary)
)
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(
text = "Closing",
color = Color.White,
fontSize = 16.sp,
fontWeight = FontWeight.Medium
)
}
}
}

0 comments on commit d399f5e

Please sign in to comment.