use of com.forcelain.android.awesomerecyclerview.model.Article in project AwesomeRecyclerView by forceLain.
the class ArticleAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
ArticleViewHolder articleViewHolder = (ArticleViewHolder) viewHolder;
Article article = articles.get(position);
articleViewHolder.textContent.setText(article.text);
articleViewHolder.textTitle.setText(article.title);
if (article.image.startsWith(SCHEME_ASSETS)) {
String fileName = article.image.replace(SCHEME_ASSETS, "");
AssetManager assetManager = viewHolder.itemView.getContext().getAssets();
InputStream is = null;
try {
is = assetManager.open(fileName);
Bitmap bitmap = BitmapFactory.decodeStream(is);
articleViewHolder.imageView.setImageBitmap(bitmap);
} catch (IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
} finally {
IOUtils.closeQuietly(is);
}
}
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (itemClickListener != null) {
itemClickListener.onItemClicked(position);
}
}
});
}
use of com.forcelain.android.awesomerecyclerview.model.Article in project AwesomeRecyclerView by forceLain.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
layoutManager = new AwesomeLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
ArticleAdapter adapter = new ArticleAdapter();
recyclerView.setAdapter(adapter);
dataProvider = new FakeDataProvider(this);
List<Article> articles = dataProvider.getArticles();
adapter.setArticles(articles);
recyclerView.setChildDrawingOrderCallback(new RecyclerView.ChildDrawingOrderCallback() {
@Override
public int onGetChildDrawingOrder(int childCount, int i) {
return childCount - i - 1;
}
});
adapter.setItemClickListener(new ArticleAdapter.OnItemClickListener() {
@Override
public void onItemClicked(int pos) {
layoutManager.openItem(pos);
}
});
findViewById(R.id.test_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recyclerView.smoothScrollToPosition(4);
}
});
}
use of com.forcelain.android.awesomerecyclerview.model.Article in project AwesomeRecyclerView by forceLain.
the class FakeDataProvider method getArticles.
@Override
public List<Article> getArticles() {
Gson gson = new Gson();
Article[] articles = gson.fromJson(new InputStreamReader(context.getResources().openRawResource(R.raw.data)), Article[].class);
return new ArrayList<>(Arrays.asList(articles));
}
Aggregations