diff --git a/app/src/main/java/one/nem/lacerta/MainActivity.java b/app/src/main/java/one/nem/lacerta/MainActivity.java index 50c3be6d..404debd0 100644 --- a/app/src/main/java/one/nem/lacerta/MainActivity.java +++ b/app/src/main/java/one/nem/lacerta/MainActivity.java @@ -36,4 +36,5 @@ public class MainActivity extends AppCompatActivity { Toast.makeText(this, "testMessage", Toast.LENGTH_SHORT).show(); } + } \ No newline at end of file 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 f9791c76..c6a016d1 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 @@ -11,41 +11,42 @@ import java.util.stream.Collectors; import javax.inject.Inject; +import dagger.hilt.android.AndroidEntryPoint; +import dagger.hilt.android.qualifiers.ApplicationContext; + +@AndroidEntryPoint public class CommonImpl { - private final AppCompatActivity activity; - + @ApplicationContext @Inject - public CommonImpl(AppCompatActivity activity) { - this.activity = activity; - } + Context applicationContext; public String getStringValue(String key) { - SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE); + SharedPreferences pref = applicationContext.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 pref = applicationContext.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); + SharedPreferences pref = applicationContext.getSharedPreferences("common", Context.MODE_PRIVATE); return pref.contains(key); } public void remove(String key) { - SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE); + SharedPreferences pref = applicationContext.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); + SharedPreferences pref = applicationContext.getSharedPreferences("common", Context.MODE_PRIVATE); // キーだけをArrayListに切り出す return new ArrayList<>(pref.getAll().keySet()); } diff --git a/feature/debug/src/main/res/layout/fragment_debug_shared_pref_editor.xml b/feature/debug/src/main/res/layout/fragment_debug_shared_pref_editor.xml index 05aa4f39..7982d0ba 100644 --- a/feature/debug/src/main/res/layout/fragment_debug_shared_pref_editor.xml +++ b/feature/debug/src/main/res/layout/fragment_debug_shared_pref_editor.xml @@ -1,16 +1,69 @@ - + android:orientation="vertical" + tools:context=".DebugSharedPrefEditorFragment"> - - \ No newline at end of file + android:layout_height="wrap_content" + android:text="Save pref" /> + + + + + + + + + + + + + + + + + + + \ No newline at end of file