Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad92e93660 | ||
|
|
bcebc1dbcf |
4 changed files with 37 additions and 6 deletions
|
|
@ -22,8 +22,8 @@ android {
|
|||
applicationId = "dev.n1ko.nikogpt"
|
||||
minSdk = 29 // Android 10
|
||||
targetSdk = 35
|
||||
versionCode = 6
|
||||
versionName = "1.2.0"
|
||||
versionCode = 8
|
||||
versionName = "1.2.2"
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
// Shared text ("Share to NikoGPT") waiting for the page to load.
|
||||
private var pendingShare: String? = null
|
||||
// Whether the chat's inner scroll container is at the top; pull-to-refresh
|
||||
// only fires there (the WebView itself never scrolls).
|
||||
@Volatile
|
||||
private var webAtTop = true
|
||||
// Where the camera writes the picture before it reaches the web app.
|
||||
private var pendingCameraUri: Uri? = null
|
||||
|
||||
|
|
@ -95,16 +99,28 @@ class MainActivity : AppCompatActivity() {
|
|||
private val legacySignIn: ActivityResultLauncher<Intent> =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
val link = legacyLinkMode
|
||||
try {
|
||||
val account = GoogleSignIn.getSignedInAccountFromIntent(result.data)
|
||||
val account = try {
|
||||
GoogleSignIn.getSignedInAccountFromIntent(result.data)
|
||||
.getResult(ApiException::class.java)
|
||||
val token = account?.idToken
|
||||
if (!token.isNullOrBlank()) deliverToken(token, link) else openGoogleInBrowser(link)
|
||||
} catch (e: ApiException) {
|
||||
// 12501/16 = the user closed the picker: stay in the app.
|
||||
if (e.statusCode == 12501 || e.statusCode == 16) return@registerForActivityResult
|
||||
Toast.makeText(this, getString(R.string.google_error_code, e.statusCode), Toast.LENGTH_LONG).show()
|
||||
openGoogleInBrowser(link)
|
||||
return@registerForActivityResult
|
||||
} catch (e: Exception) {
|
||||
openGoogleInBrowser(link)
|
||||
return@registerForActivityResult
|
||||
}
|
||||
val token = account?.idToken
|
||||
if (token.isNullOrBlank()) {
|
||||
// microG accepted the account but could not mint an ID token
|
||||
// (e.g. device registration is off): say so, then fall back.
|
||||
Toast.makeText(this, getString(R.string.google_no_token), Toast.LENGTH_LONG).show()
|
||||
openGoogleInBrowser(link)
|
||||
return@registerForActivityResult
|
||||
}
|
||||
deliverToken(token, link)
|
||||
}
|
||||
|
||||
// Runtime microphone permission, bridged to the WebView.
|
||||
|
|
@ -264,6 +280,10 @@ class MainActivity : AppCompatActivity() {
|
|||
})
|
||||
|
||||
refresh.setOnRefreshListener { webView.reload() }
|
||||
// Pull-to-refresh only when the chat list is really at the top; a
|
||||
// bigger trigger distance keeps normal scrolling from reloading.
|
||||
refresh.setOnChildScrollUpCallback { _, _ -> !webAtTop }
|
||||
refresh.setDistanceToTriggerSync((80 * resources.displayMetrics.density).toInt())
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
|
|
@ -340,6 +360,13 @@ class MainActivity : AppCompatActivity() {
|
|||
fun linkGoogle(clientId: String) {
|
||||
runOnUiThread { openGooglePicker(clientId, link = true) }
|
||||
}
|
||||
|
||||
// The web app reports the message list's scroll position, so pulling
|
||||
// down only refreshes when the list really is at the top.
|
||||
@JavascriptInterface
|
||||
fun setAtTop(atTop: Boolean) {
|
||||
webAtTop = atTop
|
||||
}
|
||||
}
|
||||
|
||||
// openGooglePicker tries the native pickers in order: Credential Manager
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
<string name="download_started">Загрузка началась</string>
|
||||
<string name="download_failed">Не удалось начать загрузку</string>
|
||||
<string name="google_error">Не удалось войти через Google (%1$s)</string>
|
||||
<string name="google_error_code">Не удалось войти через Google (код %1$d)</string>
|
||||
<string name="google_no_token">Google не вернул ID-токен (проверьте Android OAuth-клиент: package и SHA-1)</string>
|
||||
<string name="attach_file">Файл</string>
|
||||
<string name="attach_camera">Камера</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
<string name="download_started">Download started</string>
|
||||
<string name="download_failed">Could not start the download</string>
|
||||
<string name="google_error">Google sign-in failed (%1$s)</string>
|
||||
<string name="google_error_code">Google sign-in failed (code %1$d)</string>
|
||||
<string name="google_no_token">Google did not return an ID token (check the Android OAuth client, package and SHA-1)</string>
|
||||
<string name="attach_file">File</string>
|
||||
<string name="attach_camera">Camera</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue