fixed password signin

This commit is contained in:
Mariotaku Lee 2017-01-27 22:35:28 +08:00
parent 7c9a9b5ef7
commit e172d6b95a
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 36 additions and 26 deletions

View File

@ -34,8 +34,8 @@ android {
applicationId "org.mariotaku.twidere"
minSdkVersion 14
targetSdkVersion 25
versionCode 261
versionName '3.4.0'
versionCode 262
versionName '3.4.1'
multiDexEnabled true
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")'

View File

@ -170,7 +170,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, APIEditorDi
}
REQUEST_BROWSER_SIGN_IN -> {
if (resultCode == Activity.RESULT_OK && data != null) {
doBrowserLogin(data)
handleBrowserLoginResult(data)
}
}
}
@ -226,7 +226,11 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, APIEditorDi
editUsername.text = null
editPassword.text = null
}
doLogin()
if (apiConfig.credentialsType == Credentials.Type.OAUTH) {
doBrowserLogin()
} else {
doLogin()
}
}
passwordSignIn -> {
executeAfterFragmentResumed { fragment ->
@ -309,7 +313,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, APIEditorDi
}
}
internal fun openBrowserLogin(): Boolean {
internal fun doBrowserLogin(): Boolean {
if (apiConfig.credentialsType != Credentials.Type.OAUTH || signInTask != null && signInTask!!.status == AsyncTask.Status.RUNNING)
return true
val intent = Intent(this, BrowserSignInActivity::class.java)
@ -322,10 +326,6 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, APIEditorDi
if (signInTask != null && signInTask!!.status == AsyncTask.Status.RUNNING) {
signInTask!!.cancel(true)
}
if (apiConfig.credentialsType == Credentials.Type.OAUTH) {
openBrowserLogin()
return
}
val username = editUsername.text.toString()
val password = editPassword.text.toString()
@ -435,7 +435,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, APIEditorDi
}
}
private fun doBrowserLogin(intent: Intent?) {
private fun handleBrowserLoginResult(intent: Intent?) {
if (intent == null) return
if (signInTask?.status == AsyncTask.Status.RUNNING) {
signInTask?.cancel(true)

View File

@ -34,10 +34,13 @@ val AccountExtras.official: Boolean
@JvmOverloads
fun <T> AccountDetails.newMicroBlogInstance(context: Context, includeEntities: Boolean = true, includeRetweets: Boolean = true,
extraRequestParams: Map<String, String>? =
MicroBlogAPIFactory.getExtraParams(type, includeEntities, includeRetweets),
cls: Class<T>): T {
fun <T> AccountDetails.newMicroBlogInstance(
context: Context,
includeEntities: Boolean = true,
includeRetweets: Boolean = true,
extraRequestParams: Map<String, String>? = MicroBlogAPIFactory.getExtraParams(type, includeEntities, includeRetweets),
cls: Class<T>
): T {
return credentials.newMicroBlogInstance(context, type == AccountType.TWITTER, extraRequestParams, cls)
}

View File

@ -99,20 +99,24 @@ fun Credentials.getEndpoint(cls: Class<*>): Endpoint {
return Endpoint(endpointUrl)
}
fun <T> Credentials.newMicroBlogInstance(context: Context,
twitterExtraQueries: Boolean = true,
extraRequestParams: Map<String, String>? = null,
cls: Class<T>): T {
fun <T> Credentials.newMicroBlogInstance(
context: Context,
twitterExtraQueries: Boolean = true,
extraRequestParams: Map<String, String>? = null,
cls: Class<T>
): T {
return newMicroBlogInstance(context, getEndpoint(cls), getAuthorization(),
twitterExtraQueries, extraRequestParams, cls)
}
fun <T> newMicroBlogInstance(context: Context,
endpoint: Endpoint,
auth: Authorization,
twitterExtraQueries: Boolean = true,
extraRequestParams: Map<String, String>? = null,
cls: Class<T>): T {
fun <T> newMicroBlogInstance(
context: Context,
endpoint: Endpoint,
auth: Authorization,
twitterExtraQueries: Boolean = true,
extraRequestParams: Map<String, String>? = null,
cls: Class<T>
): T {
val factory = RestAPIFactory<MicroBlogException>()
val userAgent: String
if (auth is OAuthAuthorization) {

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@ -12,8 +13,9 @@
android:layout_height="wrap_content"
android:hint="@string/username"
android:inputType="textEmailAddress"
android:maxLines="1"
android:typeface="normal"
android:maxLines="1"/>
app:backgroundTint="?colorAccent"/>
<EditText
android:id="@+id/password"
@ -22,7 +24,8 @@
android:layout_marginTop="@dimen/element_spacing_normal"
android:hint="@string/password"
android:inputType="textPassword"
android:maxLines="1"
android:typeface="normal"
android:maxLines="1"/>
app:backgroundTint="?colorAccent"/>
</LinearLayout>