feature/child_mode_2 #158

Merged
Fujimatsu merged 23 commits from feature/child_mode_2 into main 2024-07-08 19:55:27 +00:00
15 changed files with 137 additions and 48 deletions

View File

@ -1,5 +1,6 @@
package one.nem.kidshift;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@ -91,12 +92,14 @@ public class ChildLoginActivity extends AppCompatActivity {
UserSettings.AppCommonSetting appCommonSetting = userSettings.getAppCommonSetting();
appCommonSetting.setLoggedIn(true);
appCommonSetting.setAccessToken(childAuthResponse.getAccessToken());
appCommonSetting.setChildId(childAuthResponse.getChildId());
appCommonSetting.setChildMode(true);
finish();
} catch (Exception e) {
logger.error("リクエストに失敗しました");
Toast.makeText(this, "ログインに失敗しました", Toast.LENGTH_SHORT).show();
}
}).thenRun(() -> {
startActivity(new Intent(this, MainActivity.class));
});
});
}

View File

@ -70,6 +70,16 @@ public class MainActivity extends AppCompatActivity {
return insets;
});
// Check logged in
if (userSettings.getAppCommonSetting().isLoggedIn()) {
logger.info("User is logged in!");
} else {
logger.info("User is not logged in!");
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@ -119,22 +129,27 @@ public class MainActivity extends AppCompatActivity {
e.printStackTrace();
}
// Check logged in
if (userSettings.getAppCommonSetting().isLoggedIn()) {
logger.info("User is logged in!");
} else {
logger.info("User is not logged in!");
UserSettings.AppCommonSetting appCommonSetting = userSettings.getAppCommonSetting();
if (appCommonSetting.isChildMode()) {
logger.info("Child mode is enabled!");
// 保護者向けのナビゲーションを削除
bottomNavigationView.getMenu().removeItem(R.id.feature_common_parent_child_navigation);
bottomNavigationView.getMenu().removeItem(R.id.feature_common_parent_parent_navigation);
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
bottomNavigationView.getMenu().removeItem(R.id.feature_wallet_parent_navigation);
// startDestinationを変更
bottomNavigationView.setSelectedItemId(R.id.feature_common_child_child_navigation);
// manage_child_accountを削除
navigationView.getMenu().removeItem(R.id.manage_child_account);
} else {
logger.info("Child mode is disabled!");
bottomNavigationView.getMenu().removeItem(R.id.feature_common_child_child_navigation);
bottomNavigationView.getMenu().removeItem(R.id.feature_wallet_child_navigation);
}
fab = findViewById(R.id.mainFab);
fabManager.setFab(fab);
// Apply feature flag
if (!featureFlag.isEnabled("showDebugMenu"))
bottomNavigationView.getMenu().removeItem(R.id.feature_debug_navigation);
}
/**

View File

@ -1,23 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- TODO: アイコン再検討 -->
<!-- 保護者モード / 保護者目線 -->
<item
android:id="@+id/feature_parent_navigation"
android:id="@+id/feature_common_parent_parent_navigation"
android:icon="@drawable/pending_24px"
android:title="Parent" />
android:title="ホーム" />
<!-- 保護者モード / 子供目線 -->
<item
android:id="@+id/feature_child_navigation"
android:id="@+id/feature_common_parent_child_navigation"
android:icon="@drawable/child_care_24px"
android:title="Child" />
android:title="こども" />
<!-- 子供モード / 子供目線 -->
<item
android:id="@+id/feature_debug_navigation"
android:icon="@drawable/developer_mode_24px"
android:title="Debug" />
android:id="@+id/feature_common_child_child_navigation"
android:icon="@drawable/child_care_24px"
android:title="ホーム" />
<item
android:id="@+id/feature_wallet_parent_navigation"
android:icon="@drawable/wallet_24px"
android:title="Wallet" />
android:title="ウォレット" />
<item
android:id="@+id/feature_wallet_child_navigation"
android:icon="@drawable/wallet_24px"
android:title="ウォレット" />
</menu>

View File

@ -2,10 +2,13 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_nav"
app:startDestination="@id/feature_parent_navigation">
app:startDestination="@id/feature_common_parent_parent_navigation">
<include app:graph="@navigation/feature_debug_navigation" />
<include app:graph="@navigation/feature_child_navigation" />
<include app:graph="@navigation/feature_parent_navigation" />
<include app:graph="@navigation/feature_common_parent_parent_navigation" />
<include app:graph="@navigation/feature_common_parent_child_navigation" />
<include app:graph="@navigation/feature_common_child_child_navigation" />
<include app:graph="@navigation/feature_wallet_parent_navigation" />
<include app:graph="@navigation/feature_wallet_child_navigation" />
</navigation>

View File

@ -37,6 +37,9 @@ public interface UserSettings {
boolean isChildMode();
void setChildMode(boolean childMode);
String getChildId();
void setChildId(String childId);
}
interface SharedPrefCache {

View File

@ -29,7 +29,7 @@ public class RewardDataImpl implements RewardData {
}
@Override
public CompletableFuture<Integer> getTotalReward(String childId) {
public CompletableFuture<Integer> getTotalReward(String childId) { // TODO: localCacheを使う
return CompletableFuture.supplyAsync(() -> ksActions.syncHistory(childId).join().stream().mapToInt(HistoryModel::getReward).sum());
}
}

View File

@ -77,6 +77,7 @@ public class UserSettingsImpl implements UserSettings {
boolean loggedIn;
String accessToken;
boolean childMode;
String childId;
AppCommonSettingImpl() {
sharedPrefUtils = sharedPrefUtilsFactory.create("user_settings");
@ -85,10 +86,12 @@ public class UserSettingsImpl implements UserSettings {
loggedIn = appCommonSetting.isLoggedIn();
accessToken = appCommonSetting.getAccessToken().isEmpty() ? "" : appCommonSetting.getAccessToken();
childMode = appCommonSetting.isChildMode();
childId = appCommonSetting.getChildId().isEmpty() ? "" : appCommonSetting.getChildId();
} else {
loggedIn = false;
accessToken = "";
childMode = false;
childId = "";
}
}
@ -128,6 +131,17 @@ public class UserSettingsImpl implements UserSettings {
this.childMode = childMode;
save();
}
@Override
public String getChildId() {
return childId;
}
@Override
public void setChildId(String childId) {
this.childId = childId;
save();
}
}
public class ApiSettingImpl implements UserSettings.ApiSetting {

View File

@ -123,7 +123,7 @@ public interface KidShiftApiService {
* 子供一覧取得
* @return ChildListResponse
*/
@GET("/parent/child")
@GET("/child")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ChildListResponse> getChildList();
@ -132,7 +132,7 @@ public interface KidShiftApiService {
* @param request ChildAddRequest
* @return ChildResponse
*/
@POST("/parent/child")
@POST("/child")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ChildResponse> addChild(@Body ChildAddRequest request);
@ -142,7 +142,7 @@ public interface KidShiftApiService {
* @param id 子供ID
* @return ChildResponse
*/
@PUT("/parent/child/{id}")
@PUT("/child/{id}")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ChildResponse> updateChild(@Body ChildAddRequest request, @Path("id") String id);
@ -151,7 +151,7 @@ public interface KidShiftApiService {
* @param id 子供ID
* @return Void
*/
@DELETE("/parent/child/{id}")
@DELETE("/child/{id}")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<Void> removeChild(@Path("id") String id);
@ -160,7 +160,7 @@ public interface KidShiftApiService {
* @param id 子供ID
* @return ChildLoginCodeResponse
*/
@GET("/parent/child/{id}/login")
@GET("/child/{id}/login")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ChildLoginCodeResponse> issueLoginCode(@Path("id") String id);

View File

@ -2,9 +2,22 @@ package one.nem.kidshift.data.retrofit.model.child.auth;
public class ChildAuthResponse {
private String accessToken;
private String childId;
public ChildAuthResponse(String accessToken) {
public ChildAuthResponse() {
}
public ChildAuthResponse(String accessToken, String childId) {
this.accessToken = accessToken;
this.childId = childId;
}
public String getChildId() {
return childId;
}
public void setChildId(String childId) {
this.childId = childId;
}
public String getAccessToken() {

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/feature_common_child_child_navigation"
app:startDestination="@id/commonHomeFragmentChildChild">
<fragment
android:id="@+id/commonHomeFragmentChildChild"
android:name="one.nem.kidshift.feature.common.CommonHomeFragment"
android:label="fragment_common_home"
tools:layout="@layout/fragment_common_home" >
<argument
android:name="isChildMode"
app:argType="boolean"
android:defaultValue="true" />
</fragment>
</navigation>

View File

@ -2,11 +2,11 @@
<navigation 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/feature_common_navigation"
app:startDestination="@id/commonHomeFragment">
android:id="@+id/feature_common_parent_child_navigation"
app:startDestination="@id/commonHomeFragmentParentChild">
<fragment
android:id="@+id/commonHomeFragment"
android:id="@+id/commonHomeFragmentParentChild"
android:name="one.nem.kidshift.feature.common.CommonHomeFragment"
android:label="fragment_common_home"
tools:layout="@layout/fragment_common_home" />

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/feature_common_parent_parent_navigation"
app:startDestination="@id/commonHomeFragmentParentParent">
<fragment
android:id="@+id/commonHomeFragmentParentParent"
android:name="one.nem.kidshift.feature.common.CommonHomeFragment"
android:label="fragment_common_home"
tools:layout="@layout/fragment_common_home" />
</navigation>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/feature_parent_navigation"
app:startDestination="@id/feature_common_navigation">
<include app:graph="@navigation/feature_common_navigation" />
</navigation>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/internal_parent_navigation">
<include app:graph="@navigation/feature_common_navigation" />
</navigation>

View File

@ -11,6 +11,7 @@ import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.kidshift.data.KSActions;
import one.nem.kidshift.data.RewardData;
import one.nem.kidshift.data.UserSettings;
import one.nem.kidshift.utils.FabManager;
import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@ -19,7 +20,6 @@ import one.nem.kidshift.utils.factory.KSLoggerFactory;
public class WalletContentFragment extends Fragment {
private static final String ARG_CHILD_ID = "childId";
@Inject
KSLoggerFactory loggerFactory;
@Inject
@ -28,6 +28,9 @@ public class WalletContentFragment extends Fragment {
@Inject
FabManager fabManager;
@Inject
UserSettings userSettings;
private KSLogger logger;
private String childId;
@ -45,6 +48,10 @@ public class WalletContentFragment extends Fragment {
return fragment;
}
public static WalletContentFragment newInstance() {
return new WalletContentFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -53,6 +60,13 @@ public class WalletContentFragment extends Fragment {
}
logger = loggerFactory.create("WalletMainFragment");
logger.debug("Received parameter: " + childId);
if (childId == null) {
// 単品で呼び出されてる = 子供モードでログインされている
childId = userSettings.getAppCommonSetting().getChildId();
if (childId == null) {
logger.error("Child ID is not set");
}
}
}
@Override