|
38 | 38 |
|
39 | 39 | @SuppressWarnings({"CanBeFinal", "MismatchedQueryAndUpdateOfCollection"}) |
40 | 40 | public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { |
41 | | - |
42 | | - private Database db = new Database(); |
43 | | - |
44 | 41 | @Override |
45 | 42 | protected void onCreate(Bundle savedInstanceState) { |
46 | 43 | super.onCreate(savedInstanceState); |
47 | 44 | setContentView(R.layout.activity_main); |
48 | 45 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
49 | 46 | setSupportActionBar(toolbar); |
50 | 47 |
|
| 48 | + Database.refreshDatabase(); |
| 49 | + |
51 | 50 | // Sets button to send user to add assignment page when clicked |
52 | 51 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); |
53 | 52 | fab.setOnClickListener(new View.OnClickListener() { |
@@ -98,24 +97,27 @@ public void onError() { |
98 | 97 |
|
99 | 98 | // Set Up Notifications |
100 | 99 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
101 | | - if (!prefs.getBoolean("firstTime", false)) { |
| 100 | + if (prefs.getBoolean("firstTime", true)) { |
| 101 | + Intent alarmIntent = new Intent(this, AlarmReceiver.class); |
| 102 | + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0); |
| 103 | + |
| 104 | + AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); |
102 | 105 |
|
103 | | - Intent alarmIntent = new Intent(this, AlarmReceiver.class); |
104 | | - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0); |
| 106 | + Calendar calendar = Calendar.getInstance(); |
| 107 | + calendar.setTimeInMillis(System.currentTimeMillis()); |
105 | 108 |
|
106 | | - AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); |
| 109 | + Calendar hourCal = Calendar.getInstance(); |
| 110 | + hourCal.setTimeInMillis(prefs.getLong("notification_time", 90000000)); |
107 | 111 |
|
108 | | - Calendar calendar = Calendar.getInstance(); |
109 | | - calendar.setTimeInMillis(System.currentTimeMillis()); |
110 | | - calendar.set(Calendar.HOUR_OF_DAY, 17); // 5:00 PM TODO: Be editable in settings. |
111 | | - calendar.set(Calendar.MINUTE, 0); |
112 | | - calendar.set(Calendar.SECOND, 0); |
| 112 | + calendar.set(Calendar.HOUR_OF_DAY, hourCal.get(Calendar.HOUR_OF_DAY)); |
| 113 | + calendar.set(Calendar.MINUTE, 0); |
| 114 | + calendar.set(Calendar.SECOND, 1); |
113 | 115 |
|
114 | | - manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), |
115 | | - AlarmManager.INTERVAL_DAY, pendingIntent); |
| 116 | + manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), |
| 117 | + AlarmManager.INTERVAL_DAY, pendingIntent); |
116 | 118 |
|
117 | 119 | SharedPreferences.Editor editor = prefs.edit(); |
118 | | - editor.putBoolean("firstTime", true); |
| 120 | + editor.putBoolean("firstTime", false); |
119 | 121 | editor.apply(); |
120 | 122 | } |
121 | 123 |
|
@@ -180,6 +182,8 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { |
180 | 182 | transaction.replace(R.id.fragment_container, newFragment); |
181 | 183 | transaction.addToBackStack(null); |
182 | 184 | transaction.commit(); |
| 185 | + } else if(id == R.id.nav_settings) { |
| 186 | + startActivity(new Intent(MainActivity.this, SettingsActivity.class)); |
183 | 187 | } |
184 | 188 |
|
185 | 189 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); |
|
0 commit comments