Skip to content

Commit

Permalink
refactor: migrate i18ns generation to FlexiLocale plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fankes committed Oct 13, 2023
1 parent d215440 commit 72d76a4
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 696 deletions.
3 changes: 3 additions & 0 deletions gradle/sweet-dependency/sweet-dependency-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ plugins:
org.jetbrains.kotlin.android:
alias: kotlin-android
version: 1.9.10
com.highcapable.flexilocale:
alias: flexi-locale
version: 1.0.0
com.google.devtools.ksp:
alias: kotlin-ksp
version: 1.9.10-1.0.13
Expand Down
1 change: 1 addition & 0 deletions module-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
autowire(libs.plugins.android.application)
autowire(libs.plugins.kotlin.android)
autowire(libs.plugins.kotlin.ksp)
autowire(libs.plugins.flexi.locale)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ package com.fankes.apperrorstracking.application

import androidx.appcompat.app.AppCompatDelegate
import com.fankes.apperrorstracking.data.ConfigData
import com.fankes.apperrorstracking.locale.LocaleString
import com.fankes.apperrorstracking.generated.locale.ModuleAppLocale
import com.fankes.apperrorstracking.locale.locale
import com.fankes.apperrorstracking.utils.tool.AppAnalyticsTool
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication

class AppErrorsApplication : ModuleApplication() {

override fun onCreate() {
super.onCreate()
/** 绑定 I18n */
locale = ModuleAppLocale.attach(this)
/** 跟随系统夜间模式 */
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
/** 绑定 I18n */
LocaleString.bind(instance = this)
/** 装载存储控制类 */
ConfigData.init(instance = this)
ConfigData.init(this)
/** 装载 App Center */
AppAnalyticsTool.init(instance = this)
AppAnalyticsTool.init(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package com.fankes.apperrorstracking.bean
import android.app.ApplicationErrorReport
import android.content.Context
import android.os.Build
import com.fankes.apperrorstracking.locale.LocaleString
import com.fankes.apperrorstracking.locale.locale
import com.fankes.apperrorstracking.utils.factory.appCpuAbiOf
import com.fankes.apperrorstracking.utils.factory.appVersionCodeOf
import com.fankes.apperrorstracking.utils.factory.appVersionNameOf
Expand Down Expand Up @@ -155,13 +155,13 @@ data class AppErrorsInfoBean(
*/
val crossTime
get() = timestamp.difference(
now = LocaleString.momentAgo,
second = LocaleString.secondAgo,
minute = LocaleString.minuteAgo,
hour = LocaleString.hourAgo,
day = LocaleString.dayAgo,
month = LocaleString.monthAgo,
year = LocaleString.yearAgo
now = locale.momentAgo,
second = locale.secondAgo,
minute = locale.minuteAgo,
hour = locale.hourAgo,
day = locale.dayAgo,
month = locale.monthAgo,
year = locale.yearAgo
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
package com.fankes.apperrorstracking.hook

import com.fankes.apperrorstracking.data.ConfigData
import com.fankes.apperrorstracking.generated.locale.ModuleAppLocale
import com.fankes.apperrorstracking.hook.entity.FrameworkHooker
import com.fankes.apperrorstracking.locale.LocaleString
import com.fankes.apperrorstracking.locale.locale
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
import com.highcapable.yukihookapi.hook.factory.configs
import com.highcapable.yukihookapi.hook.factory.encase
Expand All @@ -42,8 +43,8 @@ object HookEntry : IYukiHookXposedInit {

override fun onHook() = encase {
loadSystem {
LocaleString.bind(instance = this)
ConfigData.init(instance = this)
locale = ModuleAppLocale.attach { moduleAppResources }
ConfigData.init(this)
loadHooker(FrameworkHooker)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import com.fankes.apperrorstracking.data.AppErrorsConfigData
import com.fankes.apperrorstracking.data.AppErrorsRecordData
import com.fankes.apperrorstracking.data.ConfigData
import com.fankes.apperrorstracking.data.enum.AppErrorsConfigType
import com.fankes.apperrorstracking.locale.LocaleString
import com.fankes.apperrorstracking.locale.locale
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsDisplayActivity
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsRecordActivity
import com.fankes.apperrorstracking.utils.factory.appNameOf
Expand Down Expand Up @@ -288,18 +288,18 @@ object FrameworkHooker : YukiBaseHooker() {
val appName = appInfo?.let { context.appNameOf(it.packageName).ifBlank { it.packageName } } ?: packageName

/** 当前 APP 名称 (包含用户 ID) */
val appNameWithUserId = if (userId != 0) "$appName (${LocaleString.userId(userId)})" else appName
val appNameWithUserId = if (userId != 0) "$appName (${locale.userId(userId)})" else appName

/** 崩溃标题 */
val errorTitle = if (isRepeatingCrash) LocaleString.aerrRepeatedTitle(appNameWithUserId) else LocaleString.aerrTitle(appNameWithUserId)
val errorTitle = if (isRepeatingCrash) locale.aerrRepeatedTitle(appNameWithUserId) else locale.aerrTitle(appNameWithUserId)

/** 使用通知推送异常信息 */
fun showAppErrorsWithNotify() =
context.pushNotify(
channelId = "APPS_ERRORS",
channelName = LocaleString.appName,
channelName = locale.appName,
title = errorTitle,
content = LocaleString.appErrorsTip,
content = locale.appErrorsTip,
icon = IconCompat.createWithBitmap(moduleAppResources.drawableOf(R.drawable.ic_notify).toBitmap()),
color = 0xFFFF6200.toInt(),
intent = AppErrorsRecordActivity.intent()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* AppErrorsTracking - Added more features to app's crash dialog, fixed custom rom deleted dialog, the best experience to Android developer.
* Copyright (C) 2017-2023 Fankes Studio([email protected])
* https://github.com/KitsunePie/AppErrorsTracking
*
* This software is non-free but opensource software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* and eula along with this software. If not, see
* <https://www.gnu.org/licenses/>
*
* This file is created by fankes on 2023/10/13.
*/
@file:Suppress("StaticFieldLeak")

package com.fankes.apperrorstracking.locale

import com.fankes.apperrorstracking.generated.locale.ModuleAppLocale

/** I18ns 实例 */
lateinit var locale: ModuleAppLocale
Loading

0 comments on commit 72d76a4

Please sign in to comment.