Added Gradebook
This commit is contained in:
@@ -23,7 +23,7 @@ class ModDetailAdapter extends FragmentStatePagerAdapter {
|
|||||||
// Returns total number of pages
|
// Returns total number of pages
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the fragment to display for that page
|
// Returns the fragment to display for that page
|
||||||
@@ -38,6 +38,8 @@ class ModDetailAdapter extends FragmentStatePagerAdapter {
|
|||||||
return ModDetailAssignmentFragment.newInstance(mItemPos);
|
return ModDetailAssignmentFragment.newInstance(mItemPos);
|
||||||
case 3:
|
case 3:
|
||||||
return ModDetailEventFragment.newInstance(mItemPos);
|
return ModDetailEventFragment.newInstance(mItemPos);
|
||||||
|
case 4:
|
||||||
|
return ModDetailGradebookFragment.newInstance(mItemPos);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -55,6 +57,8 @@ class ModDetailAdapter extends FragmentStatePagerAdapter {
|
|||||||
return this.mContext.getResources().getString(R.string.assignments);
|
return this.mContext.getResources().getString(R.string.assignments);
|
||||||
case 3:
|
case 3:
|
||||||
return this.mContext.getResources().getString(R.string.events);
|
return this.mContext.getResources().getString(R.string.events);
|
||||||
|
case 4:
|
||||||
|
return this.mContext.getResources().getString(R.string.gradebook);
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Pair;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.R;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Gradebook;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||||
|
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||||
|
|
||||||
|
public class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private static final int TYPE_TOTAL = 0;
|
||||||
|
private static final int TYPE_GRADE = 1;
|
||||||
|
|
||||||
|
private static final int SECTION_GRADE = 0;
|
||||||
|
|
||||||
|
private Modules.Module mValue;
|
||||||
|
private final ArrayList<Pair<Integer, Integer>> mPositionalData;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
|
//private final ModulesFragment.OnModulesFragmentInteractionListener mListener;
|
||||||
|
|
||||||
|
public ModDetailGradebookAdapter(/*ModulesFragment.OnModulesFragmentInteractionListener listener*/) {
|
||||||
|
mValue = null;
|
||||||
|
mPositionalData = new ArrayList<>();
|
||||||
|
//mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModule(Modules.Module module) {
|
||||||
|
mValue = module;
|
||||||
|
this.setModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModule() {
|
||||||
|
mPositionalData.clear();
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_TOTAL, SECTION_GRADE));
|
||||||
|
addPositionalListData(getGradesCount(), SECTION_GRADE);
|
||||||
|
|
||||||
|
this.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPositionalListData(int count, int category) {
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_GRADE, category+1024*i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View view;
|
||||||
|
switch (viewType) {
|
||||||
|
case TYPE_TOTAL:
|
||||||
|
view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.list_all_caption, parent, false);
|
||||||
|
return new HeaderViewHolder(view);
|
||||||
|
case TYPE_GRADE:
|
||||||
|
view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.list_all_items, parent, false);
|
||||||
|
return new ItemViewHolder(view);
|
||||||
|
default:
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
// Note that unlike in ListView adapters, types don't have to be contiguous
|
||||||
|
if (position < mPositionalData.size())
|
||||||
|
return mPositionalData.get(position).first;
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
|
||||||
|
if (mValue == null || position > mPositionalData.size())
|
||||||
|
return;
|
||||||
|
Pair<Integer, Integer> data = mPositionalData.get(position);
|
||||||
|
switch (data.first) {
|
||||||
|
case TYPE_TOTAL:
|
||||||
|
HeaderViewHolder h = (HeaderViewHolder) holder;
|
||||||
|
h.mCaption.setText(R.string.hello_blank_fragment);
|
||||||
|
break;
|
||||||
|
case TYPE_GRADE:
|
||||||
|
int index = data.second / 1024;
|
||||||
|
ItemViewHolder i = (ItemViewHolder) holder;
|
||||||
|
Gradebook gradebook = mValue.gradebook.get(index);
|
||||||
|
|
||||||
|
i.mTitle.setText(gradebook.getItemName());
|
||||||
|
i.mSubLeft.setText(String.valueOf(gradebook.getPoints()));
|
||||||
|
i.mSubRight.setText(String.valueOf(gradebook.getMaxPoints()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mPositionalData.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getGradesCount() {
|
||||||
|
if (mValue.gradebook != null)
|
||||||
|
return mValue.gradebook.size();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class HeaderViewHolder extends CustomViewHolder {
|
||||||
|
final TextView mCaption;
|
||||||
|
|
||||||
|
HeaderViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
mCaption = view.findViewById(R.id.caption);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " '" + mCaption.getText() + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.MainActivity;
|
||||||
|
import de.sebse.fuplanner.R;
|
||||||
|
import de.sebse.fuplanner.services.KVV.KVV;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple {@link Fragment} subclass.
|
||||||
|
* Use the {@link ModDetailGradebookFragment#newInstance} factory method to
|
||||||
|
* create an instance of this fragment.
|
||||||
|
*/
|
||||||
|
public class ModDetailGradebookFragment extends Fragment {
|
||||||
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
|
private static final String ARG_POSITION = "itemPosition";
|
||||||
|
|
||||||
|
// TODO: Rename and change types of parameters
|
||||||
|
private int mItemPos;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
|
private ModDetailGradebookAdapter adapter;
|
||||||
|
private SwipeRefreshLayout swipeLayout;
|
||||||
|
|
||||||
|
|
||||||
|
public ModDetailGradebookFragment() {
|
||||||
|
// Required empty public constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this factory method to create a new instance of
|
||||||
|
* this fragment using the provided parameters.
|
||||||
|
*
|
||||||
|
* @param itemPosition Item position in module list.
|
||||||
|
* @return A new instance of fragment ModDetailAnnounceFragment.
|
||||||
|
*/
|
||||||
|
// TODO: Rename and change types and number of parameters
|
||||||
|
public static ModDetailGradebookFragment newInstance(int itemPosition) {
|
||||||
|
ModDetailGradebookFragment fragment = new ModDetailGradebookFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt(ARG_POSITION, itemPosition);
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (getArguments() != null) {
|
||||||
|
mItemPos = getArguments().getInt(ARG_POSITION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
View view = inflater.inflate(R.layout.fragment_recycler_view, container, false);
|
||||||
|
// Set the adapter
|
||||||
|
Context context = view.getContext();
|
||||||
|
RecyclerView recyclerView = view.findViewById(R.id.list);
|
||||||
|
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||||
|
adapter = new ModDetailGradebookAdapter();
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
// Getting SwipeContainerLayout
|
||||||
|
swipeLayout = view.findViewById(R.id.swipe_container);
|
||||||
|
// Adding Listener
|
||||||
|
swipeLayout.setOnRefreshListener(() -> refresh(true));
|
||||||
|
refresh(false);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refresh(boolean forceRefresh) {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
||||||
|
kvv.getModuleList((Modules success) -> {
|
||||||
|
Modules.Module module = success.get(mItemPos);
|
||||||
|
adapter.setModule(module);
|
||||||
|
kvv.getModuleGradebook(module, success1 -> {
|
||||||
|
adapter.setModule();
|
||||||
|
swipeLayout.setRefreshing(false);
|
||||||
|
}, error -> {
|
||||||
|
swipeLayout.setRefreshing(false);
|
||||||
|
log.e(error);
|
||||||
|
});
|
||||||
|
}, error -> {
|
||||||
|
swipeLayout.setRefreshing(false);
|
||||||
|
log.e(error);
|
||||||
|
}, forceRefresh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -36,4 +36,5 @@
|
|||||||
<string name="no_items_available">No items available!</string>
|
<string name="no_items_available">No items available!</string>
|
||||||
<string name="past_events">Past Events</string>
|
<string name="past_events">Past Events</string>
|
||||||
<string name="events">Events</string>
|
<string name="events">Events</string>
|
||||||
|
<string name="gradebook">Gradebook</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user