mirror of
https://github.com/easychen/pushdeer.git
synced 2025-01-07 21:45:54 +08:00
android add inner webview, create folder for self-hosted-push-server
This commit is contained in:
parent
94d15420f7
commit
905ff7c8fe
9
.gitignore
vendored
9
.gitignore
vendored
@ -1 +1,8 @@
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
||||
android/app_self*
|
||||
android/pushdeerclient
|
||||
android/app/java/com/pushdeer/os/values/App*
|
||||
android/app/build
|
||||
android/app/debug
|
||||
android/app/release
|
||||
|
@ -11,6 +11,7 @@
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/app_self_hosted" />
|
||||
<option value="$PROJECT_DIR$/common" />
|
||||
<option value="$PROJECT_DIR$/compose" />
|
||||
<option value="$PROJECT_DIR$/pushdeerclient" />
|
||||
|
@ -15,10 +15,21 @@
|
||||
<entry key="../../../../layout/compose-model-1641694023752.xml" value="0.1" />
|
||||
<entry key="../../../../layout/compose-model-1642733328920.xml" value="2.0" />
|
||||
<entry key="../../../../layout/compose-model-1642826587452.xml" value="2.0" />
|
||||
<entry key="../../../../layout/compose-model-1643039843013.xml" value="2.0" />
|
||||
<entry key="../../../../layout/compose-model-1643123274044.xml" value="0.2916666666666667" />
|
||||
<entry key="../../../../layout/compose-model-1643123509726.xml" value="4.0" />
|
||||
<entry key="../../../../layout/compose-model-1643595536124.xml" value="0.1" />
|
||||
<entry key="app/src/main/res/drawable/fragment_qr_scan.xml" value="0.12314814814814815" />
|
||||
<entry key="app/src/main/res/drawable/ic_apple_logo_svgrepo_com.xml" value="0.23802083333333332" />
|
||||
<entry key="app/src/main/res/drawable/ic_deer_head_with_mail.xml" value="0.23802083333333332" />
|
||||
<entry key="app/src/main/res/drawable/ic_launcher_foreground.xml" value="0.23802083333333332" />
|
||||
<entry key="app/src/main/res/drawable/ic_logo_svg_1.xml" value="0.23802083333333332" />
|
||||
<entry key="app/src/main/res/drawable/ic_markdown.xml" value="0.12962962962962962" />
|
||||
<entry key="app/src/main/res/drawable/ic_weixin_logo_svgrepo_com.xml" value="0.23802083333333332" />
|
||||
<entry key="app/src/main/res/layout/activity_qr_scan.xml" value="0.1" />
|
||||
<entry key="app/src/main/res/layout/activity_webview.xml" value="0.3691123188405797" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.1" />
|
||||
<entry key="app_self_hosted/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.1925925925925926" />
|
||||
<entry key="common/src/main/res/layout/activity_qr_scan.xml" value="0.1" />
|
||||
<entry key="pushdeerclient/src/main/res/drawable-v24/ic_markdown.xml" value="0.11944444444444445" />
|
||||
</map>
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
* MiPush(状态:已调通、已接入)
|
||||
* miui √
|
||||
* Mokee √
|
||||
* Mokee-81.0 PixelExperience-12 √
|
||||
* WaWei √
|
||||
* 坚果pro3-8.0.1 √ 坚果pro2s-7.2.0.2 x(暂无法成功注册)
|
||||
* 坚果pro3-8.0.1 √ 坚果pro2s-7.2.0.2 x(暂无法稳定成功注册)
|
||||
* 部分原生、类原生 可成功注册,无法收到推送,可能和地区识别有关,待解决
|
||||
|
||||
### TODO
|
||||
@ -117,8 +117,22 @@
|
||||
* 适配 PushDeer 的专用推送通道
|
||||
* 增加修改设备/密钥等名称时"清空文本"按钮
|
||||
* 部分英化汉化
|
||||
* 设置界面的Like
|
||||
|
||||
* 2022-01-23
|
||||
* 修复切换界面超量请求的bug
|
||||
|
||||
* 2022-01-24
|
||||
* 重写列表滑动删除逻辑
|
||||
|
||||
* 2022-01-25、26
|
||||
* 适配微信登陆
|
||||
* 适配 PushDeer 的微信登陆及账号合并路由
|
||||
* 增加只有一个确认按钮的 AlertDialog,替换无意义的双按钮弹框
|
||||
* 增加消息列表中测试推送框的收起按钮的旋转动画
|
||||
* 修改设置界面登陆账号绑定指示器UI
|
||||
|
||||
### 感谢
|
||||
|
||||
https://github.com/taoweiji/MixPush
|
||||
https://github.com/taoweiji/MixPush
|
||||
|
||||
|
@ -6,14 +6,23 @@ plugins {
|
||||
|
||||
android {
|
||||
|
||||
signingConfigs {
|
||||
debug {
|
||||
storeFile file('/Users/wolf/Documents/com.wh.pushdeer')
|
||||
storePassword 'wh.pushdeer'
|
||||
keyAlias 'whpushdeer'
|
||||
keyPassword 'wh.pushdeer'
|
||||
}
|
||||
}
|
||||
|
||||
compileSdk 31
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.pushdeer.os"
|
||||
minSdk 22
|
||||
targetSdk 31
|
||||
versionCode 8
|
||||
versionName "1.0-dev-8"
|
||||
versionCode 15
|
||||
versionName "1.0-alpha-5"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
@ -105,9 +114,8 @@ dependencies {
|
||||
implementation "io.noties.markwon:ext-tables:$markwon_version"
|
||||
implementation "io.noties.markwon:ext-tasklist:$markwon_version"
|
||||
implementation "io.noties.markwon:image-coil:$markwon_version"
|
||||
implementation "io.noties.markwon:linkify:$markwon_version"
|
||||
// implementation "io.noties.markwon:linkify:$markwon_version"
|
||||
implementation "io.noties.markwon:html:$markwon_version"
|
||||
|
||||
implementation "io.coil-kt:coil:1.4.0"
|
||||
|
||||
implementation 'com.github.vishalkumarsinghvi:sign-in-with-apple-button-android:0.6'
|
||||
|
Binary file not shown.
Binary file not shown.
@ -11,8 +11,8 @@
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 5,
|
||||
"versionName": "1.0-dev-5",
|
||||
"versionCode": 15,
|
||||
"versionName": "1.0-alpha-5",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
|
@ -123,6 +123,8 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity android:name=".WebViewActivity"/>
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
|
@ -1,20 +1,15 @@
|
||||
package com.pushdeer.os
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.Application
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import com.pushdeer.os.data.api.PushDeerApi
|
||||
import com.pushdeer.os.data.database.AppDatabase
|
||||
import com.pushdeer.os.factory.ViewModelFactory
|
||||
import com.pushdeer.os.keeper.RepositoryKeeper
|
||||
import com.pushdeer.os.keeper.StoreKeeper
|
||||
import com.pushdeer.os.util.MiPushUtils
|
||||
import com.pushdeer.os.values.AppKeys
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory
|
||||
import com.xiaomi.channel.commonutils.logger.LoggerInterface
|
||||
import com.xiaomi.mipush.sdk.Logger
|
||||
import com.xiaomi.mipush.sdk.MiPushClient
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||
@ -23,7 +18,7 @@ class App : Application() {
|
||||
|
||||
val storeKeeper by lazy { StoreKeeper(this) }
|
||||
val database by lazy { AppDatabase.getDatabase(this) }
|
||||
val repositoryKeeper by lazy { RepositoryKeeper(database,storeKeeper.settingStore) }
|
||||
val repositoryKeeper by lazy { RepositoryKeeper(database, storeKeeper.settingStore) }
|
||||
private val pushDeerService: PushDeerApi by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl(PushDeerApi.baseUrl)
|
||||
@ -40,59 +35,14 @@ class App : Application() {
|
||||
)
|
||||
}
|
||||
|
||||
val iwxapi:IWXAPI by lazy { WXAPIFactory.createWXAPI(this, AppKeys.WX_Id, true) }
|
||||
val iwxapi: IWXAPI by lazy { WXAPIFactory.createWXAPI(this, AppKeys.WX_Id, true) }
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
//初始化push推送服务
|
||||
if (shouldInit()) {
|
||||
MiPushClient.registerPush(this, AppKeys.MiPush_Id, AppKeys.MiPush_Key)
|
||||
}
|
||||
//打开Log
|
||||
Logger.setLogger(this, object : LoggerInterface {
|
||||
override fun setTag(tag: String) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
override fun log(content: String, t: Throwable) {
|
||||
Log.d(TAG, content, t)
|
||||
Thread{
|
||||
repositoryKeeper.logDogRepository.log(
|
||||
entity = "mipush",
|
||||
level = "e",
|
||||
event = t.message.toString(),
|
||||
log = content
|
||||
)
|
||||
}.start()
|
||||
}
|
||||
|
||||
override fun log(content: String) {
|
||||
Log.d(TAG, content)
|
||||
// Thread{
|
||||
// repositoryKeeper.logDogRepository.log(
|
||||
// entity = "mipush",
|
||||
// level = "d",
|
||||
// event = "",
|
||||
// log = content
|
||||
// )
|
||||
// }.start()
|
||||
|
||||
}
|
||||
})
|
||||
MiPushUtils.autoInit(this,repositoryKeeper)
|
||||
}
|
||||
|
||||
private fun shouldInit(): Boolean {
|
||||
val am = getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||||
val processInfoList = am.runningAppProcesses
|
||||
val mainProcessName = applicationInfo.processName
|
||||
val myPid = Process.myPid()
|
||||
for (info in processInfoList) {
|
||||
if (info.pid == myPid && mainProcessName == info.processName) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "TAG"
|
||||
|
@ -2,8 +2,8 @@ package com.pushdeer.os
|
||||
|
||||
import android.content.*
|
||||
import android.os.Bundle
|
||||
import android.text.util.Linkify
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.viewModels
|
||||
@ -42,9 +42,8 @@ import com.pushdeer.os.viewmodel.PushDeerViewModel
|
||||
import com.pushdeer.os.viewmodel.UiViewModel
|
||||
import com.pushdeer.os.wxapi.WXEntryActivity
|
||||
import com.tencent.mm.opensdk.constants.ConstantsAPI
|
||||
import io.noties.markwon.Markwon
|
||||
import io.noties.markwon.*
|
||||
import io.noties.markwon.image.coil.CoilImagesPlugin
|
||||
import io.noties.markwon.linkify.LinkifyPlugin
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
@ -72,36 +71,48 @@ class MainActivity : AppCompatActivity(), RequestHolder {
|
||||
.build()
|
||||
}
|
||||
override val alert: RequestHolder.AlertRequest by lazy {
|
||||
object : RequestHolder.AlertRequest(resources) {}
|
||||
RequestHolder.AlertRequest(resources)
|
||||
}
|
||||
override val key: RequestHolder.KeyRequest by lazy {
|
||||
object : RequestHolder.KeyRequest(this) {}
|
||||
RequestHolder.KeyRequest(this)
|
||||
}
|
||||
override val device: RequestHolder.DeviceRequest by lazy {
|
||||
object : RequestHolder.DeviceRequest(this) {}
|
||||
RequestHolder.DeviceRequest(this)
|
||||
}
|
||||
override val message: RequestHolder.MessageRequest by lazy {
|
||||
object : RequestHolder.MessageRequest(this) {}
|
||||
RequestHolder.MessageRequest(this)
|
||||
}
|
||||
override val clip: RequestHolder.ClipRequest by lazy {
|
||||
object : RequestHolder.ClipRequest(
|
||||
RequestHolder.ClipRequest(
|
||||
getSystemService(
|
||||
Context.CLIPBOARD_SERVICE
|
||||
) as ClipboardManager
|
||||
) {}
|
||||
)
|
||||
}
|
||||
override val weChatLogin: RequestHolder.WeChatLoginRequest by lazy {
|
||||
object : RequestHolder.WeChatLoginRequest((application as App).iwxapi) {}
|
||||
RequestHolder.WeChatLoginRequest((application as App).iwxapi)
|
||||
}
|
||||
|
||||
override val appleLogin: RequestHolder.AppleLoginRequest by lazy {
|
||||
object : RequestHolder.AppleLoginRequest(supportFragmentManager, this) {}
|
||||
RequestHolder.AppleLoginRequest(supportFragmentManager, this)
|
||||
}
|
||||
|
||||
override val markdown: Markwon by lazy {
|
||||
Markwon.builder(this)
|
||||
.usePlugin(CoilImagesPlugin.create(this, coilImageLoader))
|
||||
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
|
||||
.usePlugin(object : AbstractMarkwonPlugin() {
|
||||
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
||||
builder.linkResolver(object : LinkResolverDef() {
|
||||
override fun resolve(view: View, link: String) {
|
||||
if (settingStore.useInnerWebView){
|
||||
WebViewActivity.load(this@MainActivity, link)
|
||||
}else{
|
||||
super.resolve(view, link)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
@ -111,7 +122,7 @@ class MainActivity : AppCompatActivity(), RequestHolder {
|
||||
override lateinit var qrScanActivityOpener: ActivityResultLauncher<Intent>
|
||||
override lateinit var requestPermissionOpener: ActivityResultLauncher<Array<String>>
|
||||
|
||||
val wxRegReceiver: BroadcastReceiver by lazy {
|
||||
private val wxRegReceiver: BroadcastReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
intent?.let {
|
||||
@ -166,7 +177,8 @@ class MainActivity : AppCompatActivity(), RequestHolder {
|
||||
IntentFilter().apply {
|
||||
addAction(ConstantsAPI.ACTION_REFRESH_WXAPP)
|
||||
addAction(WXEntryActivity.ACTION_RETURN_CODE)
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
NotificationUtil.setupChannel(this)
|
||||
@ -185,7 +197,7 @@ class MainActivity : AppCompatActivity(), RequestHolder {
|
||||
Color.Transparent,
|
||||
useDarkIcons
|
||||
)
|
||||
else -> systemUiController.setSystemBarsColor(Color.Transparent, !useDarkIcons)
|
||||
else -> systemUiController.setSystemBarsColor(Color.Transparent, useDarkIcons)
|
||||
}
|
||||
WindowCompat.setDecorFitsSystemWindows(window, true)
|
||||
miPushRepository.regId.observe(this) {
|
||||
|
96
android/app/src/main/java/com/pushdeer/os/WebViewActivity.kt
Normal file
96
android/app/src/main/java/com/pushdeer/os/WebViewActivity.kt
Normal file
@ -0,0 +1,96 @@
|
||||
package com.pushdeer.os
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.webkit.WebChromeClient
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
|
||||
class WebViewActivity : Activity() {
|
||||
|
||||
companion object {
|
||||
const val URL_KEY = "url-to-open"
|
||||
|
||||
fun load(context: Context, url: String) {
|
||||
context.startActivity(Intent(context, WebViewActivity::class.java).apply {
|
||||
putExtra(URL_KEY, url)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_webview)
|
||||
|
||||
val ibClose = findViewById<ImageButton>(R.id.ib_close)
|
||||
val ibBack = findViewById<ImageButton>(R.id.ib_back)
|
||||
|
||||
val webView = findViewById<WebView>(R.id.webview)
|
||||
|
||||
val progressBar = findViewById<ProgressBar>(R.id.progressBar)
|
||||
|
||||
val tvTitle = findViewById<TextView>(R.id.tv_title)
|
||||
|
||||
webView.settings.apply {
|
||||
this.javaScriptEnabled = true
|
||||
// this.
|
||||
}
|
||||
|
||||
ibClose.setOnClickListener {
|
||||
this.finish()
|
||||
}
|
||||
|
||||
ibBack.setOnClickListener {
|
||||
if (webView.canGoBack()) {
|
||||
webView.goBack()
|
||||
} else {
|
||||
this.finish()
|
||||
}
|
||||
}
|
||||
|
||||
webView.webViewClient = object :WebViewClient(){
|
||||
override fun shouldOverrideUrlLoading(
|
||||
view: WebView?,
|
||||
request: WebResourceRequest?
|
||||
): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
webView.webChromeClient = object : WebChromeClient() {
|
||||
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
||||
super.onProgressChanged(view, newProgress)
|
||||
progressBar.progress = newProgress
|
||||
if (newProgress == 100){
|
||||
progressBar.visibility = View.GONE
|
||||
}else{
|
||||
progressBar.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReceivedTitle(view: WebView?, title: String?) {
|
||||
super.onReceivedTitle(view, title)
|
||||
title?.let {
|
||||
tvTitle.text = it
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
intent.getStringExtra(URL_KEY)?.let {
|
||||
webView.loadUrl(it)
|
||||
tvTitle.text = it
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
//package com.pushdeer.os.activity
|
||||
//
|
||||
//
|
||||
//import android.content.Context
|
||||
//import android.content.Intent
|
||||
//import android.os.Bundle
|
||||
//import android.util.Log
|
||||
//import androidx.appcompat.app.AppCompatActivity
|
||||
//import cn.bingoogolapple.qrcode.core.QRCodeView
|
||||
//import com.pushdeer.os.R
|
||||
//
|
||||
//
|
||||
//class QrScanActivity : AppCompatActivity(), QRCodeView.Delegate {
|
||||
//
|
||||
// private val TAG = "WH_" + javaClass.simpleName
|
||||
// private lateinit var qrCode: QRCodeView
|
||||
//
|
||||
// companion object {
|
||||
// val RequestCode_get_scan_result = 436
|
||||
// val DataKey = "qr_scan_result"
|
||||
//
|
||||
// fun forScanResultIntent(context: Context): Intent {
|
||||
// return Intent(context, QrScanActivity::class.java).apply {
|
||||
// putExtra(DataKey, 1)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// super.onCreate(savedInstanceState)
|
||||
// setContentView(R.layout.activity_qr_scan)
|
||||
// qrCode = findViewById(R.id.qrcode1)
|
||||
// qrCode.setDelegate(this)
|
||||
// }
|
||||
//
|
||||
// override fun onStart() {
|
||||
// super.onStart()
|
||||
// Log.d(TAG, "onStart")
|
||||
// qrCode.startSpotAndShowRect()
|
||||
// }
|
||||
//
|
||||
// override fun onStop() {
|
||||
// Log.d(TAG, "onStop")
|
||||
// qrCode.stopCamera()
|
||||
// super.onStop()
|
||||
// }
|
||||
//
|
||||
// override fun onDestroy() {
|
||||
// qrCode.onDestroy()
|
||||
// super.onDestroy()
|
||||
// }
|
||||
//
|
||||
// override fun onScanQRCodeSuccess(result: String?) {
|
||||
// Log.d(TAG, "onScanQRCodeSuccess: $result")
|
||||
// qrCode.stopCamera()
|
||||
// val intent = Intent()
|
||||
// intent.putExtra(DataKey, result)
|
||||
// setResult(RequestCode_get_scan_result, intent)
|
||||
// finish()
|
||||
// }
|
||||
//
|
||||
// override fun onScanQRCodeOpenCameraError() {
|
||||
// Log.e(TAG, "onScanQRCodeOpenCameraError")
|
||||
// qrCode.startSpotAndShowRect()
|
||||
// }
|
||||
//}
|
@ -76,7 +76,7 @@ interface RequestHolder {
|
||||
})
|
||||
}
|
||||
|
||||
abstract class AppleLoginRequest(
|
||||
class AppleLoginRequest(
|
||||
private val fragmentManager: FragmentManager,
|
||||
private val requestHolder: RequestHolder
|
||||
) {
|
||||
@ -141,7 +141,7 @@ interface RequestHolder {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class WeChatLoginRequest(val iwxapi: IWXAPI) {
|
||||
class WeChatLoginRequest(val iwxapi: IWXAPI) {
|
||||
val login: () -> Unit = {
|
||||
val req = SendAuth.Req()
|
||||
req.scope = "snsapi_userinfo"
|
||||
@ -150,7 +150,7 @@ interface RequestHolder {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ClipRequest(private val clipboardManager: ClipboardManager) {
|
||||
class ClipRequest(private val clipboardManager: ClipboardManager) {
|
||||
fun copyMessagePlainText(str: String) {
|
||||
clipboardManager.setPrimaryClip(ClipData.newPlainText("pushdeer-copy-plain-text", str))
|
||||
}
|
||||
@ -160,7 +160,7 @@ interface RequestHolder {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AlertRequest(private val resources: Resources) {
|
||||
class AlertRequest(private val resources: Resources) {
|
||||
val show2BtnDialog: MutableState<Boolean> = mutableStateOf(false)
|
||||
val show1BtnDialog: MutableState<Boolean> = mutableStateOf(false)
|
||||
var title: String = ""
|
||||
@ -253,7 +253,7 @@ interface RequestHolder {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class KeyRequest(private val requestHolder: RequestHolder) {
|
||||
class KeyRequest(private val requestHolder: RequestHolder) {
|
||||
fun gen() {
|
||||
requestHolder.coroutineScope.launch {
|
||||
requestHolder.pushDeerViewModel.keyGen()
|
||||
@ -284,7 +284,7 @@ interface RequestHolder {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DeviceRequest(private val requestHolder: RequestHolder) {
|
||||
class DeviceRequest(private val requestHolder: RequestHolder) {
|
||||
fun deviceReg(deviceInfo: DeviceInfo) {
|
||||
requestHolder.coroutineScope.launch {
|
||||
requestHolder.pushDeerViewModel.deviceReg(deviceInfo)
|
||||
@ -309,7 +309,7 @@ interface RequestHolder {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MessageRequest(private val requestHolder: RequestHolder) {
|
||||
class MessageRequest(private val requestHolder: RequestHolder) {
|
||||
fun messagePush(text: String, desp: String, type: String, pushkey: String) {
|
||||
requestHolder.coroutineScope.launch {
|
||||
requestHolder.pushDeerViewModel.messagePush(text, desp, type, pushkey)
|
||||
|
@ -3,10 +3,10 @@ package com.pushdeer.os.store
|
||||
import android.content.Context
|
||||
import com.wh.common.store.Store
|
||||
|
||||
class SettingStore(context:Context) {
|
||||
val store = Store.create(context,"setting")
|
||||
class SettingStore(context: Context) {
|
||||
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 useRecv by store.boolean("use-recv",false) // 启用接收
|
||||
// var useSend by store.boolean("use-send",false)
|
||||
@ -15,9 +15,15 @@ class SettingStore(context:Context) {
|
||||
// var useSendMissedCall by store.boolean("use-send=missed-call",false)
|
||||
// var useSendSMS by store.boolean("use-send-sms",false)
|
||||
|
||||
var showMessageSender by store.boolean("show-message-sender",true)
|
||||
var thisPushSdk by store.string("this-push-sdk","mi-push")
|
||||
var thisDeviceId by store.string("this-device-id","")
|
||||
var showMessageSender by store.boolean("show-message-sender", true)
|
||||
var thisPushSdk by store.string("this-push-sdk", "mi-push")
|
||||
var thisDeviceId by store.string("this-device-id", "")
|
||||
|
||||
var logLevel by store.string("log-level","i") // i w e - d
|
||||
var logLevel by store.string("log-level", "i") // i w e - d
|
||||
|
||||
var isServerMethodSelected by store.boolean("server-method-selected", false)
|
||||
var isSelfHosted by store.boolean("self-hosted", false)
|
||||
var selfHostedEndpointUrl by store.string("self-hosted-endpoint-url", "http://")
|
||||
|
||||
var useInnerWebView by store.boolean("user-inner-webview",false)
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.pushdeer.os.ui.compose.componment
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.widget.ImageView
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
@ -13,6 +14,7 @@ import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@ -29,7 +31,7 @@ import com.pushdeer.os.values.ConstValues
|
||||
|
||||
@ExperimentalMaterialApi
|
||||
@Composable
|
||||
fun PlainTextMessageItem(message: MessageEntity,requestHolder: RequestHolder) {
|
||||
fun PlainTextMessageItem(message: MessageEntity, requestHolder: RequestHolder) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -62,14 +64,40 @@ fun PlainTextMessageItem(message: MessageEntity,requestHolder: RequestHolder) {
|
||||
}
|
||||
|
||||
CardItemWithContent {
|
||||
Text(
|
||||
text = message.text,
|
||||
overflow = TextOverflow.Visible,
|
||||
lineHeight = 24.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
)
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
|
||||
if (TextUtils.isEmpty(message.desp)) {
|
||||
Text(
|
||||
text = message.text,
|
||||
overflow = TextOverflow.Visible,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
)
|
||||
|
||||
} else {
|
||||
Text(
|
||||
text = message.text,
|
||||
overflow = TextOverflow.Visible,
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 16.dp, top = 16.dp, end = 16.dp, bottom = 4.dp)
|
||||
.alpha(0.8F)
|
||||
)
|
||||
Text(
|
||||
text = message.desp,
|
||||
overflow = TextOverflow.Visible,
|
||||
fontSize = 15.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 16.dp, end = 16.dp, top = 4.dp, bottom = 16.dp)
|
||||
.alpha(0.5F)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,6 +150,230 @@ fun ImageMessageItem(message: MessageEntity, requestHolder: RequestHolder) {
|
||||
@ExperimentalMaterialApi
|
||||
@Composable
|
||||
fun MarkdownMessageItem(message: MessageEntity, requestHolder: RequestHolder) {
|
||||
|
||||
// val a = "![logo](./art/markwon_logo.png)\n" +
|
||||
// "\n" +
|
||||
// "# Markwon\n" +
|
||||
// "\n" +
|
||||
// "[![Build](https://github.com/noties/Markwon/workflows/Build/badge.svg)](https://github.com/noties/Markwon/actions)\n" +
|
||||
// "\n" +
|
||||
// "**Markwon** is a markdown library for Android. It parses markdown\n" +
|
||||
// "following [commonmark-spec] with the help of amazing [commonmark-java]\n" +
|
||||
// "library and renders result as _Android-native_ Spannables. **No HTML**\n" +
|
||||
// "is involved as an intermediate step. <u>**No WebView** is required</u>.\n" +
|
||||
// "It's extremely fast, feature-rich and extensible.\n" +
|
||||
// "\n" +
|
||||
// "It gives ability to display markdown in all TextView widgets\n" +
|
||||
// "(**TextView**, **Button**, **Switch**, **CheckBox**, etc), **Toasts**\n" +
|
||||
// "and all other places that accept **Spanned content**. Library provides\n" +
|
||||
// "reasonable defaults to display style of a markdown content but also \n" +
|
||||
// "gives all the means to tweak the appearance if desired. All markdown\n" +
|
||||
// "features listed in [commonmark-spec] are supported\n" +
|
||||
// "(including support for **inlined/block HTML code**, **markdown tables**,\n" +
|
||||
// "**images** and **syntax highlight**).\n" +
|
||||
// "\n" +
|
||||
// "`Markwon` comes with a [sample application](./app-sample/). It is a\n" +
|
||||
// "collection of library usages that comes with search and source code for\n" +
|
||||
// "each code sample.\n" +
|
||||
// "\n" +
|
||||
// "Since version **4.2.0** **Markwon** comes with an [editor](./markwon-editor/) to _highlight_ markdown input\n" +
|
||||
// "as user types (for example in **EditText**).\n" +
|
||||
// "\n" +
|
||||
// "[commonmark-spec]: https://spec.commonmark.org/0.28/\n" +
|
||||
// "[commonmark-java]: https://github.com/atlassian/commonmark-java/blob/master/README.md\n" +
|
||||
// "\n" +
|
||||
// "## Installation\n" +
|
||||
// "\n" +
|
||||
// "![stable](https://img.shields.io/maven-central/v/io.noties.markwon/core.svg?label=stable)\n" +
|
||||
// "![snapshot](https://img.shields.io/nexus/s/https/oss.sonatype.org/io.noties.markwon/core.svg?label=snapshot)\n" +
|
||||
// "\n" +
|
||||
// "```kotlin\n" +
|
||||
// "implementation \"io.noties.markwon:core:\"\n" +
|
||||
// "```\n" +
|
||||
// "\n" +
|
||||
// "Full list of available artifacts is present in the [install section](https://noties.github.io/Markwon/docs/v4/install.html)\n" +
|
||||
// "of the [documentation] web-site.\n" +
|
||||
// "\n" +
|
||||
// "Please visit [documentation] web-site for further reference.\n" +
|
||||
// "\n" +
|
||||
// "\n" +
|
||||
// "> You can find previous version of Markwon in [2.x.x](https://github.com/noties/Markwon/tree/2.x.x)\n" +
|
||||
// "and [3.x.x](https://github.com/noties/Markwon/tree/3.x.x) branches\n" +
|
||||
// "\n" +
|
||||
// "## Supported markdown features:\n" +
|
||||
// "* Emphasis (`*`, `_`)\n" +
|
||||
// "* Strong emphasis (`**`, `__`)\n" +
|
||||
// "* Strike-through (`~~`)\n" +
|
||||
// "* Headers (`#{1,6}`)\n" +
|
||||
// "* Links (`[]()` && `[][]`)\n" +
|
||||
// "* Images\n" +
|
||||
// "* Thematic break (`---`, `***`, `___`)\n" +
|
||||
// "* Quotes & nested quotes (`>{1,}`)\n" +
|
||||
// "* Ordered & non-ordered lists & nested ones\n" +
|
||||
// "* Inline code\n" +
|
||||
// "* Code blocks\n" +
|
||||
// "* Tables (*with limitations*)\n" +
|
||||
// "* Syntax highlight\n" +
|
||||
// "* LaTeX formulas\n" +
|
||||
// "* HTML\n" +
|
||||
// " * Emphasis (`<i>`, `<em>`, `<cite>`, `<dfn>`)\n" +
|
||||
// " * Strong emphasis (`<b>`, `<strong>`)\n" +
|
||||
// " * SuperScript (`<sup>`)\n" +
|
||||
// " * SubScript (`<sub>`)\n" +
|
||||
// " * Underline (`<u>`, `ins`)\n" +
|
||||
// " * Strike-through (`<s>`, `<strike>`, `<del>`)\n" +
|
||||
// " * Link (`a`)\n" +
|
||||
// " * Lists (`ul`, `ol`)\n" +
|
||||
// " * Images (`img` will require configured image loader)\n" +
|
||||
// " * Blockquote (`blockquote`)\n" +
|
||||
// " * Heading (`h1`, `h2`, `h3`, `h4`, `h5`, `h6`)\n" +
|
||||
// " * there is support to render any HTML tag\n" +
|
||||
// "* Task lists:\n" +
|
||||
// "- [ ] Not _done_\n" +
|
||||
// " - [X] **Done** with `X`\n" +
|
||||
// " - [x] ~~and~~ **or** small `x`\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "## Screenshots\n" +
|
||||
// "\n" +
|
||||
// "Taken with default configuration (except for image loading) in [sample app](./app-sample/):\n" +
|
||||
// "\n" +
|
||||
// "<a href=\"./art/mw_light_01.png\"><img src=\"./art/mw_light_01.png\" width=\"30%\" /></a>\n" +
|
||||
// "<a href=\"./art/mw_light_02.png\"><img src=\"./art/mw_light_02.png\" width=\"30%\" /></a>\n" +
|
||||
// "<a href=\"./art/mw_light_03.png\"><img src=\"./art/mw_light_03.png\" width=\"30%\" /></a>\n" +
|
||||
// "<a href=\"./art/mw_dark_01.png\"><img src=\"./art/mw_dark_01.png\" width=\"30%\" /></a>\n" +
|
||||
// "\n" +
|
||||
// "By default configuration uses TextView textColor for styling, so changing textColor changes style\n" +
|
||||
// "\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "## Documentation\n" +
|
||||
// "\n" +
|
||||
// "Please visit [documentation] web-site for reference\n" +
|
||||
// "\n" +
|
||||
// "[documentation]: https://noties.github.io/Markwon\n" +
|
||||
// "\n" +
|
||||
// "\n" +
|
||||
// "## Consulting\n" +
|
||||
// "Paid consulting is available. Please reach me out at [markwon+consulting[at]noties.io](mailto:markwon+consulting@noties.io)\n" +
|
||||
// "to discuss your idea or a project\n" +
|
||||
// "\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "# Demo\n" +
|
||||
// "Based on [this cheatsheet][cheatsheet]\n" +
|
||||
// "\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "## Headers\n" +
|
||||
// "---\n" +
|
||||
// "# Header 1\n" +
|
||||
// "## Header 2\n" +
|
||||
// "### Header 3\n" +
|
||||
// "#### Header 4\n" +
|
||||
// "##### Header 5\n" +
|
||||
// "###### Header 6\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "## Emphasis\n" +
|
||||
// "\n" +
|
||||
// "Emphasis, aka italics, with *asterisks* or _underscores_.\n" +
|
||||
// "\n" +
|
||||
// "Strong emphasis, aka bold, with **asterisks** or __underscores__.\n" +
|
||||
// "\n" +
|
||||
// "Combined emphasis with **asterisks and _underscores_**.\n" +
|
||||
// "\n" +
|
||||
// "Strikethrough uses two tildes. ~~Scratch this.~~\n" +
|
||||
// "\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "## Lists\n" +
|
||||
// "1. First ordered list item\n" +
|
||||
// "2. Another item\n" +
|
||||
// " * Unordered sub-list.\n" +
|
||||
// "1. Actual numbers don't matter, just that it's a number\n" +
|
||||
// " 1. Ordered sub-list\n" +
|
||||
// "4. And another item.\n" +
|
||||
// "\n" +
|
||||
// " You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).\n" +
|
||||
// "\n" +
|
||||
// " To have a line break without a paragraph, you will need to use two trailing spaces.\n" +
|
||||
// " Note that this line is separate, but within the same paragraph.\n" +
|
||||
// " (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)\n" +
|
||||
// "\n" +
|
||||
// "* Unordered list can use asterisks\n" +
|
||||
// "- Or minuses\n" +
|
||||
// "+ Or pluses\n" +
|
||||
// "\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "## Links\n" +
|
||||
// "\n" +
|
||||
// "[I'm an inline-style link](https://www.google.com)\n" +
|
||||
// "\n" +
|
||||
// "[I'm a reference-style link][Arbitrary case-insensitive reference text]\n" +
|
||||
// "\n" +
|
||||
// "[I'm a relative reference to a repository file](../blob/master/LICENSE)\n" +
|
||||
// "\n" +
|
||||
// "[You can use numbers for reference-style link definitions][1]\n" +
|
||||
// "\n" +
|
||||
// "Or leave it empty and use the [link text itself].\n" +
|
||||
// "\n" +
|
||||
// "---\n" +
|
||||
// "\n" +
|
||||
// "## Code\n" +
|
||||
// "\n" +
|
||||
// "Inline `code` has `back-ticks around` it.\n" +
|
||||
// "\n" +
|
||||
// "```javascript\n" +
|
||||
// "var s = \"JavaScript syntax highlighting\";\n" +
|
||||
// "alert(s);\n" +
|
||||
// "```\n" +
|
||||
// "\n" +
|
||||
// "```python\n" +
|
||||
// "s = \"Python syntax highlighting\"\n" +
|
||||
// "print s\n" +
|
||||
// "```\n" +
|
||||
// "\n" +
|
||||
// "```java\n" +
|
||||
// "/**\n" +
|
||||
// " * Helper method to obtain a Parser with registered strike-through & table extensions\n" +
|
||||
// " * & task lists (added in 1.0.1)\n" +
|
||||
// " *\n" +
|
||||
// " * @return a Parser instance that is supported by this library\n" +
|
||||
// " * @since 1.0.0\n" +
|
||||
// " */\n" +
|
||||
// "@NonNull\n" +
|
||||
// "public static Parser createParser() {\n" +
|
||||
// " return new Parser.Builder()\n" +
|
||||
// " .extensions(Arrays.asList(\n" +
|
||||
// " StrikethroughExtension.create(),\n" +
|
||||
// " TablesExtension.create(),\n" +
|
||||
// " TaskListExtension.create()\n" +
|
||||
// " ))\n" +
|
||||
// " .build();\n" +
|
||||
// "}\n" +
|
||||
// "```\n" +
|
||||
// "\n" +
|
||||
// "```xml\n" +
|
||||
// "<ScrollView\n" +
|
||||
// " android:id=\"@+id/scroll_view\"\n" +
|
||||
// " android:layout_width=\"match_parent\"\n" +
|
||||
// " android:layout_height=\"match_parent\"\n" +
|
||||
// " android:layout_marginTop=\"?android:attr/actionBarSize\">\n" +
|
||||
// "\n" +
|
||||
// " <TextView\n" +
|
||||
// " android:id=\"@+id/text\"\n" +
|
||||
// " android:layout_width=\"match_parent\"\n" +
|
||||
// " android:layout_height=\"wrap_content\"\n" +
|
||||
// " android:layout_margin=\"16dip\"\n" +
|
||||
// " android:lineSpacingExtra=\"2dip\"\n" +
|
||||
// " android:textSize=\"16sp\"\n" +
|
||||
// " tools:text=\"yo\\nman\" />\n" +
|
||||
// "\n" +
|
||||
// "</ScrollView>\n" +
|
||||
// "```\n"
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -135,6 +387,7 @@ fun MarkdownMessageItem(message: MessageEntity, requestHolder: RequestHolder) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
// .height(IntrinsicSize.Max)
|
||||
.padding(bottom = 12.dp), verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Box {
|
||||
@ -143,14 +396,6 @@ fun MarkdownMessageItem(message: MessageEntity, requestHolder: RequestHolder) {
|
||||
contentDescription = "",
|
||||
modifier = Modifier.size(40.dp)
|
||||
)
|
||||
// Icon(
|
||||
// painter = painterResource(id = R.drawable.ic_markdown),
|
||||
// contentDescription = "",
|
||||
// tint = MaterialTheme.colors.MBlue,
|
||||
// modifier = Modifier
|
||||
// .size(20.dp)
|
||||
// .align(alignment = Alignment.BottomCenter)
|
||||
// )
|
||||
}
|
||||
|
||||
Text(
|
||||
@ -168,20 +413,14 @@ fun MarkdownMessageItem(message: MessageEntity, requestHolder: RequestHolder) {
|
||||
factory = { ctx ->
|
||||
android.widget.TextView(ctx).apply {
|
||||
this.post {
|
||||
// requestHolder.markdown.configuration().theme().
|
||||
requestHolder.markdown.setMarkdown(this, message.text)
|
||||
requestHolder.markdown.setMarkdown(
|
||||
this,
|
||||
"${message.text}\n\n${message.desp}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}, modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
// .pointerInput(Unit) {
|
||||
// this.detectTapGestures(
|
||||
// onLongPress = {
|
||||
// Log.d("WH_", "MarkdownMessageItem: ")
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
.padding(16.dp)
|
||||
)
|
||||
}
|
||||
|
@ -5,15 +5,14 @@ import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@ -21,11 +20,13 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.pushdeer.os.R
|
||||
import com.pushdeer.os.data.api.data.response.UserInfo
|
||||
import com.pushdeer.os.holder.RequestHolder
|
||||
import com.pushdeer.os.ui.compose.componment.SettingItem
|
||||
import com.pushdeer.os.ui.navigation.Page
|
||||
import com.pushdeer.os.ui.theme.MBlue
|
||||
import com.pushdeer.os.ui.theme.MainBlue
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
@ -191,6 +192,54 @@ fun SettingPage(requestHolder: RequestHolder) {
|
||||
requestHolder.globalNavController.navigate("logdog")
|
||||
}
|
||||
}
|
||||
item {
|
||||
var useInnerWebView by remember {
|
||||
mutableStateOf(requestHolder.settingStore.useInnerWebView)
|
||||
}
|
||||
|
||||
val bgc by animateColorAsState(
|
||||
targetValue = if (useInnerWebView) MaterialTheme.colors.MBlue else Color.Transparent
|
||||
)
|
||||
val bdc by animateColorAsState(targetValue = if (!useInnerWebView) MaterialTheme.colors.MBlue else Color.Transparent)
|
||||
val fgc by animateColorAsState(targetValue = if (useInnerWebView) Color.White else MaterialTheme.colors.MBlue)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(60.dp)
|
||||
.border(1.dp, color = bdc, shape = RoundedCornerShape(10.dp))
|
||||
.clickable {
|
||||
useInnerWebView = !useInnerWebView
|
||||
requestHolder.settingStore.useInnerWebView = useInnerWebView
|
||||
},
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.weight(0.7F)
|
||||
.height(60.dp)
|
||||
.background(color = bgc, shape = RoundedCornerShape(10.dp)),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = "Use Inner WebView", color = fgc,fontSize = 18.sp)
|
||||
AnimatedVisibility(visible = useInnerWebView) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Check,
|
||||
contentDescription = "",
|
||||
tint = fgc
|
||||
)
|
||||
}
|
||||
}
|
||||
AnimatedVisibility(visible = !useInnerWebView) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Close,
|
||||
contentDescription = "",
|
||||
tint = fgc,
|
||||
modifier = Modifier.padding(horizontal = 22.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
//package com.pushdeer.os.util
|
||||
//
|
||||
//import android.content.ComponentName
|
||||
//import android.content.Context
|
||||
//import android.content.pm.PackageManager
|
||||
//import com.pushdeer.os.receiver.MessageReceiver
|
||||
//import com.xiaomi.mipush.sdk.MessageHandleService
|
||||
//import com.xiaomi.mipush.sdk.PushMessageHandler
|
||||
//import com.xiaomi.push.service.XMJobService
|
||||
//import com.xiaomi.push.service.XMPushService
|
||||
//import com.xiaomi.push.service.receivers.NetworkStatusReceiver
|
||||
//import com.xiaomi.push.service.receivers.PingReceiver
|
||||
//
|
||||
//object AppComponentUtils {
|
||||
//
|
||||
// fun switchSelfHosted(isSelfHosted: Boolean, context: Context) {
|
||||
// val noneSelfHostedComponentNames = noneSelfHostedComponentNames(context)
|
||||
//// val selfHostedComponentNames = selfHostedComponentNames(context)
|
||||
// if (isSelfHosted) {
|
||||
// disableComponents(noneSelfHostedComponentNames,context.packageManager)
|
||||
// enableComponents(selfHostedComponentNames,context.packageManager)
|
||||
// } else {
|
||||
// disableComponents(selfHostedComponentNames,context.packageManager)
|
||||
// enableComponents(noneSelfHostedComponentNames,context.packageManager)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun noneSelfHostedComponentNames(context: Context): Array<ComponentName> {
|
||||
// return arrayOf(
|
||||
// ComponentName(context,XMPushService::class.java),
|
||||
// ComponentName(context, XMJobService::class.java),
|
||||
// ComponentName(context, PushMessageHandler::class.java),
|
||||
// ComponentName(context, MessageHandleService::class.java),
|
||||
// ComponentName(context, NetworkStatusReceiver::class.java),
|
||||
// ComponentName(context, PingReceiver::class.java),
|
||||
// ComponentName(context, MessageReceiver::class.java),
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// fun enableComponents(componentNames: Array<ComponentName>, pm: PackageManager) {
|
||||
// componentNames.forEach {
|
||||
// pm.setComponentEnabledSetting(
|
||||
// it,
|
||||
// PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||
// PackageManager.DONT_KILL_APP
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun disableComponents(componentNames: Array<ComponentName>, pm: PackageManager) {
|
||||
// componentNames.forEach {
|
||||
// pm.setComponentEnabledSetting(
|
||||
// it,
|
||||
// PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
// PackageManager.DONT_KILL_APP
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -0,0 +1,66 @@
|
||||
package com.pushdeer.os.util
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import com.pushdeer.os.App
|
||||
import com.pushdeer.os.keeper.RepositoryKeeper
|
||||
import com.pushdeer.os.values.AppKeys
|
||||
import com.xiaomi.channel.commonutils.logger.LoggerInterface
|
||||
import com.xiaomi.mipush.sdk.Logger
|
||||
import com.xiaomi.mipush.sdk.MiPushClient
|
||||
|
||||
object MiPushUtils {
|
||||
|
||||
private fun shouldInitMiPush(context: Context): Boolean {
|
||||
val am = context.getSystemService(Application.ACTIVITY_SERVICE) as ActivityManager
|
||||
val processInfoList = am.runningAppProcesses
|
||||
val mainProcessName = context.applicationInfo.processName
|
||||
val myPid = Process.myPid()
|
||||
for (info in processInfoList) {
|
||||
if (info.pid == myPid && mainProcessName == info.processName) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun autoInit(context: Context,repositoryKeeper:RepositoryKeeper){
|
||||
if (shouldInitMiPush(context)){
|
||||
MiPushClient.registerPush(context, AppKeys.MiPush_Id, AppKeys.MiPush_Key)
|
||||
}
|
||||
//打开Log
|
||||
Logger.setLogger(context, object : LoggerInterface {
|
||||
override fun setTag(tag: String) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
override fun log(content: String, t: Throwable) {
|
||||
Log.d(App.TAG, content, t)
|
||||
Thread {
|
||||
repositoryKeeper.logDogRepository.log(
|
||||
entity = "mipush",
|
||||
level = "e",
|
||||
event = t.message.toString(),
|
||||
log = content
|
||||
)
|
||||
}.start()
|
||||
}
|
||||
|
||||
override fun log(content: String) {
|
||||
Log.d(App.TAG, content)
|
||||
// Thread{
|
||||
// repositoryKeeper.logDogRepository.log(
|
||||
// entity = "mipush",
|
||||
// level = "d",
|
||||
// event = "",
|
||||
// log = content
|
||||
// )
|
||||
// }.start()
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
|
||||
</vector>
|
10
android/app/src/main/res/drawable/ic_baseline_close_24.xml
Normal file
10
android/app/src/main/res/drawable/ic_baseline_close_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||
</vector>
|
73
android/app/src/main/res/layout/activity_webview.xml
Normal file
73
android/app/src/main/res/layout/activity_webview.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/constraintLayout">
|
||||
|
||||
</WebView>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="@+id/webview"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageButton
|
||||
android:background="@android:color/transparent"
|
||||
android:id="@+id/ib_close"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@drawable/ic_baseline_close_24"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageButton
|
||||
android:background="@android:color/transparent"
|
||||
android:id="@+id/ib_back"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/ib_close"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:src="@drawable/ic_baseline_arrow_back_24" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:lines="1"
|
||||
android:maxLines="1"
|
||||
android:minLines="1"
|
||||
android:singleLine="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/ib_back"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/webview" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -11,5 +11,4 @@ rootProject.name = "PushDeer"
|
||||
include ':app'
|
||||
include ':common'
|
||||
include ':compose'
|
||||
include ':pushdeerclient'
|
||||
include ':pushdeercommon'
|
||||
|
1
self-hosted-push-server/.gitignore
vendored
Normal file
1
self-hosted-push-server/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
8
self-hosted-push-server/config.js
Normal file
8
self-hosted-push-server/config.js
Normal file
@ -0,0 +1,8 @@
|
||||
module.exports = config = {
|
||||
port: 5003,
|
||||
mainServerAuthToken: "asdfghjkl",
|
||||
hosts: [
|
||||
"127.0.0.1"
|
||||
],
|
||||
mainServerUrl:"http://127.0.0.1:4567"
|
||||
};
|
137
self-hosted-push-server/index.js
Normal file
137
self-hosted-push-server/index.js
Normal file
@ -0,0 +1,137 @@
|
||||
const config = require("./config");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const axios = require("axios");
|
||||
|
||||
app.use(express.json());
|
||||
app.use("/", express.static(path.join(__dirname, "./public")));
|
||||
app.use(require("cors")());
|
||||
app.use(require("compression")());
|
||||
|
||||
const httpServer = require("http").createServer(app);
|
||||
const SocketIOServer = require("socket.io");
|
||||
const { instrument } = require("@socket.io/admin-ui");
|
||||
const io = SocketIOServer(httpServer, {
|
||||
cors: {
|
||||
origin: "*",
|
||||
credentials: false,
|
||||
},
|
||||
});
|
||||
instrument(io, {
|
||||
auth: false,
|
||||
});
|
||||
app.get("/admin", (req, res) => {
|
||||
fs.readFile("./public/index.html", (err, data) => {
|
||||
res.write(data);
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
|
||||
const checkCookieToken = function (userId, cookieToken, clientId) {
|
||||
return true;
|
||||
};
|
||||
|
||||
function checkServerToken(serverToken) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let clientIdToUserId = {};
|
||||
let userIdToClient = {}; // user-${userId}
|
||||
io.on("connection", (socket) => {
|
||||
console.log(new Date(), "client connected: ", `${io.engine.clientsCount}`);
|
||||
socket.join("unauthed");
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log(new Date(), "client disconnect: ", `${io.engine.clientsCount}`);
|
||||
if (Object.keys(clientIdToUserId).includes(socket.id)) {
|
||||
let userId = clientIdToUserId[socket.id];
|
||||
let key = `user-${userId}`;
|
||||
if (Object.keys(userIdToClient).includes(key)) {
|
||||
delete userIdToClient[key];
|
||||
}
|
||||
delete clientIdToUserId[socket.id];
|
||||
}
|
||||
});
|
||||
socket.on("register", (data) => {
|
||||
let deviceId = data.deviceId || null;
|
||||
let authToken = data.token || null;
|
||||
if (deviceId && authToken) {
|
||||
if (checkCookieToken(deviceId, authToken, socket.id)) {
|
||||
// authed
|
||||
socket.leave("unauthed");
|
||||
|
||||
// axios.post(
|
||||
// config.mainServerUrl,
|
||||
// { userId }
|
||||
// ).then(res => {
|
||||
// if (res.status != 200) {
|
||||
// console.log(`状态码: ${res.status}`);
|
||||
// return;
|
||||
// }
|
||||
// }).catch(error => {
|
||||
// console.error(error)
|
||||
// });
|
||||
|
||||
|
||||
socket.emit("register-result", "authed");
|
||||
} else {
|
||||
socket.emit("register-result", "not authed");
|
||||
// not authed
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/online-count", (req, res, next) => {
|
||||
let oc = io.engine.clientsCount;
|
||||
res.json({
|
||||
status: 200,
|
||||
message: "OK",
|
||||
data: {
|
||||
online_count: oc.length,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
app.post(
|
||||
"notify",
|
||||
(req, res, next) => {
|
||||
if (req.headers.mainServerAuthToken != config.mainServerAuthToken) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
message: "unauthed",
|
||||
data: {},
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
(req, res) => {
|
||||
if (Object.keys(clientList).includes(req.body.clientId)) {
|
||||
clientList[req.body.clientId].socket.emit("notify", req.body.notify);
|
||||
res.json({
|
||||
status: 200,
|
||||
message: "OK",
|
||||
data: {},
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
res.status(404).json({
|
||||
status: 404,
|
||||
message: "Not Found",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
httpServer.listen(config.port, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
config.hosts.forEach((host) => {
|
||||
console.log(`http://${host}:${config.port}`);
|
||||
});
|
||||
});
|
4062
self-hosted-push-server/package-lock.json
generated
Normal file
4062
self-hosted-push-server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
self-hosted-push-server/package.json
Normal file
23
self-hosted-push-server/package.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "self-hosted-push-server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Wolf Hugo",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@socket.io/admin-ui": "^0.2.0",
|
||||
"axios": "^0.26.0",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"http": "^0.0.1-security",
|
||||
"https": "^1.0.0",
|
||||
"nodemon": "^2.0.14",
|
||||
"socket.io": "^4.3.1"
|
||||
}
|
||||
}
|
1
self-hosted-push-server/public/css/app.64cb6d3f.css
Normal file
1
self-hosted-push-server/public/css/app.64cb6d3f.css
Normal file
@ -0,0 +1 @@
|
||||
.chart[data-v-58987bf8],.chart[data-v-d6482f56]{max-width:160px;margin:20px}.select-room[data-v-d014ee1e],.selector[data-v-2c330798]{max-width:200px}.key-column[data-v-1a6e3452],.key-column[data-v-8d2424e4],.key-column[data-v-18284f59]{width:30%}
|
File diff suppressed because one or more lines are too long
BIN
self-hosted-push-server/public/favicon.png
Normal file
BIN
self-hosted-push-server/public/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
@ -0,0 +1,4 @@
|
||||
<svg viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet">
|
||||
<circle cx="128" cy="128" r="114" stroke="#FFF" stroke-width="20" fill="none" />
|
||||
<path d="M97.637 121.69c27.327-22.326 54.058-45.426 81.98-67.097-14.646 22.505-29.708 44.711-44.354 67.215-12.562.06-25.123.06-37.626-.119zM120.737 134.132c12.621 0 25.183 0 37.745.179-27.505 22.206-54.117 45.484-82.099 67.096 14.646-22.505 29.708-44.77 44.354-67.275z" fill="#FFF"/>
|
||||
</svg>
|
After Width: | Height: | Size: 473 B |
@ -0,0 +1,4 @@
|
||||
<svg viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet">
|
||||
<circle cx="128" cy="128" r="114" stroke="#010101" stroke-width="20" fill="none" />
|
||||
<path d="M97.637 121.69c27.327-22.326 54.058-45.426 81.98-67.097-14.646 22.505-29.708 44.711-44.354 67.215-12.562.06-25.123.06-37.626-.119zM120.737 134.132c12.621 0 25.183 0 37.745.179-27.505 22.206-54.117 45.484-82.099 67.096 14.646-22.505 29.708-44.77 44.354-67.275z" fill="#010101"/>
|
||||
</svg>
|
After Width: | Height: | Size: 478 B |
35
self-hosted-push-server/public/index.html
Normal file
35
self-hosted-push-server/public/index.html
Normal file
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<link rel="icon" href="/favicon.png" />
|
||||
<title>Socket.IO Admin UI</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css"
|
||||
/>
|
||||
<link href="/css/app.64cb6d3f.css" rel="preload" as="style" />
|
||||
<link href="/css/chunk-vendors.9f55d012.css" rel="preload" as="style" />
|
||||
<link href="/js/app.97c623ae.js" rel="preload" as="script" />
|
||||
<link href="/js/chunk-vendors.5dbfac0a.js" rel="preload" as="script" />
|
||||
<link href="/css/chunk-vendors.9f55d012.css" rel="stylesheet" />
|
||||
<link href="/css/app.64cb6d3f.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<noscript
|
||||
><strong
|
||||
>We're sorry but Socket.IO Admin UI doesn't work properly without
|
||||
JavaScript enabled. Please enable it to continue.</strong
|
||||
></noscript
|
||||
>
|
||||
<div id="app"></div>
|
||||
<script src="/js/chunk-vendors.5dbfac0a.js"></script>
|
||||
<script src="/js/app.97c623ae.js"></script>
|
||||
</body>
|
||||
</html>
|
2
self-hosted-push-server/public/js/app.97c623ae.js
Normal file
2
self-hosted-push-server/public/js/app.97c623ae.js
Normal file
File diff suppressed because one or more lines are too long
1
self-hosted-push-server/public/js/app.97c623ae.js.map
Normal file
1
self-hosted-push-server/public/js/app.97c623ae.js.map
Normal file
File diff suppressed because one or more lines are too long
30
self-hosted-push-server/public/js/chunk-vendors.5dbfac0a.js
Normal file
30
self-hosted-push-server/public/js/chunk-vendors.5dbfac0a.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user