Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
feat(android-alarm): Finish ability to properly set android alarm
Browse files Browse the repository at this point in the history
Setting android alarm works, but cancelling still needs testing. Since UI needs to change, this
update will be deferred.

re #16
  • Loading branch information
wesharper committed Dec 1, 2018
1 parent 4d9fb98 commit 19bafdf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
21 changes: 13 additions & 8 deletions android/app/src/main/java/com/example/snuze/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.snuze;

import android.Manifest;
import android.app.AlarmManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
Expand Down Expand Up @@ -28,6 +29,7 @@ public class MainActivity extends FlutterActivity {
private static final String STRIPE_CHANNEL = "snuze.app/stripe";
private static final String ALARM_CHANNEL = "snuze.app/alarm";
private static final int MY_PERMISSIONS_REQUEST_SET_ALARM = 17;
private Intent alarmIntent;
Stripe stripe = new Stripe(this, "pk_test_YhN3AX1KBNqQQbDtGjctrCZd");

private JSONObject newJSONObject(String string) {
Expand Down Expand Up @@ -59,17 +61,19 @@ private Intent createAlarmIntent(JSONObject alarmInfo) {
try {
Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, alarmInfo.getInt("hour"));
alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, alarmInfo.getInt("minute"));
alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, alarmInfo.getInt("minute"));
alarmIntent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
return alarmIntent;
} catch (JSONException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e);
}
}

private Intent dismissAlarmIntent() {
Intent alarmIntent = new Intent(AlarmClock.ACTION_DISMISS_ALARM);
return alarmIntent;
private Intent dismissAlarmIntent(Intent currentIntent) {
currentIntent.setAction(AlarmClock.ACTION_DISMISS_ALARM);
currentIntent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
return currentIntent;
}

@Override
Expand All @@ -79,14 +83,14 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related task you need to do.
System.out.println("PERMISSION GRANTED");
} else {
System.out.println("Permissions Not Granted");
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request.
}
}

Expand All @@ -109,6 +113,7 @@ protected void onCreate(Bundle savedInstanceState) {
MY_PERMISSIONS_REQUEST_SET_ALARM);
}
} else {
System.out.println("PERMISSION GRANTED 117");
// Permission already granted
}

Expand Down Expand Up @@ -150,10 +155,10 @@ public void onError(Exception error) {
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("setAlarm")) {
JSONObject alarmInfo = newJSONObject(call.arguments().toString());
Intent alarmIntent = createAlarmIntent(alarmInfo);
alarmIntent = createAlarmIntent(alarmInfo);
startActivity(alarmIntent);
} else if (call.method.equals("cancelAlarm")) {
Intent alarmIntent = dismissAlarmIntent();
alarmIntent = dismissAlarmIntent(alarmIntent);
startActivity(alarmIntent);
}
}
Expand Down
14 changes: 2 additions & 12 deletions lib/scoped-models/connected_user_alarm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:rxdart/subjects.dart';
import 'package:flutter_facebook_login/flutter_facebook_login.dart';
import 'package:snuze/helpers/stripe.dart';
// import 'package:firebase_auth/firebase_auth.dart';

import 'package:snuze/models/auth.dart';
import 'package:snuze/models/user.dart';
Expand Down Expand Up @@ -45,15 +45,7 @@ mixin UserModel on ConnectedUserAlarmModel {
_isLoading = true;
notifyListeners();

// refactor this part later
Map<String, dynamic> cardInfo = {
'number': number,
'expMonth': expMonth,
'expYear': expYear,
'cvc': cvc
};
// print("Credit Card info: $number, $expMonth, $expYear, $cvc");
String token = await requestStripeToken(cardInfo);
print("Credit Card info: $number, $expMonth, $expYear, $cvc");
final Map<String, dynamic> authData = {
'email': email,
'password': password,
Expand Down Expand Up @@ -88,8 +80,6 @@ mixin UserModel on ConnectedUserAlarmModel {
token: responseData['refreshToken'],
darkTheme: prefs.getBool('darkTheme') == null ? false : prefs.getBool('darkTheme'),
);
print("*" * 80);
print(_authenticatedUser.id);
_userSubject.add(true);

prefs.setString(
Expand Down

0 comments on commit 19bafdf

Please sign in to comment.