Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c66f6c4dc |
@@ -11,8 +11,8 @@ android {
|
|||||||
applicationId = "com.expapp.trigger"
|
applicationId = "com.expapp.trigger"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 16
|
versionCode = 17
|
||||||
versionName = "1.2.2"
|
versionName = "1.2.3"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
|
|||||||
@@ -57,22 +57,34 @@ class ServerWidgetProvider : AppWidgetProvider() {
|
|||||||
appWidgetManager: AppWidgetManager,
|
appWidgetManager: AppWidgetManager,
|
||||||
appWidgetIds: IntArray
|
appWidgetIds: IntArray
|
||||||
) {
|
) {
|
||||||
val repository = DeviceRepository(SharedPrefsStorage(context))
|
try {
|
||||||
val devices = repository.getDevices()
|
val repository = DeviceRepository(SharedPrefsStorage(context))
|
||||||
|
val devices = repository.getDevices()
|
||||||
|
|
||||||
for (appWidgetId in appWidgetIds) {
|
for (appWidgetId in appWidgetIds) {
|
||||||
val device = devices.firstOrNull()
|
val device = devices.firstOrNull()
|
||||||
renderWidget(context, appWidgetManager, appWidgetId, device, null)
|
renderWidget(context, appWidgetManager, appWidgetId, device, null)
|
||||||
|
|
||||||
// If device exists, fetch live status asynchronously
|
// If device exists, fetch live status asynchronously
|
||||||
if (device != null && device.statusUrl.isNotBlank()) {
|
if (device != null && device.statusUrl.isNotBlank()) {
|
||||||
executor.execute {
|
executor.execute {
|
||||||
val status = TriggerClient().checkStatusSync(device)
|
try {
|
||||||
mainHandler.post {
|
val status = TriggerClient().checkStatusSync(device)
|
||||||
renderWidget(context, appWidgetManager, appWidgetId, device, status)
|
mainHandler.post {
|
||||||
|
try {
|
||||||
|
renderWidget(context, appWidgetManager, appWidgetId, device, status)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,92 +143,96 @@ class ServerWidgetProvider : AppWidgetProvider() {
|
|||||||
status: NodeStatus?,
|
status: NodeStatus?,
|
||||||
footerOverride: String? = null
|
footerOverride: String? = null
|
||||||
) {
|
) {
|
||||||
val views = RemoteViews(context.packageName, R.layout.widget_server_control)
|
try {
|
||||||
|
val views = RemoteViews(context.packageName, R.layout.widget_server_control)
|
||||||
|
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
views.setTextViewText(R.id.widget_device_name, "No Device")
|
views.setTextViewText(R.id.widget_device_name, "No Device")
|
||||||
views.setTextViewText(R.id.widget_node_name, "Configure in app")
|
views.setTextViewText(R.id.widget_node_name, "Configure in app")
|
||||||
views.setTextViewText(R.id.widget_status_text, "OFFLINE")
|
views.setTextViewText(R.id.widget_status_text, "OFFLINE")
|
||||||
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_gray)
|
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_gray)
|
||||||
views.setTextViewText(R.id.widget_footer_text, "Open app to add server")
|
views.setTextViewText(R.id.widget_footer_text, "Open app to add server")
|
||||||
|
|
||||||
val appIntent = Intent(context, MainActivity::class.java)
|
val appIntent = Intent(context, MainActivity::class.java)
|
||||||
val pendingApp = PendingIntent.getActivity(
|
val pendingApp = PendingIntent.getActivity(
|
||||||
context, 0, appIntent,
|
context, 0, appIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
||||||
|
)
|
||||||
|
views.setOnClickPendingIntent(R.id.widget_header_clickable, pendingApp)
|
||||||
|
views.setOnClickPendingIntent(R.id.widget_root, pendingApp)
|
||||||
|
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
views.setTextViewText(R.id.widget_device_name, device.name)
|
||||||
|
views.setTextViewText(R.id.widget_node_name, device.node)
|
||||||
|
|
||||||
|
// Status display
|
||||||
|
if (status == null) {
|
||||||
|
views.setTextViewText(R.id.widget_status_text, "SYNCING")
|
||||||
|
views.setTextColor(R.id.widget_status_text, 0xFF71717A.toInt())
|
||||||
|
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_gray)
|
||||||
|
} else if (status.isOnline) {
|
||||||
|
views.setTextViewText(R.id.widget_status_text, "ONLINE")
|
||||||
|
views.setTextColor(R.id.widget_status_text, 0xFF22C55E.toInt())
|
||||||
|
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_green)
|
||||||
|
} else {
|
||||||
|
views.setTextViewText(R.id.widget_status_text, "OFFLINE")
|
||||||
|
views.setTextColor(R.id.widget_status_text, 0xFFEF4444.toInt())
|
||||||
|
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_red)
|
||||||
|
}
|
||||||
|
|
||||||
|
views.setTextViewText(
|
||||||
|
R.id.widget_footer_text,
|
||||||
|
footerOverride ?: (if (status?.uptime != null) "Up: ${status.uptime}" else "Tap header to open • Tap button to trigger")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Header click -> Open app
|
||||||
|
val openAppIntent = Intent(context, MainActivity::class.java).apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
}
|
||||||
|
val pendingOpenApp = PendingIntent.getActivity(
|
||||||
|
context,
|
||||||
|
appWidgetId * 10,
|
||||||
|
openAppIntent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
||||||
)
|
)
|
||||||
views.setOnClickPendingIntent(R.id.widget_header_clickable, pendingApp)
|
views.setOnClickPendingIntent(R.id.widget_header_clickable, pendingOpenApp)
|
||||||
views.setOnClickPendingIntent(R.id.widget_root, pendingApp)
|
|
||||||
|
// Refresh click
|
||||||
|
val refreshIntent = Intent(context, ServerWidgetProvider::class.java).apply {
|
||||||
|
action = ACTION_REFRESH
|
||||||
|
}
|
||||||
|
val pendingRefresh = PendingIntent.getBroadcast(
|
||||||
|
context,
|
||||||
|
appWidgetId * 10 + 1,
|
||||||
|
refreshIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
||||||
|
)
|
||||||
|
views.setOnClickPendingIntent(R.id.widget_btn_refresh, pendingRefresh)
|
||||||
|
|
||||||
|
// Power On click
|
||||||
|
views.setOnClickPendingIntent(
|
||||||
|
R.id.widget_btn_power_on,
|
||||||
|
createTriggerPendingIntent(context, appWidgetId * 10 + 2, device.id, TriggerAction.POWER_ON)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reboot click
|
||||||
|
views.setOnClickPendingIntent(
|
||||||
|
R.id.widget_btn_reboot,
|
||||||
|
createTriggerPendingIntent(context, appWidgetId * 10 + 3, device.id, TriggerAction.REBOOT)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Power Off click
|
||||||
|
views.setOnClickPendingIntent(
|
||||||
|
R.id.widget_btn_power_off,
|
||||||
|
createTriggerPendingIntent(context, appWidgetId * 10 + 4, device.id, TriggerAction.POWER_OFF)
|
||||||
|
)
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||||
return
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
views.setTextViewText(R.id.widget_device_name, device.name)
|
|
||||||
views.setTextViewText(R.id.widget_node_name, device.node)
|
|
||||||
|
|
||||||
// Status display
|
|
||||||
if (status == null) {
|
|
||||||
views.setTextViewText(R.id.widget_status_text, "SYNCING")
|
|
||||||
views.setTextColor(R.id.widget_status_text, 0xFF71717A.toInt())
|
|
||||||
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_gray)
|
|
||||||
} else if (status.isOnline) {
|
|
||||||
views.setTextViewText(R.id.widget_status_text, "ONLINE")
|
|
||||||
views.setTextColor(R.id.widget_status_text, 0xFF22C55E.toInt())
|
|
||||||
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_green)
|
|
||||||
} else {
|
|
||||||
views.setTextViewText(R.id.widget_status_text, "OFFLINE")
|
|
||||||
views.setTextColor(R.id.widget_status_text, 0xFFEF4444.toInt())
|
|
||||||
views.setImageViewResource(R.id.widget_status_dot, R.drawable.widget_dot_red)
|
|
||||||
}
|
|
||||||
|
|
||||||
views.setTextViewText(
|
|
||||||
R.id.widget_footer_text,
|
|
||||||
footerOverride ?: (if (status?.uptime != null) "Up: ${status.uptime}" else "Tap header to open • Tap button to trigger")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Header click -> Open app
|
|
||||||
val openAppIntent = Intent(context, MainActivity::class.java).apply {
|
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
||||||
}
|
|
||||||
val pendingOpenApp = PendingIntent.getActivity(
|
|
||||||
context,
|
|
||||||
appWidgetId * 10,
|
|
||||||
openAppIntent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
|
||||||
)
|
|
||||||
views.setOnClickPendingIntent(R.id.widget_header_clickable, pendingOpenApp)
|
|
||||||
|
|
||||||
// Refresh click
|
|
||||||
val refreshIntent = Intent(context, ServerWidgetProvider::class.java).apply {
|
|
||||||
action = ACTION_REFRESH
|
|
||||||
}
|
|
||||||
val pendingRefresh = PendingIntent.getBroadcast(
|
|
||||||
context,
|
|
||||||
appWidgetId * 10 + 1,
|
|
||||||
refreshIntent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
|
||||||
)
|
|
||||||
views.setOnClickPendingIntent(R.id.widget_btn_refresh, pendingRefresh)
|
|
||||||
|
|
||||||
// Power On click
|
|
||||||
views.setOnClickPendingIntent(
|
|
||||||
R.id.widget_btn_power_on,
|
|
||||||
createTriggerPendingIntent(context, appWidgetId * 10 + 2, device.id, TriggerAction.POWER_ON)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reboot click
|
|
||||||
views.setOnClickPendingIntent(
|
|
||||||
R.id.widget_btn_reboot,
|
|
||||||
createTriggerPendingIntent(context, appWidgetId * 10 + 3, device.id, TriggerAction.REBOOT)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Power Off click
|
|
||||||
views.setOnClickPendingIntent(
|
|
||||||
R.id.widget_btn_power_off,
|
|
||||||
createTriggerPendingIntent(context, appWidgetId * 10 + 4, device.id, TriggerAction.POWER_OFF)
|
|
||||||
)
|
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTriggerPendingIntent(
|
private fun createTriggerPendingIntent(
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 324 B |
Binary file not shown.
|
After Width: | Height: | Size: 314 B |
@@ -17,7 +17,7 @@
|
|||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="18dp"
|
android:layout_width="18dp"
|
||||||
android:layout_height="18dp"
|
android:layout_height="18dp"
|
||||||
android:src="@drawable/ic_terminal"
|
android:src="@drawable/widget_ic_terminal"
|
||||||
android:contentDescription="Server" />
|
android:contentDescription="Server" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -82,14 +82,13 @@
|
|||||||
android:id="@+id/widget_btn_refresh"
|
android:id="@+id/widget_btn_refresh"
|
||||||
android:layout_width="26dp"
|
android:layout_width="26dp"
|
||||||
android:layout_height="26dp"
|
android:layout_height="26dp"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
|
||||||
android:contentDescription="Refresh"
|
android:contentDescription="Refresh"
|
||||||
android:padding="3dp"
|
android:padding="3dp"
|
||||||
android:src="@drawable/ic_refresh" />
|
android:src="@drawable/widget_ic_refresh" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Spacer / Divider -->
|
<!-- Spacer / Divider (FrameLayout is explicitly whitelisted in RemoteViews) -->
|
||||||
<View
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:minWidth="250dp"
|
android:minWidth="220dp"
|
||||||
android:minHeight="100dp"
|
android:minHeight="90dp"
|
||||||
|
android:targetCellWidth="3"
|
||||||
|
android:targetCellHeight="2"
|
||||||
|
android:minResizeWidth="180dp"
|
||||||
|
android:minResizeHeight="70dp"
|
||||||
android:updatePeriodMillis="1800000"
|
android:updatePeriodMillis="1800000"
|
||||||
android:initialLayout="@layout/widget_server_control"
|
android:initialLayout="@layout/widget_server_control"
|
||||||
android:resizeMode="horizontal|vertical"
|
android:resizeMode="horizontal|vertical"
|
||||||
|
|||||||
Reference in New Issue
Block a user