|
|
@ -1,7 +1,9 @@ |
|
|
|
package ru.visionlab.femdemo.register; |
|
|
|
|
|
|
|
|
|
|
|
import android.app.ProgressDialog; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.os.Bundle; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
import android.text.Editable; |
|
|
@ -15,9 +17,23 @@ import android.view.ViewGroup; |
|
|
|
import android.widget.Button; |
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.ScrollView; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
|
|
import com.android.volley.AuthFailureError; |
|
|
|
import com.android.volley.Request; |
|
|
|
import com.android.volley.VolleyError; |
|
|
|
import com.android.volley.toolbox.StringRequest; |
|
|
|
import com.android.volley.toolbox.Volley; |
|
|
|
import com.google.android.material.textfield.TextInputLayout; |
|
|
|
import com.google.gson.JsonArray; |
|
|
|
|
|
|
|
import org.json.JSONArray; |
|
|
|
import org.json.JSONException; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import javax.inject.Inject; |
|
|
|
|
|
|
@ -33,6 +49,7 @@ import ru.visionlab.femdemo.R; |
|
|
|
import ru.visionlab.femdemo.Storage; |
|
|
|
import ru.visionlab.femdemo.Utils; |
|
|
|
import ru.visionlab.femdemo.base.BaseFragment; |
|
|
|
import ru.visionlab.femdemo.login.LoginActivityNew; |
|
|
|
import ru.visionlab.femdemo.settings.VLPreferences; |
|
|
|
|
|
|
|
|
|
|
@ -130,16 +147,102 @@ public class RegisterFragment extends BaseFragment { |
|
|
|
|
|
|
|
|
|
|
|
Utils.hideKeyboardRoutine(getContext(), getView()); |
|
|
|
if (listener != null && validateFields(true, true)) { |
|
|
|
RegistrationModel registrationModel = new RegistrationModel(); |
|
|
|
registrationModel.email = email.getText().toString().trim(); |
|
|
|
registrationModel.login = login.getText().toString().trim(); |
|
|
|
//registrationModel.password = password.getText().toString().trim(); |
|
|
|
registrationModel.phone = phone.getText().toString().trim(); |
|
|
|
listener.onSignUpClick(registrationModel); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(login.getText().toString().isEmpty()) |
|
|
|
{ |
|
|
|
Toast.makeText(getContext(), "Please enter user name", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
else if(pass.getText().toString().isEmpty()) |
|
|
|
{ |
|
|
|
Toast.makeText(getContext(), "Please enter password", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
getRegistration(login.getText().toString(),pass.getText().toString()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void getRegistration(String username, String password) { |
|
|
|
|
|
|
|
String url= "http://43.242.212.92:7001/api/lgt/Login"; |
|
|
|
StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() { |
|
|
|
@Override |
|
|
|
public void onResponse(String response) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
JSONArray jsonArray=new JSONArray(response); |
|
|
|
Log.d("response",response); |
|
|
|
JSONObject jb1=jsonArray.getJSONObject(0); |
|
|
|
JSONObject jb2=jb1.getJSONObject("statusModel"); |
|
|
|
String statuscode=jb2.getString("_statusCode"); |
|
|
|
Log.d("status",statuscode); |
|
|
|
Toast.makeText(getContext(), statuscode, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
|
|
if(statuscode.equals("200")) |
|
|
|
{ |
|
|
|
|
|
|
|
preferences.setUsername(username); |
|
|
|
if (listener != null && validateFields(true, true)) { |
|
|
|
RegistrationModel registrationModel = new RegistrationModel(); |
|
|
|
// registrationModel.email = email.getText().toString().trim(); |
|
|
|
registrationModel.login = username; |
|
|
|
//registrationModel.password = password.getText().toString().trim(); |
|
|
|
// registrationModel.phone = phone.getText().toString().trim(); |
|
|
|
listener.onSignUpClick(registrationModel); |
|
|
|
|
|
|
|
|
|
|
|
Log.d("HH", String.valueOf(registrationModel)); |
|
|
|
|
|
|
|
} |
|
|
|
Toast.makeText(getContext(), "Success Registration", Toast.LENGTH_SHORT).show(); |
|
|
|
Intent intent=new Intent(getContext(),RegisterActivity.class); |
|
|
|
startActivity(intent); |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// we have to show alert |
|
|
|
Toast.makeText(getContext(), "Username/password is not matching!", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (JSONException e) { |
|
|
|
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show(); |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, new com.android.volley.Response.ErrorListener() { |
|
|
|
@Override |
|
|
|
public void onErrorResponse(VolleyError error) { |
|
|
|
Log.d("error-=>",error.getMessage()); |
|
|
|
|
|
|
|
Toast.makeText(getContext(), "Faied", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
{ |
|
|
|
@Override |
|
|
|
protected Map<String, String> getParams() throws AuthFailureError { |
|
|
|
HashMap<String,String> map=new HashMap<>(); |
|
|
|
map.put("username",username); |
|
|
|
map.put("password",password); |
|
|
|
map.put("imei",""); |
|
|
|
|
|
|
|
return map; |
|
|
|
} |
|
|
|
}; |
|
|
|
Volley.newRequestQueue(getContext()).add(stringRequest); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean validateFields(boolean changeFocus, boolean showError) { |
|
|
|
boolean result; |
|
|
|
|
|
|
@ -183,10 +286,10 @@ public class RegisterFragment extends BaseFragment { |
|
|
|
loginWrapper.setError(getString(R.string.register_username_short, Config.MIN_LOGIN_LENGTH)); |
|
|
|
} |
|
|
|
} |
|
|
|
if(Storage.getInstance().isLoginAlreadyExists(currentLogin) || Storage.getInstance().isLoginAlreadyExistsLocal(currentLogin)){ |
|
|
|
result = false; |
|
|
|
loginWrapper.setError(getString(R.string.register_username_exist,currentLogin)); |
|
|
|
} |
|
|
|
// if(Storage.getInstance().isLoginAlreadyExists(currentLogin) || Storage.getInstance().isLoginAlreadyExistsLocal(currentLogin)){ |
|
|
|
// result = false; |
|
|
|
//// loginWrapper.setError(getString(R.string.register_username_exist,currentLogin)); |
|
|
|
// } |
|
|
|
else { |
|
|
|
loginWrapper.setError(null); |
|
|
|
loginWrapper.setErrorEnabled(false); |
|
|
@ -228,5 +331,6 @@ public class RegisterFragment extends BaseFragment { |
|
|
|
|
|
|
|
public interface Listener { |
|
|
|
void onSignUpClick(RegistrationModel registrationModel); |
|
|
|
|
|
|
|
} |
|
|
|
} |