Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Last active September 6, 2017 08:54
Show Gist options
  • Save talhahasanzia/42a3e9ef0fa239cda06511a9571c18b3 to your computer and use it in GitHub Desktop.
Save talhahasanzia/42a3e9ef0fa239cda06511a9571c18b3 to your computer and use it in GitHub Desktop.
Alarm issue
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();
}
@talhahasanzia
Copy link
Author

IDs is also checked by breakpoint debugging that it is correct with respect to clicked item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment