Commit 5bda6e0e authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Add app-wide settings screen

parent 11d26129
......@@ -72,6 +72,7 @@ dependencies {
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.jakewharton:disklrucache:2.0.2' //For caching album art bitmaps
......
......@@ -154,7 +154,7 @@
<string name="device">Device</string>
<string name="pair_device">Pair device</string>
<string name="remote_control">Remote control</string>
<string name="settings">KDE Connect Settings</string>
<string name="settings">Settings</string>
<string name="mpris_play">Play</string>
<string name="mpris_pause">Pause</string>
<string name="mpris_previous">Previous</string>
......@@ -263,7 +263,7 @@
<string name="presenter_fullscreen">Fullscreen</string>
<string name="presenter_exit">Exit presentation</string>
<string name="presenter_lock_tip">You can lock your device to use the volume keys as previous/next buttons</string>
<string name="add_command">Add a command</string>
<string name="addcommand_explanation">There are no commands registered</string>
<string name="addcommand_explanation2">You can add new commands in the KDE Connect System Settings</string>
......@@ -292,5 +292,10 @@
<string name="pref_plugin_systemvolume">System volume</string>
<string name="pref_plugin_systemvolume_desc">Control the system volume of the remote device</string>
<string name="mute">Mute</string>
<string name="devices">Devices</string>
<string name="settings_dark_mode">Dark mode</string>
<string name="settings_more_settings_title">More settings</string>
<string name="settings_more_settings_text">Per-device settings can be found under \'Plugin settings\' from within a device.</string>
</resources>
......@@ -238,7 +238,7 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
updateComputerListAction();
break;
case R.id.menu_rename:
mActivity.renameDevice();
mActivity.openRenameDeviceDialog();
break;
case R.id.menu_custom_device_list:
startActivity(new Intent(mActivity, CustomDevicesActivity.class));
......
package org.kde.kdeconnect.UserInterface;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import org.kde.kdeconnect.Helpers.DeviceHelper;
import org.kde.kdeconnect_tp.R;
public class SettingsFragment extends PreferenceFragmentCompat implements MainActivity.NameChangeCallback {
MainActivity mainActivity;
private Preference renameDevice;
@Override
public void onDestroy() {
mainActivity.removeNameChangeCallback(this);
super.onDestroy();
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
mainActivity = (MainActivity)getActivity();
Context context = mainActivity;
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Rename device
mainActivity.addNameChangeCallback(this);
renameDevice = new Preference(context);
renameDevice.setPersistent(false);
renameDevice.setSelectable(true);
renameDevice.setOnPreferenceClickListener(preference -> {
mainActivity.openRenameDeviceDialog();
return true;
});
String deviceName = DeviceHelper.getDeviceName(context);
renameDevice.setTitle(R.string.device_rename_title);
renameDevice.setSummary(deviceName);
screen.addPreference(renameDevice);
//TODO: Trusted wifi networks settings should go here
// Dark mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
final SwitchPreference darkThemeSwitch = new SwitchPreference(context);
darkThemeSwitch.setPersistent(false);
darkThemeSwitch.setChecked(ThemeUtil.shouldUseDarkTheme(context));
darkThemeSwitch.setTitle(R.string.settings_dark_mode);
darkThemeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
boolean isChecked = (Boolean)newValue;
boolean isDarkAlready = prefs.getBoolean("darkTheme", false);
if (isDarkAlready != isChecked) {
prefs.edit().putBoolean("darkTheme", isChecked).apply();
if (mainActivity != null) {
mainActivity.recreate();
}
}
return true;
});
screen.addPreference(darkThemeSwitch);
}
//TODO: Persistent notification toggle for pre-oreo?
// More settings text
Preference moreSettingsText = new Preference(context);
moreSettingsText.setPersistent(false);
moreSettingsText.setSelectable(false);
moreSettingsText.setTitle(R.string.settings_more_settings_title);
moreSettingsText.setSummary(R.string.settings_more_settings_text);
screen.addPreference(moreSettingsText);
setPreferenceScreen(screen);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.e("AAAAAAAAAA","CHANGEEEED");
}
@Override
public void onNameChanged(String newName) {
renameDevice.setSummary(newName);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment