first commit

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kunkunxiaomaoandClaude committed 2026-11-16 20:45:22 +08:00
commit 9c5fef1a4d
412 files changed
+94582

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
.cxx/
# Remember to never publicly share your keystore.
# See https://flutter.dev/to/reference-keystore
key.properties
**/*.keystore
**/*.jks
@@ -0,0 +1,46 @@
plugins {
id("com.android.application")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
if (project.file("google-services.json").exists()) {
apply(plugin = "com.google.gms.google-services")
}
android {
namespace = "top.kunkunxiaomao.sakura_mobile"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
defaultConfig {
applicationId = "top.kunkunxiaomao.sakura_mobile"
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
}
}
}
kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}
flutter {
source = "../.."
}
@@ -0,0 +1,60 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"/>
<application
android:label="Sakura"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/sakura_file_paths" />
</provider>
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>
@@ -0,0 +1,257 @@
package top.kunkunxiaomao.sakura_mobile
import android.content.ContentValues
import android.content.Intent
import android.net.Uri
import android.media.MediaScannerConnection
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import androidx.core.content.FileProvider
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugin.common.MethodChannel
import java.io.File
import java.io.IOException
import java.nio.charset.Charset
class MainActivity : FlutterActivity() {
private var sourceImportResult: MethodChannel.Result? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"top.kunkunxiaomao.sakura_mobile/downloads"
).setMethodCallHandler { call, result ->
when (call.method) {
"saveImageToGallery" -> {
val bytes = call.argument<ByteArray>("bytes")
val fileName = call.argument<String>("fileName")
val albumName = call.argument<String>("albumName") ?: "Images"
val mimeType = call.argument<String>("mimeType") ?: "image/jpeg"
if (bytes == null || fileName.isNullOrBlank()) {
result.error("invalid_args", "Missing image payload.", null)
return@setMethodCallHandler
}
runCatching {
saveImageToGallery(
bytes = bytes,
fileName = fileName,
albumName = albumName,
mimeType = mimeType
)
}.onSuccess(result::success).onFailure { error ->
result.error("save_failed", error.message, null)
}
}
else -> result.notImplemented()
}
}
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"top.kunkunxiaomao.sakura_mobile/encoding"
).setMethodCallHandler { call, result ->
when (call.method) {
"encodeQuery" -> {
val text = call.argument<String>("text") ?: ""
val charsetName = call.argument<String>("charset") ?: "UTF-8"
runCatching {
percentEncode(text, charsetName)
}.onSuccess(result::success).onFailure { error ->
result.error("encode_failed", error.message, null)
}
}
else -> result.notImplemented()
}
}
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"top.kunkunxiaomao.sakura_mobile/source_import"
).setMethodCallHandler { call, result ->
when (call.method) {
"pickJson" -> openJsonDocument(result)
else -> result.notImplemented()
}
}
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"top.kunkunxiaomao.sakura_mobile/media"
).setMethodCallHandler { call, result ->
when (call.method) {
"openUrl" -> {
val url = call.argument<String>("url")
val mimeType = call.argument<String>("mimeType") ?: "video/*"
if (url.isNullOrBlank()) {
result.error("invalid_args", "Missing media URL.", null)
return@setMethodCallHandler
}
runCatching {
openMediaUrl(url, mimeType)
}.onSuccess(result::success).onFailure { error ->
result.error("open_failed", error.message, null)
}
}
else -> result.notImplemented()
}
}
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode != SOURCE_JSON_REQUEST_CODE) return
val pending = sourceImportResult ?: return
sourceImportResult = null
if (resultCode != RESULT_OK) {
pending.success(null)
return
}
val uri = data?.data
if (uri == null) {
pending.success(null)
return
}
runCatching {
contentResolver.openInputStream(uri)?.use { input ->
input.readBytes().toString(Charsets.UTF_8)
} ?: throw IOException("Unable to open selected file.")
}.onSuccess(pending::success).onFailure { error ->
pending.error("read_failed", error.message, null)
}
}
private fun openJsonDocument(result: MethodChannel.Result) {
if (sourceImportResult != null) {
result.error("busy", "Another file picker is already open.", null)
return
}
sourceImportResult = result
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json"
putExtra(
Intent.EXTRA_MIME_TYPES,
arrayOf("application/json", "text/json", "text/plain", "*/*")
)
}
runCatching {
startActivityForResult(intent, SOURCE_JSON_REQUEST_CODE)
}.onFailure { error ->
sourceImportResult = null
result.error("open_failed", error.message, null)
}
}
private fun percentEncode(text: String, charsetName: String): String {
val normalized = when (charsetName.lowercase()) {
"gbk", "gb2312", "gb18030" -> charsetName.uppercase()
"shift-jis", "shift_jis", "sjis" -> "Shift_JIS"
else -> charsetName
}
val bytes = text.toByteArray(Charset.forName(normalized))
val builder = StringBuilder(bytes.size * 3)
for (byte in bytes) {
val value = byte.toInt() and 0xFF
val keep = (value in 0x30..0x39) ||
(value in 0x41..0x5A) ||
(value in 0x61..0x7A) ||
value == 0x2D ||
value == 0x2E ||
value == 0x5F ||
value == 0x7E
if (keep) {
builder.append(value.toChar())
} else {
builder.append('%')
builder.append(value.toString(16).uppercase().padStart(2, '0'))
}
}
return builder.toString()
}
private fun saveImageToGallery(
bytes: ByteArray,
fileName: String,
albumName: String,
mimeType: String
): String {
val cleanAlbum = albumName.trim().ifEmpty { "Images" }
val relativeFolder = "${Environment.DIRECTORY_PICTURES}/Sakura/$cleanAlbum"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val resolver = applicationContext.contentResolver
val values = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, fileName)
put(MediaStore.MediaColumns.MIME_TYPE, mimeType)
put(MediaStore.MediaColumns.RELATIVE_PATH, relativeFolder)
put(MediaStore.MediaColumns.IS_PENDING, 1)
}
val uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
?: throw IOException("Unable to create MediaStore record.")
resolver.openOutputStream(uri)?.use { output ->
output.write(bytes)
output.flush()
} ?: throw IOException("Unable to open output stream.")
values.clear()
values.put(MediaStore.MediaColumns.IS_PENDING, 0)
resolver.update(uri, values, null, null)
return "绯荤粺鍥惧簱/Sakura/$cleanAlbum/$fileName"
}
val picturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
val albumDir = File(picturesDir, "Sakura${File.separator}$cleanAlbum")
if (!albumDir.exists() && !albumDir.mkdirs()) {
throw IOException("Unable to create public pictures directory.")
}
val imageFile = File(albumDir, fileName)
imageFile.outputStream().use { output ->
output.write(bytes)
output.flush()
}
MediaScannerConnection.scanFile(
applicationContext,
arrayOf(imageFile.absolutePath),
arrayOf(mimeType),
null
)
return imageFile.absolutePath
}
private fun openMediaUrl(url: String, mimeType: String): Boolean {
val mediaUri = if (url.startsWith("file://") || url.startsWith("/")) {
val rawPath = url.removePrefix("file://")
val file = File(rawPath)
FileProvider.getUriForFile(
applicationContext,
"${applicationContext.packageName}.fileprovider",
file
)
} else {
Uri.parse(url)
}
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(mediaUri, mimeType.ifBlank { "video/*" })
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
return true
}
companion object {
private const val SOURCE_JSON_REQUEST_CODE = 61017
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path
name="sakura_downloads"
path="." />
<cache-path
name="sakura_cache"
path="." />
</paths>
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
+44
View File
@@ -0,0 +1,44 @@
import com.android.build.api.dsl.LibraryExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.api.tasks.compile.JavaCompile
allprojects {
repositories {
google()
mavenCentral()
}
}
val newBuildDir: Directory =
rootProject.layout.buildDirectory
.dir("../../build")
.get()
rootProject.layout.buildDirectory.value(newBuildDir)
subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
project.evaluationDependsOn(":app")
plugins.withId("com.android.library") {
extensions.configure<LibraryExtension> {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
}
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_17.toString()
targetCompatibility = JavaVersion.VERSION_17.toString()
}
tasks.withType<KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(JvmTarget.JVM_17)
}
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}
+9
View File
@@ -0,0 +1,9 @@
org.gradle.java.home=E:/path/Zulu/Zulu/zulu-21
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
# This newDsl flag was added by the Flutter template
android.newDsl=false
# This builtInKotlin flag was added by the Flutter template
android.builtInKotlin=false
kotlin.incremental=false
kotlin.compiler.execution.strategy=in-process
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-all.zip
+27
View File
@@ -0,0 +1,27 @@
pluginManagement {
val flutterSdkPath =
run {
val properties = java.util.Properties()
file("local.properties").inputStream().use { properties.load(it) }
val flutterSdkPath = properties.getProperty("flutter.sdk")
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
flutterSdkPath
}
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "9.0.1" apply false
id("org.jetbrains.kotlin.android") version "2.3.20" apply false
id("com.google.gms.google-services") version "4.4.2" apply false
}
include(":app")