mirror of
				https://github.com/lacerta-doc/Lacerta.git
				synced 2025-10-30 23:10:48 +00:00 
			
		
		
		
	WIP Pref Editor
This commit is contained in:
		
							parent
							
								
									fd04610e6c
								
							
						
					
					
						commit
						f77e19556a
					
				| @ -36,4 +36,5 @@ public class MainActivity extends AppCompatActivity { | ||||
| 
 | ||||
|         Toast.makeText(this, "testMessage", Toast.LENGTH_SHORT).show(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -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<String> getExistKeys() { | ||||
|         SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE); | ||||
|         SharedPreferences pref = applicationContext.getSharedPreferences("common", Context.MODE_PRIVATE); | ||||
|         // キーだけをArrayListに切り出す | ||||
|         return new ArrayList<>(pref.getAll().keySet()); | ||||
|     } | ||||
|  | ||||
| @ -1,16 +1,69 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     tools:context=".DebugSharedPrefEditorFragment" > | ||||
|     android:orientation="vertical" | ||||
|     tools:context=".DebugSharedPrefEditorFragment"> | ||||
| 
 | ||||
|     <androidx.recyclerview.widget.RecyclerView | ||||
|     <com.google.android.material.textview.MaterialTextView | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         app:layout_constraintBottom_toBottomOf="parent" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="parent" /> | ||||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||||
|         android:layout_height="wrap_content" | ||||
|         android:text="Save pref" /> | ||||
| 
 | ||||
|     <LinearLayout | ||||
|         android:id="@+id/SaveLinearLayout" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:orientation="horizontal" | ||||
|         android:weightSum="3"> | ||||
| 
 | ||||
|         <EditText | ||||
|             android:id="@+id/saveKeyEditText" | ||||
|             android:layout_width="0dp" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_margin="4dp" | ||||
|             android:layout_weight="2" | ||||
|             android:hint="Key" /> | ||||
| 
 | ||||
|         <com.google.android.material.button.MaterialButton | ||||
|             android:id="@+id/saveButton" | ||||
|             android:layout_width="0dp" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_margin="4dp" | ||||
|             android:layout_weight="1" | ||||
|             android:lauout_weight="1" | ||||
|             android:text="Save" /> | ||||
|     </LinearLayout> | ||||
| 
 | ||||
|     <com.google.android.material.textview.MaterialTextView | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:text="Load pref" /> | ||||
| 
 | ||||
|     <LinearLayout | ||||
|         android:id="@+id/LoadLinearLayout" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:orientation="horizontal" | ||||
|         android:weightSum="3"> | ||||
| 
 | ||||
|         <EditText | ||||
|             android:id="@+id/loadKeyEditText" | ||||
|             android:layout_width="0dp" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_weight="2" | ||||
|             android:hint="Key" /> | ||||
| 
 | ||||
|         <com.google.android.material.button.MaterialButton | ||||
|             android:id="@+id/loadButton" | ||||
|             android:layout_width="0dp" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_weight="1" | ||||
|             android:lauout_weight="1" | ||||
|             android:text="Load" /> | ||||
|     </LinearLayout> | ||||
| 
 | ||||
| 
 | ||||
| </LinearLayout> | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user