Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues related to AuthSignIn page #2585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ package org.microg.gms.auth.signin
import android.accounts.Account
import android.accounts.AccountManager
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Bitmap
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.ListView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
Expand All @@ -24,7 +26,6 @@ import com.google.android.gms.auth.api.identity.SignInCredential
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.SignInAccount
import com.google.android.gms.auth.api.signin.internal.SignInConfiguration
import com.google.android.gms.common.Scopes
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.common.api.Status
import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer
Expand All @@ -36,7 +37,6 @@ import org.microg.gms.auth.AuthConstants
import org.microg.gms.auth.AuthConstants.DEFAULT_ACCOUNT
import org.microg.gms.auth.AuthConstants.DEFAULT_ACCOUNT_TYPE
import org.microg.gms.auth.login.LoginActivity
import org.microg.gms.people.DatabaseHelper
import org.microg.gms.people.PeopleManager
import org.microg.gms.utils.getApplicationLabel

Expand All @@ -53,7 +53,7 @@ class AuthSignInActivity : AppCompatActivity() {
intent?.extras?.also { it.classLoader = SignInConfiguration::class.java.classLoader }?.getParcelable<SignInConfiguration>("config")
}.getOrNull()

private val Int.px: Int get() = (this * resources.displayMetrics.density).toInt()
private lateinit var accountManager: AccountManager

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -64,8 +64,12 @@ class AuthSignInActivity : AppCompatActivity() {
val packageName = config?.packageName
if (packageName == null || (packageName != callingActivity?.packageName && callingActivity?.packageName != this.packageName))
return finishResult(CommonStatusCodes.DEVELOPER_ERROR, "package name mismatch")
val accountManager = getSystemService<AccountManager>() ?: return finishResult(CommonStatusCodes.INTERNAL_ERROR, "No account manager")
accountManager = getSystemService<AccountManager>() ?: return finishResult(CommonStatusCodes.INTERNAL_ERROR, "No account manager")

initView()
}

private fun initView(){
val accounts = accountManager.getAccountsByType(DEFAULT_ACCOUNT_TYPE)
if (accounts.isNotEmpty()) {
val account = config?.options?.account
Expand Down Expand Up @@ -121,17 +125,23 @@ class AuthSignInActivity : AppCompatActivity() {

private fun openAccountPicker(packageName: String) {
val binding = SigninPickerBinding.inflate(layoutInflater)
var accountListView: ListView = binding.pickerList
binding.isLand = (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE).also {
if (it) {
accountListView = binding.pickerListLand
}
}
binding.appName = packageManager.getApplicationLabel(packageName).toString()
binding.appIcon = packageManager.getApplicationIcon(packageName)
val accounts = getSystemService<AccountManager>()!!.getAccountsByType(DEFAULT_ACCOUNT_TYPE) + Account(DEFAULT_ACCOUNT, DEFAULT_ACCOUNT_TYPE)
binding.pickerList.adapter = object : ArrayAdapter<Account>(this, 0, accounts) {
accountListView.adapter = object : ArrayAdapter<Account>(this, 0, accounts) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val v = convertView ?: layoutInflater.inflate(R.layout.signin_account_row, parent, false)
getItem(position)?.let { bindAccountRow(v, it) { _, _ -> notifyDataSetChanged() } }
return v
}
}
binding.pickerList.setOnItemClickListener { parent, view, position, id ->
accountListView.setOnItemClickListener { parent, view, position, id ->
binding.listProgressSpinner = true
if (accounts[position].name == DEFAULT_ACCOUNT) {
openAddAccount()
Expand Down Expand Up @@ -230,4 +240,9 @@ class AuthSignInActivity : AppCompatActivity() {
}
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
initView()
}
}
132 changes: 84 additions & 48 deletions play-services-core/src/main/res/layout/signin_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,101 @@
name="listProgressSpinner"
type="boolean" />

<variable
name="isLand"
type="boolean" />

<import type="android.view.View" />

</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:layout_marginTop="32dp"
android:layout_marginBottom="16dp"
android:layout_marginHorizontal="16dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
app:imageDrawable="@{appIcon}"
tools:src="@mipmap/ic_app" />

<TextView
android:layout_margin="2dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signin_picker_title"
android:maxLines="2"
style="@style/TextAppearance.AppCompat.Title" />

<TextView
android:id="@+id/picker_subtitle"
android:layout_margin="2dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{@string/signin_picker_subtitle(appName)}"
tools:text="@string/signin_picker_subtitle"
style="@style/TextAppearance.AppCompat.Medium" />
android:orientation="horizontal"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:layout_marginTop="32dp"
android:layout_marginBottom="16dp"
android:layout_marginHorizontal="16dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
app:imageDrawable="@{appIcon}"
tools:src="@mipmap/ic_app" />

<TextView
android:layout_margin="2dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signin_picker_title"
android:maxLines="2"
style="@style/TextAppearance.AppCompat.Title" />

<TextView
android:id="@+id/picker_subtitle"
android:layout_margin="2dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{@string/signin_picker_subtitle(appName)}"
tools:text="@string/signin_picker_subtitle"
style="@style/TextAppearance.AppCompat.Medium" />

<FrameLayout
android:layout_marginTop="24dp"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
app:visibility='@{isLand ? View.GONE : View.VISIBLE}'>

<ListView
android:id="@+id/picker_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:alpha="@{listProgressSpinner ? 0.6f : 1.0f}"
tools:listitem="@layout/signin_account_row" />

<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:visibility="invisible"
app:visibility='@{listProgressSpinner ? View.VISIBLE : View.INVISIBLE}' />

</FrameLayout>

<TextView
android:id="@+id/picker_subtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:maxLines="6"
android:text='@{@string/signin_subtext_sharing(appName) + (policySpanned != null ? " " + policySpanned : "")}'
style="@style/TextAppearance.AppCompat.Small"
tools:text="To continue, microG will share name, email address and profile picture of your Google Account with Test App. Before using this app, review its privacy policy and terms of service." />
</LinearLayout>

<FrameLayout
android:layout_marginTop="24dp"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:visibility='@{isLand ? View.VISIBLE : View.GONE}'>

<ListView
android:id="@+id/picker_list"
android:id="@+id/picker_list_land"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:alpha="@{listProgressSpinner ? 0.6f : 1.0f}"
tools:listitem="@layout/signin_account_row" />

Expand All @@ -87,14 +132,5 @@

</FrameLayout>

<TextView
android:id="@+id/picker_subtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:maxLines="6"
android:text='@{@string/signin_subtext_sharing(appName) + (policySpanned != null ? " " + policySpanned : "")}'
style="@style/TextAppearance.AppCompat.Small"
tools:text="To continue, microG will share name, email address and profile picture of your Google Account with Test App. Before using this app, review its privacy policy and terms of service." />
</LinearLayout>
</layout>