Skip to content

Commit b332a5d

Browse files
committed
feat(search): Implement GitHub link detection and clipboard integration
This commit introduces the ability to detect GitHub repository links within the search query and from the system clipboard. Users can now quickly navigate to repository details by pasting or typing GitHub URLs, and the app will provide a banner for auto-detected links from the clipboard. - **feat(search)**: Added `GithubUrlParser` to identify and extract owner/repo metadata from GitHub URLs. - **feat(search)**: Implemented a clipboard banner that appears when a GitHub link is detected in the system clipboard. - **feat(search)**: Added a Floating Action Button (FAB) to manually trigger GitHub link detection from the clipboard. - **feat(search)**: Enhanced the search logic to automatically suggest navigation when the query consists entirely of GitHub URLs. - **feat(profile)**: Added a setting in the Appearance section to enable or disable automatic clipboard link detection. - **feat(core)**: Extended `ClipboardHelper` with `getText()` support for Android and Desktop platforms. - **refactor(core)**: Updated `ThemesRepository` to manage the persistence of the clipboard detection preference. - **i18n**: Added string resources for clipboard detection, link labels, and app-specific navigation prompts.
1 parent 2ea3c63 commit b332a5d

20 files changed

Lines changed: 472 additions & 23 deletions

File tree

1.86 KB
Binary file not shown.
1.88 KB
Binary file not shown.

composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/navigation/AppNavigation.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ fun AppNavigation(
102102
)
103103
)
104104
},
105+
onNavigateToDetailsFromLink = { owner, repo ->
106+
navController.navigate(
107+
GithubStoreGraph.DetailsScreen(
108+
owner = owner,
109+
repo = repo
110+
)
111+
)
112+
},
105113
onNavigateToDeveloperProfile = { username ->
106114
navController.navigate(
107115
GithubStoreGraph.DeveloperProfileScreen(

core/data/src/androidMain/kotlin/zed/rainxch/core/data/utils/AndroidClipboardHelper.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ class AndroidClipboardHelper(
1212
val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
1313
cm.setPrimaryClip(ClipData.newPlainText(label, text))
1414
}
15+
16+
override fun getText(): String? {
17+
val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
18+
val clip = cm.primaryClip ?: return null
19+
if (clip.itemCount == 0) return null
20+
return clip.getItemAt(0).text?.toString()
21+
}
1522
}

core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/ThemesRepositoryImpl.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ThemesRepositoryImpl(
1818
private val AMOLED_KEY = booleanPreferencesKey("amoled_theme")
1919
private val IS_DARK_THEME_KEY = booleanPreferencesKey("is_dark_theme")
2020
private val FONT_KEY = stringPreferencesKey("font_theme")
21+
private val AUTO_DETECT_CLIPBOARD_KEY = booleanPreferencesKey("auto_detect_clipboard_links")
2122

2223
override fun getThemeColor(): Flow<AppTheme> {
2324
return preferences.data.map { prefs ->
@@ -73,4 +74,16 @@ class ThemesRepositoryImpl(
7374
prefs[FONT_KEY] = fontTheme.name
7475
}
7576
}
77+
78+
override fun getAutoDetectClipboardLinks(): Flow<Boolean> {
79+
return preferences.data.map { prefs ->
80+
prefs[AUTO_DETECT_CLIPBOARD_KEY] ?: true
81+
}
82+
}
83+
84+
override suspend fun setAutoDetectClipboardLinks(enabled: Boolean) {
85+
preferences.edit { prefs ->
86+
prefs[AUTO_DETECT_CLIPBOARD_KEY] = enabled
87+
}
88+
}
7689
}

core/data/src/jvmMain/kotlin/zed/rainxch/core/data/utils/DesktopClipboardHelper.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@ package zed.rainxch.core.data.utils
22

33
import zed.rainxch.core.domain.utils.ClipboardHelper
44
import java.awt.Toolkit
5+
import java.awt.datatransfer.DataFlavor
56
import java.awt.datatransfer.StringSelection
67

78
class DesktopClipboardHelper : ClipboardHelper {
89
override fun copy(label: String, text: String) {
910
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
1011
clipboard.setContents(StringSelection(text), null)
1112
}
13+
14+
override fun getText(): String? {
15+
return try {
16+
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
17+
if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
18+
clipboard.getData(DataFlavor.stringFlavor) as? String
19+
} else null
20+
} catch (_: Exception) {
21+
null
22+
}
23+
}
1224
}

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/ThemesRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ interface ThemesRepository {
1313
suspend fun setAmoledTheme(enabled: Boolean)
1414
fun getFontTheme(): Flow<FontTheme>
1515
suspend fun setFontTheme(fontTheme: FontTheme)
16+
fun getAutoDetectClipboardLinks(): Flow<Boolean>
17+
suspend fun setAutoDetectClipboardLinks(enabled: Boolean)
1618
}

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/utils/ClipboardHelper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ interface ClipboardHelper {
55
label: String,
66
text: String
77
)
8+
9+
fun getText(): String?
810
}

core/presentation/src/commonMain/composeResources/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,13 @@
435435
<string name="search_language">Search language</string>
436436
<string name="change_language">Change language</string>
437437
<string name="translation_failed">Translation failed. Please try again.</string>
438+
439+
<!-- Search - GitHub Link -->
440+
<string name="open_github_link">Open GitHub Link</string>
441+
<string name="clipboard_link_detected">GitHub link detected in clipboard</string>
442+
<string name="auto_detect_clipboard_links">Auto-detect clipboard links</string>
443+
<string name="auto_detect_clipboard_description">Automatically detect GitHub links from clipboard when opening search</string>
444+
<string name="detected_links">Detected Links</string>
445+
<string name="open_in_app">Open in app</string>
446+
<string name="no_github_link_in_clipboard">No GitHub link found in clipboard</string>
438447
</resources>

feature/details/data/src/commonMain/kotlin/zed/rainxch/details/data/di/SharedModule.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ val detailsModule = module {
1818

1919
single<TranslationRepository> {
2020
TranslationRepositoryImpl(
21-
logger = get(),
2221
localizationManager = get()
2322
)
2423
}

0 commit comments

Comments
 (0)