Skip to content

Commit

Permalink
chore: merge branch dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog authored Sep 18, 2024
2 parents 94498b8 + 872f50e commit ac7f275
Show file tree
Hide file tree
Showing 69 changed files with 2,136 additions and 1,091 deletions.
2 changes: 1 addition & 1 deletion .github/crowdin-clean.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readdirSync(resPath).filter(f => f.startsWith("values-")).forEach(resFile => {
const content = readFileSync(stringsPath).toString();
const lines = content.split("\n");
console.log(`${stringsPath} has ${lines.length} lines`);
if (lines.length >= 5) return;
if (lines.length >= 100) return;
console.log(`Deleting: ${folderPath}`);
rmSync(folderPath, { recursive: true, force: true });
});
4 changes: 1 addition & 3 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ jobs:
- name: Crowdin sync
uses: crowdin/[email protected]
with:
create_pull_request: true
pull_request_title: "feat(l10n): update translations"
pull_request_base_branch_name: "dev"
create_pull_request: false
localization_branch_name: "l10n"
commit_message: "feat(l10n): update translations"
upload_sources: true
Expand Down
22 changes: 21 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: pftool
path: pftool.apk
path: pftool.apk

- name: Check if workflow supplied
id: check-workflow
run: |
if [ "$SECRET" == "" ]; then
echo "present=NO" >> $GITHUB_OUTPUT
else
echo "present=YES" >> $GITHUB_OUTPUT
fi
env:
SECRET: ${{ secrets.VERSION_DATA_WORKFLOW }}

- name: Trigger workflow
if: steps.check-workflow.outputs.present == 'YES'
uses: fjogeleit/[email protected]
with:
url: ${{ secrets.VERSION_DATA_WORKFLOW }}
method: "POST"
customHeaders: '{ "Accept":"application/vnd.github+json", "Authorization":"Bearer ${{ secrets.VERSION_DATA_TOKEN }}" }'
data: '{ "ref":"main" }'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
*.iml
*.jks
.gradle
/.idea
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
local.properties
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>

## 🌍 Translations
You can help translate PF Tool in [Crowdin](https://crowdin.com/project/pf-tool).
You can help translate PF Tool on [Crowdin](https://crowdin.com/project/pf-tool).

[![Crowdin](https://badges.crowdin.net/pf-tool/localized.svg)](https://crowdin.com/project/pf-tool)

Expand All @@ -39,7 +39,7 @@ Shizuku method will automatically be enabled if there is no other way for the ap
- Fork the repository
- Add environment variables required for signing from **Repository settings > Secrets and variables > Actions > Repository secrets**:
- `KEYSTORE_ALIAS`
- `KEYSTORE_BASE64` this can be obtained using `openssl base64 keystore.jks`
- `KEYSTORE_BASE64` this can be obtained using `openssl base64 -in keystore.jks`
- `KEYSTORE_PASSWORD`
- `KEY_PASSWORD`
- Enable workflows
Expand Down
62 changes: 50 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import org.apache.commons.io.output.ByteArrayOutputStream

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.parcelize")
id("com.mikepenz.aboutlibraries.plugin")
}

val composeMaterialVersion = "1.7.0-beta06"
val composeMaterial3Version = "1.3.0-beta05"
val composeCompilerVersion = "1.5.14"
val lifecycleVersion = "2.8.4"
val composeMaterialVersion = "1.7.1"
val composeMaterial3Version = "1.3.0"
val composeCompilerVersion = "1.5.15"
val lifecycleVersion = "2.8.5"
val shizukuVersion = "13.1.5"

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

Expand Down Expand Up @@ -81,6 +83,41 @@ android.defaultConfig.buildConfigField("String[]", "LANGUAGES", "new String[]{${
languages.joinToString(",") { "\"$it\"" }
}}")

// Utilities to get git environment information
// Source: https://github.com/vendetta-mod/VendettaManager/blob/main/app/build.gradle.kts
fun getCurrentBranch() = exec("git", "symbolic-ref", "--short", "HEAD")
?: exec("git", "describe", "--tags", "--exact-match")
fun getLatestCommit() = exec("git", "rev-parse", "--short", "HEAD")
fun hasLocalChanges(): Boolean {
val branch = getCurrentBranch()
val uncommittedChanges = exec("git", "status", "-s")?.isNotEmpty() ?: false
val unpushedChanges = exec("git", "log", "origin/$branch..HEAD")?.isNotBlank() ?: false
return uncommittedChanges || unpushedChanges
}

android.defaultConfig.run {
buildConfigField("String", "GIT_BRANCH", "\"${getCurrentBranch()}\"")
buildConfigField("String", "GIT_COMMIT", "\"${getLatestCommit()}\"")
buildConfigField("boolean", "GIT_LOCAL_CHANGES", "${hasLocalChanges()}")
}

fun exec(vararg command: String) = try {
val stdout = ByteArrayOutputStream()
val errout = ByteArrayOutputStream()
exec {
commandLine = command.toList()
standardOutput = stdout
errorOutput = errout
isIgnoreExitValue = true
}

if (errout.size() > 0) throw Error(errout.toString(Charsets.UTF_8))
stdout.toString(Charsets.UTF_8).trim()
} catch (_: Throwable) {
null
}


dependencies {
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.core:core-splashscreen:1.0.1")
Expand All @@ -91,15 +128,16 @@ 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.1")
implementation("androidx.navigation:navigation-compose:2.8.0-beta06")
implementation("com.mikepenz:aboutlibraries-core:11.2.2")
implementation("androidx.activity:activity-compose:1.9.2")
implementation("androidx.navigation:navigation-compose:2.8.0")
implementation("com.mikepenz:aboutlibraries-core:11.2.3")
implementation("io.insert-koin:koin-androidx-compose:3.5.6")
implementation("com.github.aliernfrog:top-toast-compose:2.1.0-alpha01")
implementation("com.github.aliernfrog:top-toast-compose:2.1.0")
implementation("com.lazygeniouz:dfc:1.0.8")
implementation("dev.rikka.shizuku:api:$shizukuVersion")
implementation("dev.rikka.shizuku:provider:$shizukuVersion")
implementation("io.coil-kt:coil-compose:2.7.0")
implementation("com.github.jeziellago:compose-markdown:0.5.2")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
implementation("com.github.jeziellago:compose-markdown:0.5.4")
implementation("net.engawapg.lib:zoomable:1.6.2")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.2")
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
</application>

<queries>
<package android:name="com.android.documentsui"/>
<package android:name="com.google.android.documentsui"/>
<package android:name="moe.shizuku.privileged.api"/>
</queries>
Expand Down
20 changes: 9 additions & 11 deletions app/src/main/aidl/com/aliernfrog/pftool/IFileService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ interface IFileService {

void copy(String sourcePath, String targetPath) = 2;

void delete(String path) = 3;

boolean exists(String path) = 4;

ServiceFile getFile(String path) = 5;
void createNewFile(String path) = 3;

ServiceFile[] listFiles(String path) = 6;
void delete(String path) = 4;

boolean exists(String path) = 5;

void mkdirs(String path) = 7;
ServiceFile getFile(String path) = 6;

void renameFile(String oldPath, String newPath) = 8;
ServiceFile[] listFiles(String path) = 7;

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

void zipMap(String path, String targetPath) = 10;
void renameFile(String oldPath, String newPath) = 9;

ParcelFileDescriptor getFd(String path) = 11;
ParcelFileDescriptor getFd(String path) = 10;
}
45 changes: 4 additions & 41 deletions app/src/main/java/com/aliernfrog/pftool/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,21 @@ const val TAG = "PFToolLogs"
const val experimentalSettingsRequiredClicks = 10
const val githubRepoURL = "https://github.com/aliernfrog/pf-tool"
const val crowdinURL = "https://crowdin.com/project/pf-tool"
const val documentsUIPackageName = "com.google.android.documentsui"

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

object ConfigKey {
const val PREF_NAME = "APP_CONFIG"
const val KEY_APP_LANGUAGE = "appLanguage"
const val KEY_APP_THEME = "appTheme"
const val KEY_APP_MATERIAL_YOU = "materialYou"
const val KEY_APP_AUTO_UPDATES = "autoUpdates"
const val KEY_APP_UPDATES_URL = "updatesUrl"
const val KEY_SHOW_CHOSEN_MAP_THUMBNAIL = "showChosenMapThumbnail"
const val KEY_SHOW_MAP_THUMBNAILS_LIST = "showMapThumbnailsList"
const val KEY_MAPS_DIR = "mapsDir"
const val KEY_EXPORTED_MAPS_DIR = "mapsExportDir"
const val DEFAULT_UPDATES_URL = "https://aliernfrog.github.io/pftool/latest.json"
val RECOMMENDED_MAPS_DIR = "${Environment.getExternalStorageDirectory()}/Android/data/com.MA.Polyfield/files/editor"
val RECOMMENDED_EXPORTED_MAPS_DIR = "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)}/PFTool/exported"
}

object SettingsConstant {
val folders = listOf(
PrefEditItem(
labelResourceId = R.string.settings_storage_folders_maps,
getValue = { it.pfMapsDir },
setValue = { newValue, prefs ->
prefs.pfMapsDir = newValue
},
default = ConfigKey.RECOMMENDED_MAPS_DIR
preference = { it.pfMapsDir },
label = { R.string.settings_storage_folders_maps }
),
PrefEditItem(
labelResourceId = R.string.settings_storage_folders_exportedMaps,
getValue = { it.exportedMapsDir },
setValue = { newValue, prefs ->
prefs.exportedMapsDir = newValue
},
default = ConfigKey.RECOMMENDED_EXPORTED_MAPS_DIR
preference = { it.exportedMapsDir },
label = { R.string.settings_storage_folders_exportedMaps }
)
)

Expand Down Expand Up @@ -111,18 +86,6 @@ object SettingsConstant {
link = "https://github.com/ReVanced/revanced-manager"
)
)

val experimentalPrefOptions = listOf(
PrefEditItem(
labelResourceId = R.string.settings_experimental_updatesURL,
getValue = { it.updatesURL },
setValue = { newValue, prefs ->
prefs.updatesURL = newValue
},
default = ConfigKey.DEFAULT_UPDATES_URL
),
*folders.toTypedArray()
)
}

val languages = BuildConfig.LANGUAGES.sorted().map { langCode ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.aliernfrog.pftool.data

import androidx.annotation.StringRes
import com.aliernfrog.pftool.R

data class MapActionResult(
val successful: Boolean,
val messageId: Int? = if (successful) null else R.string.warning_error,
@StringRes val message: Int? = if (successful) null else R.string.warning_error,
val newFile: Any? = null
)
24 changes: 24 additions & 0 deletions app/src/main/java/com/aliernfrog/pftool/data/MediaViewData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.aliernfrog.pftool.data

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Error
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.stringResource
import com.aliernfrog.pftool.R
import com.aliernfrog.pftool.ui.component.ErrorWithIcon

data class MediaViewData(
val model: Any?,
val title: String? = null,
val zoomEnabled: Boolean = true,
val errorContent: @Composable () -> Unit = {
ErrorWithIcon(
error = stringResource(R.string.warning_error),
painter = rememberVectorPainter(Icons.Rounded.Error),
contentColor = Color.Red
)
},
val options: (@Composable () -> Unit)? = null
)
15 changes: 10 additions & 5 deletions app/src/main/java/com/aliernfrog/pftool/data/PermissionData.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.aliernfrog.pftool.data

import android.net.Uri
import android.os.Environment
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import com.aliernfrog.pftool.util.manager.base.BasePreferenceManager

data class PermissionData(
@StringRes val title: Int,
val recommendedPath: String?,
val pref: BasePreferenceManager.Preference<String>,
val recommendedPath: String? = pref.defaultValue,
@StringRes val recommendedPathDescription: Int?,
@StringRes val recommendedPathWarning: Int? = null,
@StringRes val useUnrecommendedAnywayDescription: Int? = null,
val forceRecommendedPath: Boolean = true,
val getUri: () -> String,
val onUriUpdate: (Uri) -> Unit,
val content: @Composable () -> Unit
)
)

val PermissionData.requiresAndroidData: Boolean
get() = forceRecommendedPath && recommendedPath?.startsWith(
"${Environment.getExternalStorageDirectory()}/Android/data"
) == true
11 changes: 5 additions & 6 deletions app/src/main/java/com/aliernfrog/pftool/data/PrefEditItem.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.aliernfrog.pftool.data

import com.aliernfrog.pftool.util.manager.PreferenceManager
import com.aliernfrog.pftool.util.manager.base.BasePreferenceManager

data class PrefEditItem(
val labelResourceId: Int,
val getValue: (prefs: PreferenceManager) -> String,
val setValue: (newValue: String, prefs: PreferenceManager) -> Unit,
val default: String = ""
)
data class PrefEditItem<T>(
val preference: (PreferenceManager) -> BasePreferenceManager.Preference<T>,
val label: (PreferenceManager) -> Any = { preference(it).key }
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.aliernfrog.pftool.data

import android.os.Parcelable
import com.aliernfrog.pftool.di.getKoinInstance
import com.aliernfrog.pftool.ui.viewmodel.ShizukuViewModel
import com.aliernfrog.pftool.util.getKoinInstance
import com.aliernfrog.pftool.util.staticutil.FileUtil
import kotlinx.parcelize.Parcelize

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/aliernfrog/pftool/di/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.aliernfrog.pftool.di

import org.koin.mp.KoinPlatformTools

inline fun <reified T : Any> get(): T = KoinPlatformTools.defaultContext().get().get<T>()
inline fun <reified T : Any> getKoinInstance(): T = KoinPlatformTools.defaultContext().get().get<T>()
Loading

0 comments on commit ac7f275

Please sign in to comment.