Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/UserInterface/SettingsFragment.java
1 | package org.kde.kdeconnect.UserInterface; | 1 | package org.kde.kdeconnect.UserInterface; | ||
---|---|---|---|---|---|
2 | 2 | | |||
3 | import android.content.Context; | 3 | import android.content.Context; | ||
4 | import android.content.Intent; | ||||
4 | import android.content.SharedPreferences; | 5 | import android.content.SharedPreferences; | ||
6 | import android.net.Uri; | ||||
5 | import android.os.Build; | 7 | import android.os.Build; | ||
6 | import android.os.Bundle; | 8 | import android.os.Bundle; | ||
7 | import android.preference.PreferenceManager; | 9 | import android.preference.PreferenceManager; | ||
10 | import android.provider.Settings; | ||||
8 | 11 | | |||
9 | import org.kde.kdeconnect.BackgroundService; | 12 | import org.kde.kdeconnect.BackgroundService; | ||
10 | import org.kde.kdeconnect.Helpers.DeviceHelper; | 13 | import org.kde.kdeconnect.Helpers.DeviceHelper; | ||
11 | import org.kde.kdeconnect.Helpers.NotificationHelper; | 14 | import org.kde.kdeconnect.Helpers.NotificationHelper; | ||
12 | import org.kde.kdeconnect_tp.R; | 15 | import org.kde.kdeconnect_tp.R; | ||
13 | 16 | | |||
14 | import androidx.preference.Preference; | 17 | import androidx.preference.Preference; | ||
15 | import androidx.preference.PreferenceFragmentCompat; | 18 | import androidx.preference.PreferenceFragmentCompat; | ||
Show All 10 Lines | 23 | public class SettingsFragment extends PreferenceFragmentCompat implements MainActivity.NameChangeCallback { | |||
26 | public void onDestroy() { | 29 | public void onDestroy() { | ||
27 | mainActivity.removeNameChangeCallback(this); | 30 | mainActivity.removeNameChangeCallback(this); | ||
28 | super.onDestroy(); | 31 | super.onDestroy(); | ||
29 | } | 32 | } | ||
30 | 33 | | |||
31 | @Override | 34 | @Override | ||
32 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | 35 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
33 | 36 | | |||
34 | mainActivity = (MainActivity)getActivity(); | 37 | mainActivity = (MainActivity)getActivity(); | ||
albertvaka: Try not to include unrelated changes in patches, like this added space. | |||||
35 | Context context = getPreferenceManager().getContext(); | 38 | Context context = getPreferenceManager().getContext(); | ||
36 | 39 | | |||
37 | PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context); | 40 | PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context); | ||
38 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | 41 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | ||
39 | 42 | | |||
40 | // Rename device | 43 | // Rename device | ||
41 | mainActivity.addNameChangeCallback(this); | 44 | mainActivity.addNameChangeCallback(this); | ||
42 | renameDevice = new Preference(context); | 45 | renameDevice = new Preference(context); | ||
Show All 32 Lines | |||||
75 | 78 | | |||
76 | // Persistent notification toggle | 79 | // Persistent notification toggle | ||
77 | final TwoStatePreference notificationSwitch = new SwitchPreferenceCompat(context); | 80 | final TwoStatePreference notificationSwitch = new SwitchPreferenceCompat(context); | ||
78 | notificationSwitch.setPersistent(false); | 81 | notificationSwitch.setPersistent(false); | ||
79 | notificationSwitch.setChecked(NotificationHelper.isPersistentNotificationEnabled(context)); | 82 | notificationSwitch.setChecked(NotificationHelper.isPersistentNotificationEnabled(context)); | ||
80 | notificationSwitch.setTitle(R.string.setting_persistent_notification); | 83 | notificationSwitch.setTitle(R.string.setting_persistent_notification); | ||
81 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | 84 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
82 | notificationSwitch.setSummary(R.string.setting_persistent_notification_pie_description); | 85 | notificationSwitch.setSummary(R.string.setting_persistent_notification_pie_description); | ||
83 | notificationSwitch.setEnabled(false); | | |||
84 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | 86 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
85 | notificationSwitch.setSummary(R.string.setting_persistent_notification_oreo_description); | 87 | notificationSwitch.setSummary(R.string.setting_persistent_notification_oreo_description); | ||
86 | notificationSwitch.setEnabled(false); | | |||
87 | } | 88 | } | ||
88 | notificationSwitch.setOnPreferenceChangeListener((preference, newValue) -> { | 89 | notificationSwitch.setOnPreferenceChangeListener((preference, newValue) -> { | ||
90 | | ||||
89 | final boolean isChecked = (Boolean)newValue; | 91 | final boolean isChecked = (Boolean)newValue; | ||
92 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||||
93 | Intent intent = new Intent(); | ||||
94 | if(android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1){ | ||||
eduisters: Why this if/else? You already tested for O above | |||||
brute4s99: you're right, I shall remove it | |||||
95 | intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); | ||||
96 | intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName()); | ||||
97 | }else { | ||||
eduisters: indentation | |||||
98 | intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | ||||
99 | intent.addCategory(Intent.CATEGORY_DEFAULT); | ||||
eduisters: indentation | |||||
100 | intent.setData(Uri.parse("package:" + context.getPackageName())); | ||||
101 | } | ||||
nicolasfella: Build.VERSION.SDK_INT >= Build.VERSION_CODES.O should be enough | |||||
Can be replaced by a lambda (hover on Preference.OnPreferenceClickListener() and press Alt+enter) eduisters: Can be replaced by a lambda (hover on Preference.OnPreferenceClickListener() and press… | |||||
102 | | ||||
103 | context.startActivity(intent); | ||||
104 | } | ||||
105 | else { | ||||
90 | NotificationHelper.setPersistentNotificationEnabled(context, isChecked); | 106 | NotificationHelper.setPersistentNotificationEnabled(context, isChecked); | ||
91 | BackgroundService.RunCommand(context, service -> service.changePersistentNotificationVisibility(isChecked)); | 107 | BackgroundService.RunCommand(context, service -> service.changePersistentNotificationVisibility(isChecked)); | ||
92 | 108 | } | |||
93 | return true; | 109 | return true; | ||
94 | }); | 110 | }); | ||
95 | screen.addPreference(notificationSwitch); | 111 | screen.addPreference(notificationSwitch); | ||
96 | 112 | | |||
97 | // More settings text | 113 | // More settings text | ||
98 | Preference moreSettingsText = new Preference(context); | 114 | Preference moreSettingsText = new Preference(context); | ||
99 | moreSettingsText.setPersistent(false); | 115 | moreSettingsText.setPersistent(false); | ||
100 | moreSettingsText.setSelectable(false); | 116 | moreSettingsText.setSelectable(false); | ||
Show All 15 Lines |
Try not to include unrelated changes in patches, like this added space.