LoginActivity: add a way to change application name and website during login

This commit is contained in:
Alibek Omarov 2019-12-12 06:11:41 +03:00
parent db2cee80d2
commit 781cb09437
3 changed files with 102 additions and 14 deletions

View File

@ -55,15 +55,22 @@ class LoginActivity : BaseActivity(), Injectable {
val host = BuildConfig.APPLICATION_ID
return "$scheme://$host/"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
if(savedInstanceState == null && BuildConfig.CUSTOM_INSTANCE.isNotBlank() && !isAdditionalLogin()) {
domainEditText.setText(BuildConfig.CUSTOM_INSTANCE)
domainEditText.setSelection(BuildConfig.CUSTOM_INSTANCE.length)
if(savedInstanceState == null ) {
if(BuildConfig.CUSTOM_INSTANCE.isNotBlank() && !isAdditionalLogin()) {
domainEditText.setText(BuildConfig.CUSTOM_INSTANCE)
domainEditText.setSelection(BuildConfig.CUSTOM_INSTANCE.length)
}
appNameEditText.setText(getString(R.string.app_name))
appNameEditText.setSelection(getString(R.string.app_name).length)
websiteEditText.setText(getString(R.string.tusky_website))
websiteEditText.setSelection(getString(R.string.tusky_website).length)
}
if(BuildConfig.CUSTOM_LOGO_URL.isNotBlank()) {
@ -77,6 +84,7 @@ class LoginActivity : BaseActivity(), Injectable {
getString(R.string.preferences_file_key), Context.MODE_PRIVATE)
loginButton.setOnClickListener { onButtonClick() }
settingsButton.setOnClickListener { onSettingsButtonClick() }
whatsAnInstanceTextView.setOnClickListener {
val dialog = AlertDialog.Builder(this)
@ -115,6 +123,15 @@ class LoginActivity : BaseActivity(), Injectable {
}
return super.onOptionsItemSelected(item)
}
private fun onSettingsButtonClick() {
if(extendedSettings.visibility == View.GONE) {
extendedSettings.visibility = View.VISIBLE
} else {
extendedSettings.visibility = View.GONE
}
}
/**
* Obtain the oauth client credentials for this app. This is only necessary the first time the
@ -165,10 +182,17 @@ class LoginActivity : BaseActivity(), Injectable {
Log.e(TAG, Log.getStackTraceString(t))
}
}
var appname = getString(R.string.app_name)
var website = getString(R.string.tusky_website)
if(extendedSettings.visibility == View.VISIBLE) {
appname = appNameEditText.text.toString()
website = websiteEditText.text.toString()
}
mastodonApi
.authenticateApp(domain, getString(R.string.app_name), oauthRedirectUri,
OAUTH_SCOPES, getString(R.string.tusky_website))
.authenticateApp(domain, appname, oauthRedirectUri,
OAUTH_SCOPES, website)
.enqueue(callback)
setLoading(true)

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M19.43 12.98c0.04-0.32 0.07 -0.64 0.07 -0.98s-0.03-0.66-0.07-0.98l2.11-1.65c0.19-0.15 0.24 -0.42 0.12 -0.64l-2-3.46c-0.12-0.22-0.39-0.3-0.61-0.22l-2.49 1c-0.52-0.4-1.08-0.73-1.69-0.98l-0.38-2.65C14.46 2.18 14.25 2 14 2h-4c-0.25 0-0.46 0.18 -0.49 0.42 l-0.38 2.65c-0.61 0.25 -1.17 0.59 -1.69 0.98 l-2.49-1c-0.23-0.09-0.49 0-0.61 0.22 l-2 3.46c-0.13 0.22 -0.07 0.49 0.12 0.64 l2.11 1.65c-0.04 0.32 -0.07 0.65 -0.07 0.98 s0.03 0.66 0.07 0.98 l-2.11 1.65c-0.19 0.15 -0.24 0.42 -0.12 0.64 l2 3.46c0.12 0.22 0.39 0.3 0.61 0.22 l2.49-1c0.52 0.4 1.08 0.73 1.69 0.98 l0.38 2.65c0.03 0.24 0.24 0.42 0.49 0.42 h4c0.25 0 0.46-0.18 0.49 -0.42l0.38-2.65c0.61-0.25 1.17-0.59 1.69-0.98l2.49 1c0.23 0.09 0.49 0 0.61-0.22l2-3.46c0.12-0.22 0.07 -0.49-0.12-0.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z" />
</vector>

View File

@ -52,16 +52,70 @@
android:ems="10"
android:inputType="textUri" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/loginButton"
style="@style/TuskyButton"
android:layout_width="250dp"
<LinearLayout
android:id="@+id/extendedSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
style="@style/TuskyTextInput"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="@string/hint_appname"
android:layout_marginTop="8dp"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/appNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textUri" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/TuskyTextInput"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="@string/hint_website"
android:layout_marginTop="8dp"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/websiteEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textUri" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="@string/action_login" />
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/loginButton"
style="@style/TuskyButton"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:gravity="center"
android:text="@string/action_login" />
<com.google.android.material.button.MaterialButton
android:id="@+id/settingsButton"
style="@style/TuskyButton"
android:padding="4dp"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:gravity="center"
app:icon="@drawable/ic_settings" />
</LinearLayout>
<TextView
android:id="@+id/whatsAnInstanceTextView"
android:layout_width="250dp"