Skip to content

Commit

Permalink
Improve File Manager by Showing File Size or File Count on Folder, Tr…
Browse files Browse the repository at this point in the history
…y to fix problem when pressing back inside EmulationActivity
  • Loading branch information
KreitinnSoftware committed Dec 19, 2024
1 parent 5d08861 commit f6203d8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import com.micewine.emu.CmdEntryPoint.Companion.requestConnection
import com.micewine.emu.ICmdEntryInterface
import com.micewine.emu.LorieView
import com.micewine.emu.R
import com.micewine.emu.activities.GeneralSettings.Companion.ACTION_PREFERENCES_CHANGED
import com.micewine.emu.activities.MainActivity.Companion.ACTION_STOP_ALL
import com.micewine.emu.activities.MainActivity.Companion.enableCpuCounter
import com.micewine.emu.activities.MainActivity.Companion.enableRamCounter
Expand All @@ -73,7 +72,6 @@ import com.micewine.emu.views.OverlayView
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch


class EmulationActivity : AppCompatActivity(), View.OnApplyWindowInsetsListener {
private var mInputHandler: TouchInputHandler? = null
private var service: ICmdEntryInterface? = null
Expand All @@ -100,10 +98,6 @@ class EmulationActivity : AppCompatActivity(), View.OnApplyWindowInsetsListener
Log.e("MainActivity", "Something went wrong while we extracted connection details from binder.", e)
}
}
ACTION_PREFERENCES_CHANGED -> {
Log.d("MainActivity", "preference: " + intent.getStringExtra("key"))
onPreferencesChanged()
}
ACTION_STOP_ALL -> {
finishAffinity()
}
Expand Down Expand Up @@ -273,7 +267,6 @@ class EmulationActivity : AppCompatActivity(), View.OnApplyWindowInsetsListener
drawerLayout?.closeDrawers()
}

lorieView.releasePointerCapture()
return@OnKeyListener true
}
} else if (k == KeyEvent.KEYCODE_VOLUME_DOWN) {
Expand Down Expand Up @@ -330,7 +323,6 @@ class EmulationActivity : AppCompatActivity(), View.OnApplyWindowInsetsListener

registerReceiver(receiver, object : IntentFilter(ACTION_START) {
init {
addAction(ACTION_PREFERENCES_CHANGED)
addAction(ACTION_STOP_ALL)
}
})
Expand All @@ -349,6 +341,14 @@ class EmulationActivity : AppCompatActivity(), View.OnApplyWindowInsetsListener
}
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
lorieView.requestFocus()

mLorieKeyListener?.onKey(null, keyCode, event)

return true
}

override fun onGenericMotionEvent(event: MotionEvent?): Boolean {
checkControllerAxis(lorieView, event!!)

Expand Down Expand Up @@ -410,7 +410,7 @@ class EmulationActivity : AppCompatActivity(), View.OnApplyWindowInsetsListener
}
}

fun onPreferencesChanged() {
private fun onPreferencesChanged() {
mInputHandler!!.setInputMode(TouchInputHandler.InputMode.TRACKPAD)
mInputHandler!!.setTapToMove(false)
mInputHandler!!.setPreferScancodes(isKeyboardConnected())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class GeneralSettings : AppCompatActivity() {

companion object {
const val ACTION_PREFERENCE_SELECT = "com.micewine.emu.ACTION_PREFERENCE_SELECT"
const val ACTION_PREFERENCES_CHANGED = "com.micewine.emu.ACTION_PREFERENCES_CHANGED"
const val SWITCH = 1
const val SPINNER = 2
const val CHECKBOX = 3
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/com/micewine/emu/adapters/AdapterFiles.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.micewine.emu.adapters

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
Expand All @@ -19,13 +20,15 @@ import com.micewine.emu.activities.MainActivity.Companion.usrDir
import com.micewine.emu.core.WineWrapper.extractIcon
import com.micewine.emu.fragments.FloatingFileManagerFragment.Companion.refreshFiles
import java.io.File
import kotlin.math.round

class AdapterFiles(private val fileList: List<FileList>, private val context: Context, private val isFloatFilesDialog: Boolean) : RecyclerView.Adapter<AdapterFiles.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.adapter_files_item, parent, false)
return ViewHolder(itemView)
}

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val sList = fileList[position]

Expand All @@ -37,7 +40,31 @@ class AdapterFiles(private val fileList: List<FileList>, private val context: Co

if (sList.file.isDirectory) {
holder.icon.setImageResource(R.drawable.ic_folder)

val count = sList.file.listFiles()?.count()

if (count == null) {
holder.fileDescription.visibility = View.GONE
} else {
holder.fileDescription.visibility = View.VISIBLE

holder.fileDescription.text = when (count) {
0 -> {
context.getString(R.string.empty_text)
}
1 -> {
"$count ${context.getString(R.string.item_text)}"
}
else -> {
"$count ${context.getString(R.string.items_text)}"
}
}
}
} else if (sList.file.isFile) {
val fileSize = sList.file.length().toDouble()

holder.fileDescription.text = formatSize(fileSize)

if (sList.file.name.endsWith(".exe")) {
val output = "$usrDir/icons/${sList.file.nameWithoutExtension}-icon.ico"

Expand All @@ -62,6 +89,7 @@ class AdapterFiles(private val fileList: List<FileList>, private val context: Co

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener, View.OnLongClickListener {
val fileName: TextView = itemView.findViewById(R.id.title_preferences_model)
val fileDescription: TextView = itemView.findViewById(R.id.description_preferences_model)
val icon: ImageView = itemView.findViewById(R.id.set_img)

init {
Expand Down Expand Up @@ -109,4 +137,19 @@ class AdapterFiles(private val fileList: List<FileList>, private val context: Co
}

class FileList(var file: File)

companion object {
private const val GIGABYTE = 1024 * 1024 * 1024
private const val MEGABYTE = 1024 * 1024
private const val KILOBYTE = 1024

private fun formatSize(value: Double): String {
return when {
value < KILOBYTE -> "${round(value * 100) / 100}B"
value < MEGABYTE -> "${round(value / KILOBYTE * 100) / 100}KB"
value < GIGABYTE -> "${round(value / MEGABYTE * 100) / 100}MB"
else -> "${round(value / GIGABYTE * 100) / 100}GB"
}
}
}
}
2 changes: 0 additions & 2 deletions app/src/main/res/layout/activity_emulation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/darker_gray"
app:headerLayout="@layout/nav_header"
app:menu="@menu/emulation_drawer">
</com.google.android.material.navigation.NavigationView>
Expand All @@ -53,7 +52,6 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/darker_gray"
app:headerLayout="@layout/nav_logs_header">
</com.google.android.material.navigation.NavigationView>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:gravity="bottom"
android:orientation="vertical"
android:theme="@style/Theme.MiceWine"
android:background="@color/darker_gray"
tools:context=".activities.VirtualControllerOverlayMapper">

<com.micewine.emu.views.OverlayViewCreator
Expand All @@ -22,7 +23,6 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/darker_gray"
app:menu="@menu/virtual_controllers_drawer">
</com.google.android.material.navigation.NavigationView>

Expand Down
26 changes: 21 additions & 5 deletions app/src/main/res/layout/adapter_files_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="18dp">
android:padding="14dp">

<ImageView
android:id="@+id/set_img"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_settings_outline"
Expand All @@ -39,15 +39,31 @@
<TextView
android:id="@+id/title_preferences_model"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Title Settings"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textSize="16sp"
android:textStyle="bold"
android:singleLine="true"
android:ellipsize="marquee"
android:gravity="center_vertical"
tools:ignore="HardcodedText" />
tools:ignore="HardcodedText">
</TextView>

<TextView
android:id="@+id/description_preferences_model"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="size"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textSize="11sp"
android:textStyle="normal"
android:singleLine="true"
android:gravity="center_vertical"
tools:ignore="HardcodedText">
</TextView>

</LinearLayout>

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@
<string name="invalid_architecture_rat_file">Invalid Architecture Rat File.</string>
<string name="lnk_read_fail">Falha ao ler arquivo .lnk</string>
<string name="create_lnk">Salvar atalho .lnk</string>
<string name="item_text">item</string>
<string name="items_text">itens</string>
<string name="empty_text">Vazio</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,7 @@
<string name="invalid_architecture_rat_file">Invalid Architecture Rat File.</string>
<string name="lnk_read_fail">Failed to read .lnk file</string>
<string name="create_lnk">Create .lnk file</string>
<string name="item_text">item</string>
<string name="items_text">items</string>
<string name="empty_text">Empty</string>
</resources>

0 comments on commit f6203d8

Please sign in to comment.