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

Commit fe86329a authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Add Preferences to enable Ntfy in the Settings app

parent 160c4cfd
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@ android {
        }
    }

    buildFeatures {
        viewBinding = true
    }

    buildTypes {
        release {
            minifyEnabled true
@@ -128,4 +132,6 @@ dependencies {

    // Image viewer
    implementation 'com.github.stfalcon-studio:StfalconImageViewer:v1.0.1'

    implementation 'foundation.e:elib:0.0.1-alpha11'
}
+29 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="io.heckel.ntfy">

    <!-- Permissions -->
@@ -176,5 +177,32 @@
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/file_paths"/>
        </provider>

        <activity
            android:name=".ui.MainSettingsActivity"
            android:theme="@style/ETheme"
            android:icon="@drawable/ic_notification"
            android:label="@string/app_name"
            android:process=":ui"
            android:roundIcon="@drawable/ic_notification"/>

        <activity-alias
            android:name=".ui.SettingsActivityLink"
            android:exported="true"
            android:icon="@drawable/ic_notification"
            android:label="@string/eos_settings_title"
            android:process=":ui"
            android:roundIcon="@drawable/ic_notification"
            android:targetActivity=".ui.MainSettingsActivity">
            <intent-filter>
                <action android:name="com.android.settings.action.EXTRA_SETTINGS" />
            </intent-filter>
            <meta-data
                android:name="com.android.settings.category"
                android:value="com.android.settings.category.device" />
            <meta-data
                android:name="com.android.settings.icon"
                android:resource="@drawable/ic_notification" />
        </activity-alias>
    </application>
</manifest>
+4 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.os.PowerManager
import android.os.SystemClock
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import io.heckel.ntfy.BuildConfig
import io.heckel.ntfy.R
import io.heckel.ntfy.app.Application
@@ -93,7 +94,9 @@ class SubscriberService : Service() {
    override fun onDestroy() {
        Log.d(TAG, "Subscriber service has been destroyed")
        stopService()
        sendBroadcast(Intent(this, AutoRestartReceiver::class.java)) // Restart it if necessary!
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("isEnabled", false)) {
             sendBroadcast(Intent(this, AutoRestartReceiver::class.java))
        }
        super.onDestroy()
    }

@@ -127,7 +130,6 @@ class SubscriberService : Service() {
                }
            }
            wakeLock = null
            stopForeground(true)
            stopSelf()
        } catch (e: Exception) {
            Log.d(TAG, "Service stopped without being started: ${e.message}")
+9 −4
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ package io.heckel.ntfy.service

import android.content.Context
import android.content.Intent
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import androidx.work.*
import io.heckel.ntfy.app.Application
import io.heckel.ntfy.util.Log
@@ -43,11 +43,16 @@ class SubscriberServiceManager(private val context: Context) {
                Log.d(TAG, "ServiceStartWorker: Failed, no application found (work ID: ${id})")
                return Result.failure()
            }

            withContext(Dispatchers.IO) {
                val app = context.applicationContext as Application
                val subscriptionIdsWithInstantStatus = app.repository.getSubscriptionIdsWithInstantStatus()
                val instantSubscriptions = subscriptionIdsWithInstantStatus.toList().filter { (_, instant) -> instant }.size
                val action = if (instantSubscriptions > 0) SubscriberService.Action.START else SubscriberService.Action.STOP
                val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(app)
                val action = if (sharedPreferences.getBoolean("isEnabled", false)) {
                    SubscriberService.Action.START
                } else {
                    SubscriberService.Action.STOP
                }

                val serviceState = SubscriberService.readServiceState(context)
                if (serviceState == SubscriberService.ServiceState.STOPPED && action == SubscriberService.Action.STOP) {
                    return@withContext Result.success()
+24 −0
Original line number Diff line number Diff line
package io.heckel.ntfy.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import io.heckel.ntfy.R
import io.heckel.ntfy.databinding.MainSettingsActivityBinding


class MainSettingsActivity: AppCompatActivity() {

    private lateinit var mBinding: MainSettingsActivityBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mBinding = MainSettingsActivityBinding.inflate(layoutInflater)
        setContentView(mBinding.root)

        supportFragmentManager
            .beginTransaction()
            .replace(R.id.fragment_container, PreferencesFragment())
            .commit()
    }
}
 No newline at end of file
Loading