Skip to content

Commit

Permalink
Clean up libraries screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Oct 18, 2016
1 parent df90f14 commit 30a29c4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
100 changes: 60 additions & 40 deletions app/src/main/java/io/plaidapp/ui/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
Expand All @@ -39,6 +40,7 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.Glide;

import java.security.InvalidParameterException;
Expand Down Expand Up @@ -102,7 +104,7 @@ static class AboutPagerAdapter extends PagerAdapter {
private final LayoutInflater layoutInflater;
private final Bypass markdown;

/* package */ AboutPagerAdapter(Context context) {
AboutPagerAdapter(Context context) {
layoutInflater = LayoutInflater.from(context);
markdown = new Bypass(context, new Bypass.Options());
}
Expand Down Expand Up @@ -186,38 +188,45 @@ private static class LibraryAdapter extends RecyclerView.Adapter<RecyclerView.Vi
private static final int VIEW_TYPE_INTRO = 0;
private static final int VIEW_TYPE_LIBRARY = 1;
private static final Library[] libs = {
new Library("Android support libs",
"The Android Support Library offers a number of features that are not built into the framework",
"https://android.googlesource.com/platform/frameworks/support/",
"http://developer.android.com/assets/images/[email protected]"),
new Library("Android support libraries",
"The Android support libraries offer a number of features that are not built into the framework.",
"https://developer.android.com/topic/libraries/support-library",
"https://developer.android.com/images/android_icon_125.png",
false),
new Library("ButterKnife",
"Bind Android views and callbacks to fields and methods",
"Bind Android views and callbacks to fields and methods.",
"http://jakewharton.github.io/butterknife/",
"https://avatars.githubusercontent.com/u/66577"),
"https://avatars.githubusercontent.com/u/66577",
true),
new Library("Bypass",
"Skip the HTML, Bypass takes markdown and renders it directly on Android and iOS",
"Skip the HTML, Bypass takes markdown and renders it directly.",
"https://github.com/Uncodin/bypass",
"https://avatars.githubusercontent.com/u/1072254"),
"https://avatars.githubusercontent.com/u/1072254",
true),
new Library("Glide",
"An image loading and caching library for Android focused on smooth scrolling",
"An image loading and caching library for Android focused on smooth scrolling.",
"https://github.com/bumptech/glide",
"https://avatars.githubusercontent.com/u/423539"),
"https://avatars.githubusercontent.com/u/423539",
false),
new Library("JSoup",
"Java HTML Parser, with best of DOM, CSS, and jquery ",
"Java HTML Parser, with best of DOM, CSS, and jquery.",
"https://github.com/jhy/jsoup/",
"https://avatars.githubusercontent.com/u/76934"),
"https://avatars.githubusercontent.com/u/76934",
true),
new Library("OkHttp",
"An HTTP & HTTP/2 client for Android and Java applications",
"An HTTP & HTTP/2 client for Android and Java applications.",
"http://square.github.io/okhttp/",
"https://avatars.githubusercontent.com/u/82592"),
"https://avatars.githubusercontent.com/u/82592",
false),
new Library("Retrofit",
"A type-safe HTTP client for Android and Java",
"A type-safe HTTP client for Android and Java.",
"http://square.github.io/retrofit/",
"https://avatars.githubusercontent.com/u/82592") };
"https://avatars.githubusercontent.com/u/82592",
false) };

private final CircleTransform circleCrop;

/* package */ LibraryAdapter(Context context) {
LibraryAdapter(Context context) {
circleCrop = new CircleTransform(context);
}

Expand All @@ -228,12 +237,28 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
return new LibraryIntroHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.about_lib_intro, parent, false));
case VIEW_TYPE_LIBRARY:
return new LibraryHolder(LayoutInflater.from(parent.getContext()).inflate(
R.layout.library, parent, false));
return createLibraryHolder(parent);
}
throw new InvalidParameterException();
}

private @NonNull LibraryHolder createLibraryHolder(ViewGroup parent) {
final LibraryHolder holder = new LibraryHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.library, parent, false));
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = holder.getAdapterPosition();
if (position == RecyclerView.NO_POSITION) return;
holder.itemView.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(libs[position - 1].link)));
}
};
holder.itemView.setOnClickListener(clickListener);
holder.link.setOnClickListener(clickListener);
return holder;
}

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == VIEW_TYPE_LIBRARY) {
Expand All @@ -254,20 +279,13 @@ public int getItemCount() {
private void bindLibrary(final LibraryHolder holder, final Library lib) {
holder.name.setText(lib.name);
holder.description.setText(lib.description);
Glide.with(holder.image.getContext())
DrawableRequestBuilder<String> request = Glide.with(holder.image.getContext())
.load(lib.imageUrl)
.placeholder(R.drawable.avatar_placeholder)
.transform(circleCrop)
.into(holder.image);
final View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.link.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(lib.link)));
}
};
holder.itemView.setOnClickListener(clickListener);
holder.link.setOnClickListener(clickListener);
.placeholder(R.drawable.avatar_placeholder);
if (lib.circleCrop) {
request.transform(circleCrop);
}
request.into(holder.image);
}
}

Expand All @@ -278,7 +296,7 @@ static class LibraryHolder extends RecyclerView.ViewHolder {
@BindView(R.id.library_description) TextView description;
@BindView(R.id.library_link) Button link;

/* package */ LibraryHolder(View itemView) {
LibraryHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
Expand All @@ -288,7 +306,7 @@ static class LibraryIntroHolder extends RecyclerView.ViewHolder {

TextView intro;

/* package */ LibraryIntroHolder(View itemView) {
LibraryIntroHolder(View itemView) {
super(itemView);
intro = (TextView) itemView;
}
Expand All @@ -298,16 +316,18 @@ static class LibraryIntroHolder extends RecyclerView.ViewHolder {
* Models an open source library we want to credit
*/
private static class Library {
public final String name;
public final String link;
/* package */ final String description;
/* package */ final String imageUrl;
final String name;
final String link;
final String description;
final String imageUrl;
final boolean circleCrop;

/* package */ Library(String name, String description, String link, String imageUrl) {
Library(String name, String description, String link, String imageUrl, boolean circleCrop) {
this.name = name;
this.description = description;
this.link = link;
this.imageUrl = imageUrl;
this.circleCrop = circleCrop;
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/library.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:paddingBottom="@dimen/spacing_normal"
android:foreground="?android:selectableItemBackground"
android:stateListAnimator="@animator/raise"
android:background="@color/background_light"
android:background="@color/background_card"
android:elevation="@dimen/z_card">

<ImageView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<color name="ripple_dark">@color/mid_grey</color>
<color name="background_light">#fafafa</color> <!-- grey 50 -->
<color name="background_lightish">#e0e0e0</color> <!-- grey 300 -->
<color name="background_card">#ffffff</color>
<color name="background_dark">#ff333333</color>
<color name="immersive_bars">#99000000</color>
<color name="light_immersive_bars">@color/immersive_bars</color>
Expand Down

0 comments on commit 30a29c4

Please sign in to comment.