24
24
import android .net .Uri ;
25
25
import android .os .Vibrator ;
26
26
import android .support .annotation .IdRes ;
27
+ import android .support .annotation .Nullable ;
27
28
import android .support .v4 .graphics .drawable .DrawableCompat ;
29
+ import android .text .format .DateUtils ;
30
+ import android .text .format .Time ;
28
31
import android .util .Log ;
29
32
import android .view .View ;
30
33
import android .view .ViewGroup ;
50
53
import com .haayhappen .clockplus .timepickers .Utils ;
51
54
import com .haayhappen .clockplus .util .FragmentTagUtils ;
52
55
56
+ import java .text .ParseException ;
57
+ import java .text .SimpleDateFormat ;
58
+ import java .util .Calendar ;
59
+ import java .util .Date ;
53
60
import java .util .concurrent .TimeUnit ;
54
61
55
62
import butterknife .Bind ;
@@ -286,7 +293,7 @@ void onClearTo() {
286
293
duration .setText ("" );
287
294
final Alarm oldAlarm = getAlarm ();
288
295
Alarm newAlarm = oldAlarm .toBuilder ()
289
- .destination (new Location ("" ,0 , 0 ))
296
+ .destination (new Location ("" , 0 , 0 ))
290
297
.build ();
291
298
oldAlarm .copyMutableFieldsTo (newAlarm );
292
299
persistUpdatedAlarm (newAlarm , false );
@@ -299,21 +306,50 @@ void onDurationClicked() {
299
306
300
307
private void setDuration () {
301
308
Log .d (TAG , "set duration" );
302
- DistanceHandler asyncTask = new DistanceHandler (getAlarm (),new DistanceHandler .AsyncResponse () {
309
+ DistanceHandler asyncTask = new DistanceHandler (getAlarm (), new DistanceHandler .AsyncResponse () {
303
310
@ Override
304
311
public void processFinish (long delaySecs ) {
305
- //#################new############
306
- int min = (int )TimeUnit .SECONDS .toMinutes (delaySecs );
312
+ int testseconds = 4000 ;
307
313
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
+
310
345
Alarm newAlarm = oldAlarm .toBuilder ()
311
- .minutes (newmin )
346
+ .minutes (cal .get (Calendar .MINUTE ))
347
+ .hour (cal .get (Calendar .HOUR_OF_DAY ))
312
348
.build ();
313
349
oldAlarm .copyMutableFieldsTo (newAlarm );
314
350
persistUpdatedAlarm (newAlarm , false );
315
351
//#############################
316
- duration .setText (String .valueOf (min )+ "delay" );
352
+ duration .setText (String .valueOf (delayMinutes ) + "delay" );
317
353
}
318
354
});
319
355
0 commit comments