Merge pull request #25 from alone-wolf/main

主要更改:增加key/device重命名逻辑,增加多国语言适配
This commit is contained in:
Easy 2022-01-21 12:39:06 +08:00 committed by GitHub
commit 3f5bf6a292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 328 additions and 184 deletions

View File

@ -13,6 +13,7 @@
<entry key="../../../../layout/compose-model-1641659551303.xml" value="2.0" /> <entry key="../../../../layout/compose-model-1641659551303.xml" value="2.0" />
<entry key="../../../../layout/compose-model-1641659962289.xml" value="2.0" /> <entry key="../../../../layout/compose-model-1641659962289.xml" value="2.0" />
<entry key="../../../../layout/compose-model-1641694023752.xml" value="0.1" /> <entry key="../../../../layout/compose-model-1641694023752.xml" value="0.1" />
<entry key="../../../../layout/compose-model-1642733328920.xml" value="2.0" />
<entry key="app/src/main/res/drawable/fragment_qr_scan.xml" value="0.12314814814814815" /> <entry key="app/src/main/res/drawable/fragment_qr_scan.xml" value="0.12314814814814815" />
<entry key="app/src/main/res/drawable/ic_markdown.xml" value="0.12962962962962962" /> <entry key="app/src/main/res/drawable/ic_markdown.xml" value="0.12962962962962962" />
</map> </map>

View File

@ -101,6 +101,11 @@
* 将自动注册设备修改为手动点击加号注册设备 * 将自动注册设备修改为手动点击加号注册设备
* 当前app几乎处于可以使用的状态 * 当前app几乎处于可以使用的状态
* 2022-01-21
* 修改登陆界面ui
* 增加key/device的重命名逻辑
* 适配英语和中文
### 感谢 ### 感谢

View File

@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.pushdeer.os",
"variantName": "debug",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"outputFile": "app-debug.apk"
}
],
"elementType": "File"
}

Binary file not shown.

View File

@ -62,6 +62,7 @@ class MainActivity : AppCompatActivity(), RequestHolder {
override val messageViewModel: MessageViewModel by viewModels { viewModelFactory } override val messageViewModel: MessageViewModel by viewModels { viewModelFactory }
override val settingStore: SettingStore by lazy { (application as App).storeKeeper.settingStore } override val settingStore: SettingStore by lazy { (application as App).storeKeeper.settingStore }
override val fragmentManager: FragmentManager by lazy { this.supportFragmentManager } override val fragmentManager: FragmentManager by lazy { this.supportFragmentManager }
// override val resource: Resources by lazy { this.resource }
override val coilImageLoader: ImageLoader by lazy { override val coilImageLoader: ImageLoader by lazy {
ImageLoader.Builder(this) ImageLoader.Builder(this)
@ -72,7 +73,7 @@ class MainActivity : AppCompatActivity(), RequestHolder {
} }
.build() .build()
} }
override val alert: RequestHolder.AlertRequest = object : RequestHolder.AlertRequest() {} override val alert: RequestHolder.AlertRequest by lazy { object : RequestHolder.AlertRequest(resources) {} }
override val markdown: Markwon by lazy { override val markdown: Markwon by lazy {
Markwon.builder(this) Markwon.builder(this)

View File

@ -1,7 +1,10 @@
package com.pushdeer.os.data.api package com.pushdeer.os.data.api
import com.pushdeer.os.data.api.data.response.* import com.pushdeer.os.data.api.data.response.*
import retrofit2.http.* import retrofit2.http.Field
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
interface PushDeerApi { interface PushDeerApi {
companion object { companion object {
@ -12,8 +15,8 @@ interface PushDeerApi {
@POST("/login/idtoken") @POST("/login/idtoken")
suspend fun loginIdToken(@Field("idToken") idToken: String): ReturnData<TokenOnly> suspend fun loginIdToken(@Field("idToken") idToken: String): ReturnData<TokenOnly>
@GET("/login/fake") // @GET("/login/fake")
suspend fun fakeLogin(): ReturnData<TokenOnly> // suspend fun fakeLogin(): ReturnData<TokenOnly>
@FormUrlEncoded @FormUrlEncoded
@POST("/user/info") @POST("/user/info")
@ -31,6 +34,14 @@ interface PushDeerApi {
@POST("/device/remove") @POST("/device/remove")
suspend fun deviceRemove(@Field("token") token: String, @Field("id") id: Int): String suspend fun deviceRemove(@Field("token") token: String, @Field("id") id: Int): String
@FormUrlEncoded
@POST("/device/rename")
suspend fun deviceRename(
@Field("token") token: String,
@Field("id") id: Int,
@Field("name") newName: String
): String
@FormUrlEncoded @FormUrlEncoded
@POST("/key/gen") @POST("/key/gen")
suspend fun keyGen(@Field("token") token: String): ReturnData<PushKeyList> suspend fun keyGen(@Field("token") token: String): ReturnData<PushKeyList>
@ -47,6 +58,14 @@ interface PushDeerApi {
@POST("/key/remove") @POST("/key/remove")
suspend fun keyRemove(@FieldMap data: Map<String, String>): String suspend fun keyRemove(@FieldMap data: Map<String, String>): String
@FormUrlEncoded
@POST("/key/rename")
suspend fun keyRename(
@Field("token") token: String,
@Field("id") id: String,
@Field("name") newName: String
): String
@FormUrlEncoded @FormUrlEncoded
@POST("/message/push") @POST("/message/push")
suspend fun messagePush(@FieldMap data: Map<String, String>): String suspend fun messagePush(@FieldMap data: Map<String, String>): String

View File

@ -1,13 +0,0 @@
package com.pushdeer.os.data.api.data.response
class DeviceRemove {
var token: String = ""
var id = ""
fun toMap():Map<String,String> {
return mapOf(
"token" to token,
"id" to id
)
}
}

View File

@ -1,4 +0,0 @@
package com.pushdeer.os.holder
interface DataHolder {
}

View File

@ -3,9 +3,10 @@ package com.pushdeer.os.holder
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Intent import android.content.Intent
import android.util.Log import android.content.res.Resources
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.StringRes
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
@ -13,6 +14,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import coil.ImageLoader import coil.ImageLoader
import com.pushdeer.os.R
import com.pushdeer.os.activity.QrScanActivity import com.pushdeer.os.activity.QrScanActivity
import com.pushdeer.os.data.api.data.request.DeviceInfo import com.pushdeer.os.data.api.data.request.DeviceInfo
import com.pushdeer.os.data.api.data.response.Message import com.pushdeer.os.data.api.data.response.Message
@ -40,7 +42,9 @@ interface RequestHolder {
val activityOpener: ActivityResultLauncher<Intent> val activityOpener: ActivityResultLauncher<Intent>
val coilImageLoader: ImageLoader val coilImageLoader: ImageLoader
val fragmentManager:FragmentManager // val resource:Resources
val fragmentManager: FragmentManager
val alert: AlertRequest val alert: AlertRequest
@ -73,6 +77,16 @@ interface RequestHolder {
} }
} }
fun keyRename(pushKey: PushKey){
coroutineScope.launch {
pushDeerViewModel.keyRename(pushKey){
coroutineScope.launch {
pushDeerViewModel.keyList()
}
}
}
}
fun deviceReg(deviceInfo: DeviceInfo) { fun deviceReg(deviceInfo: DeviceInfo) {
coroutineScope.launch { coroutineScope.launch {
pushDeerViewModel.deviceReg(deviceInfo) pushDeerViewModel.deviceReg(deviceInfo)
@ -86,6 +100,16 @@ interface RequestHolder {
} }
} }
fun deviceRename(deviceInfo: DeviceInfo) {
coroutineScope.launch {
pushDeerViewModel.deviceRename(deviceInfo) {
coroutineScope.launch {
pushDeerViewModel.deviceList()
}
}
}
}
fun messagePush(text: String, desp: String, type: String, pushkey: String) { fun messagePush(text: String, desp: String, type: String, pushkey: String) {
coroutineScope.launch { coroutineScope.launch {
pushDeerViewModel.messagePush(text, desp, type, pushkey) pushDeerViewModel.messagePush(text, desp, type, pushkey)
@ -100,8 +124,10 @@ interface RequestHolder {
pushDeerViewModel.messageList() pushDeerViewModel.messageList()
} }
} else { } else {
alert.alert("Alert", "You Should Add One PushKey", onOk = {}) alert.alert(
Log.d("WH_", "messagePushTest: keylist is empty") R.string.global_alert_title_alert,
R.string.main_message_send_alert,
onOk = {})
} }
} }
@ -124,13 +150,14 @@ interface RequestHolder {
} }
} }
abstract class AlertRequest { abstract class AlertRequest(private val resources: Resources) {
val show: MutableState<Boolean> = mutableStateOf(false) val show: MutableState<Boolean> = mutableStateOf(false)
var title: String = "" var title: String = ""
var content: @Composable () -> Unit = {} var content: @Composable () -> Unit = {}
var onOKAction: () -> Unit = {} var onOKAction: () -> Unit = {}
var onCancelAction: () -> Unit = {} var onCancelAction: () -> Unit = {}
fun alert( fun alert(
title: String, title: String,
content: @Composable () -> Unit, content: @Composable () -> Unit,
@ -145,11 +172,25 @@ interface RequestHolder {
} }
fun alert(title: String, content: String, onOk: () -> Unit, onCancel: () -> Unit = {}) { fun alert(title: String, content: String, onOk: () -> Unit, onCancel: () -> Unit = {}) {
this.title = title alert(title, { Text(text = content) }, onOk, onCancel)
this.content = { Text(text = content) } }
this.onOKAction = onOk
this.onCancelAction = onCancel fun alert(
this.show.value = true @StringRes title: Int,
@StringRes content: Int,
onOk: () -> Unit,
onCancel: () -> Unit = {}
) {
alert(resources.getString(title), resources.getString(content), onOk, onCancel)
}
fun alert(
@StringRes title: Int,
content: @Composable () -> Unit,
onOk: () -> Unit,
onCancel: () -> Unit={}
) {
alert(resources.getString(title), content, onOk, onCancel)
} }
} }
} }

View File

@ -33,7 +33,6 @@ class MessageReceiver : PushMessageReceiver() {
override fun onReceivePassThroughMessage(context: Context, message: MiPushMessage) { override fun onReceivePassThroughMessage(context: Context, message: MiPushMessage) {
init(context) init(context)
// Log.d("WH_", "onReceivePassThroughMessage: $message")
mMessage = message.content mMessage = message.content
if (!TextUtils.isEmpty(message.topic)) { if (!TextUtils.isEmpty(message.topic)) {
mTopic = message.topic mTopic = message.topic
@ -46,7 +45,6 @@ class MessageReceiver : PushMessageReceiver() {
override fun onNotificationMessageClicked(context: Context, message: MiPushMessage) { override fun onNotificationMessageClicked(context: Context, message: MiPushMessage) {
init(context) init(context)
// Log.d("WH_", "onNotificationMessageClicked: $message")
mMessage = message.content mMessage = message.content
if (!TextUtils.isEmpty(message.topic)) { if (!TextUtils.isEmpty(message.topic)) {
mTopic = message.topic mTopic = message.topic
@ -59,7 +57,6 @@ class MessageReceiver : PushMessageReceiver() {
override fun onNotificationMessageArrived(context: Context, message: MiPushMessage) { override fun onNotificationMessageArrived(context: Context, message: MiPushMessage) {
init(context) init(context)
// Log.d("WH_", "onNotificationMessageArrived: $message")
mMessage = message.content mMessage = message.content
if (!TextUtils.isEmpty(message.topic)) { if (!TextUtils.isEmpty(message.topic)) {
mTopic = message.topic mTopic = message.topic
@ -72,7 +69,6 @@ class MessageReceiver : PushMessageReceiver() {
override fun onCommandResult(context: Context, message: MiPushCommandMessage) { override fun onCommandResult(context: Context, message: MiPushCommandMessage) {
init(context) init(context)
// Log.d("WH_", "onCommandResult: $message")
val command = message.command val command = message.command
val arguments = message.commandArguments val arguments = message.commandArguments
val cmdArg1 = if (arguments != null && arguments.size > 0) arguments[0] else null val cmdArg1 = if (arguments != null && arguments.size > 0) arguments[0] else null
@ -108,7 +104,6 @@ class MessageReceiver : PushMessageReceiver() {
override fun onReceiveRegisterResult(context: Context, message: MiPushCommandMessage) { override fun onReceiveRegisterResult(context: Context, message: MiPushCommandMessage) {
init(context) init(context)
// Log.d("WH_", "onReceiveRegisterResult: $message")
val command = message.command val command = message.command
val arguments = message.commandArguments val arguments = message.commandArguments
val cmdArg1 = if (arguments != null && arguments.size > 0) arguments[0] else null val cmdArg1 = if (arguments != null && arguments.size > 0) arguments[0] else null

View File

@ -1,19 +0,0 @@
//package com.pushdeer.os.sss
//
//import android.content.Context
//import android.content.Intent
//import androidx.activity.result.contract.ActivityResultContract
//import com.pushdeer.os.activity.QrScanActivity
//
//class MyActivityResultContract : ActivityResultContract<String, String>() {
// override fun createIntent(context: Context, input: String): Intent {
// return QrScanActivity.forScanResultIntent(context)
// }
//
// override fun parseResult(resultCode: Int, intent: Intent?): String {
// intent?.let {
// return it.getStringExtra(QrScanActivity.DataKey).toString()
// }
// return ""
// }
//}

View File

@ -7,13 +7,13 @@ class SettingStore(context:Context) {
val store = Store.create(context,"setting") val store = Store.create(context,"setting")
var userToken by store.string("user-token","") var userToken by store.string("user-token","")
var deviceName by store.string("device-name","My Dear Deer") // var deviceName by store.string("device-name","My Dear Deer")
var useRecv by store.boolean("use-recv",false) // 启用接收 // var useRecv by store.boolean("use-recv",false) // 启用接收
var useSend by store.boolean("use-send",false) // var useSend by store.boolean("use-send",false)
var useSendNotification by store.boolean("use-send-notification",false) // var useSendNotification by store.boolean("use-send-notification",false)
var notificationPackages by store.stringSet("notification-packages", emptySet()) // var notificationPackages by store.stringSet("notification-packages", emptySet())
var useSendMissedCall by store.boolean("use-send=missed-call",false) // var useSendMissedCall by store.boolean("use-send=missed-call",false)
var useSendSMS by store.boolean("use-send-sms",false) // var useSendSMS by store.boolean("use-send-sms",false)
var showMessageSender by store.boolean("show-message-sender",true) var showMessageSender by store.boolean("show-message-sender",true)
var thisPushSdk by store.string("this-push-sdk","mi-push") var thisPushSdk by store.string("this-push-sdk","mi-push")

View File

@ -1,8 +0,0 @@
package com.pushdeer.os.typeExt
import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

View File

@ -8,11 +8,12 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange import androidx.compose.material.icons.filled.DateRange
import androidx.compose.runtime.Composable import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@ -24,8 +25,37 @@ import com.wh.common.util.TimeUtils
@ExperimentalMaterialApi @ExperimentalMaterialApi
@Composable @Composable
fun KeyItem(key: PushKey, requestHolder: RequestHolder) { fun KeyItem(key: PushKey,requestHolder: RequestHolder) {
CardItemWithContent { var name by remember {
mutableStateOf(key.name)
}
CardItemWithContent(onClick = {
requestHolder.alert.alert(
title = R.string.main_key_alert_changekeyname,
content = {
Column {
TextField(
value = name,
onValueChange = { name = it },
shape = RoundedCornerShape(6.dp),
singleLine = true,
maxLines = 1,
label = { Text(text = stringResource(id = R.string.main_key_alert_keyname)) },
colors = TextFieldDefaults.textFieldColors(
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
errorIndicatorColor = Color.Transparent,
)
)
}
},
onOk = {
key.name = name
requestHolder.keyRename(key)
}
)
}) {
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -113,7 +143,7 @@ fun KeyItem(key: PushKey, requestHolder: RequestHolder) {
border = BorderStroke(1.dp, MaterialTheme.colors.MBlue), border = BorderStroke(1.dp, MaterialTheme.colors.MBlue),
shape = RoundedCornerShape(6.dp) shape = RoundedCornerShape(6.dp)
) { ) {
Text(text = "Reset") Text(text = stringResource(id = R.string.main_key_reset))
} }
Button( Button(
onClick = { onClick = {
@ -125,7 +155,7 @@ fun KeyItem(key: PushKey, requestHolder: RequestHolder) {
), ),
shape = RoundedCornerShape(6.dp) shape = RoundedCornerShape(6.dp)
) { ) {
Text(text = "Copy") Text(text = stringResource(id = R.string.main_key_copy))
} }
} }
} }

View File

@ -4,6 +4,8 @@ import androidx.compose.material.AlertDialog
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.pushdeer.os.R
import com.pushdeer.os.holder.RequestHolder import com.pushdeer.os.holder.RequestHolder
@Composable @Composable
@ -16,7 +18,7 @@ fun MyAlertDialog(alertRequest: RequestHolder.AlertRequest) {
alertRequest.onOKAction.invoke() alertRequest.onOKAction.invoke()
alertRequest.show.value = false alertRequest.show.value = false
}) { }) {
Text(text = "Ok") Text(text = stringResource(id = R.string.global_alert_ok))
} }
}, },
@ -25,7 +27,7 @@ fun MyAlertDialog(alertRequest: RequestHolder.AlertRequest) {
alertRequest.onCancelAction.invoke() alertRequest.onCancelAction.invoke()
alertRequest.show.value = false alertRequest.show.value = false
}) { }) {
Text(text = "Cancel") Text(text = stringResource(id = R.string.global_alert_cancel))
} }
}, },

View File

@ -2,27 +2,19 @@ package com.pushdeer.os.ui.compose.page
import android.util.Log import android.util.Log
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView import androidx.compose.ui.viewinterop.AndroidView
import com.pushdeer.os.R import com.pushdeer.os.R
import com.pushdeer.os.holder.RequestHolder import com.pushdeer.os.holder.RequestHolder
import com.pushdeer.os.ui.theme.MainBlue
import com.pushdeer.os.ui.theme.MainGreen
import com.willowtreeapps.signinwithapplebutton.SignInWithAppleConfiguration import com.willowtreeapps.signinwithapplebutton.SignInWithAppleConfiguration
import com.willowtreeapps.signinwithapplebutton.SignInWithAppleResult import com.willowtreeapps.signinwithapplebutton.SignInWithAppleResult
import com.willowtreeapps.signinwithapplebutton.view.SignInWithAppleButton import com.willowtreeapps.signinwithapplebutton.view.SignInWithAppleButton
@ -31,12 +23,7 @@ import kotlinx.coroutines.launch
@ExperimentalMaterialApi @ExperimentalMaterialApi
@Composable @Composable
fun LoginPage(requestHolder: RequestHolder) { fun LoginPage(requestHolder: RequestHolder) {
Box(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
val configuration = SignInWithAppleConfiguration.Builder() val configuration = SignInWithAppleConfiguration.Builder()
.clientId("com.pushdeer.site") .clientId("com.pushdeer.site")
@ -48,9 +35,10 @@ fun LoginPage(requestHolder: RequestHolder) {
Image( Image(
painter = painterResource(R.drawable.logo_com_x2), painter = painterResource(R.drawable.logo_com_x2),
contentDescription = "big push deer logo", contentDescription = "big push deer logo",
modifier = Modifier.clickable { modifier = Modifier
requestHolder.globalNavController.navigate("logdog") .clickable { requestHolder.globalNavController.navigate("logdog") }
} .align(Alignment.TopCenter)
.padding(top = 50.dp)
) )
AndroidView( AndroidView(
factory = { factory = {
@ -87,54 +75,8 @@ fun LoginPage(requestHolder: RequestHolder) {
} }
}, },
modifier = Modifier modifier = Modifier
.padding(bottom = 16.dp) .align(alignment = Alignment.BottomCenter)
.border( .padding(bottom = 100.dp)
width = 1.dp,
color = MainBlue,
shape = RoundedCornerShape(4.dp)
)
)
Card(
onClick = {
},
shape = RoundedCornerShape(4.dp),
modifier = Modifier
.padding(bottom = 16.dp)
.border(
width = 1.dp,
color = MainBlue,
shape = RoundedCornerShape(4.dp)
)
) {
Text(
text = "Sign in with Apple",
color = MainBlue,
textAlign = TextAlign.Center,
modifier = Modifier
.padding(vertical = 16.dp)
.fillMaxWidth(0.6F)
) )
} }
Card(
onClick = {},
shape = RoundedCornerShape(4.dp),
modifier = Modifier.border(
width = 1.dp,
color = MainGreen,
shape = RoundedCornerShape(4.dp)
)
) {
Text(
text = "Sign in with WeChat",
color = MainGreen,
textAlign = TextAlign.Center,
modifier = Modifier
.padding(vertical = 16.dp)
.fillMaxWidth(0.6F)
)
}
}
} }

View File

@ -1,16 +1,23 @@
package com.pushdeer.os.ui.compose.page.main package com.pushdeer.os.ui.compose.page.main
import android.util.Log
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.pushdeer.os.R import com.pushdeer.os.R
import com.pushdeer.os.data.api.data.request.DeviceInfo import com.pushdeer.os.data.api.data.request.DeviceInfo
import com.pushdeer.os.holder.RequestHolder import com.pushdeer.os.holder.RequestHolder
@ -29,8 +36,8 @@ fun DeviceListPage(requestHolder: RequestHolder) {
onSideIconClick = { onSideIconClick = {
if (requestHolder.settingStore.thisDeviceId == "") { if (requestHolder.settingStore.thisDeviceId == "") {
requestHolder.alert.alert( requestHolder.alert.alert(
title = "Confirm", title = R.string.global_alert_title_confirm,
content = "This Device Registered Failed in PushSDK", content = R.string.alert_device_register_failed_push_sdk,
onOk = {}) onOk = {})
// device regid got failed // device regid got failed
} else { } else {
@ -52,7 +59,7 @@ fun DeviceListPage(requestHolder: RequestHolder) {
verticalArrangement = Arrangement.Center verticalArrangement = Arrangement.Center
) { ) {
Text( Text(
text = "It's Empty, Click '+' to Add New Device" text = stringResource(id = R.string.main_device_list_placeholder)
) )
} }
} else { } else {
@ -61,14 +68,49 @@ fun DeviceListPage(requestHolder: RequestHolder) {
items( items(
items = requestHolder.pushDeerViewModel.deviceList, items = requestHolder.pushDeerViewModel.deviceList,
key = { item: DeviceInfo -> item.id }) { deviceInfo: DeviceInfo -> key = { item: DeviceInfo -> item.id }) { deviceInfo: DeviceInfo ->
var name by remember {
mutableStateOf(deviceInfo.name)
}
SwipeToDismissItem( SwipeToDismissItem(
onAction = { requestHolder.deviceRemove(deviceInfo) } onAction = { requestHolder.deviceRemove(deviceInfo) }
) { ) {
CardItemSingleLineWithIcon( CardItemSingleLineWithIcon(
onClick = {}, onClick = {
resId = R.drawable.ipad_landscape2x, requestHolder.alert.alert(
text = if (deviceInfo.device_id == requestHolder.settingStore.thisDeviceId) "${deviceInfo.name} (this device) " else deviceInfo.name title = R.string.main_device_alert_changedevicename,
content = {
Column {
// Text(text = "type:${deviceInfo.type}")
TextField(
value = name,
onValueChange = { name = it },
shape = RoundedCornerShape(6.dp),
singleLine = true,
maxLines = 1,
label = { Text(text = stringResource(id = R.string.main_device_alert_devicename)) },
colors = TextFieldDefaults.textFieldColors(
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
errorIndicatorColor = Color.Transparent,
) )
)
}
},
onOk = {
deviceInfo.name = name
requestHolder.deviceRename(deviceInfo)
}
)
},
resId = R.drawable.ipad_landscape2x,
text = if (deviceInfo.device_id == requestHolder.settingStore.thisDeviceId) "${deviceInfo.name} (${
stringResource(
id = R.string.main_device_this_device
)
}) " else deviceInfo.name
)
Log.d("WH_", "DeviceListPage: $deviceInfo")
} }
} }
item { item {

View File

@ -11,6 +11,8 @@ import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.pushdeer.os.R
import com.pushdeer.os.data.api.data.response.PushKey import com.pushdeer.os.data.api.data.response.PushKey
import com.pushdeer.os.holder.RequestHolder import com.pushdeer.os.holder.RequestHolder
import com.pushdeer.os.ui.compose.componment.KeyItem import com.pushdeer.os.ui.compose.componment.KeyItem
@ -32,7 +34,7 @@ fun KeyListPage(requestHolder: RequestHolder) {
verticalArrangement = Arrangement.Center verticalArrangement = Arrangement.Center
) { ) {
Text( Text(
text = "It's Empty, Click '+' to Add New Key" text = stringResource(id = R.string.main_key_list_placeholder)
) )
} }
}else{ }else{

View File

@ -14,7 +14,9 @@ import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.pushdeer.os.R
import com.pushdeer.os.data.database.entity.MessageEntity import com.pushdeer.os.data.database.entity.MessageEntity
import com.pushdeer.os.holder.RequestHolder import com.pushdeer.os.holder.RequestHolder
import com.pushdeer.os.ui.compose.componment.* import com.pushdeer.os.ui.compose.componment.*
@ -78,7 +80,7 @@ fun MessageListPage(requestHolder: RequestHolder) {
contentColor = Color.White contentColor = Color.White
), ),
) { ) {
Text(text = "Send") Text(text = stringResource(id = R.string.main_message_send))
} }
} }
} }

View File

@ -1,13 +1,12 @@
package com.pushdeer.os.ui.compose.page.main package com.pushdeer.os.ui.compose.page.main
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.pushdeer.os.R
import com.pushdeer.os.holder.RequestHolder import com.pushdeer.os.holder.RequestHolder
import com.pushdeer.os.ui.compose.componment.SettingItem import com.pushdeer.os.ui.compose.componment.SettingItem
import com.pushdeer.os.ui.navigation.Page import com.pushdeer.os.ui.navigation.Page
@ -24,8 +23,8 @@ fun SettingPage(requestHolder: RequestHolder) {
) { ) {
item { item {
SettingItem( SettingItem(
text = "Hi ${requestHolder.pushDeerViewModel.userInfo.name} !", text = "${stringResource(id = R.string.main_setting_user_hi)} ${requestHolder.pushDeerViewModel.userInfo.name} !",
buttonString = "Logout" buttonString = stringResource(id = R.string.main_setting_user_logout)
) { ) {
requestHolder.settingStore.userToken = "" requestHolder.settingStore.userToken = ""
// logout 操作: // logout 操作:
@ -33,26 +32,26 @@ fun SettingPage(requestHolder: RequestHolder) {
// 删除保存的 token // 删除保存的 token
} }
} }
item { // item {
SettingItem( // SettingItem(
text = "Customize Server", // text = "Customize Server",
buttonString = "Scan QR" // buttonString = "Scan QR"
) { // ) {
requestHolder.startQrScanActivity() // requestHolder.startQrScanActivity()
} // }
} // }
item { // item {
SettingItem( // SettingItem(
text = "Do you like PushDeer ?", // text = "Do you like PushDeer ?",
buttonString = "Like" // buttonString = "Like"
) { // ) {
} // }
} // }
item { item {
SettingItem( SettingItem(
text = "LogDog", text = stringResource(id = R.string.main_setting_logdog),
buttonString = "Open" buttonString = stringResource(id = R.string.main_setting_logdog_open)
) { ) {
requestHolder.globalNavController.navigate("logdog") requestHolder.globalNavController.navigate("logdog")
} }
@ -61,12 +60,12 @@ fun SettingPage(requestHolder: RequestHolder) {
} }
} }
@Composable //@Composable
fun TogglePreferenceItem(label: String) { //fun TogglePreferenceItem(label: String) {
Row( // Row(
verticalAlignment = Alignment.CenterVertically, // verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxSize() // modifier = Modifier.fillMaxSize()
) { // ) {
Text(text = label) // Text(text = label)
} // }
} //}

View File

@ -109,11 +109,12 @@ class PushDeerViewModel(
pushDeerService.deviceList(token).let { pushDeerService.deviceList(token).let {
it.content?.let { it.content?.let {
deviceList.clear() deviceList.clear()
deviceList.addAll(it.devices) deviceList.addAll(it.devices.reversed())
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "deviceList: ${e.localizedMessage}") Log.d(TAG, "deviceList: ${e.localizedMessage}")
logDogRepository.loge("deviceList", "", e.toString())
} }
} }
} }
@ -131,6 +132,19 @@ class PushDeerViewModel(
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "deviceRemove: ${e.localizedMessage}") Log.d(TAG, "deviceRemove: ${e.localizedMessage}")
logDogRepository.loge("deviceRemove", "", e.toString())
}
}
}
suspend fun deviceRename(deviceInfo: DeviceInfo,onReturn: () -> Unit={}){
withContext(Dispatchers.IO){
try {
pushDeerService.deviceRename(token,deviceInfo.id,deviceInfo.name)
onReturn()
}catch (e:Exception){
Log.d(TAG, "deviceRename: ${e.localizedMessage}")
logDogRepository.loge("deviceRename", "", e.toString())
} }
} }
} }
@ -146,6 +160,7 @@ class PushDeerViewModel(
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "keyGen: ${e.localizedMessage}") Log.d(TAG, "keyGen: ${e.localizedMessage}")
logDogRepository.loge("keyGen", "", e.toString())
} }
} }
} }
@ -163,6 +178,23 @@ class PushDeerViewModel(
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "keyRegen: ${e.localizedMessage}") Log.d(TAG, "keyRegen: ${e.localizedMessage}")
logDogRepository.loge("keyRegen", "", e.toString())
}
}
}
suspend fun keyRename(key: PushKey,onReturn: () -> Unit={}){
withContext(Dispatchers.IO){
try {
pushDeerService.keyRename(
token,
key.id,
key.name
)
onReturn()
}catch (e: Exception) {
Log.d(TAG, "keyRename: ${e.localizedMessage}")
logDogRepository.loge("keyRename", "", e.toString())
} }
} }
} }
@ -178,6 +210,7 @@ class PushDeerViewModel(
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "keyList: ${e.localizedMessage}") Log.d(TAG, "keyList: ${e.localizedMessage}")
logDogRepository.loge("keyList", "", e.toString())
} }
} }
} }
@ -190,6 +223,7 @@ class PushDeerViewModel(
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "keyRemove: ${e.localizedMessage}") Log.d(TAG, "keyRemove: ${e.localizedMessage}")
logDogRepository.loge("keyRemove", "", e.toString())
} }
} }

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">PushDeer</string>
</resources>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">PushDeer</string>
<string name="main_device">设备</string>
<string name="main_key">密钥</string>
<string name="main_message">消息</string>
<string name="main_setting">设置</string>
<string name="global_logdog">LogDog-罗格狗</string>
<string name="main_key_reset">重置</string>
<string name="main_key_copy">复制</string>
<string name="main_setting_logdog_open">打开</string>
<string name="main_setting_user_hi">你好</string>
<string name="main_setting_user_logout">注销</string>
<string name="main_setting_logdog">LogDog-罗格狗</string>
<string name="main_device_list_placeholder">点击\"+\"创建新设备</string>
<string name="main_device_this_device">本设备</string>
<string name="global_alert_title_confirm">确认</string>
<string name="alert_device_register_failed_push_sdk">本设备在厂商推送服务注册失败</string>
<string name="main_message_send">发送</string>
<string name="global_alert_title_alert">警告</string>
<string name="main_message_send_alert">发送消息前请创建新的密钥</string>
<string name="global_alert_ok">确认</string>
<string name="global_alert_cancel">取消</string>
<string name="main_key_list_placeholder">点击\"+\"创建新密钥</string>
<string name="main_device_alert_changedevicename">修改设备名称</string>
<string name="main_device_alert_devicename">设备名称</string>
<string name="main_key_alert_changekeyname">修改密钥名称</string>
<string name="main_key_alert_keyname">密钥名称</string>
</resources>

View File

@ -5,4 +5,24 @@
<string name="main_message">Message</string> <string name="main_message">Message</string>
<string name="main_setting">Setting</string> <string name="main_setting">Setting</string>
<string name="global_logdog">LogDog</string> <string name="global_logdog">LogDog</string>
<string name="main_key_reset">Reset</string>
<string name="main_key_copy">Copy</string>
<string name="main_setting_logdog_open">Open</string>
<string name="main_setting_user_hi">Hi</string>
<string name="main_setting_user_logout">Logout</string>
<string name="main_setting_logdog">LogDog</string>
<string name="main_device_list_placeholder">It\'s Empty, Click \'+\' to Add New Device.</string>
<string name="main_device_this_device">this device</string>
<string name="global_alert_title_confirm">Confirm</string>
<string name="alert_device_register_failed_push_sdk">This Device Registered Failed in PushSDK</string>
<string name="main_message_send">Send</string>
<string name="global_alert_title_alert">Alert</string>
<string name="main_message_send_alert">You Should Add One PushKey</string>
<string name="global_alert_ok">OK</string>
<string name="global_alert_cancel">Cancel</string>
<string name="main_key_list_placeholder">It\'s Empty, Click \'+\' to Add New Key.</string>
<string name="main_device_alert_changedevicename">Change Device Name</string>
<string name="main_device_alert_devicename">name</string>
<string name="main_key_alert_changekeyname">Change Key Name</string>
<string name="main_key_alert_keyname">name</string>
</resources> </resources>