gt:         Calendar timeOff9 = Calendar.getInstance();
context: package com.quexten.ulricianumplanner.ui;
  
  import android.app.AlarmManager;
  import android.app.AlertDialog;
  import android.app.PendingIntent;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.os.Bundle;
  import android.support.design.widget.TabLayout;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewTreeObserver;
  import android.widget.ArrayAdapter;
  import android.widget.LinearLayout;
  import android.widget.Switch;
  import android.widget.TextView;
  
  import com.google.gson.Gson;
  import com.quexten.ulricianumplanner.BuildConfig;
  import com.quexten.ulricianumplanner.FeedbackManager;
  import com.quexten.ulricianumplanner.R;
  import com.quexten.ulricianumplanner.RoomReceiver;
  import com.quexten.ulricianumplanner.courseplan.Hour;
  import com.quexten.ulricianumplanner.news.News;
  import com.quexten.ulricianumplanner.news.NewsHandler;
  import com.quexten.ulricianumplanner.substitutions.Substitution;
  import com.quexten.ulricianumplanner.substitutions.SubstitutionHandler;
  import com.quexten.ulricianumplanner.substitutions.SubstitutionType;
  import com.quexten.ulricianumplanner.sync.SubscriptionManager;
  import com.quexten.ulricianumplanner.substitutions.Substitutions;
  import com.quexten.ulricianumplanner.courseplan.TeacherManager;
  import com.quexten.ulricianumplanner.account.AccountManager;
  import com.quexten.ulricianumplanner.courseplan.CoursePlan;
  
  import java.util.Calendar;
  
  import hotchemi.android.rate.AppRate;
  
  public class MainActivity extends AppCompatActivity {
  
      private CoursePlan coursePlan;
      private FeedbackManager feedbackManager;
      private Substitutions substitutions;
      private TimetableManager timetableManager;
      private TeacherManager teacherManager;
  
      private UiNewsBroadcastReceiver uiNewsBroadcastReceiver;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
          tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.tab_timetable)));
          tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.tab_news)));
          tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
  
          final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
          final PagerAdapter adapter = new PagerAdapter
                  (getSupportFragmentManager(), tabLayout.getTabCount());
          viewPager.setAdapter(adapter);
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
          tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
                  viewPager.setCurrentItem(tab.getPosition());
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
                  //Do nothing
              }
  
              @Override
              public void onTabReselected(TabLayout.Tab tab) {
                  //Do nothing
              }
          });
  
          AccountManager accountManager = new AccountManager(this.getApplicationContext());
          SubscriptionManager subscriptionManager = new SubscriptionManager(this.getApplicationContext());
          coursePlan = new CoursePlan(this.getApplicationContext(), subscriptionManager);
          feedbackManager = new FeedbackManager(this, coursePlan);
          teacherManager = new TeacherManager(this.getApplicationContext());
          substitutions = new SubstitutionHandler(this.getApplicationContext()).load();
  
          View myView = findViewById(R.id.pager);
          myView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                  if(MainActivity.this.timetableManager == null) {
                      MainActivity.this.timetableManager = new TimetableManager(MainActivity.this, coursePlan, substitutions, teacherManager);
                      MainActivity.this.timetableManager.generateVisuals();
                      registerTimetableReceiver();
  
                      //Load news
                      News news = new NewsHandler(MainActivity.this).load();
                      setNews(news);
                  }
              }
          });
  
          if(hasClassName())
              showClassSelection();
  
          if(!accountManager.hasAccount()) {
              Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
              MainActivity.this.startActivity(myIntent);
          }
  
          setBackgroundTasks();
  
          new TutorialManager(this);
  
          showAppRateDialog();
  
          coursePlan.read();
          subscriptionManager.subscribeToPlan(coursePlan);
  
          registerNewsListener();
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.main_menu, menu);
  
          //Debug Test Options
          if(BuildConfig.DEBUG) {
              menu.add("TestNews")
                      .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                          @Override
                          public boolean onMenuItemClick(MenuItem menuItem) {
                              String[] testNews = {"News item 1", "News item 2"};
  
                              Intent intent = new Intent("com.quexten.ulricianumplanner.newsreceived");
                              intent.putExtra("news", new News(testNews).asStringArray());
                              MainActivity.this.sendBroadcast(intent);
                              return false;
                          }
                      });
              menu.add("TestSubstiutiton")
                      .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                          @Override
                          public boolean onMenuItemClick(MenuItem menuItem) {
                              Substitutions substitutions = new Substitutions();
                              Substitution testSubstitution = new Substitution();
  
                              Calendar calendar = Calendar.getInstance();
                              calendar.set(2017, 5, 29);
                              testSubstitution.setDate(calendar.getTime());
                              testSubstitution.setHour(Hour.THREFOUR);
                              testSubstitution.setSubstitutionType(SubstitutionType.CANCELLED);
                              testSubstitution.setSubstituteTeacher("TestTeacher");
                              testSubstitution.setSubstituteSubject("TestSubstituteSubject");
                              testSubstitution.setSubstituteRoom("TestRoom");
                              testSubstitution.setSubject("TestSubject");
                              substitutions.add(testSubstitution);
  
                              for(Substitution substitution : substitutions.asArray()) {
                                  Intent intent = new Intent("com.quexten.ulricianumplanner.substitutionreceived");
                                  intent.putExtra("substitution", new Gson().toJson(substitution));
                                  MainActivity.this.sendBroadcast(intent);
                              }
                              return false;
                          }
                      });
          }
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case R.id.action_login:
                  Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
                  MainActivity.this.startActivity(myIntent);
                  return true;
              case R.id.action_settings:
                  Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
                  MainActivity.this.startActivity(settingsIntent);
                  return true;
              case R.id.action_help:
                  Intent tutorialIntent = new Intent(MainActivity.this, TutorialActivity.class);
                  MainActivity.this.startActivity(tutorialIntent);
                  return true;
              case R.id.action_feedback:
                  AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
                  builderSingle.setTitle(getResources().getString(R.string.feedback_title));
  
                  View child = this.getLayoutInflater().inflate(R.layout.feedback_dialog, null);
                  final LinearLayout childLayout = ((LinearLayout) child);
                  final TextView feedbackDescriptionView = ((TextView) childLayout.findViewById(R.id.feedback_description));
                  final Switch feedbackAddTimetableSwitch = ((Switch) childLayout.findViewById(R.id.feedback_attachtimetable));
                  builderSingle.setView(child);
                  builderSingle.setPositiveButton(getResources().getString(R.string.dialog_positive), new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          feedbackManager.submitFeedback(feedbackDescriptionView.getText().toString(), feedbackAddTimetableSwitch.isChecked());
                      }
                  });
                  builderSingle.show();
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
      }
  
      private void showAppRateDialog() {
          AppRate.with(this)
                  .setInstallDays(5)
                  .setLaunchTimes(5)
                  .setRemindInterval(1)
                  .setShowLaterButton(true)
                  .setDebug(false)
                  .monitor();
          AppRate.showRateDialogIfMeetsConditions(this);
      }
  
      private void setDailyTask(int hour, int minute, int id, Intent intent) {
          AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  
  