Skip to content

Commit

Permalink
Progress with notifications and network reports screens.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Mar 18, 2024
1 parent 4db49c5 commit 16b9eb6
Show file tree
Hide file tree
Showing 46 changed files with 582 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.2.2" apply false
id("com.android.application") version "8.3.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
id("com.google.devtools.ksp") version "1.9.22-1.0.16" apply false
id("com.google.dagger.hilt.android") version "2.50" apply false
Expand Down
24 changes: 24 additions & 0 deletions subvt/src/main/java/io/helikon/subvt/data/dao/NotificationDAO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.helikon.subvt.data.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.helikon.subvt.data.model.Notification
import java.util.UUID

@Dao
interface NotificationDAO {
@Query("SELECT * from notification")
fun getAll(): LiveData<List<Notification>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(notification: Notification)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(notifications: List<Notification>)

@Query("SELECT * FROM notification WHERE id = :id")
fun findById(id: UUID): Notification?
}
16 changes: 16 additions & 0 deletions subvt/src/main/java/io/helikon/subvt/data/db/RoomConverters.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.helikon.subvt.data.db

import androidx.room.TypeConverter
import java.util.Date

class RoomConverters {
@TypeConverter
fun dateFromTimestamp(value: Long?): Date? {
return value?.let { Date(it) }
}

@TypeConverter
fun dateToTimestamp(date: Date?): Long? {
return date?.time?.toLong()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import io.helikon.subvt.data.dao.NetworkDAO
import io.helikon.subvt.data.dao.NotificationDAO
import io.helikon.subvt.data.model.Network
import io.helikon.subvt.data.model.Notification

@Database(
entities = [(Network::class)],
entities = [Network::class, Notification::class],
version = 1,
exportSchema = false,
)
@TypeConverters(RoomConverters::class)
abstract class SubVTDatabase : RoomDatabase() {
abstract fun networkDAO(): NetworkDAO

abstract fun notificationDAO(): NotificationDAO

companion object {
@Volatile
private var instance: SubVTDatabase? = null
Expand Down
31 changes: 31 additions & 0 deletions subvt/src/main/java/io/helikon/subvt/data/model/Notification.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.helikon.subvt.data.model

import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
import java.util.Date
import java.util.UUID

@Entity(tableName = "notification")
@Parcelize
data class Notification(
@PrimaryKey(autoGenerate = false)
@ColumnInfo(name = "id")
val id: UUID,
@ColumnInfo(name = "is_read")
val isRead: Boolean,
@ColumnInfo(name = "message")
val message: String,
@ColumnInfo(name = "network_id")
val networkId: Long,
@ColumnInfo(name = "notification_type_code")
val notificationTypeCode: String,
@ColumnInfo(name = "received_at")
val receivedAt: Date,
@ColumnInfo(name = "validator_account_id")
val validatorAccountId: String,
@ColumnInfo(name = "validator_display")
val validatorDisplay: String,
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.helikon.subvt.data.repository

import androidx.lifecycle.LiveData
import io.helikon.subvt.data.dao.NotificationDAO
import io.helikon.subvt.data.model.Notification
import java.util.UUID

class NotificationRepository(private val dao: NotificationDAO) {
val allNotifications: LiveData<List<Notification>> = dao.getAll()

suspend fun add(notification: Notification) {
dao.insert(notification)
}

suspend fun addAll(notifications: List<Notification>) {
dao.insertAll(notifications)
}

suspend fun findById(id: UUID): Notification? = dao.findById(id)
}
6 changes: 6 additions & 0 deletions subvt/src/main/java/io/helikon/subvt/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import io.helikon.subvt.data.db.SubVTDatabase
import io.helikon.subvt.data.repository.NetworkRepository
import io.helikon.subvt.data.repository.NotificationRepository
import io.helikon.subvt.data.repository.UserPreferencesRepository

@Module
Expand All @@ -22,4 +23,9 @@ class AppModule {
fun provideNetworkRepository(
@ApplicationContext context: Context,
): NetworkRepository = NetworkRepository(SubVTDatabase.getInstance(context).networkDAO())

@Provides
fun provideNotificationRepository(
@ApplicationContext context: Context,
): NotificationRepository = NotificationRepository(SubVTDatabase.getInstance(context).notificationDAO())
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,20 @@ private fun MainScreenContent(
activeImageResourceId = R.drawable.tab_icon_notifications_active,
inactiveImageResourceId = R.drawable.tab_icon_notifications_inactive,
content = {
NotificationsScreen()
NotificationsScreen(
onSettingsButtonClicked = {
},
)
},
),
Tab(
title = stringResource(id = R.string.network_reports_tab_title),
activeImageResourceId = R.drawable.tab_icon_network_reports_active,
inactiveImageResourceId = R.drawable.tab_icon_network_reports_inactive,
content = {
NetworkReportsScreen()
NetworkReportsScreen(
viewReportsButtonClicked = {},
)
},
),
)
Expand Down
Loading

0 comments on commit 16b9eb6

Please sign in to comment.