Skip to content

Commit

Permalink
Ktlint files
Browse files Browse the repository at this point in the history
  • Loading branch information
Divak2004 committed Oct 20, 2024
1 parent 6b1fe8e commit 967a53d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -111,4 +115,4 @@ class GsrReservationWidget : AppWidgetProvider() {
return mGSRReservationsRequest!!
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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) }
Expand All @@ -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) {
Expand All @@ -140,4 +134,4 @@ class GsrReservationWidgetAdapter : RemoteViewsService() {
}
}
}
}
}

0 comments on commit 967a53d

Please sign in to comment.