Skip to content

Commit

Permalink
Edit PasswordScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
gohj99 committed Aug 4, 2024
1 parent d0b4ca9 commit 899ee46
Show file tree
Hide file tree
Showing 9 changed files with 483 additions and 118 deletions.
15 changes: 13 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

252 changes: 252 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ android {
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand Down
39 changes: 32 additions & 7 deletions app/src/main/java/com/gohj99/telewatch/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gohj99.telewatch

import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
Expand All @@ -8,23 +9,27 @@ import android.util.TypedValue
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.*
import com.gohj99.telewatch.ui.login.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.gohj99.telewatch.ui.login.SplashLoginScreen
import com.gohj99.telewatch.ui.login.SplashPasswordScreen
import com.gohj99.telewatch.ui.theme.TelewatchTheme
import com.google.zxing.BarcodeFormat
import com.google.zxing.EncodeHintType
import com.google.zxing.MultiFormatWriter
import com.google.zxing.WriterException
import org.drinkless.td.libcore.telegram.Client
import org.drinkless.td.libcore.telegram.TdApi
import java.io.IOException
import java.util.Properties
import com.google.zxing.EncodeHintType
import com.google.zxing.MultiFormatWriter
import com.google.zxing.WriterException

class LoginActivity : ComponentActivity() {
private lateinit var client: Client
private var qrCodeLink by mutableStateOf<String?>(null)
private var showPasswordScreen by mutableStateOf(false)
private var passwordHint by mutableStateOf("")
private var doneStr = mutableStateOf("")

override fun onDestroy() {
super.onDestroy()
Expand All @@ -42,16 +47,17 @@ class LoginActivity : ComponentActivity() {
onDoneClick = { password ->
client.send(TdApi.CheckAuthenticationPassword(password), { authRequestHandler(it) })
},
passwordHint = passwordHint
passwordHint = passwordHint,
doneStr = doneStr
)
} else {
SplashLoginScreen(qrCodeLink = qrCodeLink)
}
}
}

// 初始化 TDLib 客户端
client = Client.create({ update -> handleUpdate(update) }, null, null)
doneStr.value = getString(R.string.Done) // 初始化 doneStr
}

// 加载配置文件
Expand Down Expand Up @@ -148,6 +154,25 @@ class LoginActivity : ComponentActivity() {
// 处理认证请求的函数
private fun authRequestHandler(result: TdApi.Object) {
// 处理认证请求结果
when (result.constructor) {
TdApi.Error.CONSTRUCTOR -> {
val error = result as TdApi.Error
println("${getString(R.string.Request_error)} : ${error.message}")
when (error.message) {
"PASSWORD_HASH_INVALID" -> {
doneStr.value = getString(R.string.Password_Error)
}

else -> runOnUiThread {
AlertDialog.Builder(this)
.setMessage("${getString(R.string.Request_error)}\ncode:${error.code}\n${error.message}")
.setPositiveButton(getString(R.string.OK)) { dialog, which -> }
.show()
}
}
}
// 处理其他结果...
}
}
}

Expand Down
Loading

0 comments on commit 899ee46

Please sign in to comment.