Skip to content

Commit

Permalink
various small fixes for older APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsynik committed Oct 24, 2024
1 parent 23b1c31 commit e1d00ae
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class NotificationTS : Service() {
this.getSystemService(NotificationManager::class.java)!!
.createNotificationChannel(channel)
}
val accessibilityNote = if (Accessibility.isEnabledService(App.context)) this.getText(R.string.accessibility_note) else ""
val accEnabled = Accessibility.isEnabledService(App.context)
val accessibilityNote = if (accEnabled) getText(R.string.accessibility_note) else getText(R.string.stat_running)
if (builder == null) {
builder = NotificationCompat.Builder(this, channelId)
.setContentTitle(getString(R.string.app_name))
Expand All @@ -131,7 +132,8 @@ class NotificationTS : Service() {
.setOngoing(true)
.setContentIntent(contentPendingIntent)
.setStyle(NotificationCompat.BigTextStyle().bigText(accessibilityNote))
.addAction(
if (!accEnabled)
builder?.addAction(
android.R.drawable.ic_menu_close_clear_cancel,
this.getText(R.string.exit).toString().uppercase(),
exitPendingIntent
Expand All @@ -146,7 +148,7 @@ class NotificationTS : Service() {
builder?.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.ic_notification))

builder?.let {
ServiceCompat.startForeground(this, notificationId, it.build(), FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
ServiceCompat.startForeground(this, notificationId, it.build(), FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/ru/yourok/torrserve/settings/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import java.io.File

object Settings {
val showFab: Boolean
get() = get("show_fab", true)
get() = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) false // TODO Fix FAB focus
else
get("show_fab", true)

val showSortFab: Boolean
get() = get("show_sort_fab", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@ import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import androidx.preference.*
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceGroup
import androidx.preference.PreferenceGroupAdapter
import androidx.preference.PreferenceScreen
import androidx.preference.PreferenceViewHolder
import androidx.preference.SwitchPreferenceCompat
import androidx.recyclerview.widget.RecyclerView
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.*
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import ru.yourok.torrserve.BuildConfig
import ru.yourok.torrserve.R
import ru.yourok.torrserve.ad.ADManager
Expand All @@ -34,6 +48,7 @@ import ru.yourok.torrserve.ui.fragments.main.update.apk.ApkUpdateFragment
import ru.yourok.torrserve.ui.fragments.main.update.apk.UpdaterApk
import ru.yourok.torrserve.ui.fragments.speedtest.SpeedTest
import ru.yourok.torrserve.utils.Accessibility
import ru.yourok.torrserve.utils.Format.dp2px
import ru.yourok.torrserve.utils.ThemeUtil
import ru.yourok.torrserve.utils.ThemeUtil.Companion.isDarkMode

Expand All @@ -56,6 +71,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
isSingleLine = false
maxLines = 2
}
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
holder.itemView.setPadding(dp2px(16f), 0, dp2px(16f), 0)
}
}
}
}
Expand All @@ -73,7 +91,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val rv = listView // This holds the PreferenceScreen's items
rv?.setPadding(0, 0, 0, 56) // (left, top, right, bottom)

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
rv?.setPadding(0, dp2px(32f), 0, dp2px(16f)) // (left, top, right, bottom)
} else
rv?.setPadding(0, 0, 0, dp2px(28f)) // (left, top, right, bottom)
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
Expand All @@ -94,10 +116,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
}

findPreference<Preference>("speedtest")?.apply {
setOnPreferenceClickListener {
SpeedTest().show(requireActivity(), R.id.container, true)
true
}
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP)
isEnabled = false
else
setOnPreferenceClickListener {
SpeedTest().show(requireActivity(), R.id.container, true)
true
}
}

findPreference<Preference>("server_settings")?.setOnPreferenceClickListener {
Expand Down Expand Up @@ -242,7 +267,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
true
}
}
// hide FAB prefs on TVs (no FAB in landscape)
// hide FAB prefs on TVs (no FAB in landscape) and on old APIs (fab focus buggy for now)
val fabPref = findPreference<Preference>("show_fab")
val sortFabPref = findPreference<Preference>("show_sort_fab")
val catFabPref = findPreference<Preference>("show_cat_fab")
Expand All @@ -251,6 +276,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
sortFabPref?.let { ps?.removePreference(it) }
catFabPref?.let { ps?.removePreference(it) }
}
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) { // TODO Fix FAB focus
fabPref?.let { ps?.removePreference(it) }
}
}

override fun onResume() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<string name="torserver_title">Настройки TorrServer</string>
<string name="torserver_summary">Настройки параметров TorrServer</string>
<string name="remove_action_title">Удалить действие по умолчанию</string>
<string name="remove_action_summary">Сброс действия по умолчанию при открытии торрента</string>
<string name="remove_action_summary">Сброс ассоциации приложения с торрентами и magnet-ссылками</string>
<string name="boot_start_title">Запускать сервер при загрузке</string>
<string name="boot_start_sum_on">Запускать локальный сервер при загрузке устройства</string>
<string name="boot_start_sum_off">Не запускать локальный сервер при загрузке устройства</string>
Expand Down

0 comments on commit e1d00ae

Please sign in to comment.