mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-10-24 21:55:52 +03:00
Final Bugfix for Crash on quick scroll
This commit is contained in:
parent
5a2f4b69e5
commit
41ec417921
2 changed files with 28 additions and 37 deletions
|
@ -109,7 +109,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
|
|||
public void setListView(List<Note> noteList) {
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
// #12 Create Sections depending on Time
|
||||
|
||||
// TODO Move to ItemAdapter?
|
||||
boolean recentSet, todaySet, yesterdaySet, weekSet, monthSet, earlierSet;
|
||||
recentSet = todaySet = yesterdaySet = weekSet = monthSet = earlierSet = false;
|
||||
Calendar recent = Calendar.getInstance();
|
||||
|
|
|
@ -13,6 +13,12 @@ import java.util.List;
|
|||
import it.niedermann.owncloud.notes.R;
|
||||
|
||||
public class ItemAdapter extends ArrayAdapter<Item> {
|
||||
/**
|
||||
* Sections and Note-Items
|
||||
*/
|
||||
private static final int count_types = 2;
|
||||
private static final int section_type = 0;
|
||||
private static final int note_type = 1;
|
||||
private List<Item> itemList = null;
|
||||
|
||||
public ItemAdapter(Context context, List<Item> itemList) {
|
||||
|
@ -22,57 +28,42 @@ public class ItemAdapter extends ArrayAdapter<Item> {
|
|||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
|
||||
Item item = itemList.get(position);
|
||||
|
||||
if (item.isSection()) {
|
||||
// first check to see if the view is null. if so, we have to inflate it.
|
||||
// to inflate it basically means to render, or show, the view.
|
||||
if (v == null) {
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
v = inflater.inflate(R.layout.fragment_notes_list_section_item, null);
|
||||
convertView = inflater.inflate(R.layout.fragment_notes_list_section_item, null);
|
||||
}
|
||||
SectionItem section = (SectionItem) item;
|
||||
TextView sectionTitle = (TextView) v.findViewById(R.id.sectionTitle);
|
||||
TextView sectionTitle = (TextView) convertView.findViewById(R.id.sectionTitle);
|
||||
if (sectionTitle != null) {
|
||||
sectionTitle.setText(section.geTitle());
|
||||
}
|
||||
} else {
|
||||
// first check to see if the view is null. if so, we have to inflate it.
|
||||
// to inflate it basically means to render, or show, the view.
|
||||
if (v == null) {
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
v = inflater.inflate(R.layout.fragment_notes_list_note_item, null);
|
||||
convertView = inflater.inflate(R.layout.fragment_notes_list_note_item, null);
|
||||
}
|
||||
/*
|
||||
* Recall that the variable position is sent in as an argument to this
|
||||
* method. The variable simply refers to the position of the current
|
||||
* object in the list. (The ArrayAdapter iterates through the list we
|
||||
* sent it)
|
||||
*
|
||||
* Therefore, i refers to the current Item object.
|
||||
*/
|
||||
Note note = (Note) item;
|
||||
|
||||
// This is how you obtain a reference to the TextViews.
|
||||
// These TextViews are created in the XML files we defined.
|
||||
|
||||
TextView noteTitle = (TextView) v.findViewById(R.id.noteTitle);
|
||||
TextView noteExcerpt = (TextView) v
|
||||
.findViewById(R.id.noteExcerpt);
|
||||
TextView noteModified = (TextView) v.findViewById(R.id.noteModified);
|
||||
|
||||
if (noteTitle != null) { //FIXME on quick scroll or moving to portrait mode the TextView seems to be null. This is only to prevent App Crashing
|
||||
noteTitle.setText(note.getTitle());
|
||||
noteExcerpt.setText(note.getExcerpt());
|
||||
noteModified.setText(DateUtils.getRelativeDateTimeString(getContext(), note.getModified().getTimeInMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
|
||||
}
|
||||
((TextView) convertView.findViewById(R.id.noteTitle)).setText(note.getTitle());
|
||||
((TextView) convertView.findViewById(R.id.noteExcerpt)).setText(note.getExcerpt());
|
||||
((TextView) convertView.findViewById(R.id.noteModified)).setText(DateUtils.getRelativeDateTimeString(getContext(), note.getModified().getTimeInMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
// the view must be returned to our activity
|
||||
return v;
|
||||
/**
|
||||
* @return count_types
|
||||
*/
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return count_types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return getItem(position).isSection() ? section_type : note_type;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue