Skip to content

Commit 2124fd1

Browse files
authored
Merge pull request #92 from sameerasw/nearby
Nearby - QuickShare auto accept impleemntation, Remove old file share
2 parents c51ad61 + 8c0567e commit 2124fd1

35 files changed

Lines changed: 3643 additions & 1077 deletions

app/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.android.application)
77
alias(libs.plugins.google.ksp)
88
alias(libs.plugins.kotlin.compose)
9+
alias(libs.plugins.wire)
910
}
1011

1112
android {
@@ -150,4 +151,13 @@ dependencies {
150151
androidTestImplementation(libs.androidx.ui.test.junit4)
151152
debugImplementation(libs.androidx.ui.tooling)
152153
debugImplementation(libs.androidx.ui.test.manifest)
154+
155+
implementation(libs.wire.runtime)
156+
implementation(libs.bouncycastle)
157+
}
158+
159+
wire {
160+
kotlin {
161+
// Wire defaults to current project's proto directory
162+
}
153163
}

app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
<uses-permission android:name="android.permission.POST_PROMOTED_NOTIFICATIONS" />
1313
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
1414
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
15+
1516
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
1617
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
1718
<uses-permission android:name="android.permission.READ_WALLPAPER_INTERNAL" />
1819

1920

21+
2022
<!-- Permission for downloading updates -->
2123
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
2224

@@ -87,30 +89,7 @@
8789
</intent-filter>
8890
</activity>
8991

90-
<!-- Share target activity for text sharing -->
91-
<activity
92-
android:name=".presentation.ui.activities.ShareActivity"
93-
android:exported="true"
94-
android:theme="@android:style/Theme.Translucent.NoTitleBar"
95-
android:noHistory="true">
96-
<intent-filter>
97-
<action android:name="android.intent.action.SEND" />
98-
<category android:name="android.intent.category.DEFAULT" />
99-
<data android:mimeType="text/plain" />
100-
</intent-filter>
101-
<!-- Accept any single file type -->
102-
<intent-filter>
103-
<action android:name="android.intent.action.SEND" />
104-
<category android:name="android.intent.category.DEFAULT" />
105-
<data android:mimeType="*/*" />
106-
</intent-filter>
107-
<!-- Accept multiple files -->
108-
<intent-filter>
109-
<action android:name="android.intent.action.SEND_MULTIPLE" />
110-
<category android:name="android.intent.category.DEFAULT" />
111-
<data android:mimeType="*/*" />
112-
</intent-filter>
113-
</activity>
92+
11493

11594
<activity
11695
android:name=".presentation.ui.activities.ClipboardActionActivity"
@@ -181,6 +160,8 @@
181160
</intent-filter>
182161
</service>
183162

163+
164+
184165
<!-- Wake-up Service for receiving reconnection requests from Mac -->
185166
<service
186167
android:name=".service.WakeupService"
@@ -192,6 +173,11 @@
192173
android:exported="false"
193174
android:foregroundServiceType="connectedDevice" />
194175

176+
<service
177+
android:name=".quickshare.QuickShareService"
178+
android:exported="false"
179+
android:foregroundServiceType="connectedDevice" />
180+
195181
<!-- Call Receiver - listens for telephony events -->
196182
<receiver
197183
android:name=".service.CallReceiver"

app/src/main/java/com/sameerasw/airsync/data/local/DataStoreManager.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class DataStoreManager(private val context: Context) {
9191
private val USE_BLUR = booleanPreferencesKey("use_blur")
9292
private val PITCH_BLACK_THEME = booleanPreferencesKey("pitch_black_theme")
9393
private val SENTRY_REPORTING_ENABLED = booleanPreferencesKey("sentry_reporting_enabled")
94+
private val QUICK_SHARE_ENABLED = booleanPreferencesKey("quick_share_enabled")
9495

9596
// Widget preferences
9697
private val WIDGET_TRANSPARENCY = androidx.datastore.preferences.core.floatPreferencesKey("widget_transparency")
@@ -328,6 +329,18 @@ class DataStoreManager(private val context: Context) {
328329
}
329330
}
330331

332+
suspend fun setQuickShareEnabled(enabled: Boolean) {
333+
context.dataStore.edit { preferences ->
334+
preferences[QUICK_SHARE_ENABLED] = enabled
335+
}
336+
}
337+
338+
fun isQuickShareEnabled(): Flow<Boolean> {
339+
return context.dataStore.data.map { preferences ->
340+
preferences[QUICK_SHARE_ENABLED] ?: false // Default to disabled
341+
}
342+
}
343+
331344
suspend fun setDefaultTab(tab: String) {
332345
context.dataStore.edit { prefs ->
333346
prefs[DEFAULT_TAB] = tab

app/src/main/java/com/sameerasw/airsync/data/repository/AirSyncRepositoryImpl.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,12 @@ class AirSyncRepositoryImpl(
287287
override fun hasRatedApp(): Flow<Boolean> {
288288
return dataStoreManager.hasRatedApp()
289289
}
290+
291+
override suspend fun setQuickShareEnabled(enabled: Boolean) {
292+
dataStoreManager.setQuickShareEnabled(enabled)
293+
}
294+
295+
override fun isQuickShareEnabled(): Flow<Boolean> {
296+
return dataStoreManager.isQuickShareEnabled()
297+
}
290298
}

app/src/main/java/com/sameerasw/airsync/domain/model/UiState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ data class UiState(
4848
val isBlurEnabled: Boolean = true,
4949
val isSentryReportingEnabled: Boolean = true,
5050
val isOnboardingCompleted: Boolean = true,
51-
val widgetTransparency: Float = 1f
51+
val widgetTransparency: Float = 1f,
52+
val isQuickShareEnabled: Boolean = false
5253
)

app/src/main/java/com/sameerasw/airsync/domain/repository/AirSyncRepository.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,8 @@ interface AirSyncRepository {
128128
fun getLastPromptDismissedVersion(): Flow<Int>
129129
suspend fun setHasRatedApp(hasRated: Boolean)
130130
fun hasRatedApp(): Flow<Boolean>
131+
132+
// Quick Share (receiving)
133+
suspend fun setQuickShareEnabled(enabled: Boolean)
134+
fun isQuickShareEnabled(): Flow<Boolean>
131135
}

app/src/main/java/com/sameerasw/airsync/presentation/ui/activities/ShareActivity.kt

Lines changed: 0 additions & 162 deletions
This file was deleted.

app/src/main/java/com/sameerasw/airsync/presentation/ui/components/AboutSection.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ import androidx.compose.ui.layout.ContentScale
3737
import androidx.compose.ui.platform.LocalContext
3838
import androidx.compose.ui.platform.LocalHapticFeedback
3939
import androidx.compose.ui.res.painterResource
40+
import androidx.compose.ui.res.stringResource
41+
import androidx.compose.ui.text.AnnotatedString
42+
import androidx.compose.ui.text.SpanStyle
43+
import androidx.compose.ui.text.buildAnnotatedString
44+
import androidx.compose.ui.text.font.FontWeight
4045
import androidx.compose.ui.text.style.TextAlign
46+
import androidx.compose.ui.text.style.TextDecoration
47+
import androidx.compose.foundation.text.ClickableText
4148
import androidx.compose.ui.unit.dp
4249
import androidx.core.net.toUri
4350
import com.sameerasw.airsync.R
@@ -166,6 +173,44 @@ fun AboutSection(
166173
)
167174
}
168175

176+
val creditText = stringResource(id = R.string.label_app_icon_credits)
177+
val annotatedString = buildAnnotatedString {
178+
append(creditText)
179+
val startIndex = creditText.indexOf("@Syntrop2k2")
180+
val endIndex = startIndex + "@Syntrop2k2".length
181+
if (startIndex != -1) {
182+
addStringAnnotation(
183+
tag = "URL",
184+
annotation = stringResource(id = R.string.url_syntrop_telegram),
185+
start = startIndex,
186+
end = endIndex
187+
)
188+
addStyle(
189+
style = SpanStyle(
190+
color = MaterialTheme.colorScheme.primary,
191+
fontWeight = FontWeight.Bold,
192+
textDecoration = TextDecoration.Underline
193+
),
194+
start = startIndex,
195+
end = endIndex
196+
)
197+
}
198+
}
199+
200+
ClickableText(
201+
text = annotatedString,
202+
style = MaterialTheme.typography.bodyMedium.copy(
203+
textAlign = TextAlign.Center,
204+
color = MaterialTheme.colorScheme.onSurfaceVariant
205+
),
206+
onClick = { offset ->
207+
annotatedString.getStringAnnotations(tag = "URL", start = offset, end = offset)
208+
.firstOrNull()?.let { annotation ->
209+
openUrl(context, annotation.item)
210+
}
211+
}
212+
)
213+
169214
Text(
170215
text = "Other Apps",
171216
style = MaterialTheme.typography.titleMedium,

app/src/main/java/com/sameerasw/airsync/presentation/ui/components/SettingsView.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ fun SettingsView(
165165
isClipboardTileAdded = com.sameerasw.airsync.utils.QuickSettingsUtil.isQSTileAdded(
166166
context,
167167
com.sameerasw.airsync.service.ClipboardTileService::class.java
168+
),
169+
isQuickShareTileAdded = com.sameerasw.airsync.utils.QuickSettingsUtil.isQSTileAdded(
170+
context,
171+
168172
)
169173
)
170174
}
@@ -256,6 +260,15 @@ fun SettingsView(
256260
viewModel.setMacMediaControlsEnabled(enabled)
257261
}
258262
)
263+
264+
SendNowPlayingCard(
265+
isSendNowPlayingEnabled = uiState.isQuickShareEnabled,
266+
onToggleSendNowPlaying = { enabled: Boolean ->
267+
viewModel.setQuickShareEnabled(context, enabled)
268+
},
269+
title = "Quick Share",
270+
subtitle = "Allow receiving files from nearby devices"
271+
)
259272
}
260273
}
261274

0 commit comments

Comments
 (0)