mirror of
				https://github.com/lacerta-doc/Lacerta.git
				synced 2025-11-04 08:50:47 +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();
 | 
					        Toast.makeText(this, "testMessage", Toast.LENGTH_SHORT).show();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -11,41 +11,42 @@ import java.util.stream.Collectors;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import javax.inject.Inject;
 | 
					import javax.inject.Inject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import dagger.hilt.android.AndroidEntryPoint;
 | 
				
			||||||
 | 
					import dagger.hilt.android.qualifiers.ApplicationContext;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@AndroidEntryPoint
 | 
				
			||||||
public class CommonImpl {
 | 
					public class CommonImpl {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final AppCompatActivity activity;
 | 
					    @ApplicationContext
 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Inject
 | 
					    @Inject
 | 
				
			||||||
    public CommonImpl(AppCompatActivity activity) {
 | 
					    Context applicationContext;
 | 
				
			||||||
        this.activity = activity;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getStringValue(String key) {
 | 
					    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, "");
 | 
					        return pref.getString(key, "");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setStringValue(String key, String value) {
 | 
					    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();
 | 
					        SharedPreferences.Editor editor = pref.edit();
 | 
				
			||||||
        editor.putString(key, value);
 | 
					        editor.putString(key, value);
 | 
				
			||||||
        editor.apply();
 | 
					        editor.apply();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isExist(String key) {
 | 
					    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);
 | 
					        return pref.contains(key);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void remove(String 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();
 | 
					        SharedPreferences.Editor editor = pref.edit();
 | 
				
			||||||
        editor.remove(key);
 | 
					        editor.remove(key);
 | 
				
			||||||
        editor.apply();
 | 
					        editor.apply();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public ArrayList<String> getExistKeys() {
 | 
					    public ArrayList<String> getExistKeys() {
 | 
				
			||||||
        SharedPreferences pref = activity.getSharedPreferences("common", Context.MODE_PRIVATE);
 | 
					        SharedPreferences pref = applicationContext.getSharedPreferences("common", Context.MODE_PRIVATE);
 | 
				
			||||||
        // キーだけをArrayListに切り出す
 | 
					        // キーだけをArrayListに切り出す
 | 
				
			||||||
        return new ArrayList<>(pref.getAll().keySet());
 | 
					        return new ArrayList<>(pref.getAll().keySet());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,16 +1,69 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="utf-8"?>
 | 
					<?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:app="http://schemas.android.com/apk/res-auto"
 | 
				
			||||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
					    xmlns:tools="http://schemas.android.com/tools"
 | 
				
			||||||
    android:layout_width="match_parent"
 | 
					    android:layout_width="match_parent"
 | 
				
			||||||
    android:layout_height="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_width="match_parent"
 | 
				
			||||||
        android:layout_height="match_parent"
 | 
					        android:layout_height="wrap_content"
 | 
				
			||||||
        app:layout_constraintBottom_toBottomOf="parent"
 | 
					        android:text="Save pref" />
 | 
				
			||||||
        app:layout_constraintEnd_toEndOf="parent"
 | 
					
 | 
				
			||||||
        app:layout_constraintStart_toStartOf="parent"
 | 
					    <LinearLayout
 | 
				
			||||||
        app:layout_constraintTop_toTopOf="parent" />
 | 
					        android:id="@+id/SaveLinearLayout"
 | 
				
			||||||
</androidx.constraintlayout.widget.ConstraintLayout>
 | 
					        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