Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge branch dev into `main #60

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ plugins {
id("com.mikepenz.aboutlibraries.plugin")
}

val composeMaterialVersion = "1.7.0-beta05"
val composeMaterial3Version = "1.3.0-beta04"
val composeMaterialVersion = "1.7.0-beta06"
val composeMaterial3Version = "1.3.0-beta05"
val composeCompilerVersion = "1.5.14"
val lifecycleVersion = "2.8.3"
val lifecycleVersion = "2.8.4"
val shizukuVersion = "13.1.5"

android {
Expand All @@ -19,8 +19,8 @@ android {
applicationId = "com.aliernfrog.pftool"
minSdk = 21
targetSdk = 34
versionCode = 18100
versionName = "1.8.1"
versionCode = 18200
versionName = "1.8.2"
vectorDrawables { useSupportLibrary = true }
}

Expand Down Expand Up @@ -91,8 +91,8 @@ dependencies {
implementation("androidx.compose.material3:material3-window-size-class:$composeMaterial3Version")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycleVersion")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.navigation:navigation-compose:2.8.0-beta05")
implementation("androidx.activity:activity-compose:1.9.1")
implementation("androidx.navigation:navigation-compose:2.8.0-beta06")
implementation("com.mikepenz:aboutlibraries-core:11.2.2")
implementation("io.insert-koin:koin-androidx-compose:3.5.6")
implementation("com.github.aliernfrog:top-toast-compose:2.1.0-alpha01")
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/aidl/com/aliernfrog/pftool/IFileService.aidl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aliernfrog.pftool;

import android.os.ParcelFileDescriptor;
import com.aliernfrog.pftool.data.ServiceFile;

interface IFileService {
Expand All @@ -13,15 +14,17 @@ interface IFileService {

boolean exists(String path) = 4;

byte[] getByteArray(String path) = 5;
ServiceFile getFile(String path) = 5;

ServiceFile getFile(String path) = 6;
ServiceFile[] listFiles(String path) = 6;

ServiceFile[] listFiles(String path) = 7;
void mkdirs(String path) = 7;

void renameFile(String oldPath, String newPath) = 8;

void unzipMap(String path, String targetPath) = 9;

void zipMap(String path, String targetPath) = 10;

ParcelFileDescriptor getFd(String path) = 11;
}
1 change: 0 additions & 1 deletion app/src/main/java/com/aliernfrog/pftool/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const val documentsUIPackageName = "com.google.android.documentsui"

val externalStorageRoot = Environment.getExternalStorageDirectory().toString()+"/"
val supportsPerAppLanguagePreferences = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
val imeSupportsSyncAppContent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
val folderPickerSupportsInitialUri = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
val hasAndroidDataRestrictions = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R

Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/aliernfrog/pftool/data/ServiceFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ fun ServiceFile.exists(): Boolean {
return shizukuViewModel.fileService!!.exists(path)
}

fun ServiceFile.getByteArray(): ByteArray {
val shizukuViewModel = getKoinInstance<ShizukuViewModel>()
return shizukuViewModel.fileService!!.getByteArray(path)
}

fun ServiceFile.listFiles(): Array<ServiceFile>? {
val shizukuViewModel = getKoinInstance<ShizukuViewModel>()
return shizukuViewModel.fileService!!.listFiles(path)
Expand All @@ -42,4 +37,9 @@ fun ServiceFile.listFiles(): Array<ServiceFile>? {
fun ServiceFile.renameTo(newPath: String) {
val shizukuViewModel = getKoinInstance<ShizukuViewModel>()
shizukuViewModel.fileService!!.renameFile(path, newPath)
}

fun ServiceFile.mkdirs() {
val shizukuViewModel = getKoinInstance<ShizukuViewModel>()
shizukuViewModel.fileService!!.mkdirs(path)
}
30 changes: 24 additions & 6 deletions app/src/main/java/com/aliernfrog/pftool/impl/MapFile.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aliernfrog.pftool.impl

import android.content.Context
import android.os.ParcelFileDescriptor
import android.util.Log
import com.aliernfrog.pftool.R
import com.aliernfrog.pftool.TAG
Expand All @@ -26,6 +27,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.io.ByteArrayOutputStream
import java.io.File

class MapFile(
Expand Down Expand Up @@ -101,15 +103,31 @@ class MapFile(
else if (path.startsWith(mapsViewModel.exportedMapsDir)) MapImportedState.EXPORTED
else MapImportedState.NONE

private var cachedThumbnailModel: Any? = null

/**
* Thumbnail model of the map.
*/
val thumbnailModel: Any? = if (importedState != MapImportedState.IMPORTED) null else when (file) {
is File -> if (file.isDirectory) "$path/Thumbnail.jpg" else null
is DocumentFileCompat -> if (file.isDirectory()) file.findFile("Thumbnail.jpg")?.uri?.toString() else null
is ServiceFile -> if (!file.isFile) shizukuViewModel.fileService!!.getByteArray("$path/Thumbnail.jpg") else null
else -> null
}
val thumbnailModel: Any?
get() {
return if (importedState != MapImportedState.IMPORTED) null else when (file) {
is File -> if (file.isDirectory) "$path/Thumbnail.jpg" else null
is DocumentFileCompat -> if (file.isDirectory()) file.findFile("Thumbnail.jpg")?.uri?.toString() else null
is ServiceFile -> if (!file.isFile) {
if (cachedThumbnailModel != null) return cachedThumbnailModel
val fd = shizukuViewModel.fileService!!.getFd("$path/Thumbnail.jpg")
val input = ParcelFileDescriptor.AutoCloseInputStream(fd)
val output = ByteArrayOutputStream()
input.copyTo(output)
cachedThumbnailModel = output.toByteArray()
output.close()
input.close()
fd.close()
return cachedThumbnailModel
} else null
else -> null
}
}

/**
* Details of the map. Includes size (KB) and modified time.
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/aliernfrog/pftool/service/FileService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aliernfrog.pftool.service

import android.os.ParcelFileDescriptor
import com.aliernfrog.pftool.IFileService
import com.aliernfrog.pftool.data.ServiceFile
import com.aliernfrog.pftool.util.getServiceFile
Expand Down Expand Up @@ -36,10 +37,6 @@ class FileService : IFileService.Stub() {
return File(path).exists()
}

override fun getByteArray(path: String): ByteArray {
return File(path).readBytes()
}

override fun getFile(path: String): ServiceFile {
return getServiceFile(File(path))
}
Expand All @@ -51,6 +48,10 @@ class FileService : IFileService.Stub() {
}.toTypedArray()
}

override fun mkdirs(path: String) {
File(path).mkdirs()
}

override fun renameFile(oldPath: String, newPath: String) {
File(oldPath).renameTo(File(newPath))
}
Expand All @@ -62,4 +63,8 @@ class FileService : IFileService.Stub() {
override fun zipMap(path: String, targetPath: String) {
ZipUtil.zipMap(File(path), File(targetPath))
}

override fun getFd(path: String): ParcelFileDescriptor {
return ParcelFileDescriptor.open(File(path), ParcelFileDescriptor.MODE_READ_ONLY)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aliernfrog.pftool.imeSupportsSyncAppContent
import com.aliernfrog.pftool.ui.viewmodel.InsetsViewModel
import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel
Expand Down Expand Up @@ -76,11 +75,6 @@ fun BaseModalBottomSheet(
dragHandle = dragHandle,
contentWindowInsets = { WindowInsets(0.dp) }
) {
content(
insetsViewModel.bottomPadding
// If IME does not sync app content, keyboard will show over the bottom sheet
// Add IME padding to workaround this
+ if (imeSupportsSyncAppContent) 0.dp else insetsViewModel.imePadding
)
content(insetsViewModel.bottomPadding)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import com.aliernfrog.pftool.R
import com.aliernfrog.pftool.TAG
import com.aliernfrog.pftool.data.MapActionResult
import com.aliernfrog.pftool.data.ServiceFile
import com.aliernfrog.pftool.data.exists
import com.aliernfrog.pftool.data.listFiles
import com.aliernfrog.pftool.data.mkdirs
import com.aliernfrog.pftool.enum.StorageAccessType
import com.aliernfrog.pftool.impl.MapFile
import com.aliernfrog.pftool.impl.Progress
Expand Down Expand Up @@ -178,6 +180,8 @@ class MapsViewModel(
}
StorageAccessType.SHIZUKU -> {
val shizukuViewModel = getKoinInstance<ShizukuViewModel>()
val file = shizukuViewModel.fileService!!.getFile(mapsDir)!!
if (!file.exists()) file.mkdirs()
shizukuViewModel.fileService!!.getFile(mapsDir)
}
StorageAccessType.ALL_FILES -> {
Expand Down Expand Up @@ -216,6 +220,8 @@ class MapsViewModel(
}
StorageAccessType.SHIZUKU -> {
val shizukuViewModel = getKoinInstance<ShizukuViewModel>()
val file = shizukuViewModel.fileService!!.getFile(exportedMapsDir)
if (!file.exists()) file.mkdirs()
shizukuViewModel.fileService!!.getFile(exportedMapsDir)
}
StorageAccessType.ALL_FILES -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Environment
import android.os.ParcelFileDescriptor
import android.provider.DocumentsContract
import android.text.format.DateUtils
import androidx.core.content.FileProvider
import com.aliernfrog.pftool.R
import com.aliernfrog.pftool.data.ServiceFile
import com.aliernfrog.pftool.data.getByteArray
import com.aliernfrog.pftool.ui.viewmodel.ShizukuViewModel
import com.aliernfrog.pftool.util.extension.toPath
import com.aliernfrog.pftool.util.getKoinInstance
import com.lazygeniouz.dfc.file.DocumentFileCompat
import java.io.File

Expand Down Expand Up @@ -110,7 +112,11 @@ class FileUtil {
val inputStream = when(file) {
is DocumentFileCompat -> context.contentResolver.openInputStream(file.uri)
is File -> file.inputStream()
is ServiceFile -> file.getByteArray().inputStream()
is ServiceFile -> {
val shizukuViewModel = getKoinInstance<ShizukuViewModel>()
val fd = shizukuViewModel.fileService!!.getFd(file.path)
ParcelFileDescriptor.AutoCloseInputStream(fd)
}
else -> throw IllegalArgumentException()
}
val targetFile = File("${context.externalCacheDir}/shared/$fileName")
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("com.android.application") version "8.4.1" apply false
id("com.android.library") version "8.4.1" apply false
id("com.android.application") version "8.5.1" apply false
id("com.android.library") version "8.5.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.24" apply false
id("org.jetbrains.kotlin.plugin.parcelize") version "1.9.24" apply false
id("com.mikepenz.aboutlibraries.plugin") version "11.2.2" apply false
Expand Down