mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-02 11:37:37 +00:00
Impl実装
This commit is contained in:
2 files changed
+53
-1
No files matched your search
@@ -1,4 +1,55 @@
|
||||
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 {
|
||||
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface Common {
|
||||
@@ -13,5 +14,5 @@ public interface Common {
|
||||
|
||||
void remove(String key);
|
||||
|
||||
List<String> getExistKeys();
|
||||
ArrayList<String> getExistKeys();
|
||||
}
|
||||
Reference in new issue
Block a user