mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
DeviceCardAction: add @Nullable / @NonNull annotations
This commit is contained in:
+23
-5
@@ -1,26 +1,44 @@
|
||||
/* Copyright (C) 2025-2026 José Rebelo, Thomas Kuehne
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
public interface DeviceCardAction {
|
||||
@DrawableRes
|
||||
int getIcon(final GBDevice device);
|
||||
int getIcon(@NonNull final GBDevice device);
|
||||
|
||||
String getDescription(final GBDevice device, final Context context);
|
||||
@NonNull
|
||||
String getDescription(@NonNull final GBDevice device, @NonNull final Context context);
|
||||
|
||||
@Nullable
|
||||
default String getLabel(final GBDevice device, final Context context) {
|
||||
default String getLabel(@NonNull final GBDevice device, @NonNull final Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
default boolean isVisible(final GBDevice device) {
|
||||
default boolean isVisible(@NonNull final GBDevice device) {
|
||||
return device.isConnected();
|
||||
}
|
||||
|
||||
void onClick(final GBDevice device, final Context context);
|
||||
void onClick(@NonNull final GBDevice device, @NonNull final Context context);
|
||||
}
|
||||
|
||||
+4
-3
@@ -180,17 +180,18 @@ public class G1DeviceCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
public List<DeviceCardAction> getCustomActions() {
|
||||
return Collections.singletonList(new DeviceCardAction() {
|
||||
@Override
|
||||
public int getIcon(GBDevice device) {
|
||||
public int getIcon(@NonNull GBDevice device) {
|
||||
return R.drawable.ic_dnd;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDescription(final GBDevice device, final Context context) {
|
||||
public String getDescription(@NonNull final GBDevice device, @NonNull final Context context) {
|
||||
return context.getString(R.string.silent_mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final GBDevice device, final Context context) {
|
||||
public void onClick(@NonNull final GBDevice device, @NonNull final Context context) {
|
||||
final Intent intent = new Intent(G1Constants.INTENT_TOGGLE_SILENT_MODE);
|
||||
intent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
intent.setPackage(context.getPackageName());
|
||||
|
||||
+7
-7
@@ -24,21 +24,21 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.weightScale.WeightScaleProfile
|
||||
|
||||
class GenericWeightScaleAction : DeviceCardAction {
|
||||
override fun getIcon(device: GBDevice?): Int {
|
||||
override fun getIcon(device: GBDevice): Int {
|
||||
return R.drawable.ic_balance
|
||||
}
|
||||
|
||||
override fun getDescription(
|
||||
device: GBDevice?, context: Context?
|
||||
): String? {
|
||||
return context?.getString(R.string.weight_scale_show_measurement)
|
||||
device: GBDevice, context: Context
|
||||
): String {
|
||||
return context.getString(R.string.weight_scale_show_measurement)
|
||||
}
|
||||
|
||||
override fun onClick(
|
||||
device: GBDevice?, context: Context?
|
||||
device: GBDevice, context: Context
|
||||
) {
|
||||
val intent = Intent(context, GenericWeightScaleMeasurementActivity::class.java)
|
||||
intent.putExtra(WeightScaleProfile.EXTRA_ADDRESS, device?.address)
|
||||
context?.startActivity(intent)
|
||||
intent.putExtra(WeightScaleProfile.EXTRA_ADDRESS, device.address)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -256,7 +256,7 @@ abstract class GloryFitCoordinator : AbstractBLEDeviceCoordinator() {
|
||||
return R.drawable.ic_camera_remote
|
||||
}
|
||||
|
||||
override fun getDescription(device: GBDevice, context: Context): String? {
|
||||
override fun getDescription(device: GBDevice, context: Context): String {
|
||||
return context.getString(R.string.open_camera)
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -114,17 +114,18 @@ public class C60DeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
|
||||
DeviceCardAction action = new DeviceCardAction() {
|
||||
@Override
|
||||
public int getIcon(GBDevice device) {
|
||||
public int getIcon(@NonNull GBDevice device) {
|
||||
return R.drawable.ic_camera_remote;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDescription(GBDevice device, Context context) {
|
||||
public String getDescription(@NonNull GBDevice device, @NonNull Context context) {
|
||||
return context.getString(R.string.open_camera);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(GBDevice device, Context context) {
|
||||
public void onClick(@NonNull GBDevice device, @NonNull Context context) {
|
||||
Intent cameraIntent = new Intent(context, CameraActivity.class);
|
||||
cameraIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
cameraIntent.putExtra(
|
||||
|
||||
+4
-3
@@ -78,17 +78,18 @@ public class SuperCarsCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
|
||||
private static final class ControlDeviceCardAction implements DeviceCardAction {
|
||||
@Override
|
||||
public int getIcon(GBDevice device) {
|
||||
public int getIcon(@NonNull GBDevice device) {
|
||||
return R.drawable.ic_steering_wheel;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDescription(final GBDevice device, final Context context) {
|
||||
public String getDescription(@NonNull final GBDevice device, @NonNull final Context context) {
|
||||
return context.getString(R.string.remote_control);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final GBDevice device, final Context context) {
|
||||
public void onClick(@NonNull final GBDevice device, @NonNull final Context context) {
|
||||
final Intent startIntent = new Intent(context, ControlActivity.class);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
context.startActivity(startIntent);
|
||||
|
||||
+4
-3
@@ -95,17 +95,18 @@ public class ThermalPrinterCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
private static final class ControlDeviceCardAction implements DeviceCardAction {
|
||||
|
||||
@Override
|
||||
public int getIcon(GBDevice device) {
|
||||
public int getIcon(@NonNull GBDevice device) {
|
||||
return R.drawable.ic_file_upload;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDescription(final GBDevice device, final Context context) {
|
||||
public String getDescription(@NonNull final GBDevice device, @NonNull final Context context) {
|
||||
return context.getString(R.string.activity_print_image_print_button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final GBDevice device, final Context context) {
|
||||
public void onClick(@NonNull final GBDevice device, @NonNull final Context context) {
|
||||
|
||||
final Intent startIntent = new Intent(context, SendToPrinterActivity.class);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
|
||||
+6
-4
@@ -20,6 +20,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.ultrahuman;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
@@ -57,17 +58,18 @@ public class UltrahumanDeviceCardAction implements DeviceCardAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIcon(GBDevice device) {
|
||||
public int getIcon(@NonNull GBDevice device) {
|
||||
return Icon;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDescription(GBDevice device, Context context) {
|
||||
public String getDescription(@NonNull GBDevice device, @NonNull Context context) {
|
||||
return context.getString(Description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(GBDevice device, Context context) {
|
||||
public void onClick(@NonNull GBDevice device, @NonNull Context context) {
|
||||
if (Question == 0) {
|
||||
sendIntent(device, context);
|
||||
} else {
|
||||
@@ -99,7 +101,7 @@ public class UltrahumanDeviceCardAction implements DeviceCardAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(final GBDevice device) {
|
||||
public boolean isVisible(@NonNull final GBDevice device) {
|
||||
// device.isInitialized() also treats State.SCANNED as initialized but that isn't
|
||||
// appropriate for this device type
|
||||
final GBDevice.State state = device.getState();
|
||||
|
||||
Reference in New Issue
Block a user