修复BUG,优化UI
This commit is contained in:
parent
290156a322
commit
f78d05f340
|
@ -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
|
||||||
|
@ -87,20 +84,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
*/
|
*/
|
||||||
fun initNav() {
|
fun initNav() {
|
||||||
appBarConfiguration = AppBarConfiguration(
|
appBarConfiguration = AppBarConfiguration(
|
||||||
setOf(R.id.community_item, R.id.mod_item, R.id.database_item, R.id.template_item),
|
setOf(R.id.community_item, R.id.mod_item, R.id.database_item, R.id.template_item),
|
||||||
viewBinding.drawerlayout
|
viewBinding.drawerlayout
|
||||||
)
|
)
|
||||||
val navController = findNavController(R.id.baseFragment)
|
val navController = findNavController(R.id.baseFragment)
|
||||||
navController.navInflater.inflate(R.navigation.main_nav).apply {
|
navController.navInflater.inflate(R.navigation.main_nav).apply {
|
||||||
val use =
|
val use =
|
||||||
AppSettings.getValue(AppSettings.Setting.UseTheCommunityAsTheLaunchPage, true)
|
AppSettings.getValue(AppSettings.Setting.UseTheCommunityAsTheLaunchPage, true)
|
||||||
this.setStartDestination(
|
this.setStartDestination(
|
||||||
if (use) {
|
if (use) {
|
||||||
viewBinding.mainButton.hide()
|
viewBinding.mainButton.hide()
|
||||||
R.id.community_item
|
R.id.community_item
|
||||||
} else {
|
} else {
|
||||||
R.id.mod_item
|
R.id.mod_item
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
navController.graph = this
|
navController.graph = this
|
||||||
}
|
}
|
||||||
|
@ -109,16 +106,14 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
viewBinding.navaiagtion.addHeaderView(headLayout.root)
|
viewBinding.navaiagtion.addHeaderView(headLayout.root)
|
||||||
//actionbar动画
|
//actionbar动画
|
||||||
val actionToggle = ActionBarDrawerToggle(
|
val actionToggle = ActionBarDrawerToggle(
|
||||||
this,
|
this,
|
||||||
viewBinding.drawerlayout,
|
viewBinding.drawerlayout,
|
||||||
viewBinding.toolbar,
|
viewBinding.toolbar,
|
||||||
R.string.app_name,
|
R.string.app_name,
|
||||||
R.string.app_name
|
R.string.app_name
|
||||||
)
|
)
|
||||||
viewBinding.drawerlayout.addDrawerListener(actionToggle)
|
viewBinding.drawerlayout.addDrawerListener(actionToggle)
|
||||||
actionToggle.syncState()
|
actionToggle.syncState()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,7 +159,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
//检查更新
|
//检查更新
|
||||||
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
|
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
|
||||||
val checkBetaUpdate =
|
val checkBetaUpdate =
|
||||||
AppSettings.getValue(AppSettings.Setting.CheckBetaUpdate, false)
|
AppSettings.getValue(AppSettings.Setting.CheckBetaUpdate, false)
|
||||||
var needShowDialog = false
|
var needShowDialog = false
|
||||||
if (data.versionNumber > packageInfo.versionCode) {
|
if (data.versionNumber > packageInfo.versionCode) {
|
||||||
if (data.isBeta) {
|
if (data.isBeta) {
|
||||||
|
@ -181,18 +176,18 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
//显示对话框
|
//显示对话框
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
val materialAlertDialogBuilder =
|
val materialAlertDialogBuilder =
|
||||||
MaterialAlertDialogBuilder(this).setTitle(data.title).setMessage(data.content)
|
MaterialAlertDialogBuilder(this).setTitle(data.title).setMessage(data.content)
|
||||||
if (data.forced) {
|
if (data.forced) {
|
||||||
//禁用点击空白关闭
|
//禁用点击空白关闭
|
||||||
materialAlertDialogBuilder.setCancelable(false)
|
materialAlertDialogBuilder.setCancelable(false)
|
||||||
} else {
|
} else {
|
||||||
materialAlertDialogBuilder.setNegativeButton(
|
materialAlertDialogBuilder.setNegativeButton(
|
||||||
R.string.dialog_cancel
|
R.string.dialog_cancel
|
||||||
) { i, i2 ->
|
) { i, i2 ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
materialAlertDialogBuilder.setPositiveButton(
|
materialAlertDialogBuilder.setPositiveButton(
|
||||||
R.string.downlod
|
R.string.downlod
|
||||||
) { i, i2 ->
|
) { i, i2 ->
|
||||||
AppOperator.useBrowserAccessWebPage(this, data.link)
|
AppOperator.useBrowserAccessWebPage(this, data.link)
|
||||||
}
|
}
|
||||||
|
@ -209,25 +204,25 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
if (!AppSettings.getValue(AppSettings.Setting.SetGameStorage, false)) {
|
if (!AppSettings.getValue(AppSettings.Setting.SetGameStorage, false)) {
|
||||||
try {
|
try {
|
||||||
val packageInfo = packageManager.getPackageInfo(
|
val packageInfo = packageManager.getPackageInfo(
|
||||||
GlobalMethod.DEFAULT_GAME_PACKAGE,
|
GlobalMethod.DEFAULT_GAME_PACKAGE,
|
||||||
PackageManager.GET_UNINSTALLED_PACKAGES
|
PackageManager.GET_UNINSTALLED_PACKAGES
|
||||||
)
|
)
|
||||||
val versionCode = packageInfo.versionCode
|
val versionCode = packageInfo.versionCode
|
||||||
//如果在1.15 p3及以上 (159)
|
//如果在1.15 p3及以上 (159)
|
||||||
if (versionCode >= 159) {
|
if (versionCode >= 159) {
|
||||||
MaterialAlertDialogBuilder(this).setTitle(R.string.game_configured)
|
MaterialAlertDialogBuilder(this).setTitle(R.string.game_configured)
|
||||||
.setMessage(R.string.unable_to_detect)
|
.setMessage(R.string.unable_to_detect)
|
||||||
.setPositiveButton(R.string.show_details) { i, i2 ->
|
.setPositiveButton(R.string.show_details) { i, i2 ->
|
||||||
startActivity(
|
startActivity(
|
||||||
Intent(
|
Intent(
|
||||||
this@MainActivity,
|
this@MainActivity,
|
||||||
GameCheckActivity::class.java
|
GameCheckActivity::class.java
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}.setNeutralButton(R.string.no_longer_prompt) { i, i2 ->
|
||||||
}.setNeutralButton(R.string.no_longer_prompt) { i, i2 ->
|
AppSettings.setValue(AppSettings.Setting.SetGameStorage, true)
|
||||||
AppSettings.setValue(AppSettings.Setting.SetGameStorage, true)
|
}.setNeutralButton(R.string.dialog_cancel) { i, i2 ->
|
||||||
}.setNeutralButton(R.string.dialog_cancel) { i, i2 ->
|
}.setCancelable(false).show()
|
||||||
}.setCancelable(false).show()
|
|
||||||
} else {
|
} else {
|
||||||
AppSettings.setValue(AppSettings.Setting.SetGameStorage, true)
|
AppSettings.setValue(AppSettings.Setting.SetGameStorage, true)
|
||||||
}
|
}
|
||||||
|
@ -243,9 +238,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
first = false
|
first = false
|
||||||
} else {
|
} else {
|
||||||
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 -> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,17 +359,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
|
|
||||||
menu.findItem(R.id.startGame).setOnMenuItemClickListener {
|
menu.findItem(R.id.startGame).setOnMenuItemClickListener {
|
||||||
val packName = AppSettings.getValue(
|
val packName = AppSettings.getValue(
|
||||||
AppSettings.Setting.GamePackage,
|
AppSettings.Setting.GamePackage,
|
||||||
GlobalMethod.DEFAULT_GAME_PACKAGE
|
GlobalMethod.DEFAULT_GAME_PACKAGE
|
||||||
)
|
)
|
||||||
if (AppOperator.isAppInstalled(this, packName)) {
|
if (AppOperator.isAppInstalled(this, packName)) {
|
||||||
AppOperator.openApp(this, packName)
|
AppOperator.openApp(this, packName)
|
||||||
} else {
|
} else {
|
||||||
viewBinding.drawerlayout.closeDrawer(GravityCompat.START)
|
viewBinding.drawerlayout.closeDrawer(GravityCompat.START)
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
R.string.no_game_installed,
|
R.string.no_game_installed,
|
||||||
Snackbar.LENGTH_SHORT
|
Snackbar.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
@ -398,17 +394,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
|
|
||||||
//激活暂时不可用
|
//激活暂时不可用
|
||||||
val longTime = AppSettings.getValue(
|
val longTime = AppSettings.getValue(
|
||||||
AppSettings.Setting.ExpirationTime,
|
AppSettings.Setting.ExpirationTime,
|
||||||
0.toLong()
|
0.toLong()
|
||||||
)
|
)
|
||||||
val loginStatus = AppSettings.getValue(
|
val loginStatus = AppSettings.getValue(
|
||||||
AppSettings.Setting.LoginStatus,
|
AppSettings.Setting.LoginStatus,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
val activationItem = menu.findItem(R.id.activation_item)
|
val activationItem = menu.findItem(R.id.activation_item)
|
||||||
if (loginStatus) {
|
if (loginStatus) {
|
||||||
val time = ServerConfiguration.toStringTime(
|
val time = ServerConfiguration.toStringTime(
|
||||||
longTime
|
longTime
|
||||||
)
|
)
|
||||||
if (time == ServerConfiguration.ForeverTime) {
|
if (time == ServerConfiguration.ForeverTime) {
|
||||||
activationItem.isVisible = false
|
activationItem.isVisible = false
|
||||||
|
@ -441,38 +437,38 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
val to = File(modDirectory + from.name)
|
val to = File(modDirectory + from.name)
|
||||||
if (FileOperator.copyFile(from, to)) {
|
if (FileOperator.copyFile(from, to)) {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
String.format(getString(R.string.import_complete), from.name),
|
String.format(getString(R.string.import_complete), from.name),
|
||||||
Snackbar.LENGTH_SHORT
|
Snackbar.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
String.format(getString(R.string.import_failed), from.name),
|
String.format(getString(R.string.import_failed), from.name),
|
||||||
Snackbar.LENGTH_SHORT
|
Snackbar.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
R.string.bad_file_type,
|
R.string.bad_file_type,
|
||||||
Snackbar.LENGTH_SHORT
|
Snackbar.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
} else if (requestCode == 2) {
|
} else if (requestCode == 2) {
|
||||||
if ("rp" == type) {
|
if ("rp" == type) {
|
||||||
val outputFolder = File(
|
val outputFolder = File(
|
||||||
AppSettings.getValue(
|
AppSettings.getValue(
|
||||||
AppSettings.Setting.TemplateDirectory,
|
AppSettings.Setting.TemplateDirectory,
|
||||||
this.filesDir.absolutePath + "/template/"
|
this.filesDir.absolutePath + "/template/"
|
||||||
) + LocalTemplatePackage.getAbsoluteFileName(from)
|
) + LocalTemplatePackage.getAbsoluteFileName(from)
|
||||||
)
|
)
|
||||||
importTemplate(from, outputFolder)
|
importTemplate(from, outputFolder)
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
R.string.bad_file_type,
|
R.string.bad_file_type,
|
||||||
Snackbar.LENGTH_SHORT
|
Snackbar.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,13 +488,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
if (templateDirectory.exists()) {
|
if (templateDirectory.exists()) {
|
||||||
val gson = Gson()
|
val gson = Gson()
|
||||||
val newInfoData =
|
val newInfoData =
|
||||||
compressionManager.readEntry(formFile, LocalTemplatePackage.INFONAME)
|
compressionManager.readEntry(formFile, LocalTemplatePackage.INFONAME)
|
||||||
if (newInfoData == null) {
|
if (newInfoData == null) {
|
||||||
handler.post {
|
handler.post {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
getString(R.string.import_failed2),
|
getString(R.string.import_failed2),
|
||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
return@Runnable
|
return@Runnable
|
||||||
|
@ -509,23 +505,23 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
if (oldInfo == null) {
|
if (oldInfo == null) {
|
||||||
handler.post {
|
handler.post {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
R.string.import_failed2,
|
R.string.import_failed2,
|
||||||
Snackbar.LENGTH_SHORT
|
Snackbar.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
return@Runnable
|
return@Runnable
|
||||||
}
|
}
|
||||||
val thisAppVersion =
|
val thisAppVersion =
|
||||||
AppOperator.getAppVersionNum(this, this.packageName)
|
AppOperator.getAppVersionNum(this, this.packageName)
|
||||||
if (newInfo.versionNum > thisAppVersion) {
|
if (newInfo.versionNum > thisAppVersion) {
|
||||||
handler.post {
|
handler.post {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
String.format(
|
String.format(
|
||||||
getString(R.string.app_version_error),
|
getString(R.string.app_version_error),
|
||||||
formFile.name
|
formFile.name
|
||||||
), Snackbar.LENGTH_LONG
|
), Snackbar.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
return@Runnable
|
return@Runnable
|
||||||
|
@ -533,10 +529,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
if (newInfo.versionNum < oldInfo.versionNum) {
|
if (newInfo.versionNum < oldInfo.versionNum) {
|
||||||
handler.post {
|
handler.post {
|
||||||
MaterialAlertDialogBuilder(this).setTitle(oldInfo.name).setMessage(
|
MaterialAlertDialogBuilder(this).setTitle(oldInfo.name).setMessage(
|
||||||
String.format(
|
String.format(
|
||||||
getString(R.string.covers_the_import),
|
getString(R.string.covers_the_import),
|
||||||
newInfo.versionName, oldInfo.versionName
|
newInfo.versionName, oldInfo.versionName
|
||||||
)
|
)
|
||||||
).setPositiveButton(R.string.dialog_ok) { i, i2 ->
|
).setPositiveButton(R.string.dialog_ok) { i, i2 ->
|
||||||
FileOperator.delete_files(templateDirectory)
|
FileOperator.delete_files(templateDirectory)
|
||||||
importTemplate(formFile, templateDirectory)
|
importTemplate(formFile, templateDirectory)
|
||||||
|
@ -554,9 +550,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
if (newInfo == null) {
|
if (newInfo == null) {
|
||||||
handler.post {
|
handler.post {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
getString(R.string.import_failed2),
|
getString(R.string.import_failed2),
|
||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
return@Runnable
|
return@Runnable
|
||||||
|
@ -564,15 +560,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
val jsonObject = JSONObject(newInfo)
|
val jsonObject = JSONObject(newInfo)
|
||||||
val appVersion = jsonObject.getInt("appVersionNum")
|
val appVersion = jsonObject.getInt("appVersionNum")
|
||||||
val thisAppVersion =
|
val thisAppVersion =
|
||||||
AppOperator.getAppVersionNum(this, this.packageName)
|
AppOperator.getAppVersionNum(this, this.packageName)
|
||||||
if (appVersion > thisAppVersion) {
|
if (appVersion > thisAppVersion) {
|
||||||
handler.post {
|
handler.post {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
viewBinding.mainButton,
|
viewBinding.mainButton,
|
||||||
String.format(
|
String.format(
|
||||||
getString(R.string.app_version_error),
|
getString(R.string.app_version_error),
|
||||||
formFile.name
|
formFile.name
|
||||||
), Snackbar.LENGTH_LONG
|
), Snackbar.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
return@Runnable
|
return@Runnable
|
||||||
|
@ -581,51 +577,61 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
compressionManager.unzip(
|
compressionManager.unzip(
|
||||||
formFile,
|
formFile,
|
||||||
templateDirectory,
|
templateDirectory,
|
||||||
object : UnzipListener {
|
object : UnzipListener {
|
||||||
override fun whenUnzipFile(zipEntry: ZipEntry, file: File): Boolean {
|
override fun whenUnzipFile(zipEntry: ZipEntry, file: File): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun whenUnzipFolder(zipEntry: ZipEntry, folder: File): Boolean {
|
override fun whenUnzipFolder(zipEntry: ZipEntry, folder: File): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun whenUnzipComplete(result: Boolean) {
|
override fun whenUnzipComplete(result: Boolean) {
|
||||||
handler.post {
|
|
||||||
handler.post {
|
handler.post {
|
||||||
Snackbar.make(
|
handler.post {
|
||||||
viewBinding.mainButton,
|
Snackbar.make(
|
||||||
String.format(
|
viewBinding.mainButton,
|
||||||
getString(R.string.import_complete),
|
String.format(
|
||||||
formFile.name
|
getString(R.string.import_complete),
|
||||||
), Snackbar.LENGTH_LONG
|
formFile.name
|
||||||
).show()
|
), Snackbar.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
val navController = findNavController(R.id.baseFragment)
|
||||||
|
//判断是否在第一个导航 社区或者仓库
|
||||||
|
if (navController.currentDestination?.id == navController.graph.startDestinationId) {
|
||||||
|
MaterialAlertDialogBuilder(this).setTitle(R.string.dialog_close).setMessage(
|
||||||
|
String.format(
|
||||||
|
getString(R.string.exit_tip),
|
||||||
|
getString(R.string.app_name)
|
||||||
|
)
|
||||||
|
).setPositiveButton(R.string.dialog_ok) { _, _ ->
|
||||||
|
super.onBackPressed()
|
||||||
|
}.setNegativeButton(R.string.dialog_cancel) { _, _ ->
|
||||||
|
}.show()
|
||||||
|
} else {
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
|
||||||
MaterialAlertDialogBuilder(this).setTitle(R.string.dialog_close).setMessage(
|
|
||||||
String.format(
|
|
||||||
getString(R.string.exit_tip),
|
|
||||||
getString(R.string.app_name)
|
|
||||||
)
|
|
||||||
).setPositiveButton(R.string.dialog_ok) { i, i2 ->
|
|
||||||
finish()
|
|
||||||
}.setNegativeButton(R.string.dialog_cancel) { i, i2 ->
|
|
||||||
}.show()
|
|
||||||
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) {
|
||||||
|
@ -660,8 +668,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
val headIcon = it.data.headIcon
|
val headIcon = it.data.headIcon
|
||||||
if (headIcon != null) {
|
if (headIcon != null) {
|
||||||
Glide.with(this).load(ServerConfiguration.getRealLink(headIcon))
|
Glide.with(this).load(ServerConfiguration.getRealLink(headIcon))
|
||||||
.apply(GlobalMethod.getRequestOptions(true, !it.data.activation))
|
.apply(GlobalMethod.getRequestOptions(true, !it.data.activation))
|
||||||
.into(headLayout.imageView)
|
.into(headLayout.imageView)
|
||||||
}
|
}
|
||||||
val account = it.data.account
|
val account = it.data.account
|
||||||
headLayout.imageView.setOnClickListener {
|
headLayout.imageView.setOnClickListener {
|
||||||
|
@ -679,10 +687,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
headLayout.emailView.text = ""
|
headLayout.emailView.text = ""
|
||||||
headLayout.imageView.setOnClickListener {
|
headLayout.imageView.setOnClickListener {
|
||||||
startActivity(
|
startActivity(
|
||||||
Intent(
|
Intent(
|
||||||
this,
|
this,
|
||||||
LoginActivity::class.java
|
LoginActivity::class.java
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -700,10 +708,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
if (it) {
|
if (it) {
|
||||||
//显示签名错误
|
//显示签名错误
|
||||||
CoreDialog(this).setTitle(R.string.sign_error)
|
CoreDialog(this).setTitle(R.string.sign_error)
|
||||||
.setMessage(R.string.sign_error_message).setCancelable(false)
|
.setMessage(R.string.sign_error_message).setCancelable(false)
|
||||||
.setPositiveButton(R.string.dialog_close) {
|
.setPositiveButton(R.string.dialog_close) {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,16 +723,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
startViewModel.verifyErrorMsgLiveData.observe(this) {
|
startViewModel.verifyErrorMsgLiveData.observe(this) {
|
||||||
if (it.isNotBlank()) {
|
if (it.isNotBlank()) {
|
||||||
CoreDialog(this).setTitle(R.string.login).setMessage(it)
|
CoreDialog(this).setTitle(R.string.login).setMessage(it)
|
||||||
.setCancelable(false).setPositiveButton(R.string.login) {
|
.setCancelable(false).setPositiveButton(R.string.login) {
|
||||||
startActivity(
|
startActivity(
|
||||||
Intent(
|
Intent(
|
||||||
this,
|
this,
|
||||||
LoginActivity::class.java
|
LoginActivity::class.java
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}.setNegativeButton(R.string.close) {
|
||||||
}.setNegativeButton(R.string.close) {
|
finish()
|
||||||
finish()
|
}.show()
|
||||||
}.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,21 +743,21 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||||
if (canUseView) {
|
if (canUseView) {
|
||||||
oldLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en")
|
oldLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en")
|
||||||
oldDynamicColor = AppSettings.getValue(
|
oldDynamicColor = AppSettings.getValue(
|
||||||
AppSettings.Setting.DynamicColor,
|
AppSettings.Setting.DynamicColor,
|
||||||
DynamicColors.isDynamicColorAvailable()
|
DynamicColors.isDynamicColorAvailable()
|
||||||
);
|
)
|
||||||
useToolbarSetSupportActionBar()
|
useToolbarSetSupportActionBar()
|
||||||
initNav()
|
initNav()
|
||||||
observeStartViewModel()
|
observeStartViewModel()
|
||||||
//偏移fab
|
//偏移fab
|
||||||
if (ImmersionBar.hasNavigationBar(this)) {
|
if (ImmersionBar.hasNavigationBar(this)) {
|
||||||
val layoutParams =
|
val layoutParams =
|
||||||
viewBinding.mainButton.layoutParams as CoordinatorLayout.LayoutParams
|
viewBinding.mainButton.layoutParams as CoordinatorLayout.LayoutParams
|
||||||
layoutParams.setMargins(
|
layoutParams.setMargins(
|
||||||
GlobalMethod.dp2px(16),
|
GlobalMethod.dp2px(16),
|
||||||
GlobalMethod.dp2px(16),
|
GlobalMethod.dp2px(16),
|
||||||
GlobalMethod.dp2px(16),
|
GlobalMethod.dp2px(16),
|
||||||
ImmersionBar.getNavigationBarHeight(this) + GlobalMethod.dp2px(16)
|
ImmersionBar.getNavigationBarHeight(this) + GlobalMethod.dp2px(16)
|
||||||
)
|
)
|
||||||
DebugHelper.printLog("导航适配", "已调整fab按钮的位置。")
|
DebugHelper.printLog("导航适配", "已调整fab按钮的位置。")
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user