PrefのListを表示するように

This commit is contained in:
ろむねこ 2023-12-11 12:56:47 +09:00
parent 00aa51e082
commit 7a3c6daf3d
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168

View File

@ -12,6 +12,10 @@ import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.Map;
import one.nem.lacerta.data.model.shared_pref.enums.SharedPrefType; import one.nem.lacerta.data.model.shared_pref.enums.SharedPrefType;
import one.nem.lacerta.source.pref.repository.Common; //TODO-rca: 名前変えるべきかも import one.nem.lacerta.source.pref.repository.Common; //TODO-rca: 名前変えるべきかも
@ -68,6 +72,8 @@ public class DebugSharedPrefEditorFragment extends Fragment {
EditText loadKeyEditText = view.findViewById(R.id.loadKeyEditText); EditText loadKeyEditText = view.findViewById(R.id.loadKeyEditText);
EditText saveKeyEditText = view.findViewById(R.id.saveKeyEditText); EditText saveKeyEditText = view.findViewById(R.id.saveKeyEditText);
TextView loadValueTextView = view.findViewById(R.id.loadValueTextView);
view.findViewById(R.id.loadButton).setOnClickListener(v -> { view.findViewById(R.id.loadButton).setOnClickListener(v -> {
String value = sharedPref.getSharedPreferencesByTag(sharedPrefType).getString(loadKeyEditText.getText().toString(), "null"); String value = sharedPref.getSharedPreferencesByTag(sharedPrefType).getString(loadKeyEditText.getText().toString(), "null");
((TextView) view.findViewById(R.id.loadValueTextView)).setText(value); ((TextView) view.findViewById(R.id.loadValueTextView)).setText(value);
@ -76,19 +82,27 @@ public class DebugSharedPrefEditorFragment extends Fragment {
view.findViewById(R.id.saveButton).setOnClickListener(v -> { view.findViewById(R.id.saveButton).setOnClickListener(v -> {
String[] split = saveKeyEditText.getText().toString().split(":"); String[] split = saveKeyEditText.getText().toString().split(":");
sharedPref.getSharedPreferencesByTag(sharedPrefType).edit().putString(split[0], split[1]).apply(); sharedPref.getSharedPreferencesByTag(sharedPrefType).edit().putString(split[0], split[1]).apply();
updateList(loadValueTextView);
}); });
// ラジオボタンの変更を監視 // ラジオボタンの変更を監視
view.findViewById(R.id.radioButtonCommon).setOnClickListener(v -> { view.findViewById(R.id.radioButtonCommon).setOnClickListener(v -> {
sharedPrefType = SharedPrefType.COMMON; sharedPrefType = SharedPrefType.COMMON;
updateList(loadValueTextView);
}); });
view.findViewById(R.id.radioButtonUserData).setOnClickListener(v -> { view.findViewById(R.id.radioButtonUserData).setOnClickListener(v -> {
sharedPrefType = SharedPrefType.USERDATA; sharedPrefType = SharedPrefType.USERDATA;
updateList(loadValueTextView);
}); });
} }
public void updateRecyclerView(RecyclerView recyclerView) { public void updateList(TextView textView) {
// リストの更新
Map<String, ?> resultMap = sharedPref.getSharedPreferencesByTag(sharedPrefType).getAll();
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, ?> entry : resultMap.entrySet()) {
sb.append(entry.getKey()).append(":").append(entry.getValue().toString()).append("\n");
}
} }
} }