Created
July 15, 2024 12:05
-
-
Save Ayush783/6e17dc0adb35c3b772f336d1caac2e93 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ListViewRemoteViewsFactory(private val context: Context, private val intent: Intent?) : RemoteViewsService.RemoteViewsFactory{ | |
private var articleImages: List<Bitmap?> = ArrayList() | |
... | |
private inner class LoadImagesTask : AsyncTask<List<NewsArticle>, Void, List<Bitmap?>>() { | |
override fun doInBackground(vararg params: List<NewsArticle>): List<Bitmap?> { | |
return params[0].map { article -> | |
try { | |
Glide.with(context) | |
.asBitmap() | |
.load(article.urlToImage) | |
.submit(65, 65) | |
.get() | |
} catch (e: Exception) { | |
e.printStackTrace() | |
Glide.with(context) | |
.asBitmap() | |
.load(R.drawable.ic_launcher) | |
.submit(65, 65) | |
.get() | |
null | |
} | |
} | |
} | |
override fun onPostExecute(result: List<Bitmap?>) { | |
articleImages = result | |
val appWidgetManager = AppWidgetManager.getInstance(context) | |
val componentName = ComponentName(context, ListViewAppWidgetProvider::class.java) | |
val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName) | |
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listview_app_widget) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment