Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
aiyu-ayaan committed Nov 25, 2023
2 parents 60bd2f8 + ab75e48 commit a1a0834
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.atech.theme.AdsUnit
import com.atech.theme.CardHighlightModel
import com.atech.theme.R
import com.atech.theme.compareDifferenceInDays
import com.atech.theme.handler
import com.atech.theme.isAPI33AndUp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
Expand All @@ -29,6 +30,7 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import java.util.Calendar
import java.util.Date
Expand All @@ -47,7 +49,7 @@ class GetHomeData(
list.add(getTopSetting(dataSetForHome.isOnline))
getSyllabus().also { list.addAll(it) }
getHoliday().also { list.addAll(it) }
getEvent()?.also {
getEventWithCallback()?.also {
list.addAll(it)
}
getCGPA().also { list.addAll(it) }
Expand Down Expand Up @@ -205,34 +207,37 @@ class GetHomeData(
} else emptyList()
}

private suspend fun getEvent(): List<HomeItems>? = coroutineScope {
withContext(Dispatchers.IO) {
suspendCoroutine { continuation ->
private suspend fun getEventWithCallback(): List<HomeItems>? = coroutineScope {
withContext(Dispatchers.IO + handler) {
suspendCancellableCoroutine { cancellableContinuation ->
val list = mutableListOf<HomeItems>()
dataSetForHome.firebaseCases.eventWithAttach.invoke { events ->
events.filter {
Date(
System.currentTimeMillis()
).compareDifferenceInDays(Date(it.created!!)) <= 1
}.map { event ->
HomeViewModelExr.EventHomeModel(
event.title ?: "",
event.content ?: "",
event.society ?: "",
event.logo_link ?: "",
if (event.attach?.isNotEmpty() == true) event.attach!![0].link
?: "" else "",
event.path ?: "",
event.created ?: 0L
)
}.let { events1 ->
if (events1.isNotEmpty()) {
list.add(HomeItems.Title("Events"))
list.add(HomeItems.Event(events1))
continuation.resumeWith(Result.success(list))
} else continuation.resumeWith(Result.success(emptyList()))
dataSetForHome
.firebaseCases
.eventWithAttach
.invoke { events ->
events.filter {
Date(
System.currentTimeMillis()
).compareDifferenceInDays(Date(it.created!!)) <= 1
}.map { event ->
HomeViewModelExr.EventHomeModel(
event.title ?: "",
event.content ?: "",
event.society ?: "",
event.logo_link ?: "",
if (event.attach?.isNotEmpty() == true) event.attach!![0].link
?: "" else "",
event.path ?: "",
event.created ?: 0L
)
}.let { events1 ->
if (events1.isNotEmpty()) {
list.add(HomeItems.Title("Events"))
list.add(HomeItems.Event(events1))
cancellableContinuation.resumeWith(Result.success(list))
} else cancellableContinuation.resumeWith(Result.success(emptyList()))
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.atech.core.utils.DEFAULT_QUERY
import com.atech.core.utils.SYLLABUS_SOURCE_DATA
import com.atech.core.utils.SharePrefKeys
import com.atech.core.utils.fromJSON
import com.atech.core.utils.handler
import com.atech.course.sem.adapter.OfflineSyllabusUIMapper
import com.atech.course.sem.adapter.OnlineSyllabusUIMapper
import com.atech.course.utils.SyllabusEnableModel
Expand Down Expand Up @@ -85,7 +86,7 @@ class HomeViewModel @Inject constructor(
var defPercentage = 7

@OptIn(ExperimentalCoroutinesApi::class)
fun getHomeData() = viewModelScope.async {
fun getHomeData() = viewModelScope.async(handler) {
combine(
dataStores.asFlow(),
isOnline.combine(isPermissionGranted) { isOnline, isPermissionGranted ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.atech.core.firebase.firestore

import android.util.Log
import com.atech.core.datastore.Cgpa
import com.atech.core.firebase.auth.AttendanceUploadModel
import com.atech.core.firebase.auth.UserData
Expand Down Expand Up @@ -89,10 +88,7 @@ class EventWithAttach @Inject constructor(
operator fun invoke(
listener: (List<EventModel>) -> Unit
) {
db.collection(Db.Event.value).addSnapshotListener { value, error ->
if (error != null) {
listener(emptyList())
}
db.collection(Db.Event.value).get().addOnSuccessListener { value ->
if (value == null) {
listener(emptyList())
}
Expand All @@ -107,6 +103,8 @@ class EventWithAttach @Inject constructor(
listener(emptyList())
}
}
}.addOnFailureListener {
listener(emptyList())
}
}
}
Expand Down

0 comments on commit a1a0834

Please sign in to comment.