Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. package com.informatika.umm.myapplication.widget;
  2.  
  3. import android.appwidget.AppWidgetManager;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.database.Cursor;
  7. import android.graphics.Bitmap;
  8. import android.os.Bundle;
  9. import android.widget.RemoteViews;
  10. import android.widget.RemoteViewsService;
  11.  
  12. import com.bumptech.glide.Glide;
  13. import com.informatika.umm.myapplication.BuildConfig;
  14. import com.informatika.umm.myapplication.R;
  15. import com.informatika.umm.myapplication.database.FavoriteHelper;
  16. import com.informatika.umm.myapplication.model.Movie;
  17.  
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.concurrent.ExecutionException;
  21.  
  22. /**
  23. * MADE_Submission_2
  24. * created by : Robin Nusantara on 1/26/2020 01 2020
  25. * 01:06 Sun
  26. **/
  27. public class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
  28.  
  29. private final Context context;
  30. private int id;
  31. private FavoriteHelper helper;
  32. private List<Movie> movieList = new ArrayList<>();
  33. private Cursor cursor;
  34.  
  35. StackRemoteViewsFactory(Context context, Intent intent) {
  36. id = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
  37. this.context = context;
  38. }
  39.  
  40.  
  41. @Override
  42. public void onCreate() {
  43. helper = FavoriteHelper.getInstance(context);
  44. }
  45.  
  46. @Override
  47. public void onDataSetChanged() {
  48. movieList.addAll(helper.queryAllMovie());
  49. }
  50.  
  51. @Override
  52. public void onDestroy() {
  53.  
  54. }
  55.  
  56. @Override
  57. public int getCount() {
  58. return movieList.size();
  59. }
  60.  
  61. @Override
  62. public RemoteViews getViewAt(int position) {
  63. RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.image_banner_widget);
  64. if (!movieList.isEmpty()) {
  65. Movie movie = movieList.get(position);
  66. try {
  67. Bitmap bitmap = Glide.with(context)
  68. .asBitmap()
  69. .load(BuildConfig.IMAGE_URL + movie.getMoviePoster())
  70. .centerCrop()
  71. .submit()
  72. .get();
  73. remoteViews.setImageViewBitmap(R.id.imageView, bitmap);
  74. } catch (ExecutionException | InterruptedException e) {
  75. e.printStackTrace();
  76. }
  77.  
  78. Bundle extras = new Bundle();
  79. extras.putInt(ImageBannerWidget.EXTRA_ITEM, position);
  80.  
  81. Intent intent = new Intent();
  82. intent.putExtras(extras);
  83. remoteViews.setOnClickFillInIntent(R.id.containerView, intent);
  84.  
  85. }
  86. return remoteViews;
  87. }
  88.  
  89. @Override
  90. public RemoteViews getLoadingView() {
  91. return null;
  92. }
  93.  
  94. @Override
  95. public int getViewTypeCount() {
  96. return 1;
  97. }
  98.  
  99. @Override
  100. public long getItemId(int i) {
  101. return 0;
  102. }
  103.  
  104. @Override
  105. public boolean hasStableIds() {
  106. return false;
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement