Open chnouman opened 6 years ago
Pls try the latest version 2.0.0
ok let me give a try
still getting error
kotlin.UninitializedPropertyAccessException: lateinit property context has not been initialized
pls provide a demo project
This is my loginActivity
class Login : AppCompatActivity(), GoogleListener {
private var signin_btn: Button? = null
private var continueAsGuestTV: TextView? = null
private var forgot_password: TextView? = null
private val image: String? = null
var googlerhelper:GoogleHelper? = null
internal val oAuthService = LinkedInOAuthServiceFactory
.getInstance().createLinkedInOAuthService(
Config.LINKEDIN_CONSUMER_KEY, Config.LINKEDIN_CONSUMER_SECRET)
internal val factory = LinkedInApiClientFactory
.newInstance(Config.LINKEDIN_CONSUMER_KEY,
Config.LINKEDIN_CONSUMER_SECRET)
internal var liToken: LinkedInRequestToken? = null
internal var client: LinkedInApiClient? = null
internal var accessToken: LinkedInAccessToken? = null
var password:EditText? = null
var email:EditText? = null
internal var spinKitView: SpinKitView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!StaticVariables.language) {
val languageToLoad = "ar" // your language
val locale = Locale(languageToLoad)
Locale.setDefault(locale)
val config = Configuration()
config.locale = locale
baseContext.resources.updateConfiguration(config,
baseContext.resources.displayMetrics)
}
setContentView(R.layout.activity_login2)
googlerhelper = GoogleHelper(this, this, null)
spinKitView = findViewById(R.id.spin_kit)
email = findViewById<EditText>(R.id.etUserName) as EditText
password = findViewById<EditText>(R.id.passwd_et) as EditText
continueAsGuestTV = findViewById<View>(R.id.continue_as_guest) as TextView
signin_btn = findViewById<View>(R.id.signin_btn) as Button
var fb_btn = findViewById<ImageView>(R.id.fb_btn)
forgot_password = findViewById<View>(R.id.forgot_password) as TextView
languageSetup()
val content = SpannableString(getString(R.string.u_continue_as_guest_u))
content.setSpan(UnderlineSpan(), 0, content.length, 0)
continueAsGuestTV!!.text = content
signin_btn!!.setOnClickListener {
doTask("")
//startActivity(new Intent(Login.this,Dashboard.class));
}
continueAsGuestTV!!.setOnClickListener {
startActivity(Intent(this@Login, Dashboard::class.java))
//finish();
//startActivity(new Intent(Login.this,Dashboard.class));
}
forgot_password!!.setOnClickListener { startActivity(Intent(this@Login, ForgotPassword::class.java)) }
forPasswordEditText()
fb_btn.setOnClickListener { loginButtonFB() }
}
fun forPasswordEditText() {
// Workaround https://issuetracker.google.com/issues/37082815 for Android 4.4+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && isRTL(this@Login)) {
// Force a right-aligned text entry, otherwise latin character input,
// like "abc123", will jump to the left and may even disappear!
password!!.textDirection = View.TEXT_DIRECTION_RTL
// Make the "Enter password" hint display on the right hand side
password!!.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
}
password!!.addTextChangedListener(object : TextWatcher {
internal var inputTypeChanged: Boolean = false
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable) {
// Workaround https://code.google.com/p/android/issues/detail?id=201471 for Android 4.4+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && isRTL(this@Login)) {
if (s.length > 0) {
if (!inputTypeChanged) {
// When a character is typed, dynamically change the EditText's
// InputType to PASSWORD, to show the dots and conceal the typed characters.
password!!.inputType = InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_VARIATION_PASSWORD or
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
// Move the cursor to the correct place (after the typed character)
password!!.setSelection(s.length)
inputTypeChanged = true
}
} else {
// Reset EditText: Make the "Enter password" hint display on the right
password!!.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
inputTypeChanged = false
}
}
}
})
}
private fun languageSetup() {
if (!StaticVariables.language) {
//email.setText("ايميل");
//email.setText("ايميل");
}
}
/** send the attendence */
fun doTask(json: String) {
/* final ProgressDialog progressDialog = new ProgressDialog(Login.this) ;
progressDialog.setMessage(getResources().getString(R.string.progress_text));
progressDialog.setIndeterminate(true);*/
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
val drawable = ProgressBar(this).indeterminateDrawable.mutate()
drawable.setColorFilter(ContextCompat.getColor(this, R.color.colorAccent),
PorterDuff.Mode.SRC_IN)
//progressDialog.setIndeterminateDrawable(drawable);
}
//progressDialog.setCancelable(false);
spinKitView!!.visibility = View.VISIBLE
val url = resources.getString(R.string.login_url)
val stringRequest = object : StringRequest(Request.Method.POST, url,
Response.Listener { response ->
Log.i("RESPONSE", "" + response)
try {
val array = JSONObject(response)
val status = array.getBoolean("status")
if (status) {
val id = array.getString("id")
val lastname = array.getString("lastname")
val firstname = array.getString("firstname")
//String phone = array.getString("phone");
val email = array.getString("email")
if (spinKitView != null)
spinKitView!!.visibility = View.GONE
Toast.makeText(this@Login, "Login Sucessfully", Toast.LENGTH_SHORT).show()
StaticVariables.setCurrentUserId(this@Login, id, lastname, firstname, "", email)
val i = Intent(this@Login, Dashboard::class.java)
i.putExtra("id", id)
startActivity(i)
} else {
Toast.makeText(this@Login, "Password is incorrect", Toast.LENGTH_SHORT).show()
}
Log.wtf("Test", "onResponse: " + array.toString())
if (spinKitView != null)
spinKitView!!.visibility = View.GONE
} catch (e: JSONException) {
e.printStackTrace()
if (spinKitView != null)
spinKitView!!.visibility = View.GONE
Toast.makeText(this@Login, "Error due to JSON ", Toast.LENGTH_SHORT).show()
}
},
Response.ErrorListener {
if (spinKitView != null)
spinKitView!!.visibility = View.GONE
Toast.makeText(this@Login, "Internet is Not working correctly", Toast.LENGTH_SHORT).show()
}) {
/*@Override
public String getBodyContentType() {
//return "application/json; charset=utf-8";
}*/
@Throws(AuthFailureError::class)
override fun getParams(): Map<String, String> {
super.getParams()
val value = HashMap<String, String>()
value.put("email", email!!.text.toString())
value.put("password", password!!.text.toString())
return value
}
}
val requestQueue = Volley.newRequestQueue(this)
requestQueue.add(stringRequest)
return
}
fun signUpAction(view: View) {
startActivity(Intent(this@Login, Signup::class.java))
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
googlerhelper!!.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
val emailS = data.getStringExtra("email")
val passwdS = data.getStringExtra("pass")
email!!.setText(emailS)
password!!.setText(passwdS)
}
}
// EVENT CLICK BUTTON SIMPLE
fun loginButtonGoogle(view: View) {
googlerhelper!!.performSignIn(this@Login)
}
private fun toast(msg: String) {
Toast.makeText(this@Login, msg, Toast.LENGTH_LONG).show()
}
override fun onGoogleAuthSignIn(authToken: String, userId: String) {
Toast.makeText(this, "you are logged in " + userId, Toast.LENGTH_SHORT).show()
}
override fun onGoogleAuthSignInFailed(errorMessage: String) {
Toast.makeText(this, "Fail to loggin", Toast.LENGTH_SHORT).show()
}
override fun onGoogleAuthSignOut() {
}
fun loginButtonLinken(view: View) {
//linkedInLogin();
}
fun twitterLogin(view:View){
toast("twitter login")
connectTwitter()
}
fun connectTwitter() {
SimpleAuth.connectTwitter(object : AuthCallback {
override fun onSuccess(socialUser: SocialUser) {
toast("Login sucess fully "+socialUser.fullName)
//ProfileActivity.start(this@MainActivity, TWITTER, socialUser)
}
override fun onError(error: Throwable) {
toast(error.message ?: "")
}
override fun onCancel() {
toast("Canceled")
}
})
}
fun loginButtonTwitter(view: View) {
connectTwitter()
/* SimpleAuthTwitterKt.connectTwitter(scopes, new AuthCallback() {
@Override
public void onSuccess(SocialUser socialUser) {
Toast.makeText(Login.this, ""+socialUser.fullName, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Throwable throwable) {
}
@Override
public void onCancel() {
}
});*/
/*SimpleAuthTwitterKt.connectTwitter(new AuthCallback() {
@Override
public void onSuccess(SocialUser socialUser) {
//ProfileActivity.start(MainActivity.this, TWITTER, socialUser);
Toast.makeText(Login.this, ""+socialUser.fullName, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Throwable error) {
toast(error.getMessage());
}
@Override
public void onCancel() {
toast("Canceled");
}
});
*/
}
fun loginButtonFB() {
connectFacebook()
}
fun connectFacebook() {
val scopes = Arrays.asList("user_birthday", "user_friends")
SimpleAuth.connectFacebook(scopes, object : AuthCallback {
override fun onSuccess(socialUser: SocialUser) {
//ProfileActivity.start(this@MainActivity, FACEBOOK, socialUser)
toast("Login Sucessfully")
}
override fun onError(error: Throwable) {
toast(error.message ?: "")
}
override fun onCancel() {
toast("Canceled")
}
})
}
companion object {
const val FACEBOOK = "FACEBOOK"
const val GOOGLE = "GOOGLE"
const val TWITTER = "TWITTER"
const val INSTAGRAM = "INSTAGRAM"
private val RC_SIGN_IN = 188
private val TAG = "TEST"
fun isRTL(context: Context): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
context.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL
// Another way:
// Define a boolean resource as "true" in res/values-ldrtl
// and "false" in res/values
// return context.getResources().getBoolean(R.bool.is_right_to_left);
} else {
false
}
}
}
}
can you provide the error stacktrace?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.noumanch.selalf, PID: 7478
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:6205)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:6205)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property context has not been initialized
at com.jaychang.sa.Initializer.getContext(Initializer.kt:8)
at com.jaychang.sa.twitter.SimpleAuthTwitterKt.connectTwitter(SimpleAuthTwitter.kt:24)
at com.noumanch.selalf.activities.Login.connectTwitter(Login.kt:322)
at com.noumanch.selalf.activities.Login.twitterLogin(Login.kt:319)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:6205)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
does your app have multiple processes?
no i don't have
i'm using this for long suddenly my friend told me that your login feature is not working and i checked and found that this error is occuring.
can you create a demo that can reproduce this issue, so that i can dig into it?
i have run your example its working perfectly don't know why it is giving me issue
I'm getting following error when i press button to execute the code: