-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added try catch blocks in Network requests to prevent timeout issues …
…from crashing the app
- Loading branch information
1 parent
8895a21
commit d26434e
Showing
23 changed files
with
1,232 additions
and
772 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHallListWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.pennapps.labs.pennmobile | ||
|
||
import android.app.PendingIntent | ||
import android.appwidget.AppWidgetManager | ||
import android.appwidget.AppWidgetProvider | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.widget.RemoteViews | ||
import com.google.gson.GsonBuilder | ||
import com.google.gson.reflect.TypeToken | ||
import com.pennapps.labs.pennmobile.adapters.DiningHallWidgetAdapter | ||
import com.pennapps.labs.pennmobile.api.DiningRequest | ||
import com.pennapps.labs.pennmobile.api.Serializer | ||
import com.pennapps.labs.pennmobile.classes.Venue | ||
import com.squareup.okhttp.OkHttpClient | ||
import retrofit.RestAdapter | ||
import retrofit.client.OkClient | ||
import retrofit.converter.GsonConverter | ||
import java.util.concurrent.TimeUnit | ||
|
||
class DiningHallListWidget : AppWidgetProvider() { | ||
override fun onUpdate( | ||
context: Context?, | ||
appWidgetManager: AppWidgetManager?, | ||
appWidgetIds: IntArray? | ||
) { | ||
super.onUpdate(context, appWidgetManager, appWidgetIds) | ||
} | ||
|
||
override fun onEnabled(context: Context?) { | ||
super.onEnabled(context) | ||
} | ||
|
||
override fun onDisabled(context: Context?) { | ||
super.onDisabled(context) | ||
} | ||
|
||
companion object { | ||
private var mDiningRequest : DiningRequest? = null; | ||
val ACTION_AUTO_UPDATE = "AUTO_UPDATE" | ||
|
||
@JvmStatic | ||
val diningRequestInstance : DiningRequest | ||
get() { | ||
if (mDiningRequest == null) { | ||
val gsonBuilder = GsonBuilder() | ||
|
||
gsonBuilder.registerTypeAdapter( | ||
object : TypeToken<MutableList<Venue?>?>() {}.type, | ||
Serializer.VenueSerializer() | ||
) | ||
|
||
val gson = gsonBuilder.create() | ||
val okHttpClient = OkHttpClient() | ||
okHttpClient.setConnectTimeout(35, TimeUnit.SECONDS) | ||
okHttpClient.setReadTimeout(35, TimeUnit.SECONDS) | ||
okHttpClient.setWriteTimeout(35, TimeUnit.SECONDS) | ||
|
||
val restAdapter = | ||
RestAdapter.Builder() | ||
.setConverter(GsonConverter(gson)) | ||
.setClient(OkClient(okHttpClient)) | ||
.setEndpoint("https://pennmobile.org/api") | ||
.build() | ||
mDiningRequest = restAdapter.create(DiningRequest::class.java) | ||
} | ||
return mDiningRequest!! | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.