From 9685f05c53ee457f2a3b70417169cff74852d05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 11 Dec 2023 12:32:35 +0900 Subject: [PATCH] =?UTF-8?q?SharedPref=20repo=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/data/impl/SharedPrefImpl.java | 26 +++++++++++++++++++ .../shared_pref/enums/SharedPrefType.java | 17 ++++++++++++ .../lacerta/data/module/SharedPrefModule.java | 17 ++++++++++++ .../lacerta/data/repository/SharedPref.java | 11 ++++++++ .../feature/debug/DebugMenuFragment.java | 26 ++----------------- 5 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 data/src/main/java/one/nem/lacerta/data/impl/SharedPrefImpl.java create mode 100644 data/src/main/java/one/nem/lacerta/data/model/shared_pref/enums/SharedPrefType.java create mode 100644 data/src/main/java/one/nem/lacerta/data/module/SharedPrefModule.java create mode 100644 data/src/main/java/one/nem/lacerta/data/repository/SharedPref.java diff --git a/data/src/main/java/one/nem/lacerta/data/impl/SharedPrefImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/SharedPrefImpl.java new file mode 100644 index 00000000..89d1f731 --- /dev/null +++ b/data/src/main/java/one/nem/lacerta/data/impl/SharedPrefImpl.java @@ -0,0 +1,26 @@ +package one.nem.lacerta.data.impl; + +import android.content.Context; +import android.content.SharedPreferences; + +import javax.inject.Inject; + +import dagger.hilt.android.qualifiers.ApplicationContext; +import one.nem.lacerta.data.repository.SharedPref; + +import one.nem.lacerta.data.model.shared_pref.enums.SharedPrefType; + +public class SharedPrefImpl implements SharedPref{ + + private Context applicationContext; + + @Inject + public SharedPrefImpl(@ApplicationContext Context applicationContext) { + this.applicationContext = applicationContext; + } + + @Override + public SharedPreferences getSharedPreferencesByTag(SharedPrefType sharedPrefType) { + return applicationContext.getSharedPreferences(SharedPrefType.COMMON.getTag(), Context.MODE_PRIVATE); + } +} diff --git a/data/src/main/java/one/nem/lacerta/data/model/shared_pref/enums/SharedPrefType.java b/data/src/main/java/one/nem/lacerta/data/model/shared_pref/enums/SharedPrefType.java new file mode 100644 index 00000000..c3612dc4 --- /dev/null +++ b/data/src/main/java/one/nem/lacerta/data/model/shared_pref/enums/SharedPrefType.java @@ -0,0 +1,17 @@ +package one.nem.lacerta.data.model.shared_pref.enums; + +public enum SharedPrefType { + + COMMON("common"), + USERDATA("userdata"); + + private String tag; + + SharedPrefType(String tag) { + this.tag = tag; + } + + public String getTag() { + return tag; + } +} diff --git a/data/src/main/java/one/nem/lacerta/data/module/SharedPrefModule.java b/data/src/main/java/one/nem/lacerta/data/module/SharedPrefModule.java new file mode 100644 index 00000000..f536fdf1 --- /dev/null +++ b/data/src/main/java/one/nem/lacerta/data/module/SharedPrefModule.java @@ -0,0 +1,17 @@ +package one.nem.lacerta.data.module; + +import android.content.Context; +import android.content.SharedPreferences; + +import dagger.Binds; +import dagger.Module; +import dagger.hilt.InstallIn; +import dagger.hilt.components.SingletonComponent; + +@Module +@InstallIn(SingletonComponent.class) +abstract public class SharedPrefModule { + + @Binds + abstract SharedPreferences bindSharedPreferences(Context applicationContext); +} diff --git a/data/src/main/java/one/nem/lacerta/data/repository/SharedPref.java b/data/src/main/java/one/nem/lacerta/data/repository/SharedPref.java new file mode 100644 index 00000000..fb635fa0 --- /dev/null +++ b/data/src/main/java/one/nem/lacerta/data/repository/SharedPref.java @@ -0,0 +1,11 @@ +package one.nem.lacerta.data.repository; + +import android.content.SharedPreferences; + +import one.nem.lacerta.data.model.shared_pref.enums.SharedPrefType; + +public interface SharedPref { + + // タグのTypoを防ぐ為にEnumで管理して取得させるやつ + SharedPreferences getSharedPreferencesByTag(SharedPrefType sharedPrefType); +} diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFragment.java index 5c1a8d1a..9682aff3 100644 --- a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFragment.java +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFragment.java @@ -30,34 +30,16 @@ public class DebugMenuFragment extends Fragment { @Inject DeviceMeta deviceMeta; + @Inject - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; public DebugMenuFragment() { // Required empty public constructor } - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment BlankFragment. - */ - // TODO: Rename and change types and number of parameters - public static DebugMenuFragment newInstance(String param1, String param2) { + public static DebugMenuFragment newInstance() { DebugMenuFragment fragment = new DebugMenuFragment(); Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @@ -65,10 +47,6 @@ public class DebugMenuFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } } @Override