-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLessonInfo.java
133 lines (94 loc) · 4.33 KB
/
LessonInfo.java
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.example.padel;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class LessonInfo extends Fragment {
TextView daytextView,hoursTextView,fieldTextView,descriptionTextView,coachTextView;
Button button;
String day,hours,field,description,coach,prenotati;
FirebaseAuth auth;
String name_user,surname_user;
public LessonInfo() {
// Required empty public constructor
}
public static LessonInfo newInstance(String param1, String param2) {
LessonInfo fragment = new LessonInfo();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
auth = FirebaseAuth.getInstance();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_lesson_info, container, false);
daytextView = view.findViewById(R.id.day);
hoursTextView = view.findViewById(R.id.hour);
descriptionTextView = view.findViewById(R.id.description);
coachTextView = view.findViewById(R.id.coach);
fieldTextView = view.findViewById(R.id.field);
button = view.findViewById(R.id.btn);
Bundle data = getArguments();
if(data != null){
day = data.getString("day");
hours = data.getString("hour");
description = data.getString("description");
field = data.getString("field");
coach = data.getString("coach");
prenotati = data.getString("prenotati");
daytextView.setText(day);
hoursTextView.setText(hours);
descriptionTextView.setText(description);
coachTextView.setText(field);
fieldTextView.setText(String.valueOf(coach));
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatabaseReference database = FirebaseDatabase.getInstance("https://padel-5d8f6-default-rtdb.europe-west1.firebasedatabase.app").getReference("lessons");
FirebaseUser user = auth.getCurrentUser();
String uid = user.getUid().toString();
DatabaseReference database2 = FirebaseDatabase.getInstance("https://padel-5d8f6-default-rtdb.europe-west1.firebasedatabase.app").getReference("users").child(uid);
database2.addValueEventListener(new ValueEventListener() {
String name,surname;
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
User user = snapshot.getValue(User.class);
surname = user.getSurname();
name = user.getName();
Lesson lesson = new Lesson(coach, description, day, hours,field, prenotati + " " + name + surname + ",");
if(prenotati.contains(name+surname)){
Toast.makeText(getContext(), "Sei Già Prenotato per questa lezione",
Toast.LENGTH_SHORT).show();
}
else {
database.child("Lezione " + day + " " + hours).setValue(lesson);
Toast.makeText(getContext(), "Prenotazione Effettuata",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
});
return view;
}
}