Skip to content

Commit

Permalink
1.添加应用图标
Browse files Browse the repository at this point in the history
2.优化部分逻辑
  • Loading branch information
LisPig committed May 20, 2024
1 parent 69d6ed6 commit 69cace8
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 153 deletions.
15 changes: 1 addition & 14 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlin-android'
}

android {
Expand Down Expand Up @@ -70,8 +71,9 @@ configurations {

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.20"
implementation 'androidx.core:core-ktx:1.8.0'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.9.20')
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
Expand All @@ -92,7 +94,7 @@ dependencies {
debugImplementation 'androidx.compose.ui:ui-test-manifest'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

implementation("androidx.compose.ui:ui:1.3.3") // 或者更高版本
implementation("androidx.compose.ui:ui:1.5.4") // 或者更高版本
implementation("androidx.compose.material3:material3:1.0.1") // 或者更高版本
implementation("androidx.activity:activity-compose:1.6.1") // 或者更高版本
implementation 'com.github.princekin-f:EasyFloat:2.0.4'
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/ic_launcher_xxxhdpi"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/ic_launcher_xxxhdpi"
android:supportsRtl="true"
android:theme="@style/Theme.WordUnlock"
tools:targetApi="31">
Expand All @@ -35,7 +35,9 @@
android:name=".WordUnlockForegroundService"
android:enabled="true"
android:exported="true"
android:theme="@style/AppTheme"/>
android:theme="@style/AppTheme">

</service>

<activity
android:name=".MainActivity"
Expand All @@ -52,7 +54,7 @@
<activity
android:name=".Fragment.FavoriteListActivity"
android:exported="true"
android:label="@string/app_name"
android:label="收藏列表"
android:theme="@style/AppTheme"/>


Expand Down
117 changes: 0 additions & 117 deletions app/src/main/java/com/example/wordunlock/FloatingWordInputService.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FavoriteListActivity : AppCompatActivity() {
adapter = FavoriteListAdapter { item ->
lifecycleScope.launch {
// 在这里处理删除操作,例如调用DAO的delete方法
// favoriteItemDao.delete(item)
item.id?.let { db.favoriteItemDao().deleteById(it) }
}
}
recyclerView.adapter = adapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
package com.example.wordunlock.Fragment

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Switch
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.example.wordunlock.R

class SettingsFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_settings, container, false)
var forceMode = view.findViewById<Switch>(R.id.switch_force_mode)
forceMode.setOnClickListener {
if (forceMode.isChecked) {
// 切换到强制模式
// 显示提示信息
//弹窗提示
val toastMessage = "已开启强制模式。关闭后弹窗将有关闭按钮,需输入正确单词即可关闭"
AlertDialog.Builder(requireContext())
.setTitle("开启强制模式")
.setMessage("开启后弹窗将无关闭按钮,需强制输入正确单词即可关闭。")
.setPositiveButton("确定") { dialog, _ ->
dialog.dismiss()
}
.setCancelable(false) // 避免用户点击外部关闭而不做处理
.show()
} else {
// 切换到普通模式
// 隐藏提示信息
// ...
}
}

val collectionView = view.findViewById<ImageView>(R.id.image_view_favorites)
collectionView.setOnClickListener {
// 点击跳转到收藏夹页面
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ class WordUnlockForegroundService : IntentService("WordUnlockService"), TextToSp
withContext(Dispatchers.IO) {
saveFavoriteItem(item = favoriteItem)
}
val goldenDrawable = ContextCompat.getDrawable(this, R.drawable.baseline_star_gold_24)
val goldenDrawable = ContextCompat.getDrawable(this, R.drawable.baseline_check_circle_24)
starButton?.setImageDrawable(goldenDrawable)
} else {
val normalDrawable = ContextCompat.getDrawable(this, R.drawable.baseline_star_24)
val normalDrawable = ContextCompat.getDrawable(this, R.drawable.baseline_check_circle_outline_24)
starButton?.setImageDrawable(normalDrawable)
withContext(Dispatchers.IO) {
removeFavoriteItem(favoriteItem?.word)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.example.wordunlock.adapters

import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.example.wordunlock.R
import com.example.wordunlock.models.FavoriteItem
import com.example.wordunlock.databinding.CollectionListBinding

class FavoriteItemViewHolder(private val binding: CollectionListBinding) :
RecyclerView.ViewHolder(binding.root) {

val ivDelete: ImageView = itemView.findViewById(R.id.iv_delete)

fun bind(favoriteItem: FavoriteItem, onDeleteClickListener: (FavoriteItem) -> Unit) {
binding.tvWord.text = favoriteItem.word
binding.ivDelete.setOnClickListener {
onDeleteClickListener.invoke(favoriteItem)
onDeleteClickListener(favoriteItem)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import com.example.wordunlock.databinding.CollectionListBinding
import com.example.wordunlock.models.FavoriteItem
import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter

class FavoriteListAdapter(private val onDeleteClickListener: (FavoriteItem) -> Unit) :
ListAdapter<FavoriteItem, FavoriteItemViewHolder>(FavoriteItemDiffCallback()) {

var selectedPosition = -1
val selectedItemOrNull: FavoriteItem?
get() = if (selectedPosition >= 0 && selectedPosition < itemCount) getItem(selectedPosition) else null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FavoriteItemViewHolder {
val binding = CollectionListBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return FavoriteItemViewHolder(binding)
Expand All @@ -29,4 +33,7 @@ class FavoriteListAdapter(private val onDeleteClickListener: (FavoriteItem) -> U
return oldItem == newItem
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ interface FavoriteItemDao {
@Query("DELETE FROM favorite_items WHERE word LIKE :word")
suspend fun delete(word: String)

@Query("DELETE FROM favorite_items WHERE id LIKE :id")
suspend fun deleteById(id: Int)
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_check_circle_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#00FF51" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>

</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#8F8F8F" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M16.59,7.58L10,14.17l-3.59,-3.58L5,12l5,5 8,-8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>

</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_delete_sweep_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FF5151" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M15,16h4v2h-4zM15,8h7v2h-7zM15,12h6v2h-6zM3,18c0,1.1 0.9,2 2,2h6c1.1,0 2,-0.9 2,-2L13,8L3,8v10zM14,5h-3l-1,-1L6,4L5,5L2,5v2h12z"/>

</vector>
4 changes: 3 additions & 1 deletion app/src/main/res/layout/collection_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
android:id="@+id/iv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="删除按钮" />
android:contentDescription="删除按钮"
android:onClick="onDeleteButtonClicked"
android:src="@drawable/baseline_delete_sweep_24"/>

</LinearLayout>
</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/float_word_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onStarButtonClicked"
android:src="@drawable/baseline_star_24"
android:src="@drawable/baseline_check_circle_outline_24"
android:layout_weight="1"/>
</LinearLayout>
<TextView
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<item
android:id="@+id/action_select_all"
android:orderInCategory="100"
android:title="Check all"
android:title="全选"
app:showAsAction="never" />

<item
android:id="@+id/action_deselect_all"
android:title="Unselect all"/>
android:title="取消全选"/>
</menu>
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher_hdpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-mdpi/ic_launcher_mdpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<fragment
android:id="@+id/navigation_home"
android:name="com.example.wordunlock.Fragment.HomeFragment"
android:label="Home"
android:label="@string/dictionary"
tools:layout="@layout/home_fragment" />

<fragment
android:id="@+id/navigation_settings"
android:name="com.example.wordunlock.Fragment.SettingsFragment"
android:label="Settings"
android:label="@string/setting"
tools:layout="@layout/fragment_settings" />


Expand Down
Loading

0 comments on commit 69cace8

Please sign in to comment.