mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -04:00
Style[runtime manager]: Conditional UI
This commit is contained in:
parent
324f62f3ca
commit
0bb4f5d113
@ -3,8 +3,11 @@ package net.kdt.pojavlaunch.multirt;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -33,14 +36,25 @@ public class MultiRTConfigDialog {
|
||||
public void prepare(Activity activity) {
|
||||
mDialogView = new RecyclerView(activity);
|
||||
mDialogView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
|
||||
mDialogView.setAdapter(new RTRecyclerViewAdapter());
|
||||
RTRecyclerViewAdapter adapter = new RTRecyclerViewAdapter();
|
||||
mDialogView.setAdapter(adapter);
|
||||
|
||||
mDialog = new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.multirt_config_title)
|
||||
.setView(mDialogView)
|
||||
.setPositiveButton(R.string.multirt_config_add, (dialog, which) -> openRuntimeSelector(activity,MULTIRT_PICK_RUNTIME))
|
||||
.setNegativeButton(R.string.mcn_exit_call, (dialog, which) -> dialog.cancel())
|
||||
.setNeutralButton(R.string.multirt_delete_runtime, null)
|
||||
.create();
|
||||
|
||||
// Custom button behavior without dismiss
|
||||
mDialog.setOnShowListener(dialog -> {
|
||||
Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL);
|
||||
button.setOnClickListener(view -> {
|
||||
boolean isEditing = !adapter.getIsEditing();
|
||||
adapter.setIsEditing(isEditing);
|
||||
button.setText(isEditing ? R.string.multirt_config_setdefault : R.string.multirt_delete_runtime);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static void openRuntimeSelector(Activity activity, int code) {
|
||||
|
@ -10,6 +10,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -26,6 +27,8 @@ import java.util.List;
|
||||
|
||||
public class RTRecyclerViewAdapter extends RecyclerView.Adapter<RTRecyclerViewAdapter.RTViewHolder> {
|
||||
|
||||
private boolean mIsDeleting = false;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RTViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@ -55,12 +58,23 @@ public class RTRecyclerViewAdapter extends RecyclerView.Adapter<RTRecyclerViewAd
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged") //not a problem, given the typical size of the list
|
||||
public void setIsEditing(boolean isEditing) {
|
||||
mIsDeleting = isEditing;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public class RTViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
|
||||
public boolean getIsEditing(){
|
||||
return mIsDeleting;
|
||||
}
|
||||
|
||||
|
||||
public class RTViewHolder extends RecyclerView.ViewHolder {
|
||||
final TextView mJavaVersionTextView;
|
||||
final TextView mFullJavaVersionTextView;
|
||||
final ColorStateList mDefaultColors;
|
||||
final Button mSetDefaultButton;
|
||||
final ImageButton mDeleteButton;
|
||||
final Context mContext;
|
||||
Runtime mCurrentRuntime;
|
||||
int mCurrentPosition;
|
||||
@ -70,41 +84,49 @@ public class RTRecyclerViewAdapter extends RecyclerView.Adapter<RTRecyclerViewAd
|
||||
mJavaVersionTextView = itemView.findViewById(R.id.multirt_view_java_version);
|
||||
mFullJavaVersionTextView = itemView.findViewById(R.id.multirt_view_java_version_full);
|
||||
mSetDefaultButton = itemView.findViewById(R.id.multirt_view_setdefaultbtn);
|
||||
mSetDefaultButton.setOnClickListener(this);
|
||||
mDeleteButton = itemView.findViewById(R.id.multirt_view_removebtn);
|
||||
|
||||
mDefaultColors = mFullJavaVersionTextView.getTextColors();
|
||||
mContext = itemView.getContext();
|
||||
itemView.findViewById(R.id.multirt_view_removebtn).setOnClickListener(this);
|
||||
|
||||
setupOnClickListeners();
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged") // same as all the other ones
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(view.getId() == R.id.multirt_view_removebtn) {
|
||||
private void setupOnClickListeners(){
|
||||
mSetDefaultButton.setOnClickListener(v -> {
|
||||
if(mCurrentRuntime != null) {
|
||||
setDefault(mCurrentRuntime);
|
||||
RTRecyclerViewAdapter.this.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
mDeleteButton.setOnClickListener(v -> {
|
||||
if (mCurrentRuntime == null) return;
|
||||
|
||||
if(MultiRTUtils.getRuntimes().size() < 2 && mSetDefaultButton.isShown()) {
|
||||
AlertDialog.Builder bldr = new AlertDialog.Builder(mContext);
|
||||
bldr.setTitle(R.string.global_error);
|
||||
bldr.setMessage(R.string.multirt_config_removeerror_last);
|
||||
bldr.setPositiveButton(android.R.string.ok,(adapter, which)->adapter.dismiss());
|
||||
bldr.show();
|
||||
if(MultiRTUtils.getRuntimes().size() < 2) {
|
||||
new AlertDialog.Builder(mContext)
|
||||
.setTitle(R.string.global_error)
|
||||
.setMessage(R.string.multirt_config_removeerror_last)
|
||||
.setPositiveButton(android.R.string.ok,(adapter, which)->adapter.dismiss())
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
sExecutorService.execute(() -> {
|
||||
try {
|
||||
MultiRTUtils.removeRuntimeNamed(mCurrentRuntime.name);
|
||||
mDeleteButton.post(() -> {
|
||||
if(getBindingAdapter() != null)
|
||||
getBindingAdapter().notifyDataSetChanged();
|
||||
});
|
||||
|
||||
} catch (IOException e) {
|
||||
Tools.showError(itemView.getContext(), e);
|
||||
}
|
||||
});
|
||||
|
||||
}else if(view.getId() == R.id.multirt_view_setdefaultbtn) {
|
||||
if(mCurrentRuntime != null) {
|
||||
setDefault(mCurrentRuntime);
|
||||
RTRecyclerViewAdapter.this.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void bindRuntime(Runtime runtime, int pos) {
|
||||
@ -116,14 +138,17 @@ public class RTRecyclerViewAdapter extends RecyclerView.Adapter<RTRecyclerViewAd
|
||||
.replace("-", " "));
|
||||
mFullJavaVersionTextView.setText(runtime.versionString);
|
||||
mFullJavaVersionTextView.setTextColor(mDefaultColors);
|
||||
mSetDefaultButton.setVisibility(View.VISIBLE);
|
||||
|
||||
updateButtonsVisibility();
|
||||
|
||||
boolean defaultRuntime = isDefaultRuntime(runtime);
|
||||
mSetDefaultButton.setEnabled(!defaultRuntime);
|
||||
mSetDefaultButton.setText(defaultRuntime ? R.string.multirt_config_setdefault_already:R.string.multirt_config_setdefault);
|
||||
return;
|
||||
}
|
||||
|
||||
// Problematic runtime moment
|
||||
// Problematic runtime moment, force propose deletion
|
||||
mDeleteButton.setVisibility(View.VISIBLE);
|
||||
if(runtime.versionString == null){
|
||||
mFullJavaVersionTextView.setText(R.string.multirt_runtime_corrupt);
|
||||
}else{
|
||||
@ -133,5 +158,10 @@ public class RTRecyclerViewAdapter extends RecyclerView.Adapter<RTRecyclerViewAd
|
||||
mFullJavaVersionTextView.setTextColor(Color.RED);
|
||||
mSetDefaultButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void updateButtonsVisibility(){
|
||||
mSetDefaultButton.setVisibility(mIsDeleting ? View.GONE : View.VISIBLE);
|
||||
mDeleteButton.setVisibility(mIsDeleting ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,57 +3,72 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_60sdp">
|
||||
android:layout_height="@dimen/_60sdp"
|
||||
android:paddingHorizontal="@dimen/padding_medium"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/multirt_view_java_version"
|
||||
android:layout_width="0dp"
|
||||
style="@style/TextAppearance.AppCompat.Body1"
|
||||
android:layout_width="@dimen/_150sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/_8sdp"
|
||||
|
||||
|
||||
android:layout_marginEnd="@dimen/_8sdp"
|
||||
android:textSize="@dimen/_12ssp"
|
||||
android:layout_marginStart="@dimen/_5sdp"
|
||||
|
||||
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/multirt_view_setdefaultbtn"
|
||||
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
||||
app:layout_constraintVertical_bias="0.28"
|
||||
tools:text="Java 8" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/multirt_view_java_version_full"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
|
||||
android:layout_marginTop="8dp"
|
||||
android:textSize="@dimen/_10ssp"
|
||||
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@+id/multirt_view_java_version"
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@+id/multirt_view_java_version"
|
||||
tools:text="1.8.0_292" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/multirt_view_removebtn"
|
||||
android:layout_width="@dimen/_60sdp"
|
||||
android:paddingVertical="@dimen/_10sdp"
|
||||
android:layout_width="@dimen/_35sdp"
|
||||
android:layout_height="0dp"
|
||||
android:src="@drawable/ic_menu_delete_forever"
|
||||
android:scaleType="fitCenter"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingVertical="@dimen/_12sdp"
|
||||
android:scaleType="fitCenter"
|
||||
|
||||
android:src="@drawable/ic_menu_delete_forever"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintStart_toEndOf="@+id/multirt_view_java_version"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/multirt_view_setdefaultbtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:text="@string/multirt_config_setdefault"
|
||||
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:text="@string/multirt_config_setdefault"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/multirt_view_removebtn"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/multirt_view_java_version"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -255,6 +255,7 @@
|
||||
<string name="multirt_config_removeerror_last">You must have at least one Java Runtime installed</string>
|
||||
<string name="multirt_nocompartiblert">Can\'t find any compartible Java Runtime. This version requires Java %d or newer.</string>
|
||||
<string name="multirt_nojava8rt">Can\'t find Java 8. In order to use this option, you need to install Java 8.</string>
|
||||
<string name="multirt_delete_runtime">Delete runtime</string>
|
||||
|
||||
<string name="compat_117_message">Minecraft 21w10a+ requires the OpenGL 3.2 core profile. Sadly, your graphics chip does not support OpenGL ES 3.0 or higher, but there are some additional resources you can install to run these versions. Press OK to confirm installation, and press Cancel to abort launch.</string>
|
||||
<string name="compat_11x_playanyway">Play anyway</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user