Fixed ModDetailsOverviewAdapter with Assignments
This commit is contained in:
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -9,32 +10,63 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.ms.square.android.expandabletextview.ExpandableTextView;
|
import com.ms.square.android.expandabletextview.ExpandableTextView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.Announcement;
|
import de.sebse.fuplanner.services.KVV.Announcement;
|
||||||
import de.sebse.fuplanner.services.KVV.Assignment;
|
import de.sebse.fuplanner.services.KVV.Assignment;
|
||||||
import de.sebse.fuplanner.services.KVV.Modules;
|
import de.sebse.fuplanner.services.KVV.Modules;
|
||||||
import de.sebse.fuplanner.tools.Conversion;
|
import de.sebse.fuplanner.tools.Conversion;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||||
|
|
||||||
public class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private static final int MAX_ITEMS_PER_PREVIEW = 2;
|
||||||
|
|
||||||
private static final int TYPE_HEADER = 0;
|
private static final int TYPE_HEADER = 0;
|
||||||
private static final int TYPE_DESCRIPTION = 1;
|
private static final int TYPE_DESCRIPTION = 1;
|
||||||
private static final int TYPE_ITEM = 2;
|
private static final int TYPE_ITEM = 2;
|
||||||
private static final int TYPE_SHOW_MORE = 3;
|
private static final int TYPE_SHOW_MORE = 3;
|
||||||
|
|
||||||
|
private static final int SECTION_DESCRIPTION = 0;
|
||||||
|
private static final int SECTION_ANNOUNCEMENT = 1;
|
||||||
|
private static final int SECTION_ASSIGNMENT = 2;
|
||||||
|
|
||||||
private Modules.Module mValue;
|
private Modules.Module mValue;
|
||||||
|
private final ArrayList<Pair<Integer, Object>> mPositionalData;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
//private final ModulesFragment.OnModulesFragmentInteractionListener mListener;
|
//private final ModulesFragment.OnModulesFragmentInteractionListener mListener;
|
||||||
|
|
||||||
public ModDetailOverviewAdapter(/*ModulesFragment.OnModulesFragmentInteractionListener listener*/) {
|
public ModDetailOverviewAdapter(/*ModulesFragment.OnModulesFragmentInteractionListener listener*/) {
|
||||||
mValue = null;
|
mValue = null;
|
||||||
|
mPositionalData = new ArrayList<>();
|
||||||
//mListener = listener;
|
//mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModule(Modules.Module module) {
|
public void setModule(Modules.Module module) {
|
||||||
mValue = module;
|
mValue = module;
|
||||||
|
this.setModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModule() {
|
||||||
|
mPositionalData.clear();
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_HEADER, SECTION_DESCRIPTION));
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_DESCRIPTION, null));
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_HEADER, SECTION_ANNOUNCEMENT));
|
||||||
|
addPositionalListData(getAnnounceCount(), SECTION_ANNOUNCEMENT);
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_HEADER, SECTION_ASSIGNMENT));
|
||||||
|
addPositionalListData(getAssignmentCount(), SECTION_ASSIGNMENT);
|
||||||
this.notifyDataSetChanged();
|
this.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addPositionalListData(int count, int category) {
|
||||||
|
for (int i = 0; i < Math.min(MAX_ITEMS_PER_PREVIEW, count); i++) {
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_ITEM, category+1024*i));
|
||||||
|
}
|
||||||
|
if (count > MAX_ITEMS_PER_PREVIEW)
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_SHOW_MORE, category));
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
@@ -64,66 +96,64 @@ public class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
// Just as an example, return 0 or 2 depending on position
|
|
||||||
// Note that unlike in ListView adapters, types don't have to be contiguous
|
// Note that unlike in ListView adapters, types don't have to be contiguous
|
||||||
if (position < 3)
|
if (position < mPositionalData.size())
|
||||||
return position % 2; // HEADER, DESCRIPTION, HEADER
|
return mPositionalData.get(position).first;
|
||||||
int count = 2;
|
else return -1;
|
||||||
|
|
||||||
// Announcements
|
|
||||||
if (position <= count+getAnnounceCount(2))
|
|
||||||
return TYPE_ITEM;
|
|
||||||
count += getAnnounceCount(3);
|
|
||||||
if (position <= count)
|
|
||||||
return TYPE_SHOW_MORE;
|
|
||||||
|
|
||||||
// Assignments
|
|
||||||
count++;
|
|
||||||
if (position <= count)
|
|
||||||
return TYPE_HEADER;
|
|
||||||
count++;
|
|
||||||
if (position <= count+getAssignmentCount(2))
|
|
||||||
return TYPE_ITEM;
|
|
||||||
count += getAssignmentCount(3);
|
|
||||||
if (position <= count)
|
|
||||||
return TYPE_SHOW_MORE;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
|
||||||
if (mValue == null)
|
if (mValue == null || position > mPositionalData.size())
|
||||||
return;
|
return;
|
||||||
if (position == 0) {
|
Pair<Integer, Object> data = mPositionalData.get(position);
|
||||||
|
switch (data.first) {
|
||||||
|
case TYPE_HEADER:
|
||||||
HeaderViewHolder h = (HeaderViewHolder) holder;
|
HeaderViewHolder h = (HeaderViewHolder) holder;
|
||||||
|
switch ((Integer) data.second) {
|
||||||
|
case SECTION_DESCRIPTION:
|
||||||
h.mCaption.setText(R.string.description);
|
h.mCaption.setText(R.string.description);
|
||||||
} else if (position == 1) {
|
break;
|
||||||
|
case SECTION_ANNOUNCEMENT:
|
||||||
|
h.mCaption.setText(h.mView.getResources().getString(R.string.announcements_count, getAnnounceCount()));
|
||||||
|
break;
|
||||||
|
case SECTION_ASSIGNMENT:
|
||||||
|
h.mCaption.setText(h.mView.getResources().getString(R.string.assignments_count, getAssignmentCount()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TYPE_DESCRIPTION:
|
||||||
DescriptionViewHolder d = (DescriptionViewHolder) holder;
|
DescriptionViewHolder d = (DescriptionViewHolder) holder;
|
||||||
d.mText.setText(mValue.description);
|
d.mText.setText(mValue.description);
|
||||||
} else if (position == 2) {
|
break;
|
||||||
HeaderViewHolder h = (HeaderViewHolder) holder;
|
case TYPE_ITEM:
|
||||||
h.mCaption.setText(h.mView.getResources().getString(R.string.announcements_count, getAnnounceCount()));
|
int section = ((Integer) data.second) % 1024;
|
||||||
} else if (position <= getAnnounceCount(2)+2) {
|
int index = ((Integer) data.second) / 1024;
|
||||||
ItemViewHolder a = (ItemViewHolder) holder;
|
ItemViewHolder i = (ItemViewHolder) holder;
|
||||||
Announcement announce = mValue.announcements.get(position - 3);
|
switch (section) {
|
||||||
a.mTitle.setText(announce.getTitle());
|
case SECTION_ANNOUNCEMENT:
|
||||||
a.mSubLeft.setText(announce.getCreatedBy());
|
Announcement announce = mValue.announcements.get(index);
|
||||||
a.mSubRight.setText(Conversion.getModifiedDate(announce.getCreatedOn()));
|
i.mTitle.setText(announce.getTitle());
|
||||||
} else if (position <= getAnnounceCount(3)+getAssignmentCount(2)+3) {
|
i.mSubLeft.setText(announce.getCreatedBy());
|
||||||
ItemViewHolder a = (ItemViewHolder) holder;
|
i.mSubRight.setText(Conversion.getModifiedDate(announce.getCreatedOn()));
|
||||||
Assignment assignment = mValue.assignments.get(position - 3);
|
i.mView.setOnClickListener(view -> log.d("Reference to:", SECTION_ANNOUNCEMENT, index));
|
||||||
a.mTitle.setText(assignment.getTitle());
|
break;
|
||||||
a.mSubLeft.setText(assignment.getStatus());
|
case SECTION_ASSIGNMENT:
|
||||||
a.mSubRight.setText(Conversion.getModifiedDate(assignment.getDueDate()));
|
Assignment assignment = mValue.assignments.get(index);
|
||||||
|
i.mTitle.setText(assignment.getTitle());
|
||||||
|
i.mSubLeft.setText(assignment.getStatus());
|
||||||
|
i.mSubRight.setText(Conversion.getModifiedDate(assignment.getDueDate()));
|
||||||
|
i.mView.setOnClickListener(view -> log.d("Refeerence to:", SECTION_ASSIGNMENT, index));
|
||||||
|
}
|
||||||
|
case TYPE_SHOW_MORE:
|
||||||
|
CustomViewHolder c = (CustomViewHolder) holder;
|
||||||
|
c.mView.setOnClickListener(view -> log.d("Refeerence to:", data.second, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (mValue != null) {
|
return mPositionalData.size();
|
||||||
return 4+getAnnounceCount(3)+getAssignmentCount(3);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAnnounceCount() {
|
private int getAnnounceCount() {
|
||||||
@@ -132,20 +162,12 @@ public class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAnnounceCount(int max) {
|
|
||||||
return Math.min(max, getAnnounceCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getAssignmentCount() {
|
private int getAssignmentCount() {
|
||||||
if (mValue.assignments != null)
|
if (mValue.assignments != null)
|
||||||
return mValue.assignments.size();
|
return mValue.assignments.size();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAssignmentCount(int max) {
|
|
||||||
return Math.min(max, getAssignmentCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">FU Planner</string>
|
<string name="app_name" translatable="false">FU Planner</string>
|
||||||
|
|
||||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<!-- TODO: Remove or change this placeholder text -->
|
<!-- TODO: Remove or change this placeholder text -->
|
||||||
<string name="overview">Overview</string>
|
<string name="overview">Overview</string>
|
||||||
<string name="announcements">Announcements</string>
|
<string name="announcements">Announcements</string>
|
||||||
<string name="lorem_ipsum_100">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</string>
|
<string name="lorem_ipsum_100" translatable="false">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</string>
|
||||||
<string name="description">Description</string>
|
<string name="description">Description</string>
|
||||||
<string name="announcements_count">Announcements (%1$d)</string>
|
<string name="announcements_count">Announcements (%1$d)</string>
|
||||||
<string name="cd_ic_launcher">App Icon</string>
|
<string name="cd_ic_launcher">App Icon</string>
|
||||||
@@ -24,4 +24,6 @@
|
|||||||
<string name="username">Username</string>
|
<string name="username">Username</string>
|
||||||
<string name="password">Password</string>
|
<string name="password">Password</string>
|
||||||
<string name="show_all">Show All</string>
|
<string name="show_all">Show All</string>
|
||||||
|
<string name="assignments_count">Assignments (%1$d)</string>
|
||||||
|
<string name="assignments">Assignments</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user