-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java
105 lines (94 loc) · 4.08 KB
/
MainActivity.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
package com.example.vishnu.retro_trail;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.vishnu.retro_trail.config.APIinterface;
import com.example.vishnu.retro_trail.config.ApiClient;
import com.example.vishnu.retro_trail.pojos.CheckUser;
import com.example.vishnu.retro_trail.pojos.Task;
import java.io.IOException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainActivity extends AppCompatActivity {
EditText checkuser_et;
Button check_bt;
APIinterface apiInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkuser_et=findViewById(R.id.checkuser);
check_bt=findViewById(R.id.check);
check_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
checkuser_API();
}
});
}
private void checkuser_API() {
String user=checkuser_et.getText().toString();
apiInterface = ApiClient.getClient().create(APIinterface.class);
CheckUser checkuserpojo = new CheckUser(user);
Call<Task> callregister = apiInterface.checkuser(checkuserpojo);
callregister.enqueue(new Callback<Task>() {
@Override
public void onResponse(@NonNull Call<Task> call, @NonNull Response<Task> response) {
String otp = "";
Task x = response.body();
if(x == null){
try {
String error = response.errorBody().string();
Log.e("ERROR",error);
Toast.makeText(MainActivity.this, "NULL", Toast.LENGTH_SHORT).show();
}catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "IOException", Toast.LENGTH_SHORT).show();
}
}
else {
String code = String.valueOf(x.getCode());
String msg = String.valueOf(x.getMsg());
if (msg.equals("success")){
Log.e("code ", code);
Toast.makeText(MainActivity.this, "Registered", Toast.LENGTH_SHORT).show();
}
else if (msg.equals("false")) {
Toast.makeText(MainActivity.this, "UnRegistewred", Toast.LENGTH_SHORT).show();
}
}
/* if(String.valueOf(response.body()).equals("true")){
callback.onuserexist(0,"");
}
else if(String.valueOf(response.body()).equals("true")){
callback.onusernotexist();
}
else {
try {
if (!response.body().isJsonNull()) {
otp = response.body().getAsJsonObject().get("otp").getAsString();
Log.e("OTP ", otp);
callback.onuserexist(1,otp);
}
//res = String.valueOf(response.body());
} catch (Exception e) {
callback.onfailure(String.valueOf(e));
Log.e("Exception ", e.getLocalizedMessage());
}
}*/
Log.e("RESPONSE", String.valueOf(response.body()));
}
@Override
public void onFailure(@NonNull Call<Task> call, @NonNull Throwable t) {
// Log.e("FAILED",t.getMessage());
Toast.makeText(MainActivity.this, "Failured", Toast.LENGTH_SHORT).show();
}
});
}
}