|
@@ -11,6 +11,7 @@ import android.util.Log
|
|
|
import android.view.View
|
|
|
import android.widget.RemoteViews
|
|
|
import com.android.volley.Request
|
|
|
+import com.android.volley.Response
|
|
|
import com.android.volley.toolbox.StringRequest
|
|
|
import com.android.volley.toolbox.Volley
|
|
|
import kotlin.concurrent.thread
|
|
@@ -19,6 +20,7 @@ import kotlin.concurrent.thread
|
|
|
class UpdateWidgetService : Service() {
|
|
|
|
|
|
override fun onStart(intent: Intent, startId: Int) {
|
|
|
+
|
|
|
val appWidgetManager = AppWidgetManager.getInstance(this.applicationContext)
|
|
|
val allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)
|
|
|
|
|
@@ -30,23 +32,25 @@ class UpdateWidgetService : Service() {
|
|
|
val remoteViews = RemoteViews(this.applicationContext.packageName, R.layout.home_temp_app_widget )
|
|
|
|
|
|
val queue = Volley.newRequestQueue(this)
|
|
|
- val url = "http://www.flacksta.com/info/curr_temp.php"
|
|
|
+ val url = "http://chef.sundby.com/info/curr_temp.php"
|
|
|
|
|
|
Thread.sleep(1000)
|
|
|
|
|
|
// Request a string response from the provided URL.
|
|
|
+ Log.i("SERVICE","Making a request...")
|
|
|
val stringRequest = StringRequest(
|
|
|
- Request.Method.GET, url,
|
|
|
- { response ->
|
|
|
+ Request.Method.GET,
|
|
|
+ url,
|
|
|
+ Response.Listener<String> { response ->
|
|
|
Log.i("SERVICE", "Response is: $response")
|
|
|
for (widgetId in allWidgetIds) {
|
|
|
- remoteViews.setTextViewText(R.id.appwidget_text,"$response \u2103")
|
|
|
+ remoteViews.setTextViewText(R.id.appwidget_text,"$response")
|
|
|
remoteViews.setTextColor(R.id.appwidget_text, Color.BLACK)
|
|
|
remoteViews.setViewVisibility(R.id.progressBar, View.INVISIBLE)
|
|
|
appWidgetManager.updateAppWidget(widgetId, remoteViews)
|
|
|
}
|
|
|
},
|
|
|
- {
|
|
|
+ Response.ErrorListener {
|
|
|
Log.i("SERVICE", "That didn't work!" )
|
|
|
for (widgetId in allWidgetIds) {
|
|
|
remoteViews.setTextViewText(R.id.appwidget_text,"Error")
|