Guest User

Untitled

a guest
Jan 21st, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. // getting the toggle button state using shared preference
  2. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
  3. Boolean runstopChecked = sharedPreferences.getBoolean("pref_runstop", false);
  4. viewHolder.tbtnJobRunStop.setChecked(runstopChecked);
  5.  
  6. // Saving the position and toggle button state
  7. viewHolder.tbtnJobRunStop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  8. @Override
  9. public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
  10. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
  11. SharedPreferences.Editor editor = sharedPreferences.edit();
  12. editor.putInt("pref_runstopposition", position);
  13. if(isChecked)
  14. {
  15. runJobId = dataModel.getJobId();
  16. editor.putBoolean("pref_runstop", true);
  17. editor.apply();
  18. Intent statusIntent = new Intent(getContext(), RefreshJobService.class);
  19. statusIntent.putExtra("id", runJobId);
  20. getContext().startService(statusIntent);
  21. } else
  22. {
  23. stopJobId = dataModel.getJobId();
  24. editor.putBoolean("pref_runstop", false);
  25. editor.apply();
  26. stopJob stopjob = new stopJob();
  27. stopjob.execute();
  28. Intent i = new Intent("stopjob");
  29. LocalBroadcastManager.getInstance(getContext()).sendBroadcast(i);
  30. i.putExtra("stopJobId",stopJobId);
  31. getContext().sendBroadcast(i);
  32. }
  33. }
  34. });
Add Comment
Please, Sign In to add comment