I'm trying to take an int from SharedPreferences
that tracks how long the app program has been active and reduce it to an int less than 7 to show what day of that program week the user is in.
Here is what I have used to reduce the int, (i am trying to use a while loop to go in and subtract 7 until the int is less than 7. The IF
statement was added to see if the int was reduced and it was displaying the wrong String)
public void methodNameHere() {
SharedPreferences onvalue = getApplicationContext().getSharedPreferences("TRAININGDAY", MODE_APPEND);
int day = (int) onvalue.getLong("DAY", 0);
SharedPreferences.Editor edit = onvalue.edit();
while (day < 7) {
day = day - 7;
}
if (day < 7) {
String da = Integer.toString(day);
Toast.makeText(CardioStart.this, da, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(CardioStart.this, "f?*k", Toast.LENGTH_LONG).show();
}
}
And this is where the int is coming from:
private void dayOfTraining() {
TextView day = (TextView) findViewById(R.id.dayoftraining);
date.setTimeInMillis(millidate);
Calendar someday = Calendar.getInstance();
someday.set(2015, 4, 25);
Calendar today = Calendar.getInstance();
Long millidate = someday.getTimeInMillis();
long timeTwo = today.getTimeInMillis();
long oneDay = 1000 * 60 * 60 * 24;
long delta = (timeTwo - millidate) / oneDay;
long actualday = delta + 1;
day.setText(Long.toString(actualday));
SharedPreferences onvalue = getApplicationContext().getSharedPreferences("TRAININGDAY", MODE_APPEND);
SharedPreferences.Editor edit = onvalue.edit();
edit.putLong("DAY", actualday);
edit.commit();
}
String da toasts as "29" so it seems its not reducing.
I feel like I am missing something simple or I just don't have a true grasp on the use of while loops. Any help would be greatly appreciated. Thank you.