Browse Source

Limit the width of the login screen in landscape mode to be easier on the eye.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
100514cde6
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 23
      app/src/main/java/com/github/apognu/otter/activities/LoginActivity.kt
  2. 2
      app/src/main/res/layout/activity_login.xml

23
app/src/main/java/com/github/apognu/otter/activities/LoginActivity.kt

@ -1,10 +1,13 @@ @@ -1,10 +1,13 @@
package com.github.apognu.otter.activities
import android.content.Intent
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.doOnLayout
import androidx.lifecycle.lifecycleScope
import com.github.apognu.otter.R
import com.github.apognu.otter.fragments.LoginDialog
@ -27,6 +30,8 @@ class LoginActivity : AppCompatActivity() { @@ -27,6 +30,8 @@ class LoginActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
limitContainerWidth()
}
override fun onResume() {
@ -79,6 +84,12 @@ class LoginActivity : AppCompatActivity() { @@ -79,6 +84,12 @@ class LoginActivity : AppCompatActivity() {
}
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
limitContainerWidth()
}
private fun authedLogin(hostname: String, username: String, password: String) {
val body = mapOf(
"username" to username,
@ -180,4 +191,16 @@ class LoginActivity : AppCompatActivity() { @@ -180,4 +191,16 @@ class LoginActivity : AppCompatActivity() {
}
}
}
private fun limitContainerWidth() {
container.doOnLayout {
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && container.width >= 1440) {
container.layoutParams.width = 1440
} else {
container.layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
}
container.requestLayout()
}
}
}

2
app/src/main/res/layout/activity_login.xml

@ -5,8 +5,10 @@ @@ -5,8 +5,10 @@
android:background="@color/colorPrimary">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="vertical"
android:padding="32dp">

Loading…
Cancel
Save