Skip to content

Instantly share code, notes, and snippets.

@Ayush783
Created July 15, 2024 12:05
Show Gist options
  • Save Ayush783/6e17dc0adb35c3b772f336d1caac2e93 to your computer and use it in GitHub Desktop.
Save Ayush783/6e17dc0adb35c3b772f336d1caac2e93 to your computer and use it in GitHub Desktop.
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