Skip to content

Commit

Permalink
Now you can refresh the readme.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
lings03 committed Jan 24, 2025
1 parent 0d7b5ed commit cb8d42e
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 271 deletions.
87 changes: 7 additions & 80 deletions app/src/main/kotlin/top/laoxin/modmanager/bean/ModBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Parcel
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import top.laoxin.modmanager.tools.LogTools

/**
* mod实体类
Expand Down Expand Up @@ -94,78 +95,6 @@ data class ModBean(
}
}

/* override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
val modBean = other as ModBean
if (name != modBean.name) return false
if (path != modBean.path) return false
//if (id != modBean.id) return false
if (isEncrypted != modBean.isEncrypted) return false
//if (isEnable != modBean.isEnable) return false
if (isZipFile != modBean.isZipFile) return false
if (version != modBean.version) return false
if (description != modBean.description) return false
if (author != modBean.author) return false
if (date != modBean.date) return false
if (icon != modBean.icon) return false
if (images != modBean.images) return false
if (modFiles != modBean.modFiles) return false
if (password != modBean.password) return false
if (readmePath != modBean.readmePath) return false
if (fileReadmePath != modBean.fileReadmePath) return false
if (gamePackageName != modBean.gamePackageName) return false
if (gameModPath != modBean.gameModPath) return false
if (modType != modBean.modType) return false
return true
}
override fun hashCode(): Int {
var result = name?.hashCode() ?: 0
result = 31 * result + (version?.hashCode() ?: 0)
result = 31 * result + (description?.hashCode() ?: 0)
result = 31 * result + (author?.hashCode() ?: 0)
result = 31 * result + date.hashCode()
result = 31 * result + (path?.hashCode() ?: 0)
result = 31 * result + (icon?.hashCode() ?: 0)
result = 31 * result + (images?.hashCode() ?: 0)
result = 31 * result + (modFiles?.hashCode() ?: 0)
// result = 31 * result + isEncrypted.hashCode()
result = 31 * result + (password?.hashCode() ?: 0)
result = 31 * result + (readmePath?.hashCode() ?: 0)
result = 31 * result + (fileReadmePath?.hashCode() ?: 0)
result = 31 * result + (gamePackageName?.hashCode() ?: 0)
result = 31 * result + (gameModPath?.hashCode() ?: 0)
result = 31 * result + (modType?.hashCode() ?: 0)
result = 31 * result + isEnable.hashCode()
result = 31 * result + isZipFile.hashCode()
return result
}*/

fun equalsIgnoreId(other: ModBean): Boolean {
if (this === other) return true
if (name != other.name) return false
if (version != other.version) return false
if (description != other.description) return false
if (author != other.author) return false
if (date != other.date) return false
if (path != other.path) return false
if (icon != other.icon) return false
if (images != other.images) return false
if (modFiles != other.modFiles) return false
if (isEncrypted != other.isEncrypted) return false
//if (password != other.password) return false
if (readmePath != other.readmePath) return false
if (fileReadmePath != other.fileReadmePath) return false
if (gamePackageName != other.gamePackageName) return false
if (gameModPath != other.gameModPath) return false
if (modType != other.modType) return false
//if (isEnable != other.isEnable) return false
if (isZipFile != other.isZipFile) return false

return true
}

fun isDelete(scanMods: List<ModBean>): ModBean? {
if (scanMods.none { it.path == path && it.name == name }) {
return this
Expand All @@ -180,7 +109,8 @@ data class ModBean(
if (mod.version != version ||
mod.description != description ||
mod.author != author ||
mod.date != date ||
// 日期不需要吧?
// mod.date != date ||
mod.icon != icon ||
mod.images != images ||
mod.modFiles != modFiles ||
Expand All @@ -190,7 +120,7 @@ data class ModBean(
mod.modType != modType ||
mod.isZipFile != isZipFile
) {
return this.copy(
var new = this.copy(
version = mod.version,
description = mod.description,
author = mod.author,
Expand All @@ -206,13 +136,10 @@ data class ModBean(
isZipFile = mod.isZipFile,
virtualPaths = mod.virtualPaths
)
LogTools.logRecord("更新前$this")
LogTools.logRecord("更新后$new")
return new
}

//if (mod.isEncrypted != isEncrypted) return true
//if (mod.password != password) return true
//if (mod.gamePackageName != gamePackageName) return true
//if (mod.isEnable != isEnable) return true

}
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ interface ModDao {
@Delete
suspend fun delete(modBean: ModBean)

// 通过id查询数据
@Query("SELECT * from mods WHERE id = :id")
suspend fun getModById(id: Int): ModBean

// 查询所有数据
@Query("SELECT * from mods ORDER BY date DESC")
fun getAll(): Flow<List<ModBean>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface ModRepository {
// 删除数据
suspend fun deleteMod(mod: ModBean)

// 通过id查询数据
suspend fun getModById(id: Int): ModBean

// 获取所有数据
fun getAllIModsStream(): Flow<List<ModBean>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class OfflineModsRepository(private val modDao: ModDao) : ModRepository {
modDao.update(mod)
}

override suspend fun getModById(id: Int): ModBean {
return modDao.getModById(id)
}


override suspend fun insertAll(mods: List<ModBean>) {
modDao.insertAll(mods)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/top/laoxin/modmanager/tools/ModTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object ModTools {
val MY_APP_PATH =
(ROOT_PATH + "/Android/data/" + (App.get().packageName ?: "")).toString() + "/"
val BACKUP_PATH = MY_APP_PATH + "backup/"
private val MODS_TEMP_PATH = MY_APP_PATH + "temp/"
val MODS_TEMP_PATH = MY_APP_PATH + "temp/"
val MODS_UNZIP_PATH = MY_APP_PATH + "temp/unzip/"
val MODS_ICON_PATH = MY_APP_PATH + "icon/"
val MODS_IMAGE_PATH = MY_APP_PATH + "images/"
Expand Down Expand Up @@ -238,7 +238,7 @@ object ModTools {
// 读取images文件输入流
if (bean.images != null) {
val images = mutableListOf<String>()
for (image in bean.images!!) {
for (image in bean.images) {
val imagePath = unZipPath + image
val file = File(imagePath)
val md5 = MD5Tools.calculateMD5(file.inputStream())
Expand All @@ -252,7 +252,7 @@ object ModTools {


// 读取readme文件
private fun readReadmeFile(unZipPath: String, modBean: ModBean): ModBean {
fun readReadmeFile(unZipPath: String, modBean: ModBean): ModBean {
// 判断是否存在readme文件
val infoMap = mutableMapOf<String, String>()
if (modBean.readmePath != null) {
Expand Down
168 changes: 0 additions & 168 deletions app/src/main/kotlin/top/laoxin/modmanager/ui/view/modView/Mod.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
package top.laoxin.modmanager.ui.view.modView

/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


import android.content.Context
import android.graphics.Bitmap
import android.util.Log
Expand Down Expand Up @@ -78,10 +61,6 @@ fun ModPage(viewModel: ModViewModel) {
val uiState by viewModel.uiState.collectAsState()

Box {
// UserTipsDialog(
// showDialog = uiState.showUserTipsDialog,
// setUserTipsDialog = viewModel::setUserTipsDialog
// )
DisEnableModsDialog(
showDialog = uiState.showDisEnableModsDialog,
mods = uiState.delEnableModsList,
Expand Down Expand Up @@ -134,49 +113,8 @@ fun ModPage(viewModel: ModViewModel) {
}
}
}


/* StoragePermissionDialog(
showDialog = uiState.openPermissionRequestDialog,
viewModel = viewModel
) { viewModel.setOpenPermissionRequestDialog(false) }*/
}


//@Composable
//fun UserTipsDialog(
// showDialog: Boolean,
// setUserTipsDialog: (Boolean) -> Unit
//) {
//
// if (showDialog) {
// val context = LocalContext.current
// AlertDialog(
// onDismissRequest = {
//
// }, // 空的 lambda 函数,表示点击对话框外的区域不会关闭对话框
// title = { Text(stringResource(id = R.string.dialog_info_title)) },
// text = { Text(stringResource(id = R.string.dialog_info_message)) },
// confirmButton = {
// TextButton(onClick = {
// setUserTipsDialog(false)
// }) {
// Text(stringResource(id = R.string.dialog_button_info_permission))
// }
// },
// dismissButton = {
// TextButton(onClick = {
// if (context is Activity) {
// context.finish()
// }
// }) {
// Text(stringResource(id = R.string.dialog_button_request_close))
// }
// }
// )
// }
//}

// 关闭mods提示框
@Composable
fun DisEnableModsDialog(
Expand Down Expand Up @@ -230,7 +168,6 @@ fun DisEnableModsDialog(
}
}


// 使用 Glide 加载 Bitmap,同时保持图片比例
suspend fun loadImageBitmapFromPath(
context: Context,
Expand All @@ -254,108 +191,6 @@ suspend fun loadImageBitmapFromPath(
}
}


///**
// * @param hint: 空字符时的提示
// * @param startIcon: 左侧图标; -1 则不显示
// * @param iconSpacing: 左侧图标与文字的距离; 相当于: drawablePadding
// */
//@Composable
//fun CustomEdit(
// text: String = "",
// onValueChange: (String) -> Unit,
// modifier: Modifier,
// hint: String = "请输入",
// @DrawableRes startIcon: Int = -1,
// iconSpacing: Dp = 6.dp,
// enabled: Boolean = true,
// readOnly: Boolean = false,
// textStyle: TextStyle = TextStyle.Default,
// keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
// visualTransformation: VisualTransformation = VisualTransformation.None,
// cursorBrush: Brush = SolidColor(MaterialTheme.colorScheme.primary),
// close: () -> Unit
//) {
// // 焦点, 用于控制是否显示 右侧叉号
// var hasFocus by remember { mutableStateOf(false) }
// val focusRequester = remember { FocusRequester() }
//
// BasicTextField(
// value = text,
// onValueChange = onValueChange,
// modifier = modifier
// .focusRequester(focusRequester)
// .onFocusChanged {
// if (!it.isFocused && hasFocus) {
// // 组件失去焦点
// close()
// }
// hasFocus = it.isFocused
// },
// singleLine = true,
// enabled = enabled,
// readOnly = readOnly,
// textStyle = textStyle,
// keyboardOptions = keyboardOptions,
// keyboardActions = KeyboardActions(onDone = { close() }),
// visualTransformation = visualTransformation,
// cursorBrush = cursorBrush,
// decorationBox = @Composable { innerTextField ->
// Row(
// modifier = Modifier.fillMaxWidth(),
// verticalAlignment = Alignment.CenterVertically
// ) {
// // -1 不显示 左侧Icon
// if (startIcon != -1) {
// Image(painter = painterResource(id = startIcon), contentDescription = null)
// Spacer(modifier = Modifier.width(iconSpacing))
// }
//
// Box(modifier = Modifier.weight(1f)) {
// // 当空字符时, 显示hint
// if (text.isEmpty())
// Text(text = hint, color = Color.Gray, style = textStyle)
//
// // 原本输入框的内容
// innerTextField()
// }
//
// // 存在焦点 且 有输入内容时. 显示叉号
// if (hasFocus && text.isNotEmpty()) {
// Log.d("CustomEdit", "CustomEdit:失去焦点 ")
//
// Icon(imageVector = Icons.Filled.Clear, // 清除图标
// contentDescription = null,
// tint = MaterialTheme.colorScheme.primaryContainer,
// // 点击就清空text
// modifier = Modifier.clickable {
// onValueChange.invoke("")
// })
// }
// Icon(
// imageVector = Icons.Filled.Search,
// contentDescription = null,
// tint = MaterialTheme.colorScheme.primaryContainer,
//
// modifier = Modifier
// .clickable {
// close()
// }
// .padding(start = 10.dp)
// )
// }
// }
// )
//
// LaunchedEffect(focusRequester) {
// focusRequester.requestFocus()
// }
//}


// 创建一个占据全屏的居中文本, 提示没有mod


// 创建一个全屏的加载动画
@Composable
fun Loading(
Expand All @@ -373,9 +208,6 @@ fun Loading(
style = MaterialTheme.typography.titleSmall
)
}
Box {

}
}


Expand Down
Loading

0 comments on commit cb8d42e

Please sign in to comment.