add setting show extension

This commit is contained in:
Kagura 2024-10-11 12:46:31 +08:00
parent 2190a509ef
commit 9d724496c0
16 changed files with 206 additions and 101 deletions

View file

@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2024-10-09T05:47:14.530453572Z">
<DropdownSelection timestamp="2024-10-11T03:45:10.780689385Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=/home/kagura/.android/avd/Pixel_6_API_33.avd" />
<DeviceId pluginId="LocalEmulator" identifier="path=/home/kagura/.android/avd/Pixel_3_API_30.avd" />
</handle>
</Target>
</DropdownSelection>

View file

@ -6,7 +6,7 @@
<GradleProjectSettings>
<option name="testRunner" value="CHOOSE_PER_TEST" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View file

@ -1,16 +1,135 @@
package com.example.myapplication.compose
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material3.IconButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat
import com.example.myapplication.R
import com.example.myapplication.SettingStorage
import com.example.myapplication.compose.ui.Setting
import com.example.myapplication.main_page
class SettingActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
val setting = Setting(
rowModifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 10.dp),
nameTextStyle = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight(400),
fontFamily = FontFamily.SansSerif
),
descriptionModifier = Modifier.padding(start = 2.dp)
)
val settingStorage = SettingStorage(this)
val context = this
setContent {
Surface(
modifier = Modifier
.fillMaxSize()
) {
Column(
modifier = Modifier
.background(Color(getColor(R.color.WhiteSmoke)))
.statusBarsPadding()
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 10.dp, vertical = 10.dp),
verticalAlignment = Alignment.CenterVertically
) {
IconButton(
onClick = {
val intent = Intent(
context,
main_page::class.java
)
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
context.startActivity(intent)
}
) {
Image(
imageVector = ImageVector.vectorResource(R.drawable.ic_left_arrow), "back"
)
}
Text(
text = getString(R.string.settings),
fontSize = 30.sp,
modifier = Modifier
.padding(start = 10.dp)
.fillMaxWidth(0.75f),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
setting.BooleanSetting(
name = ContextCompat.getString(context, R.string.setting_show_extension),
description = ContextCompat.getString(
context,
R.string.setting_show_extension_description
),
initialState = settingStorage.get(settingStorage.showExtension) ?: true
) { settingStorage.set(settingStorage.showExtension, it) }
Spacer(modifier = Modifier.weight(1f))
Text(
text = stringResource(R.string.about),
fontSize = 18.sp,
color = Color.Gray,
modifier = Modifier.padding(start = 10.dp)
)
setting.BooleanSetting(
name = "作者",
description = "B22040723 舒乔嘉祺\nB22040721 黄译",
initialState = null
) { }
setting.BooleanSetting(
name = "系统信息",
description = "Android 版本:${Build.VERSION.RELEASE}\n手机型号: ${Build.MANUFACTURER} ${Build.MODEL}",
initialState = null
) { }
Spacer(modifier = Modifier.navigationBarsPadding())
}
}
}
}
}

View file

@ -56,6 +56,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.FileProvider
import com.example.myapplication.R
import com.example.myapplication.SettingStorage
import com.example.myapplication.compose.PasteHelper
import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.WrappedFile
@ -72,6 +73,7 @@ import java.io.FileNotFoundException
class FileColumn(val context: Context) {
private val fileList = mutableStateListOf<WrappedFile>()
private val settingStorage = SettingStorage(context)
@Composable
fun Draw(startFolder: String) {
@ -132,7 +134,8 @@ class FileColumn(val context: Context) {
Text(
text = path,
fontSize = 24.sp,
modifier = Modifier.padding(start = 10.dp)
modifier = Modifier
.padding(start = 10.dp)
.fillMaxWidth(0.75f),
maxLines = 1,
overflow = TextOverflow.Ellipsis
@ -526,13 +529,21 @@ class FileColumn(val context: Context) {
.fillMaxWidth(0.8f)
) {
Text(
text = forceName ?: file.name,
text = forceName ?: if (settingStorage.get(settingStorage.showExtension) == false || file.type == Type.DIRECTORY){
file.nameWithoutExt
}else{
file.name
},
fontSize = 24.sp,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = forceParent ?: file.getModifiedTimeString(context),
text = forceParent ?: if (file.type == Type.FILE){
"${file.getModifiedTimeString(context)} ${file.getSizeString()}"
}else{
file.getModifiedTimeString(context)
},
fontSize = 15.sp,
color = Color.Gray,
maxLines = 1

View file

@ -29,7 +29,7 @@ class Setting(
@Composable
fun BooleanSetting(
name: String,
initialState: Boolean = true,
initialState: Boolean? = true,
description: String? = null,
onCheckedChange: ((Boolean) -> Unit)? = null
) {
@ -55,14 +55,16 @@ class Setting(
)
}
Spacer(modifier = Modifier.weight(1f))
Switch(
checked = checkState,
onCheckedChange = {
checkState = it
onCheckedChange?.invoke(it)
},
modifier = switchModifier
)
if (checkState != null) {
Switch(
checked = checkState!!,
onCheckedChange = {
checkState = it
onCheckedChange?.invoke(it)
},
modifier = switchModifier
)
}
}
}
}

View file

@ -19,8 +19,8 @@ import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.DocumentAdapter
import com.example.myapplication.adapters.DocumentModel
import com.example.myapplication.fileSystem.adapters.DocumentAdapter
import com.example.myapplication.fileSystem.adapters.DocumentModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion.instance

View file

@ -1,4 +1,4 @@
package com.example.myapplication.adapters
package com.example.myapplication.fileSystem.adapters
import android.content.Context
import android.view.LayoutInflater
@ -7,10 +7,12 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import com.example.myapplication.R
import com.example.myapplication.SettingStorage
import java.io.File
class DocumentModel(document: File) {
val name: String = document.name
val nameWithoutExt: String = document.nameWithoutExtension
init {
if (!document.isFile) {
@ -21,13 +23,19 @@ class DocumentModel(document: File) {
class DocumentAdapter(context: Context, list: ArrayList<DocumentModel>) :
ArrayAdapter<DocumentModel>(context, 0, list) {
private val settingStorage = SettingStorage(context)
private val showExtension = settingStorage.get(settingStorage.showExtension)
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val listView = convertView ?: LayoutInflater.from(context).inflate(
R.layout.document_card_item, parent, false
)
val model = getItem(position) ?: throw RuntimeException()
val card = listView.findViewById<TextView>(R.id.iconButton)
card.text = model.name
card.text = if (showExtension != false) {
model.name
} else {
model.nameWithoutExt
}
return listView
}
}

View file

@ -1,4 +1,4 @@
package com.example.myapplication.adapters
package com.example.myapplication.fileSystem.adapters
import android.content.Context
import android.graphics.Bitmap
@ -13,11 +13,13 @@ import android.widget.GridView
import android.widget.ImageView
import android.widget.TextView
import com.example.myapplication.R
import com.example.myapplication.SettingStorage
import java.io.File
class ImageModel(image: File) {
val name: String = image.name
var thumbnail: Bitmap
val nameWithoutExt: String = image.nameWithoutExtension
init {
if (!image.isFile) {
@ -29,13 +31,19 @@ class ImageModel(image: File) {
class ImageAdapter(context: Context, list: ArrayList<ImageModel>) :
ArrayAdapter<ImageModel>(context, 0, list) {
private val settingStorage = SettingStorage(context)
private val showExtension = settingStorage.get(settingStorage.showExtension)
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val listView = convertView ?: LayoutInflater.from(context).inflate(
R.layout.picture_card_item, parent, false
)
val model = getItem(position) ?: throw RuntimeException()
listView.findViewById<ImageView>(R.id.pictureCardImage).setImageBitmap(model.thumbnail)
listView.findViewById<TextView>(R.id.pictureCardText).text = model.name
listView.findViewById<TextView>(R.id.pictureCardText).text = if (showExtension != false) {
model.name
} else {
model.nameWithoutExt
}
listView.setLayoutParams(LayoutParams(GridView.AUTO_FIT, 530))
return listView

View file

@ -1,4 +1,4 @@
package com.example.myapplication.adapters
package com.example.myapplication.fileSystem.adapters
import android.content.Context
import android.view.LayoutInflater
@ -7,10 +7,12 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import com.example.myapplication.R
import com.example.myapplication.SettingStorage
import java.io.File
class MusicModel(music: File) {
val name: String = music.nameWithoutExtension // 歌曲就不放扩展名了
val nameWithoutExt: String = music.nameWithoutExtension
init {
if (!music.isFile) {
@ -21,13 +23,19 @@ class MusicModel(music: File) {
class MusicAdapter(context: Context, list: ArrayList<MusicModel>) :
ArrayAdapter<MusicModel>(context, 0, list) {
private val settingStorage = SettingStorage(context)
private val showExtension = settingStorage.get(settingStorage.showExtension)
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val listView = convertView ?: LayoutInflater.from(context).inflate(
R.layout.music_card_item, parent, false
)
val model = getItem(position) ?: throw RuntimeException()
val card = listView.findViewById<TextView>(R.id.iconButton)
card.text = model.name
card.text = if (showExtension != false) {
model.name
} else {
model.nameWithoutExt
}
return listView
}
}

View file

@ -1,4 +1,4 @@
package com.example.myapplication.adapters
package com.example.myapplication.fileSystem.adapters
import android.content.Context
import android.graphics.Bitmap
@ -13,11 +13,13 @@ import android.widget.GridView
import android.widget.ImageView
import android.widget.TextView
import com.example.myapplication.R
import com.example.myapplication.SettingStorage
import java.io.File
class VideoModel(video: File) {
val name: String = video.name
var thumbnail: Bitmap
val nameWithoutExt: String = video.nameWithoutExtension
init {
if (!video.isFile) {
@ -32,13 +34,19 @@ class VideoModel(video: File) {
class VideoAdapter(context: Context, list: ArrayList<VideoModel>) :
ArrayAdapter<VideoModel>(context, 0, list) {
private val settingStorage = SettingStorage(context)
private val showExtension = settingStorage.get(settingStorage.showExtension)
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val listView = convertView ?: LayoutInflater.from(context).inflate(
R.layout.picture_card_item, parent, false
)
val model = getItem(position) ?: throw RuntimeException()
listView.findViewById<ImageView>(R.id.pictureCardImage).setImageBitmap(model.thumbnail)
listView.findViewById<TextView>(R.id.pictureCardText).text = model.name
listView.findViewById<TextView>(R.id.pictureCardText).text = if (showExtension != false) {
model.name
} else {
model.nameWithoutExt
}
listView.setLayoutParams(LayoutParams(GridView.AUTO_FIT, 530))
return listView

View file

@ -12,6 +12,7 @@ import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.example.myapplication.compose.SearchActivity;
import com.example.myapplication.compose.SettingActivity;
import com.example.myapplication.compose.ViewFileActivity;
import com.example.myapplication.fileSystem.DeleteHelper;
import java.io.File;
@ -44,6 +45,7 @@ public class main_page extends AppCompatActivity {
findViewById(R.id.MainPageDCIMButton).setOnClickListener(buttonClickerHandler);
findViewById(R.id.MainPagePicturesButton).setOnClickListener(buttonClickerHandler);
findViewById(R.id.MainPageSearchButton).setOnClickListener(buttonClickerHandler);
findViewById(R.id.MainPageSettingsButton).setOnClickListener(buttonClickerHandler);
}
@Override protected void onDestroy() {
@ -131,6 +133,10 @@ public class main_page extends AppCompatActivity {
Intent intent = new Intent(context, SearchActivity.class);
startActivity(intent);
}
if (view.getId() == R.id.MainPageSettingsButton) {
Intent intent = new Intent(context, SettingActivity.class);
startActivity(intent);
}
}
}
}

View file

@ -18,8 +18,8 @@ import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.MusicAdapter
import com.example.myapplication.adapters.MusicModel
import com.example.myapplication.fileSystem.adapters.MusicAdapter
import com.example.myapplication.fileSystem.adapters.MusicModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister

View file

@ -18,8 +18,8 @@ import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.ImageAdapter
import com.example.myapplication.adapters.ImageModel
import com.example.myapplication.fileSystem.adapters.ImageAdapter
import com.example.myapplication.fileSystem.adapters.ImageModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister

View file

@ -18,8 +18,8 @@ import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.VideoAdapter
import com.example.myapplication.adapters.VideoModel
import com.example.myapplication.fileSystem.adapters.VideoAdapter
import com.example.myapplication.fileSystem.adapters.VideoModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/Delete"
android:title="@string/Delete" />
<item
android:id="@+id/copy"
android:title="@string/copy" />
<item
android:id="@+id/cut"
android:title="@string/cut" />
<item
android:id="@+id/paste"
android:title="@string/paste" />
<item
android:id="@+id/unload"
android:title="@string/unload" />
</menu>

View file

@ -13,65 +13,15 @@
<string name="delete">最近删除</string>
<string name="download">下载与接收</string>
<string name="source">来源</string>
<string name="qq">QQ</string>
<string name="wechat">微信</string>
<string name="internet">浏览器</string>
<string name="radio">录音机</string>
<string name="installpackage">安装包</string>
<string name="Camera">Camera</string>
<string name="Screenshots">屏幕截图</string>
<!-- Strings used for fragments for navigation -->
<string name="first_fragment_label">First Fragment</string>
<string name="second_fragment_label">Second Fragment</string>
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="Delete">删除</string>
<string name="copy">复制</string>
<string name="cut">剪切</string>
<string name="paste">粘贴</string>
<string name="tiktok">抖音</string>
<string name="alipay">支付宝</string>
<string name="taobao">淘宝</string>
<string name="little_red_book">小红书</string>
<string name="unload">卸载</string>
<string name="store_package">压缩包</string>
<string name="phone_information">通话与信息</string>
<string name="lorem_ipsum">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in scelerisque sem. Mauris
volutpat, dolor id interdum ullamcorper, risus dolor egestas lectus, sit amet mattis purus
dui nec risus. Maecenas non sodales nisi, vel dictum dolor. Class aptent taciti sociosqu ad
litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse blandit eleifend
diam, vel rutrum tellus vulputate quis. Aliquam eget libero aliquet, imperdiet nisl a,
ornare ex. Sed rhoncus est ut libero porta lobortis. Fusce in dictum tellus.\n\n
Suspendisse interdum ornare ante. Aliquam nec cursus lorem. Morbi id magna felis. Vivamus
egestas, est a condimentum egestas, turpis nisl iaculis ipsum, in dictum tellus dolor sed
neque. Morbi tellus erat, dapibus ut sem a, iaculis tincidunt dui. Interdum et malesuada
fames ac ante ipsum primis in faucibus. Curabitur et eros porttitor, ultricies urna vitae,
molestie nibh. Phasellus at commodo eros, non aliquet metus. Sed maximus nisl nec dolor
bibendum, vel congue leo egestas.\n\n
Sed interdum tortor nibh, in sagittis risus mollis quis. Curabitur mi odio, condimentum sit
amet auctor at, mollis non turpis. Nullam pretium libero vestibulum, finibus orci vel,
molestie quam. Fusce blandit tincidunt nulla, quis sollicitudin libero facilisis et. Integer
interdum nunc ligula, et fermentum metus hendrerit id. Vestibulum lectus felis, dictum at
lacinia sit amet, tristique id quam. Cras eu consequat dui. Suspendisse sodales nunc ligula,
in lobortis sem porta sed. Integer id ultrices magna, in luctus elit. Sed a pellentesque
est.\n\n
Aenean nunc velit, lacinia sed dolor sed, ultrices viverra nulla. Etiam a venenatis nibh.
Morbi laoreet, tortor sed facilisis varius, nibh orci rhoncus nulla, id elementum leo dui
non lorem. Nam mollis ipsum quis auctor varius. Quisque elementum eu libero sed commodo. In
eros nisl, imperdiet vel imperdiet et, scelerisque a mauris. Pellentesque varius ex nunc,
quis imperdiet eros placerat ac. Duis finibus orci et est auctor tincidunt. Sed non viverra
ipsum. Nunc quis augue egestas, cursus lorem at, molestie sem. Morbi a consectetur ipsum, a
placerat diam. Etiam vulputate dignissim convallis. Integer faucibus mauris sit amet finibus
convallis.\n\n
Phasellus in aliquet mi. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. In volutpat arcu ut felis sagittis, in finibus massa
gravida. Pellentesque id tellus orci. Integer dictum, lorem sed efficitur ullamcorper,
libero justo consectetur ipsum, in mollis nisl ex sed nisl. Donec maximus ullamcorper
sodales. Praesent bibendum rhoncus tellus nec feugiat. In a ornare nulla. Donec rhoncus
libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
</string>
<string name="title_activity_require_permission">RequirePermissionActivity</string>
<string name="require_permission_readwrite">需要读取/写入存储权限以继续</string>
@ -137,4 +87,7 @@
<string name="sort_by_size">已选择按大小排序</string>
<string name="sort_by_time">已选择按时间排序</string>
<string name="title_activity_setting">SettingActivity</string>
<string name="setting_show_extension">显示扩展名</string>
<string name="setting_show_extension_description">如果打开,则会显示 abc.txt否则只显示 abc</string>
<string name="about">关于</string>
</resources>