diff --git a/app/schemas/com.koalasat.pokey.database.AppDatabase/5.json b/app/schemas/com.koalasat.pokey.database.AppDatabase/5.json
index ef5a445..f2e1d1b 100644
--- a/app/schemas/com.koalasat.pokey.database.AppDatabase/5.json
+++ b/app/schemas/com.koalasat.pokey.database.AppDatabase/5.json
@@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 5,
- "identityHash": "233b09174bbfc8635a2635b94e69c5c8",
+ "identityHash": "304dc2730bab233084f32790628da8ae",
"entities": [
{
"tableName": "notification",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `eventId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `time` INTEGER NOT NULL)",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `eventId` TEXT NOT NULL, `time` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
@@ -20,12 +20,6 @@
"affinity": "TEXT",
"notNull": true
},
- {
- "fieldPath": "kind",
- "columnName": "kind",
- "affinity": "INTEGER",
- "notNull": true
- },
{
"fieldPath": "time",
"columnName": "time",
@@ -56,7 +50,7 @@
"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, '233b09174bbfc8635a2635b94e69c5c8')"
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '304dc2730bab233084f32790628da8ae')"
]
}
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 10fdec3..20c7284 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,7 @@
+
@@ -39,6 +40,20 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/koalasat/pokey/Pokey.kt b/app/src/main/java/com/koalasat/pokey/Pokey.kt
index a307c1e..48a60c5 100644
--- a/app/src/main/java/com/koalasat/pokey/Pokey.kt
+++ b/app/src/main/java/com/koalasat/pokey/Pokey.kt
@@ -2,7 +2,11 @@ package com.koalasat.pokey
import android.app.ActivityManager
import android.app.Application
+import android.content.Context
import android.content.Intent
+import android.content.SharedPreferences
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
import com.koalasat.pokey.database.AppDatabase
import com.koalasat.pokey.models.EncryptedStorage.preferences
import com.koalasat.pokey.models.PrefKeys
@@ -24,6 +28,8 @@ class Pokey : Application() {
super.onCreate()
instance = this
+ updateIsEnabled(isForegroundServiceEnabled(this))
+
RelayPool.register(Client)
}
@@ -39,16 +45,19 @@ class Pokey : Application() {
NotificationsService::class.java,
),
)
- NotificationsService.setRunningState(true)
+ saveForegroundServicePreference(this, true)
}
fun stopService() {
val intent = Intent(applicationContext, NotificationsService::class.java)
applicationContext.stopService(intent)
- NotificationsService.setRunningState(false)
+ saveForegroundServicePreference(this, false)
}
companion object {
+ private val _isEnabled = MutableLiveData(false)
+ val isEnabled: LiveData get() = _isEnabled
+
@Volatile
private var instance: Pokey? = null
@@ -56,5 +65,22 @@ class Pokey : Application() {
instance ?: synchronized(this) {
instance ?: Pokey().also { instance = it }
}
+
+ fun updateIsEnabled(value: Boolean) {
+ _isEnabled.value = value
+ }
+
+ private fun saveForegroundServicePreference(context: Context, value: Boolean) {
+ val sharedPreferences: SharedPreferences = context.getSharedPreferences("PokeyPreferences", Context.MODE_PRIVATE)
+ val editor = sharedPreferences.edit()
+ editor.putBoolean("foreground_service_enabled", value)
+ editor.apply()
+ updateIsEnabled(value)
+ }
+
+ fun isForegroundServiceEnabled(context: Context): Boolean {
+ val sharedPreferences: SharedPreferences = context.getSharedPreferences("PokeyPreferences", Context.MODE_PRIVATE)
+ return sharedPreferences.getBoolean("foreground_service_enabled", false)
+ }
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/koalasat/pokey/database/NotificationEntity.kt b/app/src/main/java/com/koalasat/pokey/database/NotificationEntity.kt
index 1f0da84..a9d8d52 100644
--- a/app/src/main/java/com/koalasat/pokey/database/NotificationEntity.kt
+++ b/app/src/main/java/com/koalasat/pokey/database/NotificationEntity.kt
@@ -17,6 +17,5 @@ data class NotificationEntity(
@PrimaryKey(autoGenerate = true)
val id: Int,
val eventId: String,
- val kind: Int,
val time: Long,
)
diff --git a/app/src/main/java/com/koalasat/pokey/service/BootReceiver.kt b/app/src/main/java/com/koalasat/pokey/service/BootReceiver.kt
new file mode 100644
index 0000000..e508be8
--- /dev/null
+++ b/app/src/main/java/com/koalasat/pokey/service/BootReceiver.kt
@@ -0,0 +1,46 @@
+package com.koalasat.pokey.service
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.os.Build
+import android.util.Log
+import com.koalasat.pokey.Pokey
+
+class BootReceiver : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+ if (!Pokey.isForegroundServiceEnabled(context)) return
+
+ if (intent.action == Intent.ACTION_PACKAGE_REPLACED && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
+ if (intent.dataString?.contains("com.greenart7c3.nostrsigner") == true) {
+ Log.d("BootReceiver", "Starting ConnectivityService ACTION_PACKAGE_REPLACED")
+ context.startForegroundService(
+ Intent(
+ context,
+ NotificationsService::class.java,
+ ),
+ )
+ }
+ }
+
+ if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) {
+ Log.d("BootReceiver", "Starting ConnectivityService ACTION_MY_PACKAGE_REPLACED")
+ context.startForegroundService(
+ Intent(
+ context,
+ NotificationsService::class.java,
+ ),
+ )
+ }
+
+ if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
+ Log.d("BootReceiver", "Starting ConnectivityService ACTION_BOOT_COMPLETED")
+ context.startForegroundService(
+ Intent(
+ context,
+ NotificationsService::class.java,
+ ),
+ )
+ }
+ }
+}
diff --git a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt
index 469f992..8da7023 100644
--- a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt
+++ b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt
@@ -5,6 +5,7 @@ import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
+import android.content.SharedPreferences
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
@@ -270,7 +271,7 @@ class NotificationsService : Service() {
if (!event.hasVerifiedSignature()) return@launch
- dao.insertNotification(NotificationEntity(0, event.id, event.kind, event.createdAt))
+ dao.insertNotification(NotificationEntity(0, event.id, event.createdAt))
var title = getString(R.string.unknown)
var text = ""
@@ -313,13 +314,4 @@ class NotificationsService : Service() {
}
return hexKey
}
-
- companion object {
- private val _isActive = MutableLiveData(false)
- val isActive: LiveData get() = _isActive
-
- fun setRunningState(running: Boolean) {
- _isActive.value = running
- }
- }
}
diff --git a/app/src/main/java/com/koalasat/pokey/ui/home/HomeFragment.kt b/app/src/main/java/com/koalasat/pokey/ui/home/HomeFragment.kt
index 75fb3f1..fe51295 100644
--- a/app/src/main/java/com/koalasat/pokey/ui/home/HomeFragment.kt
+++ b/app/src/main/java/com/koalasat/pokey/ui/home/HomeFragment.kt
@@ -9,6 +9,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
+import com.koalasat.pokey.Pokey
import com.koalasat.pokey.R
import com.koalasat.pokey.databinding.FragmentHomeBinding
import com.koalasat.pokey.service.NotificationsService
@@ -58,7 +59,7 @@ class HomeFragment : Fragment() {
}
}
- NotificationsService.isActive.observe(viewLifecycleOwner) {
+ Pokey.isEnabled.observe(viewLifecycleOwner) {
if (it) {
val typedValue = TypedValue()
requireContext().theme.resolveAttribute(android.R.attr.colorButtonNormal, typedValue, true)
diff --git a/app/src/main/java/com/koalasat/pokey/ui/home/HomeViewModel.kt b/app/src/main/java/com/koalasat/pokey/ui/home/HomeViewModel.kt
index ef0ab3f..f08f734 100644
--- a/app/src/main/java/com/koalasat/pokey/ui/home/HomeViewModel.kt
+++ b/app/src/main/java/com/koalasat/pokey/ui/home/HomeViewModel.kt
@@ -18,7 +18,7 @@ class HomeViewModel : ViewModel() {
val npubInput: LiveData get() = _npubInput
private val _serviceStart = MutableLiveData().apply {
- value = NotificationsService.isActive.value
+ value = Pokey.isEnabled.value
}
val serviceStart: LiveData get() = _serviceStart
diff --git a/app/src/main/java/com/koalasat/pokey/ui/relays/RelayListAdapter.kt b/app/src/main/java/com/koalasat/pokey/ui/relays/RelayListAdapter.kt
index 22dba9d..00167ef 100644
--- a/app/src/main/java/com/koalasat/pokey/ui/relays/RelayListAdapter.kt
+++ b/app/src/main/java/com/koalasat/pokey/ui/relays/RelayListAdapter.kt
@@ -7,7 +7,6 @@ import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.koalasat.pokey.R
-import com.koalasat.pokey.service.NotificationsService
import com.vitorpamplona.ammolite.relays.Relay
class RelayListAdapter(private val items: List) : RecyclerView.Adapter() {
@@ -17,7 +16,7 @@ class RelayListAdapter(private val items: List) : RecyclerView.Adapter
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_relay_item.xml b/app/src/main/res/layout/fragment_relay_item.xml
new file mode 100644
index 0000000..3f69e29
--- /dev/null
+++ b/app/src/main/res/layout/fragment_relay_item.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_relay_list.xml b/app/src/main/res/layout/fragment_relay_list.xml
deleted file mode 100644
index 51731fa..0000000
--- a/app/src/main/res/layout/fragment_relay_list.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_relays.xml b/app/src/main/res/layout/fragment_relays.xml
index 04f43d4..df415b4 100644
--- a/app/src/main/res/layout/fragment_relays.xml
+++ b/app/src/main/res/layout/fragment_relays.xml
@@ -21,6 +21,7 @@
android:id="@+id/relays"
android:layout_width="405dp"
android:layout_height="638dp"
+ android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.4"
diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml
index 86853fd..5f871a7 100644
--- a/app/src/main/res/menu/bottom_nav_menu.xml
+++ b/app/src/main/res/menu/bottom_nav_menu.xml
@@ -8,7 +8,7 @@