forked from nullxception/boorusphere
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65d1792
commit ea72f45
Showing
10 changed files
with
275 additions
and
37 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
android/app/src/main/kotlin/io/chaldeaprjkt/boorusphere/AndroidAppEnv.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.chaldeaprjkt.boorusphere | ||
|
||
import AppEnv | ||
import Env | ||
import android.os.Build | ||
import io.chaldeaprjkt.boorusphere.BuildConfig as BuildInfo // make sure that we use proper BuildConfig | ||
|
||
class AndroidAppEnv : AppEnv { | ||
override fun get(): Env { | ||
return Env( | ||
versionName = BuildInfo.VERSION_NAME, | ||
versionCode = BuildInfo.VERSION_CODE.toLong(), | ||
sdkVersion = Build.VERSION.SDK_INT.toLong() | ||
) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
android/app/src/main/kotlin/io/chaldeaprjkt/boorusphere/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package io.chaldeaprjkt.boorusphere | ||
|
||
import StorageUtil | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
|
||
class MainActivity : FlutterActivity() { | ||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
|
||
AppEnv.setUp(flutterEngine.dartExecutor.binaryMessenger, AndroidAppEnv()) | ||
StorageUtil.setUp(flutterEngine.dartExecutor.binaryMessenger, AndroidStorageUtil()) | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
android/app/src/main/kotlin/io/chaldeaprjkt/boorusphere/pigeon/AppEnv.pi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Autogenerated from Pigeon (v9.2.5), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
|
||
|
||
import android.util.Log | ||
import io.flutter.plugin.common.BasicMessageChannel | ||
import io.flutter.plugin.common.BinaryMessenger | ||
import io.flutter.plugin.common.MessageCodec | ||
import io.flutter.plugin.common.StandardMessageCodec | ||
import java.io.ByteArrayOutputStream | ||
import java.nio.ByteBuffer | ||
|
||
private fun wrapResult(result: Any?): List<Any?> { | ||
return listOf(result) | ||
} | ||
|
||
private fun wrapError(exception: Throwable): List<Any?> { | ||
if (exception is AppEnvException) { | ||
return listOf( | ||
exception.code, | ||
exception.message, | ||
exception.details | ||
) | ||
} else { | ||
return listOf( | ||
exception.javaClass.simpleName, | ||
exception.toString(), | ||
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Error class for passing custom error details to Flutter via a thrown PlatformException. | ||
* @property code The error code. | ||
* @property message The error message. | ||
* @property details The error details. Must be a datatype supported by the api codec. | ||
*/ | ||
class AppEnvException ( | ||
val code: String, | ||
override val message: String? = null, | ||
val details: Any? = null | ||
) : Throwable() | ||
|
||
/** Generated class from Pigeon that represents data sent in messages. */ | ||
data class Env ( | ||
val versionName: String, | ||
val versionCode: Long, | ||
val sdkVersion: Long | ||
|
||
) { | ||
companion object { | ||
@Suppress("UNCHECKED_CAST") | ||
fun fromList(list: List<Any?>): Env { | ||
val versionName = list[0] as String | ||
val versionCode = list[1].let { if (it is Int) it.toLong() else it as Long } | ||
val sdkVersion = list[2].let { if (it is Int) it.toLong() else it as Long } | ||
return Env(versionName, versionCode, sdkVersion) | ||
} | ||
} | ||
fun toList(): List<Any?> { | ||
return listOf<Any?>( | ||
versionName, | ||
versionCode, | ||
sdkVersion, | ||
) | ||
} | ||
} | ||
@Suppress("UNCHECKED_CAST") | ||
private object AppEnvCodec : StandardMessageCodec() { | ||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { | ||
return when (type) { | ||
128.toByte() -> { | ||
return (readValue(buffer) as? List<Any?>)?.let { | ||
Env.fromList(it) | ||
} | ||
} | ||
else -> super.readValueOfType(type, buffer) | ||
} | ||
} | ||
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { | ||
when (value) { | ||
is Env -> { | ||
stream.write(128) | ||
writeValue(stream, value.toList()) | ||
} | ||
else -> super.writeValue(stream, value) | ||
} | ||
} | ||
} | ||
|
||
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ | ||
interface AppEnv { | ||
fun get(): Env | ||
|
||
companion object { | ||
/** The codec used by AppEnv. */ | ||
val codec: MessageCodec<Any?> by lazy { | ||
AppEnvCodec | ||
} | ||
/** Sets up an instance of `AppEnv` to handle messages through the `binaryMessenger`. */ | ||
@Suppress("UNCHECKED_CAST") | ||
fun setUp(binaryMessenger: BinaryMessenger, api: AppEnv?) { | ||
run { | ||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.AppEnv.get", codec) | ||
if (api != null) { | ||
channel.setMessageHandler { _, reply -> | ||
var wrapped: List<Any?> | ||
try { | ||
wrapped = listOf<Any?>(api.get()) | ||
} catch (exception: Throwable) { | ||
wrapped = wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
import 'package:boorusphere/data/repository/version/entity/app_version.dart'; | ||
import 'package:boorusphere/domain/repository/env_repo.dart'; | ||
import 'package:device_info_plus/device_info_plus.dart'; | ||
import 'package:package_info/package_info.dart'; | ||
import 'package:boorusphere/pigeon/app_env.pi.dart'; | ||
|
||
class CurrentEnvRepo implements EnvRepo { | ||
CurrentEnvRepo({required this.packageInfo, required this.androidInfo}); | ||
CurrentEnvRepo({required this.env}); | ||
|
||
@override | ||
final PackageInfo packageInfo; | ||
final Env env; | ||
|
||
@override | ||
final AndroidDeviceInfo androidInfo; | ||
int get sdkVersion => env.sdkVersion; | ||
|
||
@override | ||
int get sdkVersion => androidInfo.version.sdkInt; | ||
|
||
@override | ||
AppVersion get appVersion => AppVersion.fromString(packageInfo.version); | ||
AppVersion get appVersion => AppVersion.fromString(env.versionName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import 'package:boorusphere/data/repository/version/entity/app_version.dart'; | ||
import 'package:device_info_plus/device_info_plus.dart'; | ||
import 'package:package_info/package_info.dart'; | ||
import 'package:boorusphere/pigeon/app_env.pi.dart'; | ||
|
||
abstract interface class EnvRepo { | ||
PackageInfo get packageInfo; | ||
AndroidDeviceInfo get androidInfo; | ||
Env get env; | ||
int get sdkVersion; | ||
AppVersion get appVersion; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Autogenerated from Pigeon (v9.2.5), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import | ||
|
||
import 'dart:async'; | ||
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; | ||
|
||
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; | ||
import 'package:flutter/services.dart'; | ||
|
||
class Env { | ||
Env({ | ||
required this.versionName, | ||
required this.versionCode, | ||
required this.sdkVersion, | ||
}); | ||
|
||
String versionName; | ||
|
||
int versionCode; | ||
|
||
int sdkVersion; | ||
|
||
Object encode() { | ||
return <Object?>[ | ||
versionName, | ||
versionCode, | ||
sdkVersion, | ||
]; | ||
} | ||
|
||
static Env decode(Object result) { | ||
result as List<Object?>; | ||
return Env( | ||
versionName: result[0]! as String, | ||
versionCode: result[1]! as int, | ||
sdkVersion: result[2]! as int, | ||
); | ||
} | ||
} | ||
|
||
class _AppEnvCodec extends StandardMessageCodec { | ||
const _AppEnvCodec(); | ||
@override | ||
void writeValue(WriteBuffer buffer, Object? value) { | ||
if (value is Env) { | ||
buffer.putUint8(128); | ||
writeValue(buffer, value.encode()); | ||
} else { | ||
super.writeValue(buffer, value); | ||
} | ||
} | ||
|
||
@override | ||
Object? readValueOfType(int type, ReadBuffer buffer) { | ||
switch (type) { | ||
case 128: | ||
return Env.decode(readValue(buffer)!); | ||
default: | ||
return super.readValueOfType(type, buffer); | ||
} | ||
} | ||
} | ||
|
||
class AppEnv { | ||
/// Constructor for [AppEnv]. The [binaryMessenger] named argument is | ||
/// available for dependency injection. If it is left null, the default | ||
/// BinaryMessenger will be used which routes to the host platform. | ||
AppEnv({BinaryMessenger? binaryMessenger}) | ||
: _binaryMessenger = binaryMessenger; | ||
final BinaryMessenger? _binaryMessenger; | ||
|
||
static const MessageCodec<Object?> codec = _AppEnvCodec(); | ||
|
||
Future<Env> get() async { | ||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( | ||
'dev.flutter.pigeon.AppEnv.get', codec, | ||
binaryMessenger: _binaryMessenger); | ||
final List<Object?>? replyList = | ||
await channel.send(null) as List<Object?>?; | ||
if (replyList == null) { | ||
throw PlatformException( | ||
code: 'channel-error', | ||
message: 'Unable to establish connection on channel.', | ||
); | ||
} else if (replyList.length > 1) { | ||
throw PlatformException( | ||
code: replyList[0]! as String, | ||
message: replyList[1] as String?, | ||
details: replyList[2], | ||
); | ||
} else if (replyList[0] == null) { | ||
throw PlatformException( | ||
code: 'null-error', | ||
message: 'Host platform returned null value for non-null return value.', | ||
); | ||
} else { | ||
return (replyList[0] as Env?)!; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:pigeon/pigeon.dart'; | ||
|
||
@ConfigurePigeon( | ||
PigeonOptions( | ||
dartOut: 'lib/pigeon/app_env.pi.dart', | ||
kotlinOut: | ||
'android/app/src/main/kotlin/io/chaldeaprjkt/boorusphere/pigeon/AppEnv.pi.kt', | ||
kotlinOptions: KotlinOptions(errorClassName: 'AppEnvException'), | ||
), | ||
) | ||
@HostApi() | ||
abstract class AppEnv { | ||
Env get(); | ||
} | ||
|
||
class Env { | ||
Env({ | ||
required this.versionName, | ||
required this.versionCode, | ||
required this.sdkVersion, | ||
}); | ||
|
||
final String versionName; | ||
final int versionCode; | ||
final int sdkVersion; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters