mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
Impl実装
This commit is contained in:
parent
e37328e1f5
commit
cb687d51e4
|
@ -1,4 +1,55 @@
|
||||||
package one.nem.lacerta.source.pref.impl;
|
package one.nem.lacerta.source.pref.impl;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
public class CommonImpl {
|
public class CommonImpl {
|
||||||
|
|
||||||
|
private final AppCompatActivity activity;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public CommonImpl(AppCompatActivity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringValue(String key) {
|
||||||
|
SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE);
|
||||||
|
return pref.getString(key, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStringValue(String key, String value) {
|
||||||
|
SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = pref.edit();
|
||||||
|
editor.putString(key, value);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExist(String key) {
|
||||||
|
SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE);
|
||||||
|
return pref.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(String key) {
|
||||||
|
SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = pref.edit();
|
||||||
|
editor.remove(key);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getExistKeys() {
|
||||||
|
SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE);
|
||||||
|
// キーだけをArrayListに切り出す
|
||||||
|
return new ArrayList<>(pref.getAll().keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package one.nem.lacerta.source.pref.repository;
|
package one.nem.lacerta.source.pref.repository;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface Common {
|
public interface Common {
|
||||||
|
@ -13,5 +14,5 @@ public interface Common {
|
||||||
|
|
||||||
void remove(String key);
|
void remove(String key);
|
||||||
|
|
||||||
List<String> getExistKeys();
|
ArrayList<String> getExistKeys();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user