feature/updateupdate #138

Merged
Fujimatsu merged 4 commits from feature/updateupdate into main 2024-07-06 02:11:16 +00:00
24 changed files with 278 additions and 179 deletions
Showing only changes of commit 30b906d284 - Show all commits

View File

@ -9,6 +9,7 @@ import javax.inject.Inject;
import dagger.hilt.android.HiltAndroidApp; import dagger.hilt.android.HiltAndroidApp;
import one.nem.kidshift.utils.FeatureFlag; import one.nem.kidshift.utils.FeatureFlag;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@HiltAndroidApp @HiltAndroidApp
public class KidShiftApplication extends Application { public class KidShiftApplication extends Application {
@ -17,13 +18,16 @@ public class KidShiftApplication extends Application {
FeatureFlag featureFlag; FeatureFlag featureFlag;
@Inject @Inject
KSLogger logger; KSLoggerFactory loggerFactory;
private KSLogger logger;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
logger.setTag("KidShiftApplication"); this.logger = loggerFactory.create("KidShiftApplication");
logger.info("super.onCreate() completed"); logger.info("super.onCreate() completed");
if(featureFlag.isEnabled("dynamicColorEnable")) { if(featureFlag.isEnabled("dynamicColorEnable")) {

View File

@ -20,6 +20,7 @@ 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.ParentLoginRequest;
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginResponse; import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginResponse;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
import retrofit2.Response; import retrofit2.Response;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
@ -28,7 +29,9 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class LoginActivity extends AppCompatActivity { public class LoginActivity extends AppCompatActivity {
@Inject @Inject
KSLogger logger; KSLoggerFactory loggerFactory;
private KSLogger logger;
@Inject @Inject
UserSettings userSettings; UserSettings userSettings;
@ -44,6 +47,8 @@ public class LoginActivity extends AppCompatActivity {
return insets; return insets;
}); });
logger = loggerFactory.create("LoginActivity");
// Retrofit init // Retrofit init
KidShiftApiService apiService = new Retrofit.Builder() KidShiftApiService apiService = new Retrofit.Builder()
.baseUrl("https://kidshift-beta.nem.one/") .baseUrl("https://kidshift-beta.nem.one/")

View File

@ -20,12 +20,15 @@ import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import one.nem.kidshift.data.UserSettings; import one.nem.kidshift.data.UserSettings;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@AndroidEntryPoint @AndroidEntryPoint
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@Inject @Inject
KSLogger ksLogger; KSLoggerFactory loggerFactory;
private KSLogger logger;
@Inject @Inject
UserSettings userSettings; UserSettings userSettings;
@ -41,7 +44,9 @@ public class MainActivity extends AppCompatActivity {
return insets; return insets;
}); });
ksLogger.info("MainActivity started!"); logger = loggerFactory.create("MainActivity");
logger.info("MainActivity started!");
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav); BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav);
@ -59,9 +64,9 @@ public class MainActivity extends AppCompatActivity {
// Check logged in // Check logged in
if (userSettings.getAppCommonSetting().isLoggedIn()) { if (userSettings.getAppCommonSetting().isLoggedIn()) {
ksLogger.info("User is logged in!"); logger.info("User is logged in!");
} else { } else {
ksLogger.info("User is not logged in!"); logger.info("User is not logged in!");
Intent intent = new Intent(this, LoginActivity.class); Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent); startActivity(intent);

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import one.nem.kidshift.model.ChildModel; import one.nem.kidshift.model.ChildModel;
import one.nem.kidshift.model.callback.ChildModelCallback;
public interface ChildData { public interface ChildData {
@ -18,7 +19,7 @@ public interface ChildData {
* 子ユーザー一覧取得 * 子ユーザー一覧取得
* @return List<ChildModel> 子ユーザー一覧 * @return List<ChildModel> 子ユーザー一覧
*/ */
CompletableFuture<List<ChildModel>> getChildList(); CompletableFuture<List<ChildModel>> getChildList(ChildModelCallback callback);
/** /**
* 子ユーザー情報更新 * 子ユーザー情報更新

View File

@ -1,30 +1,37 @@
package one.nem.kidshift.data.impl; package one.nem.kidshift.data.impl;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import one.nem.kidshift.data.ChildData; import one.nem.kidshift.data.ChildData;
import one.nem.kidshift.data.KSActions;
import one.nem.kidshift.data.retrofit.KidShiftApiService; import one.nem.kidshift.data.retrofit.KidShiftApiService;
import one.nem.kidshift.data.retrofit.model.child.ChildListResponse; import one.nem.kidshift.data.retrofit.model.child.ChildListResponse;
import one.nem.kidshift.data.retrofit.model.converter.ChildModelConverter; import one.nem.kidshift.data.retrofit.model.converter.ChildModelConverter;
import one.nem.kidshift.data.room.utils.CacheWrapper;
import one.nem.kidshift.model.ChildModel; import one.nem.kidshift.model.ChildModel;
import one.nem.kidshift.model.callback.ChildModelCallback;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Response; import retrofit2.Response;
public class ChildDataImpl implements ChildData { public class ChildDataImpl implements ChildData {
private KidShiftApiService kidShiftApiService; private final KSActions ksActions;
private final CacheWrapper cacheWrapper;
private KSLogger logger; private final KSLogger logger;
@Inject @Inject
public ChildDataImpl(KidShiftApiService kidShiftApiService, KSLogger logger) { public ChildDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) {
this.kidShiftApiService = kidShiftApiService; this.ksActions = ksActions;
this.logger = logger; this.cacheWrapper = cacheWrapper;
this.logger = loggerFactory.create("ChildDataImpl");
} }
@Override @Override
@ -33,21 +40,53 @@ public class ChildDataImpl implements ChildData {
} }
@Override @Override
public CompletableFuture<List<ChildModel>> getChildList() { // TODO-rca: DBにキャッシュするように修正する public CompletableFuture<List<ChildModel>> getChildList(ChildModelCallback callback) { // TODO: リファクタリング
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
Call<ChildListResponse> call = kidShiftApiService.getChildList(); logger.debug("子供リスト取得開始");
try { AtomicReference<List<ChildModel>> childListTmp = new AtomicReference<>();
Response<ChildListResponse> response = call.execute(); Thread thread = new Thread(() -> {
if (!response.isSuccessful()) return null; // TODO-rca: nullとするかは検討 ksActions.syncChildList().thenAccept(childList -> {
if (childListTmp.get() == null || childListTmp.get().isEmpty()) {
ChildListResponse body = response.body(); logger.debug("子供リスト取得完了: キャッシュよりはやく取得完了 or キャッシュ無し");
if (body == null) return null; if (childList == null || childList.isEmpty()) {
callback.onUnchanged();
return ChildModelConverter.childListResponseToChildModelList(body); } else {
} catch (Exception e) { callback.onUpdated(childList);
logger.error(e.getMessage()); }
return null; } else {
} boolean isChanged =
childList.size() != childListTmp.get().size() ||
childList.stream().anyMatch(child -> childListTmp.get().stream().noneMatch(childTmp -> child.getId().equals(childTmp.getId())));
if (isChanged) {
logger.debug("子供リスト取得完了: キャッシュと比較して変更あり");
callback.onUpdated(childList);
} else {
logger.debug("子供リスト取得完了: キャッシュと比較して変更なし");
callback.onUnchanged();
}
}
}).exceptionally(e -> {
logger.error("子供リスト取得失敗: " + e.getMessage());
callback.onFailed(e.getMessage());
return null;
});
});
thread.start();
return cacheWrapper.getChildList().thenApply(childList -> {
if (childList == null || childList.isEmpty()) {
try {
logger.debug("キャッシュ無: 子供リスト取得スレッド待機");
thread.join();
return cacheWrapper.getChildList().join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else {
logger.debug("キャッシュ有 (子供数: " + childList.size() + ")");
childListTmp.set(childList);
return childList;
}
}).join();
}); });
} }

View File

@ -19,23 +19,23 @@ import one.nem.kidshift.model.ChildModel;
import one.nem.kidshift.model.ParentModel; import one.nem.kidshift.model.ParentModel;
import one.nem.kidshift.model.tasks.TaskItemModel; import one.nem.kidshift.model.tasks.TaskItemModel;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Response; import retrofit2.Response;
public class KSActionsImpl implements KSActions { public class KSActionsImpl implements KSActions {
private UserSettings userSettings; private final UserSettings userSettings;
private KidShiftApiService kidShiftApiService; private final KidShiftApiService kidShiftApiService;
private KSLogger logger; private final KSLogger logger;
private CacheWrapper cacheWrapper; private final CacheWrapper cacheWrapper;
@Inject @Inject
public KSActionsImpl(UserSettings userSettings, KidShiftApiService kidShiftApiService, KSLogger logger, CacheWrapper cacheWrapper) { public KSActionsImpl(UserSettings userSettings, KidShiftApiService kidShiftApiService, KSLoggerFactory ksLoggerFactory, CacheWrapper cacheWrapper) {
this.userSettings = userSettings; this.userSettings = userSettings;
this.kidShiftApiService = kidShiftApiService; this.kidShiftApiService = kidShiftApiService;
this.logger = logger; this.logger = ksLoggerFactory.create("KSActionsImpl");
this.cacheWrapper = cacheWrapper; this.cacheWrapper = cacheWrapper;
logger.setTag("KSActions");
} }
@Override @Override

View File

@ -11,25 +11,21 @@ import one.nem.kidshift.data.retrofit.KidShiftApiService;
import one.nem.kidshift.model.ParentModel; import one.nem.kidshift.model.ParentModel;
import one.nem.kidshift.model.callback.ParentModelCallback; import one.nem.kidshift.model.callback.ParentModelCallback;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
public class ParentDataImpl implements ParentData { public class ParentDataImpl implements ParentData {
private KidShiftApiService kidshiftApiService; private final UserSettings userSettings;
private UserSettings userSettings; private final KSLogger logger;
private KSLogger logger; private final KSActions ksActions;
private KSActions ksActions;
@Inject @Inject
public ParentDataImpl(KidShiftApiService kidshiftApiService, UserSettings userSettings, KSLogger logger, KSActions ksActions) { public ParentDataImpl(KidShiftApiService kidshiftApiService, UserSettings userSettings, KSLoggerFactory ksLoggerFactory, KSActions ksActions) {
this.kidshiftApiService = kidshiftApiService;
this.userSettings = userSettings; this.userSettings = userSettings;
this.logger = logger; this.logger = ksLoggerFactory.create("ParentDataImpl");
this.ksActions = ksActions; this.ksActions = ksActions;
logger.setTag("ParentData");
} }
// 一旦キャッシュを返して, その後非同期でAPIから取得更新があればコールバックで通知 // 一旦キャッシュを返して, その後非同期でAPIから取得更新があればコールバックで通知

View File

@ -13,9 +13,6 @@ public class RewardDataDummyImpl implements RewardData {
private final Faker faker; private final Faker faker;
@Inject
KSLogger logger;
@Inject @Inject
public RewardDataDummyImpl() { public RewardDataDummyImpl() {
faker = new Faker(); faker = new Faker();

View File

@ -2,40 +2,63 @@ package one.nem.kidshift.data.impl;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.security.auth.callback.Callback;
import one.nem.kidshift.data.KSActions; import one.nem.kidshift.data.KSActions;
import one.nem.kidshift.data.TaskData; import one.nem.kidshift.data.TaskData;
import one.nem.kidshift.data.retrofit.model.converter.TaskModelConverter;
import one.nem.kidshift.data.retrofit.model.task.TaskListResponse;
import one.nem.kidshift.data.room.utils.CacheWrapper; import one.nem.kidshift.data.room.utils.CacheWrapper;
import one.nem.kidshift.model.callback.TaskItemModelCallback; import one.nem.kidshift.model.callback.TaskItemModelCallback;
import one.nem.kidshift.model.tasks.TaskItemModel; import one.nem.kidshift.model.tasks.TaskItemModel;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
public class TaskDataImpl implements TaskData { public class TaskDataImpl implements TaskData {
private KSActions ksActions; private final KSActions ksActions;
private CacheWrapper cacheWrapper; private final CacheWrapper cacheWrapper;
private KSLogger logger; private final KSLogger logger;
@Inject @Inject
public TaskDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLogger logger) { public TaskDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) {
this.ksActions = ksActions; this.ksActions = ksActions;
this.cacheWrapper = cacheWrapper; this.cacheWrapper = cacheWrapper;
this.logger = logger.setTag("TaskDataImpl"); this.logger = loggerFactory.create("TaskDataImpl");
} }
@Override @Override
public CompletableFuture<List<TaskItemModel>> getTasks(TaskItemModelCallback callback) { public CompletableFuture<List<TaskItemModel>> getTasks(TaskItemModelCallback callback) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
logger.debug("タスク取得開始"); logger.debug("タスク取得開始");
AtomicReference<List<TaskItemModel>> taskListTmp = new AtomicReference<>();
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {
// TODO-rca: ちゃんと比較して呼ぶ ksActions.syncTasks().thenAccept(taskList -> {
ksActions.syncTasks().thenAccept(callback::onUpdated); if (taskListTmp.get() == null || taskListTmp.get().isEmpty()) {
logger.debug("タスク取得完了: キャッシュよりはやく取得完了 or キャッシュ無し");
if (taskList == null || taskList.isEmpty()) {
callback.onUnchanged();
} else {
callback.onUpdated(taskList);
}
} else {
// キャッシュと比較して変更の有無を確認
boolean isChanged =
taskList.size() != taskListTmp.get().size() ||
taskList.stream().anyMatch(task -> taskListTmp.get().stream().noneMatch(taskTmp -> task.getId().equals(taskTmp.getId())));
if (isChanged) {
logger.debug("タスク取得完了: キャッシュと比較して変更あり");
callback.onUpdated(taskList);
} else {
logger.debug("タスク取得完了: キャッシュと比較して変更なし");
callback.onUnchanged();
}
}
}).exceptionally(e -> {
logger.error("タスク取得失敗: " + e.getMessage());
callback.onFailed(e.getMessage());
return null;
});
}); });
thread.start(); thread.start();
return cacheWrapper.getTaskList().thenApply(taskList -> { return cacheWrapper.getTaskList().thenApply(taskList -> {
@ -49,6 +72,7 @@ public class TaskDataImpl implements TaskData {
} }
} else { } else {
logger.debug("キャッシュ有 (タスク数: " + taskList.size() + ")"); logger.debug("キャッシュ有 (タスク数: " + taskList.size() + ")");
taskListTmp.set(taskList);
return taskList; return taskList;
} }
}).join(); }).join();

View File

@ -14,6 +14,7 @@ import okhttp3.OkHttpClient;
import one.nem.kidshift.data.UserSettings; import one.nem.kidshift.data.UserSettings;
import one.nem.kidshift.data.retrofit.interceptor.AuthorizationInterceptor; import one.nem.kidshift.data.retrofit.interceptor.AuthorizationInterceptor;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
@ -22,12 +23,12 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class KidShiftApiServiceModule { public class KidShiftApiServiceModule {
@Inject @Inject
KSLogger logger; KSLoggerFactory ksLoggerFactory;
@Provides @Provides
@Singleton @Singleton
public AuthorizationInterceptor provideAuthorizationInterceptor(UserSettings userSettings, KSLogger logger) { public AuthorizationInterceptor provideAuthorizationInterceptor(UserSettings userSettings, KSLoggerFactory ksLoggerFactory) {
return new AuthorizationInterceptor(userSettings, logger); return new AuthorizationInterceptor(userSettings, ksLoggerFactory);
} }
// Gson // Gson

View File

@ -12,6 +12,7 @@ import okhttp3.Interceptor;
import okhttp3.Response; import okhttp3.Response;
import one.nem.kidshift.data.UserSettings; import one.nem.kidshift.data.UserSettings;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
/** /**
* Authorization placeholderが指定されている場合にアクセストークンで置換するインターセプター * Authorization placeholderが指定されている場合にアクセストークンで置換するインターセプター
@ -25,10 +26,9 @@ public class AuthorizationInterceptor implements Interceptor {
private final UserSettings userSettings; private final UserSettings userSettings;
private final KSLogger logger; private final KSLogger logger;
public AuthorizationInterceptor(UserSettings userSettings, KSLogger logger) { public AuthorizationInterceptor(UserSettings userSettings, KSLoggerFactory loggerFactory) {
this.userSettings = userSettings; this.userSettings = userSettings;
this.logger = logger; this.logger = loggerFactory.create("Auth_Interceptor");
logger.setTag("Auth_Interceptor");
} }
@NonNull @NonNull

View File

@ -18,6 +18,7 @@ import one.nem.kidshift.data.room.utils.converter.TaskCacheConverter;
import one.nem.kidshift.model.ChildModel; import one.nem.kidshift.model.ChildModel;
import one.nem.kidshift.model.tasks.TaskItemModel; import one.nem.kidshift.model.tasks.TaskItemModel;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@Module @Module
@InstallIn(SingletonComponent.class) @InstallIn(SingletonComponent.class)
@ -27,9 +28,9 @@ public class CacheWrapper {
private KSLogger logger; private KSLogger logger;
@Inject @Inject
public CacheWrapper(KidShiftDatabase kidShiftDatabase, KSLogger logger) { public CacheWrapper(KidShiftDatabase kidShiftDatabase, KSLoggerFactory loggerFactory) {
this.kidShiftDatabase = kidShiftDatabase; this.kidShiftDatabase = kidShiftDatabase;
this.logger = logger; this.logger = loggerFactory.create("CacheWrapper");
} }
/** /**
@ -92,8 +93,8 @@ public class CacheWrapper {
*/ */
public CompletableFuture<List<ChildModel>> getChildList() { public CompletableFuture<List<ChildModel>> getChildList() {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
// Get a list of children from the database List<ChildCacheEntity> result = kidShiftDatabase.childCacheDao().getChildList();
return null; return ChildCacheConverter.childCacheEntityListToChildModelList(result);
}); });
} }

View File

@ -38,4 +38,12 @@ public class ChildCacheConverter {
public static ChildModel childCacheEntityToChildModel(ChildCacheEntity entity) { public static ChildModel childCacheEntityToChildModel(ChildCacheEntity entity) {
return new ChildModel(entity.id, entity.name); return new ChildModel(entity.id, entity.name);
} }
public static List<ChildModel> childCacheEntityListToChildModelList(List<ChildCacheEntity> result) {
List<ChildModel> childList = new ArrayList<>();
for (ChildCacheEntity entity : result) {
childList.add(childCacheEntityToChildModel(entity));
}
return childList;
}
} }

View File

@ -19,6 +19,7 @@ import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import one.nem.kidshift.data.RewardData; import one.nem.kidshift.data.RewardData;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
@ -29,7 +30,9 @@ import one.nem.kidshift.utils.KSLogger;
@AndroidEntryPoint @AndroidEntryPoint
public class ChildMainFragment extends Fragment { public class ChildMainFragment extends Fragment {
@Inject @Inject
KSLogger ksLogger; KSLoggerFactory loggerFactory;
private KSLogger logger;
@Inject @Inject
RewardData rewardData; RewardData rewardData;
@ -72,6 +75,8 @@ public class ChildMainFragment extends Fragment {
mParam1 = getArguments().getString(ARG_PARAM1); mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2); mParam2 = getArguments().getString(ARG_PARAM2);
} }
logger = loggerFactory.create("ChildMainFragment");
} }
@Override @Override
@ -86,11 +91,11 @@ public class ChildMainFragment extends Fragment {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
ksLogger.addTag("ChildMainFragment"); logger.addTag("ChildMainFragment");
Integer reward = rewardData.getTotalReward().join(); Integer reward = rewardData.getTotalReward().join();
ksLogger.debug("取得したデータ: " + reward); logger.debug("取得したデータ: " + reward);
Calendar cl = Calendar.getInstance(); Calendar cl = Calendar.getInstance();
TextView tr = view.findViewById(R.id.totalReward); TextView tr = view.findViewById(R.id.totalReward);

View File

@ -21,12 +21,16 @@ import one.nem.kidshift.feature.debug.adapter.DebugCommandListItemAdapter;
import one.nem.kidshift.feature.debug.model.DebugCommandItemModel; import one.nem.kidshift.feature.debug.model.DebugCommandItemModel;
import one.nem.kidshift.utils.FeatureFlag; import one.nem.kidshift.utils.FeatureFlag;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@AndroidEntryPoint @AndroidEntryPoint
public class DebugDebugConsoleFragment extends Fragment { public class DebugDebugConsoleFragment extends Fragment {
@Inject @Inject
KSLogger ksLogger; KSLoggerFactory loggerFactory;
private KSLogger ksLogger;
@Inject @Inject
FeatureFlag featureFlag; FeatureFlag featureFlag;
@ -40,6 +44,12 @@ public class DebugDebugConsoleFragment extends Fragment {
// Required empty public constructor // Required empty public constructor
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ksLogger = loggerFactory.create("DebugConsole");
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {

View File

@ -12,17 +12,26 @@ import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@AndroidEntryPoint @AndroidEntryPoint
public class DebugMainFragment extends Fragment { public class DebugMainFragment extends Fragment {
@Inject @Inject
KSLogger ksLogger; KSLoggerFactory loggerFactory;
private KSLogger logger;
public DebugMainFragment() { public DebugMainFragment() {
// Required empty public constructor // Required empty public constructor
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logger = loggerFactory.create("DebugMain");
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {

View File

@ -32,6 +32,7 @@ import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
@ -42,7 +43,9 @@ import one.nem.kidshift.utils.KSLogger;
public class DebugTempLoginFragment extends Fragment { public class DebugTempLoginFragment extends Fragment {
@Inject @Inject
KSLogger logger; KSLoggerFactory loggerFactory;
private KSLogger logger;
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
@ -91,8 +94,8 @@ public class DebugTempLoginFragment extends Fragment {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_debug_temp_login, container, false); View view = inflater.inflate(R.layout.fragment_debug_temp_login, container, false);
logger.setTag("Login");
this.logger = loggerFactory.create("DebugTempLoginFragment");
//xmlレイアウトからid取得 //xmlレイアウトからid取得
EditText id = (EditText) view.findViewById(R.id.idtext); EditText id = (EditText) view.findViewById(R.id.idtext);

View File

@ -19,7 +19,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import javax.inject.Inject; import javax.inject.Inject;
@ -29,8 +28,10 @@ import one.nem.kidshift.data.ChildData;
import one.nem.kidshift.data.ParentData; import one.nem.kidshift.data.ParentData;
import one.nem.kidshift.model.ChildModel; import one.nem.kidshift.model.ChildModel;
import one.nem.kidshift.model.ParentModel; import one.nem.kidshift.model.ParentModel;
import one.nem.kidshift.model.callback.ChildModelCallback;
import one.nem.kidshift.model.callback.ParentModelCallback; import one.nem.kidshift.model.callback.ParentModelCallback;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@AndroidEntryPoint @AndroidEntryPoint
public class SettingMainFragment extends Fragment { public class SettingMainFragment extends Fragment {
@ -42,7 +43,9 @@ public class SettingMainFragment extends Fragment {
ParentData parentData; ParentData parentData;
@Inject @Inject
KSLogger logger; KSLoggerFactory ksLoggerFactory;
private KSLogger logger;
TextView username; TextView username;
@ -56,6 +59,12 @@ public class SettingMainFragment extends Fragment {
// Required empty public constructor // Required empty public constructor
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logger = ksLoggerFactory.create("SettingMainFragment");
}
private CompletableFuture<Void> updateParentInfo(){ private CompletableFuture<Void> updateParentInfo(){
return parentData.getParent(new ParentModelCallback() { return parentData.getParent(new ParentModelCallback() {
@Override @Override
@ -81,7 +90,22 @@ public class SettingMainFragment extends Fragment {
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
private CompletableFuture<Void> updateChildInfo(){ private CompletableFuture<Void> updateChildInfo(){
return childData.getChildList().thenAccept(childModels -> { return childData.getChildList(new ChildModelCallback() {
@Override
public void onUnchanged() {
}
@Override
public void onUpdated(List<ChildModel> childModelList) {
}
@Override
public void onFailed(String message) {
}
}).thenAccept(childModels -> {
mainAdapter.setChildDataList(childModels); mainAdapter.setChildDataList(childModels);
requireActivity().runOnUiThread(() -> { requireActivity().runOnUiThread(() -> {
@ -107,66 +131,49 @@ public class SettingMainFragment extends Fragment {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_setting_main, container, false); View view = inflater.inflate(R.layout.fragment_setting_main, container, false);
username = view.findViewById(R.id.username); username = view.findViewById(R.id.username);
useradress = view.findViewById(R.id.useradress); useradress = view.findViewById(R.id.useradress);
RecyclerView recyclerView = view.findViewById(R.id.childrecyclerview); RecyclerView recyclerView = view.findViewById(R.id.childrecyclerview);
// Pull-to-refreshスワイプで更新 RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh_layout); recyclerView.setLayoutManager(layoutManager);
mainAdapter = new SettingAdapter();
recyclerView.setAdapter(mainAdapter);
recyclerView.setHasFixedSize(true); // Pull-to-refreshスワイプで更新
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh_layout);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); try {
recyclerView.setLayoutManager(layoutManager);
// List<ChildModel> child = childData.getChildList().join(); /*
TODO:
- コールバックの処理を実装
- 結果に応じてRecyclerViewを更新する
- キャッシュ受け取りの時にjoinでUIスレッドをブロックしないように
- Placeholderの表示?
- エラーハンドリング try catch文
- onFailed時にそれを通知
*/
mainAdapter = new SettingAdapter(); updateInfo();
recyclerView.setAdapter(mainAdapter);
swipeRefreshLayout.setOnRefreshListener(() ->{
try { updateInfo();
/* });
TODO:
- コールバックの処理を実装
- 結果に応じてRecyclerViewを更新する
- キャッシュ受け取りの時にjoinでUIスレッドをブロックしないように
- Placeholderの表示?
- エラーハンドリング try catch文
- onFailed時にそれを通知
*/
// updateParentInfo(); } catch (Exception e) {
// updateChildInfo(); //
}
updateInfo();
swipeRefreshLayout.setOnRefreshListener(() ->{
// updateParentInfo();
//
// updateChildInfo();
updateInfo();
//
// swipeRefreshLayout.setRefreshing(false);
});
// username.setText(parent.getName());
// useradress.setText(parent.getEmail());
} catch (Exception e) {
}
LayoutInflater inflater1 = requireActivity().getLayoutInflater(); LayoutInflater inflater1 = requireActivity().getLayoutInflater();
View view1 = inflater1.inflate(R.layout.add_child_list_dialog,null); View view1 = inflater1.inflate(R.layout.add_child_list_dialog,null);

View File

@ -0,0 +1,11 @@
package one.nem.kidshift.model.callback;
import java.util.List;
import one.nem.kidshift.model.ChildModel;
public interface ChildModelCallback {
void onUnchanged();
void onUpdated(List<ChildModel> childModelList);
void onFailed(String message);
}

View File

@ -5,9 +5,6 @@ import java.util.List;
import one.nem.kidshift.utils.models.LogModel; import one.nem.kidshift.utils.models.LogModel;
public interface KSLogger { public interface KSLogger {
KSLogger getChildLogger(String tag);
KSLogger get(String tag);
KSLogger setTag(String tag);
KSLogger addTag(String tag); KSLogger addTag(String tag);
List<LogModel> getHistory(); List<LogModel> getHistory();
void info(String message); void info(String message);

View File

@ -0,0 +1,10 @@
package one.nem.kidshift.utils.factory;
import dagger.assisted.AssistedFactory;
import one.nem.kidshift.utils.impl.KSLoggerImpl;
@AssistedFactory
public interface KSLoggerFactory {
KSLoggerImpl create(String name);
}

View File

@ -11,6 +11,7 @@ import javax.inject.Inject;
import dagger.hilt.android.qualifiers.ApplicationContext; import dagger.hilt.android.qualifiers.ApplicationContext;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
import one.nem.kidshift.utils.models.feature.FeatureFlagItemModel; import one.nem.kidshift.utils.models.feature.FeatureFlagItemModel;
import one.nem.kidshift.utils.FeatureFlag; import one.nem.kidshift.utils.FeatureFlag;
@ -40,10 +41,9 @@ public class FeatureFlagImpl implements FeatureFlag {
} }
@Inject @Inject
public FeatureFlagImpl(@ApplicationContext Context applicationContext, KSLogger logger) { public FeatureFlagImpl(@ApplicationContext Context applicationContext, KSLoggerFactory loggerFactory) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.logger = logger; this.logger = loggerFactory.create("FeatureFlag");
this.logger.setTag("FeatureFlagImpl");
this.sharedPreferences = applicationContext.getSharedPreferences("feat_flg", Context.MODE_PRIVATE); this.sharedPreferences = applicationContext.getSharedPreferences("feat_flg", Context.MODE_PRIVATE);
init(); init();
} }

View File

@ -5,10 +5,13 @@ import static one.nem.kidshift.utils.enums.LogLevelEnum.INFO;
import android.util.Log; import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.assisted.Assisted;
import dagger.assisted.AssistedInject;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.SharedPrefUtils; import one.nem.kidshift.utils.SharedPrefUtils;
import one.nem.kidshift.utils.enums.LogLevelEnum; import one.nem.kidshift.utils.enums.LogLevelEnum;
@ -21,32 +24,11 @@ public class KSLoggerImpl implements KSLogger {
private SharedPrefUtils sharedPrefUtils; private SharedPrefUtils sharedPrefUtils;
@Inject @AssistedInject
public KSLoggerImpl(SharedPrefUtilsFactory sharedPrefUtilsFactory) { public KSLoggerImpl(SharedPrefUtilsFactory sharedPrefUtilsFactory, @Assisted String name) {
tags.add("UNTAGGED"); sharedPrefUtils = sharedPrefUtilsFactory.create("KSLogger");
this.sharedPrefUtils = sharedPrefUtilsFactory.create("KSLogger");
}
public KSLoggerImpl(String tag) {
tags.add(tag);
}
@Override
public KSLogger getChildLogger(String tag) {
tags.add(tag);
return this;
}
@Override
public KSLogger get(String tag) {
return new KSLoggerImpl(tag);
}
@Override
public KSLogger setTag(String tag) {
tags.clear(); tags.clear();
tags.add(tag); tags.add(name);
return this;
} }
@Override @Override
@ -62,32 +44,32 @@ public class KSLoggerImpl implements KSLogger {
@Override @Override
public void info(String message) { public void info(String message) {
log(new LogModel(LogLevelEnum.INFO, new String[]{}, message)); log(new LogModel(LogLevelEnum.INFO, tags.toArray(new String[0]), message));
} }
@Override @Override
public void warn(String message) { public void warn(String message) {
log(new LogModel(LogLevelEnum.WARN, new String[]{}, message)); log(new LogModel(LogLevelEnum.WARN, tags.toArray(new String[0]), message));
} }
@Override @Override
public void error(String message) { public void error(String message) {
log(new LogModel(LogLevelEnum.ERROR, new String[]{}, message)); log(new LogModel(LogLevelEnum.ERROR, tags.toArray(new String[0]), message));
} }
@Override @Override
public void debug(String message) { public void debug(String message) {
log(new LogModel(LogLevelEnum.DEBUG, new String[]{}, message)); log(new LogModel(LogLevelEnum.DEBUG, tags.toArray(new String[0]), message));
} }
@Override @Override
public void trace(String message) { public void trace(String message) {
log(new LogModel(LogLevelEnum.TRACE, new String[]{}, message)); log(new LogModel(LogLevelEnum.TRACE, tags.toArray(new String[0]), message));
} }
@Override @Override
public void fatal(String message) { public void fatal(String message) {
log(new LogModel(LogLevelEnum.FATAL, new String[]{}, message)); log(new LogModel(LogLevelEnum.FATAL, tags.toArray(new String[0]), message));
} }
private void log(LogModel log) { private void log(LogModel log) {

View File

@ -1,16 +0,0 @@
package one.nem.kidshift.utils.modules;
import dagger.Binds;
import dagger.Module;
import dagger.hilt.InstallIn;
import dagger.hilt.components.SingletonComponent;
import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.impl.KSLoggerImpl;
@Module
@InstallIn(SingletonComponent.class)
abstract public class KSLoggerModule {
@Binds
public abstract KSLogger bindKSLogger(KSLoggerImpl ksLoggerImpl);
}