Skip to content

Commit

Permalink
Added swipe to update for gallery view
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback committed Jan 4, 2018
1 parent 5e89eed commit cad3d39
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -37,6 +38,7 @@ public interface OnChangeFragmentListener {

private OnChangeFragmentListener contextCallback;
private SectionedRecyclerViewAdapter sectionAdapter;
private SwipeRefreshLayout refreshLayout;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand Down Expand Up @@ -64,6 +66,17 @@ public int getSpanSize(int position) {
recyclerView.setLayoutManager(glm);
recyclerView.setAdapter(sectionAdapter);

refreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipeRefreshLayout);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
prepareData();

refreshLayout.setRefreshing(false);
}
});
refreshLayout.setEnabled(true);

return view;
}

Expand Down Expand Up @@ -114,6 +127,7 @@ private void prepareData() {
}
}

sectionAdapter.removeAllSections();
for (Map.Entry<String, Collection<File>> entry : treeListMultimap.asMap().entrySet()) {
List<GalleryItem> galleryItems = new ArrayList<>();
for (File galleryFile : entry.getValue()) {
Expand All @@ -123,6 +137,8 @@ private void prepareData() {
GallerySection section = new GallerySection(getActivity(), entry.getKey(), galleryItems, this);
sectionAdapter.addSection(section);
}

sectionAdapter.notifyDataSetChanged();
}

@Override
Expand All @@ -136,4 +152,11 @@ public void clicked(GalleryItem item) {
public void notifyDataSetChanged() {
sectionAdapter.notifyDataSetChanged();
}

@Override
public void onResume() {
super.onResume();

prepareData();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package de.timonback.android.whatisthatplace.activity;

import android.app.Fragment;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import de.timonback.android.whatisthatplace.R;
import de.timonback.android.whatisthatplace.component.CameraComponent;
import de.timonback.android.whatisthatplace.component.gallery.GallerySection;

public class MainActivity extends AppCompatActivity implements GalleryFragment.OnChangeFragmentListener {
private static final String LOG_NAME = MainActivity.class.getName();
Expand All @@ -27,6 +24,8 @@ protected void onCreate(Bundle savedInstanceState) {

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.mipmap.ic_launcher);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
Expand All @@ -37,12 +36,13 @@ public void onClick(View v) {
});
}

/*
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}*/

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ private void updateView() {
@Override
public void call(VisionResult param) {
if (param.getLandmarks().isEmpty()) {
Toast.makeText(context, "no landmark identified", Toast.LENGTH_SHORT).show();
String notFound = "no landmark identified";
Toast.makeText(context, notFound, Toast.LENGTH_SHORT).show();

TextView nameView = getActivity().findViewById(R.id.visionName);
nameView.setText(notFound);
TextView descriptionView = getActivity().findViewById(R.id.visionDescription);
descriptionView.setText(notFound);

return;
}

Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/layout/fragment_gallery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
android:layout_height="match_parent"
tools:context="de.timonback.android.whatisthatplace.activity.GalleryFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/imagegallery"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/imagegallery"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

0 comments on commit cad3d39

Please sign in to comment.