// Path: app/src/main/java/org/nutritionfacts/dailydozen/controller/Bus.java
// public class Bus {
//     public static void register(Object object) {
//         final EventBus bus = EventBus.getDefault();
//         if (!bus.isRegistered(object)) {
//             bus.register(object);
//         }
//     }
// 
//     public static void unregister(Object object) {
//         final EventBus bus = EventBus.getDefault();
//         if (bus.isRegistered(object)) {
//             bus.unregister(object);
//         }
//     }
// 
//     private static void post(BaseEvent event) {
//         EventBus.getDefault().post(event);
//     }
// 
//     public static void foodServingsChangedEvent(Day day, Food food) {
//         post(new FoodServingsChangedEvent(day.getDateString(), food.getName(), Common.isSupplement(food)));
//     }
// 
//     public static void tweakServingsChangedEvent(Day day, Tweak tweak) {
//         post(new TweakServingsChangedEvent(day.getDateString(), tweak.getName()));
//     }
// 
//     public static void displayLatestDate() {
//         post(new DisplayDateEvent(Day.getToday()));
//     }
// 
//     public static void showExplodingStarAnimation() {
//         post(new ShowExplodingStarAnimation());
//     }
// 
//     public static void restoreCompleteEvent(final boolean success) {
//         post(new RestoreCompleteEvent(success));
//     }
// 
//     public static void backupCompleteEvent(final boolean success) {
//         post(new BackupCompleteEvent(success));
//     }
// 
//     public static void calculateStreaksComplete(final boolean success) {
//         post(new CalculateStreaksTaskCompleteEvent(success));
//     }
// 
//     public static void loadHistoryCompleteEvent(final LoadHistoryCompleteEvent event) {
//         post(event);
//     }
// 
//     public static void timeScaleSelected(final int selectedTimeScale) {
//         post(new TimeScaleSelectedEvent(selectedTimeScale));
//     }
// 
//     public static void timeRangeSelectedEvent() {
//         post(new TimeRangeSelectedEvent());
//     }
// 
//     public static void weightVisibilityChanged() {
//         post(new WeightVisibilityChangedEvent());
//     }
// 
//     public static void reminderRemovedEvent(int adapterPosition) {
//         post(new ReminderRemovedEvent(adapterPosition));
//     }
// }


import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import org.nutritionfacts.dailydozen.R;
import org.nutritionfacts.dailydozen.controller.Bus;
import org.nutritionfacts.dailydozen.databinding.TimeScaleSelectorBinding;
import org.nutritionfacts.dailydozen.model.enums.TimeScale;
    @TimeScale.Interface
    public int getSelectedTimeScale() {
        switch (binding.timeScaleSpinner.getSelectedItemPosition()) {
            case TimeScale.MONTHS:
                return TimeScale.MONTHS;
            case TimeScale.YEARS:
                return TimeScale.YEARS;
            default:
            case TimeScale.DAYS:
                return TimeScale.DAYS;
        }
    }

    private void init(final Context context) {
        binding = TimeScaleSelectorBinding.inflate(LayoutInflater.from(context), this, true);
        initTimeScaleSpinner();
    }

    private void initTimeScaleSpinner() {
        final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
                R.array.servings_time_scale_choices,
                android.R.layout.simple_expandable_list_item_1);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        binding.timeScaleSpinner.setOnItemSelectedListener(this);
        binding.timeScaleSpinner.setAdapter(adapter);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// Path: app/src/main/java/org/nutritionfacts/dailydozen/controller/Bus.java
// public class Bus {
//     public static void register(Object object) {
//         final EventBus bus = EventBus.getDefault();
//         if (!bus.isRegistered(object)) {
//             bus.register(object);
//         }
//     }
// 
//     public static void unregister(Object object) {
//         final EventBus bus = EventBus.getDefault();
//         if (bus.isRegistered(object)) {
//             bus.unregister(object);
//         }
//     }
// 
//     private static void post(BaseEvent event) {
//         EventBus.getDefault().post(event);
//     }
// 
//     public static void foodServingsChangedEvent(Day day, Food food) {
//         post(new FoodServingsChangedEvent(day.getDateString(), food.getName(), Common.isSupplement(food)));
//     }
// 
//     public static void tweakServingsChangedEvent(Day day, Tweak tweak) {
//         post(new TweakServingsChangedEvent(day.getDateString(), tweak.getName()));
//     }
// 
//     public static void displayLatestDate() {
//         post(new DisplayDateEvent(Day.getToday()));
//     }
// 
//     public static void showExplodingStarAnimation() {
//         post(new ShowExplodingStarAnimation());
//     }
// 
//     public static void restoreCompleteEvent(final boolean success) {
//         post(new RestoreCompleteEvent(success));
//     }
// 
//     public static void backupCompleteEvent(final boolean success) {
//         post(new BackupCompleteEvent(success));
//     }
// 
//     public static void calculateStreaksComplete(final boolean success) {
//         post(new CalculateStreaksTaskCompleteEvent(success));
//     }
// 
//     public static void loadHistoryCompleteEvent(final LoadHistoryCompleteEvent event) {
//         post(event);
//     }
// 
//     public static void timeScaleSelected(final int selectedTimeScale) {
//         post(new TimeScaleSelectedEvent(selectedTimeScale));
//     }
// 
//     public static void timeRangeSelectedEvent() {
//         post(new TimeRangeSelectedEvent());
//     }
// 
//     public static void weightVisibilityChanged() {
//         post(new WeightVisibilityChangedEvent());
//     }
// 
//     public static void reminderRemovedEvent(int adapterPosition) {
//         post(new ReminderRemovedEvent(adapterPosition));
//     }
// }


// Path: app/src/main/java/org/nutritionfacts/dailydozen/view/TimeScaleSelector.java
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import org.nutritionfacts.dailydozen.R;
import org.nutritionfacts.dailydozen.controller.Bus;
import org.nutritionfacts.dailydozen.databinding.TimeScaleSelectorBinding;
import org.nutritionfacts.dailydozen.model.enums.TimeScale;

    @TimeScale.Interface
    public int getSelectedTimeScale() {
        switch (binding.timeScaleSpinner.getSelectedItemPosition()) {
            case TimeScale.MONTHS:
                return TimeScale.MONTHS;
            case TimeScale.YEARS:
                return TimeScale.YEARS;
            default:
            case TimeScale.DAYS:
                return TimeScale.DAYS;
        }
    }

    private void init(final Context context) {
        binding = TimeScaleSelectorBinding.inflate(LayoutInflater.from(context), this, true);
        initTimeScaleSpinner();
    }

    private void initTimeScaleSpinner() {
        final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
                R.array.servings_time_scale_choices,
                android.R.layout.simple_expandable_list_item_1);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        binding.timeScaleSpinner.setOnItemSelectedListener(this);
        binding.timeScaleSpinner.setAdapter(adapter);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Bus.timeScaleSelected(binding.timeScaleSpinner.getSelectedItemPosition());