Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÁlvaro Brey <alvaro.brey@nextcloud.com>2022-10-25 09:56:26 +0300
committerÁlvaro Brey <alvaro.brey@nextcloud.com>2022-10-25 09:56:26 +0300
commit37c22ab16a591a3f6e2ab18ca353be1451bf6b2e (patch)
tree9ccc838c4ada1c30d2136700641119861d7de7cc
parent93e6f5cb3b42783a6600a423bc5fd9893f7d05a5 (diff)
DashboardWidgetService: Prevent crash when user is not present
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
-rw-r--r--app/src/main/java/com/nextcloud/client/widget/DashboardWidgetService.kt29
1 files changed, 17 insertions, 12 deletions
diff --git a/app/src/main/java/com/nextcloud/client/widget/DashboardWidgetService.kt b/app/src/main/java/com/nextcloud/client/widget/DashboardWidgetService.kt
index aed8a70fff..01e7b1106a 100644
--- a/app/src/main/java/com/nextcloud/client/widget/DashboardWidgetService.kt
+++ b/app/src/main/java/com/nextcloud/client/widget/DashboardWidgetService.kt
@@ -94,7 +94,7 @@ class StackRemoteViewsFactory(
private var hasLoadMore = false
override fun onCreate() {
- Log_OC.d(this, "onCreate")
+ Log_OC.d(TAG, "onCreate")
val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
widgetConfiguration = widgetRepository.getWidget(appWidgetId)
@@ -110,23 +110,27 @@ class StackRemoteViewsFactory(
override fun onDataSetChanged() {
CoroutineScope(Dispatchers.IO).launch {
try {
- val client = clientFactory.createNextcloudClient(widgetConfiguration.user.get())
- val result =
- DashboardGetWidgetItemsRemoteOperation(widgetConfiguration.widgetId, LIMIT_SIZE).execute(client)
- widgetItems = result.resultData[widgetConfiguration.widgetId] ?: emptyList()
-
- hasLoadMore = widgetConfiguration.moreButton != null &&
- widgetItems.size == LIMIT_SIZE
+ if (widgetConfiguration.user.isPresent) {
+ val client = clientFactory.createNextcloudClient(widgetConfiguration.user.get())
+ val result =
+ DashboardGetWidgetItemsRemoteOperation(widgetConfiguration.widgetId, LIMIT_SIZE).execute(client)
+ widgetItems = result.resultData[widgetConfiguration.widgetId] ?: emptyList()
+
+ hasLoadMore = widgetConfiguration.moreButton != null &&
+ widgetItems.size == LIMIT_SIZE
+ } else {
+ Log_OC.w(TAG, "User not present for widget update")
+ }
} catch (e: ClientFactory.CreationException) {
- Log_OC.e(this, "Error updating widget", e)
+ Log_OC.e(TAG, "Error updating widget", e)
}
}
- Log_OC.d("WidgetService", "onDataSetChanged")
+ Log_OC.d(TAG, "onDataSetChanged")
}
override fun onDestroy() {
- Log_OC.d("WidgetService", "onDestroy")
+ Log_OC.d(TAG, "onDestroy")
widgetItems = emptyList()
}
@@ -195,7 +199,7 @@ class StackRemoteViewsFactory(
setImageViewBitmap(R.id.icon, glide.get())
}
} catch (e: Exception) {
- Log_OC.d(this, "Error setting icon", e)
+ Log_OC.d(TAG, "Error setting icon", e)
setImageViewResource(R.id.icon, R.drawable.ic_dashboard)
}
}
@@ -238,6 +242,7 @@ class StackRemoteViewsFactory(
}
companion object {
+ private val TAG = DashboardWidgetService::class.simpleName
const val LIMIT_SIZE = 14
}
}