From 6faf7c16cf6d1db896f9b8f85a894018621a106a Mon Sep 17 00:00:00 2001 From: Szzrain <54656633+Szzrain@users.noreply.github.com> Date: Thu, 7 Sep 2023 11:07:42 -0400 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9A=E4=BF=9D=E6=B4=BB=E7=AD=96=E7=95=A5=EF=BC=9A=E6=9C=80?= =?UTF-8?q?=E8=BF=91=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=20(#30)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 54badf3851f6dc698ff14d962461f13b7b685bf4. --- .../java/com/sealdice/dice/FirstFragment.kt | 48 +------------ .../java/com/sealdice/dice/MainActivity.kt | 70 ++++--------------- .../java/com/sealdice/dice/utils/Utils.kt | 14 ---- app/src/main/res/xml/preferences.xml | 5 -- 4 files changed, 16 insertions(+), 121 deletions(-) diff --git a/app/src/main/java/com/sealdice/dice/FirstFragment.kt b/app/src/main/java/com/sealdice/dice/FirstFragment.kt index a3fc004..d68385b 100644 --- a/app/src/main/java/com/sealdice/dice/FirstFragment.kt +++ b/app/src/main/java/com/sealdice/dice/FirstFragment.kt @@ -35,7 +35,7 @@ import kotlin.system.exitProcess /** * A simple [Fragment] subclass as the default destination in the navigation. */ -class FirstFragment : Fragment(),SharedPreferences.OnSharedPreferenceChangeListener { +class FirstFragment : Fragment() { private lateinit var _binding: FragmentFirstBinding @@ -56,51 +56,6 @@ class FirstFragment : Fragment(),SharedPreferences.OnSharedPreferenceChangeListe isBound = false } } - // Use onCreate function, make settings changes. - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - // 注册SharedPreferences监听器 - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) - sharedPreferences.registerOnSharedPreferenceChangeListener(this) - } - - //Pinenutn:(想写英文,发现不会说,我还是中文8) - //由于不在最近任务列表显示如果也要放在启动核心之后会出现各种反人类操作,而我又不会改:( - //主要还是本人安卓程序开发经验较少…… - override fun onSharedPreferenceChanged(p0: SharedPreferences?, p1: String?) { - if (p0 != null) { - //ADD enableExcludeFromRecents - if(p0.getBoolean("alive_excluderecents",false)){ - //不在最近任务列表中显示 - val am = context?.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager - am.let { - val tasks = it.appTasks - if (!tasks.isNullOrEmpty()) { - Toast.makeText(context,"豹豹已下潜",Toast.LENGTH_SHORT).show(); - tasks[0].setExcludeFromRecents(true) - } - } - } - else{ - //恢复最近任务列表中显示 - val am = context?.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager - am.let { - val tasks = it.appTasks - if (!tasks.isNullOrEmpty()) { - Toast.makeText(context,"豹豹已上浮",Toast.LENGTH_SHORT).show(); - tasks[0].setExcludeFromRecents(false) - } - } - } - } - } - - override fun onDestroy() { - super.onDestroy() - // 在Fragment销毁时取消注册SharedPreferences监听器,以防止内存泄漏 - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) - sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) - } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -586,5 +541,4 @@ class FirstFragment : Fragment(),SharedPreferences.OnSharedPreferenceChangeListe false } } - } \ No newline at end of file diff --git a/app/src/main/java/com/sealdice/dice/MainActivity.kt b/app/src/main/java/com/sealdice/dice/MainActivity.kt index 44b00d5..a76d188 100644 --- a/app/src/main/java/com/sealdice/dice/MainActivity.kt +++ b/app/src/main/java/com/sealdice/dice/MainActivity.kt @@ -1,6 +1,5 @@ package com.sealdice.dice -import android.app.ActivityManager import android.content.* import android.content.pm.PackageManager import android.net.Uri @@ -9,7 +8,6 @@ import android.os.PersistableBundle import android.util.Log import android.view.Menu import android.view.MenuItem -import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity @@ -20,8 +18,6 @@ import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.navigateUp import androidx.navigation.ui.setupActionBarWithNavController import com.sealdice.dice.databinding.ActivityMainBinding -import com.sealdice.dice.utils.Utils -import com.sealdice.dice.utils.ViewModelMain import com.tencent.smtt.export.external.TbsCoreSettings import com.tencent.smtt.sdk.QbSdk import kotlinx.coroutines.Dispatchers @@ -33,7 +29,7 @@ import okhttp3.Request import org.json.JSONObject -private class PreInitCallbackImpl : QbSdk.PreInitCallback { +private class PreInitCallbackImpl: QbSdk.PreInitCallback { override fun onCoreInitFinished() { } @@ -50,25 +46,6 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - //每次都检查是否需要关闭/启动后台 - if (Utils.getExcludeFromRecents(this)) { - val am = this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager - am.let { - val tasks = it.appTasks - if (!tasks.isNullOrEmpty()) { - tasks[0].setExcludeFromRecents(true) - } - } - } else { - //恢复最近任务列表中显示 - val am = this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager - am.let { - val tasks = it.appTasks - if (!tasks.isNullOrEmpty()) { - tasks[0].setExcludeFromRecents(false) - } - } - } val intentUpdateService = Intent(this, UpdateService::class.java) startService(intentUpdateService) QbSdk.initX5Environment(this, PreInitCallbackImpl()) @@ -86,18 +63,9 @@ class MainActivity : AppCompatActivity() { val navController = findNavController(R.id.nav_host_fragment_content_main) appBarConfiguration = AppBarConfiguration(navController.graph) setupActionBarWithNavController(navController, appBarConfiguration) - if (ContextCompat.checkSelfPermission( - this, - android.Manifest.permission.INTERNET - ) != PackageManager.PERMISSION_GRANTED - ) { - ActivityCompat.requestPermissions( - this, - arrayOf(android.Manifest.permission.INTERNET), - 1 - ) + if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.INTERNET),1) } - } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -109,7 +77,7 @@ class MainActivity : AppCompatActivity() { override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { super.onPostCreate(savedInstanceState, persistentState) if (this.packageName != "com.sealdice.dice") { - val alertDialogBuilder = AlertDialog.Builder(this, R.style.Theme_Mshell_DialogOverlay) + val alertDialogBuilder = AlertDialog.Builder(this,R.style.Theme_Mshell_DialogOverlay) alertDialogBuilder.setTitle("提示") alertDialogBuilder.setMessage("检测到您正在使用非官方版本或多开软件,可能会导致一些问题,建议您使用官方版本") alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int -> } @@ -171,37 +139,34 @@ class MainActivity : AppCompatActivity() { val jsonData = response.body?.string() val jsonObject = jsonData?.let { JSONObject(it) } val latestVersion = jsonObject?.getString("version") - Log.e("--Service--", "已经获取了version${latestVersion}") + Log.e("--Service--","已经获取了version${latestVersion}") // Check if current version is up-to-date val currentVersion = BuildConfig.VERSION_NAME if (latestVersion != currentVersion) { // Show update notification withContext(Dispatchers.Main) { dialog.cancel() - val alertDialogBuilder = - AlertDialog.Builder(self, R.style.Theme_Mshell_DialogOverlay) + val alertDialogBuilder = AlertDialog.Builder(self,R.style.Theme_Mshell_DialogOverlay) alertDialogBuilder.setTitle("提示") alertDialogBuilder.setMessage("发现更新,点击确定开始下载新版本\n线上版本:${latestVersion}\n本地版本:${currentVersion}") alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int -> - val uri = - Uri.parse("https://d.catlevel.com/seal/android/latest") + val uri = Uri.parse("https://d.catlevel.com/seal/android/latest") val intent = Intent() intent.action = "android.intent.action.VIEW" intent.data = uri startActivity(intent) } - alertDialogBuilder.setNegativeButton("取消") { _: DialogInterface, _: Int -> } + alertDialogBuilder.setNegativeButton("取消") {_: DialogInterface, _: Int ->} alertDialogBuilder.create().show() } } else { - // Current version is up-to-date + // Current version is up-to-date withContext(Dispatchers.Main) { dialog.cancel() - val alertDialogBuilder = - AlertDialog.Builder(self, R.style.Theme_Mshell_DialogOverlay) + val alertDialogBuilder = AlertDialog.Builder(self,R.style.Theme_Mshell_DialogOverlay) alertDialogBuilder.setTitle("提示") alertDialogBuilder.setMessage("当前版本已是最新") - alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int -> } + alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int ->} alertDialogBuilder.create().show() } } @@ -209,18 +174,13 @@ class MainActivity : AppCompatActivity() { e.printStackTrace() withContext(Dispatchers.Main) { dialog.cancel() - val alertDialogBuilder = - AlertDialog.Builder(self, R.style.Theme_Mshell_DialogOverlay) + val alertDialogBuilder = AlertDialog.Builder(self,R.style.Theme_Mshell_DialogOverlay) alertDialogBuilder.setTitle("提示") alertDialogBuilder.setMessage("检查更新时出现错误,可能是网络问题,请稍后重试") - alertDialogBuilder.setNegativeButton("查看错误信息") { _: DialogInterface, _: Int -> - AlertDialog.Builder(self, R.style.Theme_Mshell_DialogOverlay) - .setTitle("错误信息") - .setMessage("错误信息:\n${e.localizedMessage}\nStackTrace:\n${e.stackTraceToString()}") - .setPositiveButton("确定") { _: DialogInterface, _: Int -> } - .create().show() + alertDialogBuilder.setNegativeButton("查看错误信息") {_: DialogInterface, _: Int -> + AlertDialog.Builder(self,R.style.Theme_Mshell_DialogOverlay).setTitle("错误信息").setMessage("错误信息:\n${e.localizedMessage}\nStackTrace:\n${e.stackTraceToString()}").setPositiveButton("确定") { _: DialogInterface, _: Int ->}.create().show() } - alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int -> } + alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int ->} alertDialogBuilder.create().show() } } diff --git a/app/src/main/java/com/sealdice/dice/utils/Utils.kt b/app/src/main/java/com/sealdice/dice/utils/Utils.kt index 1209be2..82dcc6f 100644 --- a/app/src/main/java/com/sealdice/dice/utils/Utils.kt +++ b/app/src/main/java/com/sealdice/dice/utils/Utils.kt @@ -10,25 +10,11 @@ import android.provider.Settings import android.text.TextUtils import android.util.Log import android.widget.Toast -import android.content.SharedPreferences -import androidx.preference.PreferenceManager -import com.sealdice.dice.MediaService import java.util.ArrayList object Utils { const val REQUEST_FLOAT_CODE=1001 - /** - * 用于检查是否需要消除后台任务的变量 - */ - fun getExcludeFromRecents(context: Context):Boolean{ - val sharedPreferences = context.let { PreferenceManager.getDefaultSharedPreferences(it) } - if (sharedPreferences != null) { - return sharedPreferences.getBoolean("alive_media", false) - } - return false - } - /** * 跳转到设置页面申请打开无障碍辅助功能 */ diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index b667da2..1e18a34 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -23,11 +23,6 @@ android:title="保活策略:无声音频" android:summary="通过循环播放无声音频进行保活" android:defaultValue="false" /> -