From bee7485e39cd16a759084e55174b33ab7fedb07f Mon Sep 17 00:00:00 2001 From: kshitiz kumar <38812752+kshitiz-kumar@users.noreply.github.com> Date: Fri, 18 Oct 2019 21:59:44 +0530 Subject: [PATCH] Improved UI Of Config Activity (#1977) --- .../main/java/io/pslab/CheckBoxGetter.java | 30 ++++++ .../pslab/activity/CreateConfigActivity.java | 35 ++++--- .../io/pslab/adapters/CheckBoxAdapter.java | 75 ++++++++++++++ .../res/layout/activity_create_config.xml | 98 ++++++++++--------- app/src/main/res/layout/item_checkbox.xml | 29 ++++++ app/src/main/res/values/dimens.xml | 5 + 6 files changed, 208 insertions(+), 64 deletions(-) create mode 100644 app/src/main/java/io/pslab/CheckBoxGetter.java create mode 100644 app/src/main/java/io/pslab/adapters/CheckBoxAdapter.java create mode 100644 app/src/main/res/layout/item_checkbox.xml diff --git a/app/src/main/java/io/pslab/CheckBoxGetter.java b/app/src/main/java/io/pslab/CheckBoxGetter.java new file mode 100644 index 000000000..d79dec077 --- /dev/null +++ b/app/src/main/java/io/pslab/CheckBoxGetter.java @@ -0,0 +1,30 @@ +package io.pslab; + +import java.io.Serializable; + +public class CheckBoxGetter implements Serializable { + + private String name; + private boolean isSelected; + + public CheckBoxGetter(String name, boolean isSelected) { + this.name = name; + this.isSelected = isSelected; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isSelected() { + return isSelected; + } + + public void setSelected(boolean selected) { + isSelected = selected; + } +} diff --git a/app/src/main/java/io/pslab/activity/CreateConfigActivity.java b/app/src/main/java/io/pslab/activity/CreateConfigActivity.java index 5e2ec1d37..3d9a4501b 100644 --- a/app/src/main/java/io/pslab/activity/CreateConfigActivity.java +++ b/app/src/main/java/io/pslab/activity/CreateConfigActivity.java @@ -4,16 +4,15 @@ import android.os.Environment; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.view.Gravity; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; -import android.widget.CheckBox; import android.widget.EditText; -import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.Toast; @@ -21,8 +20,11 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.List; +import io.pslab.CheckBoxGetter; import io.pslab.R; +import io.pslab.adapters.CheckBoxAdapter; import io.pslab.others.CSVLogger; import io.pslab.others.CustomSnackBar; @@ -36,7 +38,8 @@ public class CreateConfigActivity extends AppCompatActivity { private EditText intervalEditText; private String interval; private View rootView; - private LinearLayout paramsListContainer; + private RecyclerView paramsListContainer; + private List list; @Override protected void onCreate(Bundle savedInstanceState) { @@ -58,6 +61,8 @@ protected void onCreate(Bundle savedInstanceState) { instrumentsList = new ArrayList<>(); instrumentParamsList = new ArrayList<>(); instrumentParamsListTitles = new ArrayList<>(); + paramsListContainer.setLayoutManager(new LinearLayoutManager(this)); + list = new ArrayList<>(); createArrayLists(); selectInstrumentSpinner.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, instrumentsList)); selectInstrumentSpinner.setSelection(0, true); @@ -97,9 +102,9 @@ public void onClick(View v) { Toast.makeText(CreateConfigActivity.this, getResources().getString(R.string.no_interval_message), Toast.LENGTH_SHORT).show(); } else { ArrayList selectedParamsList = new ArrayList<>(); - for (int i = 0; i < paramsListContainer.getChildCount(); i ++) { - CheckBox checkBox = (CheckBox) paramsListContainer.getChildAt(i); - if (checkBox.isChecked()) { + for (int i = 0; i < paramsListContainer.getChildCount(); i++) { + boolean checkBox = list.get(i).isSelected(); + if (checkBox) { selectedParamsList.add(instrumentParamsList.get(selectedItem)[i]); } } @@ -134,17 +139,15 @@ private void createArrayLists() { } private void createCheckboxList() { - paramsListContainer.removeAllViews(); + list.clear(); String[] params = instrumentParamsListTitles.get(selectedItem); - for (int i = 0; i < params.length; i++){ - CheckBox checkBox = new CheckBox(CreateConfigActivity.this); - checkBox.setText(params[i]); - LinearLayout.LayoutParams checkBoxParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT); - checkBoxParams.gravity = Gravity.CENTER_HORIZONTAL; - checkBoxParams.setMargins(0,(int)getResources().getDimension(R.dimen.create_config_margin1),0,0); - checkBox.setLayoutParams(checkBoxParams); - paramsListContainer.addView(checkBox, i); + for (int i = 0; i < params.length; i++) { + CheckBoxGetter check = new CheckBoxGetter(params[i], false); + list.add(check); } + CheckBoxAdapter box; + box = new CheckBoxAdapter(CreateConfigActivity.this, list); + paramsListContainer.setAdapter(box); } @Override diff --git a/app/src/main/java/io/pslab/adapters/CheckBoxAdapter.java b/app/src/main/java/io/pslab/adapters/CheckBoxAdapter.java new file mode 100644 index 000000000..ea0256bbd --- /dev/null +++ b/app/src/main/java/io/pslab/adapters/CheckBoxAdapter.java @@ -0,0 +1,75 @@ +package io.pslab.adapters; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +import io.pslab.CheckBoxGetter; +import io.pslab.R; + + +public class CheckBoxAdapter extends RecyclerView.Adapter { + + private Context boxcontext; + private List list = new ArrayList<>(); + + public CheckBoxAdapter(Context boxcontext, List list) { + this.boxcontext = boxcontext; + this.list = list; + } + + @Override + public CheckBoxHolder onCreateViewHolder(ViewGroup parent, int viewType) { + + View view = LayoutInflater.from(boxcontext).inflate(R.layout.item_checkbox, parent, false); + return new CheckBoxHolder(view); + } + + @Override + public void onBindViewHolder(final CheckBoxHolder holder, final int position) { + + final CheckBoxGetter check = list.get(position); + + holder.tv_name.setText(check.getName()); + + holder.checkBox.setChecked(check.isSelected()); + holder.checkBox.setTag(list.get(position)); + + holder.checkBox.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + CheckBoxGetter check1 = (CheckBoxGetter) holder.checkBox.getTag(); + check1.setSelected(holder.checkBox.isChecked()); + list.get(position).setSelected(holder.checkBox.isChecked()); + } + }); + } + + @Override + public int getItemCount() { + return list.size(); + } + + public List getCheckList() { + return list; + } + + public static class CheckBoxHolder extends RecyclerView.ViewHolder { + + private TextView tv_name; + private CheckBox checkBox; + + public CheckBoxHolder(View itemView) { + super(itemView); + tv_name = itemView.findViewById(R.id.tv_checkbox); + checkBox = itemView.findViewById(R.id.checkBox_select); + } + } +} diff --git a/app/src/main/res/layout/activity_create_config.xml b/app/src/main/res/layout/activity_create_config.xml index ea122dad8..a7ce15e1d 100644 --- a/app/src/main/res/layout/activity_create_config.xml +++ b/app/src/main/res/layout/activity_create_config.xml @@ -12,84 +12,86 @@ android:layout_height="wrap_content" android:layout_below="@+id/top_app_bar_layout"> - + android:orientation="vertical" + android:padding="@dimen/config_activity_padding"> - + android:orientation="horizontal"> - + - + - + - + android:orientation="horizontal"> + + + + + + + - - + android:layout_height="@dimen/create_config_recycler_view" + android:layout_marginTop="@dimen/create_config_margin1" />