mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-26 09:43:15 +00:00
SharedPref repoを作成
This commit is contained in:
parent
6fb9d77f70
commit
9685f05c53
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -30,34 +30,16 @@ public class DebugMenuFragment extends Fragment {
|
||||||
@Inject
|
@Inject
|
||||||
DeviceMeta deviceMeta;
|
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() {
|
public DebugMenuFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static DebugMenuFragment newInstance() {
|
||||||
* 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) {
|
|
||||||
DebugMenuFragment fragment = new DebugMenuFragment();
|
DebugMenuFragment fragment = new DebugMenuFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_PARAM1, param1);
|
|
||||||
args.putString(ARG_PARAM2, param2);
|
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
@ -65,10 +47,6 @@ public class DebugMenuFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments() != null) {
|
|
||||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
|
||||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user