Guest User

Untitled

a guest
Jan 29th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. public class FragmentRegistration extends Fragment {
  2. View mainView;
  3.  
  4. EditText username, email, password, name;
  5. Button button;
  6.  
  7. ApiClient pentairAPIClient = ApiClient.getInstance();
  8.  
  9. SupportopObj supportopObj = new SupportopObj();
  10. SupportopObjActivate supportopObjActivate = new SupportopObjActivate();
  11.  
  12. @Override
  13. public View onCreateView(LayoutInflater inflater,
  14. @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  15. mainView = inflater.inflate
  16. (R.layout.registration, container, false);
  17.  
  18. username = mainView.findViewById(R.id.username);
  19. email = mainView.findViewById(R.id.email);
  20. password = mainView.findViewById(R.id.password);
  21. name = mainView.findViewById(R.id.name);
  22. button = mainView.findViewById(R.id.register);
  23.  
  24. button.setOnClickListener(new View.OnClickListener() {
  25. @Override
  26. public void onClick(View v) {
  27.  
  28. //String s = name.getText().toString();
  29. //String split[] = s.split(" ");
  30.  
  31. supportopObj.setFirstName("Tester");
  32. supportopObj.setLastName("Testryan");
  33. supportopObj.setUsername(username.getText().toString());
  34. supportopObj.setEmail(email.getText().toString());
  35. supportopObj.setPassword(password.getText().toString());
  36.  
  37. supportopObjActivate.setUsername(supportopObj.getUsername());
  38. supportopObjActivate.setEmail(supportopObj.getEmail());
  39. supportopObjActivate.setPassword(supportopObj.getPassword());
  40. supportopObjActivate.setType("generic");
  41. updateApp();
  42. }
  43. });
  44.  
  45. return mainView;
  46. }
  47.  
  48.  
  49. public void updateApp() {
  50.  
  51. Call<ResponseBody> call = pentairAPIClient.registration(supportopObj);
  52. call.enqueue(new Callback<ResponseBody>() {
  53. @Override
  54. public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
  55. if (response.isSuccessful()) {
  56. activationCall();
  57.  
  58. } else {
  59. Toast.makeText(getContext(), "Something went wrong",
  60. Toast.LENGTH_SHORT).show();
  61. }
  62. }
  63.  
  64. @Override
  65. public void onFailure(Call<ResponseBody> call, Throwable t) {
  66. Toast.makeText(getContext(), "Error...", Toast.LENGTH_SHORT).show();
  67. }
  68. });
  69. }
  70.  
  71.  
  72. public void activationCall() {
  73. Call<ResponseBody> callActive = pentairAPIClient.activation(supportopObjActivate);
  74. callActive.enqueue(new Callback<ResponseBody>() {
  75. @Override
  76. public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
  77.  
  78. if (response.isSuccessful()) {
  79.  
  80. try {
  81. String data = response.body().string();
  82. JSONObject obj = new JSONObject(data);
  83. String client_id = obj.getString("client_id");
  84. String client_secret = obj.getString("client_secret");
  85.  
  86. tokenCall(client_id, client_secret);
  87.  
  88. } catch (JSONException | IOException e) {
  89. e.printStackTrace();
  90. }
  91.  
  92. } else {
  93. Toast.makeText(getContext(), "error", Toast.LENGTH_SHORT).show();
  94. }
  95. }
  96.  
  97. @Override
  98. public void onFailure(Call<ResponseBody> call, Throwable t) {
  99. Toast.makeText(getContext(), "Error in activation",
  100. Toast.LENGTH_SHORT).show();
  101. }
  102. });
  103. }
  104.  
  105.  
  106. public void tokenCall(String client_id, String client_secret) {
  107. Call<ResponseBody> token = pentairAPIClient.get_token("password", client_id, client_secret,
  108. supportopObj.getEmail(), supportopObj.getPassword());
  109.  
  110. token.enqueue(new Callback<ResponseBody>() {
  111. @Override
  112. public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
  113. if (response.isSuccessful()) {
  114. Toast.makeText(getContext(), String.valueOf(response.body()), Toast.LENGTH_SHORT).show();
  115. } else {
  116. Toast.makeText(getContext(), "Something wrong.....", Toast.LENGTH_SHORT).show();
  117. }
  118. }
  119.  
  120. @Override
  121. public void onFailure(Call<ResponseBody> call, Throwable t) {
  122. Toast.makeText(getContext(), "You're on failure", Toast.LENGTH_SHORT).show();
  123. }
  124. });
  125. }
  126.  
  127. @Override
  128. public void onFailure(Call<ResponseBody> call, Throwable t)
  129. {
  130. Toast.makeText(getContext(), "You're onfailure",Toast.LENGTH_SHORT).show();
  131. }
  132.  
  133. readTimeout(10, TimeUnit.SECONDS).connectTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS);
Add Comment
Please, Sign In to add comment