Skip to content

Commit

Permalink
Keep Event start time as session time
Browse files Browse the repository at this point in the history
Signed-off-by: Arka Prava Basu <[email protected]>
  • Loading branch information
archie94 committed Jul 29, 2018
1 parent 2edef51 commit adb6b32
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
21 changes: 16 additions & 5 deletions src/main/java/org/havenapp/main/PreferenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.havenapp.main.sensors.motion.LuminanceMotionDetector;

import java.io.File;
import java.util.Date;


public class PreferenceManager {
Expand Down Expand Up @@ -88,7 +89,7 @@ public class PreferenceManager {

public static final String DISABLE_BATTERY_OPT = "config_battery_optimizations";

private static final String CURRENT_SESSION = "current_session";
private static final String CURRENT_EVENT_START_TIME = "current_event_start_time";

private Context context;

Expand Down Expand Up @@ -347,15 +348,25 @@ public int getHeartbeatNotificationTimeMs () {
}

/**
* Set the {@link org.havenapp.main.model.Event#mStartTime} for the ongoing event.
* Sets a string with the format {@link Utils#DATE_TIME_PATTERN}
* representing current date and time for the key {@link #CURRENT_SESSION}
* representing current date and time for the key {@link #CURRENT_EVENT_START_TIME}.
*
* @param startTime the {@link org.havenapp.main.model.Event#mStartTime} for an
* {@link org.havenapp.main.model.Event}
*/
public void setCurrentSession() {
prefsEditor.putString(CURRENT_SESSION, Utils.getDateTime(System.currentTimeMillis()));
public void setCurrentSession(Date startTime) {
prefsEditor.putString(CURRENT_EVENT_START_TIME, Utils.getDateTime(startTime));
prefsEditor.commit();
}

/**
* Get the {@link org.havenapp.main.model.Event#mStartTime} for the ongoing event.
*
* @return the string corresponding to pref key {@link #CURRENT_EVENT_START_TIME}.
* Default value is unknown_session.
*/
private String getCurrentSession() {
return appSharedPrefs.getString(CURRENT_SESSION, "unknown_session");
return appSharedPrefs.getString(CURRENT_EVENT_START_TIME, "unknown_session");
}
}
9 changes: 4 additions & 5 deletions src/main/java/org/havenapp/main/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ static String getTimerText(long milliseconds) {
}

/**
* Get a user friendly date and time representation from UNIX epoch.
* Get a user friendly date and time representation from a given {@link Date}.
* The default {@link Locale} is used.
*
* @param timeMillis value representing UNIX epoch
* @return a string of the format "yyyy-MM-dd_HH:mm:ss" for the corresponding epoch
* @param date concerned {@link Date} instance
* @return a string of the format "yyyy-MM-dd_HH:mm:ss" for the corresponding date
*/
public static String getDateTime(long timeMillis) {
Date date = new Date(timeMillis);
public static String getDateTime(Date date) {
return new SimpleDateFormat(DATE_TIME_PATTERN, Locale.getDefault()).format(date);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/havenapp/main/service/MonitorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ private void startSensors ()
{
mIsRunning = true;

mPrefs.setCurrentSession();

if (!mPrefs.getAccelerometerSensitivity().equals(PreferenceManager.OFF)) {
mAccelManager = new AccelerometerMonitor(this);
if(Build.VERSION.SDK_INT>=18) {
Expand Down Expand Up @@ -290,6 +288,8 @@ public synchronized void alert(int alertType, String path) {
mLastEvent = new Event();
mLastEvent.save();
doNotification = true;
// set current event start date in prefs
mPrefs.setCurrentSession(mLastEvent.getStartTime());
}
else if (mPrefs.getNotificationTimeMs() == 0)
{
Expand Down

0 comments on commit adb6b32

Please sign in to comment.