Skip to content

Commit 4ab5494

Browse files
committed
fixed alarm set time ...still looping though
1 parent 09510bb commit 4ab5494

File tree

5 files changed

+65
-11
lines changed

5 files changed

+65
-11
lines changed

app/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ apply plugin: 'com.neenbedankt.android-apt'
1515

1616

1717
android {
18+
defaultConfig{
19+
multiDexEnabled true
20+
}
1821
/*
1922
signingConfigs {
2023
config {
@@ -39,11 +42,12 @@ android {
3942
}
4043
buildTypes {
4144
release {
42-
minifyEnabled false
45+
minifyEnabled true
4346
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4447
}
4548
debug {
4649
applicationIdSuffix ".debug"
50+
4751
}
4852
}
4953
}
@@ -72,4 +76,5 @@ dependencies {
7276
compile 'com.google.android.gms:play-services:10.0.1'
7377
compile 'agency.tango.android:material-intro-screen:0.0.5'
7478
testCompile 'junit:junit:4.12'
79+
7580
}

app/src/main/java/com/haayhappen/clockplus/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void onClick(View view) {
7474
getSupportActionBar().setTitle(getString(R.string.app_name));
7575

7676
//TODO delete when published
77-
startActivity(new Intent(this, IntroActivity.class));
77+
//startActivity(new Intent(this, IntroActivity.class));
7878
//Intro
7979
prefs = getSharedPreferences("com.haayhappen.clockplus", MODE_PRIVATE);
8080
}

app/src/main/java/com/haayhappen/clockplus/alarms/ui/ExpandedAlarmViewHolder.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
import android.net.Uri;
2525
import android.os.Vibrator;
2626
import android.support.annotation.IdRes;
27+
import android.support.annotation.Nullable;
2728
import android.support.v4.graphics.drawable.DrawableCompat;
29+
import android.text.format.DateUtils;
30+
import android.text.format.Time;
2831
import android.util.Log;
2932
import android.view.View;
3033
import android.view.ViewGroup;
@@ -50,6 +53,10 @@
5053
import com.haayhappen.clockplus.timepickers.Utils;
5154
import com.haayhappen.clockplus.util.FragmentTagUtils;
5255

56+
import java.text.ParseException;
57+
import java.text.SimpleDateFormat;
58+
import java.util.Calendar;
59+
import java.util.Date;
5360
import java.util.concurrent.TimeUnit;
5461

5562
import butterknife.Bind;
@@ -286,7 +293,7 @@ void onClearTo() {
286293
duration.setText("");
287294
final Alarm oldAlarm = getAlarm();
288295
Alarm newAlarm = oldAlarm.toBuilder()
289-
.destination(new Location("",0,0))
296+
.destination(new Location("", 0, 0))
290297
.build();
291298
oldAlarm.copyMutableFieldsTo(newAlarm);
292299
persistUpdatedAlarm(newAlarm, false);
@@ -299,21 +306,50 @@ void onDurationClicked() {
299306

300307
private void setDuration() {
301308
Log.d(TAG, "set duration");
302-
DistanceHandler asyncTask = new DistanceHandler(getAlarm(),new DistanceHandler.AsyncResponse() {
309+
DistanceHandler asyncTask = new DistanceHandler(getAlarm(), new DistanceHandler.AsyncResponse() {
303310
@Override
304311
public void processFinish(long delaySecs) {
305-
//#################new############
306-
int min = (int)TimeUnit.SECONDS.toMinutes(delaySecs);
312+
int testseconds = 4000;
307313
final Alarm oldAlarm = getAlarm();
308-
int oldmin = oldAlarm.minutes();
309-
int newmin = oldmin - min;
314+
int delayMinutes = (int) TimeUnit.SECONDS.toMinutes(testseconds);
315+
int delayHours = delayMinutes / 60;
316+
delayMinutes = delayMinutes % 60;
317+
318+
319+
Date d = new Date();
320+
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
321+
try {
322+
d = sdf.parse(oldAlarm.hour() + ":" + oldAlarm.minutes());
323+
} catch (ParseException e) {
324+
e.printStackTrace();
325+
}
326+
327+
//TODO remove all debug logs for production
328+
Calendar cal = Calendar.getInstance();
329+
cal.setTime(d);
330+
Log.d("ExpandedAlarmViewHolder","calendar time before new set: "+cal.getTime().toString());
331+
Log.d("ExpandedAlarmViewHolder","hours to be subtracted: "+delayHours);
332+
Log.d("ExpandedAlarmViewHolder","minutes to be subtracted: "+delayMinutes);
333+
334+
if (delayHours == 0){
335+
cal.add(Calendar.MINUTE, -Math.abs(delayMinutes));
336+
}else{
337+
cal.add(Calendar.HOUR_OF_DAY,-Math.abs(delayHours));
338+
cal.add(Calendar.MINUTE,-Math.abs(delayMinutes));
339+
}
340+
341+
Log.d("ExpandedAlarmViewHolder","calendar time after set: "+cal.getTime().toString());
342+
Log.d("ExpandedAlarmViewHolder","setting new hours to: "+cal.get(Calendar.HOUR_OF_DAY));
343+
Log.d("ExpandedAlarmViewHolder","setting new minutes to: "+cal.get(Calendar.MINUTE));
344+
310345
Alarm newAlarm = oldAlarm.toBuilder()
311-
.minutes(newmin)
346+
.minutes(cal.get(Calendar.MINUTE))
347+
.hour(cal.get(Calendar.HOUR_OF_DAY))
312348
.build();
313349
oldAlarm.copyMutableFieldsTo(newAlarm);
314350
persistUpdatedAlarm(newAlarm, false);
315351
//#############################
316-
duration.setText(String.valueOf(min)+"delay");
352+
duration.setText(String.valueOf(delayMinutes) + "delay");
317353
}
318354
});
319355

app/src/main/java/com/haayhappen/clockplus/util/TimeFormatUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,23 @@ public final class TimeFormatUtils {
3030

3131
private TimeFormatUtils() {}
3232

33+
/**
34+
*
35+
* @param context
36+
* @param millis
37+
* @return String time
38+
*/
3339
public static String formatTime(Context context, long millis) {
3440
return getTimeFormat(context).format(new Date(millis));
3541
}
3642

43+
/**
44+
*
45+
* @param context
46+
* @param hourOfDay
47+
* @param minute
48+
* @return String time
49+
*/
3750
public static String formatTime(Context context, int hourOfDay, int minute) {
3851
Calendar cal = Calendar.getInstance();
3952
cal.set(Calendar.HOUR_OF_DAY, hourOfDay);

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.3.0'
9+
classpath 'com.android.tools.build:gradle:2.3.3'
1010
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files

0 commit comments

Comments
 (0)