mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-09 12:43:36 -04:00
tweak(ui): inline the delete profile button
Makes the main ui slightly cleaner
This commit is contained in:
parent
208b92be83
commit
3c616b9d90
@ -18,12 +18,13 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.AppCompatSpinner;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
@ -188,7 +189,10 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
}
|
||||
|
||||
public void removeCurrentAccount(){
|
||||
int position = getSelectedItemPosition();
|
||||
removeAccount(getSelectedItemPosition());
|
||||
}
|
||||
|
||||
private void removeAccount(int position) {
|
||||
if(position == 0) return;
|
||||
File accountFile = new File(Tools.DIR_ACCOUNT_NEW, mAccountList.get(position)+".json");
|
||||
if(accountFile.exists()) accountFile.delete();
|
||||
@ -321,8 +325,9 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
BitmapDrawable oldBitmapDrawable = mHeadDrawable;
|
||||
|
||||
if(mSelectecAccount != null){
|
||||
ExtendedTextView view = ((ExtendedTextView) getSelectedView());
|
||||
if(view != null){
|
||||
View layout = getSelectedView();
|
||||
if(layout != null){
|
||||
ExtendedTextView view = layout.findViewById(R.id.account_item);
|
||||
Bitmap bitmap = mSelectecAccount.getSkinFace();
|
||||
if(bitmap != null) {
|
||||
mHeadDrawable = new BitmapDrawable(getResources(), bitmap);
|
||||
@ -339,8 +344,7 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class AccountAdapter extends ArrayAdapter<String> {
|
||||
private class AccountAdapter extends ArrayAdapter<String> {
|
||||
|
||||
private final HashMap<String, Drawable> mImageCache = new HashMap<>();
|
||||
public AccountAdapter(@NonNull Context context, int resource, @NonNull String[] objects) {
|
||||
@ -349,20 +353,19 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
return getView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
if(convertView == null){
|
||||
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_minecraft_account, parent, false);
|
||||
}
|
||||
ExtendedTextView textview = (ExtendedTextView) convertView;
|
||||
|
||||
ExtendedTextView textview = convertView.findViewById(R.id.account_item);
|
||||
ImageView deleteButton = convertView.findViewById(R.id.delete_account_button);
|
||||
textview.setText(super.getItem(position));
|
||||
|
||||
// Handle the "Add account section"
|
||||
if(position == 0) textview.setCompoundDrawables(ResourcesCompat.getDrawable(parent.getResources(), R.drawable.ic_add, null), null, null, null);
|
||||
if(position == 0) {
|
||||
textview.setCompoundDrawables(ResourcesCompat.getDrawable(parent.getResources(), R.drawable.ic_add, null), null, null, null);
|
||||
deleteButton.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
String username = super.getItem(position);
|
||||
Drawable accountHead = mImageCache.get(username);
|
||||
@ -371,9 +374,37 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
mImageCache.put(username, accountHead);
|
||||
}
|
||||
textview.setCompoundDrawables(accountHead, null, null, null);
|
||||
|
||||
deleteButton.setVisibility(View.VISIBLE);
|
||||
deleteButton.setOnClickListener(v -> {
|
||||
showDeleteDialog(getContext(), position);
|
||||
});
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
View view = getDropDownView(position, convertView, parent);
|
||||
view.findViewById(R.id.delete_account_button).setVisibility(View.GONE);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void showDeleteDialog(Context context, int position) {
|
||||
new AlertDialog.Builder(context)
|
||||
.setMessage(R.string.warning_remove_account)
|
||||
.setPositiveButton(android.R.string.cancel, null)
|
||||
.setNeutralButton(R.string.global_delete, (dialog, which) -> {
|
||||
onDetachedFromWindow();
|
||||
removeAccount(position);
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class LauncherActivity extends BaseActivity {
|
||||
|
||||
private mcAccountSpinner mAccountSpinner;
|
||||
private FragmentContainerView mFragmentView;
|
||||
private ImageButton mSettingsButton, mDeleteAccountButton;
|
||||
private ImageButton mSettingsButton;
|
||||
private ProgressLayout mProgressLayout;
|
||||
private ProgressServiceKeeper mProgressServiceKeeper;
|
||||
private ModloaderInstallTracker mInstallTracker;
|
||||
@ -101,13 +101,6 @@ public class LauncherActivity extends BaseActivity {
|
||||
}
|
||||
};
|
||||
|
||||
/* Listener for account deletion */
|
||||
private final View.OnClickListener mAccountDeleteButtonListener = v -> new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.warning_remove_account)
|
||||
.setPositiveButton(android.R.string.cancel, null)
|
||||
.setNeutralButton(R.string.global_delete, (dialog, which) -> mAccountSpinner.removeCurrentAccount())
|
||||
.show();
|
||||
|
||||
private final ExtraListener<Boolean> mLaunchGameListener = (key, value) -> {
|
||||
if(mProgressLayout.hasProcesses()){
|
||||
Toast.makeText(this, R.string.tasks_ongoing, Toast.LENGTH_LONG).show();
|
||||
@ -200,7 +193,6 @@ public class LauncherActivity extends BaseActivity {
|
||||
ProgressKeeper.addTaskCountListener((mProgressServiceKeeper = new ProgressServiceKeeper(this)));
|
||||
|
||||
mSettingsButton.setOnClickListener(mSettingButtonListener);
|
||||
mDeleteAccountButton.setOnClickListener(mAccountDeleteButtonListener);
|
||||
ProgressKeeper.addTaskCountListener(mProgressLayout);
|
||||
ExtraCore.addExtraListener(ExtraConstants.BACK_PREFERENCE, mBackPreferenceListener);
|
||||
ExtraCore.addExtraListener(ExtraConstants.SELECT_AUTH_METHOD, mSelectAuthMethod);
|
||||
@ -343,7 +335,6 @@ public class LauncherActivity extends BaseActivity {
|
||||
private void bindViews(){
|
||||
mFragmentView = findViewById(R.id.container_fragment);
|
||||
mSettingsButton = findViewById(R.id.setting_button);
|
||||
mDeleteAccountButton = findViewById(R.id.delete_account_button);
|
||||
mAccountSpinner = findViewById(R.id.account_spinner);
|
||||
mProgressLayout = findViewById(R.id.progress_layout);
|
||||
}
|
||||
|
@ -28,18 +28,8 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/delete_account_button"
|
||||
android:layout_width="@dimen/_52sdp"
|
||||
android:layout_height="@dimen/_42sdp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:src="@drawable/ic_menu_delete_forever"
|
||||
android:scaleType="fitCenter"
|
||||
|
||||
|
||||
app:layout_constraintEnd_toStartOf="@id/setting_button"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- Holding most of the dynamic content -->
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/container_fragment"
|
||||
|
@ -28,19 +28,6 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/delete_account_button"
|
||||
android:layout_width="@dimen/_52sdp"
|
||||
android:layout_height="@dimen/_52sdp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:src="@drawable/ic_menu_delete_forever"
|
||||
android:scaleType="fitCenter"
|
||||
android:paddingVertical="@dimen/_8sdp"
|
||||
|
||||
|
||||
app:layout_constraintEnd_toStartOf="@id/setting_button"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- Holding most of the dynamic content -->
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/container_fragment"
|
||||
|
@ -1,17 +1,39 @@
|
||||
<fr.spse.extended_view.ExtendedTextView
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_height="@dimen/_52sdp"
|
||||
android:layout_width="match_parent"
|
||||
android:textSize="@dimen/_16ssp"
|
||||
android:gravity="center_vertical"
|
||||
android:drawablePadding="@dimen/_6sdp"
|
||||
android:paddingStart="@dimen/_8sdp"
|
||||
app:drawableStartSize="@dimen/_30sdp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
tools:text="HELLO THERE"
|
||||
tools:drawableStart="@mipmap/ic_launcher"
|
||||
<fr.spse.extended_view.ExtendedTextView
|
||||
android:id="@+id/account_item"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
|
||||
tools:ignore="RtlSymmetry" />
|
||||
android:textSize="@dimen/_16ssp"
|
||||
android:gravity="center_vertical"
|
||||
android:drawablePadding="@dimen/_6sdp"
|
||||
android:paddingStart="@dimen/_8sdp"
|
||||
app:drawableStartSize="@dimen/_30sdp"
|
||||
|
||||
tools:text="HELLO THERE"
|
||||
tools:drawableStart="@mipmap/ic_launcher"
|
||||
|
||||
|
||||
tools:ignore="RtlSymmetry" />
|
||||
|
||||
<!-- Fun fact, if I put an Image button, the spinner fails to put an onclick listener on the extended view -->
|
||||
<ImageView
|
||||
android:id="@+id/delete_account_button"
|
||||
android:layout_width="@dimen/_52sdp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:src="@drawable/ic_menu_delete_forever"
|
||||
|
||||
android:padding="@dimen/padding_moderate"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user