mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-19 01:27:18 -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(){
|
public SearchModFragment(){
|
||||||
super(R.layout.fragment_mod_search);
|
super(R.layout.fragment_mod_search);
|
||||||
modpackApi = new CurseforgeApi();
|
modpackApi = new CurseforgeApi();
|
||||||
mModItemAdapter = new ModItemAdapter(modpackApi);
|
|
||||||
mSearchFilters = new SearchFilters();
|
mSearchFilters = new SearchFilters();
|
||||||
mSearchFilters.isModpack = true;
|
mSearchFilters.isModpack = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
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);
|
mSearchEditText = view.findViewById(R.id.search_mod_edittext);
|
||||||
mSearchProgressBar = view.findViewById(R.id.search_mod_progressbar);
|
mSearchProgressBar = view.findViewById(R.id.search_mod_progressbar);
|
||||||
mSelectedVersion = view.findViewById(R.id.search_mod_selected_mc_version_textview);
|
mSelectedVersion = view.findViewById(R.id.search_mod_selected_mc_version_textview);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.kdt.pojavlaunch.modloaders.modpacks;
|
package net.kdt.pojavlaunch.modloaders.modpacks;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -12,6 +13,9 @@ import android.widget.Spinner;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
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 androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.kdt.SimpleArrayAdapter;
|
import com.kdt.SimpleArrayAdapter;
|
||||||
@ -34,6 +38,9 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
|||||||
private ModItem[] mModItems;
|
private ModItem[] mModItems;
|
||||||
private final ModpackApi mModpackApi;
|
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
|
* Basic viewholder with expension capabilities
|
||||||
*/
|
*/
|
||||||
@ -50,6 +57,10 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
|||||||
private Future<?> mExtensionFuture;
|
private Future<?> mExtensionFuture;
|
||||||
private Bitmap mThumbnailBitmap;
|
private Bitmap mThumbnailBitmap;
|
||||||
private ImageReceiver mImageReceiver;
|
private ImageReceiver mImageReceiver;
|
||||||
|
|
||||||
|
/* Used to display available versions of the mod(pack) */
|
||||||
|
private SimpleArrayAdapter<String> mVersionAdapter = new SimpleArrayAdapter<>(null);
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
public ViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
|
|
||||||
@ -61,17 +72,14 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
|||||||
mExtendedSpinner = mExtendedLayout.findViewById(R.id.mod_extended_version_spinner);
|
mExtendedSpinner = mExtendedLayout.findViewById(R.id.mod_extended_version_spinner);
|
||||||
mExtendedErrorTextView = mExtendedLayout.findViewById(R.id.mod_extended_error_textview);
|
mExtendedErrorTextView = mExtendedLayout.findViewById(R.id.mod_extended_error_textview);
|
||||||
|
|
||||||
mExtendedButton.setOnClickListener(v1 -> {
|
mExtendedButton.setOnClickListener(v1 -> mModpackApi.handleInstallation(
|
||||||
mModpackApi.handleInstallation(
|
|
||||||
mExtendedButton.getContext().getApplicationContext(),
|
mExtendedButton.getContext().getApplicationContext(),
|
||||||
mModDetail,
|
mModDetail,
|
||||||
mExtendedSpinner.getSelectedItemPosition());
|
mExtendedSpinner.getSelectedItemPosition()));
|
||||||
|
mExtendedSpinner.setAdapter(mVersionAdapter);
|
||||||
//TODO do something !
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if(isExtended()) mExtendedLayout.setVisibility(View.GONE);
|
if(isExtended()) closeDetailedView();
|
||||||
else mExtendedLayout.setVisibility(View.VISIBLE);
|
else openDetailedView();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isExtended() && mModDetail == null && mExtensionFuture == null) { // only reload if no reloads are in progress
|
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 = bm->{
|
||||||
mImageReceiver = null;
|
mImageReceiver = null;
|
||||||
mThumbnailBitmap = bm;
|
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);
|
mIconCache.getImage(mImageReceiver, mModItem.getIconCacheTag(), mModItem.imageUrl);
|
||||||
mTitle.setText(item.title);
|
mTitle.setText(item.title);
|
||||||
mDescription.setText(item.description);
|
mDescription.setText(item.description);
|
||||||
|
|
||||||
if(hasExtended()){
|
if(hasExtended()){
|
||||||
mExtendedLayout.setVisibility(View.GONE);
|
closeDetailedView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Display extended info/interaction about a modpack */
|
/** Display extended info/interaction about a modpack */
|
||||||
private void setStateDetailed(ModDetail detailedItem) {
|
private void setStateDetailed(ModDetail detailedItem) {
|
||||||
mExtendedLayout.setVisibility(View.VISIBLE);
|
|
||||||
if(detailedItem != null) {
|
if(detailedItem != null) {
|
||||||
mExtendedButton.setEnabled(true);
|
mExtendedButton.setEnabled(true);
|
||||||
mExtendedErrorTextView.setVisibility(View.GONE);
|
mExtendedErrorTextView.setVisibility(View.GONE);
|
||||||
mExtendedSpinner.setAdapter(new SimpleArrayAdapter<>(Arrays.asList(detailedItem.versionNames)));
|
mVersionAdapter.setObjects(Arrays.asList(detailedItem.versionNames));
|
||||||
|
mExtendedSpinner.setAdapter(mVersionAdapter);
|
||||||
} else {
|
} else {
|
||||||
|
closeDetailedView();
|
||||||
mExtendedButton.setEnabled(false);
|
mExtendedButton.setEnabled(false);
|
||||||
mExtendedErrorTextView.setVisibility(View.VISIBLE);
|
mExtendedErrorTextView.setVisibility(View.VISIBLE);
|
||||||
mExtendedSpinner.setAdapter(null);
|
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() {
|
private void setDetailedStateDefault() {
|
||||||
mExtendedButton.setEnabled(false);
|
mExtendedButton.setEnabled(false);
|
||||||
mExtendedSpinner.setAdapter(null);
|
mExtendedSpinner.setAdapter(null);
|
||||||
mExtendedErrorTextView.setVisibility(View.GONE);
|
mExtendedErrorTextView.setVisibility(View.GONE);
|
||||||
|
openDetailedView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasExtended(){
|
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;
|
mModpackApi = api;
|
||||||
mModItems = new ModItem[]{};
|
mModItems = new ModItem[]{};
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,16 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/background_line"
|
android:background="@drawable/background_line"
|
||||||
android:paddingHorizontal="@dimen/padding_medium"
|
android:paddingHorizontal="@dimen/_2sdp"
|
||||||
android:paddingVertical="@dimen/padding_medium"
|
android:paddingVertical="@dimen/_2sdp"
|
||||||
android:layout_marginVertical="@dimen/padding_medium"
|
android:layout_marginVertical="@dimen/padding_medium"
|
||||||
>
|
>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/mod_thumbnail_imageview"
|
android:id="@+id/mod_thumbnail_imageview"
|
||||||
android:layout_width="@dimen/_50sdp"
|
android:layout_width="@dimen/_65sdp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="@dimen/_65sdp"
|
||||||
|
|
||||||
app:layout_constraintBottom_toBottomOf="@id/mod_limited_state_guideline"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
|
||||||
@ -38,7 +37,8 @@
|
|||||||
style="@style/TextAppearance.AppCompat.Body2"
|
style="@style/TextAppearance.AppCompat.Body2"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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_constraintHorizontal_bias="0.0"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/mod_source_imageview"
|
app:layout_constraintEnd_toStartOf="@+id/mod_source_imageview"
|
||||||
@ -50,22 +50,20 @@
|
|||||||
android:id="@+id/mod_body_textview"
|
android:id="@+id/mod_body_textview"
|
||||||
style="@style/TextAppearance.AppCompat.Body1"
|
style="@style/TextAppearance.AppCompat.Body1"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/padding_medium"
|
android:layout_marginStart="@dimen/padding_medium"
|
||||||
android:layout_marginEnd="@dimen/padding_medium"
|
android:layout_marginEnd="@dimen/padding_medium"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/mod_limited_state_guideline"
|
android:ellipsize="end"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:maxLines="3"
|
||||||
app:layout_constraintStart_toEndOf="@+id/mod_thumbnail_imageview"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/mod_title_textview"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
tools:text="Feed the beast - Reforged is a machine and magic focused modpack, with no respect for the minimum requirements of minecraft" />
|
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.
|
When clicked for the first time, the view is extended with more information.
|
||||||
@ -76,7 +74,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout="@layout/view_mod_extended"
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,7 +1,7 @@
|
|||||||
<?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"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
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:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
@ -18,7 +18,9 @@
|
|||||||
<androidx.appcompat.widget.AppCompatSpinner
|
<androidx.appcompat.widget.AppCompatSpinner
|
||||||
android:id="@+id/mod_extended_version_spinner"
|
android:id="@+id/mod_extended_version_spinner"
|
||||||
android:layout_width="match_parent"
|
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"
|
app:layout_constraintTop_toBottomOf="@+id/mod_extended_error_textview"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -26,10 +28,13 @@
|
|||||||
android:id="@+id/mod_extended_select_version_button"
|
android:id="@+id/mod_extended_select_version_button"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginVertical="@dimen/padding_large"
|
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:text="@string/generic_install"
|
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" />
|
app:layout_constraintTop_toBottomOf="@id/mod_extended_version_spinner" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user