修复BUG,优化UI

This commit is contained in:
muqing 2024-02-11 15:51:00 +08:00
parent 290156a322
commit f78d05f340
5 changed files with 172 additions and 182 deletions

View File

@ -7,7 +7,6 @@ import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.view.KeyEvent
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -18,7 +17,6 @@ import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController import androidx.navigation.ui.setupWithNavController
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
@ -53,7 +51,6 @@ import java.io.File
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
class MainActivity : BaseActivity<ActivityMainBinding>() { class MainActivity : BaseActivity<ActivityMainBinding>() {
private lateinit var appBarConfiguration: AppBarConfiguration private lateinit var appBarConfiguration: AppBarConfiguration
@ -117,8 +114,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
) )
viewBinding.drawerlayout.addDrawerListener(actionToggle) viewBinding.drawerlayout.addDrawerListener(actionToggle)
actionToggle.syncState() actionToggle.syncState()
} }
/** /**
@ -245,7 +240,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val newDynamicColor = AppSettings.getValue( val newDynamicColor = AppSettings.getValue(
AppSettings.Setting.DynamicColor, AppSettings.Setting.DynamicColor,
DynamicColors.isDynamicColorAvailable() DynamicColors.isDynamicColorAvailable()
); )
if (oldDynamicColor != newDynamicColor) { if (oldDynamicColor != newDynamicColor) {
recreate() recreate()
return return
@ -333,6 +328,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
intent.putExtra("type", "template") intent.putExtra("type", "template")
startActivity(intent) startActivity(intent)
} }
else -> { else -> {
} }
} }
@ -611,21 +607,31 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}).start() }).start()
} }
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) { override fun onBackPressed() {
val navController = findNavController(R.id.baseFragment)
//判断是否在第一个导航 社区或者仓库
if (navController.currentDestination?.id == navController.graph.startDestinationId) {
MaterialAlertDialogBuilder(this).setTitle(R.string.dialog_close).setMessage( MaterialAlertDialogBuilder(this).setTitle(R.string.dialog_close).setMessage(
String.format( String.format(
getString(R.string.exit_tip), getString(R.string.exit_tip),
getString(R.string.app_name) getString(R.string.app_name)
) )
).setPositiveButton(R.string.dialog_ok) { i, i2 -> ).setPositiveButton(R.string.dialog_ok) { _, _ ->
finish() super.onBackPressed()
}.setNegativeButton(R.string.dialog_cancel) { i, i2 -> }.setNegativeButton(R.string.dialog_cancel) { _, _ ->
}.show() }.show()
} else {
super.onBackPressed()
}
}
/*
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
return true return true
} }
return super.onKeyDown(keyCode, event) return super.onKeyDown(keyCode, event)
} }*/
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater val inflater = menuInflater
@ -633,11 +639,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
return true return true
} }
/*不知道干什么的代码
override fun onSupportNavigateUp(): Boolean { override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.baseFragment) val navController = findNavController(R.id.baseFragment)
return navController.navigateUp(appBarConfiguration) return navController.navigateUp(appBarConfiguration)
|| super.onSupportNavigateUp() || super.onSupportNavigateUp()
} }
*/
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == R.id.search) { if (item.itemId == R.id.search) {
@ -737,7 +745,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
oldDynamicColor = AppSettings.getValue( oldDynamicColor = AppSettings.getValue(
AppSettings.Setting.DynamicColor, AppSettings.Setting.DynamicColor,
DynamicColors.isDynamicColorAvailable() DynamicColors.isDynamicColorAvailable()
); )
useToolbarSetSupportActionBar() useToolbarSetSupportActionBar()
initNav() initNav()
observeStartViewModel() observeStartViewModel()

View File

@ -1,21 +1,12 @@
package com.coldmint.rust.pro package com.coldmint.rust.pro
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.ActivityOptions
import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.graphics.Shader
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.drawToBitmap
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.coldmint.dialog.CoreDialog import com.coldmint.dialog.CoreDialog
@ -31,13 +22,12 @@ import com.coldmint.rust.pro.dialog.CommentDialog
import com.coldmint.rust.pro.tool.AnimUtil import com.coldmint.rust.pro.tool.AnimUtil
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.GlobalMethod
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.CollapsingToolbarLayout import com.google.android.material.appbar.CollapsingToolbarLayout
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import com.gyf.immersionbar.ktx.immersionBar import kotlin.math.abs
class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() { class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
@ -180,14 +170,14 @@ class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
} }
userName = spaceInfoData.data.userName userName = spaceInfoData.data.userName
viewBinding.appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset -> viewBinding.appBar.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
viewBinding.toolbar.title = viewBinding.toolbar.title =
if ((Math.abs(verticalOffset) >= appBarLayout.totalScrollRange)) { if ((abs(verticalOffset) >= appBarLayout.totalScrollRange)) {
spaceInfoData.data.userName spaceInfoData.data.userName
} else { } else {
"" ""
} }
}) }
viewBinding.nameView.text = spaceInfoData.data.userName viewBinding.nameView.text = spaceInfoData.data.userName
viewBinding.describeView.text = viewBinding.describeView.text =
spaceInfoData.data.introduce ?: getString(R.string.defaultIntroduced) spaceInfoData.data.introduce ?: getString(R.string.defaultIntroduced)
@ -208,8 +198,7 @@ class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
.into(viewBinding.genderView) .into(viewBinding.genderView)
} }
val permission = spaceInfoData.data.permission when (spaceInfoData.data.permission) {
when (permission) {
1 -> { 1 -> {
viewBinding.cardView.isVisible = true viewBinding.cardView.isVisible = true
viewBinding.cardView.setCardBackgroundColor(Color.parseColor("#f47920")) viewBinding.cardView.setCardBackgroundColor(Color.parseColor("#f47920"))
@ -311,9 +300,8 @@ class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
viewBinding.tabLayout.addOnTabSelectedListener(object : viewBinding.tabLayout.addOnTabSelectedListener(object :
TabLayout.OnTabSelectedListener { TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) { override fun onTabSelected(tab: TabLayout.Tab?) {
val finalTab = tab if (tab != null) {
if (finalTab != null) { val tiltle = tab.text
val tiltle = finalTab.text
val dynamic = getString(R.string.dynamic) val dynamic = getString(R.string.dynamic)
if (dynamic == tiltle && userId == account) { if (dynamic == tiltle && userId == account) {
viewBinding.fab.show() viewBinding.fab.show()

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerlayout" android:id="@+id/drawerlayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:fitsSystemWindows="false" android:fitsSystemWindows="true"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
@ -27,7 +28,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:visibility="gone"> android:visibility="gone">
<com.google.android.material.tabs.TabItem <com.google.android.material.tabs.TabItem
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -50,8 +50,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:defaultNavHost="true" app:defaultNavHost="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" /> app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/mainButton" android:id="@+id/mainButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -63,7 +61,6 @@
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
android:src="@drawable/add" /> android:src="@drawable/add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView <com.google.android.material.navigation.NavigationView

View File

@ -109,10 +109,9 @@
android:id="@+id/recyclerView" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginHorizontal="16dp" android:paddingHorizontal="6dp"
android:background="?android:colorBackground" android:background="?android:colorBackground"
android:paddingTop="16dp" android:paddingTop="6dp"
android:visibility="gone" android:visibility="gone"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" /> app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -16,8 +16,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:windowBackground"> android:background="?android:windowBackground">
<com.google.android.material.appbar.CollapsingToolbarLayout <com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -278,7 +276,7 @@
android:id="@+id/fab" android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|right" android:layout_gravity="bottom|end"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/add" android:src="@drawable/add"
android:visibility="gone" /> android:visibility="gone" />