Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71b5d56f authored by Philipp Heckel's avatar Philipp Heckel
Browse files

WIP: Muted until

parent 0c6f1cd5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ dependencies {

    // WorkManager
    implementation "androidx.work:work-runtime-ktx:2.6.0"
    implementation 'androidx.preference:preference:1.1.1'

    // Room (SQLite)
    def roomVersion = "2.3.0"
+118 −0
Original line number Diff line number Diff line
{
  "formatVersion": 1,
  "database": {
    "version": 3,
    "identityHash": "7b0ef556331f6d2dd3515425837c3d3a",
    "entities": [
      {
        "tableName": "Subscription",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `baseUrl` TEXT NOT NULL, `topic` TEXT NOT NULL, `instant` INTEGER NOT NULL, `mutedUntil` INTEGER NOT NULL, PRIMARY KEY(`id`))",
        "fields": [
          {
            "fieldPath": "id",
            "columnName": "id",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "baseUrl",
            "columnName": "baseUrl",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "topic",
            "columnName": "topic",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "instant",
            "columnName": "instant",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "mutedUntil",
            "columnName": "mutedUntil",
            "affinity": "INTEGER",
            "notNull": true
          }
        ],
        "primaryKey": {
          "columnNames": [
            "id"
          ],
          "autoGenerate": false
        },
        "indices": [
          {
            "name": "index_Subscription_baseUrl_topic",
            "unique": true,
            "columnNames": [
              "baseUrl",
              "topic"
            ],
            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_Subscription_baseUrl_topic` ON `${TABLE_NAME}` (`baseUrl`, `topic`)"
          }
        ],
        "foreignKeys": []
      },
      {
        "tableName": "Notification",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `subscriptionId` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `message` TEXT NOT NULL, `notificationId` INTEGER NOT NULL, `deleted` INTEGER NOT NULL, PRIMARY KEY(`id`))",
        "fields": [
          {
            "fieldPath": "id",
            "columnName": "id",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "subscriptionId",
            "columnName": "subscriptionId",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "timestamp",
            "columnName": "timestamp",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "message",
            "columnName": "message",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "notificationId",
            "columnName": "notificationId",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "deleted",
            "columnName": "deleted",
            "affinity": "INTEGER",
            "notNull": true
          }
        ],
        "primaryKey": {
          "columnNames": [
            "id"
          ],
          "autoGenerate": false
        },
        "indices": [],
        "foreignKeys": []
      }
    ],
    "views": [],
    "setupQueries": [
      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7b0ef556331f6d2dd3515425837c3d3a')"
    ]
  }
}
 No newline at end of file
+13 −22
Original line number Diff line number Diff line
@@ -12,10 +12,6 @@
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <!--
         Application
         - usesCleartextTraffic is required to support "use another server" feature
    -->
    <application
            android:name=".app.Application"
            android:allowBackup="true"
@@ -25,7 +21,8 @@
            android:supportsRtl="true"
            android:theme="@style/AppTheme"
            android:usesCleartextTraffic="true">

        <activity android:name=".ui.SubscriptionSettingsActivity">
        </activity>
        <!-- Main activity -->
        <activity
                android:name=".ui.MainActivity"
@@ -35,28 +32,22 @@

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <!-- Detail activity -->
        </activity> <!-- Detail activity -->
        <activity
                android:name=".ui.DetailActivity"
                android:parentActivityName=".ui.MainActivity">
            <meta-data
                    android:name="android.support.PARENT_ACTIVITY"
                    android:value=".ui.MainActivity"/>
        </activity>

        <!-- Subscriber foreground service for hosts other than ntfy.sh -->
        <service android:name=".msg.SubscriberService" />

        <!-- Subscriber service restart on reboot -->
        <receiver android:enabled="true" android:name=".msg.SubscriberService$StartReceiver">
        </activity> <!-- Subscriber foreground service for hosts other than ntfy.sh -->
        <service android:name=".msg.SubscriberService"/> <!-- Subscriber service restart on reboot -->
        <receiver
                android:name=".msg.SubscriberService$StartReceiver"
                android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <!-- Firebase messaging -->
        </receiver> <!-- Firebase messaging -->
        <service
                android:name=".msg.FirebaseService"
                android:exported="false">
+18 −6
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import androidx.room.*
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import kotlinx.coroutines.flow.Flow
import java.util.*

@Entity(indices = [Index(value = ["baseUrl", "topic"], unique = true)])
data class Subscription(
@@ -12,12 +13,16 @@ data class Subscription(
    @ColumnInfo(name = "baseUrl") val baseUrl: String,
    @ColumnInfo(name = "topic") val topic: String,
    @ColumnInfo(name = "instant") val instant: Boolean,
    @ColumnInfo(name = "mutedUntil") val mutedUntil: Long,
    //val notificationSchedule: String,
    //val notificationSound: String,
    @Ignore val totalCount: Int = 0, // Total notifications
    @Ignore val newCount: Int = 0, // New notifications
    @Ignore val lastActive: Long = 0, // Unix timestamp
    @Ignore val state: ConnectionState = ConnectionState.NOT_APPLICABLE
) {
    constructor(id: Long, baseUrl: String, topic: String, instant: Boolean) : this(id, baseUrl, topic, instant, 0, 0, 0, ConnectionState.NOT_APPLICABLE)
    constructor(id: Long, baseUrl: String, topic: String, instant: Boolean, mutedUntil: Long) :
            this(id, baseUrl, topic, instant, mutedUntil, 0, 0, 0, ConnectionState.NOT_APPLICABLE)
}

enum class ConnectionState {
@@ -29,6 +34,7 @@ data class SubscriptionWithMetadata(
    val baseUrl: String,
    val topic: String,
    val instant: Boolean,
    val mutedUntil: Long,
    val totalCount: Int,
    val newCount: Int,
    val lastActive: Long
@@ -44,7 +50,7 @@ data class Notification(
    @ColumnInfo(name = "deleted") val deleted: Boolean,
)

@androidx.room.Database(entities = [Subscription::class, Notification::class], version = 2)
@androidx.room.Database(entities = [Subscription::class, Notification::class], version = 3)
abstract class Database : RoomDatabase() {
    abstract fun subscriptionDao(): SubscriptionDao
    abstract fun notificationDao(): NotificationDao
@@ -79,6 +85,12 @@ abstract class Database : RoomDatabase() {
                db.execSQL("ALTER TABLE Notification ADD COLUMN deleted INTEGER NOT NULL DEFAULT('0')")
            }
        }

        private val MIGRATION_2_3 = object : Migration(2, 3) {
            override fun migrate(db: SupportSQLiteDatabase) {
                db.execSQL("ALTER TABLE Subscription ADD COLUMN mutedUntil INTEGER NOT NULL DEFAULT('0')")
            }
        }
    }
}

@@ -86,7 +98,7 @@ abstract class Database : RoomDatabase() {
interface SubscriptionDao {
    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
@@ -99,7 +111,7 @@ interface SubscriptionDao {

    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
@@ -112,7 +124,7 @@ interface SubscriptionDao {

    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
@@ -125,7 +137,7 @@ interface SubscriptionDao {

    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
+2 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ class Repository(private val subscriptionDao: SubscriptionDao, private val notif
                baseUrl = s.baseUrl,
                topic = s.topic,
                instant = s.instant,
                mutedUntil = s.mutedUntil,
                totalCount = s.totalCount,
                newCount = s.newCount,
                lastActive = s.lastActive,
@@ -130,6 +131,7 @@ class Repository(private val subscriptionDao: SubscriptionDao, private val notif
            baseUrl = s.baseUrl,
            topic = s.topic,
            instant = s.instant,
            mutedUntil = s.mutedUntil,
            totalCount = s.totalCount,
            newCount = s.newCount,
            lastActive = s.lastActive,
Loading