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