From cb687d51e4d3836637f78d8bec5d82d467b5bd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 11 Dec 2023 10:49:21 +0900 Subject: [PATCH] =?UTF-8?q?Impl=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/source/pref/impl/CommonImpl.java | 51 +++++++++++++++++++ .../source/pref/repository/Common.java | 3 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/data/src/main/java/one/nem/lacerta/source/pref/impl/CommonImpl.java b/data/src/main/java/one/nem/lacerta/source/pref/impl/CommonImpl.java index c8aa14e8..f9791c76 100644 --- a/data/src/main/java/one/nem/lacerta/source/pref/impl/CommonImpl.java +++ b/data/src/main/java/one/nem/lacerta/source/pref/impl/CommonImpl.java @@ -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 getExistKeys() { + SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE); + // キーだけをArrayListに切り出す + return new ArrayList<>(pref.getAll().keySet()); + } + + + } diff --git a/data/src/main/java/one/nem/lacerta/source/pref/repository/Common.java b/data/src/main/java/one/nem/lacerta/source/pref/repository/Common.java index 3fb0f187..dec372d0 100644 --- a/data/src/main/java/one/nem/lacerta/source/pref/repository/Common.java +++ b/data/src/main/java/one/nem/lacerta/source/pref/repository/Common.java @@ -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 getExistKeys(); + ArrayList getExistKeys(); }