Merge branch 'main' into feature/setting
This commit is contained in:
commit
b2925e83af
|
@ -45,6 +45,8 @@ dependencies {
|
|||
implementation project(':feature:child')
|
||||
implementation project(':feature:setting')
|
||||
|
||||
implementation project(':data')
|
||||
|
||||
implementation project(':shared')
|
||||
implementation project(':utils')
|
||||
|
||||
|
@ -57,4 +59,8 @@ dependencies {
|
|||
implementation libs.navigation.fragment
|
||||
implementation libs.navigation.ui
|
||||
implementation libs.navigation.dynamic.features.fragment
|
||||
|
||||
// Retrofit
|
||||
implementation libs.retrofit
|
||||
implementation libs.converter.gson
|
||||
}
|
|
@ -2,7 +2,10 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:name=".KidShiftApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
@ -10,9 +13,11 @@
|
|||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:name=".KidShiftApplication"
|
||||
android:theme="@style/Theme.KidShift"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".LoginActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
|
|
104
app/src/main/java/one/nem/kidshift/LoginActivity.java
Normal file
104
app/src/main/java/one/nem/kidshift/LoginActivity.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
package one.nem.kidshift;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.data.retrofit.KidShiftApiService;
|
||||
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginRequest;
|
||||
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginResponse;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
@Inject
|
||||
KSLogger logger;
|
||||
|
||||
@Inject
|
||||
UserSettings userSettings;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_login);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
// Retrofit init
|
||||
KidShiftApiService apiService = new Retrofit.Builder()
|
||||
.baseUrl("https://kidshift-beta.nem.one/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
.create(KidShiftApiService.class);
|
||||
|
||||
EditText emailEditText = findViewById(R.id.emailEditText);
|
||||
EditText passwordEditText = findViewById(R.id.passwordEditText);
|
||||
|
||||
findViewById(R.id.loginButton).setOnClickListener(v -> {
|
||||
CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
Response<ParentLoginResponse> response = apiService.parentLogin(
|
||||
new ParentLoginRequest(
|
||||
emailEditText.getText().toString(),
|
||||
passwordEditText.getText().toString()
|
||||
)).execute();
|
||||
|
||||
return response;
|
||||
} catch (IOException e) {
|
||||
logger.error("IOException");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).thenAccept(response -> {
|
||||
if (response.isSuccessful()) {
|
||||
logger.info("Login Success");
|
||||
logger.debug("AccessToken: " + response.body().getAccessToken());
|
||||
|
||||
UserSettings.AppCommonSetting appCommonSetting = userSettings.getAppCommonSetting();
|
||||
appCommonSetting.setLoggedIn(true);
|
||||
appCommonSetting.setAccessToken(response.body().getAccessToken());
|
||||
appCommonSetting.setChildMode(false);
|
||||
|
||||
finish();
|
||||
} else {
|
||||
logger.error("Login Failed");
|
||||
try {
|
||||
logger.debug("Response: " + response.errorBody().string());
|
||||
} catch (IOException e) {
|
||||
logger.error("IOException while reading error body");
|
||||
}
|
||||
// ログイン失敗時の処理
|
||||
}
|
||||
}).exceptionally(e -> {
|
||||
logger.error("Exception occurred: " + e.getMessage());
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
// for Debug
|
||||
findViewById(R.id.loginButton).setOnLongClickListener(v -> {
|
||||
// ログイン画面をバイパスしてメイン画面に遷移
|
||||
finish();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package one.nem.kidshift;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
|
@ -17,6 +18,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
|
||||
@AndroidEntryPoint
|
||||
|
@ -25,6 +27,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
@Inject
|
||||
KSLogger ksLogger;
|
||||
|
||||
@Inject
|
||||
UserSettings userSettings;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -51,5 +56,15 @@ public class MainActivity extends AppCompatActivity {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Check logged in
|
||||
if (userSettings.getAppCommonSetting().isLoggedIn()) {
|
||||
ksLogger.info("User is logged in!");
|
||||
} else {
|
||||
ksLogger.info("User is not logged in!");
|
||||
|
||||
Intent intent = new Intent(this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
53
app/src/main/res/layout/activity_login.xml
Normal file
53
app/src/main/res/layout/activity_login.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".LoginActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/inputContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/emailEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/passwordEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="※Loginボタン長押しでBypass"
|
||||
app:layout_constraintBottom_toTopOf="@+id/loginButton"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/loginButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="LOGIN"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -43,4 +43,8 @@ dependencies {
|
|||
|
||||
implementation project(':model')
|
||||
implementation project(':utils')
|
||||
|
||||
// Retrofit
|
||||
implementation libs.retrofit
|
||||
implementation libs.converter.gson
|
||||
}
|
|
@ -1,9 +1,34 @@
|
|||
package one.nem.kidshift.data;
|
||||
|
||||
import one.nem.kidshift.model.ParentModel;
|
||||
|
||||
public interface UserSettings {
|
||||
|
||||
interface Task {
|
||||
ApiSetting getApiSetting();
|
||||
TaskSetting getTaskSetting();
|
||||
AppCommonSetting getAppCommonSetting();
|
||||
|
||||
interface AppCommonSetting {
|
||||
boolean isLoggedIn();
|
||||
void setLoggedIn(boolean loggedIn);
|
||||
|
||||
String getAccessToken();
|
||||
void setAccessToken(String token);
|
||||
|
||||
boolean isChildMode();
|
||||
void setChildMode(boolean childMode);
|
||||
}
|
||||
|
||||
interface ApiSetting {
|
||||
String getApiBaseUrl();
|
||||
void setApiBaseUrl(String url);
|
||||
}
|
||||
|
||||
interface TaskSetting {
|
||||
int getDefaultIconColor();
|
||||
void setDefaultIconColor(int color);
|
||||
String getDefaultIconEmoji();
|
||||
void setDefaultIconEmoji(String emoji);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,19 +2,63 @@ package one.nem.kidshift.data.impl;
|
|||
|
||||
import android.graphics.Color;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.Binds;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
|
||||
public class UserSettingsDummyImpl implements UserSettings {
|
||||
|
||||
class Task implements UserSettings.Task {
|
||||
@Inject
|
||||
public UserSettingsDummyImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserSettings.TaskSetting getTaskSetting() {
|
||||
return new TaskSettingImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppCommonSetting getAppCommonSetting() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserSettings.ApiSetting getApiSetting() {
|
||||
return new ApiSettingImpl();
|
||||
}
|
||||
|
||||
public class ApiSettingImpl implements UserSettings.ApiSetting {
|
||||
@Override
|
||||
public String getApiBaseUrl() {
|
||||
return "https://kidshift-beta.nem.one/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApiBaseUrl(String url) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class TaskSettingImpl implements UserSettings.TaskSetting {
|
||||
@Override
|
||||
public int getDefaultIconColor() {
|
||||
return Color.parseColor("#FF0000");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultIconColor(int color) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultIconEmoji() {
|
||||
return "🤔";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultIconEmoji(String emoji) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
package one.nem.kidshift.data.impl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.utils.SharedPrefUtils;
|
||||
import one.nem.kidshift.utils.factory.SharedPrefUtilsFactory;
|
||||
|
||||
public class UserSettingsImpl implements UserSettings {
|
||||
|
||||
SharedPrefUtilsFactory sharedPrefUtilsFactory;
|
||||
|
||||
@Inject
|
||||
public UserSettingsImpl(SharedPrefUtilsFactory sharedPrefUtilsFactory) {
|
||||
this.sharedPrefUtilsFactory = sharedPrefUtilsFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiSetting getApiSetting() {
|
||||
return new ApiSettingImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskSetting getTaskSetting() {
|
||||
return new TaskSettingImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppCommonSetting getAppCommonSetting() {
|
||||
return new AppCommonSettingImpl();
|
||||
}
|
||||
|
||||
public class AppCommonSettingImpl implements UserSettings.AppCommonSetting {
|
||||
|
||||
transient
|
||||
SharedPrefUtils sharedPrefUtils;
|
||||
|
||||
boolean loggedIn;
|
||||
String accessToken;
|
||||
boolean childMode;
|
||||
|
||||
AppCommonSettingImpl() {
|
||||
sharedPrefUtils = sharedPrefUtilsFactory.create("user_settings");
|
||||
AppCommonSettingImpl appCommonSetting = sharedPrefUtils.getObject("app_common_setting", AppCommonSettingImpl.class);
|
||||
if (appCommonSetting != null) {
|
||||
loggedIn = appCommonSetting.isLoggedIn();
|
||||
accessToken = appCommonSetting.getAccessToken().isEmpty() ? "" : appCommonSetting.getAccessToken();
|
||||
childMode = appCommonSetting.isChildMode();
|
||||
} else {
|
||||
loggedIn = false;
|
||||
accessToken = "";
|
||||
childMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
sharedPrefUtils.saveObject("app_common_setting", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoggedIn() {
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoggedIn(boolean loggedIn) {
|
||||
this.loggedIn = loggedIn;
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccessToken(String token) {
|
||||
accessToken = token;
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildMode() {
|
||||
return childMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildMode(boolean childMode) {
|
||||
this.childMode = childMode;
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public class ApiSettingImpl implements UserSettings.ApiSetting {
|
||||
|
||||
transient
|
||||
SharedPrefUtils sharedPrefUtils;
|
||||
|
||||
String apiBaseUrl;
|
||||
|
||||
ApiSettingImpl() {
|
||||
sharedPrefUtils = sharedPrefUtilsFactory.create("user_settings");
|
||||
ApiSettingImpl apiSetting = sharedPrefUtils.getObject("api_setting", ApiSettingImpl.class);
|
||||
// TODO: リフレクションつかって一括でやる?(プロパティ数があまりにも増えるなら?), 三項演算子やめる?, デフォルト値の設定方法を改善する
|
||||
if (apiSetting != null) {
|
||||
apiBaseUrl = apiSetting.apiBaseUrl.isEmpty() ? "https://kidshift-beta.nem.one/" : apiSetting.apiBaseUrl;
|
||||
} else {
|
||||
apiBaseUrl = "https://kidshift-beta.nem.one/";
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
sharedPrefUtils.saveObject("api_setting", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApiBaseUrl() {
|
||||
return apiBaseUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApiBaseUrl(String url) {
|
||||
apiBaseUrl = url;
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public class TaskSettingImpl implements UserSettings.TaskSetting {
|
||||
|
||||
transient
|
||||
SharedPrefUtils sharedPrefUtils;
|
||||
|
||||
int defaultIconColor;
|
||||
|
||||
String defaultIconEmoji;
|
||||
|
||||
TaskSettingImpl() {
|
||||
sharedPrefUtils = sharedPrefUtilsFactory.create("user_settings");
|
||||
TaskSettingImpl taskSetting = sharedPrefUtils.getObject("task_setting", TaskSettingImpl.class);
|
||||
if (taskSetting != null) {
|
||||
defaultIconColor = taskSetting.getDefaultIconColor() == 0 ? 0 : taskSetting.getDefaultIconColor();
|
||||
defaultIconEmoji = taskSetting.getDefaultIconEmoji().isEmpty() ? "" : taskSetting.getDefaultIconEmoji();
|
||||
} else {
|
||||
defaultIconColor = 0;
|
||||
defaultIconEmoji = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
sharedPrefUtils.saveObject("task_setting", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultIconColor() {
|
||||
return defaultIconColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultIconColor(int color) {
|
||||
defaultIconColor = color;
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultIconEmoji() {
|
||||
return defaultIconEmoji;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultIconEmoji(String emoji) {
|
||||
defaultIconEmoji = emoji;
|
||||
save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,13 +4,18 @@ import dagger.Binds;
|
|||
import dagger.Module;
|
||||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.android.components.FragmentComponent;
|
||||
import dagger.hilt.components.SingletonComponent;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.data.impl.UserSettingsDummyImpl;
|
||||
import one.nem.kidshift.data.impl.UserSettingsImpl;
|
||||
|
||||
@Module
|
||||
@InstallIn(FragmentComponent.class)
|
||||
@InstallIn(SingletonComponent.class)
|
||||
abstract public class UserSettingsDummyModule {
|
||||
|
||||
// @Binds
|
||||
// abstract UserSettings bindUserSettings(UserSettingsDummyImpl userSettingsDummyImpl);
|
||||
|
||||
@Binds
|
||||
abstract UserSettings bindUserSettings(UserSettingsDummyImpl userSettingsDummyImpl);
|
||||
public abstract UserSettings bindUserSettings(UserSettingsImpl userSettingsImpl);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package one.nem.kidshift.data.retrofit;
|
||||
|
||||
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginRequest;
|
||||
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginResponse;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface KidShiftApiService {
|
||||
|
||||
@POST("/parent/auth/login")
|
||||
Call<ParentLoginResponse> parentLogin(@Body ParentLoginRequest request);
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package one.nem.kidshift.data.retrofit.model.parent.auth;
|
||||
|
||||
public class ParentLoginRequest {
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
public ParentLoginRequest(String email, String password) {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package one.nem.kidshift.data.retrofit.model.parent.auth;
|
||||
|
||||
public class ParentLoginResponse {
|
||||
private String accessToken;
|
||||
|
||||
public ParentLoginResponse(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package one.nem.kidshift.feature.debug;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -10,6 +12,7 @@ import dagger.hilt.EntryPoint;
|
|||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import dagger.hilt.android.components.FragmentComponent;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.utils.FeatureFlag;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.models.LogModel;
|
||||
|
@ -20,12 +23,16 @@ public class DebugCommandProcessor {
|
|||
KSLogger ksLogger;
|
||||
FeatureFlag featureFlag;
|
||||
|
||||
UserSettings userSettings;
|
||||
|
||||
public DebugCommandProcessor(
|
||||
KSLogger ksLogger,
|
||||
FeatureFlag featureFlag
|
||||
FeatureFlag featureFlag,
|
||||
UserSettings userSettings
|
||||
) {
|
||||
this.ksLogger = ksLogger;
|
||||
this.featureFlag = featureFlag;
|
||||
this.userSettings = userSettings;
|
||||
}
|
||||
|
||||
public String execute(String command) {
|
||||
|
@ -52,11 +59,64 @@ public class DebugCommandProcessor {
|
|||
return executeLog(commandArray);
|
||||
case "flag":
|
||||
return executeFlag(commandArray);
|
||||
case "setting":
|
||||
return executeSetting(commandArray);
|
||||
default:
|
||||
throw new InvalidCommandException();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: リフレクション処理切り出し, 複数の引数に対応, String以外の引数に対応
|
||||
private String executeSetting(String[] commandArray) {
|
||||
commandArray = shiftArray(commandArray);
|
||||
Class<?> settingClazz;
|
||||
switch (commandArray[0]) {
|
||||
case "get":
|
||||
commandArray = shiftArray(commandArray);
|
||||
// リフレクションで取得
|
||||
try {
|
||||
// userSettingsのgetterでsettingクラスを取得
|
||||
Method method = userSettings.getClass().getMethod("get" + commandArray[0]);
|
||||
Object setting = method.invoke(userSettings);
|
||||
|
||||
//settingクラスのgetterで値を取得
|
||||
Method settingMethod = setting.getClass().getMethod("get" + commandArray[1]);
|
||||
return settingMethod.invoke(setting).toString();
|
||||
} catch (NoSuchMethodException e) {
|
||||
return "Method" + commandArray[0] + " not found \n" + e.getMessage();
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
return "Method" + commandArray[0] + " not accessible \n" + e.getMessage();
|
||||
} catch (Exception e) {
|
||||
return "Something went wrong! \n" + e.getMessage();
|
||||
}
|
||||
case "set":
|
||||
commandArray = shiftArray(commandArray);
|
||||
// リフレクションで取得
|
||||
try {
|
||||
// userSettingsのgetterでsettingクラスを取得
|
||||
Method method = userSettings.getClass().getMethod("get" + commandArray[0]);
|
||||
Object setting = method.invoke(userSettings);
|
||||
|
||||
//settingクラスのsetterで値を設定
|
||||
Method settingMethod = setting.getClass().getMethod("set" + commandArray[1], String.class); // TODO: String以外の型に対応
|
||||
settingMethod.invoke(setting, commandArray[2]);
|
||||
return "Setting set!";
|
||||
} catch (NoSuchMethodException e) {
|
||||
return "Method" + commandArray[0] + " not found \n" + e.getMessage();
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
return "Method" + commandArray[0] + " not accessible \n" + e.getMessage();
|
||||
} catch (Exception e) {
|
||||
return "Something went wrong! \n" + e.getMessage();
|
||||
}
|
||||
default:
|
||||
return "TODO";
|
||||
}
|
||||
}
|
||||
|
||||
private String executeLog(String[] commandArray) {
|
||||
commandArray = shiftArray(commandArray);
|
||||
switch (commandArray[0]) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.feature.debug.adapter.DebugCommandListItemAdapter;
|
||||
import one.nem.kidshift.feature.debug.model.DebugCommandItemModel;
|
||||
import one.nem.kidshift.utils.FeatureFlag;
|
||||
|
@ -29,6 +30,9 @@ public class DebugDebugConsoleFragment extends Fragment {
|
|||
@Inject
|
||||
FeatureFlag featureFlag;
|
||||
|
||||
@Inject
|
||||
UserSettings userSettings;
|
||||
|
||||
private final List<DebugCommandItemModel> debugCommandItemModels = new ArrayList<>();
|
||||
DebugCommandListItemAdapter debugCommandItemAdapter;
|
||||
|
||||
|
@ -59,7 +63,7 @@ public class DebugDebugConsoleFragment extends Fragment {
|
|||
TextView debugCommandInput = view.findViewById(R.id.debugCommandEditText);
|
||||
view.findViewById(R.id.debugCommandExecuteButton).setOnClickListener(v -> {
|
||||
DebugCommandProcessor debugCommandProcessor = new DebugCommandProcessor(
|
||||
ksLogger, featureFlag);
|
||||
ksLogger, featureFlag, userSettings);
|
||||
debugCommandItemModels.add(
|
||||
new DebugCommandItemModel(
|
||||
debugCommandInput.getText().toString(),
|
||||
|
|
|
@ -9,8 +9,10 @@ material = "1.12.0"
|
|||
activity = "1.9.0"
|
||||
constraintlayout = "2.1.4"
|
||||
nav = "2.7.7"
|
||||
retrofit = "2.11.0"
|
||||
|
||||
[libraries]
|
||||
converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" }
|
||||
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
|
@ -26,6 +28,7 @@ com-google-dagger-hilt-compiler = { group="com.google.dagger", name="hilt-compil
|
|||
navigation-fragment = { group="androidx.navigation", name="navigation-fragment", version.ref="nav"}
|
||||
navigation-ui = { group="androidx.navigation", name="navigation-ui", version.ref="nav"}
|
||||
navigation-dynamic-features-fragment = { group="androidx.navigation", name="navigation-dynamic-features-fragment", version.ref="nav"}
|
||||
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
|
||||
|
||||
[plugins]
|
||||
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
||||
|
|
Loading…
Reference in New Issue
Block a user