@@ -0,0 +1,2857 @@
+package com.example.profbola.bakingtime.ui.widget;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.database.Cursor;%0Aimport android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0Aimport android.view.LayoutInflater;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0Aimport android.widget.ArrayAdapter;%0Aimport android.widget.RemoteViews;%0Aimport android.widget.RemoteViewsService;%0Aimport android.widget.TextView;%0A%0Aimport com.example.profbola.bakingtime.R;%0Aimport com.example.profbola.bakingtime.models.Ingredient;%0Aimport com.example.profbola.bakingtime.provider.RecipeContract;%0A%0A%0A/**%0A * Created by prof.BOLA on 7/9/2017.%0A */%0A%0Apublic class IngredientWidgetService extends RemoteViewsService%7B%0A%0A    @Override public RemoteViewsFactory onGetViewFactory(Intent intent) %7B%0A%0A        int recipeId = intent.getIntExtra(RecipesWidgetProvider.RECIPE_ID, 1);%0A        return new IngredientAdapterFactory(this.getApplicationContext(), recipeId);%0A%0A    %7D%0A%7D%0A%0Aclass IngredientAdapterFactory implements RemoteViewsService.RemoteViewsFactory %7B%0A%0A    private Context mContext;private int mRecipeId;private Cursor mIngredients;%0A%0A    protected IngredientAdapterFactory(Context context, int recipeId) %7B%0A%0A        mContext = context;%0A%0A        mRecipeId = recipeId;%0A%0A    %7D%0A    @Override%0A    public RemoteViews getViewAt(int position) %7B%0A%0A        if (mIngredients == null %7C%7C mIngredients.getCount() == 0) return null;%0A%0A        RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.ingredient);%0A%0A        mIngredients.moveToPosition(position);%0A        Ingredient ingredient = new Ingredient(mIngredients);%0A        views.setTextViewText(R.id.ingredient_name, ingredient.ingredient);%0A        views.setTextViewText(R.id.measure, ingredient.measure);%0A        views.setTextViewText(R.id.quantity, String.valueOf(ingredient.quantity));%0A%0A        return views;%0A    %7D%0A%0A    @Override public void onCreate() %7B%0A%0A    %7D%0A    @Override%0A    public void onDataSetChanged() %7B%0A%0A        if (mIngredients != null) mIngredients.close();%0A%0A        mIngredients = mContext.getContentResolver().query(%0A                RecipeContract.IngredientEntry.CONTENT_URI(mRecipeId),%0A                null,%0A                null,%0A                null,%0A                null%0A        );%0A%0A    %7D%0A%0A    @Override%0A    public void onDestroy() %7B%0A%0A        if (mIngredients != null) mIngredients.close();%0A%0A    %7D%0A%0A    @Override%0A    public int getCount() %7B%0A%0A        if (mIngredients == null) return 0;%0A        return mIngredients.getCount();%0A%0A    %7D%0A%0A    @Override%0A    public RemoteViews getLoadingView() %7B%0A        return null;%0A    %7D%0A%0A    @Override%0A    public int getViewTypeCount() %7B%0A        return 1;%0A    %7D%0A%0A    @Override%0A    public long getItemId(int position) %7B%0A        return 1;%0A    %7D%0A%0A    @Override%0A    public boolean hasStableIds() %7B%0A        return true;%0A    %7D%0A%7D

Add Widget RemoteViews Factory, Service for Ingredients Listing