private void verifySMS(String smsCode) { smsPB.setVisibility(View.VISIBLE); String url = smsURL + "phone=" + userPhone + "&key=" + smsCode; String tag_json_obj = "sms_verify_request"; Log.d("Volley", url); JsonObjectRequest jsonObjReq = new JsonObjectRequest( Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d("Volley", response.toString()); try { String userHash = response.getString("hash"); if (!userHash.equals("keyCode error")) { SharedPreferences sp = getActivity().getSharedPreferences("SmartCommunity", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putString("userHash", userHash).commit(); AppUser appUserInstance = AppUser.getInstance(); appUserInstance.setUserHash(userHash); FirstDataParser parser = new FirstDataParser(getActivity(), userHash, "login_sms"); parser.getFirstTimeData("24.323288", "26.135633"); } else { smsPB.setVisibility(View.GONE); Toast.makeText( getActivity(), "Wrong code, please check you messages", Toast.LENGTH_SHORT) .show(); sms_edittext.setError("Wrong Code"); } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d("Volley", "Error: " + error.getMessage()); Toast.makeText( getActivity(), "Couldn't connect to server, try again", Toast.LENGTH_SHORT) .show(); } }); jsonObjReq.setShouldCache(false); AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj); }
public void showSocialLoginDialog() { smsPB.setVisibility(View.GONE); final MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) .customView(R.layout.smartdialog, false) .title("Sign Up") .titleGravity(GravityEnum.CENTER) .positiveText("SKIP") .cancelable(false) .callback( new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); dialog.dismiss(); mixpanel.track("Login - Skipped"); Intent mIntent = new Intent(getActivity(), LoginUserDetails.class); startActivity(mIntent); } }) .show(); View view = dialog.getCustomView(); callbackManager = CallbackManager.Factory.create(); LoginButton facebookBtn = (LoginButton) view.findViewById(R.id.smartDialogFacebook); facebookBtn.setFragment(this); facebookBtn.setReadPermissions(Arrays.asList("public_profile, email, user_birthday")); facebookBtn.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Log.d(TAG, "Facebook login success"); try { getUserFacebookDetails(loginResult); } catch (Exception e) { Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } @Override public void onCancel() { Log.d(TAG, "Facebook login cancel"); } @Override public void onError(FacebookException e) { Log.d(TAG, "Facebook login error"); Toast.makeText( getActivity(), "Couldn't login with facebook, try again" + e.getMessage(), Toast.LENGTH_SHORT) .show(); } }); SignInButton googleBtn = (SignInButton) view.findViewById(R.id.smartDialogGoogle); googleBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); } else { mShouldResolve = true; mGoogleApiClient.connect(); } } }); }