diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationWidget.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationWidget.kt index e53555b3..09fc9580 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationWidget.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationWidget.kt @@ -52,8 +52,10 @@ class GsrReservationWidget : AppWidgetProvider() { // Setting up the widget remoteViews; change cardview to something else val views = RemoteViews(context.packageName, R.layout.gsr_reservation_widget) views.setRemoteAdapter(R.id.gsr_reservation_widget_stack_view, serviceIntent) - views.setEmptyView(R.id.gsr_reservation_widget_stack_view, - R.id.gsr_reservation_widget_empty_view) + views.setEmptyView( + R.id.gsr_reservation_widget_stack_view, + R.id.gsr_reservation_widget_empty_view, + ) // Setting up the intents for the remoteview for both when it is empty and // when it loads the collection view (in this case we use setPendingIntentTemplate to @@ -63,8 +65,10 @@ class GsrReservationWidget : AppWidgetProvider() { // Notify appwidgetviewdata has changed to call getViewAt to set up the widget UI // and handle update for every appwidget item in the Collection widget. - appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, - R.id.gsr_reservation_widget_stack_view) + appWidgetManager.notifyAppWidgetViewDataChanged( + appWidgetId, + R.id.gsr_reservation_widget_stack_view, + ) appWidgetManager.updateAppWidget(appWidgetId, views) } } @@ -111,4 +115,4 @@ class GsrReservationWidget : AppWidgetProvider() { return mGSRReservationsRequest!! } } -} \ No newline at end of file +} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationWidgetAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationWidgetAdapter.kt index 0e8d04ef..8d2e2039 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationWidgetAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationWidgetAdapter.kt @@ -19,15 +19,12 @@ import rx.Observable import java.net.HttpURLConnection import java.net.URL - class GsrReservationWidgetAdapter : RemoteViewsService() { - override fun onGetViewFactory(intent: Intent): RemoteViewsFactory { - return GsrReservationWidgetFactory(applicationContext, intent) - } + override fun onGetViewFactory(intent: Intent): RemoteViewsFactory = GsrReservationWidgetFactory(applicationContext, intent) class GsrReservationWidgetFactory( private val context: Context, - intent: Intent + intent: Intent, ) : RemoteViewsFactory { private var mGsrReservationsRequest: GsrReservationsRequest? = null private var appWidgetId: Int = @@ -45,16 +42,12 @@ class GsrReservationWidgetAdapter : RemoteViewsService() { // Not used since already handled override fun onDataSetChanged() { - } override fun onDestroy() { - } - override fun getCount(): Int { - return dataSet.size - } + override fun getCount(): Int = dataSet.size // TODO("Get building name(?), and hopefully support click behavior") override fun getViewAt(index: Int): RemoteViews { @@ -69,18 +62,22 @@ class GsrReservationWidgetAdapter : RemoteViewsService() { val fromHour = from.toString("h:mm a") val toHour = to.toString("h:mm a") - val imageUrl = reservation.info?.get("thumbnail") ?: - "https://s3.us-east-2.amazonaws.com/labs.api/dining/MBA+Cafe.jpg" + val imageUrl = + reservation.info?.get("thumbnail") + ?: "https://s3.us-east-2.amazonaws.com/labs.api/dining/MBA+Cafe.jpg" val views = RemoteViews(context.packageName, R.layout.gsr_reservation_widget_item) views.setTextViewText(R.id.gsr_reservation_widget_item_location_tv, roomName) views.setTextViewText( - R.id.gsr_reservation_widget_item_time_tv, "$day\n$fromHour-$toHour") + R.id.gsr_reservation_widget_item_time_tv, + "$day\n$fromHour-$toHour", + ) try { val urlConnection = URL(imageUrl) - val connection = urlConnection - .openConnection() as HttpURLConnection + val connection = + urlConnection + .openConnection() as HttpURLConnection connection.doInput = true connection.connect() val input = connection.inputStream @@ -98,27 +95,22 @@ class GsrReservationWidgetAdapter : RemoteViewsService() { return views } - override fun getLoadingView(): RemoteViews? { - return null - } + override fun getLoadingView(): RemoteViews? = null - override fun getViewTypeCount(): Int { - return 1 - } + override fun getViewTypeCount(): Int = 1 - override fun getItemId(id: Int): Long { - return id.toLong() - } + override fun getItemId(id: Int): Long = id.toLong() - override fun hasStableIds(): Boolean { - return true - } + override fun hasStableIds(): Boolean = true private fun getWidgetGsrReservations() { try { if (mGsrReservationsRequest != null) { - val token = sharedPreferences.getString( - context.getString(R.string.access_token), "") + val token = + sharedPreferences.getString( + context.getString(R.string.access_token), + "", + ) mGsrReservationsRequest!! .getGsrReservations("Bearer $token") .flatMap { reservations -> Observable.from(reservations) } @@ -130,8 +122,10 @@ class GsrReservationWidgetAdapter : RemoteViewsService() { println("subscribed") val appWidgetManager: AppWidgetManager = AppWidgetManager.getInstance(context) - appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, - R.id.gsr_reservation_widget_stack_view) + appWidgetManager.notifyAppWidgetViewDataChanged( + appWidgetId, + R.id.gsr_reservation_widget_stack_view, + ) } } } catch (e: Exception) { @@ -140,4 +134,4 @@ class GsrReservationWidgetAdapter : RemoteViewsService() { } } } -} \ No newline at end of file +}