Skip to content

Commit fe9bdfe

Browse files
feat: fetch name of link from intent when sharing (#95)
1 parent c768788 commit fe9bdfe

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

app/src/main/java/com/yogeshpaliyal/deepr/MainActivity.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ import com.yogeshpaliyal.deepr.ui.screens.home.HomeScreen
2828
import com.yogeshpaliyal.deepr.ui.theme.DeeprTheme
2929
import kotlinx.coroutines.flow.MutableStateFlow
3030

31+
data class SharedLink(
32+
val url: String,
33+
val title: String?,
34+
)
35+
3136
class MainActivity : ComponentActivity() {
32-
val sharingLink = MutableStateFlow<String?>(null)
37+
val sharingLink = MutableStateFlow<SharedLink?>(null)
3338

3439
@OptIn(ExperimentalMaterial3Api::class)
3540
override fun onCreate(savedInstanceState: Bundle?) {
@@ -56,7 +61,13 @@ class MainActivity : ComponentActivity() {
5661
when {
5762
intent.action == Intent.ACTION_SEND -> {
5863
if (intent.type == "text/plain") {
59-
intent.getStringExtra(Intent.EXTRA_TEXT)
64+
val link = intent.getStringExtra(Intent.EXTRA_TEXT)
65+
val title = intent.getStringExtra(Intent.EXTRA_TITLE)
66+
if (link != null) {
67+
SharedLink(link, title)
68+
} else {
69+
null
70+
}
6071
} else {
6172
null
6273
}
@@ -76,7 +87,7 @@ class MainActivity : ComponentActivity() {
7687
@Composable
7788
fun Dashboard(
7889
modifier: Modifier = Modifier,
79-
sharedText: String? = null,
90+
sharedText: SharedLink? = null,
8091
resetSharedText: () -> Unit,
8192
) {
8293
val backStack = remember(sharedText) { mutableStateListOf<Any>(Home) }

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/Home.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
5757
import com.journeyapps.barcodescanner.ScanOptions
5858
import com.yogeshpaliyal.deepr.DeeprQueries
5959
import com.yogeshpaliyal.deepr.GetLinksAndTags
60+
import com.yogeshpaliyal.deepr.SharedLink
6061
import com.yogeshpaliyal.deepr.Tags
6162
import com.yogeshpaliyal.deepr.ui.components.CreateShortcutDialog
6263
import com.yogeshpaliyal.deepr.ui.components.QrCodeDialog
@@ -96,7 +97,7 @@ fun HomeScreen(
9697
modifier: Modifier = Modifier,
9798
viewModel: AccountViewModel = koinViewModel(),
9899
deeprQueries: DeeprQueries = koinInject(),
99-
sharedText: String? = null,
100+
sharedText: SharedLink? = null,
100101
resetSharedText: () -> Unit,
101102
) {
102103
var isTagsSelectionActive by remember { mutableStateOf(false) }
@@ -126,9 +127,9 @@ fun HomeScreen(
126127

127128
// Handle shared text from other apps
128129
LaunchedEffect(sharedText) {
129-
if (!sharedText.isNullOrBlank() && selectedLink == null) {
130-
if (isValidDeeplink(sharedText)) {
131-
selectedLink = createDeeprObject(link = sharedText)
130+
if (!sharedText?.url.isNullOrBlank() && selectedLink == null) {
131+
if (isValidDeeplink(sharedText.url)) {
132+
selectedLink = createDeeprObject(link = sharedText.url, name = sharedText.title ?: "")
132133
} else {
133134
Toast
134135
.makeText(context, "Invalid deeplink from shared content", Toast.LENGTH_SHORT)

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/HomeBottomContent.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,6 @@ fun HomeBottomContent(
103103
}
104104
}
105105

106-
LaunchedEffect(Unit) {
107-
deeprInfo.link?.let {
108-
viewModel.fetchMetaData(it) {
109-
if (it != null) {
110-
deeprInfo = deeprInfo.copy(name = it.title ?: "")
111-
isNameError = false
112-
}
113-
}
114-
}
115-
}
116-
117106
val save: (executeAfterSave: Boolean) -> Unit = { executeAfterSave ->
118107
// Remove unselected tags
119108
val initialTagIds = initialSelectedTags.map { it.id }.toSet()

0 commit comments

Comments
 (0)