|
|
@@ -1,30 +1,29 @@
|
|
|
import 'dart:convert';
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
-import 'package:keyboard/data/repository/account_repository.dart';
|
|
|
-import 'package:keyboard/data/repository/characters_repository.dart';
|
|
|
+import 'package:get/get.dart';
|
|
|
+import 'package:injectable/injectable.dart';
|
|
|
import 'package:keyboard/data/repository/chat_repository.dart';
|
|
|
import 'package:keyboard/data/repository/keyboard_repository.dart';
|
|
|
import 'package:keyboard/utils/atmob_log.dart';
|
|
|
-import 'package:get/get.dart';
|
|
|
|
|
|
import '../data/api/response/chat_prologue_response.dart';
|
|
|
import '../data/api/response/chat_super_speak_response.dart';
|
|
|
import '../data/api/response/keyboard_list_response.dart';
|
|
|
-import '../di/get_it.dart';
|
|
|
+import '../data/consts/constants.dart';
|
|
|
import '../utils/http_handler.dart';
|
|
|
import '../utils/mmkv_util.dart';
|
|
|
import '../utils/toast_util.dart';
|
|
|
-
|
|
|
+@injectable
|
|
|
class KeyboardMethodHandler {
|
|
|
final tag = "KeyboardMethodHandler";
|
|
|
|
|
|
// 用处存储选中的键盘id
|
|
|
static const String keyboardSelect = 'keyboard_select';
|
|
|
|
|
|
- bool get isLogin => AccountRepository.getInstance().isLoginTest();
|
|
|
+ bool get isLogin => KVUtil.getBool(Constants.keyIsLogin, false);
|
|
|
|
|
|
- bool get isMember => AccountRepository.getInstance().isMember.value;
|
|
|
+ bool get isMember => KVUtil.getBool(Constants.keyIsMember, false);
|
|
|
late KeyboardListResponse keyboardListResponse;
|
|
|
|
|
|
KeyboardMethodHandler();
|
|
|
@@ -62,7 +61,9 @@ class KeyboardMethodHandler {
|
|
|
Future<String> _handleGetKeyboardList(MethodCall call) async {
|
|
|
String? type = call.arguments?['type'] as String?;
|
|
|
|
|
|
- final keyboardList = await KeyboardRepository.getInstance().getKeyboardList(type: type);
|
|
|
+ final keyboardList = await KeyboardRepository.getInstance().getKeyboardList(
|
|
|
+ type: type,
|
|
|
+ );
|
|
|
final selectedKeyboardJson = KVUtil.getString(keyboardSelect, null);
|
|
|
if (selectedKeyboardJson != null) {
|
|
|
try {
|
|
|
@@ -90,7 +91,8 @@ class KeyboardMethodHandler {
|
|
|
final String keyboardId = call.arguments['keyboardId'];
|
|
|
|
|
|
if (keyboardListResponse.keyboardInfos.isEmpty) {
|
|
|
- keyboardListResponse = await KeyboardRepository.getInstance().getKeyboardList();
|
|
|
+ keyboardListResponse =
|
|
|
+ await KeyboardRepository.getInstance().getKeyboardList();
|
|
|
}
|
|
|
final selectedKeyboard = keyboardListResponse.keyboardInfos
|
|
|
.firstWhereOrNull((element) => element.id == keyboardId);
|
|
|
@@ -115,15 +117,15 @@ class KeyboardMethodHandler {
|
|
|
|
|
|
Future<String> _handleGetCharacterList(MethodCall call) async {
|
|
|
final String keyboardId = call.arguments['keyboardId'];
|
|
|
- final characterList = await KeyboardRepository.getInstance().getKeyboardCharacterList(
|
|
|
- keyboardId: keyboardId,
|
|
|
- );
|
|
|
+ final characterList = await KeyboardRepository.getInstance()
|
|
|
+ .getKeyboardCharacterList(keyboardId: keyboardId);
|
|
|
return jsonEncode(characterList.toJson());
|
|
|
}
|
|
|
|
|
|
// 获取开场白列表
|
|
|
Future<String> _handleGetPrologueList(MethodCall call) async {
|
|
|
- final prologueList = await KeyboardRepository.getInstance().getPrologueList();
|
|
|
+ final prologueList =
|
|
|
+ await KeyboardRepository.getInstance().getPrologueList();
|
|
|
return jsonEncode(prologueList.toJson());
|
|
|
}
|
|
|
|
|
|
@@ -133,11 +135,12 @@ class KeyboardMethodHandler {
|
|
|
final String keyboardId = call.arguments['keyboardId'];
|
|
|
final String characterId = call.arguments['characterId'];
|
|
|
try {
|
|
|
- final chatSuperReplyResponse = await ChatRepository.getInstance().chatSuperReply(
|
|
|
- content: content,
|
|
|
- keyboardId: keyboardId,
|
|
|
- characterId: characterId,
|
|
|
- );
|
|
|
+ final chatSuperReplyResponse = await ChatRepository.getInstance()
|
|
|
+ .chatSuperReply(
|
|
|
+ content: content,
|
|
|
+ keyboardId: keyboardId,
|
|
|
+ characterId: characterId,
|
|
|
+ );
|
|
|
|
|
|
return jsonEncode(chatSuperReplyResponse.toJson());
|
|
|
} catch (error) {
|
|
|
@@ -158,11 +161,12 @@ class KeyboardMethodHandler {
|
|
|
final String characterId = call.arguments['characterId'];
|
|
|
final ChatSuperSpeakResponse chatSuperSpeakResponse;
|
|
|
try {
|
|
|
- chatSuperSpeakResponse = await ChatRepository.getInstance().chatSuperSpeak(
|
|
|
- content: content,
|
|
|
- keyboardId: keyboardId,
|
|
|
- characterId: characterId,
|
|
|
- );
|
|
|
+ chatSuperSpeakResponse = await ChatRepository.getInstance()
|
|
|
+ .chatSuperSpeak(
|
|
|
+ content: content,
|
|
|
+ keyboardId: keyboardId,
|
|
|
+ characterId: characterId,
|
|
|
+ );
|
|
|
return jsonEncode(chatSuperSpeakResponse.toJson());
|
|
|
} catch (error) {
|
|
|
if (error is ServerErrorException) {
|
|
|
@@ -180,7 +184,9 @@ class KeyboardMethodHandler {
|
|
|
final String name = call.arguments['name'];
|
|
|
final ChatPrologueResponse chatPrologueResponse;
|
|
|
try {
|
|
|
- chatPrologueResponse = await ChatRepository.getInstance().chatPrologue(name: name);
|
|
|
+ chatPrologueResponse = await ChatRepository.getInstance().chatPrologue(
|
|
|
+ name: name,
|
|
|
+ );
|
|
|
return jsonEncode(chatPrologueResponse.toJson());
|
|
|
} catch (error) {
|
|
|
if (error is ServerErrorException) {
|
|
|
@@ -220,4 +226,5 @@ class KeyboardMethodHandler {
|
|
|
return '{}';
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|