mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
Feat[UI]: moditem states are now pretty
This commit is contained in:
parent
23b02cca4c
commit
90b10084ce
@ -53,13 +53,15 @@ public class SearchModFragment extends Fragment {
|
||||
public SearchModFragment(){
|
||||
super(R.layout.fragment_mod_search);
|
||||
modpackApi = new CurseforgeApi();
|
||||
mModItemAdapter = new ModItemAdapter(modpackApi);
|
||||
mSearchFilters = new SearchFilters();
|
||||
mSearchFilters.isModpack = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
// You can only access resources after attaching to current context
|
||||
mModItemAdapter = new ModItemAdapter(getResources(), modpackApi);
|
||||
|
||||
mSearchEditText = view.findViewById(R.id.search_mod_edittext);
|
||||
mSearchProgressBar = view.findViewById(R.id.search_mod_progressbar);
|
||||
mSelectedVersion = view.findViewById(R.id.search_mod_selected_mc_version_textview);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.kdt.pojavlaunch.modloaders.modpacks;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -12,6 +13,9 @@ import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.kdt.SimpleArrayAdapter;
|
||||
@ -34,6 +38,9 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
||||
private ModItem[] mModItems;
|
||||
private final ModpackApi mModpackApi;
|
||||
|
||||
/* Cache for ever so slightly rounding the image for the corner not to stick out of the layout */
|
||||
private final float mCornerDimensionCache;
|
||||
|
||||
/**
|
||||
* Basic viewholder with expension capabilities
|
||||
*/
|
||||
@ -50,6 +57,10 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
||||
private Future<?> mExtensionFuture;
|
||||
private Bitmap mThumbnailBitmap;
|
||||
private ImageReceiver mImageReceiver;
|
||||
|
||||
/* Used to display available versions of the mod(pack) */
|
||||
private SimpleArrayAdapter<String> mVersionAdapter = new SimpleArrayAdapter<>(null);
|
||||
|
||||
public ViewHolder(View view) {
|
||||
super(view);
|
||||
|
||||
@ -61,17 +72,14 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
||||
mExtendedSpinner = mExtendedLayout.findViewById(R.id.mod_extended_version_spinner);
|
||||
mExtendedErrorTextView = mExtendedLayout.findViewById(R.id.mod_extended_error_textview);
|
||||
|
||||
mExtendedButton.setOnClickListener(v1 -> {
|
||||
mModpackApi.handleInstallation(
|
||||
mExtendedButton.getContext().getApplicationContext(),
|
||||
mModDetail,
|
||||
mExtendedSpinner.getSelectedItemPosition());
|
||||
|
||||
//TODO do something !
|
||||
});
|
||||
mExtendedButton.setOnClickListener(v1 -> mModpackApi.handleInstallation(
|
||||
mExtendedButton.getContext().getApplicationContext(),
|
||||
mModDetail,
|
||||
mExtendedSpinner.getSelectedItemPosition()));
|
||||
mExtendedSpinner.setAdapter(mVersionAdapter);
|
||||
} else {
|
||||
if(isExtended()) mExtendedLayout.setVisibility(View.GONE);
|
||||
else mExtendedLayout.setVisibility(View.VISIBLE);
|
||||
if(isExtended()) closeDetailedView();
|
||||
else openDetailedView();
|
||||
}
|
||||
|
||||
if(isExtended() && mModDetail == null && mExtensionFuture == null) { // only reload if no reloads are in progress
|
||||
@ -140,36 +148,57 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
||||
mImageReceiver = bm->{
|
||||
mImageReceiver = null;
|
||||
mThumbnailBitmap = bm;
|
||||
mIconView.setImageBitmap(bm);
|
||||
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(mIconView.getResources(), bm);
|
||||
drawable.setCornerRadius(mCornerDimensionCache * bm.getHeight());
|
||||
mIconView.setImageDrawable(drawable);
|
||||
};
|
||||
mIconCache.getImage(mImageReceiver, mModItem.getIconCacheTag(), mModItem.imageUrl);
|
||||
mTitle.setText(item.title);
|
||||
mDescription.setText(item.description);
|
||||
|
||||
if(hasExtended()){
|
||||
mExtendedLayout.setVisibility(View.GONE);
|
||||
closeDetailedView();
|
||||
}
|
||||
}
|
||||
|
||||
/** Display extended info/interaction about a modpack */
|
||||
private void setStateDetailed(ModDetail detailedItem) {
|
||||
mExtendedLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
if(detailedItem != null) {
|
||||
mExtendedButton.setEnabled(true);
|
||||
mExtendedErrorTextView.setVisibility(View.GONE);
|
||||
mExtendedSpinner.setAdapter(new SimpleArrayAdapter<>(Arrays.asList(detailedItem.versionNames)));
|
||||
mVersionAdapter.setObjects(Arrays.asList(detailedItem.versionNames));
|
||||
mExtendedSpinner.setAdapter(mVersionAdapter);
|
||||
} else {
|
||||
closeDetailedView();
|
||||
mExtendedButton.setEnabled(false);
|
||||
mExtendedErrorTextView.setVisibility(View.VISIBLE);
|
||||
mExtendedSpinner.setAdapter(null);
|
||||
mVersionAdapter.setObjects(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void openDetailedView(){
|
||||
mExtendedLayout.setVisibility(View.VISIBLE);
|
||||
mDescription.setMaxLines(99);
|
||||
mExtendedLayout.post(() -> {
|
||||
// We need to align to the longer section
|
||||
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mExtendedLayout.getLayoutParams();
|
||||
params.topToBottom = mDescription.getBottom() > mIconView.getBottom() ? R.id.mod_body_textview : R.id.mod_thumbnail_imageview;
|
||||
mExtendedLayout.setLayoutParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
private void closeDetailedView(){
|
||||
mExtendedLayout.setVisibility(View.GONE);
|
||||
mDescription.setMaxLines(3);
|
||||
}
|
||||
|
||||
private void setDetailedStateDefault() {
|
||||
mExtendedButton.setEnabled(false);
|
||||
mExtendedSpinner.setAdapter(null);
|
||||
mExtendedErrorTextView.setVisibility(View.GONE);
|
||||
openDetailedView();
|
||||
}
|
||||
|
||||
private boolean hasExtended(){
|
||||
@ -182,7 +211,8 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
||||
}
|
||||
|
||||
|
||||
public ModItemAdapter(ModpackApi api) {
|
||||
public ModItemAdapter(Resources resources, ModpackApi api) {
|
||||
mCornerDimensionCache = resources.getDimension(R.dimen._1sdp) / 250;
|
||||
mModpackApi = api;
|
||||
mModItems = new ModItem[]{};
|
||||
}
|
||||
|
@ -6,17 +6,16 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/background_line"
|
||||
android:paddingHorizontal="@dimen/padding_medium"
|
||||
android:paddingVertical="@dimen/padding_medium"
|
||||
android:paddingHorizontal="@dimen/_2sdp"
|
||||
android:paddingVertical="@dimen/_2sdp"
|
||||
android:layout_marginVertical="@dimen/padding_medium"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/mod_thumbnail_imageview"
|
||||
android:layout_width="@dimen/_50sdp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_width="@dimen/_65sdp"
|
||||
android:layout_height="@dimen/_65sdp"
|
||||
|
||||
app:layout_constraintBottom_toBottomOf="@id/mod_limited_state_guideline"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
||||
@ -38,7 +37,8 @@
|
||||
style="@style/TextAppearance.AppCompat.Body2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="@dimen/padding_small"
|
||||
android:layout_marginStart="@dimen/padding_moderate"
|
||||
android:ellipsize="end"
|
||||
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintEnd_toStartOf="@+id/mod_source_imageview"
|
||||
@ -50,22 +50,20 @@
|
||||
android:id="@+id/mod_body_textview"
|
||||
style="@style/TextAppearance.AppCompat.Body1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/padding_medium"
|
||||
android:layout_marginEnd="@dimen/padding_medium"
|
||||
app:layout_constraintBottom_toTopOf="@+id/mod_limited_state_guideline"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/mod_thumbnail_imageview"
|
||||
app:layout_constraintTop_toBottomOf="@+id/mod_title_textview"
|
||||
tools:text="Feed the beast - Reforged is a machine and magic focused modpack, with no respect for the minimum requirements of minecraft" />
|
||||
android:ellipsize="end"
|
||||
android:maxLines="3"
|
||||
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@+id/mod_title_textview"
|
||||
app:layout_constraintTop_toBottomOf="@+id/mod_title_textview"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
tools:text="Feed the beast - Reforged is a machine and magic focused modpack, with no respect for the minimum requirements of minecraft. Very long text" />
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/mod_limited_state_guideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintGuide_begin="@dimen/_65sdp"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<!--
|
||||
When clicked for the first time, the view is extended with more information.
|
||||
@ -76,7 +74,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout="@layout/view_mod_extended"
|
||||
app:layout_constraintTop_toBottomOf="@id/mod_limited_state_guideline"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/mod_body_textview"/>
|
||||
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
@ -18,7 +18,9 @@
|
||||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/mod_extended_version_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_30sdp"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/_30sdp"
|
||||
android:layout_marginVertical="@dimen/padding_moderate"
|
||||
app:layout_constraintTop_toBottomOf="@+id/mod_extended_error_textview"
|
||||
/>
|
||||
|
||||
@ -26,10 +28,13 @@
|
||||
android:id="@+id/mod_extended_select_version_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="@dimen/padding_large"
|
||||
android:enabled="false"
|
||||
android:text="@string/generic_install"
|
||||
android:layout_marginHorizontal="@dimen/padding_large"
|
||||
android:layout_marginTop="@dimen/padding_moderate"
|
||||
android:layout_marginBottom="@dimen/padding_large"
|
||||
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/mod_extended_version_spinner" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user