Allow editing session date, time and message
This commit is contained in:
parent
af5d26ede4
commit
bccd964575
|
@ -1,3 +1,7 @@
|
|||
1.5.3:
|
||||
- Fix tapping widget always causing MediNET sign in dialog to be shown
|
||||
- Potentially fix
|
||||
|
||||
1.5.3:
|
||||
- Fix interval sounds not reliably playing
|
||||
- Fix timer not displaying when returning to the app while paused
|
||||
|
|
|
@ -203,6 +203,16 @@ public class CalendarFragment extends Fragment {
|
|||
updateMonthScroll();
|
||||
}
|
||||
});
|
||||
prevMonth.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
mCalendar.add(Calendar.YEAR, -1);
|
||||
gridCalendar.setAdapter(getMonthAdapter());
|
||||
|
||||
updateMonthScroll();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
nextMonth.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
|
@ -213,8 +223,26 @@ public class CalendarFragment extends Fragment {
|
|||
updateMonthScroll();
|
||||
}
|
||||
});
|
||||
nextMonth.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
Calendar midnightToday = Calendar.getInstance();
|
||||
midnightToday.set(Calendar.HOUR, 0);
|
||||
midnightToday.set(Calendar.MINUTE, 0);
|
||||
midnightToday.set(Calendar.SECOND, 0);
|
||||
|
||||
LinearLayout ldate = new LinearLayout(ctx);
|
||||
mCalendar.add(Calendar.YEAR, 1);
|
||||
if (mCalendar.after(midnightToday)) {
|
||||
mCalendar = midnightToday;
|
||||
}
|
||||
gridCalendar.setAdapter(getMonthAdapter());
|
||||
|
||||
updateMonthScroll();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
LinearLayout ldate = new LinearLayout(ctx);
|
||||
ldate.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
LinearLayout.LayoutParams lp_horiz = new LinearLayout.LayoutParams(
|
||||
|
|
|
@ -25,7 +25,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
private static final String KEY_COMPLETED = "completed";
|
||||
private static final String KEY_LENGTH = "length";
|
||||
private static final String KEY_MESSAGE = "message";
|
||||
private static final String KEY_DATE = "date";
|
||||
private static final String KEY_ISPOSTED = "isposted";
|
||||
private static final String KEY_STREAKDAY = "streakday";
|
||||
private static DatabaseHandler databaseHandler;
|
||||
|
@ -46,30 +45,32 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
return databaseHandler;
|
||||
}
|
||||
|
||||
void addSession(SessionSQL session) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_STARTED, session._started);
|
||||
values.put(KEY_COMPLETED, session._completed);
|
||||
values.put(KEY_LENGTH, session._length);
|
||||
values.put(KEY_MESSAGE, session._message);
|
||||
values.put(KEY_DATE, sessionToAPIDate(session));
|
||||
values.put(KEY_ISPOSTED, session._isposted);
|
||||
values.put(KEY_STREAKDAY, session._streakday);
|
||||
public ArrayList<Long> dateToSessionWindow(Calendar c) {
|
||||
ArrayList<Long>sessionWindow = new ArrayList<Long>();
|
||||
ArrayList<Integer> streakbuffertime = getMeditationAssistant().getStreakBufferTime();
|
||||
Calendar sessionWindowCalendar = (Calendar) c.clone();
|
||||
|
||||
sessionWindowCalendar.set(Calendar.HOUR_OF_DAY, streakbuffertime.get(0));
|
||||
sessionWindowCalendar.set(Calendar.MINUTE, streakbuffertime.get(1));
|
||||
sessionWindow.add(sessionWindowCalendar.getTimeInMillis() / 1000);
|
||||
|
||||
db.insert(TABLE_SESSIONS, null, values);
|
||||
sessionWindowCalendar.add(Calendar.DATE, 1);
|
||||
sessionWindowCalendar.set(Calendar.HOUR_OF_DAY, streakbuffertime.get(0));
|
||||
sessionWindowCalendar.set(Calendar.MINUTE, streakbuffertime.get(1));
|
||||
sessionWindow.add(sessionWindowCalendar.getTimeInMillis() / 1000);
|
||||
|
||||
getMeditationAssistant().notifySessionsUpdated();
|
||||
return sessionWindow;
|
||||
}
|
||||
|
||||
public String sessionToAPIDate(SessionSQL session) {
|
||||
public String sessionToDate(SessionSQL session) {
|
||||
if (session._completed != null) {
|
||||
return timestampToAPIDate(session._completed * 1000);
|
||||
return timestampToDate(session._completed * 1000);
|
||||
} else {
|
||||
return timestampToAPIDate((session._started + session._length) * 1000);
|
||||
return timestampToDate((session._started + session._length) * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public String timestampToAPIDate(long timestamp) {
|
||||
private String timestampToDate(long timestamp) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("d-M-yyyy", Locale.US);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
@ -79,10 +80,64 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
return sdf.format(api_date);
|
||||
}
|
||||
|
||||
public MeditationAssistant getMeditationAssistant() {
|
||||
private ArrayList<SessionSQL> unmarshalResult(Cursor c) {
|
||||
ArrayList<SessionSQL> sessionList = new ArrayList<SessionSQL>();
|
||||
if (c != null) {
|
||||
if (c.moveToFirst()) {
|
||||
do {
|
||||
SessionSQL session = new SessionSQL(
|
||||
c.getLong(c.getColumnIndex(KEY_ID)),
|
||||
c.getLong(c.getColumnIndex(KEY_STARTED)),
|
||||
c.getLong(c.getColumnIndex(KEY_COMPLETED)),
|
||||
c.getLong(c.getColumnIndex(KEY_LENGTH)),
|
||||
c.getString(c.getColumnIndex(KEY_MESSAGE)),
|
||||
c.getLong(c.getColumnIndex(KEY_ISPOSTED)),
|
||||
c.getLong(c.getColumnIndex(KEY_STREAKDAY)));
|
||||
|
||||
sessionList.add(session);
|
||||
} while (c.moveToNext());
|
||||
}
|
||||
|
||||
c.close();
|
||||
}
|
||||
|
||||
return sessionList;
|
||||
}
|
||||
|
||||
private MeditationAssistant getMeditationAssistant() {
|
||||
return ma;
|
||||
}
|
||||
|
||||
void addSession(SessionSQL session) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_STARTED, session._started);
|
||||
values.put(KEY_COMPLETED, session._completed);
|
||||
values.put(KEY_LENGTH, session._length);
|
||||
values.put(KEY_MESSAGE, session._message);
|
||||
values.put(KEY_ISPOSTED, session._isposted);
|
||||
values.put(KEY_STREAKDAY, session._streakday);
|
||||
|
||||
db.insert(TABLE_SESSIONS, null, values);
|
||||
|
||||
getMeditationAssistant().notifySessionsUpdated();
|
||||
}
|
||||
|
||||
public int updateSession(SessionSQL session) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_STARTED, session._started);
|
||||
values.put(KEY_COMPLETED, session._completed);
|
||||
values.put(KEY_LENGTH, session._length);
|
||||
values.put(KEY_MESSAGE, session._message);
|
||||
values.put(KEY_ISPOSTED, session._isposted);
|
||||
values.put(KEY_STREAKDAY, session._streakday);
|
||||
|
||||
int result = db.update(TABLE_SESSIONS, values, KEY_ID + " = ?",
|
||||
new String[]{String.valueOf(session.getID())});
|
||||
|
||||
getMeditationAssistant().notifySessionsUpdated();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void deleteSession(SessionSQL session) {
|
||||
db.delete(TABLE_SESSIONS, KEY_ID + " = ?",
|
||||
new String[]{String.valueOf(session.getID())});
|
||||
|
@ -91,56 +146,13 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public ArrayList<SessionSQL> getAllSessions() {
|
||||
ArrayList<SessionSQL> sessionList = new ArrayList<SessionSQL>();
|
||||
|
||||
String selectQuery = "SELECT * FROM `" + TABLE_SESSIONS + "` ORDER BY "
|
||||
+ "`" + KEY_COMPLETED + "` DESC";
|
||||
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
SessionSQL session = new SessionSQL(cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ID)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STARTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_COMPLETED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_LENGTH)), cursor.getString(cursor
|
||||
.getColumnIndex(KEY_MESSAGE)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ISPOSTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STREAKDAY)));
|
||||
|
||||
sessionList.add(session);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
return sessionList;
|
||||
String selectQuery = "SELECT * FROM `" + TABLE_SESSIONS + "` ORDER BY " + "`" + KEY_STARTED + "` DESC";
|
||||
return unmarshalResult(db.rawQuery(selectQuery, null));
|
||||
}
|
||||
|
||||
public ArrayList<SessionSQL> getAllLocalSessions() {
|
||||
ArrayList<SessionSQL> sessionList = new ArrayList<SessionSQL>();
|
||||
|
||||
String selectQuery = "SELECT * FROM `" + TABLE_SESSIONS + "`";
|
||||
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
SessionSQL session = new SessionSQL(cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ID)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STARTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_COMPLETED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_LENGTH)), cursor.getString(cursor
|
||||
.getColumnIndex(KEY_MESSAGE)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ISPOSTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STREAKDAY)));
|
||||
|
||||
sessionList.add(session);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
return sessionList;
|
||||
return unmarshalResult(db.rawQuery(selectQuery, null));
|
||||
}
|
||||
|
||||
public int getNumSessions() {
|
||||
|
@ -165,49 +177,40 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
return time_meditating;
|
||||
}
|
||||
|
||||
int numSessionsByDate(Calendar dateCalendar) {
|
||||
String date = String.valueOf(dateCalendar.get(Calendar.DAY_OF_MONTH)) + "-"
|
||||
+ String.valueOf(dateCalendar.get(Calendar.MONTH) + 1) + "-"
|
||||
+ String.valueOf(dateCalendar.get(Calendar.YEAR));
|
||||
Calendar nextDate = (Calendar) dateCalendar.clone();
|
||||
nextDate.add(Calendar.DATE, 1);
|
||||
String dateLateNight = String.valueOf(nextDate.get(Calendar.DAY_OF_MONTH)) + "-"
|
||||
+ String.valueOf(nextDate.get(Calendar.MONTH) + 1) + "-"
|
||||
+ String.valueOf(nextDate.get(Calendar.YEAR));
|
||||
Cursor cursor = db.rawQuery("SELECT * FROM `" + TABLE_SESSIONS + "` WHERE `" + KEY_DATE + "`=? OR `" + KEY_DATE + "`=?", new String[]{date, dateLateNight});
|
||||
int numSessionsByDate(Calendar date) {
|
||||
ArrayList<Long> sessionWindow = dateToSessionWindow(date);
|
||||
Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM `" + TABLE_SESSIONS + "` WHERE `" + KEY_STARTED + "`>=? AND `" + KEY_STARTED + "`<?", new String[]{String.valueOf(sessionWindow.get(0)), String.valueOf(sessionWindow.get(1))});
|
||||
|
||||
Calendar startedCalendar = Calendar.getInstance();
|
||||
Calendar midnightCalendar = Calendar.getInstance();
|
||||
int numsessions = 0;
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
String sessionDate = cursor.getString(cursor
|
||||
.getColumnIndex(KEY_DATE));
|
||||
long sessionStarted = cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STARTED));
|
||||
|
||||
startedCalendar.setTimeInMillis(sessionStarted * 1000);
|
||||
|
||||
midnightCalendar.setTimeInMillis(sessionStarted * 1000);
|
||||
midnightCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
midnightCalendar.set(Calendar.MINUTE, 0);
|
||||
midnightCalendar.set(Calendar.SECOND, 0);
|
||||
midnightCalendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
/*Log.d("MeditationAssistant", "numSessionsByDate " + date + " to " + dateLateNight + " - " + sessionDate + " - MIDNIGHT CALENDAR: " + String.valueOf(midnightCalendar.get(Calendar.DAY_OF_MONTH)) + "-"
|
||||
+ String.valueOf(midnightCalendar.get(Calendar.MONTH) + 1) + "-"
|
||||
+ String.valueOf(midnightCalendar.get(Calendar.YEAR)));*/
|
||||
if ((sessionDate.equals(date) && startedCalendar.getTimeInMillis() - midnightCalendar.getTimeInMillis() > (getMeditationAssistant().getMeditationStreakBuffer() * 1000)) || (sessionDate.equals(dateLateNight) && getMeditationAssistant().getMeditationStreakBuffer() > 0 && startedCalendar.getTimeInMillis() - midnightCalendar.getTimeInMillis() <= (getMeditationAssistant().getMeditationStreakBuffer() * 1000))) {
|
||||
numsessions++;
|
||||
//Log.d("MeditationAssistant", "numSessionsByDate MATCH: " + String.valueOf(startedCalendar.getTimeInMillis() - midnightCalendar.getTimeInMillis()) + " - " + (sessionDate.equals(date) ? "DATE MATCH" : "NO DATE MATCH") + " - " + (sessionDate.equals(dateLateNight) ? "LATE NIGHT MATCH" : "NO LATE NIGHT MATCH"));
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.moveToFirst();
|
||||
int numsessions = cursor.getInt(0);
|
||||
cursor.close();
|
||||
|
||||
return numsessions;
|
||||
}
|
||||
|
||||
public ArrayList<SessionSQL> getSessionsByDate(Calendar date) {
|
||||
ArrayList<Long> sessionWindow = dateToSessionWindow(date);
|
||||
return unmarshalResult(db.rawQuery("SELECT * FROM `" + TABLE_SESSIONS + "` WHERE `" + KEY_STARTED + "`>=? AND `" + KEY_STARTED + "`<? ORDER BY `" + KEY_STARTED + "` ASC LIMIT 1", new String[]{String.valueOf(sessionWindow.get(0)), String.valueOf(sessionWindow.get(1))}));
|
||||
}
|
||||
|
||||
public SessionSQL getSessionByDate(Calendar date) {
|
||||
ArrayList<SessionSQL> sessions = getSessionsByDate(date);
|
||||
if (sessions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return sessions.get(0);
|
||||
}
|
||||
|
||||
SessionSQL getSessionByStarted(long started) {
|
||||
ArrayList<SessionSQL> sessions = unmarshalResult(db.rawQuery("SELECT * FROM `" + TABLE_SESSIONS + "` WHERE `" + KEY_STARTED + "`=? LIMIT 1", new String[]{String.valueOf(started)}));
|
||||
if (sessions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return sessions.get(0);
|
||||
}
|
||||
|
||||
int getLongestSessionLength() {
|
||||
int longestsessionlength = 0;
|
||||
Cursor cursor = db.rawQuery("SELECT MAX(`" + KEY_LENGTH + "`) FROM `" + TABLE_SESSIONS + "`", null);
|
||||
|
@ -219,34 +222,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
return longestsessionlength;
|
||||
}
|
||||
|
||||
SessionSQL getSessionByStarted(long started) {
|
||||
SessionSQL session = null;
|
||||
|
||||
Cursor cursor = db.query(TABLE_SESSIONS, new String[]{KEY_ID,
|
||||
KEY_STARTED, KEY_COMPLETED, KEY_LENGTH, KEY_MESSAGE, KEY_ISPOSTED, KEY_STREAKDAY},
|
||||
KEY_STARTED + "=?", new String[]{String.valueOf(started)},
|
||||
null, null, null, "1"
|
||||
);
|
||||
if (cursor != null) {
|
||||
if (cursor.getCount() > 0) {
|
||||
cursor.moveToFirst();
|
||||
|
||||
session = new SessionSQL(cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ID)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STARTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_COMPLETED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_LENGTH)), cursor.getString(cursor
|
||||
.getColumnIndex(KEY_MESSAGE)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ISPOSTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STREAKDAY)));
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
Log.d("MeditationAssistant", "CREATING DATABASE VERSION " + String.valueOf(DATABASE_VERSION));
|
||||
|
@ -254,11 +229,10 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
+ "`" + KEY_ID + "` INTEGER PRIMARY KEY, "
|
||||
+ "`" + KEY_STARTED + "` INTEGER, `" + KEY_COMPLETED + "` INTEGER, "
|
||||
+ "`" + KEY_LENGTH + "` INTEGER, `" + KEY_MESSAGE + "` STRING, "
|
||||
+ "`" + KEY_DATE + "` STRING, `" + KEY_ISPOSTED + "` INTEGER, `" + KEY_STREAKDAY + "` INTEGER" + ")");
|
||||
+ "`" + KEY_ISPOSTED + "` INTEGER, `" + KEY_STREAKDAY + "` INTEGER" + ")");
|
||||
|
||||
db.execSQL("CREATE INDEX `" + KEY_STARTED + "_idx` ON `" + TABLE_SESSIONS + "` (`" + KEY_STARTED + "`)");
|
||||
db.execSQL("CREATE INDEX `" + KEY_COMPLETED + "_idx` ON `" + TABLE_SESSIONS + "` (`" + KEY_COMPLETED + "`)");
|
||||
db.execSQL("CREATE INDEX `" + KEY_DATE + "_idx` ON `" + TABLE_SESSIONS + "` (`" + KEY_DATE + "`)");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -276,14 +250,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
case 3:
|
||||
Log.d("MeditationAssistant", "UPGRADING DATABASE to " + String.valueOf(curVer));
|
||||
|
||||
/* Fix for incorrect upgrade code */
|
||||
try {
|
||||
db.execSQL("ALTER TABLE `" + TABLE_SESSIONS + "` ADD COLUMN `" + KEY_DATE + "` STRING");
|
||||
} catch (Exception e) {
|
||||
// Column already exists
|
||||
}
|
||||
db.execSQL("CREATE INDEX `" + KEY_STARTED + "_idx` ON `" + TABLE_SESSIONS + "` (`" + KEY_STARTED + "`)");
|
||||
db.execSQL("CREATE INDEX `" + KEY_DATE + "_idx` ON `" + TABLE_SESSIONS + "` (`" + KEY_DATE + "`)");
|
||||
break;
|
||||
case 4:
|
||||
Log.d("MeditationAssistant", "UPGRADING DATABASE to " + String.valueOf(curVer));
|
||||
|
@ -295,8 +262,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
// Column already exists
|
||||
}
|
||||
try {
|
||||
db.execSQL("ALTER TABLE `" + TABLE_SESSIONS + "` ADD COLUMN `" + KEY_DATE + "` STRING");
|
||||
db.execSQL("CREATE INDEX `" + KEY_DATE + "_idx` ON `" + TABLE_SESSIONS + "` (`" + KEY_DATE + "`)");
|
||||
db.execSQL("CREATE INDEX `" + KEY_STARTED + "_idx` ON `" + TABLE_SESSIONS + "` (`" + KEY_STARTED + "`)");
|
||||
} catch (Exception e) {
|
||||
// Column already exists
|
||||
|
@ -334,74 +299,4 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int updateSession(SessionSQL session) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_STARTED, session._started);
|
||||
values.put(KEY_COMPLETED, session._completed);
|
||||
values.put(KEY_LENGTH, session._length);
|
||||
values.put(KEY_MESSAGE, session._message);
|
||||
values.put(KEY_ISPOSTED, session._isposted);
|
||||
values.put(KEY_STREAKDAY, session._streakday);
|
||||
|
||||
int result = db.update(TABLE_SESSIONS, values, KEY_ID + " = ?",
|
||||
new String[]{String.valueOf(session.getID())});
|
||||
|
||||
getMeditationAssistant().notifySessionsUpdated();
|
||||
return result;
|
||||
}
|
||||
|
||||
public SessionSQL getSessionByDate(String date) {
|
||||
Log.d("MeditationAssistant", "SQL: get session by date " + date);
|
||||
SessionSQL session = null;
|
||||
|
||||
Cursor cursor = db.query(TABLE_SESSIONS, new String[]{KEY_ID,
|
||||
KEY_STARTED, KEY_COMPLETED, KEY_LENGTH, KEY_MESSAGE, KEY_ISPOSTED, KEY_STREAKDAY},
|
||||
KEY_DATE + "=?", new String[]{date},
|
||||
null, null, null, "1"
|
||||
);
|
||||
if (cursor != null) {
|
||||
if (cursor.getCount() > 0) {
|
||||
cursor.moveToFirst();
|
||||
|
||||
session = new SessionSQL(cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ID)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STARTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_COMPLETED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_LENGTH)), cursor.getString(cursor
|
||||
.getColumnIndex(KEY_MESSAGE)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ISPOSTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STREAKDAY)));
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
public ArrayList<SessionSQL> getSessionsByDate(String date) {
|
||||
ArrayList<SessionSQL> sessionList = new ArrayList<SessionSQL>();
|
||||
|
||||
Cursor cursor = db.rawQuery("SELECT * FROM `" + TABLE_SESSIONS + "` WHERE `" + KEY_DATE + "`=? ORDER BY `" + KEY_STARTED + "` ASC", new String[]{date});
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
SessionSQL session = new SessionSQL(cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ID)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STARTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_COMPLETED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_LENGTH)), cursor.getString(cursor
|
||||
.getColumnIndex(KEY_MESSAGE)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_ISPOSTED)), cursor.getLong(cursor
|
||||
.getColumnIndex(KEY_STREAKDAY)));
|
||||
|
||||
sessionList.add(session);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
||||
return sessionList;
|
||||
}
|
||||
}
|
|
@ -54,7 +54,7 @@ public class MediNETTask extends AsyncTask<MediNET, Integer, MediNET> {
|
|||
+ appVersion + "&am="
|
||||
+ getMeditationAssistant().getMarketName() + "&avn="
|
||||
+ String.valueOf(getMeditationAssistant().getMAAppVersionNumber()) + "&buf="
|
||||
+ String.valueOf(getMeditationAssistant().getMeditationStreakBuffer()) + "&tz="
|
||||
+ String.valueOf(getMeditationAssistant().getStreakBufferSeconds()) + "&tz="
|
||||
+ TimeZone.getDefault().getID();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.app.Activity;
|
|||
import android.app.AlarmManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Application;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -16,6 +17,7 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaCas;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
|
@ -29,7 +31,14 @@ import android.provider.Settings;
|
|||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.openid.appauth.AuthorizationRequest;
|
||||
|
@ -50,12 +59,14 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
|
@ -88,7 +99,6 @@ public class MeditationAssistant extends Application {
|
|||
public UtilityMA utility = new UtilityMA();
|
||||
public UtilityAdsMA utility_ads = new UtilityAdsMA();
|
||||
public Integer previous_volume = null;
|
||||
AlertDialog alertDialog = null;
|
||||
String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";
|
||||
private String appVersion = null;
|
||||
private Boolean appFull = null;
|
||||
|
@ -105,7 +115,8 @@ public class MeditationAssistant extends Application {
|
|||
private Boolean rememberduration = null;
|
||||
private Integer meditationstreak = null;
|
||||
private long meditationstreakexpires = 0;
|
||||
public long meditationstreakbuffer = -1;
|
||||
public ArrayList<Integer> streaktime = new ArrayList<>();
|
||||
public long streakbuffer = -1;
|
||||
private long sessrunnablestarttime = 0;
|
||||
private boolean sesswassignedout = false;
|
||||
private Boolean sendusage = null;
|
||||
|
@ -120,6 +131,101 @@ public class MeditationAssistant extends Application {
|
|||
String pausedTimerHoursMinutes;
|
||||
String pausedTimerSeconds;
|
||||
|
||||
private AlertDialog sessionDialog = null;
|
||||
private int sessionDialogStartedYear = -1;
|
||||
private int sessionDialogStartedMonth = -1;
|
||||
private int sessionDialogStartedDay = -1;
|
||||
private int sessionDialogStartedHour = -1;
|
||||
private int sessionDialogStartedMinute = -1;
|
||||
private int sessionDialogCompletedYear = -1;
|
||||
private int sessionDialogCompletedMonth = -1;
|
||||
private int sessionDialogCompletedDay = -1;
|
||||
private int sessionDialogCompletedHour = -1;
|
||||
private int sessionDialogCompletedMinute = -1;
|
||||
private String sessionDialogCurrentOption = "";
|
||||
private Button sessionDialogStartedDateButton = null;
|
||||
private Button sessionDialogStartedTimeButton = null;
|
||||
private Button sessionDialogCompletedDateButton = null;
|
||||
private Button sessionDialogCompletedTimeButton = null;
|
||||
private EditText sessionDialogMessage = null;
|
||||
private DatePickerDialog.OnDateSetListener sessionDialogDateSetListener =
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year,
|
||||
int monthOfYear, int dayOfMonth) {
|
||||
if (sessionDialogCurrentOption.equals("started")) {
|
||||
sessionDialogStartedYear = year;
|
||||
sessionDialogStartedMonth = monthOfYear;
|
||||
sessionDialogStartedDay = dayOfMonth;
|
||||
|
||||
if (sessionDialogCompletedYear == -1 || sessionDialogCompletedMonth == -1 || sessionDialogCompletedDay == -1) {
|
||||
sessionDialogCompletedYear = sessionDialogStartedYear;
|
||||
sessionDialogCompletedMonth = sessionDialogStartedMonth;
|
||||
sessionDialogCompletedDay = sessionDialogStartedDay;
|
||||
} else if (sessionDialogCompletedYear != -1 && sessionDialogCompletedMonth != -1 && sessionDialogCompletedDay != -1) {
|
||||
Calendar c_started = Calendar.getInstance();
|
||||
c_started.set(Calendar.YEAR, sessionDialogStartedYear);
|
||||
c_started.set(Calendar.MONTH, sessionDialogStartedMonth);
|
||||
c_started.set(Calendar.DAY_OF_MONTH, sessionDialogStartedDay);
|
||||
c_started.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c_started.set(Calendar.MINUTE, 0);
|
||||
c_started.set(Calendar.SECOND, 0);
|
||||
c_started.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Calendar c_completed = Calendar.getInstance();
|
||||
c_completed.set(Calendar.YEAR, sessionDialogCompletedYear);
|
||||
c_completed.set(Calendar.MONTH, sessionDialogCompletedMonth);
|
||||
c_completed.set(Calendar.DAY_OF_MONTH, sessionDialogCompletedDay);
|
||||
c_completed.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c_completed.set(Calendar.MINUTE, 0);
|
||||
c_completed.set(Calendar.SECOND, 0);
|
||||
c_completed.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
if (c_started.getTimeInMillis() > c_completed.getTimeInMillis()) {
|
||||
sessionDialogCompletedYear = sessionDialogStartedYear;
|
||||
sessionDialogCompletedMonth = sessionDialogStartedMonth;
|
||||
sessionDialogCompletedDay = sessionDialogStartedDay;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sessionDialogCompletedYear = year;
|
||||
sessionDialogCompletedMonth = monthOfYear;
|
||||
sessionDialogCompletedDay = dayOfMonth;
|
||||
}
|
||||
|
||||
updateSessionDialog();
|
||||
}
|
||||
};
|
||||
private TimePickerDialog.OnTimeSetListener sessionDialogTimeSetListener =
|
||||
new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
if (sessionDialogCurrentOption.equals("started")) {
|
||||
sessionDialogStartedHour = hourOfDay;
|
||||
sessionDialogStartedMinute = minute;
|
||||
|
||||
if (sessionDialogCompletedHour == -1 && sessionDialogCompletedMinute == -1) {
|
||||
sessionDialogCompletedHour = sessionDialogStartedHour;
|
||||
sessionDialogCompletedMinute = sessionDialogStartedMinute;
|
||||
}
|
||||
} else {
|
||||
sessionDialogCompletedHour = hourOfDay;
|
||||
sessionDialogCompletedMinute = minute;
|
||||
}
|
||||
|
||||
updateSessionDialog();
|
||||
}
|
||||
};
|
||||
|
||||
SharedPreferences.OnSharedPreferenceChangeListener sharedPrefslistener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
public void onSharedPreferenceChanged(SharedPreferences newprefs, String key) {
|
||||
if (key.equals("pref_meditationstreakbuffer")) {
|
||||
streakbuffer = -1;
|
||||
streaktime = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void setAlphaCompat(View view, float alpha) {
|
||||
view.setAlpha(alpha);
|
||||
}
|
||||
|
@ -449,13 +555,23 @@ public class MeditationAssistant extends Application {
|
|||
});
|
||||
}
|
||||
|
||||
public long getMeditationStreakBuffer() {
|
||||
if (meditationstreakbuffer < 0) {
|
||||
public ArrayList<Integer> getStreakBufferTime() {
|
||||
if (streaktime.isEmpty()) {
|
||||
String[] bufferSplit = getPrefs().getString("pref_meditationstreakbuffer", "4:00").split(":");
|
||||
meditationstreakbuffer = (Integer.valueOf(bufferSplit[0]) * 3600) + (Integer.valueOf(bufferSplit[1]) * 60);
|
||||
streaktime.add(Integer.valueOf(bufferSplit[0]));
|
||||
streaktime.add(Integer.valueOf(bufferSplit[1]));
|
||||
}
|
||||
|
||||
return meditationstreakbuffer;
|
||||
return streaktime;
|
||||
}
|
||||
|
||||
public long getStreakBufferSeconds() {
|
||||
if (streakbuffer < 0) {
|
||||
ArrayList<Integer> streakbuffertime = getStreakBufferTime();
|
||||
streakbuffer = (streakbuffertime.get(0) * 3600) + (streakbuffertime.get(1) * 60);
|
||||
}
|
||||
|
||||
return streakbuffer;
|
||||
}
|
||||
|
||||
public void recalculateMeditationStreak(Activity activity) {
|
||||
|
@ -553,7 +669,7 @@ public class MeditationAssistant extends Application {
|
|||
c_midnight_oneday.set(Calendar.MILLISECOND, 0);
|
||||
c_midnight_oneday.add(Calendar.DATE, 1); // One day
|
||||
|
||||
return (c_midnight_oneday.getTimeInMillis() / 1000) + getMeditationStreakBuffer();
|
||||
return (c_midnight_oneday.getTimeInMillis() / 1000) + getStreakBufferSeconds();
|
||||
}
|
||||
|
||||
public long getStreakExpiresTwoDaysTimestamp() {
|
||||
|
@ -565,7 +681,7 @@ public class MeditationAssistant extends Application {
|
|||
c_midnight_twodays.set(Calendar.MILLISECOND, 0);
|
||||
c_midnight_twodays.add(Calendar.DATE, 2); // Two days
|
||||
|
||||
return (c_midnight_twodays.getTimeInMillis() / 1000) + getMeditationStreakBuffer();
|
||||
return (c_midnight_twodays.getTimeInMillis() / 1000) + getStreakBufferSeconds();
|
||||
}
|
||||
|
||||
public void notifySessionsUpdated() {
|
||||
|
@ -880,6 +996,8 @@ public class MeditationAssistant extends Application {
|
|||
+ String.valueOf(Build.VERSION.SDK_INT)
|
||||
);
|
||||
|
||||
getPrefs().registerOnSharedPreferenceChangeListener(sharedPrefslistener);
|
||||
|
||||
// Reset timer to default values
|
||||
if (!getPrefs().getBoolean("pref_rememberlasttimer", true)) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
|
@ -1175,6 +1293,295 @@ public class MeditationAssistant extends Application {
|
|||
notificationManager.notify(0, notification);
|
||||
}
|
||||
|
||||
public void showSessionDialog(final SessionSQL session, Activity activity) {
|
||||
if (sessionDialog != null) {
|
||||
try {
|
||||
if (sessionDialog.isShowing()) {
|
||||
sessionDialog.dismiss();
|
||||
}
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
// Activity is not in the foreground
|
||||
}
|
||||
}
|
||||
|
||||
if (getTimeStartMeditate() > 0) {
|
||||
shortToast(getString(session._started == 0 ? R.string.addSessionMeditating : R.string.editSessionMeditating));
|
||||
return;
|
||||
}
|
||||
|
||||
sessionDialogStartedYear = -1;
|
||||
sessionDialogStartedMonth = -1;
|
||||
sessionDialogStartedDay = -1;
|
||||
sessionDialogStartedHour = -1;
|
||||
sessionDialogStartedMinute = -1;
|
||||
|
||||
sessionDialogCompletedYear = -1;
|
||||
sessionDialogCompletedMonth = -1;
|
||||
sessionDialogCompletedDay = -1;
|
||||
sessionDialogCompletedHour = -1;
|
||||
sessionDialogCompletedMinute = -1;
|
||||
|
||||
if (session._started > 0) {
|
||||
Calendar c_session_started = Calendar.getInstance();
|
||||
c_session_started.setTimeInMillis(session._started * 1000);
|
||||
sessionDialogStartedYear = c_session_started.get(Calendar.YEAR);
|
||||
sessionDialogStartedMonth = c_session_started.get(Calendar.MONTH);
|
||||
sessionDialogStartedDay = c_session_started.get(Calendar.DAY_OF_MONTH);
|
||||
sessionDialogStartedHour = c_session_started.get(Calendar.HOUR_OF_DAY);
|
||||
sessionDialogStartedMinute = c_session_started.get(Calendar.MINUTE);
|
||||
|
||||
Calendar c_session_completed = Calendar.getInstance();
|
||||
c_session_completed.setTimeInMillis(session._completed * 1000);
|
||||
sessionDialogCompletedYear = c_session_completed.get(Calendar.YEAR);
|
||||
sessionDialogCompletedMonth = c_session_completed.get(Calendar.MONTH);
|
||||
sessionDialogCompletedDay = c_session_completed.get(Calendar.DAY_OF_MONTH);
|
||||
sessionDialogCompletedHour = c_session_completed.get(Calendar.HOUR_OF_DAY);
|
||||
sessionDialogCompletedMinute = c_session_completed.get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
View sessionDialogView = LayoutInflater.from(activity).inflate(R.layout.session_dialog, (ViewGroup) activity.findViewById(R.id.sessionDialog));
|
||||
sessionDialogStartedDateButton = (Button) sessionDialogView.findViewById(R.id.sessionDialogSetDateStarted);
|
||||
sessionDialogStartedTimeButton = (Button) sessionDialogView.findViewById(R.id.sessionDialogSetTimeStarted);
|
||||
sessionDialogCompletedDateButton = (Button) sessionDialogView.findViewById(R.id.sessionDialogSetDateCompleted);
|
||||
sessionDialogCompletedTimeButton = (Button) sessionDialogView.findViewById(R.id.sessionDialogSetTimeCompleted);
|
||||
sessionDialogMessage = (EditText) sessionDialogView.findViewById(R.id.sessionDialogSetMessage);
|
||||
|
||||
sessionDialogStartedDateButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
sessionDialogCurrentOption = "started";
|
||||
DatePickerDialog dateDialog = null;
|
||||
|
||||
if (sessionDialogStartedYear == -1 || sessionDialogStartedMonth == -1 || sessionDialogStartedDay == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
dateDialog = new DatePickerDialog(activity,
|
||||
sessionDialogDateSetListener,
|
||||
c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
|
||||
} else {
|
||||
dateDialog = new DatePickerDialog(activity,
|
||||
sessionDialogDateSetListener,
|
||||
sessionDialogStartedYear, sessionDialogStartedMonth, sessionDialogStartedDay);
|
||||
}
|
||||
|
||||
dateDialog.show();
|
||||
}
|
||||
});
|
||||
sessionDialogStartedTimeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
sessionDialogCurrentOption = "started";
|
||||
TimePickerDialog timeDialog = null;
|
||||
|
||||
if (sessionDialogStartedHour == -1 || sessionDialogStartedMinute == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
timeDialog = new TimePickerDialog(activity,
|
||||
sessionDialogTimeSetListener,
|
||||
c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false);
|
||||
} else {
|
||||
timeDialog = new TimePickerDialog(activity,
|
||||
sessionDialogTimeSetListener,
|
||||
sessionDialogStartedHour, sessionDialogStartedMinute, false);
|
||||
}
|
||||
|
||||
timeDialog.show();
|
||||
}
|
||||
});
|
||||
sessionDialogCompletedDateButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
sessionDialogCurrentOption = "completed";
|
||||
DatePickerDialog dateDialog = null;
|
||||
|
||||
if (sessionDialogCompletedYear == -1 || sessionDialogCompletedMonth == -1 || sessionDialogCompletedDay == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
dateDialog = new DatePickerDialog(activity,
|
||||
sessionDialogDateSetListener,
|
||||
c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
|
||||
} else {
|
||||
dateDialog = new DatePickerDialog(activity,
|
||||
sessionDialogDateSetListener,
|
||||
sessionDialogCompletedYear, sessionDialogCompletedMonth, sessionDialogCompletedDay);
|
||||
}
|
||||
|
||||
dateDialog.show();
|
||||
}
|
||||
});
|
||||
sessionDialogCompletedTimeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
sessionDialogCurrentOption = "completed";
|
||||
TimePickerDialog timeDialog = null;
|
||||
|
||||
if (sessionDialogCompletedHour == -1 || sessionDialogCompletedMinute == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
timeDialog = new TimePickerDialog(activity,
|
||||
sessionDialogTimeSetListener,
|
||||
c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false);
|
||||
} else {
|
||||
timeDialog = new TimePickerDialog(activity,
|
||||
sessionDialogTimeSetListener,
|
||||
sessionDialogCompletedHour, sessionDialogCompletedMinute, false);
|
||||
}
|
||||
|
||||
timeDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
sessionDialog = new AlertDialog.Builder(activity)
|
||||
.setIcon(
|
||||
getResources().getDrawable(
|
||||
getTheme().obtainStyledAttributes(getMATheme(true),
|
||||
new int[]{session._started == 0 ? R.attr.actionIconNew : R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setTitle(getString(session._started == 0 ? R.string.addSession : R.string.editSession))
|
||||
.setView(sessionDialogView)
|
||||
.setPositiveButton(getString(session._started == 0 ? R.string.add : R.string.edit), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface,
|
||||
int which) {
|
||||
// Overridden later
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface,
|
||||
int which) {
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
||||
updateSessionDialog();
|
||||
sessionDialog.show();
|
||||
|
||||
Button saveButton = sessionDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (sessionDialogStartedYear == -1 || sessionDialogStartedMonth == -1 || sessionDialogStartedDay == -1 || sessionDialogStartedHour == -1 || sessionDialogStartedMinute == -1 || sessionDialogCompletedYear == -1 || sessionDialogCompletedMonth == -1 || sessionDialogCompletedDay == -1 || sessionDialogCompletedHour == -1 || sessionDialogCompletedMinute == -1) {
|
||||
shortToast(getString(R.string.invalidDateOrTime));
|
||||
} else {
|
||||
Calendar c_started = Calendar.getInstance();
|
||||
c_started.set(Calendar.YEAR, sessionDialogStartedYear);
|
||||
c_started.set(Calendar.MONTH, sessionDialogStartedMonth);
|
||||
c_started.set(Calendar.DAY_OF_MONTH, sessionDialogStartedDay);
|
||||
c_started.set(Calendar.HOUR_OF_DAY, sessionDialogStartedHour);
|
||||
c_started.set(Calendar.MINUTE, sessionDialogStartedMinute);
|
||||
c_started.set(Calendar.SECOND, 0);
|
||||
c_started.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Calendar c_completed = Calendar.getInstance();
|
||||
c_completed.set(Calendar.YEAR, sessionDialogCompletedYear);
|
||||
c_completed.set(Calendar.MONTH, sessionDialogCompletedMonth);
|
||||
c_completed.set(Calendar.DAY_OF_MONTH,sessionDialogCompletedDay);
|
||||
c_completed.set(Calendar.HOUR_OF_DAY, sessionDialogCompletedHour);
|
||||
c_completed.set(Calendar.MINUTE, sessionDialogCompletedMinute);
|
||||
c_completed.set(Calendar.SECOND, 0);
|
||||
c_completed.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
if (c_started.getTimeInMillis() > Calendar.getInstance().getTimeInMillis() || c_completed.getTimeInMillis() > Calendar.getInstance().getTimeInMillis() || c_completed.getTimeInMillis() <= c_started.getTimeInMillis()) {
|
||||
shortToast(getString(R.string.invalidDateOrTime));
|
||||
return;
|
||||
}
|
||||
|
||||
boolean sessionExists = db.getSessionByStarted(c_started.getTimeInMillis() / 1000) == null;
|
||||
if (session._started == 0) {
|
||||
if (!sessionExists) {
|
||||
getMediNET().resetSession();
|
||||
getMediNET().session.started = c_started.getTimeInMillis() / 1000;
|
||||
getMediNET().session.length = ((c_completed.getTimeInMillis() / 1000) - (c_started.getTimeInMillis() / 1000));
|
||||
getMediNET().session.completed = c_completed.getTimeInMillis() / 1000;
|
||||
getMediNET().session.message = sessionDialogMessage.getText().toString().trim();
|
||||
getMediNET().saveSession(true, false);
|
||||
|
||||
notifySessionsUpdated();
|
||||
|
||||
sessionDialog.dismiss();
|
||||
} else {
|
||||
shortToast(getString(R.string.sessionExists));
|
||||
}
|
||||
} else {
|
||||
if (sessionExists) {
|
||||
// TODO: Edit
|
||||
} else {
|
||||
// Session was updated or deleted in the background
|
||||
}
|
||||
|
||||
sessionDialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateSessionDialog() {
|
||||
if (sessionDialogStartedDateButton == null || sessionDialogCompletedDateButton == null || sessionDialogStartedTimeButton == null || sessionDialogCompletedTimeButton == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleDateFormat sdf_date = new SimpleDateFormat("MMMM d",
|
||||
Locale.getDefault());
|
||||
SimpleDateFormat sdf_time = new SimpleDateFormat("h:mm a",
|
||||
Locale.getDefault());
|
||||
|
||||
sdf_date.setTimeZone(TimeZone.getDefault());
|
||||
sdf_time.setTimeZone(TimeZone.getDefault());
|
||||
|
||||
if (sessionDialogStartedYear == -1 || sessionDialogStartedMonth == -1 || sessionDialogStartedDay == -1) {
|
||||
sessionDialogStartedDateButton.setText(getString(R.string.setDate));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.YEAR, sessionDialogStartedYear);
|
||||
c.set(Calendar.MONTH, sessionDialogStartedMonth);
|
||||
c.set(Calendar.DAY_OF_MONTH, sessionDialogStartedDay);
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c.set(Calendar.MINUTE, 0);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
sessionDialogStartedDateButton.setText(sdf_date.format(c.getTime()));
|
||||
}
|
||||
if (sessionDialogCompletedYear == -1 || sessionDialogCompletedMonth == -1 || sessionDialogCompletedDay == -1) {
|
||||
sessionDialogCompletedDateButton.setText(getString(R.string.setDate));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.YEAR, sessionDialogCompletedYear);
|
||||
c.set(Calendar.MONTH, sessionDialogCompletedMonth);
|
||||
c.set(Calendar.DAY_OF_MONTH, sessionDialogCompletedDay);
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c.set(Calendar.MINUTE, 0);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
sessionDialogCompletedDateButton.setText(sdf_date.format(c.getTime()));
|
||||
}
|
||||
|
||||
if (sessionDialogStartedHour == -1 || sessionDialogStartedMinute == -1) {
|
||||
sessionDialogStartedTimeButton.setText(getString(R.string.setTime));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, sessionDialogStartedHour);
|
||||
c.set(Calendar.MINUTE, sessionDialogStartedMinute);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
sessionDialogStartedTimeButton.setText(sdf_time.format(c.getTime()));
|
||||
}
|
||||
if (sessionDialogCompletedHour == -1 || sessionDialogCompletedMinute == -1) {
|
||||
sessionDialogCompletedTimeButton.setText(getString(R.string.setTime));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, sessionDialogCompletedHour);
|
||||
c.set(Calendar.MINUTE, sessionDialogCompletedMinute);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
sessionDialogCompletedTimeButton.setText(sdf_time.format(c.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
public AlertDialog showStaleDataDialog() {
|
||||
Log.d("MeditationAssistant", "Showing stale data dialog");
|
||||
|
||||
|
|
|
@ -50,98 +50,13 @@ public class ProgressActivity extends FragmentActivity {
|
|||
ViewPager mViewPager;
|
||||
ProgressPagerAdapter mPagerAdapter = null;
|
||||
int pagePosition = 0;
|
||||
private AlertDialog addSessionDialog = null;
|
||||
private int SESSIONS_FRAGMENT = 0;
|
||||
private int CALENDAR_FRAGMENT = 1;
|
||||
private int STATS_FRAGMENT = 2;
|
||||
private SessionsFragment sessionsFragment = null;
|
||||
private MeditationAssistant ma = null;
|
||||
private MenuItem menuCalendarBack = null;
|
||||
private MenuItem menuCalendarForward = null;
|
||||
private String beingSet = "started";
|
||||
private Button btnSetDateStarted = null;
|
||||
private Button btnSetTimeStarted = null;
|
||||
private Button btnSetDateCompleted = null;
|
||||
private Button btnSetTimeCompleted = null;
|
||||
private EditText editAddSessionMessage = null;
|
||||
private int startedYear = -1;
|
||||
private int startedMonth = -1;
|
||||
private int startedDay = -1;
|
||||
private int startedHour = -1;
|
||||
private int startedMinute = -1;
|
||||
private int completedYear = -1;
|
||||
private int completedMonth = -1;
|
||||
private int completedDay = -1;
|
||||
private int completedHour = -1;
|
||||
private int completedMinute = -1;
|
||||
private DatePickerDialog.OnDateSetListener mDateSetListener =
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year,
|
||||
int monthOfYear, int dayOfMonth) {
|
||||
if (beingSet.equals("started")) {
|
||||
startedYear = year;
|
||||
startedMonth = monthOfYear;
|
||||
startedDay = dayOfMonth;
|
||||
|
||||
if (completedYear == -1 || completedMonth == -1 || completedDay == -1) {
|
||||
completedYear = startedYear;
|
||||
completedMonth = startedMonth;
|
||||
completedDay = startedDay;
|
||||
} else if (completedYear != -1 && completedMonth != -1 && completedDay != -1) {
|
||||
Calendar c_started = Calendar.getInstance();
|
||||
c_started.set(Calendar.YEAR, startedYear);
|
||||
c_started.set(Calendar.MONTH, startedMonth);
|
||||
c_started.set(Calendar.DAY_OF_MONTH, startedDay);
|
||||
c_started.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c_started.set(Calendar.MINUTE, 0);
|
||||
c_started.set(Calendar.SECOND, 0);
|
||||
c_started.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Calendar c_completed = Calendar.getInstance();
|
||||
c_completed.set(Calendar.YEAR, completedYear);
|
||||
c_completed.set(Calendar.MONTH, completedMonth);
|
||||
c_completed.set(Calendar.DAY_OF_MONTH, completedDay);
|
||||
c_completed.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c_completed.set(Calendar.MINUTE, 0);
|
||||
c_completed.set(Calendar.SECOND, 0);
|
||||
c_completed.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
if (c_started.getTimeInMillis() > c_completed.getTimeInMillis()) {
|
||||
completedYear = startedYear;
|
||||
completedMonth = startedMonth;
|
||||
completedDay = startedDay;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
completedYear = year;
|
||||
completedMonth = monthOfYear;
|
||||
completedDay = dayOfMonth;
|
||||
}
|
||||
|
||||
updateDateAndTimeButtons();
|
||||
}
|
||||
};
|
||||
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
|
||||
new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
if (beingSet.equals("started")) {
|
||||
startedHour = hourOfDay;
|
||||
startedMinute = minute;
|
||||
|
||||
if (completedHour == -1 && completedMinute == -1) {
|
||||
completedHour = startedHour;
|
||||
completedMinute = startedMinute;
|
||||
}
|
||||
} else {
|
||||
completedHour = hourOfDay;
|
||||
completedMinute = minute;
|
||||
}
|
||||
|
||||
updateDateAndTimeButtons();
|
||||
}
|
||||
};
|
||||
private AlertDialog sessionsExportedDialog = null;
|
||||
private AlertDialog sessionDetailsDialog = null;
|
||||
|
||||
|
@ -152,76 +67,13 @@ public class ProgressActivity extends FragmentActivity {
|
|||
return ma;
|
||||
}
|
||||
|
||||
public void updateDateAndTimeButtons() {
|
||||
SimpleDateFormat sdf_date = new SimpleDateFormat("MMMM d",
|
||||
Locale.getDefault());
|
||||
SimpleDateFormat sdf_time = new SimpleDateFormat("h:mm a",
|
||||
Locale.getDefault());
|
||||
|
||||
sdf_date.setTimeZone(TimeZone.getDefault());
|
||||
sdf_time.setTimeZone(TimeZone.getDefault());
|
||||
|
||||
if (startedYear == -1 || startedMonth == -1 || startedDay == -1) {
|
||||
btnSetDateStarted.setText(getString(R.string.setDate));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.YEAR, startedYear);
|
||||
c.set(Calendar.MONTH, startedMonth);
|
||||
c.set(Calendar.DAY_OF_MONTH, startedDay);
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c.set(Calendar.MINUTE, 0);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
btnSetDateStarted.setText(sdf_date.format(c.getTime()));
|
||||
}
|
||||
if (completedYear == -1 || completedMonth == -1 || completedDay == -1) {
|
||||
btnSetDateCompleted.setText(getString(R.string.setDate));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.YEAR, completedYear);
|
||||
c.set(Calendar.MONTH, completedMonth);
|
||||
c.set(Calendar.DAY_OF_MONTH, completedDay);
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c.set(Calendar.MINUTE, 0);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
btnSetDateCompleted.setText(sdf_date.format(c.getTime()));
|
||||
}
|
||||
|
||||
if (startedHour == -1 || startedMinute == -1) {
|
||||
btnSetTimeStarted.setText(getString(R.string.setTime));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, startedHour);
|
||||
c.set(Calendar.MINUTE, startedMinute);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
btnSetTimeStarted.setText(sdf_time.format(c.getTime()));
|
||||
}
|
||||
if (completedHour == -1 || completedMinute == -1) {
|
||||
btnSetTimeCompleted.setText(getString(R.string.setTime));
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, completedHour);
|
||||
c.set(Calendar.MINUTE, completedMinute);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
btnSetTimeCompleted.setText(sdf_time.format(c.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setTheme(getMeditationAssistant().getMATheme());
|
||||
setContentView(R.layout.activity_progress);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true); /// todo: not necessary on settings activity why?
|
||||
//getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
getMeditationAssistant().utility_ads.loadAd(this);
|
||||
|
||||
|
@ -232,33 +84,6 @@ public class ProgressActivity extends FragmentActivity {
|
|||
|
||||
mViewPager.setAdapter(mPagerAdapter);
|
||||
|
||||
/*ActionBar.TabListener tabListener = new ActionBar.TabListener() {
|
||||
|
||||
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
// hide the given tab
|
||||
}
|
||||
|
||||
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
// probably ignore this event
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
getActionBar().addTab(getActionBar().newTab()
|
||||
.setText(getString(R.string.sessions))
|
||||
.setTabListener(tabListener));
|
||||
getActionBar().addTab(getActionBar().newTab()
|
||||
.setText(getString(R.string.statistics))
|
||||
.setTabListener(tabListener));
|
||||
|
||||
getActionBar().addTab(getActionBar().newTab()
|
||||
.setText(getString(R.string.calendar))
|
||||
.setTabListener(tabListener));*/
|
||||
|
||||
PagerTabStrip tabStrip = (PagerTabStrip) findViewById(R.id.titles);
|
||||
tabStrip.setDrawFullUnderline(true);
|
||||
|
||||
|
@ -270,32 +95,6 @@ public class ProgressActivity extends FragmentActivity {
|
|||
tabStrip.setTabIndicatorColor(getResources().getColor(android.R.color.holo_blue_dark));
|
||||
}
|
||||
|
||||
|
||||
/*ViewPagerIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
|
||||
titleIndicator.setViewPager(mViewPager);
|
||||
|
||||
titleIndicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
|
||||
|
||||
titleIndicator
|
||||
.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position,
|
||||
float positionOffset, int positionOffsetPixels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (menuCalendarBack != null
|
||||
&& menuCalendarForward != null) {
|
||||
pagePosition = position;
|
||||
}
|
||||
}
|
||||
});*/
|
||||
|
||||
String defaulttab = getMeditationAssistant().getPrefs().getString(
|
||||
"pref_progresstab", "calendar");
|
||||
if (defaulttab.equals("sessions")) {
|
||||
|
@ -311,7 +110,14 @@ public class ProgressActivity extends FragmentActivity {
|
|||
|
||||
public void goToSessionAtDate(int[] date) {
|
||||
if (date != null) {
|
||||
SessionSQL sessionsql = getMeditationAssistant().db.getSessionByDate(String.valueOf(date[0]) + "-" + String.valueOf(date[1] + 1) + "-" + String.valueOf(date[2]));
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.DAY_OF_MONTH, date[0]);
|
||||
c.set(Calendar.MONTH, date[1]);
|
||||
c.set(Calendar.YEAR, date[2]);
|
||||
|
||||
Log.d("MeditationAssistant", "Req date " + String.valueOf(date[0]) + " " + String.valueOf(date[1]) + " " + String.valueOf(date[2]) + " " + " - Proc date " + String.valueOf(c.getTimeInMillis() / 1000));
|
||||
|
||||
SessionSQL sessionsql = getMeditationAssistant().db.getSessionByDate(c);
|
||||
if (sessionsql != null) {
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(sessionsql._completed * 1000);
|
||||
|
@ -327,7 +133,7 @@ public class ProgressActivity extends FragmentActivity {
|
|||
SimpleDateFormat sdf2 = new SimpleDateFormat("h:mm a",
|
||||
Locale.getDefault());
|
||||
|
||||
ArrayList<SessionSQL> sessions = getMeditationAssistant().db.getSessionsByDate(String.valueOf(date[0]) + "-" + String.valueOf(date[1] + 1) + "-" + String.valueOf(date[2]));
|
||||
ArrayList<SessionSQL> sessions = getMeditationAssistant().db.getSessionsByDate(c);
|
||||
|
||||
final ArrayAdapter<String> sessionsDialogAdapter = new ArrayAdapter<String>(
|
||||
this,
|
||||
|
@ -383,13 +189,6 @@ public class ProgressActivity extends FragmentActivity {
|
|||
} else {
|
||||
showSessionPopup(sessionsql);
|
||||
}
|
||||
|
||||
/*mViewPager.setCurrentItem(SESSIONS_FRAGMENT, false);
|
||||
Integer session_position = ((SessionAdapter) sessionsFragment.getListAdapter()).sessions_map.get(String.valueOf(date[0]) + "-" + String.valueOf(date[1] + 1) + "-" + String.valueOf(date[2]));
|
||||
if (session_position != null) {
|
||||
Log.d("MeditationAssistant", "Position: " + String.valueOf(session_position));
|
||||
sessionsFragment.getListView().smoothScrollToPosition(session_position);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -534,209 +333,7 @@ public class ProgressActivity extends FragmentActivity {
|
|||
sessionsExportedDialog.show();
|
||||
}
|
||||
} else if (i == R.id.addSession) {
|
||||
if (addSessionDialog != null) {
|
||||
try {
|
||||
if (addSessionDialog.isShowing()) {
|
||||
addSessionDialog.dismiss();
|
||||
}
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
// Activity is not in the foreground
|
||||
}
|
||||
}
|
||||
|
||||
//debug
|
||||
|
||||
if (getMeditationAssistant()
|
||||
.getTimeStartMeditate() > 0) {
|
||||
getMeditationAssistant().shortToast(getString(R.string.addSessionMeditating));
|
||||
return true;
|
||||
}
|
||||
|
||||
startedYear = -1;
|
||||
startedMonth = -1;
|
||||
startedDay = -1;
|
||||
startedHour = -1;
|
||||
startedMinute = -1;
|
||||
|
||||
completedYear = -1;
|
||||
completedMonth = -1;
|
||||
completedDay = -1;
|
||||
completedHour = -1;
|
||||
completedMinute = -1;
|
||||
|
||||
View addSessionView = LayoutInflater.from(this).inflate(
|
||||
R.layout.session_add,
|
||||
(ViewGroup) findViewById(R.id.sessionAdd_root));
|
||||
|
||||
btnSetDateStarted = (Button) addSessionView.findViewById(R.id.btnSetDateStarted);
|
||||
btnSetTimeStarted = (Button) addSessionView.findViewById(R.id.btnSetTimeStarted);
|
||||
btnSetDateCompleted = (Button) addSessionView.findViewById(R.id.btnSetDateCompleted);
|
||||
btnSetTimeCompleted = (Button) addSessionView.findViewById(R.id.btnSetTimeCompleted);
|
||||
editAddSessionMessage = (EditText) addSessionView.findViewById(R.id.editAddSessionMessage);
|
||||
|
||||
btnSetDateStarted.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
beingSet = "started";
|
||||
DatePickerDialog dateDialog = null;
|
||||
|
||||
if (startedYear == -1 || startedMonth == -1 || startedDay == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
dateDialog = new DatePickerDialog(ProgressActivity.this,
|
||||
mDateSetListener,
|
||||
c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
|
||||
} else {
|
||||
dateDialog = new DatePickerDialog(ProgressActivity.this,
|
||||
mDateSetListener,
|
||||
startedYear, startedMonth, startedDay);
|
||||
}
|
||||
|
||||
dateDialog.show();
|
||||
}
|
||||
});
|
||||
btnSetTimeStarted.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
beingSet = "started";
|
||||
TimePickerDialog timeDialog = null;
|
||||
|
||||
if (startedHour == -1 || startedMinute == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
timeDialog = new TimePickerDialog(ProgressActivity.this,
|
||||
mTimeSetListener,
|
||||
c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false);
|
||||
} else {
|
||||
timeDialog = new TimePickerDialog(ProgressActivity.this,
|
||||
mTimeSetListener,
|
||||
startedHour, startedMinute, false);
|
||||
}
|
||||
|
||||
timeDialog.show();
|
||||
}
|
||||
});
|
||||
btnSetDateCompleted.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
beingSet = "completed";
|
||||
DatePickerDialog dateDialog = null;
|
||||
|
||||
if (completedYear == -1 || completedMonth == -1 || completedDay == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
dateDialog = new DatePickerDialog(ProgressActivity.this,
|
||||
mDateSetListener,
|
||||
c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
|
||||
} else {
|
||||
dateDialog = new DatePickerDialog(ProgressActivity.this,
|
||||
mDateSetListener,
|
||||
completedYear, completedMonth, completedDay);
|
||||
}
|
||||
|
||||
dateDialog.show();
|
||||
}
|
||||
});
|
||||
btnSetTimeCompleted.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
beingSet = "completed";
|
||||
TimePickerDialog timeDialog = null;
|
||||
|
||||
if (completedHour == -1 || completedMinute == -1) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
timeDialog = new TimePickerDialog(ProgressActivity.this,
|
||||
mTimeSetListener,
|
||||
c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false);
|
||||
} else {
|
||||
timeDialog = new TimePickerDialog(ProgressActivity.this,
|
||||
mTimeSetListener,
|
||||
completedHour, completedMinute, false);
|
||||
}
|
||||
|
||||
timeDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
updateDateAndTimeButtons();
|
||||
|
||||
addSessionDialog = new AlertDialog.Builder(this)
|
||||
.setIcon(
|
||||
getResources().getDrawable(
|
||||
getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true),
|
||||
new int[]{R.attr.actionIconNew})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setTitle(getString(R.string.addSession))
|
||||
.setView(addSessionView)
|
||||
.setPositiveButton(getString(R.string.add), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface,
|
||||
int which) {
|
||||
// Overridden later
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface,
|
||||
int which) {
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
||||
addSessionDialog.show();
|
||||
|
||||
Button saveButton = addSessionDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (startedYear == -1 || startedMonth == -1 || startedDay == -1 || startedHour == -1 || startedMinute == -1 || completedYear == -1 || completedMonth == -1 || completedDay == -1 || completedHour == -1 || completedMinute == -1) {
|
||||
getMeditationAssistant().shortToast(getString(R.string.invalidDateOrTime));
|
||||
} else {
|
||||
Calendar c_started = Calendar.getInstance();
|
||||
c_started.set(Calendar.YEAR, startedYear);
|
||||
c_started.set(Calendar.MONTH, startedMonth);
|
||||
c_started.set(Calendar.DAY_OF_MONTH, startedDay);
|
||||
c_started.set(Calendar.HOUR_OF_DAY, startedHour);
|
||||
c_started.set(Calendar.MINUTE, startedMinute);
|
||||
c_started.set(Calendar.SECOND, 0);
|
||||
c_started.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Calendar c_completed = Calendar.getInstance();
|
||||
c_completed.set(Calendar.YEAR, completedYear);
|
||||
c_completed.set(Calendar.MONTH, completedMonth);
|
||||
c_completed.set(Calendar.DAY_OF_MONTH, completedDay);
|
||||
c_completed.set(Calendar.HOUR_OF_DAY, completedHour);
|
||||
c_completed.set(Calendar.MINUTE, completedMinute);
|
||||
c_completed.set(Calendar.SECOND, 0);
|
||||
c_completed.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
if (c_started.getTimeInMillis() > Calendar.getInstance().getTimeInMillis() || c_completed.getTimeInMillis() > Calendar.getInstance().getTimeInMillis() || c_completed.getTimeInMillis() <= c_started.getTimeInMillis()) {
|
||||
getMeditationAssistant().shortToast(getString(R.string.invalidDateOrTime));
|
||||
} else if (getMeditationAssistant().db
|
||||
.getSessionByStarted(c_started.getTimeInMillis() / 1000) == null) {
|
||||
getMeditationAssistant().getMediNET().resetSession();
|
||||
getMeditationAssistant().getMediNET().session.started = c_started.getTimeInMillis() / 1000;
|
||||
getMeditationAssistant().getMediNET().session.length = ((c_completed.getTimeInMillis() / 1000) - (c_started.getTimeInMillis() / 1000));
|
||||
getMeditationAssistant().getMediNET().session.completed = c_completed.getTimeInMillis() / 1000;
|
||||
getMeditationAssistant().getMediNET().session.message = editAddSessionMessage.getText().toString().trim();
|
||||
getMeditationAssistant().getMediNET().saveSession(true, false);
|
||||
|
||||
addSessionDialog.dismiss();
|
||||
|
||||
if (sessionsFragment != null) {
|
||||
sessionsFragment.refreshSessionList();
|
||||
}
|
||||
|
||||
/*if (calendarFragment != null) {
|
||||
calendarFragment.refreshMonthDisplay();
|
||||
}*/
|
||||
} else {
|
||||
getMeditationAssistant().shortToast(getString(R.string.addSessionExists));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
getMeditationAssistant().showSessionDialog(new SessionSQL(), ProgressActivity.this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -808,60 +405,3 @@ public class ProgressActivity extends FragmentActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public class ProgressActivity extends FragmentActivity
|
||||
implements ItemListFragment.Callbacks {
|
||||
|
||||
/**
|
||||
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
|
||||
* device.
|
||||
private boolean mTwoPane;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_item_list);
|
||||
|
||||
if (findViewById(R.id.item_detail_container) != null) {
|
||||
// The detail container view will be present only in the
|
||||
// large-screen layouts (res/values-large and
|
||||
// res/values-sw600dp). If this view is present, then the
|
||||
// activity should be in two-pane mode.
|
||||
mTwoPane = true;
|
||||
|
||||
// In two-pane mode, list items should be given the
|
||||
// 'activated' state when touched.
|
||||
((ItemListFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.item_list))
|
||||
.setActivateOnItemClick(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback method from {@link ItemListFragment.Callbacks}
|
||||
* indicating that the item with the given ID was selected.
|
||||
@Override
|
||||
public void onItemSelected(String id) {
|
||||
if (mTwoPane) {
|
||||
// In two-pane mode, show the detail view in this activity by
|
||||
// adding or replacing the detail fragment using a
|
||||
// fragment transaction.
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putString(ItemDetailFragment.ARG_ITEM_ID, id);
|
||||
ItemDetailFragment fragment = new ItemDetailFragment();
|
||||
fragment.setArguments(arguments);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.item_detail_container, fragment)
|
||||
.apply();
|
||||
|
||||
} else {
|
||||
// In single-pane mode, simply start the detail activity
|
||||
// for the selected item ID.
|
||||
Intent detailIntent = new Intent(this, ItemDetailActivity.class);
|
||||
detailIntent.putExtra(ItemDetailFragment.ARG_ITEM_ID, id);
|
||||
startActivity(detailIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -10,6 +10,13 @@ public class SessionSQL {
|
|||
public Long _streakday;
|
||||
|
||||
public SessionSQL() {
|
||||
this._id = (long)0;
|
||||
this._started = (long)0;
|
||||
this._completed = (long)0;
|
||||
this._length = (long)0;
|
||||
this._message = "";
|
||||
this._isposted = (long)0;
|
||||
this._streakday = (long)0;
|
||||
}
|
||||
|
||||
public SessionSQL(Long id, Long started, Long completed, Long length, String message,
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.TimeZone;
|
|||
public class SessionsFragment extends ListFragment {
|
||||
public MeditationAssistant ma = null;
|
||||
AlertDialog sessionDialog = null;
|
||||
AlertDialog sessionDetailsDialog = null;
|
||||
SessionSQL selected_session = null;
|
||||
String session_title = null;
|
||||
String session_started = null;
|
||||
|
@ -56,16 +55,6 @@ public class SessionsFragment extends ListFragment {
|
|||
getListView().setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(android.widget.AdapterView<?> adapterView, View view, int position, long id) {
|
||||
if (sessionDetailsDialog != null) {
|
||||
try {
|
||||
if (sessionDetailsDialog.isShowing()) {
|
||||
sessionDetailsDialog.dismiss();
|
||||
}
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
// Activity is not in the foreground
|
||||
}
|
||||
}
|
||||
|
||||
if (sessionDialog != null) {
|
||||
try {
|
||||
if (sessionDialog.isShowing()) {
|
||||
|
@ -77,8 +66,6 @@ public class SessionsFragment extends ListFragment {
|
|||
}
|
||||
|
||||
selected_session = (SessionSQL) getListView().getItemAtPosition(position);
|
||||
setSessionDialogDetails();
|
||||
|
||||
sessionDialog = new AlertDialog.Builder(getActivity())
|
||||
.setIcon(
|
||||
getActivity().getResources().getDrawable(
|
||||
|
@ -93,7 +80,7 @@ public class SessionsFragment extends ListFragment {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) {
|
||||
if (which == 0) {
|
||||
if (which == 0) { // Post
|
||||
if (getMeditationAssistant()
|
||||
.getTimeStartMeditate() > 0) {
|
||||
getActivity().runOnUiThread(
|
||||
|
@ -115,7 +102,7 @@ public class SessionsFragment extends ListFragment {
|
|||
.postSession(true,
|
||||
getActivity());
|
||||
}
|
||||
} else {
|
||||
} else { // Delete
|
||||
AlertDialog deleteDialog = new AlertDialog.Builder(
|
||||
getActivity())
|
||||
.setIcon(
|
||||
|
@ -177,16 +164,6 @@ public class SessionsFragment extends ListFragment {
|
|||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
if (sessionDetailsDialog != null) {
|
||||
try {
|
||||
if (sessionDetailsDialog.isShowing()) {
|
||||
sessionDetailsDialog.dismiss();
|
||||
}
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
// Activity is not in the foreground
|
||||
}
|
||||
}
|
||||
|
||||
if (sessionDialog != null) {
|
||||
try {
|
||||
if (sessionDialog.isShowing()) {
|
||||
|
@ -198,65 +175,11 @@ public class SessionsFragment extends ListFragment {
|
|||
}
|
||||
|
||||
selected_session = (SessionSQL) l.getItemAtPosition(position);
|
||||
setSessionDialogDetails();
|
||||
|
||||
View detailsView = LayoutInflater.from(getActivity()).inflate(
|
||||
R.layout.session_details,
|
||||
(ViewGroup) getActivity().findViewById(R.id.sessionDetails_root));
|
||||
|
||||
TextView txtSessionDetailsStarted = (TextView) detailsView.findViewById(R.id.txtSessionDetailsStarted);
|
||||
TextView txtSessionDetailsMessage = (TextView) detailsView.findViewById(R.id.txtSessionDetailsMessage);
|
||||
|
||||
txtSessionDetailsStarted.setText(String.format(getString(R.string.sessionStartedAt), session_started));
|
||||
|
||||
if (!selected_session._message.trim().equals("")) {
|
||||
txtSessionDetailsMessage.setText(selected_session._message.trim());
|
||||
} else {
|
||||
View divSessionDetailsMessage = detailsView.findViewById(R.id.divSessionDetailsMessage);
|
||||
|
||||
divSessionDetailsMessage.setVisibility(View.GONE);
|
||||
txtSessionDetailsMessage.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
sessionDetailsDialog = new AlertDialog.Builder(getActivity())
|
||||
.setIcon(
|
||||
getActivity().getResources().getDrawable(
|
||||
getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true),
|
||||
new int[]{R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setTitle(session_title)
|
||||
.setView(detailsView)
|
||||
.create();
|
||||
|
||||
sessionDetailsDialog.show();
|
||||
}
|
||||
|
||||
private void setSessionDialogDetails() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("d MMM yyyy h:mm a",
|
||||
Locale.getDefault());
|
||||
sdf.setTimeZone(TimeZone.getDefault());
|
||||
|
||||
SimpleDateFormat sdf2 = new SimpleDateFormat("h:mm a",
|
||||
Locale.getDefault());
|
||||
sdf2.setTimeZone(TimeZone.getDefault());
|
||||
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(selected_session._completed * 1000);
|
||||
Date date = cal.getTime();
|
||||
|
||||
session_title = String.valueOf(selected_session._length / 3600) + ":"
|
||||
+ String.format("%02d", (selected_session._length % 3600) / 60)
|
||||
+ " - " + sdf.format(date);
|
||||
|
||||
cal.setTimeInMillis(selected_session._started * 1000);
|
||||
session_started = sdf2.format(cal.getTime());
|
||||
getMeditationAssistant().showSessionDialog(selected_session, getActivity());
|
||||
}
|
||||
|
||||
public void refreshSessionList() {
|
||||
setListAdapter(new SessionAdapter(getActivity(),
|
||||
getMeditationAssistant().db.getAllSessions()));
|
||||
setListAdapter(new SessionAdapter(getActivity(), getMeditationAssistant().db.getAllSessions()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -224,8 +224,6 @@ public class SettingsActivity extends PreferenceActivity {
|
|||
Intent intent = new Intent();
|
||||
intent.setAction(MeditationAssistant.ACTION_UPDATED);
|
||||
sendBroadcast(intent);
|
||||
} else {
|
||||
getMeditationAssistant().meditationstreakbuffer = -1;
|
||||
}
|
||||
} else { // pref_session_delay and pref_session_interval
|
||||
Log.d("MeditationAssistant", preference.getKey() + " value: " + String.valueOf(stringValue));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<RelativeLayout
|
||||
android:id="@+id/sessionAdd_root"
|
||||
android:id="@+id/sessionDialog"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -31,7 +31,7 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSetDateStarted"
|
||||
android:id="@+id/sessionDialogSetDateStarted"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
|
@ -52,7 +52,7 @@
|
|||
android:background="?android:attr/listDivider"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSetTimeStarted"
|
||||
android:id="@+id/sessionDialogSetTimeStarted"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
|
@ -101,7 +101,7 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSetDateCompleted"
|
||||
android:id="@+id/sessionDialogSetDateCompleted"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
|
@ -121,7 +121,7 @@
|
|||
android:background="?android:attr/listDivider"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSetTimeCompleted"
|
||||
android:id="@+id/sessionDialogSetTimeCompleted"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
|
@ -164,7 +164,7 @@
|
|||
android:background="?android:attr/listDivider"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editAddSessionMessage"
|
||||
android:id="@+id/sessionDialogSetMessage"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="top"
|
||||
|
@ -172,8 +172,8 @@
|
|||
android:inputType="textMultiLine"
|
||||
android:lines="2"
|
||||
android:maxLength="160"
|
||||
android:nextFocusLeft="@+id/addSessionMessage"
|
||||
android:nextFocusUp="@+id/addSessionMessage"
|
||||
android:nextFocusLeft="@+id/sessionDialogSetMessage"
|
||||
android:nextFocusUp="@+id/sessionDialogSetMessage"
|
||||
android:scrollbars="vertical"
|
||||
android:singleLine="false"
|
||||
android:text=""
|
|
@ -118,7 +118,9 @@
|
|||
<string name="daySaturdayShort">Sat</string>
|
||||
<string name="daySundayShort">Sun</string>
|
||||
<string name="addSession">Add session</string>
|
||||
<string name="editSession">Edit session</string>
|
||||
<string name="add">Add</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="exportSessions">Export sessions</string>
|
||||
<string name="sessionExportFailed">Unable to export sessions</string>
|
||||
<string name="showExportedSessions">Sessions exported. Would you like to browse the folder containing the export?</string>
|
||||
|
@ -129,7 +131,8 @@
|
|||
<string name="setTime">Set time</string>
|
||||
<string name="invalidDateOrTime">Invalid date or time</string>
|
||||
<string name="addSessionMeditating">Unable to add a session while meditating</string>
|
||||
<string name="addSessionExists">Session already exists</string>
|
||||
<string name="editSessionMeditating">Unable to edit a session while meditating</string>
|
||||
<string name="sessionExists">Session already exists</string>
|
||||
|
||||
<string name="days">Days</string>
|
||||
<string name="hours">Hours</string>
|
||||
|
|
Loading…
Reference in New Issue