Skip to content

Commit 6f65e41

Browse files
committed
Merge branch 'archie94-media_storage'
2 parents b88ea43 + 0aae3db commit 6f65e41

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/main/java/org/havenapp/main/PreferenceManager.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import org.havenapp.main.sensors.motion.LuminanceMotionDetector;
2828

29+
import java.io.File;
30+
import java.util.Date;
31+
2932

3033
public class PreferenceManager {
3134

@@ -86,6 +89,8 @@ public class PreferenceManager {
8689

8790
public static final String DISABLE_BATTERY_OPT = "config_battery_optimizations";
8891

92+
private static final String CURRENT_EVENT_START_TIME = "current_event_start_time";
93+
8994
private Context context;
9095

9196
public PreferenceManager(Context context) {
@@ -293,7 +298,7 @@ public String getSMSText() {
293298

294299
public String getImagePath ()
295300
{
296-
return "/phoneypot";
301+
return getDefaultMediaStoragePath();
297302
}
298303

299304
public int getMaxImages ()
@@ -303,7 +308,11 @@ public int getMaxImages ()
303308

304309
public String getAudioPath ()
305310
{
306-
return "/phoneypot"; //phoneypot is the old code name for Haven
311+
return getDefaultMediaStoragePath();
312+
}
313+
314+
private String getDefaultMediaStoragePath() {
315+
return "/phoneypot" + File.separator + getCurrentSession(); //phoneypot is the old code name for Haven
307316
}
308317

309318
public int getAudioLength ()
@@ -338,4 +347,26 @@ public int getHeartbeatNotificationTimeMs () {
338347
return appSharedPrefs.getInt(HEARTBEAT_MONITOR_DELAY,300000);
339348
}
340349

350+
/**
351+
* Set the {@link org.havenapp.main.model.Event#mStartTime} for the ongoing event.
352+
* Sets a string with the format {@link Utils#DATE_TIME_PATTERN}
353+
* representing current date and time for the key {@link #CURRENT_EVENT_START_TIME}.
354+
*
355+
* @param startTime the {@link org.havenapp.main.model.Event#mStartTime} for an
356+
* {@link org.havenapp.main.model.Event}
357+
*/
358+
public void setCurrentSession(Date startTime) {
359+
prefsEditor.putString(CURRENT_EVENT_START_TIME, Utils.getDateTime(startTime));
360+
prefsEditor.commit();
361+
}
362+
363+
/**
364+
* Get the {@link org.havenapp.main.model.Event#mStartTime} for the ongoing event.
365+
*
366+
* @return the string corresponding to pref key {@link #CURRENT_EVENT_START_TIME}.
367+
* Default value is unknown_session.
368+
*/
369+
private String getCurrentSession() {
370+
return appSharedPrefs.getString(CURRENT_EVENT_START_TIME, "unknown_session");
371+
}
341372
}

src/main/java/org/havenapp/main/Utils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.havenapp.main;
22

3+
import java.text.SimpleDateFormat;
4+
import java.util.Date;
35
import java.util.Locale;
46
import java.util.concurrent.TimeUnit;
57

@@ -10,6 +12,9 @@
1012
*/
1113

1214
class Utils {
15+
16+
private static final String DATE_TIME_PATTERN = "yyyy-MM-dd_HH:mm:ss";
17+
1318
static String getTimerText(long milliseconds) {
1419
String timerText;
1520
if (TimeUnit.MILLISECONDS.toHours(milliseconds) % 24 == 0) {
@@ -30,4 +35,15 @@ static String getTimerText(long milliseconds) {
3035

3136
return timerText;
3237
}
38+
39+
/**
40+
* Get a user friendly date and time representation from a given {@link Date}.
41+
* The default {@link Locale} is used.
42+
*
43+
* @param date concerned {@link Date} instance
44+
* @return a string of the format "yyyy-MM-dd_HH:mm:ss" for the corresponding date
45+
*/
46+
public static String getDateTime(Date date) {
47+
return new SimpleDateFormat(DATE_TIME_PATTERN, Locale.getDefault()).format(date);
48+
}
3349
}

src/main/java/org/havenapp/main/service/MonitorService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ public synchronized void alert(int alertType, String path) {
295295
mLastEvent = new Event();
296296
mLastEvent.save();
297297
doNotification = true;
298+
// set current event start date in prefs
299+
mPrefs.setCurrentSession(mLastEvent.getStartTime());
298300
}
299301
else if (mPrefs.getNotificationTimeMs() == 0)
300302
{

0 commit comments

Comments
 (0)