diff --git a/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt index 508affd..9dc7cad 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt @@ -371,7 +371,7 @@ class EditModInfoActivity : BaseActivity() { iconFile.delete() } val bitmap = BitmapFactory.decodeFile(newIconFile.absolutePath) - if (bitmap.height == bitmap.width) { + if (bitmap != null && bitmap.height == bitmap.width) { if (FileOperator.copyFile(newIconFile, iconFile)) { Glide.with(this@EditModInfoActivity).load(newIconFile) .apply(GlobalMethod.getRequestOptions()) diff --git a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt index 71ce742..3a4a7c4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt @@ -17,6 +17,7 @@ import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.tool.FileOperator.copyFile import com.coldmint.rust.pro.databinding.ActivityImporterBinding import com.coldmint.rust.pro.tool.AppSettings +import com.coldmint.rust.pro.tool.EventRecord import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.viewmodel.StartViewModel import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -38,7 +39,7 @@ class ImporterActivity : BaseActivity() { setTitle(R.string.file_importer) val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isNotBlank()) { - firebaseAnalytics.setUserId(account) + EventRecord.setUserId(account) } startViewModel.initAllData() GlobalMethod.requestStoragePermissions(this) { diff --git a/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt b/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt index 109e110..d199895 100644 --- a/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt @@ -30,6 +30,7 @@ import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.ActivityLoginBinding import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.EmailAutoCompleteHelper +import com.coldmint.rust.pro.tool.EventRecord import com.coldmint.rust.pro.tool.GlobalMethod import com.google.android.material.snackbar.Snackbar import com.gyf.immersionbar.ktx.immersionBar @@ -124,10 +125,8 @@ class LoginActivity : BaseActivity() { viewBinding.button.setText(R.string.login) if (userData.code == ServerConfiguration.Success_Code) { //记录登录事件 - val bundle = Bundle() - bundle.putString("账号", userData.data.account) - firebaseAnalytics.logEvent(GlobalMethod.Event_LOGIN, bundle) - firebaseAnalytics.setUserId(userData.data.account) + EventRecord.setUserId(account) + EventRecord.login() AppSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) AppSettings.forceSetValue( AppSettings.Setting.Account, diff --git a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt index 1a589d9..67d3f47 100644 --- a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt @@ -39,6 +39,7 @@ import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.pro.databinding.ActivityMainBinding import com.coldmint.rust.pro.databinding.HeadLayoutBinding import com.coldmint.rust.pro.fragments.UserGroupFragment +import com.coldmint.rust.pro.tool.EventRecord import com.coldmint.rust.pro.viewmodel.StartViewModel import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.tabs.TabLayout @@ -642,7 +643,7 @@ class MainActivity : BaseActivity() { opIntent.putExtra("userId", account) startActivity(opIntent) } - firebaseAnalytics.setUserId(account) + EventRecord.setUserId(account) } startViewModel.needLoginLiveData.observe(this) { diff --git a/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt b/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt index e8ba53f..9b3823e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt @@ -22,6 +22,7 @@ import com.coldmint.rust.core.interfaces.LineParserEvent import com.coldmint.rust.core.tool.FileFinder2 import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.pro.databinding.ActivityPackBinding +import com.coldmint.rust.pro.tool.EventRecord import java.io.File import java.lang.StringBuilder import java.text.SimpleDateFormat @@ -307,7 +308,10 @@ class PackActivity : BaseActivity() { } override fun whenCompressionComplete(result: Boolean) { - handler.post { resetButton(result) } + handler.post { + EventRecord.packMod(targetFile.name) + resetButton(result) + } } }, object : CompressionInterceptor { override val sourceFileRule: String diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt index f276af5..feb4028 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt @@ -34,7 +34,6 @@ import java.util.* abstract class BaseActivity : AppCompatActivity() { - protected lateinit var firebaseAnalytics: FirebaseAnalytics abstract fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) @@ -50,7 +49,6 @@ abstract class BaseActivity : } override fun onCreate(savedInstanceState: Bundle?) { - firebaseAnalytics = Firebase.analytics WindowCompat.setDecorFitsSystemWindows(window, false) super.onCreate(savedInstanceState) whenCreateActivity(savedInstanceState, false) diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt index cd644f6..8e1837a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt @@ -16,6 +16,7 @@ abstract class BaseFragment : Fragment() { protected lateinit var firebaseAnalytics: FirebaseAnalytics val viewBinding: T by lazy { + val layoutInflater = LayoutInflater.from(requireActivity()) getViewBindingObject(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt index e60adb2..ae2ccbe 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt @@ -164,16 +164,18 @@ class InstalledTemplateFragment : BaseFragment } } viewModel.setLoadCallBack { - mTemplateAdapter = TemplateAdapter( - requireContext(), - viewModel.getGroupData(), - viewModel.getItemData(), - viewModel.environmentLanguage, startTemplateParserActivity - ) - viewBinding.expandableList.setAdapter(mTemplateAdapter) - val path = viewModel.createPathLiveData.value.toString() - mTemplateAdapter.setCreatePath(path) - LogCat.d("创建目录观察者", "模板适配器设置目录为${path}。") + if (isAdded) { + mTemplateAdapter = TemplateAdapter( + requireContext(), + viewModel.getGroupData(), + viewModel.getItemData(), + viewModel.environmentLanguage, startTemplateParserActivity + ) + viewBinding.expandableList.setAdapter(mTemplateAdapter) + val path = viewModel.createPathLiveData.value.toString() + mTemplateAdapter.setCreatePath(path) + LogCat.d("创建目录观察者", "模板适配器设置目录为${path}。") + } } viewModel.loadTemplate(requireContext()) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt index ad84fbd..efcd039 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt @@ -19,6 +19,7 @@ import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databean.CommunityServiceInfo import com.coldmint.rust.pro.databinding.FragmentUserInfoBinding import com.coldmint.rust.pro.tool.AppSettings +import com.coldmint.rust.pro.tool.EventRecord import com.coldmint.rust.pro.tool.GlobalMethod class UserInfoFragment : BaseFragment() { @@ -169,10 +170,8 @@ class UserInfoFragment : BaseFragment() { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { viewBinding.logOutButton.setOnClickListener { - val bundle = Bundle() - bundle.putString("账号", account) - firebaseAnalytics.setUserId(null); - firebaseAnalytics.logEvent(GlobalMethod.Event_LOGOUT, bundle) + EventRecord.logout() + EventRecord.setUserId(null) AppSettings.setValue(AppSettings.Setting.LoginStatus, false) // GlobalMethod.isActive = false AppSettings.setValue( diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/EventRecord.kt b/app/src/main/java/com/coldmint/rust/pro/tool/EventRecord.kt new file mode 100644 index 0000000..008ed62 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/tool/EventRecord.kt @@ -0,0 +1,56 @@ +package com.coldmint.rust.pro.tool + +import android.os.Bundle +import com.google.firebase.analytics.ktx.analytics +import com.google.firebase.ktx.Firebase + +/** + * 事件记录类 + */ +object EventRecord { + const val Event_LOGOUT = "logout" + + //打包Mod + const val Event_PACK_MOD = "pack_mod" + const val Event_LOGIN = "login" + + private val firebaseAnalytics = Firebase.analytics + private var account: String? = null + + /** + * 设置用户id + */ + fun setUserId(userId: String?) { + account = userId + } + + /** + * 登录 + */ + fun login() { + val bundle = Bundle() + bundle.putString("account", account) + firebaseAnalytics.logEvent(Event_LOGIN, bundle) + firebaseAnalytics.setUserId(account) + } + + /** + * 登出 + */ + fun logout() { + val bundle = Bundle() + bundle.putString("account", account) + firebaseAnalytics.logEvent(Event_LOGOUT, bundle) + } + + /** + * 打包模组 + */ + fun packMod(targetFileName: String) { + val bundle = Bundle() + bundle.putString("account", account) + bundle.putString("fileName", targetFileName) + firebaseAnalytics.logEvent(Event_PACK_MOD, bundle) + firebaseAnalytics.setUserId(account) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt index 72e954c..a93906d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt @@ -47,8 +47,7 @@ object GlobalMethod { const val DEFAULT_GAME_PACKAGE = "com.corrodinggames.rts" const val DEBUG_SIGN = "963dfd616924b27f9247a35e45bc130a" const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda" - const val Event_LOGOUT = "logOut" - const val Event_LOGIN = "logIn" + /** diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateMakerViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateMakerViewModel.kt index 454a2b5..a4395c0 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateMakerViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateMakerViewModel.kt @@ -116,11 +116,16 @@ class TemplateMakerViewModel : BaseViewModel() { TemplatePhp.instance.getTemplate(path ?: "", object : ApiCallBack { override fun onResponse(t: WebTemplateData) { if (t.code == ServerConfiguration.Success_Code) { - json = JSONObject(t.data.content) - val code = json!!.getString("data") - val jsonArray = json!!.getJSONArray("action") - parsingSourceCode(code, jsonArray, func) - LogCat.d(key, "已加载远程模板 ${path} 。") + try { + json = JSONObject(t.data.content) + val code = json!!.getString("data") + val jsonArray = json!!.getJSONArray("action") + parsingSourceCode(code, jsonArray, func) + LogCat.d(key, "已加载远程模板 ${path} 。") + }catch (e:Exception){ + e.printStackTrace() + LogCat.d(key, "远程模板加载异常。"+e.toString()) + } } else { LogCat.e(key, "远程模板响应: ${t.message}") }