Last active
September 6, 2017 08:54
-
-
Save talhahasanzia/42a3e9ef0fa239cda06511a9571c18b3 to your computer and use it in GitHub Desktop.
Alarm issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void add() | |
{ | |
AlarmManager am = (AlarmManager) getApplicationContext().getSystemService( Context.ALARM_SERVICE ); | |
Intent intent = new Intent( getApplicationContext(), AlarmReceiver.class ); | |
intent.setAction( "com.actions.alarms" ); | |
intent.putExtra( "id", suppID ); | |
IDs = IDs + 1; | |
intent.putExtras( dataModel.toBundle() ); | |
Long cal = new GregorianCalendar().getTimeInMillis() + ( IDs * 60 * 1000 ); | |
PendingIntent i1 = PendingIntent.getBroadcast( getApplicationContext(), IDs, intent, 0 ); | |
am.set( AlarmManager.RTC_WAKEUP, cal, i1 ); | |
RemindersModel remindersModel = new RemindersModel( 0, suppID, IDs, cal, -1 ); | |
remindersRepo.add( remindersModel ); | |
remindersModels = remindersRepo.query( suppID + "" ); | |
if ( remindersModels.size() > 0 ) | |
{ | |
listView.setAdapter( new SwipeListAdapter() ); | |
listView.setVisibility( View.VISIBLE ); | |
reminderMessage.setVisibility( View.GONE ); | |
} | |
Toast.makeText( this, "Added reminder", Toast.LENGTH_SHORT ).show(); | |
} | |
private void delete( int position ) | |
{ | |
RemindersModel temp = remindersModels.get( position ); | |
AlarmManager am = (AlarmManager) getApplicationContext().getSystemService( Context.ALARM_SERVICE ); | |
Intent intent = new Intent( getApplicationContext(), AlarmReceiver.class ); | |
PendingIntent pIntent = PendingIntent.getBroadcast( getApplicationContext(), temp.getAlarmID(), intent, PendingIntent.FLAG_UPDATE_CURRENT ); | |
am.cancel( pIntent ); | |
remindersRepo.remove( temp ); | |
remindersModels = remindersRepo.query( suppID + "" ); | |
if ( remindersModels.size() > 0 ) | |
{ | |
listView.setAdapter( new SwipeListAdapter() ); | |
listView.setVisibility( View.VISIBLE ); | |
reminderMessage.setVisibility( View.GONE ); | |
} | |
else | |
{ | |
listView.setVisibility( View.GONE ); | |
reminderMessage.setVisibility( View.VISIBLE ); | |
} | |
Toast.makeText( this, "Removed reminder", Toast.LENGTH_SHORT ).show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IDs is also checked by breakpoint debugging that it is correct with respect to clicked item.