Wear: tile add no phone data message
This commit is contained in:
parent
6ff314a9cb
commit
ee27b07377
3 changed files with 36 additions and 8 deletions
|
@ -18,6 +18,7 @@ import android.util.Log;
|
|||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.wear.tiles.TileService;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.api.GoogleApiClient;
|
||||
|
@ -46,6 +47,8 @@ import info.nightscout.androidaps.interaction.AAPSPreferences;
|
|||
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.CPPActivity;
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence;
|
||||
import info.nightscout.androidaps.tile.ActionsTileService;
|
||||
import info.nightscout.androidaps.tile.TempTargetTileService;
|
||||
import info.nightscout.shared.SafeParse;
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||
|
||||
|
@ -547,6 +550,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean("wearcontrol", wearcontrol);
|
||||
editor.apply();
|
||||
updateTiles();
|
||||
}
|
||||
} else if (path.equals(NEW_CHANGECONFIRMATIONREQUEST_PATH)) {
|
||||
String title = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("title");
|
||||
|
@ -568,6 +572,16 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
}
|
||||
}
|
||||
|
||||
private void updateTiles() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
TileService.getUpdater(this)
|
||||
.requestUpdate(ActionsTileService.class);
|
||||
|
||||
TileService.getUpdater(this)
|
||||
.requestUpdate(TempTargetTileService.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyChangeRequest(String title, String message, String actionstring) {
|
||||
// Create the NotificationChannel, but only on API 26+ because
|
||||
// the NotificationChannel class is new and not in the support library
|
||||
|
|
|
@ -47,7 +47,6 @@ private const val BUTTON_COLOR = R.color.gray_850
|
|||
const val TAG = "ASTAG-tile"
|
||||
|
||||
interface TileSource {
|
||||
|
||||
fun getActions(): List<Action>
|
||||
fun getDefaultConfig(): Map<String, String>
|
||||
}
|
||||
|
@ -62,6 +61,11 @@ data class Action(
|
|||
val actionString: String? = null,
|
||||
)
|
||||
|
||||
enum class WearControl {
|
||||
NO_DATA, ENABLED, DISABLED
|
||||
}
|
||||
|
||||
|
||||
abstract class TileBase : TileService() {
|
||||
|
||||
open val resourceVersion = "1"
|
||||
|
@ -78,14 +82,14 @@ abstract class TileBase : TileService() {
|
|||
): ListenableFuture<Tile> = serviceScope.future {
|
||||
Log.i(TAG, "onTileRequest: ")
|
||||
val actionsSelected = getSelectedActions()
|
||||
val wearControlEnabled = hasWearControl()
|
||||
val wearControl = getWearControl()
|
||||
|
||||
Tile.Builder()
|
||||
.setResourcesVersion(resourceVersion)
|
||||
.setTimeline(
|
||||
Timeline.Builder().addTimelineEntry(
|
||||
TimelineEntry.Builder().setLayout(
|
||||
Layout.Builder().setRoot(layout(wearControlEnabled, actionsSelected, requestParams.deviceParameters!!)).build()
|
||||
Layout.Builder().setRoot(layout(wearControl, actionsSelected, requestParams.deviceParameters!!)).build()
|
||||
).build()
|
||||
).build()
|
||||
)
|
||||
|
@ -115,11 +119,15 @@ abstract class TileBase : TileService() {
|
|||
.build()
|
||||
}
|
||||
|
||||
private fun layout(enabled: Boolean, actions: List<Action>, deviceParameters: DeviceParameters): LayoutElement {
|
||||
if (!enabled) {
|
||||
private fun layout(wearControl: WearControl, actions: List<Action>, deviceParameters: DeviceParameters): LayoutElement {
|
||||
if (wearControl == WearControl.DISABLED) {
|
||||
return Text.Builder()
|
||||
.setText(resources.getString(R.string.wear_control_not_enabled))
|
||||
.build()
|
||||
} else if (wearControl == WearControl.NO_DATA) {
|
||||
return Text.Builder()
|
||||
.setText(resources.getString(R.string.wear_control_no_data))
|
||||
.build()
|
||||
}
|
||||
if (actions.isNotEmpty()) {
|
||||
val b = Column.Builder()
|
||||
|
@ -222,9 +230,14 @@ abstract class TileBase : TileService() {
|
|||
)
|
||||
.build()
|
||||
|
||||
private fun hasWearControl(): Boolean {
|
||||
private fun getWearControl(): WearControl {
|
||||
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
return sharedPrefs.getBoolean("wearcontrol", false)
|
||||
if (!sharedPrefs.contains("wearcontrol")) return WearControl.NO_DATA;
|
||||
val wearControlPref = sharedPrefs.getBoolean("wearcontrol", false)
|
||||
if (wearControlPref) {
|
||||
return WearControl.ENABLED
|
||||
}
|
||||
return WearControl.DISABLED
|
||||
}
|
||||
|
||||
private fun getSelectedActions(): List<Action> {
|
||||
|
|
|
@ -177,6 +177,7 @@
|
|||
<string name="temp_target_cancel">Cancel</string>
|
||||
<string name="tile_none">None</string>
|
||||
<string name="tile_no_config">No config available</string>
|
||||
<string name="wear_control_not_enabled">Wear control disabled</string>
|
||||
<string name="wear_control_not_enabled">Wear controls disabled</string>
|
||||
<string name="wear_control_no_data">No data available</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue