Some style fixes

This commit is contained in:
Philipp Heckel 2022-12-06 20:37:30 -05:00
parent e64cd79c28
commit 314bba4113
14 changed files with 20 additions and 33 deletions

View file

@ -1,7 +1,6 @@
package io.heckel.ntfy.app
import android.app.Application
import android.content.Context
import io.heckel.ntfy.db.Database
import io.heckel.ntfy.db.Repository
import io.heckel.ntfy.util.Log

View file

@ -95,7 +95,7 @@ class ApiService {
throw Exception("Unexpected response ${response.code} when polling topic $url")
}
val body = response.body?.string()?.trim()
if (body == null || body.isEmpty()) return emptyList()
if (body.isNullOrEmpty()) return emptyList()
val notifications = body.lines().mapNotNull { line ->
parser.parse(line, subscriptionId = subscriptionId, notificationId = 0) // No notification when we poll
}
@ -166,7 +166,7 @@ class ApiService {
}
class UnauthorizedException(val user: User?) : Exception()
class EntityTooLargeException() : Exception()
class EntityTooLargeException : Exception()
companion object {
val USER_AGENT = "ntfy/${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR}; Android ${Build.VERSION.RELEASE}; SDK ${Build.VERSION.SDK_INT})"

View file

@ -11,7 +11,7 @@ import io.heckel.ntfy.util.Log
* Download attachment in the background via WorkManager
*
* The indirection via WorkManager is required since this code may be executed
* in a doze state and Internet may not be available. It's also best practice apparently.
* in a doze state and Internet may not be available. It's also best practice, apparently.
*/
object DownloadManager {
private const val TAG = "NtfyDownloadManager"

View file

@ -200,7 +200,7 @@ class SubscriberService : Service() {
// retrieve old messages. This is important, so we don't download attachments from old messages.
val since = sinceByBaseUrl[connectionId.baseUrl] ?: "none"
val serviceActive = { -> isServiceStarted }
val serviceActive = { isServiceStarted }
val user = repository.getUser(connectionId.baseUrl)
val connection = if (repository.getConnectionProtocol() == Repository.CONNECTION_PROTOCOL_WS) {
val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager

View file

@ -5,8 +5,6 @@ import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager

View file

@ -25,16 +25,18 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.button.MaterialButton
import com.stfalcon.imageviewer.StfalconImageViewer
import io.heckel.ntfy.BuildConfig
import io.heckel.ntfy.R
import io.heckel.ntfy.db.*
import io.heckel.ntfy.msg.DownloadManager
import io.heckel.ntfy.msg.DownloadAttachmentWorker
import io.heckel.ntfy.msg.DownloadManager
import io.heckel.ntfy.msg.DownloadType
import io.heckel.ntfy.msg.NotificationService
import io.heckel.ntfy.msg.NotificationService.Companion.ACTION_VIEW
import io.heckel.ntfy.util.*
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
class DetailAdapter(private val activity: Activity, private val lifecycleScope: CoroutineScope, private val repository: Repository, private val onClick: (Notification) -> Unit, private val onLongClick: (Notification) -> Unit) :
ListAdapter<Notification, DetailAdapter.DetailViewHolder>(TopicDiffCallback) {
@ -204,7 +206,7 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
}
private fun maybeRenderActions(context: Context, notification: Notification) {
if (notification.actions != null && notification.actions.isNotEmpty()) {
if (!notification.actions.isNullOrEmpty()) {
actionsWrapperView.visibility = View.VISIBLE
val actionsCount = Math.min(notification.actions.size, 3) // per documentation, only 3 actions are available
for (i in 0 until actionsCount) {
@ -220,7 +222,7 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
private fun resetCardButtons() {
// clear any previously created dynamic buttons
actionsFlow.allViews.forEach { it -> actionsFlow.removeView(it) }
actionsFlow.allViews.forEach { actionsFlow.removeView(it) }
actionsWrapperView.removeAllViews()
actionsWrapperView.addView(actionsFlow)
}

View file

@ -175,9 +175,8 @@ class DetailSettingsActivity : AppCompatActivity() {
return subscription.mutedUntil.toString()
}
}
pref?.summaryProvider = Preference.SummaryProvider<ListPreference> { _ ->
val mutedUntilValue = subscription.mutedUntil
when (mutedUntilValue) {
pref?.summaryProvider = Preference.SummaryProvider<ListPreference> {
when (val mutedUntilValue = subscription.mutedUntil) {
Repository.MUTED_UNTIL_SHOW_ALL -> getString(R.string.settings_notifications_muted_until_show_all)
Repository.MUTED_UNTIL_FOREVER -> getString(R.string.settings_notifications_muted_until_forever)
else -> {
@ -258,7 +257,7 @@ class DetailSettingsActivity : AppCompatActivity() {
iconSetPref = findPreference(prefId) ?: return
iconSetPref.isVisible = subscription.icon == null
iconSetPref.preferenceDataStore = object : PreferenceDataStore() { } // Dummy store to protect from accidentally overwriting
iconSetPref.onPreferenceClickListener = Preference.OnPreferenceClickListener { _ ->
iconSetPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
iconSetLauncher.launch("image/*")
true
}
@ -269,7 +268,7 @@ class DetailSettingsActivity : AppCompatActivity() {
iconRemovePref = findPreference(prefId) ?: return
iconRemovePref.isVisible = subscription.icon != null
iconRemovePref.preferenceDataStore = object : PreferenceDataStore() { } // Dummy store to protect from accidentally overwriting
iconRemovePref.onPreferenceClickListener = Preference.OnPreferenceClickListener { _ ->
iconRemovePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
iconRemovePref.isVisible = false
iconSetPref.isVisible = true
deleteIcon(subscription.icon)

View file

@ -1,9 +1,7 @@
package io.heckel.ntfy.ui
import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Color
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -17,10 +15,8 @@ import io.heckel.ntfy.R
import io.heckel.ntfy.db.ConnectionState
import io.heckel.ntfy.db.Repository
import io.heckel.ntfy.db.Subscription
import io.heckel.ntfy.msg.NotificationService
import io.heckel.ntfy.util.Log
import io.heckel.ntfy.util.readBitmapFromUriOrNull
import io.heckel.ntfy.util.displayName
import io.heckel.ntfy.util.readBitmapFromUriOrNull
import java.text.DateFormat
import java.util.*

View file

@ -8,10 +8,8 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import io.heckel.ntfy.db.*
import io.heckel.ntfy.up.Distributor
import io.heckel.ntfy.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlin.collections.List
class SubscriptionsViewModel(private val repository: Repository) : ViewModel() {
fun list(): LiveData<List<Subscription>> {

View file

@ -8,7 +8,6 @@ import android.widget.RadioButton
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import io.heckel.ntfy.R
import io.heckel.ntfy.db.Database
import io.heckel.ntfy.db.Repository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay

View file

@ -3,13 +3,11 @@ package io.heckel.ntfy.ui
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import com.google.android.material.textfield.TextInputEditText
import io.heckel.ntfy.R

View file

@ -10,12 +10,10 @@ import io.heckel.ntfy.service.SubscriberServiceManager
import io.heckel.ntfy.util.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import java.util.*
import kotlin.random.Random
/**
* This is the UnifiedPush broadcast receiver to handle the distributor actions REGISTER and UNREGISTER.

View file

@ -309,7 +309,7 @@
<string name="detail_settings_appearance_header">Darstellung</string>
<string name="detail_settings_appearance_icon_set_title">Abo-Icon</string>
<string name="detail_settings_appearance_icon_set_summary">Ein Icon zur Darstellung in Benachrichtigungen auswählen</string>
<string name="detail_settings_appearance_icon_remove_title">Abo-Icon (entfernen durch antippen)</string>
<string name="detail_settings_appearance_icon_remove_title">Abo-Icon (entfernen durch Antippen)</string>
<string name="detail_settings_appearance_icon_error_saving">Kann Icon nicht speichern: %1$s</string>
<string name="detail_settings_global_setting_title">Globale Einstellung verwenden</string>
<string name="detail_settings_global_setting_suffix">globale Einstellung</string>
@ -323,9 +323,9 @@
<string name="add_dialog_base_urls_dropdown_clear">Service-URL löschen</string>
<string name="detail_settings_appearance_display_name_default_summary">%1$s (Standard)</string>
<string name="detail_settings_appearance_display_name_title">Anzeigename</string>
<string name="detail_settings_appearance_display_name_message">Gib einen eigenen Anzeigenamen für diese Abo an. Leer lassen für den Standardwert (%1$s).</string>
<string name="detail_settings_appearance_display_name_message">Gib einen eigenen Anzeigenamen für dieses Abo an. Leer lassen für den Standardwert (%1$s).</string>
<string name="detail_settings_about_topic_url_title">Themen-URL</string>
<string name="detail_settings_about_header">Über</string>
<string name="detail_settings_about_topic_url_copied_to_clipboard_message">In Zwischenablage kopiert</string>
<string name="main_menu_donate_title">Spenden 💸</string>
</resources>
</resources>

View file

@ -318,7 +318,7 @@
<string name="settings_advanced_broadcast_summary_disabled">Apps cannot receive notifications as broadcasts</string>
<string name="settings_advanced_record_logs_title">Record logs</string>
<string name="settings_advanced_record_logs_summary_enabled">Logging (up to 1,000 entries) to device …</string>
<string name="settings_advanced_record_logs_summary_disabled">Turn on logging so you can share logs later to diagnose issues.</string>
<string name="settings_advanced_record_logs_summary_disabled">Turn on logging, so you can share logs later to diagnose issues.</string>
<string name="settings_advanced_export_logs_title">Copy/upload logs</string>
<string name="settings_advanced_export_logs_summary">Copy logs to the clipboard, or upload to nopaste.net (owned by the ntfy author). Hostnames and topics can be censored, notifications will never be.</string>
<string name="settings_advanced_export_logs_entry_copy_original">Copy to clipboard</string>