package de.fau.cs.mad.fablab.android.widget;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

import java.lang.annotation.Annotation;

import javax.inject.Inject;

import de.fau.cs.mad.fablab.android.R;
import de.fau.cs.mad.fablab.android.model.SpaceApiModel;
import de.fau.cs.mad.fablab.android.util.Formatter;
import de.fau.cs.mad.fablab.android.view.actionbar.ActionBarViewModel;
import de.fau.cs.mad.fablab.android.view.activities.MainActivity;




public class WidgetProvider extends AppWidgetProvider
{
//    @Inject
//    ActionBarViewModel mViewModel;
//
//    @Inject
//    SpaceApiModel mSpaceApiModel;

    boolean isOpen;
    String widgetTime;
    final String SET_TIME = "set_time";

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
    {
        super.onUpdate(context, appWidgetManager, appWidgetIds);

        //isOpen = mSpaceApiModel.getOpen();
        //widgetTime = Formatter.formatTime(mSpaceApiModel.getTime());

//        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
//        ComponentName widgetComponent = new ComponentName(context, WidgetProvider.class);
//
//        remoteViews.setTextViewText(R.id.widget_tv, widgetTime);
//        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);


    }

    @Override
    public void onReceive(Context context, Intent intent)
    {
        super.onReceive(context, intent);

        if(intent.getAction().toString() == SET_TIME)
        {

        }
    }

    public void updateWidgetNow(Context context, RemoteViews remoteViews)
    {
        ComponentName widgetComponent = new ComponentName(context, WidgetProvider.class);
        AppWidgetManager.getInstance(context).updateAppWidget(widgetComponent, remoteViews);
    }

    public PendingIntent onClickPendingIntent(Context context, String stringAction)
    {
        Intent onClickIntent = new Intent(context, WidgetProvider.class);
        onClickIntent.setAction(stringAction);

        return PendingIntent.getBroadcast(context, 0, onClickIntent, 0);
    }


}

@@ -817,16 +817,18 @@
 Model;%0A%0A
+//
     bool
@@ -839,16 +839,18 @@
 isOpen;%0A
+//
     Stri
@@ -864,16 +864,18 @@
 etTime;%0A
+//
     fina
@@ -1677,650 +1677,16 @@
 );%0A%0A
-        if(intent.getAction().toString() == SET_TIME)%0A        %7B%0A%0A        %7D%0A    %7D%0A%0A    public void updateWidgetNow(Context context, RemoteViews remoteViews)%0A    %7B%0A        ComponentName widgetComponent = new ComponentName(context, WidgetProvider.class);%0A        AppWidgetManager.getInstance(context).updateAppWidget(widgetComponent, remoteViews);%0A    %7D%0A%0A    public PendingIntent onClickPendingIntent(Context context, String stringAction)%0A    %7B%0A        Intent onClickIntent = new Intent(context, WidgetProvider.class);%0A        onClickIntent.setAction(stringAction);%0A%0A        return PendingIntent.getBroadcast(context, 0, onClickIntent, 0);
 %0A    %7D
+%0A%0A
 %0A%0A%0A%7D

add manifest and layout files for widget