Skip to content

Commit caf9cc8

Browse files
committed
refactor: code optimization
1 parent 9e378b5 commit caf9cc8

172 files changed

Lines changed: 3298 additions & 2250 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle.kts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.gradle.api.JavaVersion.VERSION_11
2-
import org.gradle.api.JavaVersion.VERSION_17
31
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
42

53
plugins {
@@ -49,11 +47,11 @@ android {
4947
sourceCompatibility = JavaVersion.VERSION_21
5048
targetCompatibility = JavaVersion.VERSION_21
5149
}
52-
kotlin {
53-
compilerOptions {
54-
jvmTarget.set(JvmTarget.JVM_21)
50+
kotlin {
51+
compilerOptions {
52+
jvmTarget.set(JvmTarget.JVM_21)
53+
}
5554
}
56-
}
5755
buildFeatures {
5856
compose = true
5957
buildConfig = true
@@ -86,7 +84,7 @@ dependencies {
8684
// Android 12+ SplashScreen API with backward compatibility attributes
8785
implementation("androidx.core:core-splashscreen:1.0.1")
8886

89-
implementation ("androidx.compose.material3:material3:1.5.0-alpha10")
87+
implementation("androidx.compose.material3:material3:1.5.0-alpha10")
9088
implementation("androidx.compose.material:material-icons-core:1.7.8")
9189
implementation("androidx.compose.material:material-icons-extended:1.7.8")
9290

app/src/androidTest/java/com/sameerasw/airsync/ExampleInstrumentedTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.sameerasw.airsync
22

3-
import androidx.test.platform.app.InstrumentationRegistry
43
import androidx.test.ext.junit.runners.AndroidJUnit4
5-
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import org.junit.Assert.assertEquals
66
import org.junit.Test
77
import org.junit.runner.RunWith
88

9-
import org.junit.Assert.*
10-
119
/**
1210
* Instrumented test, which will execute on an Android device.
1311
*

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
2020
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
2121
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
22-
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
22+
23+
<uses-feature
24+
android:name="android.hardware.bluetooth_le"
25+
android:required="false" />
2326

2427
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
2528
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
2629
<uses-permission android:name="android.permission.READ_WALLPAPER_INTERNAL" />
2730

2831

29-
3032
<!-- Permission for downloading updates -->
3133
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
3234

@@ -57,21 +59,23 @@
5759
android:fullBackupContent="@xml/backup_rules"
5860
android:icon="@mipmap/ic_launcher"
5961
android:label="@string/app_name"
62+
android:networkSecurityConfig="@xml/network_security_config"
6063
android:roundIcon="@mipmap/ic_launcher_round"
6164
android:supportsRtl="true"
6265
android:theme="@style/Theme.AirSync"
63-
android:networkSecurityConfig="@xml/network_security_config"
6466
tools:targetApi="36">
6567

6668
<!-- Disable Sentry auto-init as it's handled manually in AirSyncApp -->
67-
<meta-data android:name="io.sentry.auto-init" android:value="false" />
69+
<meta-data
70+
android:name="io.sentry.auto-init"
71+
android:value="false" />
6872

6973
<activity
7074
android:name=".MainActivity"
75+
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
7176
android:exported="true"
7277
android:label="@string/app_name"
73-
android:theme="@style/Theme.AirSync.Splash"
74-
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden">
78+
android:theme="@style/Theme.AirSync.Splash">
7579
<!-- Main launcher intent filter -->
7680
<intent-filter>
7781
<action android:name="android.intent.action.MAIN" />
@@ -87,29 +91,30 @@
8791
<!-- Deep link intent filter for QR codes -->
8892
<intent-filter>
8993
<action android:name="android.intent.action.VIEW" />
94+
9095
<category android:name="android.intent.category.DEFAULT" />
9196
<category android:name="android.intent.category.BROWSABLE" />
97+
9298
<data android:scheme="airsync" />
9399
</intent-filter>
94100

95101
<intent-filter>
96102
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
97103
</intent-filter>
98-
104+
99105
<meta-data
100106
android:name="android.app.shortcuts"
101107
android:resource="@xml/shortcuts" />
102108
</activity>
103109

104110

105-
106111
<activity
107112
android:name=".presentation.ui.activities.ClipboardActionActivity"
108-
android:theme="@style/Theme.AirSync.Transparent"
109-
android:exported="true"
110113
android:excludeFromRecents="true"
114+
android:exported="true"
111115
android:noHistory="true"
112-
android:taskAffinity="">
116+
android:taskAffinity=""
117+
android:theme="@style/Theme.AirSync.Transparent">
113118
<intent-filter>
114119
<action android:name="android.intent.action.SEND" />
115120
<category android:name="android.intent.category.DEFAULT" />
@@ -131,8 +136,8 @@
131136
android:name=".presentation.ui.activities.QRScannerActivity"
132137
android:exported="true"
133138
android:label="@string/app_name"
134-
android:theme="@style/Theme.AirSync"
135-
android:screenOrientation="portrait">
139+
android:screenOrientation="portrait"
140+
android:theme="@style/Theme.AirSync">
136141
<!-- Allow external apps to launch the scanner -->
137142
<intent-filter>
138143
<action android:name="com.sameerasw.airsync.SCAN_QR" />
@@ -151,8 +156,7 @@
151156
<service
152157
android:name=".service.MacMediaPlayerService"
153158
android:exported="false"
154-
android:foregroundServiceType="connectedDevice">
155-
</service>
159+
android:foregroundServiceType="connectedDevice"></service>
156160

157161
<!-- Quick Settings Tile Service -->
158162
<service
@@ -179,7 +183,6 @@
179183
</service>
180184

181185

182-
183186
<!-- Wake-up Service for receiving reconnection requests from Mac -->
184187
<service
185188
android:name=".service.WakeupService"
@@ -234,8 +237,8 @@
234237
<provider
235238
android:name=".smartspacer.AirSyncDeviceTarget"
236239
android:authorities="${applicationId}.target.airsync_device"
237-
android:permission="com.kieronquinn.app.smartspacer.permission.ACCESS_SMARTSPACER_TARGETS"
238-
android:exported="true">
240+
android:exported="true"
241+
android:permission="com.kieronquinn.app.smartspacer.permission.ACCESS_SMARTSPACER_TARGETS">
239242
<intent-filter>
240243
<action android:name="com.kieronquinn.app.smartspacer.TARGET" />
241244
</intent-filter>
@@ -270,8 +273,9 @@
270273
<action android:name="android.intent.action.MAIN" />
271274
<category android:name="android.intent.category.LAUNCHER" />
272275
</intent>
273-
<package android:name="com.google.ar.lens" />
274-
<package android:name="com.sameerasw.essentials" />
276+
277+
<package android:name="com.google.ar.lens" />
278+
<package android:name="com.sameerasw.essentials" />
275279
</queries>
276280

277281
</manifest>

app/src/main/java/com/sameerasw/airsync/AirSyncApp.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,29 @@ class AirSyncApp : Application() {
1515
companion object {
1616
private var instance: AirSyncApp? = null
1717
fun isAppForeground(): Boolean = instance?.isForeground() ?: false
18-
fun getBleConnectionManager(): com.sameerasw.airsync.data.ble.BleConnectionManager? = instance?.bleConnectionManager
18+
fun getBleConnectionManager(): com.sameerasw.airsync.data.ble.BleConnectionManager? =
19+
instance?.bleConnectionManager
1920
}
2021

2122
override fun onCreate() {
2223
super.onCreate()
2324
instance = this
2425
initSentry()
25-
26+
2627
bleConnectionManager = com.sameerasw.airsync.data.ble.BleConnectionManager(this)
2728
bleConnectionManager.start()
2829
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
2930
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
3031
override fun onActivityStarted(activity: Activity) {
3132
activityCount++
3233
}
34+
3335
override fun onActivityResumed(activity: Activity) {}
3436
override fun onActivityPaused(activity: Activity) {}
3537
override fun onActivityStopped(activity: Activity) {
3638
activityCount--
3739
}
40+
3841
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
3942
override fun onActivityDestroyed(activity: Activity) {}
4043
})
@@ -49,7 +52,8 @@ class AirSyncApp : Application() {
4952
if (!isEnabled) return
5053

5154
SentryAndroid.init(this) { options ->
52-
options.dsn = "https://cb9b0ead9e88e0818269e773cb662141@o4510996760887296.ingest.de.sentry.io/4511002261389392"
55+
options.dsn =
56+
"https://cb9b0ead9e88e0818269e773cb662141@o4510996760887296.ingest.de.sentry.io/4511002261389392"
5357
options.isEnabled = true
5458
}
5559
}

app/src/main/java/com/sameerasw/airsync/MainActivity.kt

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,15 @@ import android.widget.Toast
1212
import androidx.activity.ComponentActivity
1313
import androidx.activity.compose.setContent
1414
import androidx.activity.result.contract.ActivityResultContracts
15-
import androidx.compose.foundation.Image
16-
import androidx.compose.foundation.layout.Row
17-
import androidx.compose.foundation.layout.Spacer
18-
import androidx.compose.foundation.layout.WindowInsets
1915
import androidx.compose.foundation.layout.fillMaxSize
2016
import androidx.compose.foundation.layout.padding
21-
import androidx.compose.foundation.layout.size
22-
import androidx.compose.foundation.layout.statusBars
23-
import androidx.compose.foundation.layout.width
24-
import androidx.compose.foundation.layout.windowInsetsPadding
25-
import androidx.compose.material.icons.rounded.HelpOutline
2617
import androidx.compose.material3.ExperimentalMaterial3Api
27-
import androidx.compose.material3.Icon
28-
import androidx.compose.material3.IconButton
29-
import androidx.compose.material3.IconButtonDefaults
3018
import androidx.compose.material3.MaterialTheme
3119
import androidx.compose.material3.Scaffold
32-
import androidx.compose.material3.Text
33-
import androidx.compose.material3.Surface
3420
import androidx.compose.runtime.LaunchedEffect
3521
import androidx.compose.runtime.collectAsState
3622
import androidx.compose.runtime.getValue
37-
import androidx.compose.runtime.mutableStateOf
38-
import androidx.compose.runtime.remember
39-
import androidx.compose.runtime.setValue
4023
import androidx.compose.ui.Modifier
41-
import androidx.compose.ui.graphics.ColorFilter
42-
import androidx.compose.ui.input.nestedscroll.nestedScroll
43-
import androidx.compose.ui.layout.ContentScale
44-
import androidx.compose.ui.res.painterResource
45-
import androidx.compose.ui.unit.dp
4624
import androidx.core.animation.doOnEnd
4725
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
4826
import androidx.navigation.compose.NavHost
@@ -52,7 +30,6 @@ import com.sameerasw.airsync.data.local.DataStoreManager
5230
import com.sameerasw.airsync.presentation.ui.activities.QRScannerActivity
5331
import com.sameerasw.airsync.presentation.ui.screens.AirSyncMainScreen
5432
import com.sameerasw.airsync.ui.theme.AirSyncTheme
55-
import com.sameerasw.airsync.presentation.viewmodel.AirSyncViewModel
5633
import com.sameerasw.airsync.utils.AdbMdnsDiscovery
5734
import com.sameerasw.airsync.utils.ContentCaptureManager
5835
import com.sameerasw.airsync.utils.DevicePreviewResolver
@@ -246,7 +223,8 @@ class MainActivity : ComponentActivity() {
246223
this@MainActivity,
247224
R.color.material_primary
248225
)
249-
splashIcon.imageTintList = android.content.res.ColorStateList.valueOf(colorPrimary)
226+
splashIcon.imageTintList =
227+
android.content.res.ColorStateList.valueOf(colorPrimary)
250228
Log.d("MainActivity", "Switched to device icon with primary tint")
251229

252230
// Fade in the new device icon
@@ -299,28 +277,28 @@ class MainActivity : ComponentActivity() {
299277
fadeOutIcon.start()
300278
} else {
301279
// No device icon found, or splashIcon is null/not ImageView (OEM device compatibility)
302-
// Proceed directly to outro after a brief hold
303-
try {
304-
splashScreenView.postDelayed({
305-
startOutroAnimation(
306-
splashScreenView,
307-
splashIcon,
308-
splashScreenViewProvider
309-
)
310-
}, 500)
311-
} catch (e: Exception) {
312-
Log.e(
313-
"MainActivity",
314-
"Error scheduling outro with no icon: ${e.message}",
315-
e
316-
)
317-
// Fallback: start outro immediately
280+
// Proceed directly to outro after a brief hold
281+
try {
282+
splashScreenView.postDelayed({
318283
startOutroAnimation(
319284
splashScreenView,
320285
splashIcon,
321286
splashScreenViewProvider
322287
)
323-
}
288+
}, 500)
289+
} catch (e: Exception) {
290+
Log.e(
291+
"MainActivity",
292+
"Error scheduling outro with no icon: ${e.message}",
293+
e
294+
)
295+
// Fallback: start outro immediately
296+
startOutroAnimation(
297+
splashScreenView,
298+
splashIcon,
299+
splashScreenViewProvider
300+
)
301+
}
324302
}
325303
} catch (e: Exception) {
326304
// Fallback for any unexpected exceptions during animation
@@ -344,7 +322,10 @@ class MainActivity : ComponentActivity() {
344322
AdbDiscoveryHolder.initialize(this)
345323
Log.d("MainActivity", "Started persistent ADB discovery at app startup")
346324
} else {
347-
Log.d("MainActivity", "Skipping persistent ADB discovery at startup: ACCESS_LOCAL_NETWORK permission not granted")
325+
Log.d(
326+
"MainActivity",
327+
"Skipping persistent ADB discovery at startup: ACCESS_LOCAL_NETWORK permission not granted"
328+
)
348329
}
349330

350331
// Check if this is a QS tile long-press intent and device is not connected
@@ -412,7 +393,8 @@ class MainActivity : ComponentActivity() {
412393
modifier = Modifier.padding(innerPadding)
413394
) {
414395
composable("main") {
415-
val initialPage = if (intent?.action == ShortcutUtil.DASH_ACTION_REMOTE) 1 else 0
396+
val initialPage =
397+
if (intent?.action == ShortcutUtil.DASH_ACTION_REMOTE) 1 else 0
416398
AirSyncMainScreen(
417399
initialIp = ip,
418400
initialPort = port,

0 commit comments

Comments
 (0)