Merge remote-tracking branch 'origin/feature/updateupdate' into feature/updateupdate
# Conflicts: # feature/parent/src/main/java/one/nem/kidshift/feature/parent/ParentMainFragment.java
This commit is contained in:
commit
30b906d284
|
@ -9,6 +9,7 @@ import javax.inject.Inject;
|
|||
import dagger.hilt.android.HiltAndroidApp;
|
||||
import one.nem.kidshift.utils.FeatureFlag;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
@HiltAndroidApp
|
||||
public class KidShiftApplication extends Application {
|
||||
|
@ -17,13 +18,16 @@ public class KidShiftApplication extends Application {
|
|||
FeatureFlag featureFlag;
|
||||
|
||||
@Inject
|
||||
KSLogger logger;
|
||||
KSLoggerFactory loggerFactory;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
logger.setTag("KidShiftApplication");
|
||||
this.logger = loggerFactory.create("KidShiftApplication");
|
||||
|
||||
logger.info("super.onCreate() completed");
|
||||
|
||||
if(featureFlag.isEnabled("dynamicColorEnable")) {
|
||||
|
|
|
@ -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.ParentLoginResponse;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
@ -28,7 +29,9 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
|||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
@Inject
|
||||
KSLogger logger;
|
||||
KSLoggerFactory loggerFactory;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
@Inject
|
||||
UserSettings userSettings;
|
||||
|
@ -44,6 +47,8 @@ public class LoginActivity extends AppCompatActivity {
|
|||
return insets;
|
||||
});
|
||||
|
||||
logger = loggerFactory.create("LoginActivity");
|
||||
|
||||
// Retrofit init
|
||||
KidShiftApiService apiService = new Retrofit.Builder()
|
||||
.baseUrl("https://kidshift-beta.nem.one/")
|
||||
|
|
|
@ -20,12 +20,15 @@ import javax.inject.Inject;
|
|||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Inject
|
||||
KSLogger ksLogger;
|
||||
KSLoggerFactory loggerFactory;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
@Inject
|
||||
UserSettings userSettings;
|
||||
|
@ -41,7 +44,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
return insets;
|
||||
});
|
||||
|
||||
ksLogger.info("MainActivity started!");
|
||||
logger = loggerFactory.create("MainActivity");
|
||||
|
||||
logger.info("MainActivity started!");
|
||||
|
||||
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav);
|
||||
|
||||
|
@ -59,9 +64,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
// Check logged in
|
||||
if (userSettings.getAppCommonSetting().isLoggedIn()) {
|
||||
ksLogger.info("User is logged in!");
|
||||
logger.info("User is logged in!");
|
||||
} else {
|
||||
ksLogger.info("User is not logged in!");
|
||||
logger.info("User is not logged in!");
|
||||
|
||||
Intent intent = new Intent(this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import one.nem.kidshift.model.ChildModel;
|
||||
import one.nem.kidshift.model.callback.ChildModelCallback;
|
||||
|
||||
public interface ChildData {
|
||||
|
||||
|
@ -18,7 +19,7 @@ public interface ChildData {
|
|||
* 子ユーザー一覧取得
|
||||
* @return List<ChildModel> 子ユーザー一覧
|
||||
*/
|
||||
CompletableFuture<List<ChildModel>> getChildList();
|
||||
CompletableFuture<List<ChildModel>> getChildList(ChildModelCallback callback);
|
||||
|
||||
/**
|
||||
* 子ユーザー情報更新
|
||||
|
|
|
@ -1,30 +1,37 @@
|
|||
package one.nem.kidshift.data.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
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.model.child.ChildListResponse;
|
||||
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.callback.ChildModelCallback;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class ChildDataImpl implements ChildData {
|
||||
|
||||
private KidShiftApiService kidShiftApiService;
|
||||
|
||||
private KSLogger logger;
|
||||
private final KSActions ksActions;
|
||||
private final CacheWrapper cacheWrapper;
|
||||
private final KSLogger logger;
|
||||
|
||||
@Inject
|
||||
public ChildDataImpl(KidShiftApiService kidShiftApiService, KSLogger logger) {
|
||||
this.kidShiftApiService = kidShiftApiService;
|
||||
this.logger = logger;
|
||||
public ChildDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) {
|
||||
this.ksActions = ksActions;
|
||||
this.cacheWrapper = cacheWrapper;
|
||||
this.logger = loggerFactory.create("ChildDataImpl");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,21 +40,53 @@ public class ChildDataImpl implements ChildData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<ChildModel>> getChildList() { // TODO-rca: DBにキャッシュするように修正する
|
||||
public CompletableFuture<List<ChildModel>> getChildList(ChildModelCallback callback) { // TODO: リファクタリング
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Call<ChildListResponse> call = kidShiftApiService.getChildList();
|
||||
try {
|
||||
Response<ChildListResponse> response = call.execute();
|
||||
if (!response.isSuccessful()) return null; // TODO-rca: nullとするかは検討
|
||||
|
||||
ChildListResponse body = response.body();
|
||||
if (body == null) return null;
|
||||
|
||||
return ChildModelConverter.childListResponseToChildModelList(body);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
return null;
|
||||
logger.debug("子供リスト取得開始");
|
||||
AtomicReference<List<ChildModel>> childListTmp = new AtomicReference<>();
|
||||
Thread thread = new Thread(() -> {
|
||||
ksActions.syncChildList().thenAccept(childList -> {
|
||||
if (childListTmp.get() == null || childListTmp.get().isEmpty()) {
|
||||
logger.debug("子供リスト取得完了: キャッシュよりはやく取得完了 or キャッシュ無し");
|
||||
if (childList == null || childList.isEmpty()) {
|
||||
callback.onUnchanged();
|
||||
} else {
|
||||
callback.onUpdated(childList);
|
||||
}
|
||||
} 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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -19,23 +19,23 @@ import one.nem.kidshift.model.ChildModel;
|
|||
import one.nem.kidshift.model.ParentModel;
|
||||
import one.nem.kidshift.model.tasks.TaskItemModel;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class KSActionsImpl implements KSActions {
|
||||
|
||||
private UserSettings userSettings;
|
||||
private KidShiftApiService kidShiftApiService;
|
||||
private KSLogger logger;
|
||||
private CacheWrapper cacheWrapper;
|
||||
private final UserSettings userSettings;
|
||||
private final KidShiftApiService kidShiftApiService;
|
||||
private final KSLogger logger;
|
||||
private final CacheWrapper cacheWrapper;
|
||||
|
||||
@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.kidShiftApiService = kidShiftApiService;
|
||||
this.logger = logger;
|
||||
this.logger = ksLoggerFactory.create("KSActionsImpl");
|
||||
this.cacheWrapper = cacheWrapper;
|
||||
logger.setTag("KSActions");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,25 +11,21 @@ import one.nem.kidshift.data.retrofit.KidShiftApiService;
|
|||
import one.nem.kidshift.model.ParentModel;
|
||||
import one.nem.kidshift.model.callback.ParentModelCallback;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
public class ParentDataImpl implements ParentData {
|
||||
|
||||
private KidShiftApiService kidshiftApiService;
|
||||
private final UserSettings userSettings;
|
||||
|
||||
private UserSettings userSettings;
|
||||
private final KSLogger logger;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
private KSActions ksActions;
|
||||
private final KSActions ksActions;
|
||||
|
||||
@Inject
|
||||
public ParentDataImpl(KidShiftApiService kidshiftApiService, UserSettings userSettings, KSLogger logger, KSActions ksActions) {
|
||||
this.kidshiftApiService = kidshiftApiService;
|
||||
public ParentDataImpl(KidShiftApiService kidshiftApiService, UserSettings userSettings, KSLoggerFactory ksLoggerFactory, KSActions ksActions) {
|
||||
this.userSettings = userSettings;
|
||||
this.logger = logger;
|
||||
this.logger = ksLoggerFactory.create("ParentDataImpl");
|
||||
this.ksActions = ksActions;
|
||||
|
||||
logger.setTag("ParentData");
|
||||
}
|
||||
|
||||
// 一旦キャッシュを返して, その後非同期でAPIから取得→更新があればコールバックで通知
|
||||
|
|
|
@ -13,9 +13,6 @@ public class RewardDataDummyImpl implements RewardData {
|
|||
|
||||
private final Faker faker;
|
||||
|
||||
@Inject
|
||||
KSLogger logger;
|
||||
|
||||
@Inject
|
||||
public RewardDataDummyImpl() {
|
||||
faker = new Faker();
|
||||
|
|
|
@ -2,40 +2,63 @@ package one.nem.kidshift.data.impl;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.security.auth.callback.Callback;
|
||||
|
||||
import one.nem.kidshift.data.KSActions;
|
||||
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.model.callback.TaskItemModelCallback;
|
||||
import one.nem.kidshift.model.tasks.TaskItemModel;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
public class TaskDataImpl implements TaskData {
|
||||
|
||||
private KSActions ksActions;
|
||||
private CacheWrapper cacheWrapper;
|
||||
private KSLogger logger;
|
||||
private final KSActions ksActions;
|
||||
private final CacheWrapper cacheWrapper;
|
||||
private final KSLogger logger;
|
||||
|
||||
@Inject
|
||||
public TaskDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLogger logger) {
|
||||
public TaskDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) {
|
||||
this.ksActions = ksActions;
|
||||
this.cacheWrapper = cacheWrapper;
|
||||
this.logger = logger.setTag("TaskDataImpl");
|
||||
this.logger = loggerFactory.create("TaskDataImpl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<TaskItemModel>> getTasks(TaskItemModelCallback callback) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
logger.debug("タスク取得開始");
|
||||
AtomicReference<List<TaskItemModel>> taskListTmp = new AtomicReference<>();
|
||||
Thread thread = new Thread(() -> {
|
||||
// TODO-rca: ちゃんと比較して呼ぶ
|
||||
ksActions.syncTasks().thenAccept(callback::onUpdated);
|
||||
ksActions.syncTasks().thenAccept(taskList -> {
|
||||
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();
|
||||
return cacheWrapper.getTaskList().thenApply(taskList -> {
|
||||
|
@ -49,6 +72,7 @@ public class TaskDataImpl implements TaskData {
|
|||
}
|
||||
} else {
|
||||
logger.debug("キャッシュ有 (タスク数: " + taskList.size() + ")");
|
||||
taskListTmp.set(taskList);
|
||||
return taskList;
|
||||
}
|
||||
}).join();
|
||||
|
|
|
@ -14,6 +14,7 @@ import okhttp3.OkHttpClient;
|
|||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.data.retrofit.interceptor.AuthorizationInterceptor;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
|
@ -22,12 +23,12 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
|||
public class KidShiftApiServiceModule {
|
||||
|
||||
@Inject
|
||||
KSLogger logger;
|
||||
KSLoggerFactory ksLoggerFactory;
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public AuthorizationInterceptor provideAuthorizationInterceptor(UserSettings userSettings, KSLogger logger) {
|
||||
return new AuthorizationInterceptor(userSettings, logger);
|
||||
public AuthorizationInterceptor provideAuthorizationInterceptor(UserSettings userSettings, KSLoggerFactory ksLoggerFactory) {
|
||||
return new AuthorizationInterceptor(userSettings, ksLoggerFactory);
|
||||
}
|
||||
|
||||
// Gson
|
||||
|
|
|
@ -12,6 +12,7 @@ import okhttp3.Interceptor;
|
|||
import okhttp3.Response;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
/**
|
||||
* Authorization placeholderが指定されている場合にアクセストークンで置換するインターセプター
|
||||
|
@ -25,10 +26,9 @@ public class AuthorizationInterceptor implements Interceptor {
|
|||
private final UserSettings userSettings;
|
||||
private final KSLogger logger;
|
||||
|
||||
public AuthorizationInterceptor(UserSettings userSettings, KSLogger logger) {
|
||||
public AuthorizationInterceptor(UserSettings userSettings, KSLoggerFactory loggerFactory) {
|
||||
this.userSettings = userSettings;
|
||||
this.logger = logger;
|
||||
logger.setTag("Auth_Interceptor");
|
||||
this.logger = loggerFactory.create("Auth_Interceptor");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
@ -18,6 +18,7 @@ import one.nem.kidshift.data.room.utils.converter.TaskCacheConverter;
|
|||
import one.nem.kidshift.model.ChildModel;
|
||||
import one.nem.kidshift.model.tasks.TaskItemModel;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
|
@ -27,9 +28,9 @@ public class CacheWrapper {
|
|||
private KSLogger logger;
|
||||
|
||||
@Inject
|
||||
public CacheWrapper(KidShiftDatabase kidShiftDatabase, KSLogger logger) {
|
||||
public CacheWrapper(KidShiftDatabase kidShiftDatabase, KSLoggerFactory loggerFactory) {
|
||||
this.kidShiftDatabase = kidShiftDatabase;
|
||||
this.logger = logger;
|
||||
this.logger = loggerFactory.create("CacheWrapper");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,8 +93,8 @@ public class CacheWrapper {
|
|||
*/
|
||||
public CompletableFuture<List<ChildModel>> getChildList() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
// Get a list of children from the database
|
||||
return null;
|
||||
List<ChildCacheEntity> result = kidShiftDatabase.childCacheDao().getChildList();
|
||||
return ChildCacheConverter.childCacheEntityListToChildModelList(result);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -38,4 +38,12 @@ public class ChildCacheConverter {
|
|||
public static ChildModel childCacheEntityToChildModel(ChildCacheEntity entity) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import javax.inject.Inject;
|
|||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.kidshift.data.RewardData;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
|
@ -29,7 +30,9 @@ import one.nem.kidshift.utils.KSLogger;
|
|||
@AndroidEntryPoint
|
||||
public class ChildMainFragment extends Fragment {
|
||||
@Inject
|
||||
KSLogger ksLogger;
|
||||
KSLoggerFactory loggerFactory;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
@Inject
|
||||
RewardData rewardData;
|
||||
|
@ -72,6 +75,8 @@ public class ChildMainFragment extends Fragment {
|
|||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
|
||||
logger = loggerFactory.create("ChildMainFragment");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,11 +91,11 @@ public class ChildMainFragment extends Fragment {
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
|
||||
ksLogger.addTag("ChildMainFragment");
|
||||
logger.addTag("ChildMainFragment");
|
||||
|
||||
Integer reward = rewardData.getTotalReward().join();
|
||||
|
||||
ksLogger.debug("取得したデータ: " + reward);
|
||||
logger.debug("取得したデータ: " + reward);
|
||||
|
||||
Calendar cl = Calendar.getInstance();
|
||||
TextView tr = view.findViewById(R.id.totalReward);
|
||||
|
|
|
@ -21,12 +21,16 @@ import one.nem.kidshift.feature.debug.adapter.DebugCommandListItemAdapter;
|
|||
import one.nem.kidshift.feature.debug.model.DebugCommandItemModel;
|
||||
import one.nem.kidshift.utils.FeatureFlag;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class DebugDebugConsoleFragment extends Fragment {
|
||||
|
||||
@Inject
|
||||
KSLogger ksLogger;
|
||||
KSLoggerFactory loggerFactory;
|
||||
|
||||
private KSLogger ksLogger;
|
||||
|
||||
@Inject
|
||||
FeatureFlag featureFlag;
|
||||
|
||||
|
@ -40,6 +44,12 @@ public class DebugDebugConsoleFragment extends Fragment {
|
|||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ksLogger = loggerFactory.create("DebugConsole");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
|
|
@ -12,17 +12,26 @@ import javax.inject.Inject;
|
|||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class DebugMainFragment extends Fragment {
|
||||
|
||||
@Inject
|
||||
KSLogger ksLogger;
|
||||
KSLoggerFactory loggerFactory;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
public DebugMainFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
logger = loggerFactory.create("DebugMain");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import javax.inject.Inject;
|
|||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
|
@ -42,7 +43,9 @@ import one.nem.kidshift.utils.KSLogger;
|
|||
public class DebugTempLoginFragment extends Fragment {
|
||||
|
||||
@Inject
|
||||
KSLogger logger;
|
||||
KSLoggerFactory loggerFactory;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
|
@ -91,8 +94,8 @@ public class DebugTempLoginFragment extends Fragment {
|
|||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_debug_temp_login, container, false);
|
||||
|
||||
logger.setTag("Login");
|
||||
|
||||
this.logger = loggerFactory.create("DebugTempLoginFragment");
|
||||
|
||||
//xmlレイアウトからid取得
|
||||
EditText id = (EditText) view.findViewById(R.id.idtext);
|
||||
|
|
|
@ -19,7 +19,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -29,8 +28,10 @@ import one.nem.kidshift.data.ChildData;
|
|||
import one.nem.kidshift.data.ParentData;
|
||||
import one.nem.kidshift.model.ChildModel;
|
||||
import one.nem.kidshift.model.ParentModel;
|
||||
import one.nem.kidshift.model.callback.ChildModelCallback;
|
||||
import one.nem.kidshift.model.callback.ParentModelCallback;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.factory.KSLoggerFactory;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class SettingMainFragment extends Fragment {
|
||||
|
@ -42,7 +43,9 @@ public class SettingMainFragment extends Fragment {
|
|||
ParentData parentData;
|
||||
|
||||
@Inject
|
||||
KSLogger logger;
|
||||
KSLoggerFactory ksLoggerFactory;
|
||||
|
||||
private KSLogger logger;
|
||||
|
||||
TextView username;
|
||||
|
||||
|
@ -56,6 +59,12 @@ public class SettingMainFragment extends Fragment {
|
|||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
logger = ksLoggerFactory.create("SettingMainFragment");
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> updateParentInfo(){
|
||||
return parentData.getParent(new ParentModelCallback() {
|
||||
@Override
|
||||
|
@ -81,7 +90,22 @@ public class SettingMainFragment extends Fragment {
|
|||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
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);
|
||||
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
|
@ -118,20 +142,14 @@ public class SettingMainFragment extends Fragment {
|
|||
|
||||
RecyclerView recyclerView = view.findViewById(R.id.childrecyclerview);
|
||||
|
||||
// Pull-to-refresh(スワイプで更新)
|
||||
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh_layout);
|
||||
|
||||
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
// List<ChildModel> child = childData.getChildList().join();
|
||||
|
||||
mainAdapter = new SettingAdapter();
|
||||
recyclerView.setAdapter(mainAdapter);
|
||||
|
||||
// Pull-to-refresh(スワイプで更新)
|
||||
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh_layout);
|
||||
|
||||
try {
|
||||
|
||||
|
@ -145,27 +163,16 @@ public class SettingMainFragment extends Fragment {
|
|||
- onFailed時にそれを通知
|
||||
*/
|
||||
|
||||
// updateParentInfo();
|
||||
// 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();
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -5,9 +5,6 @@ import java.util.List;
|
|||
import one.nem.kidshift.utils.models.LogModel;
|
||||
|
||||
public interface KSLogger {
|
||||
KSLogger getChildLogger(String tag);
|
||||
KSLogger get(String tag);
|
||||
KSLogger setTag(String tag);
|
||||
KSLogger addTag(String tag);
|
||||
List<LogModel> getHistory();
|
||||
void info(String message);
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -11,6 +11,7 @@ import javax.inject.Inject;
|
|||
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext;
|
||||
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.FeatureFlag;
|
||||
|
||||
|
@ -40,10 +41,9 @@ public class FeatureFlagImpl implements FeatureFlag {
|
|||
}
|
||||
|
||||
@Inject
|
||||
public FeatureFlagImpl(@ApplicationContext Context applicationContext, KSLogger logger) {
|
||||
public FeatureFlagImpl(@ApplicationContext Context applicationContext, KSLoggerFactory loggerFactory) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.logger = logger;
|
||||
this.logger.setTag("FeatureFlagImpl");
|
||||
this.logger = loggerFactory.create("FeatureFlag");
|
||||
this.sharedPreferences = applicationContext.getSharedPreferences("feat_flg", Context.MODE_PRIVATE);
|
||||
init();
|
||||
}
|
||||
|
|
|
@ -5,10 +5,13 @@ import static one.nem.kidshift.utils.enums.LogLevelEnum.INFO;
|
|||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import one.nem.kidshift.utils.SharedPrefUtils;
|
||||
import one.nem.kidshift.utils.enums.LogLevelEnum;
|
||||
|
@ -21,32 +24,11 @@ public class KSLoggerImpl implements KSLogger {
|
|||
|
||||
private SharedPrefUtils sharedPrefUtils;
|
||||
|
||||
@Inject
|
||||
public KSLoggerImpl(SharedPrefUtilsFactory sharedPrefUtilsFactory) {
|
||||
tags.add("UNTAGGED");
|
||||
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) {
|
||||
@AssistedInject
|
||||
public KSLoggerImpl(SharedPrefUtilsFactory sharedPrefUtilsFactory, @Assisted String name) {
|
||||
sharedPrefUtils = sharedPrefUtilsFactory.create("KSLogger");
|
||||
tags.clear();
|
||||
tags.add(tag);
|
||||
return this;
|
||||
tags.add(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,32 +44,32 @@ public class KSLoggerImpl implements KSLogger {
|
|||
|
||||
@Override
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user