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

Commit 2bc87013 authored by Philipp Heckel's avatar Philipp Heckel
Browse files

Preferences dialog

parent 72393ec0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,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"
+29 −11
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
            android:supportsRtl="true"
            android:theme="@style/AppTheme"
            android:usesCleartextTraffic="true">

        <!-- Main activity -->
        <activity
                android:name=".ui.MainActivity"
@@ -43,29 +44,48 @@
                    android:value=".ui.MainActivity"/>
        </activity>

        <!-- Settings activity -->
        <activity
                android:name=".ui.SettingsActivity"
                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=".service.SubscriberService"/>

        <!-- Subscriber service restart on reboot -->
        <receiver android:name=".service.SubscriberService$BootStartReceiver" android:enabled="true">
        <receiver
                android:name=".service.SubscriberService$BootStartReceiver"
                android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <!-- Subscriber service restart on destruction -->
        <receiver android:name=".service.SubscriberService$AutoRestartReceiver" android:enabled="true"
        <receiver
                android:name=".service.SubscriberService$AutoRestartReceiver"
                android:enabled="true"
                android:exported="false"/>

        <!-- Broadcast receiver to send messages via intents -->
        <receiver android:name=".msg.BroadcastService$BroadcastReceiver" android:enabled="true" android:exported="true">
        <receiver
                android:name=".msg.BroadcastService$BroadcastReceiver"
                android:enabled="true"
                android:exported="true">
            <intent-filter>
                <action android:name="io.heckel.ntfy.SEND_MESSAGE"/>
            </intent-filter>
        </receiver>

        <!-- Broadcast receiver for UnifiedPush; must match https://github.com/UnifiedPush/UP-spec/blob/main/specifications.md -->
        <receiver android:name=".up.BroadcastReceiver" android:enabled="true" android:exported="true">
        <receiver
                android:name=".up.BroadcastReceiver"
                android:enabled="true"
                android:exported="true">
            <intent-filter>
                <action android:name="org.unifiedpush.android.distributor.REGISTER"/>
                <action android:name="org.unifiedpush.android.distributor.UNREGISTER"/>
@@ -80,7 +100,6 @@
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <meta-data
                android:name="firebase_analytics_collection_enabled"
                android:value="false"/>
@@ -88,5 +107,4 @@
                android:name="com.google.firebase.messaging.default_notification_icon"
                android:resource="@drawable/ic_notification"/>
    </application>

</manifest>
+28 −5
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import android.content.SharedPreferences
import android.util.Log
import androidx.annotation.WorkerThread
import androidx.lifecycle.*
import androidx.preference.PreferenceManager
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicLong

@@ -142,12 +143,32 @@ class Repository(private val sharedPrefs: SharedPreferences, private val subscri
            .apply()
    }

    private suspend fun isMuted(subscriptionId: Long): Boolean {
        if (isGlobalMuted()) {
            return true

    fun getUnifiedPushEnabled(): Boolean {
        return sharedPrefs.getBoolean(SHARED_PREFS_UNIFIED_PUSH_ENABLED, true) // Enabled by default!
    }

    fun setUnifiedPushEnabled(enabled: Boolean) {
        sharedPrefs.edit()
            .putBoolean(SHARED_PREFS_UNIFIED_PUSH_ENABLED, enabled)
            .apply()
    }

    fun getUnifiedPushBaseUrl(): String? {
        return sharedPrefs.getString(SHARED_PREFS_UNIFIED_PUSH_BASE_URL, null)
    }

    fun setUnifiedPushBaseUrl(baseUrl: String) {
        if (baseUrl == "") {
            sharedPrefs
                .edit()
                .remove(SHARED_PREFS_UNIFIED_PUSH_BASE_URL)
                .apply()
        } else {
            sharedPrefs.edit()
                .putString(SHARED_PREFS_UNIFIED_PUSH_BASE_URL, baseUrl)
                .apply()
        }
        val s = getSubscription(subscriptionId) ?: return true
        return s.mutedUntil == 1L || (s.mutedUntil > 1L && s.mutedUntil > System.currentTimeMillis()/1000)
    }

    fun isGlobalMuted(): Boolean {
@@ -242,6 +263,8 @@ class Repository(private val sharedPrefs: SharedPreferences, private val subscri
        const val SHARED_PREFS_POLL_WORKER_VERSION = "PollWorkerVersion"
        const val SHARED_PREFS_AUTO_RESTART_WORKER_VERSION = "AutoRestartWorkerVersion"
        const val SHARED_PREFS_MUTED_UNTIL_TIMESTAMP = "MutedUntil"
        const val SHARED_PREFS_UNIFIED_PUSH_ENABLED = "UnifiedPushEnabled"
        const val SHARED_PREFS_UNIFIED_PUSH_BASE_URL = "UnifiedPushBaseURL"

        private const val TAG = "NtfyRepository"
        private var instance: Repository? = null
+0 −1
Original line number Diff line number Diff line
@@ -420,7 +420,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
                val formattedDate = formatDateShort(subscriptionMutedUntil)
                notificationsDisabledUntilItem?.title = getString(R.string.detail_menu_notifications_disabled_until, formattedDate)
            }

        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -232,6 +232,10 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
                onNotificationSettingsClick(enable = true)
                true
            }
            R.id.main_menu_settings -> {
                startActivity(Intent(this, SettingsActivity::class.java))
                true
            }
            R.id.main_menu_source -> {
                startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_source_url))))
                true
Loading