mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-02 11:37:37 +00:00
SharedPref repoを作成
This commit is contained in:
5 files changed
+73
-24
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user