Skip to content

Commit 37ac23b

Browse files
committed
chore(reduceCodeSmell): reduce the code quality gate
1 parent eae8858 commit 37ac23b

File tree

6 files changed

+45
-30
lines changed

6 files changed

+45
-30
lines changed

app/src/main/java/com/xpeho/xpeapp/MainActivity.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import com.xpeho.xpeapp.ui.Home
2121
import com.xpeho.xpeapp.ui.notifications.AlarmScheduler
2222
import com.xpeho.xpeapp.ui.theme.XpeAppTheme
2323
import kotlinx.coroutines.CoroutineScope
24-
import kotlinx.coroutines.Dispatchers
24+
import com.xpeho.xpeapp.utils.DefaultDispatcherProvider
2525
import kotlinx.coroutines.flow.MutableStateFlow
2626
import kotlinx.coroutines.launch
2727
import kotlinx.coroutines.runBlocking
@@ -71,30 +71,30 @@ class MainActivity : ComponentActivity() {
7171
MutableStateFlow(if (connectedLastTime) Screens.Home else Screens.Login)
7272

7373
// Periodic check for token expiration (every 8 hours)
74-
CoroutineScope(Dispatchers.IO).launch {
74+
CoroutineScope(DefaultDispatcherProvider.io).launch {
7575
while (true) {
7676
kotlinx.coroutines.delay(TOKEN_CHECK_INTERVAL.inWholeMilliseconds)
7777

7878
// Check if we are connected and if the token has expired
7979
val authState = XpeApp.appModule.authenticationManager.authState.value
80-
if (authState is com.xpeho.xpeapp.domain.AuthState.Authenticated) {
81-
if (!XpeApp.appModule.authenticationManager.isAuthValid()) {
82-
XpeApp.appModule.authenticationManager.logout()
83-
withContext(Dispatchers.Main) {
84-
startScreenFlow.value = Screens.Login
85-
}
80+
if (authState is com.xpeho.xpeapp.domain.AuthState.Authenticated &&
81+
!XpeApp.appModule.authenticationManager.isAuthValid()
82+
) {
83+
XpeApp.appModule.authenticationManager.logout()
84+
withContext(DefaultDispatcherProvider.main) {
85+
startScreenFlow.value = Screens.Login
8686
}
8787
}
8888
}
8989
}
9090

9191
// If the user was connected last time, try to restore the authentication state.
9292
if (connectedLastTime) {
93-
CoroutineScope(Dispatchers.IO).launch {
93+
CoroutineScope(DefaultDispatcherProvider.io).launch {
9494
XpeApp.appModule.authenticationManager.restoreAuthStateFromStorage()
9595
if (!XpeApp.appModule.authenticationManager.isAuthValid()) {
9696
XpeApp.appModule.authenticationManager.logout()
97-
withContext(Dispatchers.Main) {
97+
withContext(DefaultDispatcherProvider.main) {
9898
startScreenFlow.value = Screens.Login
9999
}
100100
}
@@ -142,13 +142,13 @@ class MainActivity : ComponentActivity() {
142142
private fun checkForUpdate() {
143143
// Check for updates only in release mode
144144
if (!BuildConfig.DEBUG) {
145-
CoroutineScope(Dispatchers.IO).launch {
145+
CoroutineScope(DefaultDispatcherProvider.io).launch {
146146
val latestVersion = getLatestReleaseTag()
147147
val currentVersion = getCurrentAppVersion()
148148

149149
// If the latest version is not null and is greater than the current version,
150150
if (latestVersion != null && isVersionLessThan(currentVersion, latestVersion)) {
151-
withContext(Dispatchers.Main) {
151+
withContext(DefaultDispatcherProvider.main) {
152152
showUpdateDialog(latestVersion)
153153
}
154154
}
@@ -181,7 +181,7 @@ class MainActivity : ComponentActivity() {
181181
}
182182

183183
private suspend fun getLatestReleaseTag(): String? {
184-
return withContext(Dispatchers.IO) {
184+
return withContext(DefaultDispatcherProvider.io) {
185185
val client = OkHttpClient()
186186
val request = Request.Builder()
187187
.url("https://api.github.com/repos/XPEHO/xpeapp_android/releases/latest")

app/src/main/java/com/xpeho/xpeapp/di/AppModule.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.xpeho.xpeapp.di
33
import android.content.Context
44
import com.google.firebase.analytics.FirebaseAnalytics
55
import com.google.gson.GsonBuilder
6-
import com.google.type.DateTime
76
import com.xpeho.xpeapp.BuildConfig
87
import com.xpeho.xpeapp.data.DatastorePref
98
import com.xpeho.xpeapp.data.dateConverter.DateTimeTypeAdapter
@@ -42,7 +41,7 @@ class MainAppModule(
4241
// Register custom date format for Date and DateTime
4342
.registerTypeAdapter(Date::class.java, DateTypeAdapter())
4443
.registerTypeAdapter(LocalTime::class.java, DateTimeTypeAdapter())
45-
.setLenient().create()
44+
.create()
4645

4746
private val logging = HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BASIC }
4847
private val authorization by lazy {
@@ -111,5 +110,3 @@ class MainAppModule(
111110
)
112111
}
113112
}
114-
115-

app/src/main/java/com/xpeho/xpeapp/ui/components/qvst/QvstCardList.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import androidx.compose.ui.Modifier
88
import androidx.compose.ui.unit.dp
99
import androidx.navigation.NavController
1010
import com.xpeho.xpeapp.data.entity.QvstCampaignEntity
11-
import com.xpeho.xpeapp.ui.components.layout.NoContentPlaceHolder
1211

1312
@Composable
1413
fun QvstCardList(

app/src/main/java/com/xpeho/xpeapp/ui/page/AgencyPage.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.xpeho.xpeapp.ui.page
22

33
import android.content.Context
4+
import android.content.ClipData
5+
import android.content.ClipboardManager
46
import android.widget.Toast
57
import androidx.compose.foundation.layout.Spacer
68
import androidx.compose.foundation.layout.fillMaxSize
@@ -15,11 +17,8 @@ import androidx.compose.runtime.mutableStateOf
1517
import androidx.compose.runtime.remember
1618
import androidx.compose.ui.Modifier
1719
import androidx.compose.ui.graphics.Color
18-
import androidx.compose.ui.platform.ClipboardManager
19-
import androidx.compose.ui.platform.LocalClipboardManager
2020
import androidx.compose.ui.platform.LocalContext
2121
import androidx.compose.ui.res.painterResource
22-
import androidx.compose.ui.text.AnnotatedString
2322
import androidx.compose.ui.unit.dp
2423
import androidx.compose.ui.unit.sp
2524
import com.xpeho.xpeapp.BuildConfig
@@ -34,7 +33,6 @@ import com.xpeho.xpeho_ui_android.foundations.Colors as XpehoColors
3433
@Composable
3534
fun AgencyPage() {
3635
val context = LocalContext.current
37-
val clipboardManager = LocalClipboardManager.current
3836
val showdigiCode = remember { mutableStateOf(false) }
3937
val showalarmCode = remember { mutableStateOf(false) }
4038

@@ -56,12 +54,12 @@ fun AgencyPage() {
5654
}
5755

5856
item {
59-
WifiCard(clipboardManager, context)
57+
WifiCard(context)
6058
Spacer(modifier = Modifier.height(10.dp))
6159
}
6260

6361
item {
64-
GuestWifiCard(clipboardManager, context)
62+
GuestWifiCard(context)
6563
Spacer(modifier = Modifier.height(10.dp))
6664
}
6765

@@ -122,7 +120,7 @@ private fun EveningInstructionsCard() {
122120
}
123121

124122
@Composable
125-
private fun WifiCard(clipboardManager: ClipboardManager, context: Context) {
123+
private fun WifiCard(context: Context) {
126124
CollapsableCard(
127125
label = "Wifi",
128126
tags = {
@@ -138,7 +136,9 @@ private fun WifiCard(clipboardManager: ClipboardManager, context: Context) {
138136
backgroundColor = XpehoColors.XPEHO_COLOR,
139137
labelColor = Color.White
140138
) {
141-
clipboardManager.setText(AnnotatedString(BuildConfig.WIFI_PASSWORD))
139+
val clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
140+
val clip = ClipData.newPlainText("password", BuildConfig.WIFI_PASSWORD)
141+
clipboardManager.setPrimaryClip(clip)
142142
Toast.makeText(context,
143143
"Wifi copié", Toast.LENGTH_SHORT).show()
144144
}
@@ -158,7 +158,7 @@ private fun WifiCard(clipboardManager: ClipboardManager, context: Context) {
158158
}
159159

160160
@Composable
161-
private fun GuestWifiCard(clipboardManager: ClipboardManager, context: Context) {
161+
private fun GuestWifiCard(context: Context) {
162162
CollapsableCard(
163163
label = "Wifi invité",
164164
tags = {
@@ -175,7 +175,9 @@ private fun GuestWifiCard(clipboardManager: ClipboardManager, context: Context)
175175
backgroundColor = XpehoColors.XPEHO_COLOR,
176176
labelColor = Color.White
177177
) {
178-
clipboardManager.setText(AnnotatedString(BuildConfig.WIFI_GUEST_PASSWORD))
178+
val clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
179+
val clip = ClipData.newPlainText("password", BuildConfig.WIFI_GUEST_PASSWORD)
180+
clipboardManager.setPrimaryClip(clip)
179181
Toast.makeText(context,
180182
"Wifi invité copié",
181183
Toast.LENGTH_SHORT).show()

app/src/main/java/com/xpeho/xpeapp/ui/page/HomePage.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ fun HomePage(navigationController: NavController) {
164164
}
165165
}
166166
}
167-
else -> {}
168167
}
169168
}
170169

@@ -190,7 +189,6 @@ fun HomePage(navigationController: NavController) {
190189
}
191190
}
192191
}
193-
else -> {}
194192
}
195193
}
196194
} else {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.xpeho.xpeapp.utils
2+
3+
import kotlinx.coroutines.CoroutineDispatcher
4+
import kotlinx.coroutines.Dispatchers
5+
6+
interface DispatcherProvider {
7+
val main: CoroutineDispatcher
8+
val io: CoroutineDispatcher
9+
val default: CoroutineDispatcher
10+
val unconfined: CoroutineDispatcher
11+
}
12+
13+
object DefaultDispatcherProvider : DispatcherProvider {
14+
override val main: CoroutineDispatcher = Dispatchers.Main
15+
override val io: CoroutineDispatcher = Dispatchers.IO
16+
override val default: CoroutineDispatcher = Dispatchers.Default
17+
override val unconfined: CoroutineDispatcher = Dispatchers.Unconfined
18+
}
19+

0 commit comments

Comments
 (0)