Merge branch 'no-featured-app' into 'master'

* no-featured-app:
  cleanup imports
  fix padding of top item in Latest Tab
  Remove feature graphic of first app from "Latest" view

See merge request fdroid/fdroidclient!807
This commit is contained in:
Hans-Christoph Steiner 2019-03-26 21:29:33 +01:00
commit 80bab5611b
4 changed files with 18 additions and 184 deletions

View File

@ -2,30 +2,22 @@ package org.fdroid.fdroid.views.categories;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.Pair;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import org.fdroid.fdroid.views.AppDetailsActivity;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.views.apps.FeatureImage;
import org.fdroid.fdroid.views.AppDetailsActivity;
/**
* The {@link AppCardController} can bind an app to several different layouts, as long as the layout
@ -33,10 +25,9 @@ import org.fdroid.fdroid.views.apps.FeatureImage;
* + {@link R.id#icon} ({@link ImageView}, required)
* + {@link R.id#summary} ({@link TextView}, required)
* + {@link R.id#new_tag} ({@link TextView}, optional)
* + {@link R.id#featured_image} ({@link ImageView}, optional)
*/
public class AppCardController extends RecyclerView.ViewHolder
implements ImageLoadingListener, View.OnClickListener {
implements View.OnClickListener {
/**
* After this many days, don't consider showing the "New" tag next to an app.
@ -58,13 +49,6 @@ public class AppCardController extends RecyclerView.ViewHolder
@Nullable
private final TextView newTag;
/**
* Wide and short image for branding the app. If it is not present in the metadata then F-Droid
* will draw some abstract art instead.
*/
@Nullable
private final FeatureImage featuredImage;
@Nullable
private App currentApp;
@ -78,7 +62,6 @@ public class AppCardController extends RecyclerView.ViewHolder
icon = (ImageView) findViewAndEnsureNonNull(itemView, R.id.icon);
summary = (TextView) findViewAndEnsureNonNull(itemView, R.id.summary);
featuredImage = (FeatureImage) itemView.findViewById(R.id.featured_image);
newTag = (TextView) itemView.findViewById(R.id.new_tag);
itemView.setOnClickListener(this);
@ -113,25 +96,7 @@ public class AppCardController extends RecyclerView.ViewHolder
}
}
ImageLoader.getInstance().displayImage(app.iconUrl, icon, Utils.getRepoAppDisplayImageOptions(), this);
if (featuredImage != null) {
featuredImage.setColour(ContextCompat.getColor(activity, R.color.fdroid_blue));
featuredImage.setImageDrawable(null);
// Note: We could call the convenience function
// loadImageAndDisplay(ImageLoader, DisplayImageOptions, String, String)
// which includes a fallback for when currentApp.featureGraphic is empty. However we need
// to take care of also loading the icon (regardless of whether there is a featureGraphic
// or not for this app) so that we can display the icon to the user. We will use the
// load complete listener for the icon to decide whether we need to extract the colour
// from that icon and assign to the `FeatureImage` (or whether we should wait for the
// feature image to be loaded).
if (!TextUtils.isEmpty(app.featureGraphic)) {
featuredImage.loadImageAndDisplay(ImageLoader.getInstance(),
Utils.getRepoAppDisplayImageOptions(), app.getFeatureGraphicUrl(activity));
}
}
ImageLoader.getInstance().displayImage(app.iconUrl, icon, Utils.getRepoAppDisplayImageOptions());
}
private boolean isConsideredNew(@NonNull App app) {
@ -166,44 +131,4 @@ public class AppCardController extends RecyclerView.ViewHolder
activity.startActivity(intent);
}
}
// =============================================================================================
// Icon loader callbacks
//
// Most are unused, the main goal is to specify a background colour for the featured image if
// no featured image is specified in the apps metadata. If an image is specified, then it will
// get loaded using the `FeatureImage.loadImageAndDisplay()` method and so we don't need to do
// anything special here.
// =============================================================================================
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (currentApp != null
&& TextUtils.isEmpty(currentApp.featureGraphic)
&& featuredImage != null
&& loadedImage != null) {
new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(@NonNull Palette palette) {
featuredImage.setColorAndAnimateChange(palette.getDominantColor(Color.LTGRAY));
}
});
}
}
@Override
public void onLoadingStarted(String imageUri, View view) {
// Do nothing
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
// Do nothing
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
// Do nothing
}
}

View File

@ -11,7 +11,6 @@ import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import org.fdroid.fdroid.BuildConfig;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.App;
@ -44,15 +43,17 @@ public class WhatsNewAdapter extends RecyclerView.Adapter<AppCardController> {
@Override
public AppCardController onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
int layout;
if (viewType == R.id.whats_new_feature) {
layout = R.layout.app_card_featured;
} else if (viewType == R.id.whats_new_large_tile) {
switch (viewType) {
case R.id.whats_new_large_tile:
layout = R.layout.app_card_large;
} else if (viewType == R.id.whats_new_small_tile) {
break;
case R.id.whats_new_small_tile:
layout = R.layout.app_card_horizontal;
} else if (viewType == R.id.whats_new_regular_list) {
break;
case R.id.whats_new_regular_list:
layout = R.layout.app_card_list_item;
} else {
break;
default:
throw new IllegalArgumentException("Unknown view type when rendering \"Whats New\": " + viewType);
}
@ -72,7 +73,7 @@ public class WhatsNewAdapter extends RecyclerView.Adapter<AppCardController> {
}
if (position == 0) {
return R.id.whats_new_feature;
return R.id.whats_new_regular_list;
} else {
switch (relativePositionInCycle) {
case 1:
@ -145,11 +146,7 @@ public class WhatsNewAdapter extends RecyclerView.Adapter<AppCardController> {
int verticalPadding = (int) resources.getDimension(R.dimen.whats_new__padding__app_card__vertical);
int relativePositionInCycle = position % 5;
if (position == 0) {
// Don't set any padding for the first item as the FeatureImage behind it needs to butt right
// up against the left/top/right of the screen.
outRect.set(0, 0, 0, verticalPadding);
} else if (relativePositionInCycle != 0) {
if (relativePositionInCycle != 0) {
// The item on the left will have both left and right padding. The item on the right
// will only have padding on the right. This will allow the same amount of padding
// on the left, centre, and right of the grid, rather than double the padding in the
@ -161,7 +158,7 @@ public class WhatsNewAdapter extends RecyclerView.Adapter<AppCardController> {
int paddingRight = isLtr ? horizontalPadding : paddingStart;
outRect.set(paddingLeft, 0, paddingRight, verticalPadding);
} else {
outRect.set(horizontalPadding, 0, horizontalPadding, verticalPadding);
outRect.set(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
}
}
}

View File

@ -1,87 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dp"
android:clipToPadding="false">
<org.fdroid.fdroid.views.apps.FeatureImage
android:id="@+id/featured_image"
android:layout_width="0dp"
android:layout_height="120dp"
tools:src="@color/fdroid_green"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/header_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="80dp" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/whats_new__padding__app_card__horizontal"
android:layout_marginStart="@dimen/whats_new__padding__app_card__horizontal"
android:layout_marginRight="@dimen/whats_new__padding__app_card__horizontal"
android:layout_marginEnd="@dimen/whats_new__padding__app_card__horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/header_height"
android:foreground="?attr/selectableItemBackground"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp">
<!-- Ignore ContentDescription because it is kind of meaningless to have TTS read out "App icon"
when it will inevitably read out the name of the app straight after. -->
<ImageView
android:id="@+id/icon"
android:layout_width="48dp"
android:layout_height="48dp"
tools:src="@drawable/ic_launcher"
android:scaleType="fitCenter"
android:transitionName="@string/transition_app_item_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
tools:text="F-Droid An application summary which takes up too much space and must ellipsize, perhaps after wrapping to a new line"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/summary"
android:lines="2"
android:textSize="14sp"
android:ellipsize="end"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include layout="@layout/app_status_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/new_tag"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/summary"
app:layout_constraintStart_toEndOf="@+id/icon"
android:layout_marginTop="8dp" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>

View File

@ -2,7 +2,6 @@
<resources>
<item type="id" name="preference_fragment_parent"/>
<item type="id" name="whats_new_feature"/>
<item type="id" name="whats_new_large_tile"/>
<item type="id" name="whats_new_small_tile"/>
<item type="id" name="whats_new_regular_list"/>