Guest User

Untitled

a guest
May 31st, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. {
  2. "hotels" : {
  3. "bCtwqGdnLlU5cumqun7yyv1MDFC5" : {
  4. "address" : "Rua. Exemplo 1",
  5. "city" : "ITAGUAÍ",
  6. "name" : "HOTEL TULIPINN"
  7. },
  8. "bdtwqGdnLlU5cumqun7yyv1MDFC6" : {
  9. "address" : "Rua. Exemplo 2",
  10. "city" : "P. NEGRA",
  11. "name" : "HOTEL GOLDEN TULIP"
  12. }
  13. },
  14. "users" : {
  15. "zDtwqGdnLlU5cumqun7yyv1MDFC3" : {
  16. "password" : "123456",
  17. "username" : "thiago.saad@neoris.com"
  18. }
  19. },
  20. "vouchers" : {
  21. "aBtwqGdnLlU5cumqun7yyv1MDFC4" : {
  22. "dateBooking" : "01/01/01",
  23. "dateCheckin" : "02/02/02",
  24. "dateCheckout" : "03/03/03",
  25. "hotel" : "bCtwqGdnLlU5cumqun7yyv1MDFC5",
  26. "quantityAdult" : 2,
  27. "quantityChild" : 0,
  28. "quantityRoom" : 1,
  29. "user" : "zDtwqGdnLlU5cumqun7yyv1MDFC3"
  30. },
  31. "aCtwqGdnLlU5cumqun7yyv1MDFC5" : {
  32. "dateBooking" : "05/05/05",
  33. "dateCheckin" : "06/06/06",
  34. "dateCheckout" : "07/07/07",
  35. "hotel" : "bdtwqGdnLlU5cumqun7yyv1MDFC6",
  36. "quantityAdult" : 1,
  37. "quantityChild" : 5,
  38. "quantityRoom" : 10,
  39. "user" : "zDtwqGdnLlU5cumqun7yyv1MDFC3"
  40. }
  41. }
  42. }
  43.  
  44. package com.hotelaria.neoris.checkincheckout.models.objects;
  45.  
  46. public class Hotel {
  47.  
  48. private String code;
  49. private String name;
  50. private String address;
  51. private String city;
  52. //private int imageLogoType;
  53. //private int imageBackground;
  54. //private int imageStars;
  55.  
  56. public Hotel() {
  57. // Default constructor required for calls to DataSnapshot.getValue(Hotel.class)
  58. }
  59.  
  60. public Hotel(String code, String name, String address, String city){
  61. this.code = code;
  62. this.name = name;
  63. this.address = address;
  64. this.city = city;
  65. }
  66.  
  67. public String getCode() {
  68. return code;
  69. }
  70.  
  71. public void setCode(String code) {
  72. this.code = code;
  73. }
  74.  
  75. public String getName() {
  76. return name;
  77. }
  78.  
  79. public void setName(String name) {
  80. this.name = name;
  81. }
  82.  
  83. public String getAddress() {
  84. return address;
  85. }
  86.  
  87. public void setAddress(String address) {
  88. this.address = address;
  89. }
  90.  
  91. public String getCity() {
  92. return city;
  93. }
  94.  
  95. public void setCity(String city) {
  96. this.city = city;
  97. }
  98. }
  99.  
  100. package com.hotelaria.neoris.checkincheckout.models.objects;
  101.  
  102. import java.util.ArrayList;
  103.  
  104. public class User {
  105. private String code;
  106. private String username;
  107. private String password;
  108. private ArrayList<Voucher> voucher;
  109.  
  110. public User(){
  111. // Default constructor required for calls to DataSnapshot.getValue(User.class)
  112. }
  113.  
  114. public User(String code, String username, String password, ArrayList<Voucher> voucher){
  115. this.code = code;
  116. this.username = username;
  117. this.password = password;
  118. this.voucher = new ArrayList<Voucher>();
  119. }
  120.  
  121. public String getCode() {
  122. return code;
  123. }
  124.  
  125. public void setCode(String code) {
  126. this.code = code;
  127. }
  128.  
  129. public String getUsername() {
  130. return username;
  131. }
  132.  
  133. public void setUsername(String username) {
  134. this.username = username;
  135. }
  136.  
  137. public String getPassword() {
  138. return password;
  139. }
  140.  
  141. public void setPassword(String password) {
  142. this.password = password;
  143. }
  144.  
  145. public ArrayList<Voucher> getVoucher() {
  146. return voucher;
  147. }
  148.  
  149. public void setVoucher(ArrayList<Voucher> voucher) {
  150. this.voucher = voucher;
  151. }
  152.  
  153. }
  154.  
  155. package com.hotelaria.neoris.checkincheckout.models.objects;
  156.  
  157. import java.util.ArrayList;
  158.  
  159. public class Voucher {
  160. private String code;
  161. private String dateBooking;
  162. private String dateCheckin;
  163. private String dateCheckout;
  164. private byte quantityRoom;
  165. private byte quantityAdult;
  166. private byte quantityChild;
  167. private ArrayList<Hotel> hotel;
  168.  
  169. public Voucher() {
  170. // Default constructor required for calls to DataSnapshot.getValue(Voucher.class)
  171. }
  172.  
  173. public Voucher(String code, String dateBooking, String dateCheckin, String dateCheckout, byte quantityRoom, byte quantityAdult, byte quantityChild, ArrayList<Hotel> hotel){
  174. this.code = code;
  175. this.dateBooking = dateBooking;
  176. this.dateCheckin = dateCheckin;
  177. this.dateCheckout = dateCheckout;
  178. this.quantityRoom = quantityRoom;
  179. this.quantityAdult = quantityAdult;
  180. this.quantityChild = quantityChild;
  181. this.hotel = new ArrayList<Hotel>();
  182. }
  183.  
  184. public String getCode() {
  185. return code;
  186. }
  187.  
  188. public void setCode(String code) {
  189. this.code = code;
  190. }
  191.  
  192. public String getDateBooking() {
  193. return dateBooking;
  194. }
  195.  
  196. public void setDateBooking(String dateBooking) {
  197. this.dateBooking = dateBooking;
  198. }
  199.  
  200. public String getDateCheckin() {
  201. return dateCheckin;
  202. }
  203.  
  204. public void setDateCheckin(String dateCheckin) {
  205. this.dateCheckin = dateCheckin;
  206. }
  207.  
  208. public String getDateCheckout() {
  209. return dateCheckout;
  210. }
  211.  
  212. public void setDateCheckout(String dateCheckout) {
  213. this.dateCheckout = dateCheckout;
  214. }
  215.  
  216. public byte getQuantityRoom() {
  217. return quantityRoom;
  218. }
  219.  
  220. public void setQuantityRoom(byte quantityRoom) {
  221. this.quantityRoom = quantityRoom;
  222. }
  223.  
  224. public byte getQuantityAdult() {
  225. return quantityAdult;
  226. }
  227.  
  228. public void setQuantityAdult(byte quantityAdult) {
  229. this.quantityAdult = quantityAdult;
  230. }
  231.  
  232. public byte getQuantityChild() {
  233. return quantityChild;
  234. }
  235.  
  236. public void setQuantityChild(byte quantityChild) {
  237. this.quantityChild = quantityChild;
  238. }
  239.  
  240. public ArrayList<Hotel> getHotel() {
  241. return hotel;
  242. }
  243.  
  244. public void setHotel(ArrayList<Hotel> hotel) {
  245. this.hotel = hotel;
  246. }
  247. }
  248.  
  249. package com.hotelaria.neoris.checkincheckout.models.objects;
  250.  
  251. import android.app.Activity;
  252. import android.content.Context;
  253. import android.content.Intent;
  254. import android.support.annotation.NonNull;
  255. import android.util.Log;
  256. import android.widget.Toast;
  257.  
  258. import com.google.android.gms.tasks.OnCompleteListener;
  259. import com.google.android.gms.tasks.Task;
  260. import com.google.firebase.auth.AuthResult;
  261. import com.google.firebase.auth.FirebaseAuth;
  262. import com.google.firebase.database.DataSnapshot;
  263. import com.google.firebase.database.DatabaseError;
  264. import com.google.firebase.database.DatabaseReference;
  265. import com.google.firebase.database.FirebaseDatabase;
  266. import com.google.firebase.database.Query;
  267. import com.google.firebase.database.ValueEventListener;
  268. import com.hotelaria.neoris.checkincheckout.activitys.MainActivity;
  269. import com.hotelaria.neoris.checkincheckout.activitys.SignupActivity;
  270. ;
  271.  
  272. public class Firebase {
  273. private FirebaseDatabase mFirebaseDatabase = FirebaseDatabase.getInstance();
  274. private FirebaseAuth mFirebaseAuth = FirebaseAuth.getInstance();
  275. private DatabaseReference mDatabaseReference = mFirebaseDatabase.getReference();
  276. private Query mQuery;
  277.  
  278. private User mUser;
  279.  
  280. public Firebase(){
  281. // @TODO
  282. }
  283.  
  284. public void writeNewUser(final String username, final String password, final Context activityContext){
  285. this.mFirebaseAuth.createUserWithEmailAndPassword(username, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  286. @Override
  287. public void onComplete(@NonNull Task<AuthResult> task) {
  288. if(task.isSuccessful()){
  289. String userKey = mFirebaseAuth.getUid();
  290. mUser = new User(userKey, username, password, null);
  291. mDatabaseReference.child("users/" + userKey).setValue(mUser);
  292. Toast.makeText(activityContext,"SUCESSO, CONTA CADASTRADA!", Toast.LENGTH_SHORT).show();
  293. } else {
  294. Toast.makeText(activityContext,"OPS, ACONTECEU ALGUM ERRO!", Toast.LENGTH_SHORT).show();
  295. }
  296. }
  297. });
  298. }
  299.  
  300. public void signIn(String username, String password, final Context activityContext){
  301. this.mFirebaseAuth.signInWithEmailAndPassword(username, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  302. @Override
  303. public void onComplete(@NonNull Task<AuthResult> task) {
  304. if(task.isSuccessful()){
  305. Toast.makeText(activityContext,"SUCESSO NA AUTENTIFICAÇÃO", Toast.LENGTH_SHORT).show();
  306. activityContext.startActivity(new Intent(activityContext, MainActivity.class));
  307. } else{
  308. Toast.makeText(activityContext,"PROBLEMA NA AUTENTIFICAÇÃO", Toast.LENGTH_SHORT).show();
  309. }
  310. }
  311. });
  312. }
  313.  
  314. public void queryUserData(){
  315. String userId = this.mFirebaseAuth.getUid();
  316. this.mQuery = this.mDatabaseReference.child("users").orderByKey().equalTo(userId);
  317. this.mQuery.addValueEventListener(new ValueEventListener() {
  318. @Override
  319. public void onDataChange(DataSnapshot dataSnapshot) {
  320. for (DataSnapshot userSnapshot: dataSnapshot.getChildren()){
  321. mUser = userSnapshot.getValue(User.class);
  322. Log.i("TESTANDO", mUser.getUsername().toString());
  323. Log.i("TESTANDO", mUser.getPassword().toString());
  324. Log.i("TESTANDO", mUser.getVoucher().toString());
  325. //setUsername(mDataUser.getUsername().toString());
  326. }
  327. }
  328.  
  329. @Override
  330. public void onCancelled(DatabaseError databaseError) {
  331. // Getting Post failed, log a message
  332. Log.w("onCancelled", "loadPost:onCancelled", databaseError.toException());
  333. // ...
  334. }
  335. });
  336. }
  337.  
  338.  
  339.  
  340. }
Add Comment
Please, Sign In to add comment