From 781cb0943774f7f302fd700d0469824a100b2000 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 12 Dec 2019 06:11:41 +0300 Subject: [PATCH] LoginActivity: add a way to change application name and website during login --- .../com/keylesspalace/tusky/LoginActivity.kt | 38 +++++++++-- app/src/main/res/drawable/ic_settings.xml | 10 +++ app/src/main/res/layout/activity_login.xml | 68 +++++++++++++++++-- 3 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/drawable/ic_settings.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt index 7deb2dd7..8938abaa 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt @@ -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) diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml new file mode 100644 index 00000000..b8520543 --- /dev/null +++ b/app/src/main/res/drawable/ic_settings.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 25844b69..d2c6ec93 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -52,16 +52,70 @@ android:ems="10" android:inputType="textUri" /> - - + + + + + + + + + + + + + android:orientation="horizontal"> + + + +