You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
2.9 KiB
127 lines
2.9 KiB
package ru.defend.defdevteam.tstu;
|
|
|
|
import android.os.Build;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.ListIterator;
|
|
import java.util.NoSuchElementException;
|
|
|
|
/**
|
|
* Created by itsmy on 13.02.2017.
|
|
*/
|
|
|
|
public class NewsItemList {
|
|
|
|
private ArrayList<Group> list;
|
|
private HashMap<Integer, Integer> hashMap;
|
|
|
|
NewsItemList() {
|
|
list = new ArrayList<>();
|
|
hashMap = new HashMap<>();
|
|
}
|
|
|
|
public int size() {
|
|
return list.size();
|
|
}
|
|
|
|
public Group get(int index) {
|
|
return list.get(index);
|
|
}
|
|
|
|
public void add(Group group) {
|
|
this.list.add(group);
|
|
this.hashMap.put(group.getViewId(), this.list.size());
|
|
}
|
|
//
|
|
// public void set(int index, Group group) {
|
|
// this.list.set(index, group);
|
|
// this.hashMap.keySet(group.getViewId(), this.list.size());
|
|
// }
|
|
|
|
public void clear() {
|
|
this.list.clear();
|
|
this.hashMap.clear();
|
|
}
|
|
|
|
public Group getGroupByViewId(int viewId) {
|
|
return this.list.get(this.hashMap.get(viewId));
|
|
}
|
|
|
|
// @Override
|
|
// public Iterator<Group> iterator() {
|
|
// return new NewsIterator();
|
|
// }
|
|
|
|
// private class NewsIterator implements Iterator<Group> {
|
|
// private int cursor;
|
|
//
|
|
// public NewsIterator() {
|
|
// this.cursor = 0;
|
|
// }
|
|
//
|
|
// public boolean hasNext() {
|
|
// return this.cursor < size();
|
|
// }
|
|
//
|
|
// public Group next() {
|
|
// if(this.hasNext()) {
|
|
// Group current = get(cursor);
|
|
// cursor ++;
|
|
// return current;
|
|
// }
|
|
// throw new NoSuchElementException();
|
|
// }
|
|
//
|
|
// public void remove() {
|
|
// throw new UnsupportedOperationException();
|
|
// }
|
|
// }
|
|
|
|
public class Group {
|
|
private String title;
|
|
private String text;
|
|
private String link;
|
|
private Integer viewId;
|
|
private String fullText;
|
|
|
|
Group(String title, String text, String link) {
|
|
this.title = title;
|
|
this.text = text;
|
|
this.link = link;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
this.viewId = View.generateViewId();
|
|
Log.i("Generated view id", Integer.toString(viewId));
|
|
} else {
|
|
this.viewId = -1;
|
|
}
|
|
}
|
|
|
|
public String getTitle() {
|
|
return this.title;
|
|
}
|
|
|
|
public String getText() {
|
|
return this.text;
|
|
}
|
|
|
|
public String getLink() {
|
|
return this.link;
|
|
}
|
|
|
|
public int getViewId() {
|
|
return this.viewId;
|
|
}
|
|
|
|
public void setFullText(String fullText) {
|
|
this.fullText = fullText;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|