fix: 修复UI优化中的文件修改问题

- 添加遗漏的UI优化文件到git提交
- 修复文件换行符警告问题
- 确保所有修改已正确提交

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ddshi 2025-10-27 15:29:32 +08:00
parent 709e2ba044
commit adbf5b4a05
11 changed files with 108 additions and 64 deletions

View File

@ -30,7 +30,8 @@
"Bash(dir:*)",
"Bash(copy:*)",
"Bash(.gradlew:*)",
"Bash(gradlew.bat assembleDebug:*)"
"Bash(gradlew.bat assembleDebug:*)",
"Bash(mv:*)"
],
"deny": [],
"ask": []

View File

@ -6,9 +6,12 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import android.util.Log
import com.chick_mood.data.model.MoodRecord
import com.chick_mood.utils.MoodDescriptionGenerator
import com.chick_mood.utils.FontUtils
import com.daodaoshi.chick_mood.databinding.ItemMoodCardBinding
import com.daodaoshi.chick_mood.ImageUtils
/**
* 心情卡片适配器
@ -60,40 +63,34 @@ class MoodCardAdapter(
)
binding.tvMoodDescription.text = moodDescription
// 应用阿里妈妈数黑体字体到心情文案
FontUtils.applyAlimamaShuHeiBold(binding.tvMoodDescription, binding.root.context)
// 设置收藏状态
updateFavoriteIcon(record.isFavorite)
// 处理文本和图片内容的显示逻辑
// 处理文本和图片内容的显示逻辑 - 使用固定布局左侧100x100dp配图 + 右侧自适应文本
val hasText = !record.textContent.isNullOrEmpty()
val hasImage = !record.imagePath.isNullOrEmpty()
if (hasText && hasImage) {
// 有图有文:图片在左,文本在右
// 有图有文:图片在左(100x100dp),文本在右(自适应)
binding.ivImage.visibility = View.VISIBLE
binding.tvTextContent.visibility = View.VISIBLE
binding.llMainContent.orientation = LinearLayout.HORIZONTAL
binding.ivImage.layoutParams = LinearLayout.LayoutParams(80, 80).apply {
marginEnd = 12
}
binding.tvTextContent.text = record.textContent
// TODO: 加载真实图片
binding.ivImage.setImageResource(com.daodaoshi.chick_mood.R.drawable.placeholder_background)
// 加载真实图片
Log.d("MoodCardAdapter", "Loading image path: ${record.imagePath}")
ImageUtils.loadImage(binding.ivImage, record.imagePath)
} else if (hasImage && !hasText) {
// 有图无文:图片居中显示
// 有图无文:图片在左(100x100dp),右侧空白
binding.ivImage.visibility = View.VISIBLE
binding.tvTextContent.visibility = View.GONE
binding.llMainContent.orientation = LinearLayout.VERTICAL
binding.llMainContent.gravity = android.view.Gravity.CENTER
binding.ivImage.layoutParams = LinearLayout.LayoutParams(120, 120).apply {
marginEnd = 0
}
// TODO: 加载真实图片
binding.ivImage.setImageResource(com.daodaoshi.chick_mood.R.drawable.placeholder_background)
// 加载真实图片
ImageUtils.loadImage(binding.ivImage, record.imagePath)
} else if (hasText && !hasImage) {
// 无图有文:文本占满整个内容区域
// 无图有文:左侧空白,文本在右(占满右侧)
binding.ivImage.visibility = View.GONE
binding.tvTextContent.visibility = View.VISIBLE
binding.llMainContent.orientation = LinearLayout.VERTICAL
binding.tvTextContent.text = record.textContent
} else {
// 无图无文:隐藏内容区域

View File

@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.chick_mood.data.database.SimpleDatabaseManager
import com.chick_mood.data.model.Emotion
import com.chick_mood.data.model.MoodRecord
import com.chick_mood.utils.FontUtils
import com.chick_mood.utils.EmotionResourceManager
import com.daodaoshi.chick_mood.ImageUtils
import kotlinx.coroutines.CoroutineScope
@ -97,6 +98,9 @@ class DetailActivity : AppCompatActivity() {
moodValueText.text = record.moodIntensity.toString()
moodText.text = generateMoodText(record.moodIntensity, record.emotion)
// 应用阿里妈妈数黑体字体到心情文案
FontUtils.applyAlimamaShuHeiBold(moodText, this)
// 设置图片内容(如果有)
if (record.imagePath != null) {
imageContent.visibility = View.VISIBLE

View File

@ -16,6 +16,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.chick_mood.data.database.SimpleDatabaseManager
import com.chick_mood.data.model.Emotion
import com.chick_mood.data.model.MoodRecord
import com.chick_mood.utils.FontUtils
import com.chick_mood.utils.EmotionResourceManager
import com.daodaoshi.chick_mood.ImageUtils
import kotlinx.coroutines.CoroutineScope
@ -258,6 +259,9 @@ class EditActivity : AppCompatActivity() {
moodValueText.text = record.moodIntensity.toString()
moodText.text = generateMoodText(record.moodIntensity, record.emotion)
// 应用阿里妈妈数黑体字体到心情文案
FontUtils.applyAlimamaShuHeiBold(moodText, this)
// 设置文本内容
textInput.setText(record.textContent ?: "")
updateCharCount()

View File

@ -6,6 +6,7 @@ import android.graphics.BitmapFactory
import android.net.Uri
import android.provider.MediaStore
import android.util.Log
import android.widget.ImageView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
@ -66,6 +67,34 @@ object ImageUtils {
}
}
/**
* 从文件路径加载图片到ImageView简化版本
*/
fun loadImage(imageView: ImageView, imagePath: String?) {
if (!imagePath.isNullOrEmpty()) {
imageView.setImageResource(com.daodaoshi.chick_mood.R.drawable.placeholder_background)
return
}
try {
val file = File(imagePath)
if (file.exists()) {
val bitmap = BitmapFactory.decodeFile(file.absolutePath)
if (bitmap != null) {
imageView.setImageBitmap(bitmap)
} else {
imageView.setImageResource(com.daodaoshi.chick_mood.R.drawable.placeholder_background)
}
} else {
Log.w(TAG, "图片文件不存在: $imagePath")
imageView.setImageResource(com.daodaoshi.chick_mood.R.drawable.placeholder_background)
}
} catch (e: Exception) {
Log.e(TAG, "加载图片失败", e)
imageView.setImageResource(com.daodaoshi.chick_mood.R.drawable.placeholder_background)
}
}
/**
* 从文件路径加载Bitmap
*/

View File

@ -23,6 +23,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import com.chick_mood.utils.MoodDescriptionGenerator
import com.chick_mood.utils.FontUtils
/**
* 简化的首页Activity - 主要用于展示历史心情记录和创建新记录的入口
@ -243,6 +244,9 @@ class MainActivitySimple : AppCompatActivity() {
binding.tvWeekday.text = weekdayText
binding.tvTime.text = time
// 应用阿里妈妈数黑体字体
FontUtils.applyAlimamaShuHeiBold(binding.tvWeekday, this)
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -91,7 +91,6 @@
android:id="@+id/mood_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="完全无法控制 开心"
android:textSize="18sp"
android:textColor="@color/text_secondary" />

View File

@ -89,7 +89,6 @@
android:id="@+id/mood_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="完全无法控制 开心"
android:textSize="18sp"
android:textColor="@color/text_secondary" />

View File

@ -164,6 +164,8 @@
android:layout_marginBottom="24dp"
android:elevation="4dp"
android:stateListAnimator="@null"
android:drawableStart="@drawable/ic_add_mood"
android:drawablePadding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"

View File

@ -4,77 +4,82 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="12dp"
app:cardElevation="2dp"
app:cardBackgroundColor="@color/white">
android:layout_margin="4dp"
app:cardCornerRadius="16dp"
app:cardElevation="3dp"
app:cardBackgroundColor="@color/white"
android:foreground="@drawable/card_selector">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
android:layout_height="wrap_content"
android:padding="20dp">
<!-- 心情文案 - 左上角 -->
<!-- 顶部区域:心情文案标题 + 查看详情按钮 -->
<TextView
android:id="@+id/tv_mood_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/text_primary"
android:maxLines="2"
android:ellipsize="end"
android:layout_marginEnd="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/btn_detail"
tools:text="完全无法控制 开心" />
tools:text="有些 开心" />
<!-- 查看详情按钮 - 右上角 -->
<ImageView
<!-- 查看详情按钮 - 右上角,橙色 -->
<TextView
android:id="@+id/btn_detail"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_more_info"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/text_secondary"
android:padding="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查看详情"
android:textSize="13sp"
android:textColor="@color/white"
android:textStyle="bold"
android:background="@drawable/bg_detail_button"
android:paddingHorizontal="14dp"
android:paddingVertical="8dp"
android:clickable="true"
android:focusable="true"
android:contentDescription="查看详情"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<!-- 主要内容区域 -->
<!-- 中间内容区域:固定尺寸,左侧配图 + 右侧文本 -->
<LinearLayout
android:id="@+id/ll_main_content"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="8dp"
android:layout_height="100dp"
android:layout_marginTop="16dp"
android:orientation="horizontal"
android:gravity="top"
app:layout_constraintTop_toBottomOf="@id/tv_mood_description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<!-- 左侧图片区域 -->
<!-- 左侧图片区域 - 1:1比例100x100dp -->
<ImageView
android:id="@+id/iv_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginEnd="12dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginEnd="16dp"
android:scaleType="centerCrop"
android:visibility="gone"
android:background="@drawable/placeholder_background"
android:contentDescription="心情图" />
android:background="@drawable/shape_image_background"
android:contentDescription="心情图" />
<!-- 右侧文本区域 -->
<!-- 右侧文本区域 - 自适应宽度,超出显示... -->
<TextView
android:id="@+id/tv_text_content"
android:layout_width="0dp"
android:layout_height="match_parent"
android:textSize="14sp"
android:layout_weight="1"
android:textSize="15sp"
android:textColor="@color/text_secondary"
android:lineSpacingExtra="2dp"
android:lineSpacingExtra="3dp"
android:maxLines="4"
android:ellipsize="end"
android:gravity="top"
@ -83,35 +88,35 @@
</LinearLayout>
<!-- 操作按钮区域 - 右下角 -->
<!-- 底部操作区域:收藏和分享按钮,居右下角 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginBottom="4dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<!-- 收藏按钮 -->
<ImageView
android:id="@+id/btn_favorite"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_card_favorite_border"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="2dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_favorite_border"
android:background="@drawable/shape_button_ripple"
android:padding="4dp"
android:contentDescription="收藏" />
<!-- 分享按钮 -->
<ImageView
android:id="@+id/btn_share"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_card_share"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="2dp"
android:src="@drawable/ic_share"
android:background="@drawable/shape_button_ripple"
android:padding="4dp"
android:contentDescription="分享" />
</LinearLayout>