Skip to content

Commit

Permalink
Added expandable sections
Browse files Browse the repository at this point in the history
Improved gallery item description
  • Loading branch information
timonback committed Jan 4, 2018
1 parent 1ce4948 commit 5e89eed
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package de.timonback.android.whatisthatplace.activity;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.google.common.collect.ListMultimap;
import com.google.common.collect.MultimapBuilder;
Expand All @@ -29,10 +26,6 @@
import de.timonback.android.whatisthatplace.activity.provider.ImageProvider;
import de.timonback.android.whatisthatplace.component.gallery.GalleryItem;
import de.timonback.android.whatisthatplace.component.gallery.GallerySection;
import de.timonback.android.whatisthatplace.model.knowledge.KnowledgeResult;
import de.timonback.android.whatisthatplace.model.vision.VisionResult;
import de.timonback.android.whatisthatplace.service.ServiceProvider;
import de.timonback.android.whatisthatplace.util.MyParamCallable;
import io.github.luizgrp.sectionedrecyclerviewadapter.SectionedRecyclerViewAdapter;

public class GalleryFragment extends Fragment implements GallerySection.OnGalleryItemClickListener {
Expand Down Expand Up @@ -134,9 +127,13 @@ private void prepareData() {

@Override
public void clicked(GalleryItem item) {
final Context context = getContext();
final File file = item.getImageFile();

contextCallback.onFragmentChange(file.getPath());
}

@Override
public void notifyDataSetChanged() {
sectionAdapter.notifyDataSetChanged();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package de.timonback.android.whatisthatplace.component.gallery;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GalleryItem {
private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
private final String title;
private final File file;

Expand All @@ -15,6 +18,11 @@ public String getTitle() {
return title;
}

public String getDescription() {
Date modificationDate = new Date(getImageFile().lastModified());
return sdf.format(modificationDate);
}

public File getImageFile() {
return file;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
package de.timonback.android.whatisthatplace.component.gallery;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.List;

import de.timonback.android.whatisthatplace.R;
import de.timonback.android.whatisthatplace.model.knowledge.KnowledgeResult;
import de.timonback.android.whatisthatplace.model.vision.VisionResult;
import de.timonback.android.whatisthatplace.service.ServiceProvider;
import de.timonback.android.whatisthatplace.util.MyParamCallable;
import io.github.luizgrp.sectionedrecyclerviewadapter.SectionParameters;
import io.github.luizgrp.sectionedrecyclerviewadapter.StatelessSection;

public class GallerySection extends StatelessSection {
public interface OnGalleryItemClickListener {
void clicked(GalleryItem item);
void notifyDataSetChanged();
}
private static final String LOG_NAME = GallerySection.class.getName();

Expand All @@ -48,7 +42,7 @@ public GallerySection(Context context, String title, List<GalleryItem> collectio

@Override
public int getContentItemsTotal() {
return list.size();
return expanded? list.size() : 0;
}

@Override
Expand All @@ -61,7 +55,7 @@ public void onBindItemViewHolder(RecyclerView.ViewHolder holder, final int posit
final ItemViewHolder itemHolder = (ItemViewHolder) holder;

String name = list.get(position).getTitle();
String category = list.get(position).getTitle();
String category = list.get(position).getDescription();

itemHolder.mainText.setText(name);
itemHolder.subText.setText(category);
Expand All @@ -84,20 +78,33 @@ public RecyclerView.ViewHolder getHeaderViewHolder(View view) {

@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
final HeaderViewHolder headerHolder = (HeaderViewHolder) holder;

headerHolder.title.setText(title);

headerHolder.rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expanded = !expanded;
headerHolder.arrow.setImageResource(
expanded ? R.drawable.ic_keyboard_arrow_up : R.drawable.ic_keyboard_arrow_down
);
listener.notifyDataSetChanged();
}
});
}

private class HeaderViewHolder extends RecyclerView.ViewHolder {
private final View rootView;
private final TextView title;
private final Button btnMore;
private final ImageView arrow;

HeaderViewHolder(View view) {
super(view);

rootView = view;
title = (TextView) view.findViewById(R.id.header_title);
btnMore = (Button) view.findViewById(R.id.header_button);
arrow = (ImageView) view.findViewById(R.id.header_arrow);
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 5 additions & 8 deletions app/src/main/res/layout/gallery_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
android:textStyle="bold"
android:id="@+id/header_title" />

<Button
android:id="@+id/header_button"
android:layout_width="wrap_content"
android:layout_height="30dp"
<ImageView
android:id="@+id/header_arrow"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="15dp"
android:textColor="@color/white"
android:textStyle="bold"
android:text="@string/gallery_header_more"
android:background="@drawable/selector_btn" />
android:src="@drawable/ic_keyboard_arrow_up"/>
</RelativeLayout>

0 comments on commit 5e89eed

Please sign in to comment.