From 37a9c0968f86b5ee72e798b7d0788181484497c6 Mon Sep 17 00:00:00 2001 From: muqing <1966944300@qq.com> Date: Fri, 17 Jan 2025 21:03:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(layout):=20=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E7=BB=84=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了 activity_web_mod_info.xml 和 fragment_insert_coins.xml 等布局文件 - 为平板设备添加了专门的布局文件 activity_web_mod_info.xml (横屏模式) - 调整了布局结构,优化了页面展示效果 - 移除了不必要的 android:fitsSystemWindows 属性- 更改了部分视图的布局参数,使其适应不同屏幕尺寸 --- app/build.gradle | 8 +- .../coldmint/rust/pro/WebModInfoActivity.kt | 121 ++++++++++++------ .../pro/adapters/ModPageDetailsAdapter.kt | 66 ++++++---- .../rust/pro/fragments/ModCommentsFragment.kt | 1 + .../java/com/coldmint/rust/pro/tool/Tools.kt | 19 +++ .../res/layout-land/activity_web_mod_info.xml | 71 ++++++++++ .../main/res/layout/activity_web_mod_info.xml | 3 +- .../main/res/layout/fragment_insert_coins.xml | 33 +++-- .../main/res/layout/fragment_mod_comments.xml | 32 +++-- 9 files changed, 258 insertions(+), 96 deletions(-) create mode 100644 app/src/main/java/com/coldmint/rust/pro/tool/Tools.kt create mode 100644 app/src/main/res/layout-land/activity_web_mod_info.xml diff --git a/app/build.gradle b/app/build.gradle index 674a292..cab3e25 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { minSdkVersion 23 targetSdkVersion 33 versionCode 28 - versionName "2.1.1 Test(2024-7-20)" + versionName "2.3.0 Test(2025-One)"//第一季度 One 第二季度 Two 第三季度 Three 第四季度 Four testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -180,8 +180,8 @@ dependencies { implementation 'com.google.android.flexbox:flexbox:3.0.0' // Android智能下拉刷新框架-SmartRefreshLayout - implementation 'io.github.scwang90:refresh-layout-kernel:2.1.0' //核心必须依赖 - implementation 'io.github.scwang90:refresh-header-classics:2.1.0' //经典刷新头 - implementation 'io.github.scwang90:refresh-footer-classics:2.1.0' //经典加载 + implementation 'io.github.scwang90:refresh-layout-kernel:2.1.0' //核心必须依赖 + implementation 'io.github.scwang90:refresh-header-classics:2.1.0' //经典刷新头 + implementation 'io.github.scwang90:refresh-footer-classics:2.1.0' //经典加载 } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt index 53f6610..b15d91b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt @@ -1,9 +1,11 @@ package com.coldmint.rust.pro +import android.annotation.SuppressLint import android.content.Intent import android.os.Bundle import android.os.Environment import android.view.* +import androidx.lifecycle.MutableLiveData import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.dataBean.AppUpdateData import com.coldmint.rust.core.tool.AppOperator @@ -15,8 +17,10 @@ import com.coldmint.rust.pro.adapters.ModPageDetailsAdapter import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.ActivityWebModInfoBinding import com.coldmint.rust.pro.databinding.LoadFileLayoutBinding +import com.coldmint.rust.pro.fragments.WebModDetailsFragment import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod +import com.coldmint.rust.pro.tool.Tools import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayoutMediator import com.google.gson.Gson @@ -29,8 +33,8 @@ class WebModInfoActivity : BaseActivity() { lateinit var tip: String val targetFile: File by lazy { val modFolderPath = AppSettings.getValue( - AppSettings.Setting.ModFolder, - Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + AppSettings.Setting.ModFolder, + Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" ) val modFolder = File(modFolderPath) if (!modFolder.exists()) { @@ -44,6 +48,10 @@ class WebModInfoActivity : BaseActivity() { } lateinit var adapter: ModPageDetailsAdapter + val modName: MutableLiveData by lazy { + MutableLiveData() + } + @SuppressLint("CommitTransaction") private fun initView() { setReturnButton() val activityIntent = intent @@ -64,27 +72,52 @@ class WebModInfoActivity : BaseActivity() { viewBinding.button.isEnabled = false viewBinding.button.text = getString(R.string.installated) } - adapter = ModPageDetailsAdapter(this, modId) - adapter.modName.observe(this) { + modName.observe(this) { title = it } + val webModDetailsFragment = WebModDetailsFragment(modId, modName) +// 检测是否处于平板模式 + if (Tools.isTabletMode(this)) { + adapter = ModPageDetailsAdapter(this, modId) + supportFragmentManager.beginTransaction() + .replace(R.id.fragment,webModDetailsFragment) + .commit() viewBinding.viewPager2.adapter = adapter - TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager2) { tab, i -> - tab.text = when (i) { - 0 -> { - getString(R.string.details) + TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager2) { tab, i -> + tab.text = when (i) { + 0 -> { + getString(R.string.insert_coins) + } + 1 -> { + getString(R.string.discussion) + }else -> { + getString(R.string.title) + } } - 1 -> { - getString(R.string.insert_coins) + }.attach() + } else { + adapter = ModPageDetailsAdapter(this, modId, webModDetailsFragment) + viewBinding.viewPager2.adapter = adapter + TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager2) { tab, i -> + tab.text = when (i) { + 0 -> { + getString(R.string.details) + } + + 1 -> { + getString(R.string.insert_coins) + } + + 2 -> { + getString(R.string.discussion) + } + + else -> { + getString(R.string.title) + } } - 2 -> { - getString(R.string.discussion) - } - else -> { - getString(R.string.title) - } - } - }.attach() + }.attach() + } viewBinding.button.setOnClickListener { val type = viewBinding.button.text val installation = getString(R.string.installation) @@ -111,25 +144,27 @@ class WebModInfoActivity : BaseActivity() { when (AppOperator.getNetworkType(this)) { AppOperator.NetWorkType.NetWorkType_Moble -> { val useMobileNetWork = - AppSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) + AppSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) if (useMobileNetWork) { downloadWork(fileLink) } else { CoreDialog(this).setTitle(R.string.using_mobile_networks) - .setMessage(R.string.using_mobile_networks_msg) - .setPositiveButton(R.string.only_one) { - downloadWork(fileLink) - }.setNegativeButton(R.string.always_allow) { - AppSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) - downloadWork(fileLink) - }.setNeutralButton(R.string.dialog_cancel) { + .setMessage(R.string.using_mobile_networks_msg) + .setPositiveButton(R.string.only_one) { + downloadWork(fileLink) + }.setNegativeButton(R.string.always_allow) { + AppSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) + downloadWork(fileLink) + }.setNeutralButton(R.string.dialog_cancel) { - }.show() + }.show() } } + AppOperator.NetWorkType.NetWorkType_Wifi -> { downloadWork(fileLink) } + else -> {} } @@ -143,14 +178,15 @@ class WebModInfoActivity : BaseActivity() { } + @SuppressLint("StringFormatInvalid") override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.report_item -> { if (token.isBlank()) { Snackbar.make( - viewBinding.button, - R.string.please_login_first, - Snackbar.LENGTH_SHORT + viewBinding.button, + R.string.please_login_first, + Snackbar.LENGTH_SHORT ).show() return true } @@ -165,29 +201,32 @@ class WebModInfoActivity : BaseActivity() { } else { //不能举报未公开的模组 Snackbar.make( - viewBinding.button, - R.string.unable_to_report, - Snackbar.LENGTH_SHORT + viewBinding.button, + R.string.unable_to_report, + Snackbar.LENGTH_SHORT ).show() } } + R.id.share_item -> { val link = AppSettings.getValue(AppSettings.Setting.ServerAddress, "") val updateData = AppSettings.getValue(AppSettings.Setting.UpdateData, "") var appUpdateLink = "" - if (!updateData.isNullOrBlank()) { + if (updateData.isNotBlank()) { val gson = Gson() val updateDataObj = gson.fromJson(updateData, AppUpdateData.Data::class.java) appUpdateLink = updateDataObj.link } + val s = String.format( - getString(R.string.share_mod_msg), - title, - link + "website/pages/modPage.php?&modId=" + modId, appUpdateLink + getString(R.string.share_mod_msg), + title, + link + "website/pages/modPage.php?&modId=" + modId, appUpdateLink ) AppOperator.shareText(this, getString(R.string.share_mod), s) } + R.id.update_record -> { GlobalMethod.showUpdateLog(this, modId) } @@ -215,7 +254,7 @@ class WebModInfoActivity : BaseActivity() { val numberFormat = NumberFormat.getNumberInstance() numberFormat.maximumFractionDigits = 2 val trueProgress = - numberFormat.format(bytesRead.toDouble() / contentLength.toDouble() * 100) + numberFormat.format(bytesRead.toDouble() / contentLength.toDouble() * 100) progress = trueProgress.toFloat().toInt() runOnUiThread { val progressTip = String.format(tip, progress) @@ -319,12 +358,12 @@ class WebModInfoActivity : BaseActivity() { */ fun gotoUserPage(userId: String) { val intent = Intent( - this@WebModInfoActivity, - UserHomePageActivity::class.java + this@WebModInfoActivity, + UserHomePageActivity::class.java ) intent.putExtra("userId", userId) startActivity( - intent + intent ) } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageDetailsAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageDetailsAdapter.kt index c378f72..ab21368 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageDetailsAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageDetailsAdapter.kt @@ -15,19 +15,18 @@ import com.coldmint.rust.pro.fragments.WebModDetailsFragment * 模组详情页面适配器 * @constructor */ -class ModPageDetailsAdapter(fragmentActivity: FragmentActivity, val modId: String) : - FragmentStateAdapter(fragmentActivity) { +class ModPageDetailsAdapter(fragmentActivity: FragmentActivity, val modId: String, var A: WebModDetailsFragment? = null) : + FragmentStateAdapter(fragmentActivity) { private lateinit var webModDetailsFragment: WebModDetailsFragment private lateinit var modCommentsFragment: ModCommentsFragment override fun getItemCount(): Int { - return 3 - } + if (A == null) { + return 2 + } else + return 3 - val modName: MutableLiveData by lazy { - MutableLiveData() } - /** * 获取下载链接 * @return String? @@ -55,25 +54,48 @@ class ModPageDetailsAdapter(fragmentActivity: FragmentActivity, val modId: Strin } override fun createFragment(position: Int): Fragment { - return when (position) { - 0 -> { - if (!this::webModDetailsFragment.isInitialized) { - webModDetailsFragment = WebModDetailsFragment(modId, modName) + if (A == null) { + return when (position) { + 0 -> { + InsertCoinsFragment(modId) } - webModDetailsFragment - } - 1 -> { - InsertCoinsFragment(modId) - } - 2 -> { - if (!this::modCommentsFragment.isInitialized) { - modCommentsFragment = ModCommentsFragment(modId) + + 1 -> { + if (!this::modCommentsFragment.isInitialized) { + modCommentsFragment = ModCommentsFragment(modId) + } + modCommentsFragment + }else -> { + NullFragment() } - modCommentsFragment } - else -> { - NullFragment() + + } else { + return when (position) { + 0 -> { + if (!this::webModDetailsFragment.isInitialized) { + webModDetailsFragment = A as WebModDetailsFragment + } + webModDetailsFragment + } + + 1 -> { + InsertCoinsFragment(modId) + } + + 2 -> { + if (!this::modCommentsFragment.isInitialized) { + modCommentsFragment = ModCommentsFragment(modId) + } + modCommentsFragment + }else -> { + NullFragment() + } } } +// +// else -> { +// NullFragment() +// } } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt index 58cf965..43cfd2b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt @@ -42,6 +42,7 @@ class ModCommentsFragment(val modId: String) : BaseFragment + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_web_mod_info.xml b/app/src/main/res/layout/activity_web_mod_info.xml index 0b6d0f1..99892ad 100644 --- a/app/src/main/res/layout/activity_web_mod_info.xml +++ b/app/src/main/res/layout/activity_web_mod_info.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true" tools:context=".WebModInfoActivity"> - + android:visibility="gone" /> - + android:layout_height="wrap_content"> + + + + + android:layout_height="wrap_content" + android:text="@string/no_content" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_mod_comments.xml b/app/src/main/res/layout/fragment_mod_comments.xml index 1576373..a3fb573 100644 --- a/app/src/main/res/layout/fragment_mod_comments.xml +++ b/app/src/main/res/layout/fragment_mod_comments.xml @@ -1,16 +1,16 @@ - + + android:layout_marginTop="8dp" + android:indeterminate="true" + android:visibility="invisible" /> - - + android:layout_height="wrap_content"> + + + - \ No newline at end of file + \ No newline at end of file