diff --git a/app/build.gradle b/app/build.gradle index e74c17e..3eb630e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,15 +24,15 @@ android { keyAlias 'coldmint' } } - compileSdkVersion 33 - buildToolsVersion "30.0.3" + compileSdk 33 +// buildToolsVersion "30.0.3" defaultConfig { applicationId "com.coldmint.rust.pro" minSdkVersion 23 targetSdkVersion 33 versionCode 28 - versionName "2.1 Bata6(2023-7-20)" + versionName "2.1.1 Bata6(2023-7-20)" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -91,12 +91,15 @@ dependencies { exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib' } + api 'androidx.appcompat:appcompat:1.6.1' + api 'com.google.android.material:material:1.9.0' + implementation platform('com.google.firebase:firebase-bom:31.1.1') implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-crashlytics-ktx' implementation 'com.google.firebase:firebase-perf-ktx' - implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: []) - +// implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: []) + api project(path: ':library') def nav_version = "2.5.1" // implementation 'com.luolc:emoji-rain:0.1.1' @@ -133,16 +136,10 @@ dependencies { implementation 'com.github.florent37:glidepalette:2.1.2' implementation 'cat.ereza:customactivityoncrash:2.3.0' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" - implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'dev.rikka.rikkax.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" implementation 'androidx.preference:preference-ktx:1.2.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' - } \ No newline at end of file diff --git a/app/libs/colorpicker-0.0.15.aar b/app/libs/colorpicker-0.0.15.aar deleted file mode 100644 index c70d803..0000000 Binary files a/app/libs/colorpicker-0.0.15.aar and /dev/null differ diff --git a/app/src/androidTest/java/com/coldmint/rust/pro/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/coldmint/rust/pro/ExampleInstrumentedTest.java deleted file mode 100644 index 08169d6..0000000 --- a/app/src/androidTest/java/com/coldmint/rust/pro/ExampleInstrumentedTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.coldmint.rust.pro; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * 仪器测试,将在Android设备上执行。 - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // 被测试应用程序的上下文。 - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.coldmint.rust.pro", appContext.getPackageName()); - } - - -} \ No newline at end of file diff --git a/app/src/androidTest/java/com/coldmint/rust/pro/SourceFileUnitTest.kt b/app/src/androidTest/java/com/coldmint/rust/pro/SourceFileUnitTest.kt deleted file mode 100644 index 3d05313..0000000 --- a/app/src/androidTest/java/com/coldmint/rust/pro/SourceFileUnitTest.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.coldmint.rust.pro - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.coldmint.rust.core.SourceFile -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.Assert.* - - -@RunWith(AndroidJUnit4::class) -class SourceFileUnitTest { - - @Test - fun testWriteValue() { - val sourceFile = SourceFile("[core]\nname:124") - //测试修改值 - sourceFile.writeValue("name", "love") - assertEquals("[core]\nname:love", sourceFile.text) - //测试修改值2 - sourceFile.text = "[core]\nname:124\nmsg:ni" - sourceFile.writeValue("msg", "happy") - sourceFile.writeValue("name", "loveMe") - assertEquals("[core]\nname:loveMe\nmsg:happy", sourceFile.text) - } - - @Test - fun testReadValue() { - val sourceFile = SourceFile("[core]\n\nname:124\nkey:value2") - //测试修改值 - val value = sourceFile.readValue("name") - assertEquals("124", value) - //测试修改值2 - sourceFile.text = "[core]\nname:124\nmsg:ni" - val value2 = sourceFile.readValue("msg") - assertEquals("ni", value2) - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0104239..c295d67 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,27 +24,28 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.rust.Concept" - android:usesCleartextTraffic="true"> + android:usesCleartextTraffic="true" + android:screenOrientation="portrait" + tools:targetApi="tiramisu"> + android:screenOrientation="portrait" + tools:ignore="LockedOrientationActivity" /> + android:screenOrientation="portrait" + tools:ignore="LockedOrientationActivity" /> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:label="@string/built_in_browser"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:name="com.yalantis.ucrop.UCropActivity"/> + android:launchMode="singleTask"> @@ -167,8 +146,7 @@ android:excludeFromRecents="true" android:exported="true" android:label="@string/file_importer" - android:maxRecents="3" - android:screenOrientation="portrait"> + android:maxRecents="3"> @@ -268,93 +246,69 @@ + android:exported="false"/> + android:name=".ValueTypeActivity"/> + android:label="@string/global_operations"/> + android:name=".CreateModActivity"/> + android:name=".UnitsActivity"/> + android:name=".OptimizeActivity"/> + android:name=".FileManagerActivity"/> + android:name=".CreateUnitActivity"/> + android:name=".TemplateParserActivity"/> + android:name=".LibraryActivity"/> + android:label="@string/setting"/> + android:name=".TemplateMakerActivity"/> + android:name=".CreateTemplateActivity"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false" /> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> + android:exported="false"/> \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt index 40acc3c..30eb9b4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt @@ -8,7 +8,12 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.provider.MediaStore -import android.view.* +import android.view.KeyEvent +import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuItem +import android.view.SubMenu +import android.view.View import android.widget.PopupMenu import android.widget.Toast import androidx.activity.result.ActivityResultLauncher @@ -17,7 +22,6 @@ import androidx.core.view.GravityCompat import androidx.core.view.isVisible import androidx.drawerlayout.widget.DrawerLayout import androidx.lifecycle.ViewModelProvider -import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions @@ -31,7 +35,6 @@ import com.coldmint.rust.core.database.file.FileDataBase import com.coldmint.rust.core.tool.AppOperator import com.coldmint.rust.core.tool.DebugHelper import com.coldmint.rust.core.tool.FileOperator -import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.pro.adapters.FileAdapter import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databean.ErrorInfo @@ -49,23 +52,16 @@ import com.coldmint.rust.pro.viewmodel.EditStartViewModel import com.coldmint.rust.pro.viewmodel.EditViewModel import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar -import com.google.firebase.crashlytics.ktx.crashlytics -import com.google.firebase.ktx.Firebase -import io.github.rosemoe.sora.lang.completion.CompletionPublisher -import io.github.rosemoe.sora.text.CharPosition -import io.github.rosemoe.sora.text.ContentReference import io.github.rosemoe.sora.widget.EditorSearcher import io.github.rosemoe.sora.widget.component.EditorAutoCompletion import io.github.rosemoe.sora.widget.schemes.EditorColorScheme import jp.wasabeef.glide.transformations.BlurTransformation import java.io.File -import java.util.* -import kotlin.collections.ArrayList class EditActivity : BaseActivity() { private val viewModel by lazy { - ViewModelProvider(this).get(EditViewModel::class.java) + ViewModelProvider(this)[EditViewModel::class.java] } private lateinit var turretCoordinateResults: ActivityResultLauncher diff --git a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt index 97e18d8..5aff312 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -1,27 +1,21 @@ package com.coldmint.rust.pro -import com.coldmint.rust.pro.base.BaseActivity -import com.coldmint.rust.pro.tool.BookmarkManager -import androidx.recyclerview.widget.LinearLayoutManager import android.content.Intent -import com.coldmint.rust.pro.tool.GlobalMethod -import com.google.android.material.snackbar.Snackbar -import android.provider.MediaStore -import android.provider.DocumentsContract -import android.content.ContentUris -import android.content.Context -import android.database.Cursor import android.net.Uri -import android.os.* -import android.view.* -import android.widget.* -import android.widget.Toast.makeText +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.provider.MediaStore +import android.view.KeyEvent +import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.annotation.RequiresApi import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider -import com.bumptech.glide.Glide +import androidx.recyclerview.widget.LinearLayoutManager import com.coldmint.dialog.CoreDialog import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.tool.DebugHelper @@ -29,27 +23,20 @@ import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.tool.LineParser import com.coldmint.rust.pro.adapters.FileAdapter import com.coldmint.rust.pro.adapters.FileTabAdapter +import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databean.FileTab import com.coldmint.rust.pro.databinding.ActivityFileBinding import com.coldmint.rust.pro.interfaces.BookmarkListener import com.coldmint.rust.pro.tool.AppSettings +import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.ui.StableLinearLayoutManager import com.coldmint.rust.pro.viewmodel.FileManagerViewModel -import com.google.android.material.chip.Chip -import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.google.android.material.snackbar.SnackbarContentLayout +import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.launch import me.zhanghai.android.fastscroll.FastScrollerBuilder -import java.io.BufferedReader import java.io.File -import java.io.InputStreamReader -import java.lang.Exception -import java.util.* -import java.util.concurrent.Executors -import javax.sql.CommonDataSource -import kotlin.collections.ArrayList class FileManagerActivity : BaseActivity() { 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 655a090..7776691 100644 --- a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt @@ -1,20 +1,17 @@ package com.coldmint.rust.pro -import com.coldmint.rust.pro.base.BaseActivity -import com.coldmint.rust.pro.tool.GlobalMethod -import android.content.pm.PackageInfo -import com.coldmint.rust.pro.tool.AppSettings import android.content.Intent +import android.content.pm.PackageInfo import android.content.pm.PackageManager -import android.content.res.Resources -import com.google.android.material.snackbar.Snackbar -import android.os.* -import android.util.Log -import android.view.* -import android.widget.Toast +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.view.KeyEvent +import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuItem import androidx.appcompat.app.ActionBarDrawerToggle -import androidx.appcompat.widget.Toolbar import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.GravityCompat import androidx.core.view.isVisible @@ -33,16 +30,21 @@ import com.coldmint.rust.core.dataBean.template.TemplateInfo import com.coldmint.rust.core.debug.LogCat import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.interfaces.UnzipListener -import com.coldmint.rust.core.tool.* +import com.coldmint.rust.core.tool.AppOperator +import com.coldmint.rust.core.tool.DebugHelper +import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.web.AppUpdate import com.coldmint.rust.core.web.ServerConfiguration +import com.coldmint.rust.pro.base.BaseActivity 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.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.color.DynamicColors import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout import com.google.gson.Gson import com.gyf.immersionbar.ImmersionBar @@ -331,7 +333,6 @@ class MainActivity : BaseActivity() { intent.putExtra("type", "template") startActivity(intent) } - else -> { } } @@ -380,7 +381,7 @@ class MainActivity : BaseActivity() { menu.findItem(R.id.rust_api).setOnMenuItemClickListener { val thisIntent = Intent(this, BrowserActivity::class.java) - thisIntent.putExtra("link", "https://rustedwarfareapicode.top/") + thisIntent.putExtra("link", "https://git.coldmint.top/") thisIntent.putExtra("javaScriptEnabled", true) startActivity(thisIntent) false diff --git a/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt b/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt index 273c0fc..86bb51f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt +++ b/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt @@ -1,23 +1,22 @@ package com.coldmint.rust.pro +import android.annotation.SuppressLint +import android.app.Activity import android.app.Application import android.content.Context -import android.os.Environment -import android.util.Log +import android.content.pm.ActivityInfo +import android.os.Bundle import cat.ereza.customactivityoncrash.config.CaocConfig import com.coldmint.rust.core.debug.LogCat import com.coldmint.rust.core.debug.LogCatObserver -import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.pro.tool.AppSettings -import com.coldmint.rust.pro.tool.CompletionItemConverter -import com.coldmint.rust.pro.tool.GlobalMethod import com.google.android.material.color.DynamicColors import com.google.android.material.color.DynamicColorsOptions import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.ktx.Firebase import com.hjq.language.MultiLanguages import com.youth.banner.BuildConfig -import java.util.* + class RustApplication : Application() { @@ -38,7 +37,7 @@ class RustApplication : Application() { AppSettings.initAppSettings(this) //动态颜色 val options = DynamicColorsOptions.Builder() - .setPrecondition { activity, theme -> + .setPrecondition { _, _ -> AppSettings .getValue( AppSettings.Setting.DynamicColor, @@ -66,8 +65,24 @@ class RustApplication : Application() { .errorActivity(ErrorActivity::class.java) //default: null (default error activity) .apply() - MultiLanguages.init(this); - + MultiLanguages.init(this) + registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks { + @SuppressLint("SourceLockedOrientationActivity") + override fun onActivityCreated( + activity: Activity, + savedInstanceState: Bundle? + ) { +// android:screenOrientation="portrait" + //全局强制横屏 + activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } + override fun onActivityStarted(activity: Activity) {} + override fun onActivityResumed(activity: Activity) {} + override fun onActivityPaused(activity: Activity) {} + override fun onActivityStopped(activity: Activity) {} + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} + override fun onActivityDestroyed(activity: Activity) {} + }) } 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 9bec71a..2a778c6 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 @@ -1,9 +1,6 @@ package com.coldmint.rust.pro.base import android.content.Context -import android.content.res.Configuration -import androidx.appcompat.app.AppCompatActivity -import com.coldmint.rust.pro.tool.AppSettings import android.os.Bundle import android.view.LayoutInflater import android.view.MenuItem @@ -11,24 +8,15 @@ import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.EditText import android.widget.Toast -import androidx.appcompat.app.AppCompatDelegate -import androidx.appcompat.widget.Toolbar +import androidx.appcompat.app.AppCompatActivity import androidx.core.view.WindowCompat -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider import androidx.viewbinding.ViewBinding import com.coldmint.dialog.CoreDialog import com.coldmint.rust.pro.R import com.google.android.material.appbar.MaterialToolbar -import com.google.android.material.color.DynamicColors -import com.google.android.material.color.DynamicColorsOptions import com.google.android.material.snackbar.Snackbar import com.google.android.material.textfield.TextInputLayout -import com.google.firebase.analytics.FirebaseAnalytics -import com.google.firebase.analytics.ktx.analytics -import com.google.firebase.ktx.Firebase import com.hjq.language.MultiLanguages -import java.util.* /*主活动,所有活动都应该继承于此*/ abstract class BaseActivity : diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt b/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt index 56ec152..c699280 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt @@ -1,6 +1,5 @@ package com.coldmint.rust.pro.edit.autoComplete -import android.os.Bundle import com.coldmint.rust.core.SourceFile import com.coldmint.rust.core.database.code.CodeDao import com.coldmint.rust.core.database.code.CodeDataBase @@ -8,14 +7,11 @@ import com.coldmint.rust.core.database.file.FileDataBase import com.coldmint.rust.core.tool.DebugHelper import com.coldmint.rust.core.tool.LineParser import com.coldmint.rust.pro.edit.RustAnalyzer -import com.coldmint.rust.pro.edit.RustAutoComplete -import com.coldmint.rust.pro.edit.RustCompletionItem import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.CompletionItemConverter import io.github.rosemoe.sora.lang.completion.CompletionPublisher import io.github.rosemoe.sora.text.CharPosition import io.github.rosemoe.sora.text.ContentReference -import io.github.rosemoe.sora.widget.CodeEditor /** * 代码自动完成项目(来自数据库) diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt index e6b17b8..aade47b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt @@ -2,11 +2,10 @@ package com.coldmint.rust.pro.fragments import android.content.Intent import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import androidx.core.view.isVisible -import androidx.recyclerview.widget.LinearLayoutManager import com.bumptech.glide.Glide import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.dataBean.BannerItemDataBean @@ -24,13 +23,10 @@ import com.coldmint.rust.pro.databinding.FragmentRecommendedBinding import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.TextStyleMaker -import com.coldmint.rust.pro.ui.StableLinearLayoutManager -import com.google.android.material.color.DynamicColors +import com.coldmint.rust.pro.ui.ScrollLinearLayoutManager import com.youth.banner.adapter.BannerImageAdapter import com.youth.banner.holder.BannerImageHolder import com.youth.banner.indicator.CircleIndicator -import com.youth.banner.transformer.AlphaPageTransformer -import com.youth.banner.transformer.DepthPageTransformer class RecommendedFragment : BaseFragment() { @@ -233,10 +229,10 @@ class RecommendedFragment : BaseFragment() { } override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { - viewBinding.latestReleaseView.layoutManager = StableLinearLayoutManager(requireContext()) + viewBinding.latestReleaseView.layoutManager = ScrollLinearLayoutManager(requireContext()) viewBinding.soleRecommendedRecyclerView.layoutManager = - StableLinearLayoutManager(requireContext()) - viewBinding.randomRecommendedView.layoutManager = StableLinearLayoutManager(requireContext()) + ScrollLinearLayoutManager(requireContext()) + viewBinding.randomRecommendedView.layoutManager = ScrollLinearLayoutManager(requireContext()) loadRandomRecommended() viewBinding.changeRandomRecommended.setOnClickListener { loadRandomRecommended() diff --git a/app/src/main/java/com/coldmint/rust/pro/ui/ScrollLinearLayoutManager.kt b/app/src/main/java/com/coldmint/rust/pro/ui/ScrollLinearLayoutManager.kt new file mode 100644 index 0000000..ec9ecf7 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/ui/ScrollLinearLayoutManager.kt @@ -0,0 +1,25 @@ +package com.coldmint.rust.pro.ui + +import android.content.Context +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView + +/** + * 稳定的线性布局管理器 + */ +class ScrollLinearLayoutManager(val context: Context) : LinearLayoutManager(context) { + + /** + * 这里加了try catch防止奔溃 + */ + override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) { + try { + super.onLayoutChildren(recycler, state) + } catch (e: Exception) { + e.printStackTrace() + } + } + override fun canScrollVertically(): Boolean { + return false + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/code_tool_item.xml b/app/src/main/res/layout/code_tool_item.xml index 44091c0..ef272b9 100644 --- a/app/src/main/res/layout/code_tool_item.xml +++ b/app/src/main/res/layout/code_tool_item.xml @@ -3,13 +3,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"> -