Skip to content

Commit 1002b8b

Browse files
committed
detekt
1 parent 54b4350 commit 1002b8b

File tree

8 files changed

+151
-150
lines changed

8 files changed

+151
-150
lines changed

composeApp/src/androidMain/kotlin/presentation/NotificationPromptTrigger.android.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ actual fun NotificationPromptTrigger(
124124
}
125125
}
126126

127-
// Extension function to find the activity from a context
128127
private fun android.content.Context.findActivity(): android.app.Activity {
129128
var context = this
130129
while (context is android.content.ContextWrapper) {
131130
if (context is android.app.Activity) return context
132131
context = context.baseContext
133132
}
134-
throw IllegalStateException("Couldn't find activity from context")
133+
error("Couldn't find activity from context")
135134
}

composeApp/src/androidMain/kotlin/utils/UpdatesWorkers.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ object UpdatesWorkers {
2525
private const val CC_GRADES_UPDATE_WORK = "cc_grades_update_work"
2626
private const val CC_GRADES_IMMEDIATE_WORK = "cc_grades_immediate_work"
2727

28-
2928
fun scheduleExamGradesUpdateWork(context: Context) {
3029
val constraints = Constraints.Builder()
3130
.setRequiredNetworkType(NetworkType.CONNECTED)
3231
.build()
3332

3433
val examGradesUpdateRequest =
3534
PeriodicWorkRequestBuilder<ExamGradesUpdateWorker>(Duration.ofHours(1))
36-
.setConstraints(constraints)
37-
.build()
35+
.setConstraints(constraints)
36+
.build()
3837

3938
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
4039
EXAM_GRADES_UPDATE_WORK,

composeApp/src/androidMain/kotlin/utils/workers/ExamGradesUpdateWorker.kt

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,81 +18,84 @@ import mehiz.abdallah.progres.i18n.MR
1818
import utils.FirebaseUtils
1919

2020
class ExamGradesUpdateWorker(
21-
appContext: Context,
22-
workerParams: WorkerParameters,
23-
private val examGradesUseCase: ExamGradeUseCase,
21+
appContext: Context,
22+
workerParams: WorkerParameters,
23+
private val examGradesUseCase: ExamGradeUseCase,
2424
) : CoroutineWorker(appContext, workerParams) {
2525

26-
companion object {
27-
private const val CHANNEL_ID = "exam_grades_updates"
28-
private const val NOTIFICATION_ID = 1001
29-
}
26+
companion object {
27+
private const val CHANNEL_ID = "exam_grades_updates"
28+
private const val NOTIFICATION_ID = 1001
29+
}
3030

31-
override suspend fun doWork(): Result {
32-
Log.d(TAG, "Exam grades update check started")
31+
override suspend fun doWork(): Result {
32+
Log.d(TAG, "Exam grades update check started")
3333

34-
return try {
35-
val storedGrades = examGradesUseCase.getExamGrades(false, propagateRefresh = false)
36-
val newGrades = examGradesUseCase.getExamGrades(true, propagateRefresh = false)
37-
val changedGrades = compareExamGrades(storedGrades, newGrades)
34+
return try {
35+
val storedGrades = examGradesUseCase.getExamGrades(false, propagateRefresh = false)
36+
val newGrades = examGradesUseCase.getExamGrades(true, propagateRefresh = false)
37+
val changedGrades = compareExamGrades(storedGrades, newGrades)
3838

39-
if (changedGrades.isNotEmpty()) {
40-
sendGradesUpdateNotification(changedGrades.size)
41-
Log.d(TAG, "Found ${changedGrades.size} updated exam grades")
42-
Result.success()
43-
} else {
44-
Log.d(TAG, "No changes in exam grades")
45-
Result.success()
46-
}
47-
} catch (e: Exception) {
48-
Log.e(TAG, "Error checking exam grades updates: ${e.message}")
49-
FirebaseUtils.reportException(e)
50-
Result.failure(Data.Builder().putString("error", e.message).build())
51-
}
39+
if (changedGrades.isNotEmpty()) {
40+
sendGradesUpdateNotification(changedGrades.size)
41+
Log.d(TAG, "Found ${changedGrades.size} updated exam grades")
42+
Result.success()
43+
} else {
44+
Log.d(TAG, "No changes in exam grades")
45+
Result.success()
46+
}
47+
} catch (e: Exception) {
48+
Log.e(TAG, "Error checking exam grades updates: ${e.message}")
49+
FirebaseUtils.reportException(e)
50+
Result.failure(Data.Builder().putString("error", e.message).build())
5251
}
52+
}
5353

54-
private fun compareExamGrades(
55-
oldGrades: List<ExamGradeModel>, newGrades: List<ExamGradeModel>
56-
): List<ExamGradeModel> {
57-
return newGrades.filter { newGrade ->
58-
val oldGrade = oldGrades.find { it.id == newGrade.id }
59-
oldGrade == null || oldGrade.grade != newGrade.grade
60-
}
54+
private fun compareExamGrades(
55+
oldGrades: List<ExamGradeModel>,
56+
newGrades: List<ExamGradeModel>
57+
): List<ExamGradeModel> {
58+
return newGrades.filter { newGrade ->
59+
val oldGrade = oldGrades.find { it.id == newGrade.id }
60+
oldGrade == null || oldGrade.grade != newGrade.grade
6161
}
62+
}
6263

63-
private fun sendGradesUpdateNotification(count: Int) {
64-
val notificationManager = applicationContext.getSystemService<NotificationManager>()
65-
createNotificationChannel(notificationManager)
64+
private fun sendGradesUpdateNotification(count: Int) {
65+
val notificationManager = applicationContext.getSystemService<NotificationManager>()
66+
createNotificationChannel(notificationManager)
6667

67-
val notificationBuilder = NotificationCompat.Builder(applicationContext, CHANNEL_ID)
68-
.setSmallIcon(R.drawable.notifications_icon).setContentTitle(
69-
MR.strings.new_exams_grades_notification_title.getString(
70-
applicationContext
71-
)
72-
).setContentText(
73-
applicationContext.resources.getQuantityString(
74-
MR.plurals.new_examgrades_notification_message.resourceId, count, count
75-
)
76-
).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true)
68+
val notificationBuilder = NotificationCompat.Builder(applicationContext, CHANNEL_ID)
69+
.setSmallIcon(R.drawable.notifications_icon).setContentTitle(
70+
MR.strings.new_exams_grades_notification_title.getString(
71+
applicationContext
72+
)
73+
).setContentText(
74+
applicationContext.resources.getQuantityString(
75+
MR.plurals.new_examgrades_notification_message.resourceId,
76+
count,
77+
count
78+
)
79+
).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true)
7780

78-
notificationManager?.notify(NOTIFICATION_ID, notificationBuilder.build())
79-
}
81+
notificationManager?.notify(NOTIFICATION_ID, notificationBuilder.build())
82+
}
8083

81-
private fun createNotificationChannel(notificationManager: NotificationManager?) {
82-
if (notificationManager == null) return
84+
private fun createNotificationChannel(notificationManager: NotificationManager?) {
85+
if (notificationManager == null) return
8386

84-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
85-
val name =
86-
applicationContext.getString(MR.strings.exams_grades_update_channel_name.resourceId)
87-
val description =
88-
applicationContext.getString(MR.strings.exams_grades_update_channel_description.resourceId)
89-
val importance = NotificationManager.IMPORTANCE_HIGH
87+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
88+
val name =
89+
applicationContext.getString(MR.strings.exams_grades_update_channel_name.resourceId)
90+
val description =
91+
applicationContext.getString(MR.strings.exams_grades_update_channel_description.resourceId)
92+
val importance = NotificationManager.IMPORTANCE_HIGH
9093

91-
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
92-
this.description = description
93-
}
94+
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
95+
this.description = description
96+
}
9497

95-
notificationManager.createNotificationChannel(channel)
96-
}
98+
notificationManager.createNotificationChannel(channel)
9799
}
100+
}
98101
}

composeApp/src/androidMain/kotlin/utils/workers/TranscriptsUpdateWorker.kt

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -19,83 +19,83 @@ import utils.FirebaseUtils
1919
import kotlin.math.absoluteValue
2020

2121
class TranscriptsUpdateWorker(
22-
appContext: Context,
23-
workerParams: WorkerParameters,
24-
private val transcriptUseCase: TranscriptUseCase,
22+
appContext: Context,
23+
workerParams: WorkerParameters,
24+
private val transcriptUseCase: TranscriptUseCase,
2525
) : CoroutineWorker(appContext, workerParams) {
2626

27-
companion object {
28-
const val CHANNEL_ID = "transcripts_updates_channel"
29-
const val NOTIFICATION_ID = 1002
30-
const val TRANSCRIPTS_COUNT_KEY = "transcriptsCount"
27+
companion object {
28+
const val CHANNEL_ID = "transcripts_updates_channel"
29+
const val NOTIFICATION_ID = 1002
30+
const val TRANSCRIPTS_COUNT_KEY = "transcriptsCount"
31+
}
32+
33+
override suspend fun doWork(): Result {
34+
Log.d(TAG, "Transcripts update check started")
35+
36+
return try {
37+
val oldTranscripts = transcriptUseCase.getAllTranscripts(false, false)
38+
val newTranscripts = transcriptUseCase.getAllTranscripts(true, false)
39+
40+
val newTranscriptsCount = countNewTranscripts(oldTranscripts, newTranscripts)
41+
42+
if (newTranscriptsCount > 0) {
43+
sendGradesUpdateNotification(newTranscriptsCount)
44+
Log.d(TAG, "Found $newTranscriptsCount updated transcripts")
45+
} else {
46+
Log.d(TAG, "No changes in transcripts")
47+
}
48+
49+
Result.success(
50+
Data.Builder().putInt(TRANSCRIPTS_COUNT_KEY, newTranscriptsCount).build()
51+
)
52+
} catch (e: Exception) {
53+
Log.e(TAG, "Error checking transcript updates: ${e.message}")
54+
FirebaseUtils.reportException(e)
55+
Result.failure(Data.Builder().putString("error", e.message).build())
3156
}
32-
33-
override suspend fun doWork(): Result {
34-
Log.d(TAG, "Transcripts update check started")
35-
36-
return try {
37-
val oldTranscripts = transcriptUseCase.getAllTranscripts(false, false)
38-
val newTranscripts = transcriptUseCase.getAllTranscripts(true, false)
39-
40-
val newTranscriptsCount = countNewTranscripts(oldTranscripts, newTranscripts)
41-
42-
if (newTranscriptsCount > 0) {
43-
sendGradesUpdateNotification(newTranscriptsCount)
44-
Log.d(TAG, "Found $newTranscriptsCount updated transcripts")
45-
} else {
46-
Log.d(TAG, "No changes in transcripts")
47-
}
48-
49-
Result.success(
50-
Data.Builder().putInt(TRANSCRIPTS_COUNT_KEY, newTranscriptsCount).build()
51-
)
52-
} catch (e: Exception) {
53-
Log.e(TAG, "Error checking transcript updates: ${e.message}")
54-
FirebaseUtils.reportException(e)
55-
Result.failure(Data.Builder().putString("error", e.message).build())
56-
}
57-
}
58-
59-
private fun countNewTranscripts(
60-
oldTranscripts: List<TranscriptModel>,
61-
newTranscripts: List<TranscriptModel>
62-
): Int {
63-
return (oldTranscripts.toSet().size - newTranscripts.toSet().size).absoluteValue
64-
}
65-
66-
private fun sendGradesUpdateNotification(count: Int) {
67-
val notificationManager = applicationContext.getSystemService<NotificationManager>()
68-
createNotificationChannel(notificationManager)
69-
70-
val messageText = applicationContext.resources.getQuantityString(
71-
MR.plurals.new_transcripts_notification_message.resourceId,
72-
count,
73-
count
74-
)
75-
76-
val notificationBuilder = NotificationCompat.Builder(applicationContext, CHANNEL_ID)
77-
.setSmallIcon(R.drawable.notifications_icon)
78-
.setContentTitle(applicationContext.getString(MR.strings.new_transcripts_notification_title.resourceId))
79-
.setContentText(messageText)
80-
.setPriority(NotificationCompat.PRIORITY_HIGH)
81-
.setAutoCancel(true)
82-
83-
notificationManager?.notify(NOTIFICATION_ID, notificationBuilder.build())
84-
}
85-
86-
private fun createNotificationChannel(notificationManager: NotificationManager?) {
87-
if (notificationManager == null) return
88-
89-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
90-
val name = applicationContext.getString(MR.strings.transcripts_update_channel_name.resourceId)
91-
val description = applicationContext.getString(MR.strings.transcripts_update_channel_description.resourceId)
92-
val importance = NotificationManager.IMPORTANCE_HIGH
93-
94-
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
95-
this.description = description
96-
}
97-
98-
notificationManager.createNotificationChannel(channel)
99-
}
57+
}
58+
59+
private fun countNewTranscripts(
60+
oldTranscripts: List<TranscriptModel>,
61+
newTranscripts: List<TranscriptModel>
62+
): Int {
63+
return (oldTranscripts.toSet().size - newTranscripts.toSet().size).absoluteValue
64+
}
65+
66+
private fun sendGradesUpdateNotification(count: Int) {
67+
val notificationManager = applicationContext.getSystemService<NotificationManager>()
68+
createNotificationChannel(notificationManager)
69+
70+
val messageText = applicationContext.resources.getQuantityString(
71+
MR.plurals.new_transcripts_notification_message.resourceId,
72+
count,
73+
count
74+
)
75+
76+
val notificationBuilder = NotificationCompat.Builder(applicationContext, CHANNEL_ID)
77+
.setSmallIcon(R.drawable.notifications_icon)
78+
.setContentTitle(applicationContext.getString(MR.strings.new_transcripts_notification_title.resourceId))
79+
.setContentText(messageText)
80+
.setPriority(NotificationCompat.PRIORITY_HIGH)
81+
.setAutoCancel(true)
82+
83+
notificationManager?.notify(NOTIFICATION_ID, notificationBuilder.build())
84+
}
85+
86+
private fun createNotificationChannel(notificationManager: NotificationManager?) {
87+
if (notificationManager == null) return
88+
89+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
90+
val name = applicationContext.getString(MR.strings.transcripts_update_channel_name.resourceId)
91+
val description = applicationContext.getString(MR.strings.transcripts_update_channel_description.resourceId)
92+
val importance = NotificationManager.IMPORTANCE_HIGH
93+
94+
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
95+
this.description = description
96+
}
97+
98+
notificationManager.createNotificationChannel(channel)
10099
}
100+
}
101101
}

composeApp/src/commonMain/kotlin/presentation/NotificationPromptTrigger.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ import androidx.compose.runtime.Composable
44
import androidx.compose.ui.Modifier
55

66
@Composable
7+
@Suppress("ModifierWithoutDefault")
78
expect fun NotificationPromptTrigger(modifier: Modifier)

composeApp/src/commonMain/kotlin/presentation/StudentCard.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import androidx.compose.material.icons.rounded.Save
2626
import androidx.compose.material.icons.rounded.Share
2727
import androidx.compose.material3.Icon
2828
import androidx.compose.material3.LocalContentColor
29-
import androidx.compose.material3.MaterialTheme
3029
import androidx.compose.material3.Scaffold
3130
import androidx.compose.material3.Text
3231
import androidx.compose.runtime.Composable

composeApp/src/commonMain/kotlin/ui/home/HomeScreen.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ object HomeScreen : Screen {
320320
start.linkTo(profileCard.start)
321321
},
322322
)
323-
NotificationPromptTrigger(Modifier.constrainAs(notificationsPrompt) {
324-
top.linkTo(screensGrid.bottom, 8.dp)
325-
start.linkTo(parent.start)
326-
end.linkTo(parent.end)
327-
})
323+
NotificationPromptTrigger(
324+
Modifier.constrainAs(notificationsPrompt) {
325+
top.linkTo(screensGrid.bottom, 8.dp)
326+
start.linkTo(parent.start)
327+
end.linkTo(parent.end)
328+
}
329+
)
328330
}
329331
}
330332

domain/src/commonMain/kotlin/mehiz/abdallah/progres/domain/TranscriptUseCase.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class TranscriptUseCase(
5656
cards.forEach { card ->
5757
api.getAcademicTranscripts(uuid, card.id, token).forEach { transcript ->
5858
academicPeriods.first {
59-
it.oofId == card.openingTrainingOfferId &&
60-
it.periodStringLatin == transcript.periodeLibelleFr
59+
it.oofId == card.openingTrainingOfferId && it.periodStringLatin == transcript.periodeLibelleFr
6160
}.let { transcripts.add(transcript.toTable(it.yearPeriodCode)) }
6261
ues.addAll(transcript.bilanUes.map { it.toTable() })
6362
transcript.bilanUes.forEach { ue -> subjects.addAll(ue.bilanMcs.map(TranscriptSubjectsDto::toTable)) }
@@ -68,7 +67,6 @@ class TranscriptUseCase(
6867
transcriptUEDao.deleteAllUETranscripts()
6968
transcriptSubjectDao.deleteAllSubjects()
7069
}
71-
transcripts.onEach { println(it) }
7270
return transcripts.map { transcript ->
7371
transcriptDao.insert(transcript)
7472
transcript.toModel(

0 commit comments

Comments
 (0)