Skip to content

Commit

Permalink
Deep links;
Browse files Browse the repository at this point in the history
Open archive website from share icon;
  • Loading branch information
vipulyaara committed Oct 14, 2023
1 parent 58f1d47 commit 108ce7f
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "kafka-books"
}
}
6 changes: 2 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="vipulyaara.github.io" />
<data android:pathPrefix="/kafka" />
<data android:host="kafka-books.web.app" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
Expand All @@ -56,8 +55,7 @@
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="www.vipulyaara.github.io" />
<data android:pathPrefix="/kafka" />
<data android:host="www.kafka-books.web.app" />
</intent-filter>
</activity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class EventRepository @Inject constructor() {

fun shareItem(itemId: String) = "share_item" to mapOf("item_id" to itemId)

fun openArchiveItem(itemId: String) = "open_archive_item" to mapOf("item_id" to itemId)

fun setDownloadLocation(location: String) = "set_download_location" to mapOf(
"location" to location
)
Expand Down
13 changes: 13 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"storage": {
"rules": "storage.rules"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.kafka.navigation.deeplink

object Config {
private const val BASE_HOST = "vipulyaara.github.io"
const val BASE_URL = "https://$BASE_HOST/kafka/"
private const val BASE_HOST = "kafka-books.web.app"
const val BASE_URL = "https://$BASE_HOST/"

fun archiveDetailUrl(itemId: String) = "https://archive.org/details/$itemId"
}
39 changes: 39 additions & 0 deletions public/.well-known/assetlinks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"relation": [
"delegate_permission/common.handle_all_urls"
],
"target": {
"namespace": "android_app",
"package_name": "com.kafka.user",
"sha256_cert_fingerprints": [
"4E:52:3B:D3:E6:6B:08:16:E4:ED:E5:90:24:06:9B:7F:68:4F:25:5E:59:67:DA:E9:6D:25:CB:F6:22:2E:7E:A3",
"5A:32:2E:AF:B6:DC:82:2F:15:66:DC:5B:00:A7:37:9C:63:90:2C:1E:B0:46:94:C1:B1:B8:C8:F1:00:D0:2D:DB"
]
}
},
{
"relation": [
"delegate_permission/common.handle_all_urls"
],
"target": {
"namespace": "android_app",
"package_name": "com.kafka.user.debug",
"sha256_cert_fingerprints": [
"58:7A:25:D2:44:76:38:DB:B4:73:75:98:80:EC:64:A5:46:22:23:6B:2F:52:91:93:AB:52:FF:23:A7:97:95:39"
]
}
},
{
"relation": [
"delegate_permission/common.handle_all_urls"
],
"target": {
"namespace": "android_app",
"package_name": "com.kafka.user.rc",
"sha256_cert_fingerprints": [
"58:7A:25:D2:44:76:38:DB:B4:73:75:98:80:EC:64:A5:46:22:23:6B:2F:52:91:93:AB:52:FF:23:A7:97:95:39"
]
}
}
]
12 changes: 12 additions & 0 deletions storage.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rules_version = '2';

// Craft rules based on data in your Firestore database
// allow write: if firestore.get(
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.kafka.common.widgets

import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
Expand Down Expand Up @@ -57,12 +57,14 @@ fun IconButton(
rippleRadius: Dp = RippleRadius,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
onClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
content: @Composable BoxScope.() -> Unit
) {
Box(
modifier = modifier
.clickable(
.combinedClickable(
onClick = onClick,
onLongClick = onLongClick,
enabled = enabled,
role = Role.Button,
onClickLabel = onClickLabel,
Expand Down
1 change: 1 addition & 0 deletions ui/item/src/main/java/org/kafka/item/detail/ItemDetail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fun ItemDetail(viewModel: ItemDetailViewModel = hiltViewModel()) {
TopBar(
lazyGridState = lazyGridState,
onShareClicked = { viewModel.shareItemText(context) },
onShareLongClicked = { viewModel.openArchiveItem() },
onBackPressed = { navigator.goBack() },
isShareVisible = viewModel.isShareEnabled()
)
Expand Down
18 changes: 13 additions & 5 deletions ui/item/src/main/java/org/kafka/item/detail/ItemDetailTopBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package org.kafka.item.detail
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
Expand All @@ -27,6 +25,7 @@ import ui.common.theme.theme.Dimens
@Composable
internal fun TopBar(
onShareClicked: () -> Unit,
onShareLongClicked: () -> Unit,
onBackPressed: () -> Unit,
lazyGridState: LazyGridState,
isShareVisible: Boolean = true
Expand All @@ -49,17 +48,26 @@ internal fun TopBar(
},
actions = {
if (isShareVisible) {
ShareIcon(isRaised, onShareClicked)
ShareIcon(
isRaised = isRaised,
onClick = onShareClicked,
onLongClick = onShareLongClicked
)
}
}
)
}

@Composable
private fun ShareIcon(isRaised: Boolean, onShareClicked: () -> Unit) {
private fun ShareIcon(
isRaised: Boolean,
onClick: () -> Unit,
onLongClick: () -> Unit
) {
AnimatedVisibilityFade(!isRaised) {
IconButton(
onClick = { onShareClicked() },
onClick = onClick,
onLongClick = onLongClick,
modifier = Modifier.padding(Dimens.Spacing08)
) {
IconResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import org.kafka.navigation.RootScreen
import org.kafka.navigation.Screen
import org.kafka.navigation.Screen.ItemDescription
import org.kafka.navigation.Screen.Search
import org.kafka.navigation.deeplink.Config
import org.kafka.navigation.deeplink.DeepLinksNavigation
import org.kafka.navigation.deeplink.DynamicDeepLinkHandler
import org.kafka.navigation.deeplink.Navigation
import javax.inject.Inject

Expand Down Expand Up @@ -181,6 +181,11 @@ class ItemDetailViewModel @Inject constructor(
context.shareText(text)
}

fun openArchiveItem() {
analytics.log { this.openArchiveItem(itemId) }
navigator.navigate(Screen.Web.createRoute(currentRoot, Config.archiveDetailUrl(itemId)))
}

fun showAppRatingIfNeeded(context: Context) {
viewModelScope.launch { appReviewManager.incrementItemOpenCount() }

Expand Down
4 changes: 3 additions & 1 deletion ui/webview/src/main/java/org/kafka/webview/WebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fun WebView(url: String, goBack: () -> Unit) {

Scaffold(topBar = {
Column {
TopBar(navigationIcon = { BackButton { goBack() } })
TopBar(
title = webViewState.pageTitle.orEmpty(),
navigationIcon = { BackButton { goBack() } })
AnimatedVisibility(webViewState.isLoading) {
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
}
Expand Down

0 comments on commit 108ce7f

Please sign in to comment.