Code quality: preference
This commit is contained in:
parent
71ae99012b
commit
ce3242c748
|
@ -70,13 +70,13 @@ DO NOT COMMIT
|
|||
layout_constraintRight_
|
||||
layout_constraintLeft_
|
||||
|
||||
### Use Preference from v7 library (android.support.v7.preference.PreferenceScreen)
|
||||
### Use Preference from androidx library (androidx.preference.PreferenceScreen)
|
||||
<PreferenceScreen
|
||||
|
||||
### Use im.vector.preference.VectorSwitchPreference to support multiline of the title
|
||||
### Use im.vector.riotredesign.core.preference.VectorSwitchPreference to support multiline of the title
|
||||
<SwitchPreference
|
||||
|
||||
### Use im.vector.preference.VectorPreference to support multiline of the title
|
||||
### Use im.vector.riotredesign.core.preference.VectorPreference to support multiline of the title
|
||||
<Preference\n
|
||||
|
||||
### Will crash on API < 21. Use ?colorAccent instead
|
||||
|
|
|
@ -39,7 +39,8 @@ open class UserAvatarPreference : Preference {
|
|||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.vector_settings_round_avatar
|
||||
isIconSpaceReserved = false
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
|
|
|
@ -37,7 +37,8 @@ class VectorEditTextPreference : EditTextPreference {
|
|||
|
||||
init {
|
||||
dialogLayoutResource = R.layout.dialog_preference_edit_text
|
||||
isIconSpaceReserved = false
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
// No single line for title
|
||||
|
|
|
@ -54,7 +54,8 @@ class VectorListPreference : ListPreference {
|
|||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.vector_settings_list_preference_with_warning
|
||||
isIconSpaceReserved = false
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
|
|
|
@ -75,7 +75,8 @@ open class VectorPreference : Preference {
|
|||
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
|
||||
|
||||
init {
|
||||
isIconSpaceReserved = false
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
var isHighlighted = false
|
||||
|
@ -156,8 +157,4 @@ open class VectorPreference : Preference {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LOG_TAG = VectorPreference::class.java.simpleName
|
||||
}
|
||||
}
|
|
@ -36,7 +36,8 @@ class VectorPreferenceCategory : PreferenceCategory {
|
|||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
||||
|
||||
init {
|
||||
isIconSpaceReserved = false
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
|
@ -47,6 +48,8 @@ class VectorPreferenceCategory : PreferenceCategory {
|
|||
titleTextView?.setTypeface(null, Typeface.BOLD)
|
||||
|
||||
// "isIconSpaceReserved = false" does not work for preference category, so remove the padding
|
||||
if (!isIconSpaceReserved) {
|
||||
(titleTextView?.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,8 @@ class VectorSwitchPreference : SwitchPreference {
|
|||
constructor(context: Context) : super(context)
|
||||
|
||||
init {
|
||||
isIconSpaceReserved = false
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.PowerManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import timber.log.Timber
|
||||
|
@ -30,7 +29,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
it.action = "SLOW"
|
||||
context.startService(it)
|
||||
try {
|
||||
if (SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
} else {
|
||||
context.startService(intent)
|
||||
|
@ -41,7 +40,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
}
|
||||
}
|
||||
|
||||
scheduleAlarm(context,30_000L)
|
||||
scheduleAlarm(context, 30_000L)
|
||||
|
||||
Timber.i("Alarm scheduled to restart service")
|
||||
}
|
||||
|
@ -56,7 +55,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val firstMillis = System.currentTimeMillis() + delay
|
||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
if (SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
alarmMgr.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, firstMillis, pIntent)
|
||||
} else {
|
||||
alarmMgr.set(AlarmManager.RTC_WAKEUP, firstMillis, pIntent)
|
||||
|
|
|
@ -19,13 +19,11 @@ import android.app.NotificationManager
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.IBinder
|
||||
import im.vector.matrix.android.internal.session.sync.job.SyncService
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.features.notifications.NotificationUtils
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
|
||||
class VectorSyncService : SyncService() {
|
||||
|
||||
|
@ -51,7 +49,7 @@ class VectorSyncService : SyncService() {
|
|||
*/
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
Timber.v("VectorSyncService - onStartCommand ")
|
||||
if (SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val notification = NotificationUtils.buildForegroundServiceNotification(applicationContext, R.string.notification_listening_for_events, false)
|
||||
startForeground(NotificationUtils.NOTIFICATION_ID_FOREGROUND_SERVICE, notification)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory
|
||||
<im.vector.riotredesign.core.preference.VectorPreferenceCategory
|
||||
android:key="SETTINGS_NOTIFICATION_LEVEL"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_notification_by_event">
|
||||
|
@ -34,7 +34,7 @@
|
|||
android:key="SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY_2"
|
||||
android:title="@string/settings_messages_sent_by_bot" />
|
||||
|
||||
</PreferenceCategory>
|
||||
</im.vector.riotredesign.core.preference.VectorPreferenceCategory>
|
||||
|
||||
<im.vector.riotredesign.core.preference.VectorPreferenceDivider />
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<!--<SwitchPreference-->
|
||||
<!--<im.vector.riotredesign.core.preference.VectorSwitchPreference-->
|
||||
<!--android:key="SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY"-->
|
||||
<!--android:title="@string/settings_enable_all_notif" />-->
|
||||
|
||||
<SwitchPreference
|
||||
<im.vector.riotredesign.core.preference.VectorSwitchPreference
|
||||
android:key="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/settings_enable_this_device" />
|
||||
|
@ -17,12 +17,12 @@
|
|||
<!--android:key="SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY"-->
|
||||
<!--android:title="@string/settings_turn_screen_on" />-->
|
||||
|
||||
<!--<Preference-->
|
||||
<!--<im.vector.riotredesign.core.preference.VectorPreference-->
|
||||
<!--android:dialogTitle="@string/settings_notification_privacy"-->
|
||||
<!--android:key="SETTINGS_NOTIFICATION_PRIVACY_PREFERENCE_KEY"-->
|
||||
<!--android:title="@string/settings_notification_privacy" />-->
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:key="SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
|
@ -32,24 +32,24 @@
|
|||
android:enabled="false"
|
||||
app:fragment="im.vector.fragments.VectorSettingsNotificationsAdvancedFragment" />
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:key="SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY"
|
||||
android:title="@string/settings_notification_troubleshoot"
|
||||
app:fragment="im.vector.riotredesign.features.settings.VectorSettingsNotificationsTroubleshootFragment" />
|
||||
|
||||
<PreferenceCategory android:title="@string/settings_expert">
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:title="@string/settings_notifications_targets"
|
||||
android:persistent="false"
|
||||
app:fragment="im.vector.riotredesign.features.settings.push.PushGatewaysFragment" />
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:title="@string/settings_push_rules"
|
||||
android:persistent="false"
|
||||
app:fragment="im.vector.riotredesign.features.settings.push.PushRulesFragment" />
|
||||
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
</androidx.preference.PreferenceScreen>
|
|
@ -1,21 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:icon="@drawable/ic_settings_general"
|
||||
android:title="@string/settings_general_title"
|
||||
app:fragment="com.example.SyncFragment" />
|
||||
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:icon="@drawable/ic_flair"
|
||||
android:title="@string/settings_flair"
|
||||
app:fragment="com.example.SyncFragment" />
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:icon="@drawable/ic_bell"
|
||||
android:key="SETTINGS_NOTIFICATIONS_KEY"
|
||||
|
@ -23,32 +23,32 @@
|
|||
app:fragment="im.vector.riotredesign.features.settings.VectorSettingsNotificationPreferenceFragment" />
|
||||
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:icon="@drawable/ic_sliders"
|
||||
android:title="@string/settings_preferences"
|
||||
app:fragment="com.example.SyncFragment" />
|
||||
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:icon="@drawable/ic_lock"
|
||||
android:title="@string/settings_security_and_privacy"
|
||||
app:fragment="com.example.SyncFragment" />
|
||||
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:icon="@drawable/ic_settings_lab"
|
||||
android:title="@string/room_settings_labs_pref_title"
|
||||
app:fragment="com.example.SyncFragment" />
|
||||
|
||||
|
||||
<Preference
|
||||
<im.vector.riotredesign.core.preference.VectorPreference
|
||||
android:layout_width="match_parent"
|
||||
android:icon="@drawable/ic_devices_info"
|
||||
android:title="Legacy"
|
||||
app:fragment="com.example.SyncFragment" />
|
||||
|
||||
|
||||
</PreferenceScreen>
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue