AppList : Add a expandable view to show changelog in updatable applist

Resolves issue :  https://gitlab.com/AuroraOSS/AuroraStore/issues/61
This commit is contained in:
Mr. Dragon
2019-04-06 04:15:43 +05:30
parent e4ccc5105e
commit a30516fca0
8 changed files with 227 additions and 16 deletions

View File

@@ -22,11 +22,13 @@ package com.aurora.store.adapter;
import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -39,6 +41,7 @@ import com.aurora.store.activity.AuroraActivity;
import com.aurora.store.activity.DetailsActivity;
import com.aurora.store.model.App;
import com.aurora.store.sheet.AppMenuSheet;
import com.aurora.store.utility.ViewUtil;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
@@ -50,7 +53,7 @@ import butterknife.ButterKnife;
public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdapter.ViewHolder> {
public List<App> appsToAdd;
private List<App> appsToAdd;
private Context context;
private ListType listType;
@@ -78,7 +81,7 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdap
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.item_installed, parent, false);
View view = inflater.inflate(R.layout.item_updatable, parent, false);
return new ViewHolder(view);
}
@@ -88,10 +91,11 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdap
List<String> Version = new ArrayList<>();
List<String> Extra = new ArrayList<>();
viewHolder.AppTitle.setText(app.getDisplayName());
viewHolder.txtTitle.setText(app.getDisplayName());
getDetails(Version, Extra, app);
setText(viewHolder.AppVersion, TextUtils.join("", Version));
setText(viewHolder.AppExtra, TextUtils.join("", Extra));
setText(viewHolder.txtVersion, TextUtils.join("", Version));
setText(viewHolder.txtExtra, TextUtils.join("", Extra));
setText(viewHolder.txtChanges, Html.fromHtml(app.getChanges()).toString());
viewHolder.itemView.setOnClickListener(v -> {
Intent intent = new Intent(context, DetailsActivity.class);
@@ -103,7 +107,8 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdap
final AppMenuSheet menuSheet = new AppMenuSheet();
menuSheet.setApp(app);
menuSheet.setListType(listType);
menuSheet.show(((AuroraActivity) context).getSupportFragmentManager(), "BOTTOM_MENU_SHEET");
menuSheet.show(((AuroraActivity) context).getSupportFragmentManager(),
"BOTTOM_MENU_SHEET");
return false;
});
@@ -112,7 +117,20 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdap
.load(app.getIconInfo().getUrl())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.transition(new DrawableTransitionOptions().crossFade())
.into(viewHolder.AppIcon);
.into(viewHolder.imgIcon);
viewHolder.imgExpand.setOnClickListener(v -> {
if (viewHolder.layoutChanges.getHeight() == 0) {
ViewUtil.rotateView(v, false);
ViewUtil.expandView(viewHolder.layoutChanges,
viewHolder.txtChanges.getHeight()
+ viewHolder.txtChangesTitle.getHeight()
+ 120 /*Padding & Margins*/);
} else {
ViewUtil.rotateView(v, true);
ViewUtil.collapseView(viewHolder.layoutChanges, 0);
}
});
}
private void getDetails(List<String> Version, List<String> Extra, App app) {
@@ -135,14 +153,24 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdap
}
public class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.layout_info)
RelativeLayout layoutInfo;
@BindView(R.id.layout_changes)
RelativeLayout layoutChanges;
@BindView(R.id.app_icon)
ImageView AppIcon;
ImageView imgIcon;
@BindView(R.id.app_title)
TextView AppTitle;
TextView txtTitle;
@BindView(R.id.app_version)
TextView AppVersion;
TextView txtVersion;
@BindView(R.id.app_extra)
TextView AppExtra;
TextView txtExtra;
@BindView(R.id.img_expand)
ImageView imgExpand;
@BindView(R.id.txt_title)
TextView txtChangesTitle;
@BindView(R.id.txt_changes)
TextView txtChanges;
ViewHolder(@NonNull View itemView) {
super(itemView);

View File

@@ -22,17 +22,21 @@ package com.aurora.store.utility;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.TextView;
import androidx.annotation.MenuRes;
@@ -50,6 +54,16 @@ import java.util.List;
public class ViewUtil {
public static int dpToPx(Context context, int dp) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}
public static int pxToDp(Context context, int px) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}
public static void setCustomColors(Context mContext, SwipeRefreshLayout swipeRefreshLayout) {
swipeRefreshLayout.setColorSchemeColors(mContext
.getResources()
@@ -111,7 +125,7 @@ public class ViewUtil {
}
public static void showWithAnimation(View view) {
int mShortAnimationDuration = view.getResources().getInteger(
final int mShortAnimationDuration = view.getResources().getInteger(
android.R.integer.config_shortAnimTime);
view.setAlpha(0f);
view.setVisibility(View.VISIBLE);
@@ -123,7 +137,7 @@ public class ViewUtil {
}
public static void hideWithAnimation(View view) {
int mShortAnimationDuration = view.getResources().getInteger(
final int mShortAnimationDuration = view.getResources().getInteger(
android.R.integer.config_shortAnimTime);
view.animate()
.alpha(0f)
@@ -136,6 +150,43 @@ public class ViewUtil {
});
}
public static void rotateView(View view, boolean reverse) {
final RotateAnimation animation = new RotateAnimation(
reverse ? 180 : 0,
reverse ? 0 : 180,
(float) view.getWidth() / 2,
(float) view.getHeight() / 2);
animation.setDuration(300);
animation.setFillAfter(true);
view.startAnimation(animation);
}
public static void expandView(final View v, int targetHeight) {
int prevHeight = v.getHeight();
v.setVisibility(View.VISIBLE);
ValueAnimator valueAnimator = ValueAnimator.ofInt(prevHeight, targetHeight);
valueAnimator.addUpdateListener(animation -> {
v.getLayoutParams().height = (int) animation.getAnimatedValue();
v.requestLayout();
});
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.setDuration(300);
valueAnimator.start();
}
public static void collapseView(final View v, int targetHeight) {
int prevHeight = v.getHeight();
ValueAnimator valueAnimator = ValueAnimator.ofInt(prevHeight, targetHeight);
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.addUpdateListener(animation -> {
v.getLayoutParams().height = (int) animation.getAnimatedValue();
v.requestLayout();
});
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.setDuration(300);
valueAnimator.start();
}
public static void setVisibility(View view, boolean visibility) {
if (visibility)
showWithAnimation(view);

View File

@@ -34,5 +34,4 @@
<stroke
android:width="1dp"
android:color="?android:attr/strokeColor" />
<solid android:color="?android:attr/colorBackground" />
</shape>

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z"/>
</vector>

View File

@@ -20,6 +20,7 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -80,7 +81,8 @@
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
android:scrollbars="vertical"
tools:listitem="@layout/item_updatable" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"

View File

@@ -35,7 +35,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="What's New"
android:text="@string/details_new_changes"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
android:textStyle="bold" />

View File

@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Aurora Store
~ Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
~
~ Aurora Store is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 2 of the License, or
~ (at your option) any later version.
~
~ Aurora Store is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
~
~
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal"
android:paddingStart="@dimen/margin_medium"
android:paddingTop="@dimen/margin_small"
android:paddingEnd="@dimen/margin_xxsmall"
android:paddingBottom="@dimen/margin_small">
<RelativeLayout
android:id="@+id/layout_info"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/app_icon"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginStart="@dimen/margin_small"
android:layout_marginEnd="@dimen/margin_normal"
android:contentDescription="@string/content_description_icon" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/img_expand"
android:layout_toEndOf="@id/app_icon">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/app_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorPrimary"
android:textSize="17sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/app_version"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/app_title"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/app_extra"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/app_version"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewStart"
android:textSize="12sp" />
</RelativeLayout>
<ImageView
android:id="@+id/img_expand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/margin_small"
android:layout_marginEnd="@dimen/margin_small"
android:padding="@dimen/margin_small"
android:src="@drawable/ic_expand" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_changes"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/layout_info"
android:layout_margin="@dimen/margin_small"
android:background="@drawable/generic_padded_bg">
<TextView
android:id="@+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_small"
android:text="@string/details_new_changes"
android:textAppearance="@style/TextAppearance.Aurora.DialogSubTitle" />
<TextView
android:id="@+id/txt_changes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txt_title"
android:textAppearance="@style/TextAppearance.Aurora.Body" />
</RelativeLayout>
</RelativeLayout>

View File

@@ -131,6 +131,7 @@
<string name="details_installing">Installing</string>
<string name="details_more">Read more</string>
<string name="details_no_ads">No ads</string>
<string name="details_new_changes">What\'s New</string>
<string name="details_permissions">App permissions</string>
<string name="details_purchase">Purchase</string>
<string name="details_rate_this_app">Rate this app</string>