-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcece7e
commit a222c10
Showing
18 changed files
with
3,501 additions
and
76 deletions.
There are no files selected for viewing
3,301 changes: 3,301 additions & 0 deletions
3,301
app/schemas/com.forcetower.uefs.core.storage.database.UDatabase/57.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/forcetower/uefs/core/model/edge/sync/PublicAppMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.forcetower.uefs.core.model.edge.sync | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.time.OffsetDateTime | ||
|
||
data class PublicAppMessage( | ||
@SerializedName("id") | ||
val id: String, | ||
@SerializedName("title") | ||
val title: String, | ||
@SerializedName("content") | ||
val content: String, | ||
@SerializedName("imageUrl") | ||
val imageUrl: String?, | ||
@SerializedName("clickableLink") | ||
val clickableLink: String?, | ||
@SerializedName("createdAt") | ||
val createdAt: OffsetDateTime | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/forcetower/uefs/core/model/unes/EdgeAppMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.forcetower.uefs.core.model.unes | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import java.time.ZonedDateTime | ||
|
||
@Entity | ||
data class EdgeAppMessage( | ||
@PrimaryKey | ||
val id: String, | ||
val title: String, | ||
val content: String, | ||
val imageUrl: String?, | ||
val clickableLink: String?, | ||
val createdAt: ZonedDateTime | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/forcetower/uefs/core/storage/database/dao/EdgeAppMessageDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.forcetower.uefs.core.storage.database.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Query | ||
import com.forcetower.core.database.BaseDao | ||
import com.forcetower.uefs.core.model.unes.EdgeAppMessage | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
abstract class EdgeAppMessageDao : BaseDao<EdgeAppMessage>() { | ||
@Query("SELECT * FROM EdgeAppMessage ORDER BY createdAt DESC") | ||
abstract fun getAll(): Flow<List<EdgeAppMessage>> | ||
|
||
@Query("DELETE FROM EdgeAppMessage") | ||
abstract suspend fun deleteAll() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/forcetower/uefs/core/storage/repository/cloud/EdgeMessageRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.forcetower.uefs.core.storage.repository.cloud | ||
|
||
import androidx.room.withTransaction | ||
import com.forcetower.uefs.core.model.unes.EdgeAppMessage | ||
import com.forcetower.uefs.core.storage.database.UDatabase | ||
import com.forcetower.uefs.core.storage.network.EdgeService | ||
import dagger.Reusable | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.withContext | ||
import java.time.ZoneId | ||
import javax.inject.Inject | ||
|
||
@Reusable | ||
class EdgeMessageRepository @Inject constructor( | ||
private val service: EdgeService, | ||
private val database: UDatabase | ||
) { | ||
suspend fun syncDataIfNeeded() { | ||
database.edgeAccessToken.require() ?: return | ||
messages() | ||
} | ||
|
||
fun getAll(): Flow<List<EdgeAppMessage>> { | ||
return database.edgeMessages.getAll() | ||
} | ||
|
||
private suspend fun messages() { | ||
val messages = service.appMessages().data | ||
val converted = messages.map { | ||
EdgeAppMessage( | ||
it.id, | ||
it.title, | ||
it.content, | ||
it.imageUrl, | ||
it.clickableLink, | ||
it.createdAt.atZoneSameInstant(ZoneId.systemDefault()) | ||
) | ||
} | ||
withContext(Dispatchers.IO) { | ||
database.withTransaction { | ||
database.edgeMessages.deleteAll() | ||
database.edgeMessages.insertAllIgnore(converted) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.