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

Commit a6750c4a authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

Merge branch '3467-activate_silently_on_push_murena_com' into 'main'

3467 activate silently ntfy on push murena com

See merge request !15
parents 3fb7e642 60679467
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -27,10 +27,6 @@ android {
        }
    }

    buildFeatures {
        viewBinding = true
    }

    buildTypes {
        release {
            minifyEnabled true
@@ -133,6 +129,4 @@ dependencies {

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

    implementation 'foundation.e:elib:0.0.1-alpha11'
}
+0 −20
Original line number Diff line number Diff line
@@ -176,25 +176,5 @@
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/file_paths"/>
        </provider>

        <activity
            android:name=".ui.MainSettingsActivity"
            android:theme="@style/PreferenceTheme"/>

        <activity-alias
            android:name=".ui.SettingsActivityLink"
            android:exported="true"
            android:label="@string/eos_settings_title"
            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>
+2 −6
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ 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
@@ -94,11 +93,7 @@ class SubscriberService : Service() {
    override fun onDestroy() {
        Log.d(TAG, "Subscriber service has been destroyed")
        stopService()
        val preferenceKey = getString(R.string.eos_preference_key_is_enabled)
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(preferenceKey, false)) {
             sendBroadcast(Intent(this, AutoRestartReceiver::class.java))
        }

        sendBroadcast(Intent(this, AutoRestartReceiver::class.java)) // Restart it if necessary!
        super.onDestroy()
    }

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

import android.content.Context
import android.content.Intent
import androidx.preference.PreferenceManager
import androidx.core.content.ContextCompat
import androidx.work.*
import io.heckel.ntfy.app.Application
import io.heckel.ntfy.util.Log
import io.heckel.ntfy.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

@@ -44,17 +43,11 @@ 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 sharedPreferences = PreferenceManager.getDefaultSharedPreferences(app)
                val preferenceKey = context.getString(R.string.eos_preference_key_is_enabled)
                val action = if (sharedPreferences.getBoolean(preferenceKey, false)) {
                    SubscriberService.Action.START
                } else {
                    SubscriberService.Action.STOP
                }

                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 serviceState = SubscriberService.readServiceState(context)
                if (serviceState == SubscriberService.ServiceState.STOPPED && action == SubscriberService.Action.STOP) {
                    return@withContext Result.success()
+0 −71
Original line number Diff line number Diff line
package io.heckel.ntfy.ui

import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.WindowInsetsController
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import io.heckel.ntfy.R
import io.heckel.ntfy.databinding.MainSettingsActivityBinding

class MainSettingsActivity : AppCompatActivity() {

    private lateinit var mBinding: MainSettingsActivityBinding

    @RequiresApi(Build.VERSION_CODES.R)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

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

        setupToolbar()
        setSystemBarsAppearance()
        showPreferencesFragment()
    }

    private fun setupToolbar() {
        mBinding.toolbar.setNavigationOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
    }

    @RequiresApi(Build.VERSION_CODES.R)
    private fun setSystemBarsAppearance() {
        val insetsController = window.insetsController ?: return

        val isLightMode = isSystemInLightMode()
        if (isLightMode) {
            insetsController.setSystemBarsAppearance(
                WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
                WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
            )
            insetsController.setSystemBarsAppearance(
                WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS,
                WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS
            )
        } else {
            insetsController.setSystemBarsAppearance(
                0,
                WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
            )
            insetsController.setSystemBarsAppearance(
                0,
                WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS
            )
        }
    }

    private fun isSystemInLightMode(): Boolean {
        val nightModeFlags = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
        return nightModeFlags != Configuration.UI_MODE_NIGHT_YES
    }

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