Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.informatika.umm.myapplication.widget;
- import android.appwidget.AppWidgetManager;
- import android.content.Context;
- import android.content.Intent;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- import android.os.Bundle;
- import android.widget.RemoteViews;
- import android.widget.RemoteViewsService;
- import com.bumptech.glide.Glide;
- import com.informatika.umm.myapplication.BuildConfig;
- import com.informatika.umm.myapplication.R;
- import com.informatika.umm.myapplication.database.FavoriteHelper;
- import com.informatika.umm.myapplication.model.Movie;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.ExecutionException;
- /**
- * MADE_Submission_2
- * created by : Robin Nusantara on 1/26/2020 01 2020
- * 01:06 Sun
- **/
- public class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
- private final Context context;
- private int id;
- private FavoriteHelper helper;
- private List<Movie> movieList = new ArrayList<>();
- private Cursor cursor;
- StackRemoteViewsFactory(Context context, Intent intent) {
- id = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
- this.context = context;
- }
- @Override
- public void onCreate() {
- helper = FavoriteHelper.getInstance(context);
- }
- @Override
- public void onDataSetChanged() {
- movieList.addAll(helper.queryAllMovie());
- }
- @Override
- public void onDestroy() {
- }
- @Override
- public int getCount() {
- return movieList.size();
- }
- @Override
- public RemoteViews getViewAt(int position) {
- RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.image_banner_widget);
- if (!movieList.isEmpty()) {
- Movie movie = movieList.get(position);
- try {
- Bitmap bitmap = Glide.with(context)
- .asBitmap()
- .load(BuildConfig.IMAGE_URL + movie.getMoviePoster())
- .centerCrop()
- .submit()
- .get();
- remoteViews.setImageViewBitmap(R.id.imageView, bitmap);
- } catch (ExecutionException | InterruptedException e) {
- e.printStackTrace();
- }
- Bundle extras = new Bundle();
- extras.putInt(ImageBannerWidget.EXTRA_ITEM, position);
- Intent intent = new Intent();
- intent.putExtras(extras);
- remoteViews.setOnClickFillInIntent(R.id.containerView, intent);
- }
- return remoteViews;
- }
- @Override
- public RemoteViews getLoadingView() {
- return null;
- }
- @Override
- public int getViewTypeCount() {
- return 1;
- }
- @Override
- public long getItemId(int i) {
- return 0;
- }
- @Override
- public boolean hasStableIds() {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement