Skip to content

Commit

Permalink
Merge branch 'media_storage' of https://github.com/archie94/haven int…
Browse files Browse the repository at this point in the history
…o archie94-media_storage
  • Loading branch information
n8fr8 committed Aug 20, 2018
2 parents b88ea43 + adb6b32 commit 0aae3db
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/main/java/org/havenapp/main/PreferenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

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

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


public class PreferenceManager {

Expand Down Expand Up @@ -86,6 +89,8 @@ public class PreferenceManager {

public static final String DISABLE_BATTERY_OPT = "config_battery_optimizations";

private static final String CURRENT_EVENT_START_TIME = "current_event_start_time";

private Context context;

public PreferenceManager(Context context) {
Expand Down Expand Up @@ -293,7 +298,7 @@ public String getSMSText() {

public String getImagePath ()
{
return "/phoneypot";
return getDefaultMediaStoragePath();
}

public int getMaxImages ()
Expand All @@ -303,7 +308,11 @@ public int getMaxImages ()

public String getAudioPath ()
{
return "/phoneypot"; //phoneypot is the old code name for Haven
return getDefaultMediaStoragePath();
}

private String getDefaultMediaStoragePath() {
return "/phoneypot" + File.separator + getCurrentSession(); //phoneypot is the old code name for Haven
}

public int getAudioLength ()
Expand Down Expand Up @@ -338,4 +347,26 @@ public int getHeartbeatNotificationTimeMs () {
return appSharedPrefs.getInt(HEARTBEAT_MONITOR_DELAY,300000);
}

/**
* 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_EVENT_START_TIME}.
*
* @param startTime the {@link org.havenapp.main.model.Event#mStartTime} for an
* {@link org.havenapp.main.model.Event}
*/
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_EVENT_START_TIME, "unknown_session");
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/havenapp/main/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.havenapp.main;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

Expand All @@ -10,6 +12,9 @@
*/

class Utils {

private static final String DATE_TIME_PATTERN = "yyyy-MM-dd_HH:mm:ss";

static String getTimerText(long milliseconds) {
String timerText;
if (TimeUnit.MILLISECONDS.toHours(milliseconds) % 24 == 0) {
Expand All @@ -30,4 +35,15 @@ static String getTimerText(long milliseconds) {

return timerText;
}

/**
* Get a user friendly date and time representation from a given {@link Date}.
* The default {@link Locale} is used.
*
* @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(Date date) {
return new SimpleDateFormat(DATE_TIME_PATTERN, Locale.getDefault()).format(date);
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/havenapp/main/service/MonitorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,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 0aae3db

Please sign in to comment.