-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd.java
More file actions
90 lines (81 loc) · 3.88 KB
/
Add.java
File metadata and controls
90 lines (81 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.example.findme_technovation;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;
import java.util.HashMap;
import java.util.Map;
public class Add extends Activity {
private EditText titleEdit, timeEdit, messageEdit, hourAdd, minuteAdd;
private CheckBox amCheckBox, pmCheckBox, medCheckBox;
private Button doneButton;
FirebaseFirestore db;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adding);
db = FirebaseFirestore.getInstance();
titleEdit = (EditText) findViewById(R.id.titleAdd);
messageEdit = (EditText) findViewById(R.id.dirAdd);
hourAdd = (EditText) findViewById(R.id.hourAdd);
minuteAdd = (EditText) findViewById(R.id.minuteAdd);
amCheckBox = (CheckBox) findViewById(R.id.AMbox);
pmCheckBox = (CheckBox) findViewById(R.id.PMbox);
medCheckBox = (CheckBox) findViewById(R.id.medBox);
doneButton = (Button) findViewById(R.id.doneButton);
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String title = titleEdit.getText().toString();
String hours = hourAdd.getText().toString();
String minutes = minuteAdd.getText().toString();
String message = messageEdit.getText().toString();
boolean isAM = amCheckBox.isChecked();
boolean isMedicine = medCheckBox.isChecked();
Map<String,Object> todos = new HashMap<>();
todos.put("Title", title);
todos.put("Message", message);
todos.put("Hours", hours);
todos.put("Minutes", minutes);
if(isAM)
todos.put("Time", "AM");
else
todos.put("Time", "PM");
db.collection("todos")
.add(todos)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Toast.makeText(Add.this, "Success", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Add.this, "Failed", Toast.LENGTH_SHORT).show();
}
});
startActivity(new Intent(Add.this, CalendarActivity.class));
/*
Event newEvent = new Event(time, isAM, isMedicine);
newEvent.setTitle(title);
newEvent.setMessage(message);
Intent resultIntent = new Intent(); // so we gotta create intent to pass it into other compeontnts
resultIntent.putExtra("event", newEvent); // lowkey dont know what this does got this code from stack
setResult(RESULT_OK, resultIntent); // somethign to do wth the fact that it was successful
//"here is the result of the activity and it contains this data (Event object)"
finish(); // finish the activity */
}
});
}
}