<commit_before>package de.htwdd.htwdresden;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.RemoteViews;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.nio.charset.Charset;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;

import de.htwdd.htwdresden.classes.Const;
import de.htwdd.htwdresden.classes.MensaHelper;
import de.htwdd.htwdresden.classes.VolleyDownloader;
import de.htwdd.htwdresden.types.Meal;
import io.realm.Realm;
import io.realm.RealmResults;

/**
 * Mensa-Widget Provider
 *
 * @author <NAME>
 */
public class MensaWidget extends AppWidgetProvider {
    private static final String[] nameOfDays = DateFormatSymbols.getInstance().getWeekdays();

    static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
        // Construct the RemoteViews object
        final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
        final int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
        final RemoteViews views = getRemoteViews(context, minHeight);
        final Calendar calendar = GregorianCalendar.getInstance();

        // Erstelle Intent zum Starten der App
        final Intent intent = new Intent(context, MainActivity.class);
        intent.setAction(Const.IntentParams.START_ACTION_MENSA);
        final PendingIntent pendingIntent = PendingIntent.getActivity(context, PendingIntent.FLAG_UPDATE_CURRENT, intent, 0);
        views.setOnClickPendingIntent(R.id.mensa_widget_layout, pendingIntent);

        // Bestimme Tag, welcher angezeigt werden soll
        views.setTextViewText(R.id.widget_mensa_date, context.getString(R.string.mensa_date, context.getString(R.string.mensa_date_today)));

        if (calendar.get(Calendar.HOUR_OF_DAY) > 15) {
            calendar.add(Calendar.DAY_OF_YEAR, 1);
            views.setTextViewText(R.id.widget_mensa_date, context.getString(R.string.mensa_date, nameOfDays[calendar.get(Calendar.DAY_OF_WEEK)]));
        }
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            // Ersten Tag in der Woche berechnen
            calendar.add(Calendar.WEEK_OF_YEAR, 1);
            calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
            views.setTextViewText(R.id.widget_mensa_date, context.getString(R.string.mensa_date, nameOfDays[2]));
        }

        // Lade Daten aus der Datenbank
        final Realm realm = Realm.getDefaultInstance();
        final RealmResults<Meal> meals = realm.where(Meal.class)
                .equalTo("date", MensaHelper.getDate(calendar))
                .notEqualTo("title", ".*kombinierBAR:.*").or()
                .notEqualTo("price", "ausverkauft").or()
                .isNotNull("price").findAll();

        // Anzeigen der Gerichte
        final Resources ressource = context.getResources();
        final String packageName = context.getPackageName();
        final int cells = minHeight <= 65 ? 4 : 8;

        for (int i = 1; i < cells + 1; i++) {
            final int mealName = ressource.getIdentifier("widget_mensa_item_meal_" + i, "id", packageName);
            final int mealPrice = ressource.getIdentifier("widget_mensa_item_price_" + i, "id", packageName);

            if (meals.size() < i) {
                views.setTextViewText(mealName, null);
                views.setTextViewText(mealPrice, null);
                continue;
            }

            final Meal meal = meals.get(i - 1);
            views.setTextViewText(mealName, meal.getTitle());
            views.setTextViewText(mealPrice, context.getString(R.string.mensa_price, meal.getPrice()));
        }

        if (meals.size() != 0)
            views.setTextViewText(R.id.info_message, null);
        else views.setTextViewText(R.id.info_message, ressource.getText(R.string.mensa_no_offer));

        // Instruct the widget manager to update the widget<commit_msg>Fix: falsche Mensa Abfrage in Widget<commit_after>package de.htwdd.htwdresden;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.RemoteViews;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.nio.charset.Charset;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;

import de.htwdd.htwdresden.classes.Const;
import de.htwdd.htwdresden.classes.MensaHelper;
import de.htwdd.htwdresden.classes.VolleyDownloader;
import de.htwdd.htwdresden.types.Meal;
import io.realm.Realm;
import io.realm.RealmResults;

/**
 * Mensa-Widget Provider
 *
 * @author <NAME>
 */
public class MensaWidget extends AppWidgetProvider {
    private static final String[] nameOfDays = DateFormatSymbols.getInstance().getWeekdays();

    static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
        // Construct the RemoteViews object
        final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
        final int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
        final RemoteViews views = getRemoteViews(context, minHeight);
        final Calendar calendar = GregorianCalendar.getInstance();

        // Erstelle Intent zum Starten der App
        final Intent intent = new Intent(context, MainActivity.class);
        intent.setAction(Const.IntentParams.START_ACTION_MENSA);
        final PendingIntent pendingIntent = PendingIntent.getActivity(context, PendingIntent.FLAG_UPDATE_CURRENT, intent, 0);
        views.setOnClickPendingIntent(R.id.mensa_widget_layout, pendingIntent);

        // Bestimme Tag, welcher angezeigt werden soll
        views.setTextViewText(R.id.widget_mensa_date, context.getString(R.string.mensa_date, context.getString(R.string.mensa_date_today)));

        if (calendar.get(Calendar.HOUR_OF_DAY) > 15) {
            calendar.add(Calendar.DAY_OF_YEAR, 1);
            views.setTextViewText(R.id.widget_mensa_date, context.getString(R.string.mensa_date, nameOfDays[calendar.get(Calendar.DAY_OF_WEEK)]));
        }
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            // Ersten Tag in der Woche berechnen
            calendar.add(Calendar.WEEK_OF_YEAR, 1);
            calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
            views.setTextViewText(R.id.widget_mensa_date, context.getString(R.string.mensa_date, nameOfDays[2]));
        }

        // Lade Daten aus der Datenbank
        final Realm realm = Realm.getDefaultInstance();
        final RealmResults<Meal> meals = realm.where(Meal.class)
                .equalTo("date", MensaHelper.getDate(calendar))
                .notEqualTo("title", ".*kombinierBAR:.*")
                .notEqualTo("price", "ausverkauft")
                .isNotNull("price").findAll();

        // Anzeigen der Gerichte
        final Resources ressource = context.getResources();
        final String packageName = context.getPackageName();
        final int cells = minHeight <= 65 ? 4 : 8;

        for (int i = 1; i < cells + 1; i++) {
            final int mealName = ressource.getIdentifier("widget_mensa_item_meal_" + i, "id", packageName);
            final int mealPrice = ressource.getIdentifier("widget_mensa_item_price_" + i, "id", packageName);

            if (meals.size() < i) {
                views.setTextViewText(mealName, null);
                views.setTextViewText(mealPrice, null);
                continue;
            }

            final Meal meal = meals.get(i - 1);
            views.setTextViewText(mealName, meal.getTitle());
            views.setTextViewText(mealPrice, context.getString(R.string.mensa_price, meal.getPrice()));
        }

        if (meals.size() != 0)
            views.setTextViewText(R.id.info_message, null);
        else views.setTextViewText(R.id.info_message, ressource.getText(R.string.mensa_no_offer));

        // Instruct the widget manager to update the widget
{'fraction_non_alphanumeric': 0.10511134187146648, 'fraction_numerical': 0.0032306449751932616, 'mean_word_length': 3.3601609657947686, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '411941', 'n_tokens_mistral': 2653, 'n_tokens_neox': 2529, 'n_words': 488}