Skip to content

Commit

Permalink
[EXAM] Creates RecycleView for Exams
Browse files Browse the repository at this point in the history
- Now Exam have one RecycleView to show
- Fix bug on reload Exam

Signed-off-by: Arthur Diniz <[email protected]>
Signed-off-by: Guilherme Augusto <[email protected]>
  • Loading branch information
arthurbdiniz committed May 13, 2017
1 parent b345f29 commit fee8de0
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 19 deletions.
115 changes: 102 additions & 13 deletions app/src/main/java/fga/mds/gpp/trezentos/View/ExamsFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fga.mds.gpp.trezentos.View;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
Expand All @@ -20,6 +21,7 @@
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.util.ArrayList;

Expand Down Expand Up @@ -48,7 +50,6 @@ public ExamsFragment() {
public static ExamsFragment newInstance(String param1, String param2) {
ExamsFragment fragment = new ExamsFragment();
Bundle args = new Bundle();

return fragment;
}

Expand All @@ -60,6 +61,7 @@ public void onCreate(Bundle savedInstanceState){
@Override
public void onResume(){
super.onResume();
new ServerOperation().execute();

}

Expand All @@ -76,18 +78,27 @@ private void loadRecover(){
}

public void initListView(){
arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, userExams);
arrayAdapter.notifyDataSetChanged();

listView = (ListView) getActivity().findViewById(R.id.list);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Snackbar.make(view, "Click List", Snackbar.LENGTH_LONG).setAction("No action", null).show();
}
});
// arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, userExams);
// arrayAdapter.notifyDataSetChanged();
//
// listView = (ListView) getActivity().findViewById(R.id.list);
// listView.setAdapter(arrayAdapter);
// listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// @Override
// public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//
// Snackbar.make(view, "Click List", Snackbar.LENGTH_LONG).setAction("No action", null).show();
// }
// });

progressBar.setVisibility(View.GONE);

RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.recycler);
recyclerView.setAdapter(new ExamsFragment.Adapter(userExams, getActivity().getApplicationContext(), recyclerView));

final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);

}

Expand Down Expand Up @@ -139,4 +150,82 @@ protected void onPreExecute() {
@Override
protected void onProgressUpdate(Void... values) {}
}

private class Adapter extends RecyclerView.Adapter implements View.OnClickListener {

private final ArrayList<Exam> exams;
private Context context;
private RecyclerView recyclerView;


public Adapter(ArrayList<Exam> exams, Context context, RecyclerView recyclerView) {
this.exams = exams;
this.context = context;
this.recyclerView = recyclerView;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(context).inflate(R.layout.exam_item, parent, false);
ExamsFragment.ViewHolder holder = new ExamsFragment.ViewHolder(view);
view.setOnClickListener(this);

return holder;
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

ExamsFragment.ViewHolder holder = (ExamsFragment.ViewHolder) viewHolder;


Exam exam = exams.get(position) ;
holder.className.setText(exam.getNameExam());//


}

@Override
public int getItemCount() {
return exams.size();
}

@Override
public long getItemId(int position) {
return super.getItemId(position);
}


@Override
public void onClick(View v) {

int itemPosition = recyclerView.getChildLayoutPosition(v);
Exam exam = exams.get(itemPosition);

Intent goClass = new Intent(context, ClassActivity.class);
goClass.putExtra("Class", userClass);
goClass.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(goClass);

}
}


public class ViewHolder extends RecyclerView.ViewHolder {

final TextView className;


public ViewHolder(View view) {
super(view);
className = (TextView) view.findViewById(R.id.class_name);

}
}


}



35 changes: 35 additions & 0 deletions app/src/main/res/layout/exam_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
xmlns:card_view="http://schemas.android.com/apk/res-auto"

android:layout_margin="4dp"
android:weightSum="1"
card_view:cardCornerRadius="10dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#444444">


<TextView
android:id="@+id/class_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"

android:text="Classe"
android:textColor="#FFF"
android:textSize="20dp"
android:textStyle="bold"

android:layout_marginLeft="50dp"/>

</RelativeLayout>



</android.support.v7.widget.CardView>
14 changes: 8 additions & 6 deletions app/src/main/res/layout/fragment_exams.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
tools:context="fga.mds.gpp.trezentos.View.ExamsFragment">


<ListView
android:id="@+id/list"

android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>

<ProgressBar
android:id="@+id/progressBarExam"
Expand All @@ -21,6 +15,14 @@
android:layout_gravity="center_horizontal|center_vertical"
android:visibility="gone" />

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
/>



</FrameLayout>

0 comments on commit fee8de0

Please sign in to comment.