2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Use lambdas

This commit is contained in:
Nicolas Fella
2018-09-29 20:40:02 +02:00
parent c3fc001621
commit e68224f2b1
4 changed files with 31 additions and 66 deletions

View File

@@ -213,18 +213,12 @@ public class MprisReceiverPlugin extends Plugin implements MediaSessionManager.O
return new AlertDialog.Builder(deviceActivity)
.setTitle(R.string.pref_plugin_mpris)
.setMessage(R.string.no_permission_mprisreceiver)
.setPositiveButton(R.string.open_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
deviceActivity.startActivityForResult(intent, MainActivity.RESULT_NEEDS_RELOAD);
}
.setPositiveButton(R.string.open_settings, (dialogInterface, i) -> {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
deviceActivity.startActivityForResult(intent, MainActivity.RESULT_NEEDS_RELOAD);
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Do nothing
}
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
//Do nothing
})
.create();
}

View File

@@ -64,13 +64,9 @@ public class PresenterActivity extends AppCompatActivity {
runOnUiThread(() -> {
findViewById(R.id.next_button).setOnClickListener(v -> {
plugin.sendNext();
});
findViewById(R.id.next_button).setOnClickListener(v -> plugin.sendNext());
findViewById(R.id.previous_button).setOnClickListener(v -> {
plugin.sendPrevious();
});
findViewById(R.id.previous_button).setOnClickListener(v -> plugin.sendPrevious());
});

View File

@@ -59,36 +59,28 @@ public class SystemvolumeFragment extends ListFragment implements Sink.UpdateLis
// Don't set progress while the slider is moved
if (!tracking) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
}
});
activity.runOnUiThread(() -> adapter.notifyDataSetChanged());
}
}
public void connectToPlugin(final String deviceId) {
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
BackgroundService.RunCommand(activity, service -> {
Device device = service.getDevice(deviceId);
if (device == null)
return;
if (device == null)
return;
plugin = device.getPlugin(SystemvolumePlugin.class);
plugin = device.getPlugin(SystemvolumePlugin.class);
if (plugin == null) {
Log.e("SystemvolumeFragment", "device has no systemvolume plugin!");
return;
}
plugin.addSinkListener(SystemvolumeFragment.this);
plugin.requestSinkList();
Log.d("Systemvolume", "requestSinklist");
if (plugin == null) {
Log.e("SystemvolumeFragment", "device has no systemvolume plugin!");
return;
}
plugin.addSinkListener(SystemvolumeFragment.this);
plugin.requestSinkList();
Log.d("Systemvolume", "requestSinklist");
});
}
@@ -107,12 +99,9 @@ public class SystemvolumeFragment extends ListFragment implements Sink.UpdateLis
sink.addListener(SystemvolumeFragment.this);
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
adapter = new SinkAdapter(context, plugin.getSinks().toArray(new Sink[0]));
setListAdapter(adapter);
}
activity.runOnUiThread(() -> {
adapter = new SinkAdapter(context, plugin.getSinks().toArray(new Sink[0]));
setListAdapter(adapter);
});
}
@@ -157,12 +146,7 @@ public class SystemvolumeFragment extends ListFragment implements Sink.UpdateLis
@Override
public void onProgressChanged(final SeekBar seekBar, int i, boolean b) {
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
@Override
public void onServiceStart(BackgroundService service) {
plugin.sendVolume(sink.getName(), seekBar.getProgress());
}
});
BackgroundService.RunCommand(activity, service -> plugin.sendVolume(sink.getName(), seekBar.getProgress()));
}
@Override
@@ -173,12 +157,7 @@ public class SystemvolumeFragment extends ListFragment implements Sink.UpdateLis
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
tracking = false;
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
@Override
public void onServiceStart(BackgroundService service) {
plugin.sendVolume(sink.getName(), seekBar.getProgress());
}
});
BackgroundService.RunCommand(activity, service -> plugin.sendVolume(sink.getName(), seekBar.getProgress()));
}
@Override

View File

@@ -154,16 +154,12 @@ public class MainActivity extends AppCompatActivity {
SwitchCompat darkThemeSwitch = (SwitchCompat) drawerHeader.findViewById(R.id.dark_theme);
darkThemeSwitch.setChecked(ThemeUtil.shouldUseDarkTheme(this));
darkThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onCheckedChanged(CompoundButton darkThemeSwitch, boolean isChecked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
boolean isDarkAlready = prefs.getBoolean("darkTheme", false);
if (isDarkAlready != isChecked) {
prefs.edit().putBoolean("darkTheme", isChecked).apply();
MainActivity.this.recreate();
}
darkThemeSwitch.setOnCheckedChangeListener((darkThemeSwitch1, isChecked) -> {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
boolean isDarkAlready = prefs.getBoolean("darkTheme", false);
if (isDarkAlready != isChecked) {
prefs.edit().putBoolean("darkTheme", isChecked).apply();
MainActivity.this.recreate();
}
});
}