Newer
Older
NemophilaClient / app / src / main / java / com / example / nemophila / Nemophila.java
  1. package com.example.nemophila;
  2.  
  3. import android.app.Application;
  4. import android.content.SharedPreferences;
  5.  
  6. import com.example.nemophila.entities.Shop;
  7.  
  8. public class Nemophila extends Application {
  9. private String name;
  10. private String uid;
  11. private String token;
  12. private Shop currentShop;
  13. private double currentLongitude;
  14. private double currentLatitude;
  15. private Shop dummyShop;
  16.  
  17. //Getter
  18.  
  19. public String getName() {
  20. if(name == null){
  21. SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
  22. name = preferences.getString("name", null);
  23. }
  24. return name;
  25. }
  26. public String getUid() {
  27. if(uid == null){
  28. SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
  29. uid = preferences.getString("uid", null);
  30. }
  31. return uid;
  32. }
  33. public String getToken() {
  34. if(token == null){
  35. SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
  36. token = preferences.getString("token", null);
  37. }
  38. return token;
  39. }
  40. public Shop getCurrentShop() {
  41. return currentShop;
  42. }
  43. public double getCurrentLongitude() {
  44. return currentLongitude;
  45. }
  46. public double getCurrentLatitude() {
  47. return currentLatitude;
  48. }
  49. public Shop getDummyShop() {
  50. return dummyShop;
  51. }
  52.  
  53. //Setter
  54. public void setName(String name) {
  55. SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
  56. SharedPreferences.Editor editor = preferences.edit();
  57. editor.putString("name", name);
  58. this.name = name;
  59. editor.commit();
  60. }
  61. public void setUid(String uid) {
  62. SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
  63. SharedPreferences.Editor editor = preferences.edit();
  64. editor.putString("uid", uid);
  65. this.uid = uid;
  66. editor.commit();
  67. }
  68. public void setToken(String token) {
  69. SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
  70. SharedPreferences.Editor editor = preferences.edit();
  71. editor.putString("token", token);
  72. this.token = token;
  73. editor.commit();
  74. }
  75. public void setCurrentShop(Shop currentShop) {
  76. this.currentShop = currentShop;
  77. }
  78. public void setCurrentLongitude(double currentLongitude) {
  79. this.currentLongitude = currentLongitude;
  80. }
  81. public void setCurrentLatitude(double currentLatitude) {
  82. this.currentLatitude = currentLatitude;
  83. }
  84. public void setDummyShop(Shop dummyShop) {
  85. this.dummyShop = dummyShop;
  86. }
  87. }