Commit 68826399 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Optimization

Correct grid and list views
Fix list bug
Fix text bug
parent 5f2047e9
......@@ -55,7 +55,7 @@ public class ArticleKeyboardActivity extends ArticleGroupActivity {
}
}
if (!in)
if (!in && config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
else if (config.getInGrid())
......
......@@ -40,6 +40,8 @@ abstract class ArticlesAdapter extends BaseAdapter {
protected Bitmap[] imageList;
protected Integer[] nbrClicksList;
protected View[] viewList;
protected TextView[] clickViewList;
protected ArrayNode articleList;
......@@ -52,6 +54,8 @@ abstract class ArticlesAdapter extends BaseAdapter {
this.articleList = articleList;
this.imageList = new Bitmap[articleList.size()];
this.nbrClicksList = new Integer[articleList.size()];
this.viewList = new View[articleList.size()];
this.clickViewList = new TextView[articleList.size()];
for (int i = 0; i < this.nbrClicksList.length; i++)
......
......@@ -52,25 +52,24 @@ public class GridAdapter extends ArticlesAdapter {
public View getView(int position, View view, ViewGroup viewGroup) {
JsonNode article = this.articleList.get(position);
if (view == null) {
if (this.viewList[position] == null) {
LayoutInflater layoutInflater = LayoutInflater.from(this.activity);
view = layoutInflater.inflate(R.layout.fragment_article_grid, null);
this.viewList[position] = layoutInflater.inflate(R.layout.fragment_article_grid, null);
ImageView imageView = view.findViewById(R.id.image_article);
ImageView imageView = this.viewList[position].findViewById(R.id.image_article);
RelativeLayout.LayoutParams parms = new RelativeLayout.LayoutParams(this.size, this.size);
imageView.setLayoutParams(parms);
if (article == null || article.size() == 0)
view.setVisibility(View.INVISIBLE);
this.viewList[position].setVisibility(View.INVISIBLE);
else {
if (clickViewList[position] == null)
clickViewList[position] = view.findViewById(R.id.text_nbr_clicks);
this.clickViewList[position] = this.viewList[position].findViewById(R.id.text_nbr_clicks);
TextView textView = view.findViewById(R.id.text_article);
TextView textView = this.viewList[position].findViewById(R.id.text_article);
textView.setText(article.get("name").textValue());
ImageView imageCotisant = view.findViewById(R.id.image_cotisant);
ImageView image18 = view.findViewById(R.id.image_18);
ImageView imageCotisant = this.viewList[position].findViewById(R.id.image_cotisant);
ImageView image18 = this.viewList[position].findViewById(R.id.image_18);
LinearLayout.LayoutParams imageParms = new LinearLayout.LayoutParams(45, 45);
imageParms.setMargins(0, this.size - 45, 0, 0);
......@@ -83,6 +82,6 @@ public class GridAdapter extends ArticlesAdapter {
}
}
return view;
return this.viewList[position];
}
}
......@@ -61,7 +61,6 @@ public class GroupAdapter extends BaseAdapter {
((LinearLayout) view).addView(checkBox);
Log.d(LOG_TAG, Integer.toString(position));
if (this.checkBoxList[position] == null)
this.checkBoxList[position] = checkBox;
}
......
......@@ -34,33 +34,31 @@ public class ListAdapater extends ArticlesAdapter {
public ListAdapater(final Activity activity, final ArrayNode articleList, final Boolean printCotisant, final Boolean print18) throws Exception {
super(activity, articleList, printCotisant, print18);
Log.d(LOG_TAG, articleList.toString());
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
JsonNode article = this.articleList.get(position);
if (view == null) {
if (this.viewList[position] == null) {
LayoutInflater layoutInflater = LayoutInflater.from(this.activity);
view = layoutInflater.inflate(R.layout.fragment_article_list, null);
this.viewList[position] = layoutInflater.inflate(R.layout.fragment_article_list, null);
ImageView imageView = view.findViewById(R.id.image_article);
ImageView imageView = this.viewList[position].findViewById(R.id.image_article);
if (clickViewList[position] == null)
clickViewList[position] = view.findViewById(R.id.text_nbr_clicks);
clickViewList[position] = this.viewList[position].findViewById(R.id.text_nbr_clicks);
TextView nameText = view.findViewById(R.id.text_article);
TextView nameText = this.viewList[position].findViewById(R.id.text_article);
nameText.setText(article.get("name").textValue());
TextView priceText = view.findViewById(R.id.text_price);
TextView priceText = this.viewList[position].findViewById(R.id.text_price);
priceText.setText((article.has("quantity") ? Integer.toString(article.get("quantity").intValue()) + "x " : "") + String.format("%.2f", new Float(articleList.get(position).get("price").intValue()) / 100.00f) + "€");
ImageView imageCotisant = view.findViewById(R.id.image_cotisant);
ImageView image18 = view.findViewById(R.id.image_18);
ImageView imageCotisant = this.viewList[position].findViewById(R.id.image_cotisant);
ImageView image18 = this.viewList[position].findViewById(R.id.image_18);
if (article.has("info")) {
TextView infoText = view.findViewById(R.id.text_info);
TextView infoText = this.viewList[position].findViewById(R.id.text_info);
infoText.setText(article.get("info").textValue());
imageCotisant.setVisibility(View.GONE);
......@@ -78,7 +76,7 @@ public class ListAdapater extends ArticlesAdapter {
setClickView(position);
}
return view;
return this.viewList[position];
}
public void toast(final int position, int lengthLong) {
......
......@@ -7,7 +7,6 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/filters" />
......
......@@ -66,7 +66,7 @@
<TextView
android:id="@+id/text_article"
android:layout_height="35dp"
android:layout_height="36dp"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:text="@string/article" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment