From 71d8e4e7a939d0aa05b709815944ac3006b00ce1 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 08:57:57 +0100 Subject: [PATCH 01/35] Removed id from ColumnHeader --- .../tableview/TableViewModel.java | 2 +- .../tableviewsample/tableview/model/Cell.java | 30 +-------- .../tableview/model/CellBase.java | 61 +++++++++++++++++++ .../tableview/model/ColumnHeader.java | 7 +-- 4 files changed, 67 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 27d3dd0b..5f1d890c 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -99,7 +99,7 @@ private List getRandomColumnHeaderList() { title = "large column " + i; } - ColumnHeader header = new ColumnHeader(String.valueOf(i), title); + ColumnHeader header = new ColumnHeader(title); list.add(header); } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java index 258c560a..fce90756 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java @@ -27,25 +27,19 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.filter.IFilterableModel; import com.evrencoskun.tableview.sort.ISortableModel; /** * Created by evrencoskun on 11/06/2017. */ -public class Cell implements ISortableModel, IFilterableModel { +public class Cell extends CellBase implements ISortableModel { @NonNull private final String mId; - @Nullable - private final Object mData; - @NonNull - private final String mFilterKeyword; public Cell(@NonNull String id, @Nullable Object data) { + super(data); this.mId = id; - this.mData = data; - this.mFilterKeyword = String.valueOf(data); } /** @@ -58,24 +52,4 @@ public String getId() { return mId; } - /** - * This is necessary for sorting process. - * See ISortableModel - */ - @Nullable - @Override - public Object getContent() { - return mData; - } - - @Nullable - public Object getData() { - return mData; - } - - @NonNull - @Override - public String getFilterableKeyword() { - return mFilterKeyword; - } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java new file mode 100644 index 00000000..ca9af282 --- /dev/null +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java @@ -0,0 +1,61 @@ +/* + * MIT License + * + * Copyright (c) 2021 Evren Coşkun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.evrencoskun.tableviewsample.tableview.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.evrencoskun.tableview.filter.IFilterableModel; + +public class CellBase implements IFilterableModel { + @Nullable + protected final Object mData; + @NonNull + protected final String mFilterKeyword; + + public CellBase(@Nullable Object data) { + this.mData = data; + this.mFilterKeyword = String.valueOf(data); + } + + /** + * This is necessary for sorting process. + * See ISortableModel + */ + @Nullable + public Object getContent() { + return mData; + } + + @Nullable + public Object getData() { + return mData; + } + + @NonNull + @Override + public String getFilterableKeyword() { + return mFilterKeyword; + } +} diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java index 5fa19923..367b07b6 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java @@ -24,15 +24,14 @@ package com.evrencoskun.tableviewsample.tableview.model; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** * Created by evrencoskun on 11/06/2017. */ -public class ColumnHeader extends Cell { - public ColumnHeader(@NonNull String id, @Nullable String data) { - super(id, data); +public class ColumnHeader extends CellBase { + public ColumnHeader(@Nullable String data) { + super(data); } } From 3342e9053731bfa880f259724f05cc3d34e3193f Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 09:47:27 +0100 Subject: [PATCH 02/35] Replaced ColumnHeader with String; Removed ColumnHeader --- .../tableviewsample/tableview/TableViewAdapter.java | 7 +++---- .../tableviewsample/tableview/TableViewModel.java | 10 ++++------ .../tableview/holder/ColumnHeaderViewHolder.java | 5 ++--- .../recyclerview/AbstractRecyclerViewAdapter.java | 4 +--- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index 3954929b..909e880f 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -42,7 +42,6 @@ import com.evrencoskun.tableviewsample.tableview.holder.MoodCellViewHolder; import com.evrencoskun.tableviewsample.tableview.holder.RowHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.model.Cell; -import com.evrencoskun.tableviewsample.tableview.model.ColumnHeader; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; /** @@ -51,7 +50,7 @@ * This is a sample of custom TableView Adapter. */ -public class TableViewAdapter extends AbstractTableAdapter { +public class TableViewAdapter extends AbstractTableAdapter { // Cell View Types by Column Position private static final int MOOD_CELL_TYPE = 1; @@ -176,12 +175,12 @@ public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup pare * on ```onCreateColumnHeaderViewHolder``` method. In this example * we have created "ColumnHeaderViewHolder" holder. * @param columnHeaderItemModel : This is the column header view model located on this X - * position. In this example, the model class is "ColumnHeader". + * position. In this example, the model class is "String". * @param columnPosition : This is the X (Column) position of the column header item. * @see #onCreateColumnHeaderViewHolder(ViewGroup, int) ; */ @Override - public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable ColumnHeader + public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String columnHeaderItemModel, int columnPosition) { // Get the holder to update cell item text diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 5f1d890c..6287ccde 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -29,7 +29,6 @@ import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewsample.tableview.model.Cell; -import com.evrencoskun.tableviewsample.tableview.model.ColumnHeader; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; import java.util.ArrayList; @@ -89,8 +88,8 @@ private List getSimpleRowHeaderList() { * This is a dummy model list test some cases. */ @NonNull - private List getRandomColumnHeaderList() { - List list = new ArrayList<>(); + private List getRandomColumnHeaderList() { + List list = new ArrayList<>(); for (int i = 0; i < COLUMN_SIZE; i++) { String title = "column " + i; @@ -99,8 +98,7 @@ private List getRandomColumnHeaderList() { title = "large column " + i; } - ColumnHeader header = new ColumnHeader(title); - list.add(header); + list.add(title); } return list; @@ -169,7 +167,7 @@ public List getRowHeaderList() { } @NonNull - public List getColumnHeaderList() { + public List getColumnHeaderList() { return getRandomColumnHeaderList(); } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/ColumnHeaderViewHolder.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/ColumnHeaderViewHolder.java index 40d4dd71..8383eccb 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/ColumnHeaderViewHolder.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/ColumnHeaderViewHolder.java @@ -37,7 +37,6 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder; import com.evrencoskun.tableview.sort.SortState; import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.model.ColumnHeader; /** * Created by evrencoskun on 23/10/2017. @@ -70,8 +69,8 @@ public ColumnHeaderViewHolder(@NonNull View itemView, @Nullable ITableView table /** * This method is calling from onBindColumnHeaderHolder on TableViewAdapter */ - public void setColumnHeader(@Nullable ColumnHeader columnHeader) { - column_header_textview.setText(String.valueOf(columnHeader.getData())); + public void setColumnHeader(@Nullable String columnHeader) { + column_header_textview.setText(columnHeader); // If your TableView should have auto resize for cells & columns. // Then you should consider the below lines. Otherwise, you can remove them. diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java index a3b38544..c7241632 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java @@ -73,9 +73,7 @@ public List getItems() { } public void setItems(@NonNull List itemList) { - mItemList = new ArrayList<>(itemList); - - this.notifyDataSetChanged(); + setItems(itemList, true); } public void setItems(@NonNull List itemList, boolean notifyDataSet) { From 622575c03d1280fde6d7472441929938aefca2e8 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 09:50:19 +0100 Subject: [PATCH 03/35] Replaced ColumnHeader with String; Removed ColumnHeader --- .../tableview/model/ColumnHeader.java | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java deleted file mode 100644 index 367b07b6..00000000 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/ColumnHeader.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2021 Evren Coşkun - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.evrencoskun.tableviewsample.tableview.model; - -import androidx.annotation.Nullable; - -/** - * Created by evrencoskun on 11/06/2017. - */ - -public class ColumnHeader extends CellBase { - public ColumnHeader(@Nullable String data) { - super(data); - } -} From a58ad24815fa3b73b1b18b70ca6654133e18a16f Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 09:52:44 +0100 Subject: [PATCH 04/35] Removed CellBase --- .../tableviewsample/tableview/model/Cell.java | 29 ++++++++- .../tableview/model/CellBase.java | 61 ------------------- 2 files changed, 27 insertions(+), 63 deletions(-) delete mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java index fce90756..9b767896 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java @@ -27,18 +27,24 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.evrencoskun.tableview.filter.IFilterableModel; import com.evrencoskun.tableview.sort.ISortableModel; /** * Created by evrencoskun on 11/06/2017. */ -public class Cell extends CellBase implements ISortableModel { +public class Cell implements ISortableModel, IFilterableModel { + @Nullable + protected final Object mData; + @NonNull + protected final String mFilterKeyword; @NonNull private final String mId; public Cell(@NonNull String id, @Nullable Object data) { - super(data); + this.mData = data; + this.mFilterKeyword = String.valueOf(data); this.mId = id; } @@ -52,4 +58,23 @@ public String getId() { return mId; } + /** + * This is necessary for sorting process. + * See ISortableModel + */ + @Nullable + public Object getContent() { + return mData; + } + + @Nullable + public Object getData() { + return mData; + } + + @NonNull + @Override + public String getFilterableKeyword() { + return mFilterKeyword; + } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java deleted file mode 100644 index ca9af282..00000000 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/CellBase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2021 Evren Coşkun - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.evrencoskun.tableviewsample.tableview.model; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.evrencoskun.tableview.filter.IFilterableModel; - -public class CellBase implements IFilterableModel { - @Nullable - protected final Object mData; - @NonNull - protected final String mFilterKeyword; - - public CellBase(@Nullable Object data) { - this.mData = data; - this.mFilterKeyword = String.valueOf(data); - } - - /** - * This is necessary for sorting process. - * See ISortableModel - */ - @Nullable - public Object getContent() { - return mData; - } - - @Nullable - public Object getData() { - return mData; - } - - @NonNull - @Override - public String getFilterableKeyword() { - return mFilterKeyword; - } -} From 1f223401e11abce9b89584a86dc0f8189f7c3c01 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:15:00 +0100 Subject: [PATCH 05/35] For Sorting to work id must be unique per row. Unique per cell is not neccessary --- .../tableviewsample/tableview/TableViewModel.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 6287ccde..68b1f884 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -24,6 +24,8 @@ package com.evrencoskun.tableviewsample.tableview; +import static java.lang.Math.abs; + import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; @@ -119,7 +121,11 @@ private List> getCellListForSortingTest() { if (j == 0) { text = i; } else if (j == 1) { + // to test Sorting text = random; + } else if (j == 2) { + // to test Sorting + text = abs(random) % 100; } else if (j == MOOD_COLUMN_INDEX) { text = random % 2 == 0 ? HAPPY : SAD; } else if (j == GENDER_COLUMN_INDEX) { @@ -127,7 +133,9 @@ private List> getCellListForSortingTest() { } // Create dummy id. - String id = j + "-" + i; + // String id = j + "-" + i; + // For Sorting to work id must be unique per row. Unique per cell is not neccessary + String id = "" + i; Cell cell; if (j == 3) { From fb773c98160d300da3b5068cd0b6aadf6f56806a Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:18:13 +0100 Subject: [PATCH 06/35] reverted changes in Cell --- .../tableviewsample/tableview/model/Cell.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java index 9b767896..258c560a 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java @@ -35,17 +35,17 @@ */ public class Cell implements ISortableModel, IFilterableModel { - @Nullable - protected final Object mData; - @NonNull - protected final String mFilterKeyword; @NonNull private final String mId; + @Nullable + private final Object mData; + @NonNull + private final String mFilterKeyword; public Cell(@NonNull String id, @Nullable Object data) { + this.mId = id; this.mData = data; this.mFilterKeyword = String.valueOf(data); - this.mId = id; } /** @@ -63,6 +63,7 @@ public String getId() { * See ISortableModel */ @Nullable + @Override public Object getContent() { return mData; } From f3d32a7ef28cb022ce252d848bb27d176eb3356a Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:23:45 +0100 Subject: [PATCH 07/35] Fixed inline docs --- .../tableviewsample/tableview/TableViewAdapter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index 909e880f..34eab1fa 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -166,7 +166,7 @@ public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup pare } /** - * That is where you set Column Header View Model data to your custom Column Header ViewHolder. + * That is where you set Column Header data to your custom Column Header ViewHolder. * This method is Called by ColumnHeader RecyclerView of the TableView to display the data at * the specified position. This method gives you everything you need about a column header * item. @@ -174,18 +174,18 @@ public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup pare * @param holder : This is one of your column header ViewHolders that was created * on ```onCreateColumnHeaderViewHolder``` method. In this example * we have created "ColumnHeaderViewHolder" holder. - * @param columnHeaderItemModel : This is the column header view model located on this X + * @param columnHeader : This is the column header located on this X * position. In this example, the model class is "String". * @param columnPosition : This is the X (Column) position of the column header item. * @see #onCreateColumnHeaderViewHolder(ViewGroup, int) ; */ @Override public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String - columnHeaderItemModel, int columnPosition) { + columnHeader, int columnPosition) { // Get the holder to update cell item text ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder; - columnHeaderViewHolder.setColumnHeader(columnHeaderItemModel); + columnHeaderViewHolder.setColumnHeader(columnHeader); } /** From 35360c2c9d1d0352b4814826ed561bf32a85e16e Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:32:15 +0100 Subject: [PATCH 08/35] Fixed inline docs --- .../tableviewsample/tableview/model/Cell.java | 9 ++++++--- .../com/evrencoskun/tableview/sort/ISortableModel.java | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java index 258c560a..5d7af9da 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java @@ -49,8 +49,8 @@ public Cell(@NonNull String id, @Nullable Object data) { } /** - * This is necessary for sorting process. - * See ISortableModel + * This is necessary for sorting process. Id must be unique per data row. + * See {@link ISortableModel}. */ @NonNull @Override @@ -60,7 +60,7 @@ public String getId() { /** * This is necessary for sorting process. - * See ISortableModel + * See {@link ISortableModel}. */ @Nullable @Override @@ -73,6 +73,9 @@ public Object getData() { return mData; } + /** + * See {@link IFilterableModel}. + */ @NonNull @Override public String getFilterableKeyword() { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java index 2b62ab07..0a8cf3a4 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java @@ -32,6 +32,9 @@ */ public interface ISortableModel { + /** + * to make sorting work, Id must be unique per data row. + */ @NonNull String getId(); From 3fd73ede29579bae1aac7e2fb6b43f7caf6842ac Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:50:09 +0100 Subject: [PATCH 09/35] Redesign: made Cell generic using new Itemtype MyItem --- .../tableviewsample/MainFragment.java | 5 +- .../tableview/TableViewAdapter.java | 44 +++++---- .../tableview/TableViewModel.java | 90 ++----------------- ...r.java => BoolDrawableCellViewHolder.java} | 15 ++-- .../holder/GenderCellViewHolder.java | 51 ----------- ...er.java => GenericTextCellViewHolder.java} | 12 ++- .../tableviewsample/tableview/model/Cell.java | 17 ++-- .../tableview/model/MyItem.java | 62 +++++++++++++ .../tableview/model/RowHeader.java | 8 +- .../tableview/test/models/Cell.java | 2 +- .../ColumnForRowHeaderSortComparator.java | 4 +- .../tableview/sort/ColumnSortCallback.java | 4 +- .../tableview/sort/ColumnSortComparator.java | 4 +- .../tableview/sort/ISortableModel.java | 2 +- .../sort/RowHeaderForCellSortComparator.java | 8 +- .../tableview/sort/RowHeaderSortCallback.java | 4 +- .../sort/RowHeaderSortComparator.java | 4 +- 17 files changed, 140 insertions(+), 196 deletions(-) rename app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/{MoodCellViewHolder.java => BoolDrawableCellViewHolder.java} (75%) delete mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenderCellViewHolder.java rename app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/{CellViewHolder.java => GenericTextCellViewHolder.java} (83%) create mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MyItem.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java index 68379ffb..0efcfa0a 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java @@ -45,6 +45,7 @@ import com.evrencoskun.tableviewsample.tableview.TableViewAdapter; import com.evrencoskun.tableviewsample.tableview.TableViewListener; import com.evrencoskun.tableviewsample.tableview.TableViewModel; +import com.evrencoskun.tableviewsample.tableview.model.MyItem; /** * A simple {@link Fragment} subclass. @@ -158,7 +159,7 @@ public void filterTableForMood(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the mood column. if (mTableFilter != null) { - mTableFilter.set(TableViewModel.MOOD_COLUMN_INDEX, filter); + mTableFilter.set(MyItem.COLUMN_INDEX_MOOD_HAPPY, filter); } } @@ -166,7 +167,7 @@ public void filterTableForGender(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the gender column. if (mTableFilter != null) { - mTableFilter.set(TableViewModel.GENDER_COLUMN_INDEX, filter); + mTableFilter.set(MyItem.COLUMN_INDEX_GENDER_MALE, filter); } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index 34eab1fa..a4d46fc5 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -36,12 +36,12 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.sort.SortState; import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.holder.CellViewHolder; +import com.evrencoskun.tableviewsample.tableview.holder.GenericTextCellViewHolder; import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; -import com.evrencoskun.tableviewsample.tableview.holder.GenderCellViewHolder; -import com.evrencoskun.tableviewsample.tableview.holder.MoodCellViewHolder; +import com.evrencoskun.tableviewsample.tableview.holder.BoolDrawableCellViewHolder; import com.evrencoskun.tableviewsample.tableview.holder.RowHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.model.Cell; +import com.evrencoskun.tableviewsample.tableview.model.MyItem; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; /** @@ -50,7 +50,7 @@ * This is a sample of custom TableView Adapter. */ -public class TableViewAdapter extends AbstractTableAdapter { +public class TableViewAdapter extends AbstractTableAdapter> { // Cell View Types by Column Position private static final int MOOD_CELL_TYPE = 1; @@ -89,18 +89,18 @@ public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int // Get image cell layout which has ImageView on the base instead of TextView. layout = inflater.inflate(R.layout.table_view_image_cell_layout, parent, false); - return new MoodCellViewHolder(layout); + return new BoolDrawableCellViewHolder(layout, R.drawable.ic_happy ,R.drawable.ic_sad); case GENDER_CELL_TYPE: // Get image cell layout which has ImageView instead of TextView. layout = inflater.inflate(R.layout.table_view_image_cell_layout, parent, false); - return new GenderCellViewHolder(layout); + return new BoolDrawableCellViewHolder(layout, R.drawable.ic_male, R.drawable.ic_female); default: // For cells that display a text layout = inflater.inflate(R.layout.table_view_cell_layout, parent, false); // Create a Cell ViewHolder - return new CellViewHolder(layout); + return new GenericTextCellViewHolder(layout); } } @@ -111,7 +111,7 @@ public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int * * @param holder : This is one of your cell ViewHolders that was created on * ```onCreateCellViewHolder``` method. In this example we have created - * "CellViewHolder" holder. + * "GenericTextCellViewHolder" holder. * @param cellItemModel : This is the cell view model located on this X and Y position. In this * example, the model class is "Cell". * @param columnPosition : This is the X (Column) position of the cell item. @@ -119,26 +119,22 @@ public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int * @see #onCreateCellViewHolder(ViewGroup, int) ; */ @Override - public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int + public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int columnPosition, int rowPosition) { switch (holder.getItemViewType()) { case MOOD_CELL_TYPE: - MoodCellViewHolder moodViewHolder = (MoodCellViewHolder) holder; - - moodViewHolder.cell_image.setImageResource(mTableViewModel.getDrawable((int) cellItemModel - .getData(), false)); + BoolDrawableCellViewHolder moodViewHolder = (BoolDrawableCellViewHolder) holder; + moodViewHolder.setData(cellItemModel.getData().mMoodHappy); break; case GENDER_CELL_TYPE: - GenderCellViewHolder genderViewHolder = (GenderCellViewHolder) holder; - - genderViewHolder.cell_image.setImageResource(mTableViewModel.getDrawable((int) - cellItemModel.getData(), true)); + BoolDrawableCellViewHolder genderViewHolder = (BoolDrawableCellViewHolder) holder; + genderViewHolder.setData(cellItemModel.getData().mGenderMale); break; default: // Get the holder to update cell item text - CellViewHolder viewHolder = (CellViewHolder) holder; - viewHolder.setCell(cellItemModel); + GenericTextCellViewHolder viewHolder = (GenericTextCellViewHolder) holder; + viewHolder.setCell(cellItemModel, columnPosition, rowPosition); break; } } @@ -228,7 +224,7 @@ public void onBindRowHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nulla // Get the holder to update row header item text RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder; - rowHeaderViewHolder.row_header_textview.setText(String.valueOf(rowHeaderItemModel.getData())); + rowHeaderViewHolder.row_header_textview.setText(String.valueOf(rowHeaderItemModel.getId())); } @NonNull @@ -256,7 +252,7 @@ public int getColumnHeaderItemViewType(int position) { // The unique ID for this type of column header item // If you have different items for Cell View by X (Column) position, // then you should fill this method to be able create different - // type of CellViewHolder on "onCreateCellViewHolder" + // type of GenericTextCellViewHolder on "onCreateCellViewHolder" return 0; } @@ -275,11 +271,11 @@ public int getCellItemViewType(int column) { // The unique ID for this type of cell item // If you have different items for Cell View by X (Column) position, // then you should fill this method to be able create different - // type of CellViewHolder on "onCreateCellViewHolder" + // type of GenericTextCellViewHolder on "onCreateCellViewHolder" switch (column) { - case TableViewModel.MOOD_COLUMN_INDEX: + case MyItem.COLUMN_INDEX_MOOD_HAPPY: return MOOD_CELL_TYPE; - case TableViewModel.GENDER_COLUMN_INDEX: + case MyItem.COLUMN_INDEX_GENDER_MALE: return GENDER_CELL_TYPE; default: // Default view type diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 68b1f884..2e6deb39 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -24,13 +24,10 @@ package com.evrencoskun.tableviewsample.tableview; -import static java.lang.Math.abs; - -import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; -import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewsample.tableview.model.Cell; +import com.evrencoskun.tableviewsample.tableview.model.MyItem; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; import java.util.ArrayList; @@ -42,44 +39,15 @@ */ public class TableViewModel { - - // Columns indexes - public static final int MOOD_COLUMN_INDEX = 3; - public static final int GENDER_COLUMN_INDEX = 4; - - // Constant values for icons - public static final int SAD = 1; - public static final int HAPPY = 2; - public static final int BOY = 1; - public static final int GIRL = 2; - // Constant size for dummy data sets private static final int COLUMN_SIZE = 500; private static final int ROW_SIZE = 500; - // Drawables - @DrawableRes - private final int mBoyDrawable; - @DrawableRes - private final int mGirlDrawable; - @DrawableRes - private final int mHappyDrawable; - @DrawableRes - private final int mSadDrawable; - - public TableViewModel() { - // initialize drawables - mBoyDrawable = R.drawable.ic_male; - mGirlDrawable = R.drawable.ic_female; - mHappyDrawable = R.drawable.ic_happy; - mSadDrawable = R.drawable.ic_sad; - } - @NonNull private List getSimpleRowHeaderList() { List list = new ArrayList<>(); for (int i = 0; i < ROW_SIZE; i++) { - RowHeader header = new RowHeader(String.valueOf(i), "row " + i); + RowHeader header = new RowHeader(new MyItem(String.valueOf(i))); list.add(header); } @@ -110,43 +78,12 @@ private List getRandomColumnHeaderList() { * This is a dummy model list test some cases. */ @NonNull - private List> getCellListForSortingTest() { - List> list = new ArrayList<>(); - for (int i = 0; i < ROW_SIZE; i++) { - List cellList = new ArrayList<>(); - for (int j = 0; j < COLUMN_SIZE; j++) { - Object text = "cell " + j + " " + i; - - final int random = new Random().nextInt(); - if (j == 0) { - text = i; - } else if (j == 1) { - // to test Sorting - text = random; - } else if (j == 2) { - // to test Sorting - text = abs(random) % 100; - } else if (j == MOOD_COLUMN_INDEX) { - text = random % 2 == 0 ? HAPPY : SAD; - } else if (j == GENDER_COLUMN_INDEX) { - text = random % 2 == 0 ? BOY : GIRL; - } - - // Create dummy id. - // String id = j + "-" + i; - // For Sorting to work id must be unique per row. Unique per cell is not neccessary - String id = "" + i; - - Cell cell; - if (j == 3) { - cell = new Cell(id, text); - } else if (j == 4) { - // NOTE female and male keywords for filter will have conflict since "female" - // contains "male" - cell = new Cell(id, text); - } else { - cell = new Cell(id, text); - } + private List>> getCellListForSortingTest() { + List>> list = new ArrayList<>(); + for (int rowId = 0; rowId < ROW_SIZE; rowId++) { + List> cellList = new ArrayList<>(); + Cell cell = new Cell(new MyItem("" + rowId)); + for (int colId = 0; colId < COLUMN_SIZE; colId++) { cellList.add(cell); } list.add(cellList); @@ -155,17 +92,8 @@ private List> getCellListForSortingTest() { return list; } - @DrawableRes - public int getDrawable(int value, boolean isGender) { - if (isGender) { - return value == BOY ? mBoyDrawable : mGirlDrawable; - } else { - return value == SAD ? mSadDrawable : mHappyDrawable; - } - } - @NonNull - public List> getCellList() { + public List>> getCellList() { return getCellListForSortingTest(); } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/MoodCellViewHolder.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/BoolDrawableCellViewHolder.java similarity index 75% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/MoodCellViewHolder.java rename to app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/BoolDrawableCellViewHolder.java index f48197da..f8db3363 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/MoodCellViewHolder.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/BoolDrawableCellViewHolder.java @@ -27,28 +27,31 @@ import android.view.View; import android.widget.ImageView; +import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.TableViewModel; /** * Created by evrencoskun on 4.02.2018. */ -public class MoodCellViewHolder extends AbstractViewHolder { +public class BoolDrawableCellViewHolder extends AbstractViewHolder { @NonNull public final ImageView cell_image; + @DrawableRes private final int mIdDrawableTrue; + @DrawableRes private final int mIdDrawableFalse; - public MoodCellViewHolder(@NonNull View itemView) { + public BoolDrawableCellViewHolder(@NonNull View itemView, @DrawableRes int idDrawableTrue, @DrawableRes int idDrawableFalse) { super(itemView); cell_image = itemView.findViewById(R.id.cell_image); + mIdDrawableTrue = idDrawableTrue; + mIdDrawableFalse = idDrawableFalse; } - public void setData(Object data) { - int mood = (int) data; - int moodDrawable = mood == TableViewModel.HAPPY ? R.drawable.ic_happy : R.drawable.ic_sad; + public void setData(boolean data) { + int moodDrawable = data ? mIdDrawableTrue : mIdDrawableFalse; cell_image.setImageResource(moodDrawable); } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenderCellViewHolder.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenderCellViewHolder.java deleted file mode 100644 index d56d4246..00000000 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenderCellViewHolder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2021 Evren Coşkun - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.evrencoskun.tableviewsample.tableview.holder; - -import android.view.View; - -import androidx.annotation.NonNull; - -import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.TableViewModel; - -/** - * Created by evrencoskun on 4.02.2018. - */ - -public class GenderCellViewHolder extends MoodCellViewHolder { - - public GenderCellViewHolder(@NonNull View itemView) { - super(itemView); - } - - @Override - public void setData(Object data) { - int gender = (int) data; - int genderDrawable = gender == TableViewModel.BOY ? R.drawable.ic_male : R.drawable.ic_female; - - cell_image.setImageResource(genderDrawable); - } -} diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/CellViewHolder.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java similarity index 83% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/CellViewHolder.java rename to app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java index e13ee332..6c145379 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/CellViewHolder.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java @@ -39,20 +39,24 @@ * Created by evrencoskun on 23/10/2017. */ -public class CellViewHolder extends AbstractViewHolder { +public class GenericTextCellViewHolder extends AbstractViewHolder { @NonNull private final TextView cell_textview; @NonNull private final LinearLayout cell_container; + private int mColumnPosition; + private int mRowPosition; - public CellViewHolder(@NonNull View itemView) { + public GenericTextCellViewHolder(@NonNull View itemView) { super(itemView); cell_textview = itemView.findViewById(R.id.cell_data); cell_container = itemView.findViewById(R.id.cell_container); } - public void setCell(@Nullable Cell cell) { - cell_textview.setText(String.valueOf(cell.getData())); + public void setCell(@Nullable Cell cell, int columnPosition, int rowPosition) { + mColumnPosition = columnPosition; + mRowPosition = rowPosition; + cell_textview.setText(String.valueOf(cell.getContent(columnPosition))); // If your TableView should have auto resize for cells & columns. // Then you should consider the below lines. Otherwise, you can ignore them. diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java index 5d7af9da..2f729b70 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java @@ -34,16 +34,13 @@ * Created by evrencoskun on 11/06/2017. */ -public class Cell implements ISortableModel, IFilterableModel { - @NonNull - private final String mId; +public class Cell implements ISortableModel, IFilterableModel { @Nullable - private final Object mData; + private final C mData; @NonNull private final String mFilterKeyword; - public Cell(@NonNull String id, @Nullable Object data) { - this.mId = id; + public Cell(@NonNull C data) { this.mData = data; this.mFilterKeyword = String.valueOf(data); } @@ -55,7 +52,7 @@ public Cell(@NonNull String id, @Nullable Object data) { @NonNull @Override public String getId() { - return mId; + return mData.getId(); } /** @@ -64,12 +61,12 @@ public String getId() { */ @Nullable @Override - public Object getContent() { - return mData; + public Object getContent(int column) { + return mData.getContent(column); } @Nullable - public Object getData() { + public C getData() { return mData; } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MyItem.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MyItem.java new file mode 100644 index 00000000..6122e3d4 --- /dev/null +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MyItem.java @@ -0,0 +1,62 @@ +package com.evrencoskun.tableviewsample.tableview.model; + +import static java.lang.Math.abs; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.evrencoskun.tableview.sort.ISortableModel; + +import java.util.Random; + +public class MyItem implements ISortableModel { + // Columns indexes + public static final int COLUMN_INDEX_ID = 0; + public static final int COLUMN_INDEX_RANDOM_LONG = 1; + public static final int COLUMN_INDEX_RAMDOM_SHORT = 2; + public static final int COLUMN_INDEX_MOOD_HAPPY = 3; + public static final int COLUMN_INDEX_GENDER_MALE = 4; + + private final Integer mRandom; + private final Integer mRandomShort; + private final Object[] columns; + @NonNull + private final String mId; + @Nullable + private final String mText; + public final boolean mGenderMale; + public final boolean mMoodHappy; + + public MyItem(@NonNull String id) { + this.mId = id; + this.mText = "cell " + mId + " 1"; + mGenderMale = new Random().nextBoolean(); + mMoodHappy = new Random().nextBoolean(); + mRandom = abs(new Random().nextInt()); + mRandomShort = mRandom % 100; + columns = new Object[]{mRandom, mRandomShort, mText, mGenderMale, mMoodHappy}; + } + + /** + * This is necessary for sorting process. Id must be unique per data row. + * See {@link ISortableModel}. + */ + @NonNull + @Override + public String getId() { + return mId; + } + + /** + * This is necessary for sorting process. + * See {@link ISortableModel}. + */ + @Nullable + @Override + public Object getContent(int column) { + if (column >= 0 && column < columns.length) { + return columns[column]; + } + return "cell " + mId + " " + column; + } +} diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java index 1180fdb4..3319b94f 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java @@ -27,12 +27,14 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.evrencoskun.tableview.sort.ISortableModel; + /** * Created by evrencoskun on 11/06/2017. */ -public class RowHeader extends Cell { - public RowHeader(@NonNull String id, @Nullable String data) { - super(id, data); +public class RowHeader extends Cell { + public RowHeader(@NonNull C data) { + super(data); } } diff --git a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java index 6b41602f..12d55988 100644 --- a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java +++ b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java @@ -60,7 +60,7 @@ public String getId() { */ @Nullable @Override - public Object getContent() { + public Object getContent(int column) { return mData; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java index 62443f13..d99f2f14 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java @@ -61,8 +61,8 @@ public ColumnForRowHeaderSortComparator(@NonNull List rowHeader, @Override public int compare(ISortableModel o, ISortableModel t1) { - Object o1 = mReferenceList.get(this.mRowHeaderList.indexOf(o)).get(column).getContent(); - Object o2 = mReferenceList.get(this.mRowHeaderList.indexOf(t1)).get(column).getContent(); + Object o1 = mReferenceList.get(this.mRowHeaderList.indexOf(o)).get(column).getContent(column); + Object o2 = mReferenceList.get(this.mRowHeaderList.indexOf(t1)).get(column).getContent(column); if (mSortState == SortState.DESCENDING) { return mColumnSortComparator.compareContent(o2, o1); } else { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java index a2bbee5d..85fd9f9f 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java @@ -81,9 +81,9 @@ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { (newItemPosition).size() > mColumnPosition) { // Compare contents Object oldContent = mOldCellItems.get(oldItemPosition).get(mColumnPosition) - .getContent(); + .getContent(mColumnPosition); Object newContent = mNewCellItems.get(newItemPosition).get(mColumnPosition) - .getContent(); + .getContent(mColumnPosition); return ObjectsCompat.equals(oldContent, newContent); } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java index 8fa7add8..323db564 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java @@ -44,8 +44,8 @@ public ColumnSortComparator(int xPosition, @NonNull SortState sortState) { @Override public int compare(List t1, List t2) { - Object o1 = t1.get(mXPosition).getContent(); - Object o2 = t2.get(mXPosition).getContent(); + Object o1 = t1.get(mXPosition).getContent(mXPosition); + Object o2 = t2.get(mXPosition).getContent(mXPosition); if (mSortState == SortState.DESCENDING) { return compareContent(o2, o1); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java index 0a8cf3a4..15bf185a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java @@ -39,5 +39,5 @@ public interface ISortableModel { String getId(); @Nullable - Object getContent(); + Object getContent(int column); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java index aa8495fa..f42b1bcc 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java @@ -53,9 +53,11 @@ public RowHeaderForCellSortComparator(@NonNull List referenceLis } @Override - public int compare(List o, List t1) { - Object o1 = mReferenceList.get(this.mColumnList.indexOf(o)).getContent(); - Object o2 = mReferenceList.get(this.mColumnList.indexOf(t1)).getContent(); + public int compare(List l1, List l2) { + int colL1 = this.mColumnList.indexOf(l1); + int colL2 = this.mColumnList.indexOf(l2); + Object o1 = mReferenceList.get(colL1).getContent(colL1); + Object o2 = mReferenceList.get(colL2).getContent(colL2); if (mSortState == SortState.DESCENDING) { return mRowHeaderSortComparator.compareContent(o2, o1); } else { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java index b3188ac6..58caca47 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java @@ -73,9 +73,9 @@ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { if (mOldCellItems.size() > oldItemPosition && mNewCellItems.size() > newItemPosition) { // Compare contents Object oldContent = mOldCellItems.get(oldItemPosition) - .getContent(); + .getContent(0); Object newContent = mNewCellItems.get(newItemPosition) - .getContent(); + .getContent(0); return oldContent.equals(newContent); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java index 8dc6c7a3..c80563ae 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java @@ -41,9 +41,9 @@ public RowHeaderSortComparator(@NonNull SortState sortState) { @Override public int compare(ISortableModel o1, ISortableModel o2) { if (mSortState == SortState.DESCENDING) { - return compareContent(o2.getContent(), o1.getContent()); + return compareContent(o2.getContent(0), o1.getContent(0)); } else { - return compareContent(o1.getContent(), o2.getContent()); + return compareContent(o1.getContent(0), o2.getContent(0)); } } } From ca97deaf72009fbfe34ccc9407551b1cd4096daf Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 15:25:35 +0100 Subject: [PATCH 10/35] refactored colors: renamed to default_table_xxx and moved to lib --- app/src/main/res/layout/table_view_cell_layout.xml | 4 ++-- .../res/layout/table_view_column_header_layout.xml | 6 +++--- .../main/res/layout/table_view_corner_layout.xml | 8 ++++---- .../res/layout/table_view_image_cell_layout.xml | 2 +- .../res/layout/table_view_row_header_layout.xml | 6 +++--- app/src/main/res/values/colors.xml | 4 ---- tableview/src/androidTest/res/values/colors.xml | 6 +++--- .../java/com/evrencoskun/tableview/TableView.java | 8 ++++---- .../src/main/res/drawable/cell_line_divider.xml | 2 +- tableview/src/main/res/values/colors.xml | 14 ++++++++++---- 10 files changed, 31 insertions(+), 29 deletions(-) diff --git a/app/src/main/res/layout/table_view_cell_layout.xml b/app/src/main/res/layout/table_view_cell_layout.xml index 42b78655..2e7e0093 100644 --- a/app/src/main/res/layout/table_view_cell_layout.xml +++ b/app/src/main/res/layout/table_view_cell_layout.xml @@ -27,7 +27,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="@dimen/cell_height" - android:background="@color/cell_background_color" + android:background="@color/default_table_cell_background_color" android:gravity="center" android:orientation="vertical"> @@ -41,7 +41,7 @@ android:layout_marginStart="10dp" android:gravity="center" android:maxLines="1" - android:textColor="@color/table_view_default_text_color" + android:textColor="@color/default_table_view_text_color" android:textSize="@dimen/text_size" android:visibility="visible" tools:text="Cell Data"/> diff --git a/app/src/main/res/layout/table_view_column_header_layout.xml b/app/src/main/res/layout/table_view_column_header_layout.xml index 33beff0f..9449f03f 100644 --- a/app/src/main/res/layout/table_view_column_header_layout.xml +++ b/app/src/main/res/layout/table_view_column_header_layout.xml @@ -29,7 +29,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="@dimen/cell_height" - android:background="@color/cell_background_color" + android:background="@color/default_table_cell_background_color" android:orientation="vertical"> @@ -73,7 +73,7 @@ android:layout_width="match_parent" android:layout_height="1dp" android:layout_gravity="bottom" - android:background="@color/header_line_color"/> + android:background="@color/default_table_header_line_color"/> diff --git a/app/src/main/res/layout/table_view_corner_layout.xml b/app/src/main/res/layout/table_view_corner_layout.xml index 5c31f46e..5a685fa7 100644 --- a/app/src/main/res/layout/table_view_corner_layout.xml +++ b/app/src/main/res/layout/table_view_corner_layout.xml @@ -25,7 +25,7 @@ + android:background="@color/default_table_cell_background_color"> + android:background="@color/default_table_header_line_color"/> + android:background="@color/default_table_header_line_color"/> diff --git a/app/src/main/res/layout/table_view_image_cell_layout.xml b/app/src/main/res/layout/table_view_image_cell_layout.xml index 84ec3644..667891e6 100644 --- a/app/src/main/res/layout/table_view_image_cell_layout.xml +++ b/app/src/main/res/layout/table_view_image_cell_layout.xml @@ -27,7 +27,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="@dimen/cell_height" - android:background="@color/cell_background_color" + android:background="@color/default_table_cell_background_color" android:gravity="center" android:orientation="vertical"> diff --git a/app/src/main/res/layout/table_view_row_header_layout.xml b/app/src/main/res/layout/table_view_row_header_layout.xml index a81e6d9c..f01750ad 100644 --- a/app/src/main/res/layout/table_view_row_header_layout.xml +++ b/app/src/main/res/layout/table_view_row_header_layout.xml @@ -25,7 +25,7 @@ @@ -43,7 +43,7 @@ android:ellipsize="end" android:gravity="center" android:maxLines="1" - android:textColor="@color/table_view_default_text_color" + android:textColor="@color/default_table_view_text_color" android:textSize="@dimen/text_size" tools:text="Row Data"/> @@ -53,5 +53,5 @@ android:layout_width="1dp" android:layout_height="match_parent" android:layout_alignParentRight="true" - android:background="@color/header_line_color"/> + android:background="@color/default_table_header_line_color"/> \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ef923f18..7772cc82 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -28,8 +28,4 @@ #FF4081 #E7E7E7 - #ffffff - @android:color/holo_red_light - - #0a0a0a diff --git a/tableview/src/androidTest/res/values/colors.xml b/tableview/src/androidTest/res/values/colors.xml index a17bcd3d..a48ca29e 100644 --- a/tableview/src/androidTest/res/values/colors.xml +++ b/tableview/src/androidTest/res/values/colors.xml @@ -23,7 +23,7 @@ ~ SOFTWARE. --> - #ffffff - #0a0a0a - #0a0a0a + #ffffff + #0a0a0a + #0a0a0a diff --git a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java index 9cdfd9fa..fed36b4a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java @@ -180,11 +180,11 @@ private void initialDefaultValues(@Nullable AttributeSet attrs) { // Colors mSelectedColor = ContextCompat.getColor(getContext(), R.color - .table_view_default_selected_background_color); + .default_table_view_selected_background_color); mUnSelectedColor = ContextCompat.getColor(getContext(), R.color - .table_view_default_unselected_background_color); + .default_table_view_unselected_background_color); mShadowColor = ContextCompat.getColor(getContext(), R.color - .table_view_default_shadow_background_color); + .default_table_view_shadow_background_color); if (attrs == null) { // That means TableView is created programmatically. @@ -212,7 +212,7 @@ private void initialDefaultValues(@Nullable AttributeSet attrs) { mUnSelectedColor = a.getColor(R.styleable.TableView_unselected_color, mUnSelectedColor); mShadowColor = a.getColor(R.styleable.TableView_shadow_color, mShadowColor); mSeparatorColor = a.getColor(R.styleable.TableView_separator_color, ContextCompat - .getColor(getContext(), R.color.table_view_default_separator_color)); + .getColor(getContext(), R.color.default_table_view_separator_color)); // Booleans mShowVerticalSeparators = a.getBoolean(R.styleable.TableView_show_vertical_separator, diff --git a/tableview/src/main/res/drawable/cell_line_divider.xml b/tableview/src/main/res/drawable/cell_line_divider.xml index b1993ade..f4bbdd02 100644 --- a/tableview/src/main/res/drawable/cell_line_divider.xml +++ b/tableview/src/main/res/drawable/cell_line_divider.xml @@ -28,5 +28,5 @@ - + diff --git a/tableview/src/main/res/values/colors.xml b/tableview/src/main/res/values/colors.xml index 3852e35a..30d649cf 100644 --- a/tableview/src/main/res/values/colors.xml +++ b/tableview/src/main/res/values/colors.xml @@ -24,8 +24,14 @@ --> - #E7E7E7 - #ffffff - #fada65 - #f2f2f2 + #E7E7E7 + #ffffff + #fada65 + #f2f2f2 + + #ffffff + @android:color/holo_red_light + + #0a0a0a + From ae0cdb1485e2f278ec6e3a9e25b356693d27db43 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 1 Mar 2023 15:36:54 +0100 Subject: [PATCH 11/35] Revert "refactored colors: renamed to default_table_xxx and moved to lib" This reverts commit ca97deaf72009fbfe34ccc9407551b1cd4096daf. --- app/src/main/res/layout/table_view_cell_layout.xml | 4 ++-- .../res/layout/table_view_column_header_layout.xml | 6 +++--- .../main/res/layout/table_view_corner_layout.xml | 8 ++++---- .../res/layout/table_view_image_cell_layout.xml | 2 +- .../res/layout/table_view_row_header_layout.xml | 6 +++--- app/src/main/res/values/colors.xml | 4 ++++ tableview/src/androidTest/res/values/colors.xml | 6 +++--- .../java/com/evrencoskun/tableview/TableView.java | 8 ++++---- .../src/main/res/drawable/cell_line_divider.xml | 2 +- tableview/src/main/res/values/colors.xml | 14 ++++---------- 10 files changed, 29 insertions(+), 31 deletions(-) diff --git a/app/src/main/res/layout/table_view_cell_layout.xml b/app/src/main/res/layout/table_view_cell_layout.xml index 2e7e0093..42b78655 100644 --- a/app/src/main/res/layout/table_view_cell_layout.xml +++ b/app/src/main/res/layout/table_view_cell_layout.xml @@ -27,7 +27,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="@dimen/cell_height" - android:background="@color/default_table_cell_background_color" + android:background="@color/cell_background_color" android:gravity="center" android:orientation="vertical"> @@ -41,7 +41,7 @@ android:layout_marginStart="10dp" android:gravity="center" android:maxLines="1" - android:textColor="@color/default_table_view_text_color" + android:textColor="@color/table_view_default_text_color" android:textSize="@dimen/text_size" android:visibility="visible" tools:text="Cell Data"/> diff --git a/app/src/main/res/layout/table_view_column_header_layout.xml b/app/src/main/res/layout/table_view_column_header_layout.xml index 9449f03f..33beff0f 100644 --- a/app/src/main/res/layout/table_view_column_header_layout.xml +++ b/app/src/main/res/layout/table_view_column_header_layout.xml @@ -29,7 +29,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="@dimen/cell_height" - android:background="@color/default_table_cell_background_color" + android:background="@color/cell_background_color" android:orientation="vertical"> @@ -73,7 +73,7 @@ android:layout_width="match_parent" android:layout_height="1dp" android:layout_gravity="bottom" - android:background="@color/default_table_header_line_color"/> + android:background="@color/header_line_color"/> diff --git a/app/src/main/res/layout/table_view_corner_layout.xml b/app/src/main/res/layout/table_view_corner_layout.xml index 5a685fa7..5c31f46e 100644 --- a/app/src/main/res/layout/table_view_corner_layout.xml +++ b/app/src/main/res/layout/table_view_corner_layout.xml @@ -25,7 +25,7 @@ + android:background="@color/cell_background_color"> + android:background="@color/header_line_color"/> + android:background="@color/header_line_color"/> diff --git a/app/src/main/res/layout/table_view_image_cell_layout.xml b/app/src/main/res/layout/table_view_image_cell_layout.xml index 667891e6..84ec3644 100644 --- a/app/src/main/res/layout/table_view_image_cell_layout.xml +++ b/app/src/main/res/layout/table_view_image_cell_layout.xml @@ -27,7 +27,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="@dimen/cell_height" - android:background="@color/default_table_cell_background_color" + android:background="@color/cell_background_color" android:gravity="center" android:orientation="vertical"> diff --git a/app/src/main/res/layout/table_view_row_header_layout.xml b/app/src/main/res/layout/table_view_row_header_layout.xml index f01750ad..a81e6d9c 100644 --- a/app/src/main/res/layout/table_view_row_header_layout.xml +++ b/app/src/main/res/layout/table_view_row_header_layout.xml @@ -25,7 +25,7 @@ @@ -43,7 +43,7 @@ android:ellipsize="end" android:gravity="center" android:maxLines="1" - android:textColor="@color/default_table_view_text_color" + android:textColor="@color/table_view_default_text_color" android:textSize="@dimen/text_size" tools:text="Row Data"/> @@ -53,5 +53,5 @@ android:layout_width="1dp" android:layout_height="match_parent" android:layout_alignParentRight="true" - android:background="@color/default_table_header_line_color"/> + android:background="@color/header_line_color"/> \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 7772cc82..ef923f18 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -28,4 +28,8 @@ #FF4081 #E7E7E7 + #ffffff + @android:color/holo_red_light + + #0a0a0a diff --git a/tableview/src/androidTest/res/values/colors.xml b/tableview/src/androidTest/res/values/colors.xml index a48ca29e..a17bcd3d 100644 --- a/tableview/src/androidTest/res/values/colors.xml +++ b/tableview/src/androidTest/res/values/colors.xml @@ -23,7 +23,7 @@ ~ SOFTWARE. --> - #ffffff - #0a0a0a - #0a0a0a + #ffffff + #0a0a0a + #0a0a0a diff --git a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java index fed36b4a..9cdfd9fa 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java @@ -180,11 +180,11 @@ private void initialDefaultValues(@Nullable AttributeSet attrs) { // Colors mSelectedColor = ContextCompat.getColor(getContext(), R.color - .default_table_view_selected_background_color); + .table_view_default_selected_background_color); mUnSelectedColor = ContextCompat.getColor(getContext(), R.color - .default_table_view_unselected_background_color); + .table_view_default_unselected_background_color); mShadowColor = ContextCompat.getColor(getContext(), R.color - .default_table_view_shadow_background_color); + .table_view_default_shadow_background_color); if (attrs == null) { // That means TableView is created programmatically. @@ -212,7 +212,7 @@ private void initialDefaultValues(@Nullable AttributeSet attrs) { mUnSelectedColor = a.getColor(R.styleable.TableView_unselected_color, mUnSelectedColor); mShadowColor = a.getColor(R.styleable.TableView_shadow_color, mShadowColor); mSeparatorColor = a.getColor(R.styleable.TableView_separator_color, ContextCompat - .getColor(getContext(), R.color.default_table_view_separator_color)); + .getColor(getContext(), R.color.table_view_default_separator_color)); // Booleans mShowVerticalSeparators = a.getBoolean(R.styleable.TableView_show_vertical_separator, diff --git a/tableview/src/main/res/drawable/cell_line_divider.xml b/tableview/src/main/res/drawable/cell_line_divider.xml index f4bbdd02..b1993ade 100644 --- a/tableview/src/main/res/drawable/cell_line_divider.xml +++ b/tableview/src/main/res/drawable/cell_line_divider.xml @@ -28,5 +28,5 @@ - + diff --git a/tableview/src/main/res/values/colors.xml b/tableview/src/main/res/values/colors.xml index 30d649cf..3852e35a 100644 --- a/tableview/src/main/res/values/colors.xml +++ b/tableview/src/main/res/values/colors.xml @@ -24,14 +24,8 @@ --> - #E7E7E7 - #ffffff - #fada65 - #f2f2f2 - - #ffffff - @android:color/holo_red_light - - #0a0a0a - + #E7E7E7 + #ffffff + #fada65 + #f2f2f2 From 2028ad278a6f2732a2c837d1d07b60c21d074d74 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Thu, 2 Mar 2023 09:13:16 +0100 Subject: [PATCH 12/35] docs updated; renamed app specific MyItem to MySamplePojo --- .../tableviewsample/MainFragment.java | 9 +++-- .../tableview/TableViewAdapter.java | 10 ++--- .../tableview/TableViewModel.java | 14 +++---- .../model/{MyItem.java => MySamplePojo.java} | 40 ++++++++++++++++--- changelog.md | 16 ++++++++ 5 files changed, 69 insertions(+), 20 deletions(-) rename app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/{MyItem.java => MySamplePojo.java} (51%) create mode 100644 changelog.md diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java index 0efcfa0a..000da087 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java @@ -45,10 +45,13 @@ import com.evrencoskun.tableviewsample.tableview.TableViewAdapter; import com.evrencoskun.tableviewsample.tableview.TableViewListener; import com.evrencoskun.tableviewsample.tableview.TableViewModel; -import com.evrencoskun.tableviewsample.tableview.model.MyItem; +import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; /** * A simple {@link Fragment} subclass. + * + * * Display the TableView. + * * Implements filtering, paging, selection, onClick-handling, menue-commands */ public class MainFragment extends Fragment { private Spinner moodFilter, genderFilter; @@ -159,7 +162,7 @@ public void filterTableForMood(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the mood column. if (mTableFilter != null) { - mTableFilter.set(MyItem.COLUMN_INDEX_MOOD_HAPPY, filter); + mTableFilter.set(MySamplePojo.COLUMN_INDEX_MOOD_HAPPY, filter); } } @@ -167,7 +170,7 @@ public void filterTableForGender(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the gender column. if (mTableFilter != null) { - mTableFilter.set(MyItem.COLUMN_INDEX_GENDER_MALE, filter); + mTableFilter.set(MySamplePojo.COLUMN_INDEX_GENDER_MALE, filter); } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index a4d46fc5..534c62bb 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -41,7 +41,7 @@ import com.evrencoskun.tableviewsample.tableview.holder.BoolDrawableCellViewHolder; import com.evrencoskun.tableviewsample.tableview.holder.RowHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.model.Cell; -import com.evrencoskun.tableviewsample.tableview.model.MyItem; +import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; /** @@ -50,7 +50,7 @@ * This is a sample of custom TableView Adapter. */ -public class TableViewAdapter extends AbstractTableAdapter> { +public class TableViewAdapter extends AbstractTableAdapter> { // Cell View Types by Column Position private static final int MOOD_CELL_TYPE = 1; @@ -119,7 +119,7 @@ public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int * @see #onCreateCellViewHolder(ViewGroup, int) ; */ @Override - public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int + public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int columnPosition, int rowPosition) { switch (holder.getItemViewType()) { @@ -273,9 +273,9 @@ public int getCellItemViewType(int column) { // then you should fill this method to be able create different // type of GenericTextCellViewHolder on "onCreateCellViewHolder" switch (column) { - case MyItem.COLUMN_INDEX_MOOD_HAPPY: + case MySamplePojo.COLUMN_INDEX_MOOD_HAPPY: return MOOD_CELL_TYPE; - case MyItem.COLUMN_INDEX_GENDER_MALE: + case MySamplePojo.COLUMN_INDEX_GENDER_MALE: return GENDER_CELL_TYPE; default: // Default view type diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 2e6deb39..881e89da 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -27,7 +27,7 @@ import androidx.annotation.NonNull; import com.evrencoskun.tableviewsample.tableview.model.Cell; -import com.evrencoskun.tableviewsample.tableview.model.MyItem; +import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; import java.util.ArrayList; @@ -47,7 +47,7 @@ public class TableViewModel { private List getSimpleRowHeaderList() { List list = new ArrayList<>(); for (int i = 0; i < ROW_SIZE; i++) { - RowHeader header = new RowHeader(new MyItem(String.valueOf(i))); + RowHeader header = new RowHeader(new MySamplePojo(String.valueOf(i))); list.add(header); } @@ -78,11 +78,11 @@ private List getRandomColumnHeaderList() { * This is a dummy model list test some cases. */ @NonNull - private List>> getCellListForSortingTest() { - List>> list = new ArrayList<>(); + private List>> getCellListForSortingTest() { + List>> list = new ArrayList<>(); for (int rowId = 0; rowId < ROW_SIZE; rowId++) { - List> cellList = new ArrayList<>(); - Cell cell = new Cell(new MyItem("" + rowId)); + List> cellList = new ArrayList<>(); + Cell cell = new Cell(new MySamplePojo("" + rowId)); for (int colId = 0; colId < COLUMN_SIZE; colId++) { cellList.add(cell); } @@ -93,7 +93,7 @@ private List>> getCellListForSortingTest() { } @NonNull - public List>> getCellList() { + public List>> getCellList() { return getCellListForSortingTest(); } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MyItem.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java similarity index 51% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MyItem.java rename to app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java index 6122e3d4..5a6ba9a2 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MyItem.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2021 Evren Coşkun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package com.evrencoskun.tableviewsample.tableview.model; import static java.lang.Math.abs; @@ -9,11 +33,11 @@ import java.util.Random; -public class MyItem implements ISortableModel { +/** + * An example Pojo that is displayed in demo app-s tableview. + */ +public class MySamplePojo implements ISortableModel { // Columns indexes - public static final int COLUMN_INDEX_ID = 0; - public static final int COLUMN_INDEX_RANDOM_LONG = 1; - public static final int COLUMN_INDEX_RAMDOM_SHORT = 2; public static final int COLUMN_INDEX_MOOD_HAPPY = 3; public static final int COLUMN_INDEX_GENDER_MALE = 4; @@ -27,13 +51,19 @@ public class MyItem implements ISortableModel { public final boolean mGenderMale; public final boolean mMoodHappy; - public MyItem(@NonNull String id) { + /** + * Create an item that will be displayed in the TableView. + * the "column-values" are random generated. + */ + public MySamplePojo(@NonNull String id) { this.mId = id; this.mText = "cell " + mId + " 1"; mGenderMale = new Random().nextBoolean(); mMoodHappy = new Random().nextBoolean(); mRandom = abs(new Random().nextInt()); mRandomShort = mRandom % 100; + + // the first colums of the table columns = new Object[]{mRandom, mRandomShort, mText, mGenderMale, mMoodHappy}; } diff --git a/changelog.md b/changelog.md new file mode 100644 index 00000000..1c2542b5 --- /dev/null +++ b/changelog.md @@ -0,0 +1,16 @@ +changelog.md + +TableView is a powerful and beatifull looking Android library for displaying complex +data structures and rendering tabular data composed of rows, columns and cells. + +The current implementation at https://github.com/evrencoskun/TableView +requires a lot of copy&paste from example code to use the TableView in a clientapp. + +Product vision: reduce the amount of (copied) code to integrate TableView into a clientapp. + +* v done: replaced the table header modell with simple Strings. +* v done: replaced the must-customize Cell.java with a templated Cell where customisation takes place in the pojo +* v done: keep demo app intact using MySamplePojo +* . customized TableViewAdapter inherits from new generic TableViewAdapterBase +* . (planed): replace List>> with List> +* . additional lib containing the generic gui classes and resources From b569ddb61c4e72d55b326b9b095e551a50965a78 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:03:28 +0100 Subject: [PATCH 13/35] customized TableViewAdapter inherits from new generic TableViewAdapterBase --- .../tableview/TableViewAdapter.java | 156 +----------- .../tableview/TableViewAdapterBase.java | 232 ++++++++++++++++++ changelog.md | 2 +- 3 files changed, 240 insertions(+), 150 deletions(-) create mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index 534c62bb..4515528d 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -32,39 +32,28 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.adapter.AbstractTableAdapter; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import com.evrencoskun.tableview.sort.SortState; import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.holder.GenericTextCellViewHolder; -import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.holder.BoolDrawableCellViewHolder; -import com.evrencoskun.tableviewsample.tableview.holder.RowHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; -import com.evrencoskun.tableviewsample.tableview.model.RowHeader; /** * Created by evrencoskun on 11/06/2017. *

- * This is a sample of custom TableView Adapter. + * This is a sample of custom TableView Adapter that is customized for MySamplePojo: + * Columns MOOD_CELL and GENDER_CELL are displayed as images. */ -public class TableViewAdapter extends AbstractTableAdapter> { +public class TableViewAdapter extends TableViewAdapterBase { // Cell View Types by Column Position private static final int MOOD_CELL_TYPE = 1; private static final int GENDER_CELL_TYPE = 2; // add new one if it necessary.. - private static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); - - @NonNull - private final TableViewModel mTableViewModel; - public TableViewAdapter(@NonNull TableViewModel tableViewModel) { - super(); - this.mTableViewModel = tableViewModel; + super(tableViewModel); } /** @@ -96,11 +85,7 @@ public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int return new BoolDrawableCellViewHolder(layout, R.drawable.ic_male, R.drawable.ic_female); default: - // For cells that display a text - layout = inflater.inflate(R.layout.table_view_cell_layout, parent, false); - - // Create a Cell ViewHolder - return new GenericTextCellViewHolder(layout); + return super.onCreateCellViewHolder(parent,viewType); } } @@ -133,138 +118,11 @@ public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable C break; default: // Get the holder to update cell item text - GenericTextCellViewHolder viewHolder = (GenericTextCellViewHolder) holder; - viewHolder.setCell(cellItemModel, columnPosition, rowPosition); + super.onBindCellViewHolder(holder, cellItemModel, columnPosition, rowPosition); break; } } - /** - * This is where you create your custom Column Header ViewHolder. This method is called when - * Column Header RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given - * type to represent an item. - * - * @param viewType : This value comes from "getColumnHeaderItemViewType" method to support - * different type of viewHolder as a Column Header item. - * @see #getColumnHeaderItemViewType(int); - */ - @NonNull - @Override - public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { - // TODO: check - //Log.e(LOG_TAG, " onCreateColumnHeaderViewHolder has been called"); - // Get Column Header xml Layout - View layout = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.table_view_column_header_layout, parent, false); - - // Create a ColumnHeader ViewHolder - return new ColumnHeaderViewHolder(layout, getTableView()); - } - - /** - * That is where you set Column Header data to your custom Column Header ViewHolder. - * This method is Called by ColumnHeader RecyclerView of the TableView to display the data at - * the specified position. This method gives you everything you need about a column header - * item. - * - * @param holder : This is one of your column header ViewHolders that was created - * on ```onCreateColumnHeaderViewHolder``` method. In this example - * we have created "ColumnHeaderViewHolder" holder. - * @param columnHeader : This is the column header located on this X - * position. In this example, the model class is "String". - * @param columnPosition : This is the X (Column) position of the column header item. - * @see #onCreateColumnHeaderViewHolder(ViewGroup, int) ; - */ - @Override - public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String - columnHeader, int columnPosition) { - - // Get the holder to update cell item text - ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder; - columnHeaderViewHolder.setColumnHeader(columnHeader); - } - - /** - * This is where you create your custom Row Header ViewHolder. This method is called when - * Row Header RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given - * type to represent an item. - * - * @param viewType : This value comes from "getRowHeaderItemViewType" method to support - * different type of viewHolder as a row Header item. - * @see #getRowHeaderItemViewType(int); - */ - @NonNull - @Override - public AbstractViewHolder onCreateRowHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { - // Get Row Header xml Layout - View layout = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.table_view_row_header_layout, parent, false); - - // Create a Row Header ViewHolder - return new RowHeaderViewHolder(layout); - } - - - /** - * That is where you set Row Header View Model data to your custom Row Header ViewHolder. This - * method is Called by RowHeader RecyclerView of the TableView to display the data at the - * specified position. This method gives you everything you need about a row header item. - * - * @param holder : This is one of your row header ViewHolders that was created on - * ```onCreateRowHeaderViewHolder``` method. In this example we have - * created "RowHeaderViewHolder" holder. - * @param rowHeaderItemModel : This is the row header view model located on this Y position. In - * this example, the model class is "RowHeader". - * @param rowPosition : This is the Y (row) position of the row header item. - * @see #onCreateRowHeaderViewHolder(ViewGroup, int) ; - */ - @Override - public void onBindRowHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable RowHeader rowHeaderItemModel, - int rowPosition) { - - // Get the holder to update row header item text - RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder; - rowHeaderViewHolder.row_header_textview.setText(String.valueOf(rowHeaderItemModel.getId())); - } - - @NonNull - @Override - public View onCreateCornerView(@NonNull ViewGroup parent) { - // Get Corner xml layout - View corner = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.table_view_corner_layout, parent, false); - corner.setOnClickListener(view -> { - SortState sortState = TableViewAdapter.this.getTableView() - .getRowHeaderSortingStatus(); - if (sortState != SortState.ASCENDING) { - Log.d("TableViewAdapter", "Order Ascending"); - TableViewAdapter.this.getTableView().sortRowHeader(SortState.ASCENDING); - } else { - Log.d("TableViewAdapter", "Order Descending"); - TableViewAdapter.this.getTableView().sortRowHeader(SortState.DESCENDING); - } - }); - return corner; - } - - @Override - public int getColumnHeaderItemViewType(int position) { - // The unique ID for this type of column header item - // If you have different items for Cell View by X (Column) position, - // then you should fill this method to be able create different - // type of GenericTextCellViewHolder on "onCreateCellViewHolder" - return 0; - } - - @Override - public int getRowHeaderItemViewType(int position) { - // The unique ID for this type of row header item - // If you have different items for Row Header View by Y (Row) position, - // then you should fill this method to be able create different - // type of RowHeaderViewHolder on "onCreateRowHeaderViewHolder" - return 0; - } - @Override public int getCellItemViewType(int column) { @@ -279,7 +137,7 @@ public int getCellItemViewType(int column) { return GENDER_CELL_TYPE; default: // Default view type - return 0; + return getRowHeaderItemViewType(0); } } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java new file mode 100644 index 00000000..81fddad9 --- /dev/null +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java @@ -0,0 +1,232 @@ +/* + * MIT License + * + * Copyright (c) 2021 Evren Coşkun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableviewsample.tableview; + +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.evrencoskun.tableview.adapter.AbstractTableAdapter; +import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; +import com.evrencoskun.tableview.sort.ISortableModel; +import com.evrencoskun.tableview.sort.SortState; +import com.evrencoskun.tableviewsample.R; +import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; +import com.evrencoskun.tableviewsample.tableview.holder.GenericTextCellViewHolder; +import com.evrencoskun.tableviewsample.tableview.holder.RowHeaderViewHolder; +import com.evrencoskun.tableviewsample.tableview.model.Cell; +import com.evrencoskun.tableviewsample.tableview.model.RowHeader; + +/** + * Generic adapter that translates a Pojo to TableView-Cells. + * + * Defaultimplementation translates all columns to TextView fields. + */ +public abstract class TableViewAdapterBase extends AbstractTableAdapter> { + protected static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); + @NonNull + protected final TableViewModel mTableViewModel; + + public TableViewAdapterBase(TableViewModel tableViewModel) { + this.mTableViewModel = tableViewModel; + } + + /** + * This is where you create your custom Column Header ViewHolder. This method is called when + * Column Header RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given + * type to represent an item. + * + * @param viewType : This value comes from "getColumnHeaderItemViewType" method to support + * different type of viewHolder as a Column Header item. + * @see #getColumnHeaderItemViewType(int); + */ + @NonNull + @Override + public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { + // TODO: check + //Log.e(LOG_TAG, " onCreateColumnHeaderViewHolder has been called"); + // Get Column Header xml Layout + View layout = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.table_view_column_header_layout, parent, false); + + // Create a ColumnHeader ViewHolder + return new ColumnHeaderViewHolder(layout, getTableView()); + } + + /** + * That is where you set Column Header data to your custom Column Header ViewHolder. + * This method is Called by ColumnHeader RecyclerView of the TableView to display the data at + * the specified position. This method gives you everything you need about a column header + * item. + * + * @param holder : This is one of your column header ViewHolders that was created + * on ```onCreateColumnHeaderViewHolder``` method. In this example + * we have created "ColumnHeaderViewHolder" holder. + * @param columnHeader : This is the column header located on this X + * position. In this example, the model class is "String". + * @param columnPosition : This is the X (Column) position of the column header item. + * @see #onCreateColumnHeaderViewHolder(ViewGroup, int) ; + */ + @Override + public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String + columnHeader, int columnPosition) { + + // Get the holder to update cell item text + ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder; + columnHeaderViewHolder.setColumnHeader(columnHeader); + } + + /** + * This is where you create your custom Cell ViewHolder. This method is called when Cell + * RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given type to + * represent an item. + * + * @param viewType : This value comes from "getCellItemViewType" method to support different + * type of viewHolder as a Cell item. + * @see #getCellItemViewType(int); + */ + @NonNull + @Override + public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int viewType) { + //TODO check + Log.e(LOG_TAG, " onCreateCellViewHolder has been called"); + LayoutInflater inflater = LayoutInflater.from(parent.getContext()); + View layout; + + // For cells that display a text + layout = inflater.inflate(R.layout.table_view_cell_layout, parent, false); + + // Create a Cell ViewHolder + return new GenericTextCellViewHolder(layout); + } + + /** + * That is where you set Cell View Model data to your custom Cell ViewHolder. This method is + * Called by Cell RecyclerView of the TableView to display the data at the specified position. + * This method gives you everything you need about a cell item. + * + * @param holder : This is one of your cell ViewHolders that was created on + * ```onCreateCellViewHolder``` method. In this example we have created + * "GenericTextCellViewHolder" holder. + * @param cellItemModel : This is the cell view model located on this X and Y position. In this + * example, the model class is "Cell". + * @param columnPosition : This is the X (Column) position of the cell item. + * @param rowPosition : This is the Y (Row) position of the cell item. + * @see #onCreateCellViewHolder(ViewGroup, int) ; + */ + @Override + public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int + columnPosition, int rowPosition) { + + // Get the holder to update cell item text + GenericTextCellViewHolder viewHolder = (GenericTextCellViewHolder) holder; + viewHolder.setCell(cellItemModel, columnPosition, rowPosition); + } + + + /** + * This is where you create your custom Row Header ViewHolder. This method is called when + * Row Header RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given + * type to represent an item. + * + * @param viewType : This value comes from "getRowHeaderItemViewType" method to support + * different type of viewHolder as a row Header item. + * @see #getRowHeaderItemViewType(int); + */ + @NonNull + @Override + public AbstractViewHolder onCreateRowHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { + // Get Row Header xml Layout + View layout = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.table_view_row_header_layout, parent, false); + + // Create a Row Header ViewHolder + return new RowHeaderViewHolder(layout); + } + + /** + * That is where you set Row Header View Model data to your custom Row Header ViewHolder. This + * method is Called by RowHeader RecyclerView of the TableView to display the data at the + * specified position. This method gives you everything you need about a row header item. + * + * @param holder : This is one of your row header ViewHolders that was created on + * ```onCreateRowHeaderViewHolder``` method. In this example we have + * created "RowHeaderViewHolder" holder. + * @param rowHeaderItemModel : This is the row header view model located on this Y position. In + * this example, the model class is "RowHeader". + * @param rowPosition : This is the Y (row) position of the row header item. + * @see #onCreateRowHeaderViewHolder(ViewGroup, int) ; + */ + @Override + public void onBindRowHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable RowHeader rowHeaderItemModel, + int rowPosition) { + + // Get the holder to update row header item text + RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder; + rowHeaderViewHolder.row_header_textview.setText(String.valueOf(rowHeaderItemModel.getId())); + } + + @NonNull + @Override + public View onCreateCornerView(@NonNull ViewGroup parent) { + // Get Corner xml layout + View corner = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.table_view_corner_layout, parent, false); + corner.setOnClickListener(view -> { + SortState sortState = TableViewAdapterBase.this.getTableView() + .getRowHeaderSortingStatus(); + if (sortState != SortState.ASCENDING) { + Log.d("TableViewAdapter", "Order Ascending"); + TableViewAdapterBase.this.getTableView().sortRowHeader(SortState.ASCENDING); + } else { + Log.d("TableViewAdapter", "Order Descending"); + TableViewAdapterBase.this.getTableView().sortRowHeader(SortState.DESCENDING); + } + }); + return corner; + } + + @Override + public int getColumnHeaderItemViewType(int position) { + // The unique ID for this type of column header item + // If you have different items for Cell View by X (Column) position, + // then you should fill this method to be able create different + // type of GenericTextCellViewHolder on "onCreateCellViewHolder" + return 0; + } + + @Override + public int getRowHeaderItemViewType(int position) { + // The unique ID for this type of row header item + // If you have different items for Row Header View by Y (Row) position, + // then you should fill this method to be able create different + // type of RowHeaderViewHolder on "onCreateRowHeaderViewHolder" + return 0; + } +} diff --git a/changelog.md b/changelog.md index 1c2542b5..b44c29c9 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,6 @@ Product vision: reduce the amount of (copied) code to integrate TableView into a * v done: replaced the table header modell with simple Strings. * v done: replaced the must-customize Cell.java with a templated Cell where customisation takes place in the pojo * v done: keep demo app intact using MySamplePojo -* . customized TableViewAdapter inherits from new generic TableViewAdapterBase +* v done: customized TableViewAdapter inherits from new generic TableViewAdapterBase * . (planed): replace List>> with List> * . additional lib containing the generic gui classes and resources From 80044dd8468c7536f7c20c4276a3032f1d90bab3 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Thu, 2 Mar 2023 12:53:45 +0100 Subject: [PATCH 14/35] Introduced (I)Row as a replacement for List(i.e. List>> becomes List>) --- .../tableview/TableViewModel.java | 10 +++-- changelog.md | 4 +- .../tableview/test/data/SimpleData.java | 10 +++-- .../java/com/evrencoskun/tableview/IRow.java | 30 +++++++++++++++ .../java/com/evrencoskun/tableview/Row.java | 38 +++++++++++++++++++ .../com/evrencoskun/tableview/TableView.java | 3 +- .../adapter/AbstractTableAdapter.java | 14 ++++--- .../AdapterDataSetChangedListener.java | 6 ++- .../tableview/adapter/ITableAdapter.java | 3 +- .../AbstractRecyclerViewAdapter.java | 6 +-- .../recyclerview/CellRecyclerViewAdapter.java | 20 ++++++---- .../CellRowRecyclerViewAdapter.java | 3 +- .../filter/FilterChangedListener.java | 6 ++- .../tableview/handler/ColumnSortHandler.java | 21 +++++----- .../tableview/handler/FilterHandler.java | 36 +++++++++--------- .../tableview/pagination/Pagination.java | 13 ++++--- .../ColumnForRowHeaderSortComparator.java | 6 ++- .../tableview/sort/ColumnSortCallback.java | 8 ++-- .../sort/RowHeaderForCellSortComparator.java | 6 ++- 19 files changed, 169 insertions(+), 74 deletions(-) create mode 100644 tableview/src/main/java/com/evrencoskun/tableview/IRow.java create mode 100644 tableview/src/main/java/com/evrencoskun/tableview/Row.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 881e89da..d6aac25d 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -26,6 +26,8 @@ import androidx.annotation.NonNull; +import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.Row; import com.evrencoskun.tableviewsample.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; @@ -78,10 +80,10 @@ private List getRandomColumnHeaderList() { * This is a dummy model list test some cases. */ @NonNull - private List>> getCellListForSortingTest() { - List>> list = new ArrayList<>(); + private List>> getCellListForSortingTest() { + List>> list = new ArrayList<>(); for (int rowId = 0; rowId < ROW_SIZE; rowId++) { - List> cellList = new ArrayList<>(); + IRow> cellList = new Row<>(); Cell cell = new Cell(new MySamplePojo("" + rowId)); for (int colId = 0; colId < COLUMN_SIZE; colId++) { cellList.add(cell); @@ -93,7 +95,7 @@ private List>> getCellListForSortingTest() { } @NonNull - public List>> getCellList() { + public List>> getCellList() { return getCellListForSortingTest(); } diff --git a/changelog.md b/changelog.md index b44c29c9..ec3e7af7 100644 --- a/changelog.md +++ b/changelog.md @@ -12,5 +12,5 @@ Product vision: reduce the amount of (copied) code to integrate TableView into a * v done: replaced the must-customize Cell.java with a templated Cell where customisation takes place in the pojo * v done: keep demo app intact using MySamplePojo * v done: customized TableViewAdapter inherits from new generic TableViewAdapterBase -* . (planed): replace List>> with List> -* . additional lib containing the generic gui classes and resources +* v done: replace List>> with List> +* . (planed): additional lib containing the generic gui classes and resources diff --git a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java index 991694a2..d570ea13 100644 --- a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java +++ b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java @@ -24,6 +24,8 @@ package com.evrencoskun.tableview.test.data; +import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.Row; import com.evrencoskun.tableview.test.models.Cell; import com.evrencoskun.tableview.test.models.ColumnHeader; import com.evrencoskun.tableview.test.models.RowHeader; @@ -32,7 +34,7 @@ import java.util.List; public class SimpleData { - private List> cells; + private List> cells; private List columnHeaders; private List rowHeaders; @@ -57,7 +59,7 @@ private void init(int columnSize, int rowSize) { cells = new ArrayList<>(); for (int i = 0; i < rowSize; i++) { - ArrayList cellList = new ArrayList<>(); + IRow cellList = new Row<>(); for (int j = 0; j < columnSize; j++) { String id = j + ":" + i; cellList.add(new Cell(id, "r:" + i + "c:" + j)); @@ -66,11 +68,11 @@ private void init(int columnSize, int rowSize) { } } - public List> getCells() { + public List> getCells() { return cells; } - public void setCells(List> cells) { + public void setCells(List> cells) { this.cells = cells; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/IRow.java b/tableview/src/main/java/com/evrencoskun/tableview/IRow.java new file mode 100644 index 00000000..8872c120 --- /dev/null +++ b/tableview/src/main/java/com/evrencoskun/tableview/IRow.java @@ -0,0 +1,30 @@ +/* + * MIT License + * + * Copyright (c) 2023 Evren Coşkun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableview; + +import java.util.List; + +public interface IRow extends List { +} diff --git a/tableview/src/main/java/com/evrencoskun/tableview/Row.java b/tableview/src/main/java/com/evrencoskun/tableview/Row.java new file mode 100644 index 00000000..2b61e6c9 --- /dev/null +++ b/tableview/src/main/java/com/evrencoskun/tableview/Row.java @@ -0,0 +1,38 @@ +/* + * MIT License + * + * Copyright (c) 2023 Evren Coşkun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableview; + +import java.util.ArrayList; +import java.util.List; + +public class Row extends ArrayList implements IRow { + public Row(List cs) { + super(cs); + } + + public Row() { + super(); + } +} diff --git a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java index 9cdfd9fa..65876c54 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java @@ -54,6 +54,7 @@ import com.evrencoskun.tableview.listener.scroll.HorizontalRecyclerViewListener; import com.evrencoskun.tableview.listener.scroll.VerticalRecyclerViewListener; import com.evrencoskun.tableview.preference.SavedState; +import com.evrencoskun.tableview.sort.ISortableModel; import com.evrencoskun.tableview.sort.SortState; import androidx.annotation.AttrRes; @@ -396,7 +397,7 @@ protected CellRecyclerView createCellRecyclerView() { return recyclerView; } - public void setAdapter(@Nullable AbstractTableAdapter tableAdapter) { + public void setAdapter(@Nullable AbstractTableAdapter tableAdapter) { if (tableAdapter != null) { this.mTableAdapter = tableAdapter; this.mTableAdapter.setRowHeaderWidth(mRowHeaderWidth); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java index 9f9e93c9..7b7cd966 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java @@ -32,10 +32,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.evrencoskun.tableview.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.RowHeaderRecyclerViewAdapter; +import com.evrencoskun.tableview.sort.ISortableModel; import java.util.ArrayList; import java.util.List; @@ -44,7 +46,7 @@ * Created by evrencoskun on 10/06/2017. */ -public abstract class AbstractTableAdapter implements ITableAdapter { +public abstract class AbstractTableAdapter implements ITableAdapter { private int mRowHeaderWidth; private int mColumnHeaderHeight; @@ -56,7 +58,7 @@ public abstract class AbstractTableAdapter implements ITableAdapter mColumnHeaderItems; protected List mRowHeaderItems; - protected List> mCellItems; + protected List> mCellItems; private ITableView mTableView; private List> dataSetChangedListeners; @@ -107,7 +109,7 @@ public void setRowHeaderItems(@Nullable List rowHeaderItems) { dispatchRowHeaderDataSetChangesToListeners(mRowHeaderItems); } - public void setCellItems(@Nullable List> cellItems) { + public void setCellItems(@Nullable List> cellItems) { if (cellItems == null) { return; } @@ -124,7 +126,7 @@ public void setCellItems(@Nullable List> cellItems) { public void setAllItems( @Nullable List columnHeaderItems, @Nullable List rowHeaderItems, - @Nullable List> cellItems + @Nullable List> cellItems ) { // Set all items setColumnHeaderItems(columnHeaderItems); @@ -302,7 +304,7 @@ public void addRow(int rowPosition, @Nullable RH rowHeaderItem, @Nullable List rowHeaderItem, @Nullable List> cellItems) { + public void addRowRange(int rowPositionStart, @Nullable List rowHeaderItem, @Nullable List> cellItems) { mRowHeaderRecyclerViewAdapter.addItemRange(rowPositionStart, rowHeaderItem); mCellRecyclerViewAdapter.addItemRange(rowPositionStart, cellItems); } @@ -377,7 +379,7 @@ private void dispatchRowHeaderDataSetChangesToListeners(@NonNull final List } } - private void dispatchCellDataSetChangesToListeners(@NonNull List> newCellItems) { + private void dispatchCellDataSetChangesToListeners(@NonNull List> newCellItems) { if (dataSetChangedListeners != null) { for (AdapterDataSetChangedListener listener : dataSetChangedListeners) { listener.onCellItemsChanged(newCellItems); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java index cf363c8a..5b73c84e 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java @@ -26,6 +26,8 @@ import androidx.annotation.NonNull; +import com.evrencoskun.tableview.IRow; + import java.util.List; public abstract class AdapterDataSetChangedListener { @@ -51,7 +53,7 @@ public void onRowHeaderItemsChanged(@NonNull List rowHeaderItems) { * * @param cellItems The current cell items. */ - public void onCellItemsChanged(@NonNull List> cellItems) { + public void onCellItemsChanged(@NonNull List> cellItems) { } /** @@ -64,6 +66,6 @@ public void onCellItemsChanged(@NonNull List> cellItems) { public void onDataSetChanged( List columnHeaderItems, List rowHeaderItems, - List> cellItems) { + List> cellItems) { } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/ITableAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/ITableAdapter.java index 70f677df..f6475eef 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/ITableAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/ITableAdapter.java @@ -32,12 +32,13 @@ import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; +import com.evrencoskun.tableview.sort.ISortableModel; /** * Created by evrencoskun on 10/06/2017. */ -public interface ITableAdapter { +public interface ITableAdapter { int getColumnHeaderItemViewType(int position); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java index c7241632..c60c96a6 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java @@ -30,9 +30,9 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import com.evrencoskun.tableview.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import java.util.ArrayList; import java.util.List; /** @@ -56,7 +56,7 @@ public AbstractRecyclerViewAdapter(@NonNull Context context, @Nullable List i mContext = context; if (itemList == null) { - mItemList = new ArrayList<>(); + mItemList = new Row<>(); } else { setItems(itemList); } @@ -77,7 +77,7 @@ public void setItems(@NonNull List itemList) { } public void setItems(@NonNull List itemList, boolean notifyDataSet) { - mItemList = new ArrayList<>(itemList); + mItemList = new Row<>(itemList); if (notifyDataSet) { this.notifyDataSetChanged(); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java index 8afa8ef9..2462e84d 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java @@ -32,7 +32,9 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import com.evrencoskun.tableview.IRow; import com.evrencoskun.tableview.ITableView; +import com.evrencoskun.tableview.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder.SelectionState; import com.evrencoskun.tableview.handler.ScrollHandler; @@ -46,9 +48,11 @@ /** * Created by evrencoskun on 10/06/2017. + * + * The adapter contains a List of IRow-s of Cells */ -public class CellRecyclerViewAdapter extends AbstractRecyclerViewAdapter { +public class CellRecyclerViewAdapter extends AbstractRecyclerViewAdapter> { @NonNull private final ITableView mTableView; @@ -58,7 +62,7 @@ public class CellRecyclerViewAdapter extends AbstractRecyclerViewAdapter { // This is for testing purpose private int mRecyclerViewId = 0; - public CellRecyclerViewAdapter(@NonNull Context context, @Nullable List itemList, @NonNull ITableView tableView) { + public CellRecyclerViewAdapter(@NonNull Context context, @Nullable List> itemList, @NonNull ITableView tableView) { super(context, itemList); this.mTableView = tableView; @@ -250,9 +254,9 @@ public void removeColumnItems(int column) { // Lets change the model list silently // Create a new list which the column is already removed. - List> cellItems = new ArrayList<>(); + List> cellItems = new ArrayList<>(); for (int i = 0; i < mItemList.size(); i++) { - List rowList = new ArrayList<>((List) mItemList.get(i)); + IRow rowList = new Row<>(mItemList.get(i)); if (rowList.size() > column) { rowList.remove(column); @@ -262,7 +266,7 @@ public void removeColumnItems(int column) { } // Change data without notifying. Because we already did for visible recyclerViews. - setItems((List) cellItems, false); + setItems(cellItems, false); } public void addColumnItems(int column, @NonNull List cellColumnItems) { @@ -286,9 +290,9 @@ public void addColumnItems(int column, @NonNull List cellColumnItems) { // Lets change the model list silently - List> cellItems = new ArrayList<>(); + List> cellItems = new ArrayList<>(); for (int i = 0; i < mItemList.size(); i++) { - List rowList = new ArrayList<>((List) mItemList.get(i)); + IRow rowList = new Row<>(mItemList.get(i)); if (rowList.size() > column) { rowList.add(column, cellColumnItems.get(i)); @@ -298,6 +302,6 @@ public void addColumnItems(int column, @NonNull List cellColumnItems) { } // Change data without notifying. Because we already did for visible recyclerViews. - setItems((List) cellItems, false); + setItems(cellItems, false); } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java index 65b0f5c5..86c60367 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java @@ -33,12 +33,13 @@ import com.evrencoskun.tableview.adapter.ITableAdapter; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder.SelectionState; +import com.evrencoskun.tableview.sort.ISortableModel; /** * Created by evrencoskun on 10/06/2017. */ -public class CellRowRecyclerViewAdapter extends AbstractRecyclerViewAdapter { +public class CellRowRecyclerViewAdapter extends AbstractRecyclerViewAdapter { private int mYPosition; private final ITableAdapter mTableAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java index 7fa4e51a..17e4622a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java @@ -26,6 +26,8 @@ import androidx.annotation.NonNull; +import com.evrencoskun.tableview.IRow; + import java.util.List; public abstract class FilterChangedListener { @@ -36,7 +38,7 @@ public abstract class FilterChangedListener { * @param filteredCellItems The list of filtered cell items. * @param filteredRowHeaderItems The list of filtered row items. */ - public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull List filteredRowHeaderItems) { + public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull IRow filteredRowHeaderItems) { } /** @@ -45,6 +47,6 @@ public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull L * @param originalCellItems The unfiltered cell item list. * @param originalRowHeaderItems The unfiltered row header list. */ - public void onFilterCleared(@NonNull List> originalCellItems, @NonNull List originalRowHeaderItems) { + public void onFilterCleared(@NonNull List> originalCellItems, @NonNull IRow originalRowHeaderItems) { } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java index 35cfa243..6910d752 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java @@ -28,6 +28,7 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.DiffUtil; +import com.evrencoskun.tableview.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; @@ -52,7 +53,7 @@ public class ColumnSortHandler { - private final CellRecyclerViewAdapter> mCellRecyclerViewAdapter; + private final CellRecyclerViewAdapter mCellRecyclerViewAdapter; private final RowHeaderRecyclerViewAdapter mRowHeaderRecyclerViewAdapter; private final ColumnHeaderRecyclerViewAdapter mColumnHeaderRecyclerViewAdapter; @@ -68,7 +69,7 @@ public void setEnableAnimation(boolean mEnableAnimation) { } public ColumnSortHandler(@NonNull ITableView tableView) { - this.mCellRecyclerViewAdapter = (CellRecyclerViewAdapter>) tableView.getCellRecyclerView() + this.mCellRecyclerViewAdapter = (CellRecyclerViewAdapter) tableView.getCellRecyclerView() .getAdapter(); this.mRowHeaderRecyclerViewAdapter = (RowHeaderRecyclerViewAdapter) tableView @@ -82,8 +83,8 @@ public void sortByRowHeader(@NonNull final SortState sortState) { List originalRowHeaderList = mRowHeaderRecyclerViewAdapter.getItems(); List sortedRowHeaderList = new ArrayList<>(originalRowHeaderList); - List> originalList = mCellRecyclerViewAdapter.getItems(); - List> sortedList = new ArrayList<>(originalList); + List> originalList = mCellRecyclerViewAdapter.getItems(); + List> sortedList = new ArrayList<>(originalList); if (sortState != SortState.UNSORTED) { // Do descending / ascending sort @@ -106,8 +107,8 @@ public void sortByRowHeader(@NonNull final SortState sortState) { } public void sort(int column, @NonNull SortState sortState) { - List> originalList = mCellRecyclerViewAdapter.getItems(); - List> sortedList = new ArrayList<>(originalList); + List> originalList = mCellRecyclerViewAdapter.getItems(); + List> sortedList = new ArrayList<>(originalList); List originalRowHeaderList = mRowHeaderRecyclerViewAdapter.getItems(); @@ -138,7 +139,7 @@ public void sort(int column, @NonNull SortState sortState) { private void swapItems(@NonNull List oldRowHeader, @NonNull List newRowHeader, - @NonNull List> newColumnItems, + @NonNull List> newColumnItems, @NonNull SortState sortState ) { @@ -160,7 +161,7 @@ private void swapItems(@NonNull List oldRowHeader, } } - private void swapItems(@NonNull List> oldItems, @NonNull List> + private void swapItems(@NonNull List> oldItems, @NonNull List> newItems, int column, @NonNull List newRowHeader, @NonNull SortState sortState) { // Set new items without calling notifyCellDataSetChanged method of CellRecyclerViewAdapter @@ -181,9 +182,9 @@ private void swapItems(@NonNull List> oldItems, @NonNull Li } } - public void swapItems(@NonNull List> newItems, int column) { + public void swapItems(@NonNull List> newItems, int column) { - List> oldItems = mCellRecyclerViewAdapter.getItems(); + List> oldItems = mCellRecyclerViewAdapter.getItems(); // Set new items without calling notifyCellDataSetChanged method of CellRecyclerViewAdapter mCellRecyclerViewAdapter.setItems(newItems, !mEnableAnimation); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java index b331ed5e..2741592d 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java @@ -26,7 +26,9 @@ import androidx.annotation.NonNull; +import com.evrencoskun.tableview.IRow; import com.evrencoskun.tableview.ITableView; +import com.evrencoskun.tableview.Row; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.RowHeaderRecyclerViewAdapter; @@ -41,16 +43,16 @@ public class FilterHandler { - private final CellRecyclerViewAdapter> mCellRecyclerViewAdapter; + private final CellRecyclerViewAdapter mCellRecyclerViewAdapter; private final RowHeaderRecyclerViewAdapter mRowHeaderRecyclerViewAdapter; - private List> originalCellDataStore; - private List originalRowDataStore; + private List> originalCellDataStore; + private IRow originalRowDataStore; private List> filterChangedListeners; public FilterHandler(@NonNull ITableView tableView) { tableView.getAdapter().addAdapterDataSetChangedListener(adapterDataSetChangedListener); - this.mCellRecyclerViewAdapter = (CellRecyclerViewAdapter>) tableView + this.mCellRecyclerViewAdapter = (CellRecyclerViewAdapter) tableView .getCellRecyclerView().getAdapter(); this.mRowHeaderRecyclerViewAdapter = (RowHeaderRecyclerViewAdapter) tableView @@ -62,20 +64,20 @@ public void filter(@NonNull Filter filter) { return; } - List> originalCellData = new ArrayList<>(originalCellDataStore); - List originalRowData = new ArrayList<>(originalRowDataStore); - List> filteredCellList = new ArrayList<>(); - List filteredRowList = new ArrayList<>(); + List> originalCellData = new ArrayList<>(originalCellDataStore); + IRow originalRowData = new Row<>(originalRowDataStore); + List> filteredCellList = new ArrayList<>(); + IRow filteredRowList = new Row<>(); if (filter.getFilterItems().isEmpty()) { filteredCellList = new ArrayList<>(originalCellDataStore); - filteredRowList = new ArrayList<>(originalRowDataStore); + filteredRowList = new Row<>(originalRowDataStore); dispatchFilterClearedToListeners(originalCellDataStore, originalRowDataStore); } else { for (int x = 0; x < filter.getFilterItems().size(); ) { final FilterItem filterItem = filter.getFilterItems().get(x); if (filterItem.getFilterType().equals(FilterType.ALL)) { - for (List itemsList : originalCellData) { + for (IRow itemsList : originalCellData) { for (T item : itemsList) { if (item .getFilterableKeyword() @@ -90,7 +92,7 @@ public void filter(@NonNull Filter filter) { } } } else { - for (List itemsList : originalCellData) { + for (IRow itemsList : originalCellData) { if (itemsList .get(filterItem .getColumn()) @@ -108,7 +110,7 @@ public void filter(@NonNull Filter filter) { // If this is the last filter to be processed, the filtered lists will not be cleared. if (++x < filter.getFilterItems().size()) { originalCellData = new ArrayList<>(filteredCellList); - originalRowData = new ArrayList<>(filteredRowList); + originalRowData = new Row<>(filteredRowList); filteredCellList.clear(); filteredRowList.clear(); } @@ -129,7 +131,7 @@ public void filter(@NonNull Filter filter) { new AdapterDataSetChangedListener() { @Override public void onRowHeaderItemsChanged(@NonNull List rowHeaderItems) { - originalRowDataStore = new ArrayList<>(rowHeaderItems); + originalRowDataStore = new Row<>(rowHeaderItems); } @Override @@ -139,8 +141,8 @@ public void onCellItemsChanged(@NonNull List cellItems) { }; private void dispatchFilterChangedToListeners( - @NonNull List> filteredCellItems, - @NonNull List filteredRowHeaderItems + @NonNull List> filteredCellItems, + @NonNull IRow filteredRowHeaderItems ) { if (filterChangedListeners != null) { for (FilterChangedListener listener : filterChangedListeners) { @@ -150,8 +152,8 @@ private void dispatchFilterChangedToListeners( } private void dispatchFilterClearedToListeners( - @NonNull List> originalCellItems, - @NonNull List originalRowHeaderItems + @NonNull List> originalCellItems, + @NonNull IRow originalRowHeaderItems ) { if (filterChangedListeners != null) { for (FilterChangedListener listener : filterChangedListeners) { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java index 343a92ce..14bd79d5 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java @@ -27,6 +27,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.evrencoskun.tableview.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; @@ -51,13 +52,13 @@ public class Pagination implements IPagination { private int currentPage; private int pageCount; @NonNull - private List> originalCellData; + private List> originalCellData; @NonNull private List originalRowData; @Nullable private RowHeaderRecyclerViewAdapter mRowHeaderRecyclerViewAdapter; @Nullable - private CellRecyclerViewAdapter> mCellRecyclerViewAdapter; + private CellRecyclerViewAdapter mCellRecyclerViewAdapter; @Nullable private OnTableViewPageTurnedListener onTableViewPageTurnedListener; @@ -116,7 +117,7 @@ private void reloadPages() { private void paginateData() { int start, end; - List> currentPageCellData = new ArrayList<>(); + List> currentPageCellData = new ArrayList<>(); List currentPageRowData = new ArrayList<>(); // No pagination if itemsPerPage is 0, all data will be loaded into the TableView. if (itemsPerPage == 0) { @@ -226,14 +227,14 @@ public void onCellItemsChanged(@NonNull List cellItems) { private final FilterChangedListener filterChangedListener = new FilterChangedListener() { @Override - public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull List filteredRowHeaderItems) { + public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull IRow filteredRowHeaderItems) { originalCellData = new ArrayList<>(filteredCellItems); originalRowData = new ArrayList<>(filteredRowHeaderItems); reloadPages(); } @Override - public void onFilterCleared(@NonNull List> originalCellItems, @NonNull List originalRowHeaderItems) { + public void onFilterCleared(@NonNull List> originalCellItems, @NonNull IRow originalRowHeaderItems) { originalCellData = new ArrayList<>(originalCellItems); originalRowData = new ArrayList<>(originalRowHeaderItems); reloadPages(); @@ -256,7 +257,7 @@ public void onRowHeaderSortStatusChanged(@NonNull SortState sortState) { private void paginateOnColumnSort(int column, @NonNull SortState sortState) { List sortedRowHeaderList = new ArrayList<>(originalRowData); - List> sortedList = new ArrayList<>(originalCellData); + List> sortedList = new ArrayList<>(originalCellData); if (sortState != SortState.UNSORTED) { if (column == -1) { Collections.sort(sortedRowHeaderList, new RowHeaderSortComparator(sortState)); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java index d99f2f14..b33147aa 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java @@ -26,6 +26,8 @@ import androidx.annotation.NonNull; +import com.evrencoskun.tableview.IRow; + import java.util.Comparator; import java.util.List; @@ -41,7 +43,7 @@ public class ColumnForRowHeaderSortComparator implements Comparator mRowHeaderList; @NonNull - private final List> mReferenceList; + private final List> mReferenceList; private final int column; @NonNull private final SortState mSortState; @@ -49,7 +51,7 @@ public class ColumnForRowHeaderSortComparator implements Comparator rowHeader, - @NonNull List> referenceList, + @NonNull List> referenceList, int column, @NonNull SortState sortState) { this.mRowHeaderList = rowHeader; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java index 85fd9f9f..f2cda868 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java @@ -28,6 +28,8 @@ import androidx.core.util.ObjectsCompat; import androidx.recyclerview.widget.DiffUtil; +import com.evrencoskun.tableview.IRow; + import java.util.List; /** @@ -36,12 +38,12 @@ public class ColumnSortCallback extends DiffUtil.Callback { @NonNull - private final List> mOldCellItems; + private final List> mOldCellItems; @NonNull - private final List> mNewCellItems; + private final List> mNewCellItems; private final int mColumnPosition; - public ColumnSortCallback(@NonNull List> oldCellItems, @NonNull List> + public ColumnSortCallback(@NonNull List> oldCellItems, @NonNull List> newCellItems, int column) { this.mOldCellItems = oldCellItems; this.mNewCellItems = newCellItems; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java index f42b1bcc..3dbf800e 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java @@ -26,6 +26,8 @@ import androidx.annotation.NonNull; +import com.evrencoskun.tableview.IRow; + import java.util.Comparator; import java.util.List; @@ -37,14 +39,14 @@ public class RowHeaderForCellSortComparator implements Comparator mReferenceList; @NonNull - private final List> mColumnList; + private final List> mColumnList; @NonNull private final SortState mSortState; @NonNull private final RowHeaderSortComparator mRowHeaderSortComparator; public RowHeaderForCellSortComparator(@NonNull List referenceList, - @NonNull List> columnList, + @NonNull List> columnList, @NonNull SortState sortState) { this.mReferenceList = referenceList; this.mColumnList = columnList; From 71f2ca0f5202a49bff094a0fadf9ae8896012ead Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Mon, 6 Mar 2023 11:10:53 +0100 Subject: [PATCH 15/35] Introduced (I)Row as a replacement for List(i.e. List>> becomes List>) --- .../java/com/evrencoskun/tableview/IRow.java | 9 +++ .../adapter/AbstractTableAdapter.java | 78 ++++++++++++++----- .../recyclerview/CellRecyclerViewAdapter.java | 16 ++-- .../tableview/handler/VisibilityHandler.java | 9 ++- 4 files changed, 80 insertions(+), 32 deletions(-) diff --git a/tableview/src/main/java/com/evrencoskun/tableview/IRow.java b/tableview/src/main/java/com/evrencoskun/tableview/IRow.java index 8872c120..10e339fb 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/IRow.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/IRow.java @@ -27,4 +27,13 @@ import java.util.List; public interface IRow extends List { +// public interface IRow { +/* + // methods implemented by List<> + int size(); + C get(int position); + C remove(int position); + + void add(int position, C item); + */ } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java index 7b7cd966..1f6f93fa 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java @@ -25,6 +25,7 @@ package com.evrencoskun.tableview.adapter; import android.content.Context; +import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -48,12 +49,13 @@ public abstract class AbstractTableAdapter implements ITableAdapter { + private final String tag = getClass().getSimpleName(); private int mRowHeaderWidth; private int mColumnHeaderHeight; private ColumnHeaderRecyclerViewAdapter mColumnHeaderRecyclerViewAdapter; private RowHeaderRecyclerViewAdapter mRowHeaderRecyclerViewAdapter; - private CellRecyclerViewAdapter mCellRecyclerViewAdapter; + private CellRecyclerViewAdapter mCellRecyclerViewAdapter; private View mCornerView; protected List mColumnHeaderItems; @@ -207,7 +209,7 @@ public RowHeaderRecyclerViewAdapter getRowHeaderRecyclerViewAdapter() { return mRowHeaderRecyclerViewAdapter; } - public CellRecyclerViewAdapter getCellRecyclerViewAdapter() { + public CellRecyclerViewAdapter getCellRecyclerViewAdapter() { return mCellRecyclerViewAdapter; } @@ -225,37 +227,70 @@ public void setColumnHeaderHeight(int columnHeaderHeight) { } @Nullable - public CH getColumnHeaderItem(int position) { - if ((mColumnHeaderItems == null || mColumnHeaderItems.isEmpty()) || position < 0 || - position >= mColumnHeaderItems.size()) { + public CH getColumnHeaderItem(int columnPosition) { + int size = (mColumnHeaderItems == null) ? 0 : mColumnHeaderItems.size(); + if (columnPosition < 0 || columnPosition >= size) { + Log.i(tag,"getColumnHeaderItem(col=" + columnPosition + + ") : Illegal columnPosition allowed 0 .. " + size); return null; } - return mColumnHeaderItems.get(position); + return mColumnHeaderItems.get(columnPosition); } @Nullable - public RH getRowHeaderItem(int position) { - if ((mRowHeaderItems == null || mRowHeaderItems.isEmpty()) || position < 0 || position >= - mRowHeaderItems.size()) { + public RH getRowHeaderItem(int rowPosition) { + int size = (mRowHeaderItems == null) ? 0 : mRowHeaderItems.size(); + if (rowPosition < 0 || rowPosition >= size) { + Log.i(tag,"getRowHeaderItem(row=" + rowPosition + + ") : Illegal rowPosition allowed 0 .. " + size); + return null; } - return mRowHeaderItems.get(position); + return mRowHeaderItems.get(rowPosition); } + /** + * gets data from model column/row (and not from visibile column/row + * that may not match current filter/sorting) + * @param columnPosition + * @param rowPosition + */ + @Deprecated @Nullable public C getCellItem(int columnPosition, int rowPosition) { - if ((mCellItems == null || mCellItems.isEmpty()) || columnPosition < 0 || rowPosition >= - mCellItems.size() || mCellItems.get(rowPosition) == null || rowPosition < 0 || - columnPosition >= mCellItems.get(rowPosition).size()) { + IRow row = getRowFromModel(rowPosition); + if (row == null) { return null; } + int size = row.size(); + if (columnPosition < 0 || columnPosition >= size) { + Log.i(tag,"getCellItem(col=" + columnPosition + + ", row=" + rowPosition + + ") : Illegal columnPosition allowed 0 .. " + size); + return null; + } + return row.get(columnPosition); + } - return mCellItems.get(rowPosition).get(columnPosition); + /** + * gets data from model row (and not from visibile row + * that may not match current filter/sorting) + * @param rowPosition + */ + @Deprecated + private IRow getRowFromModel(int rowPosition) { + int size = (mCellItems == null) ? 0 : mCellItems.size(); + if (rowPosition < 0 || rowPosition >= size) { + Log.i(tag,"getCellItems(row=" + rowPosition + + ") : Illegal rowPosition allowed 0 .. " + size); + return null; + } + return mCellItems.get(rowPosition); } @Nullable - public List getCellRowItems(int rowPosition) { - return (List) mCellRecyclerViewAdapter.getItem(rowPosition); + public IRow getCellRowItems(int rowPosition) { + return mCellRecyclerViewAdapter.getItem(rowPosition); } public void removeRow(int rowPosition) { @@ -299,7 +334,7 @@ public void removeRowRange(int rowPositionStart, int itemCount, boolean updateRo mRowHeaderRecyclerViewAdapter.deleteItemRange(rowPositionStart, itemCount); } - public void addRow(int rowPosition, @Nullable RH rowHeaderItem, @Nullable List cellItems) { + public void addRow(int rowPosition, @Nullable RH rowHeaderItem, @Nullable IRow cellItems) { mCellRecyclerViewAdapter.addItem(rowPosition, cellItems); mRowHeaderRecyclerViewAdapter.addItem(rowPosition, rowHeaderItem); } @@ -318,7 +353,7 @@ public void changeRowHeaderItemRange(int rowPositionStart, @Nullable List ro } public void changeCellItem(int columnPosition, int rowPosition, C cellModel) { - List cellItems = (List) mCellRecyclerViewAdapter.getItem(rowPosition); + IRow cellItems = mCellRecyclerViewAdapter.getItem(rowPosition); if (cellItems != null && cellItems.size() > columnPosition) { // Update cell row items. cellItems.set(columnPosition, cellModel); @@ -336,9 +371,12 @@ public void changeColumnHeaderRange(int columnPositionStart, @Nullable List columnHeaderModelList); } + /** + * This method helps to get cell item model that is located on given vertical column position. + */ @NonNull - public List getCellColumnItems(int columnPosition) { - return mCellRecyclerViewAdapter.getColumnItems(columnPosition); + public List getVerticalItemsAtColumn(int columnPosition) { + return mCellRecyclerViewAdapter.getVerticalItemsAtColumn(columnPosition); } public void removeColumn(int columnPosition) { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java index 2462e84d..3fa3b121 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java @@ -124,7 +124,7 @@ public void onBindViewHolder(@NonNull AbstractViewHolder holder, int yPosition) .recyclerView.getAdapter(); // Get the list - List rowList = (List) mItemList.get(yPosition); + IRow rowList = mItemList.get(yPosition); // Set Row position viewAdapter.setYPosition(yPosition); @@ -216,23 +216,23 @@ public void notifyCellDataSetChanged() { } /** - * This method helps to get cell item model that is located on given column position. + * This method helps to get cell item model that is located on given vertical column position. * * @param columnPosition */ @NonNull - public List getColumnItems(int columnPosition) { - List cellItems = new ArrayList<>(); + public List getVerticalItemsAtColumn(int columnPosition) { + List columnItems = new ArrayList<>(); for (int i = 0; i < mItemList.size(); i++) { - List rowList = (List) mItemList.get(i); + IRow row = mItemList.get(i); - if (rowList.size() > columnPosition) { - cellItems.add(rowList.get(columnPosition)); + if (row.size() > columnPosition) { + columnItems.add(row.get(columnPosition)); } } - return cellItems; + return columnItems; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java index 61a7908a..34fa449b 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java @@ -30,6 +30,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.evrencoskun.tableview.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AbstractTableAdapter; import java.util.List; @@ -76,7 +77,7 @@ private void showRow(int row, boolean removeFromList) { if (hiddenRow != null) { // add row model to the adapter mTableView.getAdapter().addRow(row, hiddenRow.getRowHeaderModel(), - hiddenRow.getCellModelList()); + (IRow) hiddenRow.getCellModelList()); } else { Log.e(LOG_TAG, "This row is already visible."); } @@ -127,7 +128,7 @@ private void showColumn(int column, boolean removeFromList) { if (hiddenColumn != null) { // add column model to the adapter mTableView.getAdapter().addColumn(column, hiddenColumn.getColumnHeaderModel(), - hiddenColumn.getCellModelList()); + (List) hiddenColumn.getCellModelList()); } else { Log.e(LOG_TAG, "This column is already visible."); } @@ -252,9 +253,9 @@ private Row getRowValueFromPosition(int row) { private Column getColumnValueFromPosition(int column) { AbstractTableAdapter adapter = mTableView.getAdapter(); Object columnHeaderModel = adapter.getColumnHeaderItem(column); - List cellModelList = adapter.getCellColumnItems(column); + List verticalItemsAtColumn = adapter.getVerticalItemsAtColumn(column); - return new Column(column, columnHeaderModel, cellModelList); + return new Column(column, columnHeaderModel, verticalItemsAtColumn); } @NonNull From 799fe06bf009d1133a09f1d75bf3277fb4f4128b Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Mon, 6 Mar 2023 11:22:47 +0100 Subject: [PATCH 16/35] fix: match show/hide postition with menutext --- .../tableview/popup/ColumnHeaderLongPressPopup.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java index e9865e97..0ae49dd7 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java @@ -107,10 +107,10 @@ public boolean onMenuItemClick(MenuItem menuItem) { mTableView.sortColumn(mXPosition, SortState.DESCENDING); break; case HIDE_ROW: - mTableView.hideRow(5); + mTableView.hideRow(3); break; case SHOW_ROW: - mTableView.showRow(5); + mTableView.showRow(3); break; case SCROLL_ROW: mTableView.scrollToRowPosition(5); From e9eb42f35ce71669c1ae139ca2f2be9812fd31e0 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Tue, 7 Mar 2023 10:53:43 +0100 Subject: [PATCH 17/35] refactored: --- .../adapter/recyclerview/CellRecyclerViewAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java index 3fa3b121..c8b12e21 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java @@ -124,13 +124,13 @@ public void onBindViewHolder(@NonNull AbstractViewHolder holder, int yPosition) .recyclerView.getAdapter(); // Get the list - IRow rowList = mItemList.get(yPosition); + IRow row = mItemList.get(yPosition); // Set Row position viewAdapter.setYPosition(yPosition); // Set the list to the adapter - viewAdapter.setItems(rowList); + viewAdapter.setItems(row); } @Override From 5507a57df2b9289bc9b5d77f967866ebe8374393 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Tue, 7 Mar 2023 11:25:13 +0100 Subject: [PATCH 18/35] added empty androidlib tableviewutil --- changelog.md | 2 +- settings.gradle | 1 + tableviewutil/.gitignore | 1 + tableviewutil/build.gradle | 38 +++++++++++++++++++ tableviewutil/consumer-rules.pro | 0 tableviewutil/proguard-rules.pro | 21 ++++++++++ tableviewutil/src/main/AndroidManifest.xml | 4 ++ .../tableviewutil/ExampleUnitTest.java | 17 +++++++++ 8 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tableviewutil/.gitignore create mode 100644 tableviewutil/build.gradle create mode 100644 tableviewutil/consumer-rules.pro create mode 100644 tableviewutil/proguard-rules.pro create mode 100644 tableviewutil/src/main/AndroidManifest.xml create mode 100644 tableviewutil/src/test/java/com/evrencoskun/tableviewutil/ExampleUnitTest.java diff --git a/changelog.md b/changelog.md index ec3e7af7..582506e3 100644 --- a/changelog.md +++ b/changelog.md @@ -12,5 +12,5 @@ Product vision: reduce the amount of (copied) code to integrate TableView into a * v done: replaced the must-customize Cell.java with a templated Cell where customisation takes place in the pojo * v done: keep demo app intact using MySamplePojo * v done: customized TableViewAdapter inherits from new generic TableViewAdapterBase -* v done: replace List>> with List> +* v done: replace List>> with List> * . (planed): additional lib containing the generic gui classes and resources diff --git a/settings.gradle b/settings.gradle index a9454f81..bc3a7820 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,3 +23,4 @@ */ include ':app', ':tableview' +include ':tableviewutil' diff --git a/tableviewutil/.gitignore b/tableviewutil/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/tableviewutil/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/tableviewutil/build.gradle b/tableviewutil/build.gradle new file mode 100644 index 00000000..522173a1 --- /dev/null +++ b/tableviewutil/build.gradle @@ -0,0 +1,38 @@ +plugins { + id 'com.android.library' +} + +android { + namespace 'com.evrencoskun.tableviewutil' + compileSdkVersion compile_sdk_version + + defaultConfig { + minSdkVersion min_sdk_version + targetSdkVersion target_sdk_version + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility = java_version + targetCompatibility = java_version + } +} + +dependencies { + + implementation "androidx.appcompat:appcompat:$androidx_appcompat_version" + testImplementation "junit:junit:$junit_version" + androidTestImplementation "androidx.test.ext:junit:$androidx_test_ext_version" + androidTestImplementation "androidx.test:rules:$androidx_test_version" + androidTestImplementation "androidx.test:runner:$androidx_test_version" + androidTestImplementation "androidx.test.espresso:espresso-core:$androidx_test_espresso_version" + androidTestImplementation "androidx.test.espresso:espresso-contrib:$androidx_test_espresso_version" +} \ No newline at end of file diff --git a/tableviewutil/consumer-rules.pro b/tableviewutil/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/tableviewutil/proguard-rules.pro b/tableviewutil/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/tableviewutil/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/tableviewutil/src/main/AndroidManifest.xml b/tableviewutil/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a5918e68 --- /dev/null +++ b/tableviewutil/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tableviewutil/src/test/java/com/evrencoskun/tableviewutil/ExampleUnitTest.java b/tableviewutil/src/test/java/com/evrencoskun/tableviewutil/ExampleUnitTest.java new file mode 100644 index 00000000..584655ca --- /dev/null +++ b/tableviewutil/src/test/java/com/evrencoskun/tableviewutil/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.evrencoskun.tableviewutil; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file From a2e7ecbcf4aa56b613a2c17bdbd8f981b0bec36a Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 8 Mar 2023 09:35:54 +0100 Subject: [PATCH 19/35] moved app resources to lib tableviewutil --- app/build.gradle | 1 + tableviewutil/build.gradle | 1 + {app => tableviewutil}/src/main/res/drawable/ic_down.xml | 0 {app => tableviewutil}/src/main/res/drawable/ic_next.xml | 0 .../src/main/res/drawable/ic_previous.xml | 0 {app => tableviewutil}/src/main/res/drawable/ic_up.xml | 0 .../src/main/res/layout/table_view_cell_layout.xml | 0 .../src/main/res/layout/table_view_column_header_layout.xml | 0 .../src/main/res/layout/table_view_corner_layout.xml | 0 .../src/main/res/layout/table_view_image_cell_layout.xml | 6 ++---- .../src/main/res/layout/table_view_row_header_layout.xml | 0 {app => tableviewutil}/src/main/res/values/colors.xml | 0 {app => tableviewutil}/src/main/res/values/dimens.xml | 1 + 13 files changed, 5 insertions(+), 4 deletions(-) rename {app => tableviewutil}/src/main/res/drawable/ic_down.xml (100%) rename {app => tableviewutil}/src/main/res/drawable/ic_next.xml (100%) rename {app => tableviewutil}/src/main/res/drawable/ic_previous.xml (100%) rename {app => tableviewutil}/src/main/res/drawable/ic_up.xml (100%) rename {app => tableviewutil}/src/main/res/layout/table_view_cell_layout.xml (100%) rename {app => tableviewutil}/src/main/res/layout/table_view_column_header_layout.xml (100%) rename {app => tableviewutil}/src/main/res/layout/table_view_corner_layout.xml (100%) rename {app => tableviewutil}/src/main/res/layout/table_view_image_cell_layout.xml (90%) rename {app => tableviewutil}/src/main/res/layout/table_view_row_header_layout.xml (100%) rename {app => tableviewutil}/src/main/res/values/colors.xml (100%) rename {app => tableviewutil}/src/main/res/values/dimens.xml (96%) diff --git a/app/build.gradle b/app/build.gradle index a0ae9733..de95fbfb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,6 +60,7 @@ android { dependencies { implementation project(path: ':tableview') + implementation project(path: ':tableviewutil') implementation "androidx.annotation:annotation:$androidx_annotation_version" implementation "androidx.appcompat:appcompat:$androidx_appcompat_version" diff --git a/tableviewutil/build.gradle b/tableviewutil/build.gradle index 522173a1..acdb3db8 100644 --- a/tableviewutil/build.gradle +++ b/tableviewutil/build.gradle @@ -27,6 +27,7 @@ android { } dependencies { + implementation project(path: ':tableview') implementation "androidx.appcompat:appcompat:$androidx_appcompat_version" testImplementation "junit:junit:$junit_version" diff --git a/app/src/main/res/drawable/ic_down.xml b/tableviewutil/src/main/res/drawable/ic_down.xml similarity index 100% rename from app/src/main/res/drawable/ic_down.xml rename to tableviewutil/src/main/res/drawable/ic_down.xml diff --git a/app/src/main/res/drawable/ic_next.xml b/tableviewutil/src/main/res/drawable/ic_next.xml similarity index 100% rename from app/src/main/res/drawable/ic_next.xml rename to tableviewutil/src/main/res/drawable/ic_next.xml diff --git a/app/src/main/res/drawable/ic_previous.xml b/tableviewutil/src/main/res/drawable/ic_previous.xml similarity index 100% rename from app/src/main/res/drawable/ic_previous.xml rename to tableviewutil/src/main/res/drawable/ic_previous.xml diff --git a/app/src/main/res/drawable/ic_up.xml b/tableviewutil/src/main/res/drawable/ic_up.xml similarity index 100% rename from app/src/main/res/drawable/ic_up.xml rename to tableviewutil/src/main/res/drawable/ic_up.xml diff --git a/app/src/main/res/layout/table_view_cell_layout.xml b/tableviewutil/src/main/res/layout/table_view_cell_layout.xml similarity index 100% rename from app/src/main/res/layout/table_view_cell_layout.xml rename to tableviewutil/src/main/res/layout/table_view_cell_layout.xml diff --git a/app/src/main/res/layout/table_view_column_header_layout.xml b/tableviewutil/src/main/res/layout/table_view_column_header_layout.xml similarity index 100% rename from app/src/main/res/layout/table_view_column_header_layout.xml rename to tableviewutil/src/main/res/layout/table_view_column_header_layout.xml diff --git a/app/src/main/res/layout/table_view_corner_layout.xml b/tableviewutil/src/main/res/layout/table_view_corner_layout.xml similarity index 100% rename from app/src/main/res/layout/table_view_corner_layout.xml rename to tableviewutil/src/main/res/layout/table_view_corner_layout.xml diff --git a/app/src/main/res/layout/table_view_image_cell_layout.xml b/tableviewutil/src/main/res/layout/table_view_image_cell_layout.xml similarity index 90% rename from app/src/main/res/layout/table_view_image_cell_layout.xml rename to tableviewutil/src/main/res/layout/table_view_image_cell_layout.xml index 84ec3644..8e26c4ce 100644 --- a/app/src/main/res/layout/table_view_image_cell_layout.xml +++ b/tableviewutil/src/main/res/layout/table_view_image_cell_layout.xml @@ -33,10 +33,8 @@ + android:layout_width="@dimen/cell_image_size" + android:layout_height="@dimen/cell_image_size" /> diff --git a/app/src/main/res/layout/table_view_row_header_layout.xml b/tableviewutil/src/main/res/layout/table_view_row_header_layout.xml similarity index 100% rename from app/src/main/res/layout/table_view_row_header_layout.xml rename to tableviewutil/src/main/res/layout/table_view_row_header_layout.xml diff --git a/app/src/main/res/values/colors.xml b/tableviewutil/src/main/res/values/colors.xml similarity index 100% rename from app/src/main/res/values/colors.xml rename to tableviewutil/src/main/res/values/colors.xml diff --git a/app/src/main/res/values/dimens.xml b/tableviewutil/src/main/res/values/dimens.xml similarity index 96% rename from app/src/main/res/values/dimens.xml rename to tableviewutil/src/main/res/values/dimens.xml index ae89c5e8..f016182d 100644 --- a/app/src/main/res/values/dimens.xml +++ b/tableviewutil/src/main/res/values/dimens.xml @@ -30,4 +30,5 @@ 55dp 40dp + 32dp From 96fb3f49509e5c7cb540e0f60758b49350d8f85e Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:35:05 +0100 Subject: [PATCH 20/35] moved Cell, (I)Row to com.evrencoskun.tableview.modell --- .../tableviewsample/MainFragment.java | 5 ++--- .../tableview/TableViewAdapter.java | 9 ++++++--- .../tableview/TableViewAdapterBase.java | 2 +- .../tableview/TableViewModel.java | 20 ++++++++++++++----- .../holder/GenericTextCellViewHolder.java | 2 +- .../tableview/model/MySamplePojo.java | 9 +++------ .../tableview/model/RowHeader.java | 4 ++-- .../tableview/test/data/SimpleData.java | 4 ++-- .../adapter/AbstractTableAdapter.java | 2 +- .../AdapterDataSetChangedListener.java | 2 +- .../AbstractRecyclerViewAdapter.java | 2 +- .../recyclerview/CellRecyclerViewAdapter.java | 4 ++-- .../filter/FilterChangedListener.java | 2 +- .../tableview/handler/ColumnSortHandler.java | 2 +- .../tableview/handler/FilterHandler.java | 4 ++-- .../tableview/handler/VisibilityHandler.java | 2 +- .../evrencoskun/tableview/modell}/Cell.java | 12 ++++++----- .../tableview/modell/IColumnValue.java | 5 +++++ .../tableview/{ => modell}/IRow.java | 2 +- .../tableview/{ => modell}/Row.java | 2 +- .../tableview/pagination/Pagination.java | 2 +- .../ColumnForRowHeaderSortComparator.java | 2 +- .../tableview/sort/ColumnSortCallback.java | 2 +- .../sort/RowHeaderForCellSortComparator.java | 2 +- 24 files changed, 60 insertions(+), 44 deletions(-) rename {app/src/main/java/com/evrencoskun/tableviewsample/tableview/model => tableview/src/main/java/com/evrencoskun/tableview/modell}/Cell.java (86%) create mode 100644 tableview/src/main/java/com/evrencoskun/tableview/modell/IColumnValue.java rename tableview/src/main/java/com/evrencoskun/tableview/{ => modell}/IRow.java (97%) rename tableview/src/main/java/com/evrencoskun/tableview/{ => modell}/Row.java (96%) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java index 000da087..014eef18 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java @@ -45,7 +45,6 @@ import com.evrencoskun.tableviewsample.tableview.TableViewAdapter; import com.evrencoskun.tableviewsample.tableview.TableViewListener; import com.evrencoskun.tableviewsample.tableview.TableViewModel; -import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; /** * A simple {@link Fragment} subclass. @@ -162,7 +161,7 @@ public void filterTableForMood(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the mood column. if (mTableFilter != null) { - mTableFilter.set(MySamplePojo.COLUMN_INDEX_MOOD_HAPPY, filter); + mTableFilter.set(TableViewAdapter.COLUMN_INDEX_MOOD_HAPPY, filter); } } @@ -170,7 +169,7 @@ public void filterTableForGender(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the gender column. if (mTableFilter != null) { - mTableFilter.set(MySamplePojo.COLUMN_INDEX_GENDER_MALE, filter); + mTableFilter.set(TableViewAdapter.COLUMN_INDEX_GENDER_MALE, filter); } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index 4515528d..c3636ec2 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -35,7 +35,7 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewsample.tableview.holder.BoolDrawableCellViewHolder; -import com.evrencoskun.tableviewsample.tableview.model.Cell; +import com.evrencoskun.tableview.modell.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; /** @@ -47,6 +47,9 @@ public class TableViewAdapter extends TableViewAdapterBase { + // Columns indexes + public static final int COLUMN_INDEX_MOOD_HAPPY = 3; + public static final int COLUMN_INDEX_GENDER_MALE = 4; // Cell View Types by Column Position private static final int MOOD_CELL_TYPE = 1; private static final int GENDER_CELL_TYPE = 2; @@ -131,9 +134,9 @@ public int getCellItemViewType(int column) { // then you should fill this method to be able create different // type of GenericTextCellViewHolder on "onCreateCellViewHolder" switch (column) { - case MySamplePojo.COLUMN_INDEX_MOOD_HAPPY: + case COLUMN_INDEX_MOOD_HAPPY: return MOOD_CELL_TYPE; - case MySamplePojo.COLUMN_INDEX_GENDER_MALE: + case COLUMN_INDEX_GENDER_MALE: return GENDER_CELL_TYPE; default: // Default view type diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java index 81fddad9..abcd925a 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java @@ -40,7 +40,7 @@ import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.holder.GenericTextCellViewHolder; import com.evrencoskun.tableviewsample.tableview.holder.RowHeaderViewHolder; -import com.evrencoskun.tableviewsample.tableview.model.Cell; +import com.evrencoskun.tableview.modell.Cell; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; /** diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index d6aac25d..9216e381 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -26,9 +26,10 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.IRow; -import com.evrencoskun.tableview.Row; -import com.evrencoskun.tableviewsample.tableview.model.Cell; +import com.evrencoskun.tableview.modell.IColumnValue; +import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.modell.Row; +import com.evrencoskun.tableview.modell.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; import com.evrencoskun.tableviewsample.tableview.model.RowHeader; @@ -63,10 +64,15 @@ private List getSimpleRowHeaderList() { private List getRandomColumnHeaderList() { List list = new ArrayList<>(); + // columns = new Object[]{mRandom, mRandomShort, mText, mGenderMale, mMoodHappy}; for (int i = 0; i < COLUMN_SIZE; i++) { String title = "column " + i; int nRandom = new Random().nextInt(); - if (nRandom % 4 == 0 || nRandom % 3 == 0 || nRandom == i) { + if (i == TableViewAdapter.COLUMN_INDEX_GENDER_MALE) { + title = "Gender " + i; + } else if (i == TableViewAdapter.COLUMN_INDEX_MOOD_HAPPY) { + title = "Mood " + i; + } else if (nRandom % 4 == 0 || nRandom % 3 == 0 || nRandom == i) { title = "large column " + i; } @@ -81,11 +87,15 @@ private List getRandomColumnHeaderList() { */ @NonNull private List>> getCellListForSortingTest() { + IColumnValue[] getter = new IColumnValue[COLUMN_SIZE]; + for (int colId = 0; colId < COLUMN_SIZE; colId++) { + + } List>> list = new ArrayList<>(); for (int rowId = 0; rowId < ROW_SIZE; rowId++) { IRow> cellList = new Row<>(); - Cell cell = new Cell(new MySamplePojo("" + rowId)); for (int colId = 0; colId < COLUMN_SIZE; colId++) { + Cell cell = new Cell(new MySamplePojo("" + rowId), null); cellList.add(cell); } list.add(cellList); diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java index 6c145379..cda1f732 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java @@ -33,7 +33,7 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.model.Cell; +import com.evrencoskun.tableview.modell.Cell; /** * Created by evrencoskun on 23/10/2017. diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java index 5a6ba9a2..03f453aa 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java @@ -37,17 +37,14 @@ * An example Pojo that is displayed in demo app-s tableview. */ public class MySamplePojo implements ISortableModel { - // Columns indexes - public static final int COLUMN_INDEX_MOOD_HAPPY = 3; - public static final int COLUMN_INDEX_GENDER_MALE = 4; - private final Integer mRandom; - private final Integer mRandomShort; + public final Integer mRandom; + public final Integer mRandomShort; private final Object[] columns; @NonNull private final String mId; @Nullable - private final String mText; + public final String mText; public final boolean mGenderMale; public final boolean mMoodHappy; diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java index 3319b94f..3e9481a7 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java @@ -25,8 +25,8 @@ package com.evrencoskun.tableviewsample.tableview.model; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; +import com.evrencoskun.tableview.modell.Cell; import com.evrencoskun.tableview.sort.ISortableModel; /** @@ -35,6 +35,6 @@ public class RowHeader extends Cell { public RowHeader(@NonNull C data) { - super(data); + super(data, null); } } diff --git a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java index d570ea13..ed17228d 100644 --- a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java +++ b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java @@ -24,8 +24,8 @@ package com.evrencoskun.tableview.test.data; -import com.evrencoskun.tableview.IRow; -import com.evrencoskun.tableview.Row; +import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.modell.Row; import com.evrencoskun.tableview.test.models.Cell; import com.evrencoskun.tableview.test.models.ColumnHeader; import com.evrencoskun.tableview.test.models.RowHeader; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java index 1f6f93fa..01bd6597 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java @@ -33,7 +33,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java index 5b73c84e..b577c775 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java index c60c96a6..4595f3cc 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java @@ -30,7 +30,7 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; -import com.evrencoskun.tableview.Row; +import com.evrencoskun.tableview.modell.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java index c8b12e21..a1ea384f 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java @@ -32,9 +32,9 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import com.evrencoskun.tableview.ITableView; -import com.evrencoskun.tableview.Row; +import com.evrencoskun.tableview.modell.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder.SelectionState; import com.evrencoskun.tableview.handler.ScrollHandler; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java index 17e4622a..d7db0e93 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java index 6910d752..faf59939 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java @@ -28,7 +28,7 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.DiffUtil; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java index 2741592d..a6e6d12a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java @@ -26,9 +26,9 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import com.evrencoskun.tableview.ITableView; -import com.evrencoskun.tableview.Row; +import com.evrencoskun.tableview.modell.Row; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.RowHeaderRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java index 34fa449b..6733bba9 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java @@ -30,7 +30,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AbstractTableAdapter; import java.util.List; diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java b/tableview/src/main/java/com/evrencoskun/tableview/modell/Cell.java similarity index 86% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java rename to tableview/src/main/java/com/evrencoskun/tableview/modell/Cell.java index 2f729b70..88ad6abb 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/Cell.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/modell/Cell.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewsample.tableview.model; +package com.evrencoskun.tableview.modell; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -34,15 +34,17 @@ * Created by evrencoskun on 11/06/2017. */ -public class Cell implements ISortableModel, IFilterableModel { +public class Cell implements ISortableModel, IFilterableModel { @Nullable - private final C mData; + private final T mData; @NonNull private final String mFilterKeyword; + private final IColumnValue columnValueProvider; - public Cell(@NonNull C data) { + public Cell(@NonNull T data, IColumnValue columnValueProvider) { this.mData = data; this.mFilterKeyword = String.valueOf(data); + this.columnValueProvider = columnValueProvider; } /** @@ -66,7 +68,7 @@ public Object getContent(int column) { } @Nullable - public C getData() { + public T getData() { return mData; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/modell/IColumnValue.java b/tableview/src/main/java/com/evrencoskun/tableview/modell/IColumnValue.java new file mode 100644 index 00000000..2d62d350 --- /dev/null +++ b/tableview/src/main/java/com/evrencoskun/tableview/modell/IColumnValue.java @@ -0,0 +1,5 @@ +package com.evrencoskun.tableview.modell; + +public interface IColumnValue { + Object get(T row); +} diff --git a/tableview/src/main/java/com/evrencoskun/tableview/IRow.java b/tableview/src/main/java/com/evrencoskun/tableview/modell/IRow.java similarity index 97% rename from tableview/src/main/java/com/evrencoskun/tableview/IRow.java rename to tableview/src/main/java/com/evrencoskun/tableview/modell/IRow.java index 10e339fb..a0f707f4 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/IRow.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/modell/IRow.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableview; +package com.evrencoskun.tableview.modell; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/Row.java b/tableview/src/main/java/com/evrencoskun/tableview/modell/Row.java similarity index 96% rename from tableview/src/main/java/com/evrencoskun/tableview/Row.java rename to tableview/src/main/java/com/evrencoskun/tableview/modell/Row.java index 2b61e6c9..9dbf9b34 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/Row.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/modell/Row.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableview; +package com.evrencoskun.tableview.modell; import java.util.ArrayList; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java index 14bd79d5..6edc7b6a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java @@ -27,7 +27,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java index b33147aa..3b917e89 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import java.util.Comparator; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java index f2cda868..524527d5 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java @@ -28,7 +28,7 @@ import androidx.core.util.ObjectsCompat; import androidx.recyclerview.widget.DiffUtil; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java index 3dbf800e..aeaae136 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.IRow; +import com.evrencoskun.tableview.modell.IRow; import java.util.Comparator; import java.util.List; From 1abb02080996f59e617cfdb23c37bde7c261297a Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:58:37 +0100 Subject: [PATCH 21/35] renamed modell to model; moved com.evrencoskun.tableviewsample.holder to com.evrencoskun.tableviewutil.holder --- .../tableviewsample/tableview/TableViewAdapter.java | 4 ++-- .../tableview/TableViewAdapterBase.java | 8 ++++---- .../tableviewsample/tableview/TableViewModel.java | 10 +++++----- changelog.md | 2 +- .../evrencoskun/tableview/test/data/SimpleData.java | 4 ++-- .../tableview/adapter/AbstractTableAdapter.java | 2 +- .../adapter/AdapterDataSetChangedListener.java | 2 +- .../recyclerview/AbstractRecyclerViewAdapter.java | 2 +- .../adapter/recyclerview/CellRecyclerViewAdapter.java | 4 ++-- .../tableview/filter/FilterChangedListener.java | 2 +- .../tableview/handler/ColumnSortHandler.java | 2 +- .../evrencoskun/tableview/handler/FilterHandler.java | 4 ++-- .../tableview/handler/VisibilityHandler.java | 2 +- .../evrencoskun/tableview/{modell => model}/Cell.java | 2 +- .../tableview/{modell => model}/IColumnValue.java | 2 +- .../evrencoskun/tableview/{modell => model}/IRow.java | 2 +- .../evrencoskun/tableview/{modell => model}/Row.java | 2 +- .../com/evrencoskun}/tableview/model/RowHeader.java | 3 +-- .../evrencoskun/tableview/pagination/Pagination.java | 2 +- .../sort/ColumnForRowHeaderSortComparator.java | 2 +- .../evrencoskun/tableview/sort/ColumnSortCallback.java | 2 +- .../tableview/sort/RowHeaderForCellSortComparator.java | 2 +- tableviewutil/build.gradle | 1 + tableviewutil/src/main/AndroidManifest.xml | 2 +- .../holder/BoolDrawableCellViewHolder.java | 4 ++-- .../holder/GenericTextCellViewHolder.java | 6 +++--- .../tableviewutil}/holder/RowHeaderViewHolder.java | 4 ++-- 27 files changed, 42 insertions(+), 42 deletions(-) rename tableview/src/main/java/com/evrencoskun/tableview/{modell => model}/Cell.java (98%) rename tableview/src/main/java/com/evrencoskun/tableview/{modell => model}/IColumnValue.java (59%) rename tableview/src/main/java/com/evrencoskun/tableview/{modell => model}/IRow.java (97%) rename tableview/src/main/java/com/evrencoskun/tableview/{modell => model}/Row.java (96%) rename {app/src/main/java/com/evrencoskun/tableviewsample => tableview/src/main/java/com/evrencoskun}/tableview/model/RowHeader.java (93%) rename {app/src/main/java/com/evrencoskun/tableviewsample/tableview => tableviewutil/src/main/java/com/evrencoskun/tableviewutil}/holder/BoolDrawableCellViewHolder.java (95%) rename {app/src/main/java/com/evrencoskun/tableviewsample/tableview => tableviewutil/src/main/java/com/evrencoskun/tableviewutil}/holder/GenericTextCellViewHolder.java (94%) rename {app/src/main/java/com/evrencoskun/tableviewsample/tableview => tableviewutil/src/main/java/com/evrencoskun/tableviewutil}/holder/RowHeaderViewHolder.java (94%) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index c3636ec2..2552d992 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -34,8 +34,8 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.holder.BoolDrawableCellViewHolder; -import com.evrencoskun.tableview.modell.Cell; +import com.evrencoskun.tableviewutil.holder.BoolDrawableCellViewHolder; +import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; /** diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java index abcd925a..487af2ea 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java @@ -38,10 +38,10 @@ import com.evrencoskun.tableview.sort.SortState; import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; -import com.evrencoskun.tableviewsample.tableview.holder.GenericTextCellViewHolder; -import com.evrencoskun.tableviewsample.tableview.holder.RowHeaderViewHolder; -import com.evrencoskun.tableview.modell.Cell; -import com.evrencoskun.tableviewsample.tableview.model.RowHeader; +import com.evrencoskun.tableviewutil.holder.GenericTextCellViewHolder; +import com.evrencoskun.tableviewutil.holder.RowHeaderViewHolder; +import com.evrencoskun.tableview.model.Cell; +import com.evrencoskun.tableview.model.RowHeader; /** * Generic adapter that translates a Pojo to TableView-Cells. diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 9216e381..9671780a 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -26,12 +26,12 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.modell.IColumnValue; -import com.evrencoskun.tableview.modell.IRow; -import com.evrencoskun.tableview.modell.Row; -import com.evrencoskun.tableview.modell.Cell; +import com.evrencoskun.tableview.model.IColumnValue; +import com.evrencoskun.tableview.model.IRow; +import com.evrencoskun.tableview.model.Row; +import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; -import com.evrencoskun.tableviewsample.tableview.model.RowHeader; +import com.evrencoskun.tableview.model.RowHeader; import java.util.ArrayList; import java.util.List; diff --git a/changelog.md b/changelog.md index 582506e3..6d15fde8 100644 --- a/changelog.md +++ b/changelog.md @@ -8,7 +8,7 @@ requires a lot of copy&paste from example code to use the TableView in a clienta Product vision: reduce the amount of (copied) code to integrate TableView into a clientapp. -* v done: replaced the table header modell with simple Strings. +* v done: replaced the table header model with simple Strings. * v done: replaced the must-customize Cell.java with a templated Cell where customisation takes place in the pojo * v done: keep demo app intact using MySamplePojo * v done: customized TableViewAdapter inherits from new generic TableViewAdapterBase diff --git a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java index ed17228d..4e8ed827 100644 --- a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java +++ b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java @@ -24,8 +24,8 @@ package com.evrencoskun.tableview.test.data; -import com.evrencoskun.tableview.modell.IRow; -import com.evrencoskun.tableview.modell.Row; +import com.evrencoskun.tableview.model.IRow; +import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.test.models.Cell; import com.evrencoskun.tableview.test.models.ColumnHeader; import com.evrencoskun.tableview.test.models.RowHeader; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java index 01bd6597..b57df7a1 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java @@ -33,7 +33,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java index b577c775..80b4c59e 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java index 4595f3cc..b402351d 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java @@ -30,7 +30,7 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; -import com.evrencoskun.tableview.modell.Row; +import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java index a1ea384f..30ab972d 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java @@ -32,9 +32,9 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; -import com.evrencoskun.tableview.modell.Row; +import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder.SelectionState; import com.evrencoskun.tableview.handler.ScrollHandler; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java index d7db0e93..2c3eec78 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java index faf59939..309446bf 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java @@ -28,7 +28,7 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.DiffUtil; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java index a6e6d12a..bba8a122 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java @@ -26,9 +26,9 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; -import com.evrencoskun.tableview.modell.Row; +import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.RowHeaderRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java index 6733bba9..a7e21c3d 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java @@ -30,7 +30,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AbstractTableAdapter; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/modell/Cell.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java similarity index 98% rename from tableview/src/main/java/com/evrencoskun/tableview/modell/Cell.java rename to tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java index 88ad6abb..ab6b9d3c 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/modell/Cell.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableview.modell; +package com.evrencoskun.tableview.model; import androidx.annotation.NonNull; import androidx.annotation.Nullable; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/modell/IColumnValue.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValue.java similarity index 59% rename from tableview/src/main/java/com/evrencoskun/tableview/modell/IColumnValue.java rename to tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValue.java index 2d62d350..b26952c8 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/modell/IColumnValue.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValue.java @@ -1,4 +1,4 @@ -package com.evrencoskun.tableview.modell; +package com.evrencoskun.tableview.model; public interface IColumnValue { Object get(T row); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/modell/IRow.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java similarity index 97% rename from tableview/src/main/java/com/evrencoskun/tableview/modell/IRow.java rename to tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java index a0f707f4..c7a1c92f 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/modell/IRow.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableview.modell; +package com.evrencoskun.tableview.model; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/modell/Row.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java similarity index 96% rename from tableview/src/main/java/com/evrencoskun/tableview/modell/Row.java rename to tableview/src/main/java/com/evrencoskun/tableview/model/Row.java index 9dbf9b34..0644fb5b 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/modell/Row.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableview.modell; +package com.evrencoskun.tableview.model; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java b/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java similarity index 93% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java rename to tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java index 3e9481a7..4d265264 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/RowHeader.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java @@ -22,11 +22,10 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewsample.tableview.model; +package com.evrencoskun.tableview.model; import androidx.annotation.NonNull; -import com.evrencoskun.tableview.modell.Cell; import com.evrencoskun.tableview.sort.ISortableModel; /** diff --git a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java index 6edc7b6a..3ff56e95 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java @@ -27,7 +27,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java index 3b917e89..97e3210a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import java.util.Comparator; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java index 524527d5..644118e0 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java @@ -28,7 +28,7 @@ import androidx.core.util.ObjectsCompat; import androidx.recyclerview.widget.DiffUtil; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import java.util.List; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java index aeaae136..35ab2745 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java @@ -26,7 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.modell.IRow; +import com.evrencoskun.tableview.model.IRow; import java.util.Comparator; import java.util.List; diff --git a/tableviewutil/build.gradle b/tableviewutil/build.gradle index acdb3db8..b4c8da4a 100644 --- a/tableviewutil/build.gradle +++ b/tableviewutil/build.gradle @@ -30,6 +30,7 @@ dependencies { implementation project(path: ':tableview') implementation "androidx.appcompat:appcompat:$androidx_appcompat_version" + implementation "androidx.recyclerview:recyclerview:$androidx_recyclerview_version" testImplementation "junit:junit:$junit_version" androidTestImplementation "androidx.test.ext:junit:$androidx_test_ext_version" androidTestImplementation "androidx.test:rules:$androidx_test_version" diff --git a/tableviewutil/src/main/AndroidManifest.xml b/tableviewutil/src/main/AndroidManifest.xml index a5918e68..1cf554fa 100644 --- a/tableviewutil/src/main/AndroidManifest.xml +++ b/tableviewutil/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/BoolDrawableCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java similarity index 95% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/BoolDrawableCellViewHolder.java rename to tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java index f8db3363..ce4a8d40 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/BoolDrawableCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewsample.tableview.holder; +package com.evrencoskun.tableviewutil.holder; import android.view.View; import android.widget.ImageView; @@ -31,7 +31,7 @@ import androidx.annotation.NonNull; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import com.evrencoskun.tableviewsample.R; +import com.evrencoskun.tableviewutil.R; /** * Created by evrencoskun on 4.02.2018. diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java similarity index 94% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java rename to tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java index cda1f732..9c691648 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/GenericTextCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewsample.tableview.holder; +package com.evrencoskun.tableviewutil.holder; import android.view.View; import android.widget.LinearLayout; @@ -32,8 +32,8 @@ import androidx.annotation.Nullable; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableview.modell.Cell; +import com.evrencoskun.tableview.model.Cell; +import com.evrencoskun.tableviewutil.R; /** * Created by evrencoskun on 23/10/2017. diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/RowHeaderViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/RowHeaderViewHolder.java similarity index 94% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/RowHeaderViewHolder.java rename to tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/RowHeaderViewHolder.java index ce74dad9..7adae523 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/RowHeaderViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/RowHeaderViewHolder.java @@ -22,15 +22,15 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewsample.tableview.holder; +package com.evrencoskun.tableviewutil.holder; import android.view.View; import android.widget.TextView; import androidx.annotation.NonNull; +import com.evrencoskun.tableviewutil.R; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import com.evrencoskun.tableviewsample.R; /** * Created by evrencoskun on 23/10/2017. From 0ae521be3975d900f367528a0efddfbe85a2e80d Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:28:20 +0100 Subject: [PATCH 22/35] moved TableViewAdapterBase + holder.ColumnHeaderViewHolder from com.evrencoskun.tableviewsample to com.evrencoskun.tableviewutil --- .../tableview/TableViewAdapter.java | 8 +++++++- .../tableview/TableViewListener.java | 2 +- .../popup/ColumnHeaderLongPressPopup.java | 2 +- .../tableviewutil}/TableViewAdapterBase.java | 14 ++++---------- .../holder/ColumnHeaderViewHolder.java | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) rename {app/src/main/java/com/evrencoskun/tableviewsample/tableview => tableviewutil/src/main/java/com/evrencoskun/tableviewutil}/TableViewAdapterBase.java (95%) rename {app/src/main/java/com/evrencoskun/tableviewsample/tableview => tableviewutil/src/main/java/com/evrencoskun/tableviewutil}/holder/ColumnHeaderViewHolder.java (98%) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index 2552d992..338f539e 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -34,6 +34,8 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewsample.R; +import com.evrencoskun.tableviewutil.TableViewAdapterBase; +import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewutil.holder.BoolDrawableCellViewHolder; import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; @@ -46,6 +48,7 @@ */ public class TableViewAdapter extends TableViewAdapterBase { + private static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); // Columns indexes public static final int COLUMN_INDEX_MOOD_HAPPY = 3; @@ -55,8 +58,11 @@ public class TableViewAdapter extends TableViewAdapterBase { private static final int GENDER_CELL_TYPE = 2; // add new one if it necessary.. + @NonNull + protected final TableViewModel mTableViewModel; + public TableViewAdapter(@NonNull TableViewModel tableViewModel) { - super(tableViewModel); + mTableViewModel = tableViewModel; } /** diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java index 242bf0ae..a259475c 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java @@ -32,7 +32,7 @@ import com.evrencoskun.tableview.TableView; import com.evrencoskun.tableview.listener.ITableViewListener; -import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; +import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.popup.ColumnHeaderLongPressPopup; import com.evrencoskun.tableviewsample.tableview.popup.RowHeaderLongPressPopup; diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java index 0ae49dd7..64cf54c4 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java @@ -34,7 +34,7 @@ import com.evrencoskun.tableview.TableView; import com.evrencoskun.tableview.sort.SortState; import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; +import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; /** * Created by evrencoskun on 24.12.2017. diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java similarity index 95% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java rename to tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java index 487af2ea..75e52dd2 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapterBase.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewsample.tableview; +package com.evrencoskun.tableviewutil; import android.util.Log; import android.view.LayoutInflater; @@ -36,8 +36,8 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.sort.ISortableModel; import com.evrencoskun.tableview.sort.SortState; -import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewsample.tableview.holder.ColumnHeaderViewHolder; +import com.evrencoskun.tableviewutil.R; +import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewutil.holder.GenericTextCellViewHolder; import com.evrencoskun.tableviewutil.holder.RowHeaderViewHolder; import com.evrencoskun.tableview.model.Cell; @@ -49,13 +49,7 @@ * Defaultimplementation translates all columns to TextView fields. */ public abstract class TableViewAdapterBase extends AbstractTableAdapter> { - protected static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); - @NonNull - protected final TableViewModel mTableViewModel; - - public TableViewAdapterBase(TableViewModel tableViewModel) { - this.mTableViewModel = tableViewModel; - } + private static final String LOG_TAG = TableViewAdapterBase.class.getSimpleName(); /** * This is where you create your custom Column Header ViewHolder. This method is called when diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/ColumnHeaderViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java similarity index 98% rename from app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/ColumnHeaderViewHolder.java rename to tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java index 8383eccb..2db80cf6 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/holder/ColumnHeaderViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewsample.tableview.holder; +package com.evrencoskun.tableviewutil.holder; import android.util.Log; import android.view.View; @@ -36,7 +36,7 @@ import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder; import com.evrencoskun.tableview.sort.SortState; -import com.evrencoskun.tableviewsample.R; +import com.evrencoskun.tableviewutil.R; /** * Created by evrencoskun on 23/10/2017. From 20462f0bb76072871a1b6f53435498962c8be5ed Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 8 Mar 2023 16:55:20 +0100 Subject: [PATCH 23/35] introduced ColumnDefinition --- .../tableviewsample/MainFragment.java | 4 +- .../tableview/TableViewAdapter.java | 8 +--- .../tableview/TableViewModel.java | 40 +++++++++++------ .../com/evrencoskun/tableview/model/Cell.java | 18 ++++---- .../tableview/model/IColumnValue.java | 5 --- .../tableview/model/IColumnValueProvider.java | 32 +++++++++++++ .../tableviewutil/ColumnDefinition.java | 45 +++++++++++++++++++ .../tableviewutil/TableViewAdapterBase.java | 1 - 8 files changed, 118 insertions(+), 35 deletions(-) delete mode 100644 tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValue.java create mode 100644 tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java create mode 100644 tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java index 014eef18..40c7a224 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java @@ -161,7 +161,7 @@ public void filterTableForMood(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the mood column. if (mTableFilter != null) { - mTableFilter.set(TableViewAdapter.COLUMN_INDEX_MOOD_HAPPY, filter); + mTableFilter.set(TableViewModel.COLUMN_INDEX_MOOD_HAPPY, filter); } } @@ -169,7 +169,7 @@ public void filterTableForGender(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the gender column. if (mTableFilter != null) { - mTableFilter.set(TableViewAdapter.COLUMN_INDEX_GENDER_MALE, filter); + mTableFilter.set(TableViewModel.COLUMN_INDEX_GENDER_MALE, filter); } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index 338f539e..fda81b97 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -35,7 +35,6 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewutil.TableViewAdapterBase; -import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewutil.holder.BoolDrawableCellViewHolder; import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; @@ -50,9 +49,6 @@ public class TableViewAdapter extends TableViewAdapterBase { private static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); - // Columns indexes - public static final int COLUMN_INDEX_MOOD_HAPPY = 3; - public static final int COLUMN_INDEX_GENDER_MALE = 4; // Cell View Types by Column Position private static final int MOOD_CELL_TYPE = 1; private static final int GENDER_CELL_TYPE = 2; @@ -140,9 +136,9 @@ public int getCellItemViewType(int column) { // then you should fill this method to be able create different // type of GenericTextCellViewHolder on "onCreateCellViewHolder" switch (column) { - case COLUMN_INDEX_MOOD_HAPPY: + case TableViewModel.COLUMN_INDEX_MOOD_HAPPY: return MOOD_CELL_TYPE; - case COLUMN_INDEX_GENDER_MALE: + case TableViewModel.COLUMN_INDEX_GENDER_MALE: return GENDER_CELL_TYPE; default: // Default view type diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java index 9671780a..dcf1f952 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java @@ -26,14 +26,16 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.model.IColumnValue; +import com.evrencoskun.tableview.model.IColumnValueProvider; import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; import com.evrencoskun.tableview.model.RowHeader; +import com.evrencoskun.tableviewutil.ColumnDefinition; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Random; @@ -42,6 +44,9 @@ */ public class TableViewModel { + // Columns indexes + public static final int COLUMN_INDEX_MOOD_HAPPY = 3; + public static final int COLUMN_INDEX_GENDER_MALE = 4; // Constant size for dummy data sets private static final int COLUMN_SIZE = 500; private static final int ROW_SIZE = 500; @@ -57,6 +62,15 @@ private List getSimpleRowHeaderList() { return list; } + private static final IColumnValueProvider TEXT_VALUE_PROVIDER = r -> r.mText; + private static final List> COLUMN_DEFINITIONS = + Arrays.asList( + new ColumnDefinition<>("Random 0", r -> r.mRandom), + new ColumnDefinition<>("Short 1", r -> r.mRandomShort), + new ColumnDefinition<>("Text 2", TEXT_VALUE_PROVIDER), + new ColumnDefinition<>("Gender 3", r -> r.mGenderMale), + new ColumnDefinition<>("Mood 4", r -> r.mMoodHappy)); + /** * This is a dummy model list test some cases. */ @@ -64,15 +78,14 @@ private List getSimpleRowHeaderList() { private List getRandomColumnHeaderList() { List list = new ArrayList<>(); - // columns = new Object[]{mRandom, mRandomShort, mText, mGenderMale, mMoodHappy}; - for (int i = 0; i < COLUMN_SIZE; i++) { + for (ColumnDefinition c : COLUMN_DEFINITIONS) { + list.add(c.getHeader()); + } + + for (int i = COLUMN_DEFINITIONS.size(); i < COLUMN_SIZE; i++) { String title = "column " + i; int nRandom = new Random().nextInt(); - if (i == TableViewAdapter.COLUMN_INDEX_GENDER_MALE) { - title = "Gender " + i; - } else if (i == TableViewAdapter.COLUMN_INDEX_MOOD_HAPPY) { - title = "Mood " + i; - } else if (nRandom % 4 == 0 || nRandom % 3 == 0 || nRandom == i) { + if (nRandom % 4 == 0 || nRandom % 3 == 0 || nRandom == i) { title = "large column " + i; } @@ -87,15 +100,16 @@ private List getRandomColumnHeaderList() { */ @NonNull private List>> getCellListForSortingTest() { - IColumnValue[] getter = new IColumnValue[COLUMN_SIZE]; - for (int colId = 0; colId < COLUMN_SIZE; colId++) { - - } List>> list = new ArrayList<>(); for (int rowId = 0; rowId < ROW_SIZE; rowId++) { IRow> cellList = new Row<>(); for (int colId = 0; colId < COLUMN_SIZE; colId++) { - Cell cell = new Cell(new MySamplePojo("" + rowId), null); + IColumnValueProvider provider = + colId < COLUMN_DEFINITIONS.size() + ? COLUMN_DEFINITIONS.get(colId).getValueProvider() + : TEXT_VALUE_PROVIDER; + + Cell cell = new Cell(new MySamplePojo("" + rowId), provider); cellList.add(cell); } list.add(cellList); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java index ab6b9d3c..fdfce9c6 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java @@ -35,15 +35,17 @@ */ public class Cell implements ISortableModel, IFilterableModel { - @Nullable - private final T mData; @NonNull - private final String mFilterKeyword; - private final IColumnValue columnValueProvider; + private final T mData; + private final IColumnValueProvider columnValueProvider; - public Cell(@NonNull T data, IColumnValue columnValueProvider) { + /** + * + * @param data the row where the cell data belongs to. + * @param columnValueProvider that gets the cell value out of the data-row + */ + public Cell(@NonNull T data, IColumnValueProvider columnValueProvider) { this.mData = data; - this.mFilterKeyword = String.valueOf(data); this.columnValueProvider = columnValueProvider; } @@ -64,7 +66,7 @@ public String getId() { @Nullable @Override public Object getContent(int column) { - return mData.getContent(column); + return columnValueProvider.get(mData); } @Nullable @@ -78,6 +80,6 @@ public T getData() { @NonNull @Override public String getFilterableKeyword() { - return mFilterKeyword; + return getContent(0).toString(); } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValue.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValue.java deleted file mode 100644 index b26952c8..00000000 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValue.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.evrencoskun.tableview.model; - -public interface IColumnValue { - Object get(T row); -} diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java new file mode 100644 index 00000000..d3908d7c --- /dev/null +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java @@ -0,0 +1,32 @@ +/* + * MIT License + * + * Copyright (c) 2023 K3b + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableview.model; + +/** + * Provides a column value object + */ +public interface IColumnValueProvider { + Object get(T row); +} diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java new file mode 100644 index 00000000..0398f1ca --- /dev/null +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) 2023 K3b + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableviewutil; + +import com.evrencoskun.tableview.model.IColumnValueProvider; + +public class ColumnDefinition { + private final String header; + private final IColumnValueProvider valueProvider; + + public ColumnDefinition(String header, IColumnValueProvider valueProvider) { + this.header = header; + this.valueProvider = valueProvider; + } + + public String getHeader() { + return header; + } + + public IColumnValueProvider getValueProvider() { + return valueProvider; + } +} diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java index 75e52dd2..50d834a1 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java @@ -143,7 +143,6 @@ public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable C viewHolder.setCell(cellItemModel, columnPosition, rowPosition); } - /** * This is where you create your custom Row Header ViewHolder. This method is called when * Row Header RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given From a7fb62f0329a792a49c83755992e25d5ceebe47a Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:27:30 +0100 Subject: [PATCH 24/35] POJO must only implement IModelWithId --- .../tableview/model/MySamplePojo.java | 22 ++---------- .../com/evrencoskun/tableview/model/Cell.java | 8 ++--- .../tableview/model/IModelWithId.java | 35 +++++++++++++++++++ .../tableview/model/RowHeader.java | 11 +++--- .../tableview/sort/ISortableModel.java | 9 ++--- .../tableviewutil/TableViewAdapterBase.java | 9 +++-- 6 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java index 03f453aa..9db419e3 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java @@ -29,6 +29,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.evrencoskun.tableview.model.IModelWithId; import com.evrencoskun.tableview.sort.ISortableModel; import java.util.Random; @@ -36,14 +37,13 @@ /** * An example Pojo that is displayed in demo app-s tableview. */ -public class MySamplePojo implements ISortableModel { +public class MySamplePojo implements IModelWithId { public final Integer mRandom; public final Integer mRandomShort; - private final Object[] columns; @NonNull private final String mId; - @Nullable + @NonNull public final String mText; public final boolean mGenderMale; public final boolean mMoodHappy; @@ -59,9 +59,6 @@ public MySamplePojo(@NonNull String id) { mMoodHappy = new Random().nextBoolean(); mRandom = abs(new Random().nextInt()); mRandomShort = mRandom % 100; - - // the first colums of the table - columns = new Object[]{mRandom, mRandomShort, mText, mGenderMale, mMoodHappy}; } /** @@ -73,17 +70,4 @@ public MySamplePojo(@NonNull String id) { public String getId() { return mId; } - - /** - * This is necessary for sorting process. - * See {@link ISortableModel}. - */ - @Nullable - @Override - public Object getContent(int column) { - if (column >= 0 && column < columns.length) { - return columns[column]; - } - return "cell " + mId + " " + column; - } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java index fdfce9c6..f30b8ce3 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java @@ -34,9 +34,9 @@ * Created by evrencoskun on 11/06/2017. */ -public class Cell implements ISortableModel, IFilterableModel { +public class Cell implements ISortableModel, IFilterableModel { @NonNull - private final T mData; + private final POJO mData; private final IColumnValueProvider columnValueProvider; /** @@ -44,7 +44,7 @@ public class Cell implements ISortableModel, IFilterab * @param data the row where the cell data belongs to. * @param columnValueProvider that gets the cell value out of the data-row */ - public Cell(@NonNull T data, IColumnValueProvider columnValueProvider) { + public Cell(@NonNull POJO data, IColumnValueProvider columnValueProvider) { this.mData = data; this.columnValueProvider = columnValueProvider; } @@ -70,7 +70,7 @@ public Object getContent(int column) { } @Nullable - public T getData() { + public POJO getData() { return mData; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java new file mode 100644 index 00000000..b2bedbd8 --- /dev/null +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2021 Evren Coşkun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableview.model; + +import androidx.annotation.NonNull; + +public interface IModelWithId { + /** + * to make sorting work, Id must be unique per data row. + */ + @NonNull + String getId(); +} diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java b/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java index 4d265264..762b9eab 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java @@ -26,14 +26,17 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.sort.ISortableModel; - /** * Created by evrencoskun on 11/06/2017. */ -public class RowHeader extends Cell { - public RowHeader(@NonNull C data) { +public class RowHeader extends Cell { + public RowHeader(@NonNull POJO data) { super(data, null); } + + @Override + public Object getContent(int column) { + return getId(); + } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java index 15bf185a..143ad367 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java @@ -27,16 +27,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.evrencoskun.tableview.model.IModelWithId; + /** * Created by evrencoskun on 24.11.2017. */ -public interface ISortableModel { - /** - * to make sorting work, Id must be unique per data row. - */ - @NonNull - String getId(); +public interface ISortableModel extends IModelWithId { @Nullable Object getContent(int column); diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java index 50d834a1..57ef2a43 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java @@ -34,9 +34,8 @@ import com.evrencoskun.tableview.adapter.AbstractTableAdapter; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import com.evrencoskun.tableview.sort.ISortableModel; +import com.evrencoskun.tableview.model.IModelWithId; import com.evrencoskun.tableview.sort.SortState; -import com.evrencoskun.tableviewutil.R; import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewutil.holder.GenericTextCellViewHolder; import com.evrencoskun.tableviewutil.holder.RowHeaderViewHolder; @@ -44,11 +43,11 @@ import com.evrencoskun.tableview.model.RowHeader; /** - * Generic adapter that translates a Pojo to TableView-Cells. + * Generic adapter that translates a POJO to TableView-Cells. * * Defaultimplementation translates all columns to TextView fields. */ -public abstract class TableViewAdapterBase extends AbstractTableAdapter> { +public abstract class TableViewAdapterBase extends AbstractTableAdapter> { private static final String LOG_TAG = TableViewAdapterBase.class.getSimpleName(); /** @@ -135,7 +134,7 @@ public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int * @see #onCreateCellViewHolder(ViewGroup, int) ; */ @Override - public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int + public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int columnPosition, int rowPosition) { // Get the holder to update cell item text From aaa11ab9d119784ef6ed740f4cdaec6ddfbb365b Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:34:43 +0100 Subject: [PATCH 25/35] removed column-Index : getContent(int column) -> getContent() --- .../java/com/evrencoskun/tableview/test/models/Cell.java | 2 +- .../src/main/java/com/evrencoskun/tableview/model/Cell.java | 4 ++-- .../main/java/com/evrencoskun/tableview/model/RowHeader.java | 2 +- .../tableview/sort/ColumnForRowHeaderSortComparator.java | 4 ++-- .../com/evrencoskun/tableview/sort/ColumnSortCallback.java | 4 ++-- .../com/evrencoskun/tableview/sort/ColumnSortComparator.java | 4 ++-- .../java/com/evrencoskun/tableview/sort/ISortableModel.java | 3 +-- .../tableview/sort/RowHeaderForCellSortComparator.java | 4 ++-- .../com/evrencoskun/tableview/sort/RowHeaderSortCallback.java | 4 ++-- .../evrencoskun/tableview/sort/RowHeaderSortComparator.java | 4 ++-- .../tableviewutil/holder/GenericTextCellViewHolder.java | 2 +- 11 files changed, 18 insertions(+), 19 deletions(-) diff --git a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java index 12d55988..6b41602f 100644 --- a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java +++ b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/models/Cell.java @@ -60,7 +60,7 @@ public String getId() { */ @Nullable @Override - public Object getContent(int column) { + public Object getContent() { return mData; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java index f30b8ce3..1eec584b 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java @@ -65,7 +65,7 @@ public String getId() { */ @Nullable @Override - public Object getContent(int column) { + public Object getContent() { return columnValueProvider.get(mData); } @@ -80,6 +80,6 @@ public POJO getData() { @NonNull @Override public String getFilterableKeyword() { - return getContent(0).toString(); + return getContent().toString(); } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java b/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java index 762b9eab..91a1988b 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/RowHeader.java @@ -36,7 +36,7 @@ public RowHeader(@NonNull POJO data) { } @Override - public Object getContent(int column) { + public Object getContent() { return getId(); } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java index 97e3210a..7744dc9f 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java @@ -63,8 +63,8 @@ public ColumnForRowHeaderSortComparator(@NonNull List rowHeader, @Override public int compare(ISortableModel o, ISortableModel t1) { - Object o1 = mReferenceList.get(this.mRowHeaderList.indexOf(o)).get(column).getContent(column); - Object o2 = mReferenceList.get(this.mRowHeaderList.indexOf(t1)).get(column).getContent(column); + Object o1 = mReferenceList.get(this.mRowHeaderList.indexOf(o)).get(column).getContent(); + Object o2 = mReferenceList.get(this.mRowHeaderList.indexOf(t1)).get(column).getContent(); if (mSortState == SortState.DESCENDING) { return mColumnSortComparator.compareContent(o2, o1); } else { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java index 644118e0..7ee02d35 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java @@ -83,9 +83,9 @@ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { (newItemPosition).size() > mColumnPosition) { // Compare contents Object oldContent = mOldCellItems.get(oldItemPosition).get(mColumnPosition) - .getContent(mColumnPosition); + .getContent(); Object newContent = mNewCellItems.get(newItemPosition).get(mColumnPosition) - .getContent(mColumnPosition); + .getContent(); return ObjectsCompat.equals(oldContent, newContent); } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java index 323db564..8fa7add8 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortComparator.java @@ -44,8 +44,8 @@ public ColumnSortComparator(int xPosition, @NonNull SortState sortState) { @Override public int compare(List t1, List t2) { - Object o1 = t1.get(mXPosition).getContent(mXPosition); - Object o2 = t2.get(mXPosition).getContent(mXPosition); + Object o1 = t1.get(mXPosition).getContent(); + Object o2 = t2.get(mXPosition).getContent(); if (mSortState == SortState.DESCENDING) { return compareContent(o2, o1); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java index 143ad367..0c106fbb 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ISortableModel.java @@ -24,7 +24,6 @@ package com.evrencoskun.tableview.sort; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.evrencoskun.tableview.model.IModelWithId; @@ -36,5 +35,5 @@ public interface ISortableModel extends IModelWithId { @Nullable - Object getContent(int column); + Object getContent(); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java index 35ab2745..30aa8884 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java @@ -58,8 +58,8 @@ public RowHeaderForCellSortComparator(@NonNull List referenceLis public int compare(List l1, List l2) { int colL1 = this.mColumnList.indexOf(l1); int colL2 = this.mColumnList.indexOf(l2); - Object o1 = mReferenceList.get(colL1).getContent(colL1); - Object o2 = mReferenceList.get(colL2).getContent(colL2); + Object o1 = mReferenceList.get(colL1).getContent(); + Object o2 = mReferenceList.get(colL2).getContent(); if (mSortState == SortState.DESCENDING) { return mRowHeaderSortComparator.compareContent(o2, o1); } else { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java index 58caca47..b3188ac6 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortCallback.java @@ -73,9 +73,9 @@ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { if (mOldCellItems.size() > oldItemPosition && mNewCellItems.size() > newItemPosition) { // Compare contents Object oldContent = mOldCellItems.get(oldItemPosition) - .getContent(0); + .getContent(); Object newContent = mNewCellItems.get(newItemPosition) - .getContent(0); + .getContent(); return oldContent.equals(newContent); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java index c80563ae..8dc6c7a3 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderSortComparator.java @@ -41,9 +41,9 @@ public RowHeaderSortComparator(@NonNull SortState sortState) { @Override public int compare(ISortableModel o1, ISortableModel o2) { if (mSortState == SortState.DESCENDING) { - return compareContent(o2.getContent(0), o1.getContent(0)); + return compareContent(o2.getContent(), o1.getContent()); } else { - return compareContent(o1.getContent(0), o2.getContent(0)); + return compareContent(o1.getContent(), o2.getContent()); } } } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java index 9c691648..a72eb517 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java @@ -56,7 +56,7 @@ public GenericTextCellViewHolder(@NonNull View itemView) { public void setCell(@Nullable Cell cell, int columnPosition, int rowPosition) { mColumnPosition = columnPosition; mRowPosition = rowPosition; - cell_textview.setText(String.valueOf(cell.getContent(columnPosition))); + cell_textview.setText(String.valueOf(cell.getContent())); // If your TableView should have auto resize for cells & columns. // Then you should consider the below lines. Otherwise, you can ignore them. From 44f5d41d7306d81e94214f6fbc89a890f0d83c6d Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Thu, 9 Mar 2023 08:14:47 +0100 Subject: [PATCH 26/35] Seperated new TestData plus generic tableviewutil.TableViewModel --- .../tableviewsample/MainFragment.java | 15 +- .../tableview/TableViewAdapter.java | 5 +- .../tableview/TableViewModel.java | 135 ------------------ .../tableviewsample/tableview/TestData.java | 77 ++++++++++ .../tableview/model/MySamplePojo.java | 5 +- .../tableviewutil/TableViewModel.java | 90 ++++++++++++ 6 files changed, 185 insertions(+), 142 deletions(-) delete mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java create mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java create mode 100644 tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java index 40c7a224..e4e76176 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java @@ -44,7 +44,12 @@ import com.evrencoskun.tableview.pagination.Pagination; import com.evrencoskun.tableviewsample.tableview.TableViewAdapter; import com.evrencoskun.tableviewsample.tableview.TableViewListener; -import com.evrencoskun.tableviewsample.tableview.TableViewModel; +import com.evrencoskun.tableviewutil.TableViewModel; +import com.evrencoskun.tableviewsample.tableview.TestData; +import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; +import com.evrencoskun.tableviewutil.ColumnDefinition; + +import java.util.List; /** * A simple {@link Fragment} subclass. @@ -118,8 +123,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat } private void initializeTableView() { + List> columnDefinitions = TestData.createColumnDefinitions(); + List pojos = TestData.createSampleData(); // Create TableView View model class to group view models of TableView - TableViewModel tableViewModel = new TableViewModel(); + TableViewModel tableViewModel = new TableViewModel(columnDefinitions, pojos); // Create TableView Adapter TableViewAdapter tableViewAdapter = new TableViewAdapter(tableViewModel); @@ -161,7 +168,7 @@ public void filterTableForMood(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the mood column. if (mTableFilter != null) { - mTableFilter.set(TableViewModel.COLUMN_INDEX_MOOD_HAPPY, filter); + mTableFilter.set(TestData.COLUMN_INDEX_MOOD_HAPPY, filter); } } @@ -169,7 +176,7 @@ public void filterTableForGender(@NonNull String filter) { // Sets a filter to the table, this will only filter a specific column. // In the example data, this will filter the gender column. if (mTableFilter != null) { - mTableFilter.set(TableViewModel.COLUMN_INDEX_GENDER_MALE, filter); + mTableFilter.set(TestData.COLUMN_INDEX_GENDER_MALE, filter); } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java index fda81b97..c70b66f5 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java @@ -35,6 +35,7 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewutil.TableViewAdapterBase; +import com.evrencoskun.tableviewutil.TableViewModel; import com.evrencoskun.tableviewutil.holder.BoolDrawableCellViewHolder; import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; @@ -136,9 +137,9 @@ public int getCellItemViewType(int column) { // then you should fill this method to be able create different // type of GenericTextCellViewHolder on "onCreateCellViewHolder" switch (column) { - case TableViewModel.COLUMN_INDEX_MOOD_HAPPY: + case TestData.COLUMN_INDEX_MOOD_HAPPY: return MOOD_CELL_TYPE; - case TableViewModel.COLUMN_INDEX_GENDER_MALE: + case TestData.COLUMN_INDEX_GENDER_MALE: return GENDER_CELL_TYPE; default: // Default view type diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java deleted file mode 100644 index dcf1f952..00000000 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewModel.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2021 Evren Coşkun - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.evrencoskun.tableviewsample.tableview; - -import androidx.annotation.NonNull; - -import com.evrencoskun.tableview.model.IColumnValueProvider; -import com.evrencoskun.tableview.model.IRow; -import com.evrencoskun.tableview.model.Row; -import com.evrencoskun.tableview.model.Cell; -import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; -import com.evrencoskun.tableview.model.RowHeader; -import com.evrencoskun.tableviewutil.ColumnDefinition; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; - -/** - * Created by evrencoskun on 4.02.2018. - */ - -public class TableViewModel { - // Columns indexes - public static final int COLUMN_INDEX_MOOD_HAPPY = 3; - public static final int COLUMN_INDEX_GENDER_MALE = 4; - // Constant size for dummy data sets - private static final int COLUMN_SIZE = 500; - private static final int ROW_SIZE = 500; - - @NonNull - private List getSimpleRowHeaderList() { - List list = new ArrayList<>(); - for (int i = 0; i < ROW_SIZE; i++) { - RowHeader header = new RowHeader(new MySamplePojo(String.valueOf(i))); - list.add(header); - } - - return list; - } - - private static final IColumnValueProvider TEXT_VALUE_PROVIDER = r -> r.mText; - private static final List> COLUMN_DEFINITIONS = - Arrays.asList( - new ColumnDefinition<>("Random 0", r -> r.mRandom), - new ColumnDefinition<>("Short 1", r -> r.mRandomShort), - new ColumnDefinition<>("Text 2", TEXT_VALUE_PROVIDER), - new ColumnDefinition<>("Gender 3", r -> r.mGenderMale), - new ColumnDefinition<>("Mood 4", r -> r.mMoodHappy)); - - /** - * This is a dummy model list test some cases. - */ - @NonNull - private List getRandomColumnHeaderList() { - List list = new ArrayList<>(); - - for (ColumnDefinition c : COLUMN_DEFINITIONS) { - list.add(c.getHeader()); - } - - for (int i = COLUMN_DEFINITIONS.size(); i < COLUMN_SIZE; i++) { - String title = "column " + i; - int nRandom = new Random().nextInt(); - if (nRandom % 4 == 0 || nRandom % 3 == 0 || nRandom == i) { - title = "large column " + i; - } - - list.add(title); - } - - return list; - } - - /** - * This is a dummy model list test some cases. - */ - @NonNull - private List>> getCellListForSortingTest() { - List>> list = new ArrayList<>(); - for (int rowId = 0; rowId < ROW_SIZE; rowId++) { - IRow> cellList = new Row<>(); - for (int colId = 0; colId < COLUMN_SIZE; colId++) { - IColumnValueProvider provider = - colId < COLUMN_DEFINITIONS.size() - ? COLUMN_DEFINITIONS.get(colId).getValueProvider() - : TEXT_VALUE_PROVIDER; - - Cell cell = new Cell(new MySamplePojo("" + rowId), provider); - cellList.add(cell); - } - list.add(cellList); - } - - return list; - } - - @NonNull - public List>> getCellList() { - return getCellListForSortingTest(); - } - - @NonNull - public List getRowHeaderList() { - return getSimpleRowHeaderList(); - } - - @NonNull - public List getColumnHeaderList() { - return getRandomColumnHeaderList(); - } -} diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java new file mode 100644 index 00000000..823ef783 --- /dev/null +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java @@ -0,0 +1,77 @@ +/* + * MIT License + * + * Copyright (c) 2023 K3b + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableviewsample.tableview; + +import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; +import com.evrencoskun.tableviewutil.ColumnDefinition; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +/** + * This is where all Testdata for the demo app comes from. + * + * Created by k3b on 2023-03-09 + */ + +public class TestData { + // Columns indexes + public static final int COLUMN_INDEX_MOOD_HAPPY = 3; + public static final int COLUMN_INDEX_GENDER_MALE = 4; + // Constant size for dummy data sets + private static final int COLUMN_SIZE = 500; + private static final int ROW_SIZE = 500; + + public static List createSampleData() { + List sampleData = new ArrayList<>(); + for(int i = 0; i < ROW_SIZE; i++) { + MySamplePojo header = new MySamplePojo(String.valueOf(i)); + sampleData.add(header); + } + return sampleData; + } + + public static List> createColumnDefinitions() { + List> definitions = new ArrayList<>(); + definitions.addAll( + Arrays.asList( + new ColumnDefinition<>("Random 0", r -> r.mRandom), + new ColumnDefinition<>("Short 1", r -> r.mRandomShort), + new ColumnDefinition<>("Text 2", r1 -> r1.mText), + new ColumnDefinition<>("Gender 3", r -> r.mGenderMale), + new ColumnDefinition<>("Mood 4", r -> r.mMoodHappy))); + for (int i = 5; i < COLUMN_SIZE;i++) { + final int columnNumber = i; + boolean large = new Random().nextBoolean(); + definitions.add(new ColumnDefinition<>( + (large ? "Lage Column " : "Column ") + i, + r -> r.getColumnValue(columnNumber))); + } + return definitions; + } + +} diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java index 9db419e3..6c065567 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java @@ -54,13 +54,16 @@ public class MySamplePojo implements IModelWithId { */ public MySamplePojo(@NonNull String id) { this.mId = id; - this.mText = "cell " + mId + " 1"; + this.mText = getColumnValue(1); mGenderMale = new Random().nextBoolean(); mMoodHappy = new Random().nextBoolean(); mRandom = abs(new Random().nextInt()); mRandomShort = mRandom % 100; } + public String getColumnValue(int columnNumber) { + return "cell " + mId + " " + columnNumber; + } /** * This is necessary for sorting process. Id must be unique per data row. * See {@link ISortableModel}. diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java new file mode 100644 index 00000000..7c21d056 --- /dev/null +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java @@ -0,0 +1,90 @@ +/* + * MIT License + * + * Copyright (c) 2021 Evren Coşkun, 2023 k3b + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.evrencoskun.tableviewutil; + +import androidx.annotation.NonNull; + +import com.evrencoskun.tableview.model.Cell; +import com.evrencoskun.tableview.model.IColumnValueProvider; +import com.evrencoskun.tableview.model.IModelWithId; +import com.evrencoskun.tableview.model.IRow; +import com.evrencoskun.tableview.model.Row; +import com.evrencoskun.tableview.model.RowHeader; + +import java.util.ArrayList; +import java.util.List; + +/** + * Generic TableViewModel that defines RowHeader, ColumnHeader and Cells of the Table. + */ +public class TableViewModel { + protected final List> columnDefinitions; + protected final List pojos; + + public TableViewModel(List> columnDefinitions, List pojos) { + this.columnDefinitions = columnDefinitions; + this.pojos = pojos; + } + + @NonNull + public List>> getCellList() { + List>> list = new ArrayList<>(); + int numberOfColumns = columnDefinitions.size(); + for (POJO pojo : pojos) { + IRow> cellList = new Row<>(); + for (int colId = 0; colId < numberOfColumns; colId++) { + IColumnValueProvider provider = + columnDefinitions.get(colId).getValueProvider(); + + Cell cell = new Cell(pojo, provider); + cellList.add(cell); + } + list.add(cellList); + } + + return list; + } + + @NonNull + public List getColumnHeaderList() { + List list = new ArrayList<>(); + + for (ColumnDefinition c : columnDefinitions) { + list.add(c.getHeader()); + } + return list; + } + + + @NonNull + public List getRowHeaderList() { + List list = new ArrayList<>(); + for (POJO pojo : pojos) { + RowHeader header = new RowHeader(pojo); + list.add(header); + } + + return list; + } +} From 7fa68d66d573e3ef4146004d785a7eac59a8a6de Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Fri, 10 Mar 2023 10:43:52 +0100 Subject: [PATCH 27/35] Made TableViewAdapter generic. All column definitions come from ColumnDefinition. --- .../tableviewsample/MainFragment.java | 4 +- .../tableview/TableViewAdapter.java | 149 ------------------ .../tableviewsample/tableview/TestData.java | 30 ++-- .../adapter/AbstractTableAdapter.java | 1 + .../ColumnHeaderRecyclerViewAdapter.java | 6 +- .../holder/AbstractViewHolder.java | 8 + .../tableview/model/IColumnValueProvider.java | 4 +- .../tableview/model/IViewHolderFactory.java | 36 +++++ .../tableviewutil/ColumnDefinition.java | 46 ++++-- ...AdapterBase.java => TableViewAdapter.java} | 109 +++++++++---- .../tableviewutil/TableViewModel.java | 13 +- .../holder/BoolDrawableCellViewHolder.java | 16 +- .../holder/ColumnHeaderViewHolder.java | 5 + .../holder/GenericTextCellViewHolder.java | 10 +- 14 files changed, 221 insertions(+), 216 deletions(-) delete mode 100644 app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java create mode 100644 tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java rename tableviewutil/src/main/java/com/evrencoskun/tableviewutil/{TableViewAdapterBase.java => TableViewAdapter.java} (70%) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java index e4e76176..1350787c 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java @@ -42,8 +42,8 @@ import com.evrencoskun.tableview.TableView; import com.evrencoskun.tableview.filter.Filter; import com.evrencoskun.tableview.pagination.Pagination; -import com.evrencoskun.tableviewsample.tableview.TableViewAdapter; import com.evrencoskun.tableviewsample.tableview.TableViewListener; +import com.evrencoskun.tableviewutil.TableViewAdapter; import com.evrencoskun.tableviewutil.TableViewModel; import com.evrencoskun.tableviewsample.tableview.TestData; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; @@ -129,7 +129,7 @@ private void initializeTableView() { TableViewModel tableViewModel = new TableViewModel(columnDefinitions, pojos); // Create TableView Adapter - TableViewAdapter tableViewAdapter = new TableViewAdapter(tableViewModel); + TableViewAdapter tableViewAdapter = new TableViewAdapter<>(columnDefinitions); mTableView.setAdapter(tableViewAdapter); mTableView.setTableViewListener(new TableViewListener(mTableView)); diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java deleted file mode 100644 index c70b66f5..00000000 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewAdapter.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2021 Evren Coşkun - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.evrencoskun.tableviewsample.tableview; - -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import com.evrencoskun.tableviewsample.R; -import com.evrencoskun.tableviewutil.TableViewAdapterBase; -import com.evrencoskun.tableviewutil.TableViewModel; -import com.evrencoskun.tableviewutil.holder.BoolDrawableCellViewHolder; -import com.evrencoskun.tableview.model.Cell; -import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; - -/** - * Created by evrencoskun on 11/06/2017. - *

- * This is a sample of custom TableView Adapter that is customized for MySamplePojo: - * Columns MOOD_CELL and GENDER_CELL are displayed as images. - */ - -public class TableViewAdapter extends TableViewAdapterBase { - private static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); - - // Cell View Types by Column Position - private static final int MOOD_CELL_TYPE = 1; - private static final int GENDER_CELL_TYPE = 2; - // add new one if it necessary.. - - @NonNull - protected final TableViewModel mTableViewModel; - - public TableViewAdapter(@NonNull TableViewModel tableViewModel) { - mTableViewModel = tableViewModel; - } - - /** - * This is where you create your custom Cell ViewHolder. This method is called when Cell - * RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given type to - * represent an item. - * - * @param viewType : This value comes from "getCellItemViewType" method to support different - * type of viewHolder as a Cell item. - * @see #getCellItemViewType(int); - */ - @NonNull - @Override - public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int viewType) { - //TODO check - Log.e(LOG_TAG, " onCreateCellViewHolder has been called"); - LayoutInflater inflater = LayoutInflater.from(parent.getContext()); - View layout; - - switch (viewType) { - case MOOD_CELL_TYPE: - // Get image cell layout which has ImageView on the base instead of TextView. - layout = inflater.inflate(R.layout.table_view_image_cell_layout, parent, false); - - return new BoolDrawableCellViewHolder(layout, R.drawable.ic_happy ,R.drawable.ic_sad); - case GENDER_CELL_TYPE: - // Get image cell layout which has ImageView instead of TextView. - layout = inflater.inflate(R.layout.table_view_image_cell_layout, parent, false); - - return new BoolDrawableCellViewHolder(layout, R.drawable.ic_male, R.drawable.ic_female); - default: - return super.onCreateCellViewHolder(parent,viewType); - } - } - - /** - * That is where you set Cell View Model data to your custom Cell ViewHolder. This method is - * Called by Cell RecyclerView of the TableView to display the data at the specified position. - * This method gives you everything you need about a cell item. - * - * @param holder : This is one of your cell ViewHolders that was created on - * ```onCreateCellViewHolder``` method. In this example we have created - * "GenericTextCellViewHolder" holder. - * @param cellItemModel : This is the cell view model located on this X and Y position. In this - * example, the model class is "Cell". - * @param columnPosition : This is the X (Column) position of the cell item. - * @param rowPosition : This is the Y (Row) position of the cell item. - * @see #onCreateCellViewHolder(ViewGroup, int) ; - */ - @Override - public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int - columnPosition, int rowPosition) { - - switch (holder.getItemViewType()) { - case MOOD_CELL_TYPE: - BoolDrawableCellViewHolder moodViewHolder = (BoolDrawableCellViewHolder) holder; - moodViewHolder.setData(cellItemModel.getData().mMoodHappy); - break; - case GENDER_CELL_TYPE: - BoolDrawableCellViewHolder genderViewHolder = (BoolDrawableCellViewHolder) holder; - genderViewHolder.setData(cellItemModel.getData().mGenderMale); - break; - default: - // Get the holder to update cell item text - super.onBindCellViewHolder(holder, cellItemModel, columnPosition, rowPosition); - break; - } - } - - @Override - public int getCellItemViewType(int column) { - - // The unique ID for this type of cell item - // If you have different items for Cell View by X (Column) position, - // then you should fill this method to be able create different - // type of GenericTextCellViewHolder on "onCreateCellViewHolder" - switch (column) { - case TestData.COLUMN_INDEX_MOOD_HAPPY: - return MOOD_CELL_TYPE; - case TestData.COLUMN_INDEX_GENDER_MALE: - return GENDER_CELL_TYPE; - default: - // Default view type - return getRowHeaderItemViewType(0); - } - } -} diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java index 823ef783..3b228bf1 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java @@ -24,8 +24,10 @@ package com.evrencoskun.tableviewsample.tableview; +import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; import com.evrencoskun.tableviewutil.ColumnDefinition; +import com.evrencoskun.tableviewutil.TableViewAdapter; import java.util.ArrayList; import java.util.Arrays; @@ -39,9 +41,13 @@ */ public class TestData { - // Columns indexes + // Columns indexes also used as cell-types public static final int COLUMN_INDEX_MOOD_HAPPY = 3; public static final int COLUMN_INDEX_GENDER_MALE = 4; + + public static final int COLUMN_TYPE_GENERIC = TableViewAdapter.COLUMN_TYPE_GENERIC; + + // Constant size for dummy data sets private static final int COLUMN_SIZE = 500; private static final int ROW_SIZE = 500; @@ -49,8 +55,7 @@ public class TestData { public static List createSampleData() { List sampleData = new ArrayList<>(); for(int i = 0; i < ROW_SIZE; i++) { - MySamplePojo header = new MySamplePojo(String.valueOf(i)); - sampleData.add(header); + sampleData.add(new MySamplePojo(String.valueOf(i))); } return sampleData; } @@ -58,18 +63,25 @@ public static List createSampleData() { public static List> createColumnDefinitions() { List> definitions = new ArrayList<>(); definitions.addAll( + // column 0..4 userdefined Arrays.asList( - new ColumnDefinition<>("Random 0", r -> r.mRandom), - new ColumnDefinition<>("Short 1", r -> r.mRandomShort), - new ColumnDefinition<>("Text 2", r1 -> r1.mText), - new ColumnDefinition<>("Gender 3", r -> r.mGenderMale), - new ColumnDefinition<>("Mood 4", r -> r.mMoodHappy))); + new ColumnDefinition<>("Random 0", r -> r.mRandom, null), + new ColumnDefinition<>("Short 1", r -> r.mRandomShort, null), + new ColumnDefinition<>("Text 2", r1 -> r1.mText, null), + + // column 3..4 contain image + new ColumnDefinition<>("Gender 3", r -> r.mGenderMale, + parent -> TableViewAdapter.createBoolDrawableCellViewHolder(parent, R.drawable.ic_male, R.drawable.ic_female)), + new ColumnDefinition<>("Mood 4", r -> r.mMoodHappy, + parent -> TableViewAdapter.createBoolDrawableCellViewHolder(parent, R.drawable.ic_happy ,R.drawable.ic_sad)))); + + // column 5..500 contain generic text for (int i = 5; i < COLUMN_SIZE;i++) { final int columnNumber = i; boolean large = new Random().nextBoolean(); definitions.add(new ColumnDefinition<>( (large ? "Lage Column " : "Column ") + i, - r -> r.getColumnValue(columnNumber))); + r -> r.getColumnValue(columnNumber), null)); } return definitions; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java index b57df7a1..6478fe4e 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java @@ -190,6 +190,7 @@ public int getRowHeaderItemViewType(int position) { return 0; } + /** Translates columnNumber to CellItemViewType */ @Override public int getCellItemViewType(int position) { return 0; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/ColumnHeaderRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/ColumnHeaderRecyclerViewAdapter.java index d444debe..838c484b 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/ColumnHeaderRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/ColumnHeaderRecyclerViewAdapter.java @@ -50,8 +50,10 @@ public class ColumnHeaderRecyclerViewAdapter extends AbstractRecyclerViewAda private final ITableView mTableView; private ColumnSortHelper mColumnSortHelper; - public ColumnHeaderRecyclerViewAdapter(@NonNull Context context, @Nullable List itemList, @NonNull ITableAdapter - tableAdapter) { + public ColumnHeaderRecyclerViewAdapter( + @NonNull Context context, + @Nullable List itemList, + @NonNull ITableAdapter tableAdapter) { super(context, itemList); this.mTableAdapter = tableAdapter; this.mTableView = tableAdapter.getTableView(); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java index 7b202e40..c8fc4c17 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java @@ -28,6 +28,7 @@ import androidx.annotation.ColorInt; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; /** @@ -35,6 +36,9 @@ */ public abstract class AbstractViewHolder extends RecyclerView.ViewHolder { + protected int mColumnPosition; + protected int mRowPosition; + public enum SelectionState {SELECTED, UNSELECTED, SHADOWED} // Default value @@ -74,4 +78,8 @@ public boolean onFailedToRecycleView() { return false; } + public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { + mColumnPosition = columnPosition; + mRowPosition = rowPosition; + } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java index d3908d7c..41878c4f 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java @@ -27,6 +27,6 @@ /** * Provides a column value object */ -public interface IColumnValueProvider { - Object get(T row); +public interface IColumnValueProvider { + Object get(POJO row); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java new file mode 100644 index 00000000..b2a6c0f7 --- /dev/null +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java @@ -0,0 +1,36 @@ +/* + * MIT License + * + * Copyright (c) 2023 K3b + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.evrencoskun.tableview.model; + +import android.view.ViewGroup; + +import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; + +/** + * Provides a factory that creates a view with viewholder. + */ +public interface IViewHolderFactory { + AbstractViewHolder createViewHolder(ViewGroup parent); +} diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java index 0398f1ca..ec278fae 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java @@ -24,22 +24,48 @@ package com.evrencoskun.tableviewutil; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.evrencoskun.tableview.model.IColumnValueProvider; +import com.evrencoskun.tableview.model.IViewHolderFactory; + +/** + * All informations needed to define a Table + * @param + */ +public class ColumnDefinition { + @NonNull private final String columnHeaderText; + @NonNull private final IColumnValueProvider pojoToCellValueProvider; + @Nullable private final IViewHolderFactory viewHolderFactory; -public class ColumnDefinition { - private final String header; - private final IColumnValueProvider valueProvider; + /** + * Constructor + * @param columnHeaderText text to be displayed as column header + * @param pojoToCellValueProvider translates POJO to cell column Text + * @param viewHolderFactory creates view with viewholder for this column. null means default viewholder + */ + public ColumnDefinition( + @NonNull String columnHeaderText, + @NonNull IColumnValueProvider pojoToCellValueProvider, + @Nullable IViewHolderFactory viewHolderFactory) { + this.columnHeaderText = columnHeaderText; + this.pojoToCellValueProvider = pojoToCellValueProvider; + this.viewHolderFactory = viewHolderFactory; + } - public ColumnDefinition(String header, IColumnValueProvider valueProvider) { - this.header = header; - this.valueProvider = valueProvider; + /** text to be displayed as column header */ + @NonNull public String getColumnHeaderText() { + return columnHeaderText; } - public String getHeader() { - return header; + /** translates POJO to cell column Text */ + @NonNull public IColumnValueProvider getPojoToCellValueProvider() { + return pojoToCellValueProvider; } - public IColumnValueProvider getValueProvider() { - return valueProvider; + /** creates view with viewholder for this column. null means default viewholder */ + @Nullable public IViewHolderFactory getViewHolderFactory() { + return viewHolderFactory; } } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java similarity index 70% rename from tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java rename to tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java index 57ef2a43..2838d069 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapterBase.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2021 Evren Coşkun + * Copyright (c) 2021 Evren Coşkun, 2023 k3b * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,26 +29,39 @@ import android.view.View; import android.view.ViewGroup; +import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.evrencoskun.tableview.adapter.AbstractTableAdapter; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.model.IModelWithId; +import com.evrencoskun.tableview.model.IViewHolderFactory; import com.evrencoskun.tableview.sort.SortState; -import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; +import com.evrencoskun.tableviewutil.holder.BoolDrawableCellViewHolder; import com.evrencoskun.tableviewutil.holder.GenericTextCellViewHolder; import com.evrencoskun.tableviewutil.holder.RowHeaderViewHolder; import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableview.model.RowHeader; +import java.util.List; + /** * Generic adapter that translates a POJO to TableView-Cells. * * Defaultimplementation translates all columns to TextView fields. */ -public abstract class TableViewAdapterBase extends AbstractTableAdapter> { - private static final String LOG_TAG = TableViewAdapterBase.class.getSimpleName(); +public class TableViewAdapter + extends AbstractTableAdapter> { + private static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); + + public static final int COLUMN_TYPE_GENERIC = 9999; + @Nullable private final List> columnDefinitions; + + public TableViewAdapter(@Nullable List> columnDefinitions) { + super(); + this.columnDefinitions = columnDefinitions; + } /** * This is where you create your custom Column Header ViewHolder. This method is called when @@ -62,14 +75,8 @@ public abstract class TableViewAdapterBase extends Ab @NonNull @Override public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { - // TODO: check - //Log.e(LOG_TAG, " onCreateColumnHeaderViewHolder has been called"); - // Get Column Header xml Layout - View layout = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.table_view_column_header_layout, parent, false); - - // Create a ColumnHeader ViewHolder - return new ColumnHeaderViewHolder(layout, getTableView()); + return getViewHolderFactory(viewType, TableViewAdapter::createGenericTextCellViewHolder) + .createViewHolder(parent); } /** @@ -90,9 +97,7 @@ public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup pare public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String columnHeader, int columnPosition) { - // Get the holder to update cell item text - ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder; - columnHeaderViewHolder.setColumnHeader(columnHeader); + holder.setCell(columnHeader, columnPosition,0); } /** @@ -107,18 +112,69 @@ public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nu @NonNull @Override public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int viewType) { - //TODO check - Log.e(LOG_TAG, " onCreateCellViewHolder has been called"); + return getViewHolderFactory(viewType, TableViewAdapter::createGenericTextCellViewHolder).createViewHolder(parent); + } + + /** + * Translates columnNumber to CellItemViewType. + * + * @return columnNumber or COLUMN_TYPE_GENERIC if there is no special CellItemViewType + */ + @Override + public int getCellItemViewType(int columnNumber) { + IViewHolderFactory viewHolderFactory = getViewHolderFactory(columnNumber, null); + + if (viewHolderFactory != null) { + // if columnDefinitions found use columnNumber as returned viewtype + return columnNumber; + } + + // if no specialised viewType is found use generic + return COLUMN_TYPE_GENERIC; + } + + private IViewHolderFactory getViewHolderFactory(int column,@Nullable IViewHolderFactory notFoundValue) { + if (columnDefinitions != null && column >= 0 && column < columnDefinitions.size()) { + IViewHolderFactory factory = columnDefinitions.get(column).getViewHolderFactory(); + if (factory != null) { + return factory; + } + } + return notFoundValue; + } + + /** + * For cells that display a text + * + * @param parent where view and viewholder will be attached to + * @return viewholder for view attached to R.layout.table_view_cell_layout + */ + @NonNull + public static GenericTextCellViewHolder createGenericTextCellViewHolder(@NonNull ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(parent.getContext()); - View layout; // For cells that display a text - layout = inflater.inflate(R.layout.table_view_cell_layout, parent, false); + View layout = inflater.inflate(R.layout.table_view_cell_layout, parent, false); // Create a Cell ViewHolder return new GenericTextCellViewHolder(layout); } + // Get image cell layout which has ImageView on the base instead of TextView. + + /** + * For cells that display one of two images based on a boolean value + * @param parent where view and viewholder will be attached to + * @param idDrawableTrue icon id for the image that represents true. + * @param idDrawableFalse icon id for the image that represents false. + * @return viewholder for view attached to R.layout.table_view_image_cell_layout + */ + @NonNull public static AbstractViewHolder createBoolDrawableCellViewHolder(@NonNull ViewGroup parent, @DrawableRes int idDrawableTrue, @DrawableRes int idDrawableFalse) { + LayoutInflater inflater = LayoutInflater.from(parent.getContext()); + View layout = inflater.inflate(R.layout.table_view_image_cell_layout, parent, false); + return new BoolDrawableCellViewHolder(layout, idDrawableTrue, idDrawableFalse); + } + /** * That is where you set Cell View Model data to your custom Cell ViewHolder. This method is * Called by Cell RecyclerView of the TableView to display the data at the specified position. @@ -136,10 +192,7 @@ public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int @Override public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int columnPosition, int rowPosition) { - - // Get the holder to update cell item text - GenericTextCellViewHolder viewHolder = (GenericTextCellViewHolder) holder; - viewHolder.setCell(cellItemModel, columnPosition, rowPosition); + holder.setCell(cellItemModel != null ? cellItemModel.getContent() : null, columnPosition, rowPosition); } /** @@ -191,14 +244,14 @@ public View onCreateCornerView(@NonNull ViewGroup parent) { View corner = LayoutInflater.from(parent.getContext()) .inflate(R.layout.table_view_corner_layout, parent, false); corner.setOnClickListener(view -> { - SortState sortState = TableViewAdapterBase.this.getTableView() + SortState sortState = TableViewAdapter.this.getTableView() .getRowHeaderSortingStatus(); if (sortState != SortState.ASCENDING) { Log.d("TableViewAdapter", "Order Ascending"); - TableViewAdapterBase.this.getTableView().sortRowHeader(SortState.ASCENDING); + TableViewAdapter.this.getTableView().sortRowHeader(SortState.ASCENDING); } else { Log.d("TableViewAdapter", "Order Descending"); - TableViewAdapterBase.this.getTableView().sortRowHeader(SortState.DESCENDING); + TableViewAdapter.this.getTableView().sortRowHeader(SortState.DESCENDING); } }); return corner; @@ -210,7 +263,7 @@ public int getColumnHeaderItemViewType(int position) { // If you have different items for Cell View by X (Column) position, // then you should fill this method to be able create different // type of GenericTextCellViewHolder on "onCreateCellViewHolder" - return 0; + return COLUMN_TYPE_GENERIC; } @Override @@ -219,6 +272,6 @@ public int getRowHeaderItemViewType(int position) { // If you have different items for Row Header View by Y (Row) position, // then you should fill this method to be able create different // type of RowHeaderViewHolder on "onCreateRowHeaderViewHolder" - return 0; + return COLUMN_TYPE_GENERIC; } } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java index 7c21d056..99a42c3f 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java @@ -29,6 +29,7 @@ import com.evrencoskun.tableview.model.IColumnValueProvider; import com.evrencoskun.tableview.model.IModelWithId; import com.evrencoskun.tableview.model.IRow; +import com.evrencoskun.tableview.model.IViewHolderFactory; import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.model.RowHeader; @@ -38,8 +39,8 @@ /** * Generic TableViewModel that defines RowHeader, ColumnHeader and Cells of the Table. */ -public class TableViewModel { - protected final List> columnDefinitions; +public class TableViewModel { + private final List> columnDefinitions; protected final List pojos; public TableViewModel(List> columnDefinitions, List pojos) { @@ -55,7 +56,7 @@ public List>> getCellList() { IRow> cellList = new Row<>(); for (int colId = 0; colId < numberOfColumns; colId++) { IColumnValueProvider provider = - columnDefinitions.get(colId).getValueProvider(); + columnDefinitions.get(colId).getPojoToCellValueProvider(); Cell cell = new Cell(pojo, provider); cellList.add(cell); @@ -71,7 +72,7 @@ public List getColumnHeaderList() { List list = new ArrayList<>(); for (ColumnDefinition c : columnDefinitions) { - list.add(c.getHeader()); + list.add(c.getColumnHeaderText()); } return list; } @@ -87,4 +88,8 @@ public List getRowHeaderList() { return list; } + + public List> getColumnDefinitions() { + return columnDefinitions; + } } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java index ce4a8d40..0e3e5d9e 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java @@ -29,6 +29,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableviewutil.R; @@ -50,9 +51,18 @@ public BoolDrawableCellViewHolder(@NonNull View itemView, @DrawableRes int idDra mIdDrawableFalse = idDrawableFalse; } - public void setData(boolean data) { - int moodDrawable = data ? mIdDrawableTrue : mIdDrawableFalse; + public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { + super.setCell(content, columnPosition, rowPosition); + setData(content == null ? null : (Boolean) content); + } + + public void setData(Boolean data) { + if (data != null) { + int moodDrawable = data ? mIdDrawableTrue : mIdDrawableFalse; - cell_image.setImageResource(moodDrawable); + cell_image.setImageResource(moodDrawable); + } else { + cell_image.setImageBitmap(null); + } } } \ No newline at end of file diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java index 2db80cf6..6cdb12e4 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java @@ -66,6 +66,11 @@ public ColumnHeaderViewHolder(@NonNull View itemView, @Nullable ITableView table column_header_sortButton.setOnClickListener(mSortButtonClickListener); } + public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { + super.setCell(content, columnPosition, rowPosition); + setColumnHeader(content == null ? "" : content.toString()); + } + /** * This method is calling from onBindColumnHeaderHolder on TableViewAdapter */ diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java index a72eb517..5b3af321 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java @@ -32,7 +32,6 @@ import androidx.annotation.Nullable; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; -import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableviewutil.R; /** @@ -44,8 +43,6 @@ public class GenericTextCellViewHolder extends AbstractViewHolder { private final TextView cell_textview; @NonNull private final LinearLayout cell_container; - private int mColumnPosition; - private int mRowPosition; public GenericTextCellViewHolder(@NonNull View itemView) { super(itemView); @@ -53,10 +50,9 @@ public GenericTextCellViewHolder(@NonNull View itemView) { cell_container = itemView.findViewById(R.id.cell_container); } - public void setCell(@Nullable Cell cell, int columnPosition, int rowPosition) { - mColumnPosition = columnPosition; - mRowPosition = rowPosition; - cell_textview.setText(String.valueOf(cell.getContent())); + public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { + super.setCell(content, columnPosition, rowPosition); + cell_textview.setText(content == null ? "" : content.toString()); // If your TableView should have auto resize for cells & columns. // Then you should consider the below lines. Otherwise, you can ignore them. From dc4f95f8ca671bbdbb2a5e78f83d36763ac24d97 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Fri, 10 Mar 2023 13:48:20 +0100 Subject: [PATCH 28/35] Updated docs --- .../tableview/model/MySamplePojo.java | 2 +- changelog.md | 105 +++++++++++++++++- .../tableview/model/IColumnValueProvider.java | 4 +- .../tableview/model/IModelWithId.java | 3 +- .../com/evrencoskun/tableview/model/IRow.java | 11 +- .../tableview/model/IViewHolderFactory.java | 2 +- .../com/evrencoskun/tableview/model/Row.java | 2 +- 7 files changed, 108 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java index 6c065567..ca533614 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2021 Evren Coşkun + * Copyright (c) 2023 k3b * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/changelog.md b/changelog.md index 6d15fde8..6d93d34f 100644 --- a/changelog.md +++ b/changelog.md @@ -8,9 +8,102 @@ requires a lot of copy&paste from example code to use the TableView in a clienta Product vision: reduce the amount of (copied) code to integrate TableView into a clientapp. -* v done: replaced the table header model with simple Strings. -* v done: replaced the must-customize Cell.java with a templated Cell where customisation takes place in the pojo -* v done: keep demo app intact using MySamplePojo -* v done: customized TableViewAdapter inherits from new generic TableViewAdapterBase -* v done: replace List>> with List> -* . (planed): additional lib containing the generic gui classes and resources +* all app specific data comes from tableview independent POJOs (i.e. List from TestData.createSampleData()) +* all info how the POJO is displayed in the tableview comes from ColumnDefinition (i.e. List> from TestData.createColumnDefinitions()) +* no more need to implement app-specific XxxViewHolder, XxxModell for Cell, Column, RowHeader +* no more need to implement app-specific TableViewAdapter, TableViewModel +* no more need to define app specific layout for table_view_Xxx_layout.xml for Cell, Column, RowHeader +* Instead of the app-specific classes/layouts (mentioned in "no more need") there are generic, app-independant in the new modul tableviewutil. +* For legacy apps the tableview lib can be used as before. + +## Additional Requirements + +* java-8 lamda expressions to define column values and custom cell-view(-holders). See createColumnDefinitions() in TestData.java + +# Some differences between old and new style app that uses tableview + +### old style: + +build.gradle dependencies: + + implementation "com.evrencoskun.library:tableview:$tableview_version" + +Mainfragment.java + + private void initializeTableView(TableView tableView){ + // Create TableView Adapter + mTableAdapter = new MyTableAdapter(getContext()); + tableView.setAdapter(mTableAdapter); + + // Create listener + tableView.setTableViewListener(new MyTableViewListener(tableView)); + } + +Define app specific classes and resources + +* MainFragment.java +* MainActivity.java +* MainViewModel.java +* MyTableViewModel.java +* ColumnHeaderViewHolder.java +* MyTableAdapter.java +* CellModel.java +* RowHeaderViewHolder.java +* MyTableViewListener.java +* ColumnHeaderModel.java +* GenderCellViewHolder.java +* MoneyCellViewHolder.java +* RowHeaderModel.java +* CellViewHolder.java + +* ic_down.xml +* ic_up.xml +* activity_main.xml +* fragment_main.xml +* tableview_cell_layout.xml +* tableview_column_header_layout.xml +* tableview_corner_layout.xml +* tableview_gender_cell_layout.xml +* tableview_money_cell_layout.xml +* tableview_row_header_layout.xml + +### new style: + +build.gradle dependencies: + + implementation "com.evrencoskun.library:tableview:$tableview_version" + implementation "com.evrencoskun.library:tableviewutil:$tableview_version" + +Mainfragment.java + + private void initializeTableView(TableView tableView){ + List> columnDefinitions = TestData.createColumnDefinitions(); + List pojos = TestData.createSampleData(); + // Create TableView View model class to group view models of TableView + TableViewModel tableViewModel = new TableViewModel(columnDefinitions, pojos); + + // Create TableView Adapter + TableViewAdapter tableViewAdapter = new TableViewAdapter<>(columnDefinitions); + + tableView.setAdapter(tableViewAdapter); + tableView.setTableViewListener(new MyTableViewListener(tableView)); + + // Create an instance of a Filter and pass the TableView. + //mTableFilter = new Filter(tableView); + + // Load the dummy data to the TableView + tableViewAdapter.setAllItems(tableViewModel.getColumnHeaderList(), tableViewModel + .getRowHeaderList(), tableViewModel.getCellList()); + + } + +Define app specific classes and resources + +* MySamplePojo.java +* MyTableViewListener.java +* TestData.java +* MainActivity.java +* MainFragment.java + +* activity_main.xml +* fragment_main.xml diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java index 41878c4f..d1ed5451 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IColumnValueProvider.java @@ -25,7 +25,9 @@ package com.evrencoskun.tableview.model; /** - * Provides a column value object + * Lamda support to translate POJO to column value object in a table cell. + * + * Example: pojo -> pojo.getName() */ public interface IColumnValueProvider { Object get(POJO row); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java index b2bedbd8..7b61ddb4 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IModelWithId.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2021 Evren Coşkun + * Copyright (c) 2023 k3b * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,6 +26,7 @@ import androidx.annotation.NonNull; +/** All POJO-items in TableView must implement this */ public interface IModelWithId { /** * to make sorting work, Id must be unique per data row. diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java index c7a1c92f..33fd93d8 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023 Evren Coşkun + * Copyright (c) 2023 k3b * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,13 +27,4 @@ import java.util.List; public interface IRow extends List { -// public interface IRow { -/* - // methods implemented by List<> - int size(); - C get(int position); - C remove(int position); - - void add(int position, C item); - */ } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java index b2a6c0f7..ea1137b8 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/IViewHolderFactory.java @@ -29,7 +29,7 @@ import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; /** - * Provides a factory that creates a view with viewholder. + * Lamda Support to create a factory that creates a view with viewholder. */ public interface IViewHolderFactory { AbstractViewHolder createViewHolder(ViewGroup parent); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java index 0644fb5b..381fa528 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023 Evren Coşkun + * Copyright (c) 2023 k3b * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal From aad16605416871658e1ae620d1ae50b5fd9849d4 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Fri, 10 Mar 2023 14:10:09 +0100 Subject: [PATCH 29/35] Updated docs --- changelog.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 6d93d34f..96ef9901 100644 --- a/changelog.md +++ b/changelog.md @@ -8,8 +8,8 @@ requires a lot of copy&paste from example code to use the TableView in a clienta Product vision: reduce the amount of (copied) code to integrate TableView into a clientapp. -* all app specific data comes from tableview independent POJOs (i.e. List from TestData.createSampleData()) -* all info how the POJO is displayed in the tableview comes from ColumnDefinition (i.e. List> from TestData.createColumnDefinitions()) +* all app specific data comes from tableview independent POJOs (i.e. `List from TestData.createSampleData()`) +* all info how the POJO is displayed in the tableview comes from ColumnDefinition (i.e. `List>` from `TestData.createColumnDefinitions()`) * no more need to implement app-specific XxxViewHolder, XxxModell for Cell, Column, RowHeader * no more need to implement app-specific TableViewAdapter, TableViewModel * no more need to define app specific layout for table_view_Xxx_layout.xml for Cell, Column, RowHeader @@ -18,7 +18,7 @@ Product vision: reduce the amount of (copied) code to integrate TableView into a ## Additional Requirements -* java-8 lamda expressions to define column values and custom cell-view(-holders). See createColumnDefinitions() in TestData.java +* java-8 lamda expressions to define column values and custom cell-view(-holders). See createColumnDefinitions() in TestData.java # Some differences between old and new style app that uses tableview @@ -28,7 +28,7 @@ build.gradle dependencies: implementation "com.evrencoskun.library:tableview:$tableview_version" -Mainfragment.java +Mainfragment.java private void initializeTableView(TableView tableView){ // Create TableView Adapter From 0c87e2296544f00784a25ae28f6f5689dd0ae7b6 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:17:52 +0100 Subject: [PATCH 30/35] fixed Header-Menu. Added pojo to ViewHolder and app showToast --- .../tableview/TableViewListener.java | 40 ++++++++++++++----- .../tableview/model/MySamplePojo.java | 11 +++++ .../popup/ColumnHeaderLongPressPopup.java | 4 +- .../popup/RowHeaderLongPressPopup.java | 4 +- .../holder/AbstractViewHolder.java | 8 +++- .../tableviewutil/TableViewAdapter.java | 13 ++++-- .../holder/BoolDrawableCellViewHolder.java | 4 +- .../holder/ColumnHeaderViewHolder.java | 4 +- .../holder/GenericTextCellViewHolder.java | 4 +- 9 files changed, 68 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java index a259475c..72862d70 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java @@ -25,12 +25,14 @@ package com.evrencoskun.tableviewsample.tableview; import android.content.Context; +import android.util.Log; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.evrencoskun.tableview.TableView; +import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.listener.ITableViewListener; import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewsample.tableview.popup.ColumnHeaderLongPressPopup; @@ -60,10 +62,23 @@ public TableViewListener(@NonNull TableView tableView) { */ @Override public void onCellClicked(@NonNull RecyclerView.ViewHolder cellView, int column, int row) { + showToast("Cell " + getMessageContext(cellView, column, row, "clicked")); - // Do what you want. - showToast("Cell " + column + " " + row + " has been clicked."); + } + @NonNull + private String getMessageContext(RecyclerView.ViewHolder cellView, int column, int row, String action) { + String data = ""; + if (cellView instanceof AbstractViewHolder) { + final Object pojo = ((AbstractViewHolder) cellView).getPojo(); + if (pojo != null) { + data = pojo.toString(); + } + } + return "" + column + " " + row + " has been " + + action + + " for " + data + " [" + + cellView.getClass().getSimpleName() + ".]"; } /** @@ -76,7 +91,7 @@ public void onCellClicked(@NonNull RecyclerView.ViewHolder cellView, int column, @Override public void onCellDoubleClicked(@NonNull RecyclerView.ViewHolder cellView, int column, int row) { // Do what you want. - showToast("Cell " + column + " " + row + " has been double clicked."); + showToast("Cell " + getMessageContext(cellView, column, row, "double clicked")); } /** @@ -90,7 +105,7 @@ public void onCellDoubleClicked(@NonNull RecyclerView.ViewHolder cellView, int c public void onCellLongPressed(@NonNull RecyclerView.ViewHolder cellView, final int column, int row) { // Do What you want - showToast("Cell " + column + " " + row + " has been long pressed."); + showToast("Cell " + getMessageContext(cellView, column, row, "long pressed")); } /** @@ -103,7 +118,7 @@ public void onCellLongPressed(@NonNull RecyclerView.ViewHolder cellView, final i public void onColumnHeaderClicked(@NonNull RecyclerView.ViewHolder columnHeaderView, int column) { // Do what you want. - showToast("Column header " + column + " has been clicked."); + showToast("Column header " + getMessageContext(columnHeaderView, column, -1, "clicked")); } /** @@ -115,7 +130,7 @@ public void onColumnHeaderClicked(@NonNull RecyclerView.ViewHolder columnHeaderV @Override public void onColumnHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder columnHeaderView, int column) { // Do what you want. - showToast("Column header " + column + " has been double clicked."); + showToast("Column header " + getMessageContext(columnHeaderView, column, -1, "double clicked")); } /** @@ -127,11 +142,12 @@ public void onColumnHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder columnH @Override public void onColumnHeaderLongPressed(@NonNull RecyclerView.ViewHolder columnHeaderView, int column) { + showToast("Column header " + getMessageContext(columnHeaderView, column, -1, "long pressed")); if (columnHeaderView instanceof ColumnHeaderViewHolder) { // Create Long Press Popup ColumnHeaderLongPressPopup popup = new ColumnHeaderLongPressPopup( - (ColumnHeaderViewHolder) columnHeaderView, mTableView); + (ColumnHeaderViewHolder) columnHeaderView, mTableView, column); // Show popup.show(); } @@ -146,7 +162,7 @@ public void onColumnHeaderLongPressed(@NonNull RecyclerView.ViewHolder columnHea @Override public void onRowHeaderClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) { // Do whatever you want. - showToast("Row header " + row + " has been clicked."); + showToast("Row header " + getMessageContext(rowHeaderView, -1, row, "clicked")); } /** @@ -158,7 +174,7 @@ public void onRowHeaderClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, i @Override public void onRowHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) { // Do whatever you want. - showToast("Row header " + row + " has been double clicked."); + showToast("Row header " + getMessageContext(rowHeaderView, -1, row, "double clicked")); } /** @@ -169,15 +185,17 @@ public void onRowHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder rowHeaderV */ @Override public void onRowHeaderLongPressed(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) { + showToast("Row header " + getMessageContext(rowHeaderView, -1, row, "long pressed")); // Create Long Press Popup - RowHeaderLongPressPopup popup = new RowHeaderLongPressPopup(rowHeaderView, mTableView); + RowHeaderLongPressPopup popup = new RowHeaderLongPressPopup(rowHeaderView, mTableView, row); // Show popup.show(); } private void showToast(String p_strMessage) { - Toast.makeText(mContext, p_strMessage, Toast.LENGTH_SHORT).show(); + Log.d(this.getClass().getSimpleName(), p_strMessage); + Toast.makeText(mContext, p_strMessage, Toast.LENGTH_LONG).show(); } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java index ca533614..24896d59 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/model/MySamplePojo.java @@ -73,4 +73,15 @@ public String getColumnValue(int columnNumber) { public String getId() { return mId; } + + @Override + public String toString() { + return "MySamplePojo{" + + "Id='" + mId + '\'' + + ", Random=" + mRandom + + ", RandomShort=" + mRandomShort + + ", GenderMale=" + mGenderMale + + ", MoodHappy=" + mMoodHappy + + '}'; + } } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java index 64cf54c4..5b93848e 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/ColumnHeaderLongPressPopup.java @@ -52,11 +52,13 @@ public class ColumnHeaderLongPressPopup extends PopupMenu implements PopupMenu @NonNull private final TableView mTableView; private final int mXPosition; + private final int column; - public ColumnHeaderLongPressPopup(@NonNull ColumnHeaderViewHolder viewHolder, @NonNull TableView tableView) { + public ColumnHeaderLongPressPopup(@NonNull ColumnHeaderViewHolder viewHolder, @NonNull TableView tableView, int column) { super(viewHolder.itemView.getContext(), viewHolder.itemView); this.mTableView = tableView; this.mXPosition = viewHolder.getBindingAdapterPosition(); + this.column = column; initialize(); } diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/RowHeaderLongPressPopup.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/RowHeaderLongPressPopup.java index 609c4a1e..bcba1c93 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/RowHeaderLongPressPopup.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/popup/RowHeaderLongPressPopup.java @@ -50,12 +50,14 @@ public class RowHeaderLongPressPopup extends PopupMenu implements PopupMenu @NonNull private final TableView mTableView; private final int mRowPosition; + private final int row; - public RowHeaderLongPressPopup(@NonNull RecyclerView.ViewHolder viewHolder, @NonNull TableView tableView) { + public RowHeaderLongPressPopup(@NonNull RecyclerView.ViewHolder viewHolder, @NonNull TableView tableView, int row) { super(viewHolder.itemView.getContext(), viewHolder.itemView); this.mTableView = tableView; this.mRowPosition = viewHolder.getBindingAdapterPosition(); + this.row = row; initialize(); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java index c8fc4c17..4740019c 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/holder/AbstractViewHolder.java @@ -38,6 +38,7 @@ public abstract class AbstractViewHolder extends RecyclerView.ViewHolder { protected int mColumnPosition; protected int mRowPosition; + @Nullable private Object mPojo; public enum SelectionState {SELECTED, UNSELECTED, SHADOWED} @@ -78,8 +79,13 @@ public boolean onFailedToRecycleView() { return false; } - public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { + public void setCell(@Nullable Object content, int columnPosition, int rowPosition, @Nullable Object pojo) { mColumnPosition = columnPosition; mRowPosition = rowPosition; + this.mPojo = pojo; } + public Object getPojo() { + return mPojo; + } + } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java index 2838d069..5fc815d0 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java @@ -39,6 +39,7 @@ import com.evrencoskun.tableview.model.IViewHolderFactory; import com.evrencoskun.tableview.sort.SortState; import com.evrencoskun.tableviewutil.holder.BoolDrawableCellViewHolder; +import com.evrencoskun.tableviewutil.holder.ColumnHeaderViewHolder; import com.evrencoskun.tableviewutil.holder.GenericTextCellViewHolder; import com.evrencoskun.tableviewutil.holder.RowHeaderViewHolder; import com.evrencoskun.tableview.model.Cell; @@ -75,8 +76,12 @@ public TableViewAdapter(@Nullable List> columnDefinitions @NonNull @Override public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { - return getViewHolderFactory(viewType, TableViewAdapter::createGenericTextCellViewHolder) - .createViewHolder(parent); + View layout = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.table_view_column_header_layout, parent, false); + + // Create a ColumnHeader ViewHolder + return new ColumnHeaderViewHolder(layout, getTableView()); + } /** @@ -97,7 +102,7 @@ public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup pare public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String columnHeader, int columnPosition) { - holder.setCell(columnHeader, columnPosition,0); + holder.setCell(columnHeader, columnPosition,0, null); } /** @@ -192,7 +197,7 @@ public static GenericTextCellViewHolder createGenericTextCellViewHolder(@NonNull @Override public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int columnPosition, int rowPosition) { - holder.setCell(cellItemModel != null ? cellItemModel.getContent() : null, columnPosition, rowPosition); + holder.setCell(cellItemModel != null ? cellItemModel.getContent() : null, columnPosition, rowPosition, cellItemModel.getData()); } /** diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java index 0e3e5d9e..cd651989 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java @@ -51,8 +51,8 @@ public BoolDrawableCellViewHolder(@NonNull View itemView, @DrawableRes int idDra mIdDrawableFalse = idDrawableFalse; } - public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { - super.setCell(content, columnPosition, rowPosition); + public void setCell(@Nullable Object content, int columnPosition, int rowPosition, Object pojo) { + super.setCell(content, columnPosition, rowPosition, pojo); setData(content == null ? null : (Boolean) content); } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java index 6cdb12e4..5e4b37a5 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java @@ -66,8 +66,8 @@ public ColumnHeaderViewHolder(@NonNull View itemView, @Nullable ITableView table column_header_sortButton.setOnClickListener(mSortButtonClickListener); } - public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { - super.setCell(content, columnPosition, rowPosition); + public void setCell(@Nullable Object content, int columnPosition, int rowPosition, Object pojo) { + super.setCell(content, columnPosition, rowPosition, pojo); setColumnHeader(content == null ? "" : content.toString()); } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java index 5b3af321..eece81a7 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/GenericTextCellViewHolder.java @@ -50,8 +50,8 @@ public GenericTextCellViewHolder(@NonNull View itemView) { cell_container = itemView.findViewById(R.id.cell_container); } - public void setCell(@Nullable Object content, int columnPosition, int rowPosition) { - super.setCell(content, columnPosition, rowPosition); + public void setCell(@Nullable Object content, int columnPosition, int rowPosition, Object pojo) { + super.setCell(content, columnPosition, rowPosition, pojo); cell_textview.setText(content == null ? "" : content.toString()); // If your TableView should have auto resize for cells & columns. From 02196001e99dc917d7a4903b97042a13a8cf2de7 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Sat, 11 Mar 2023 14:02:37 +0100 Subject: [PATCH 31/35] Removed obsolete (I)Row --- .../tableview/test/data/SimpleData.java | 10 ++--- .../adapter/AbstractTableAdapter.java | 21 +++++----- .../AdapterDataSetChangedListener.java | 6 +-- .../AbstractRecyclerViewAdapter.java | 6 +-- .../recyclerview/CellRecyclerViewAdapter.java | 18 ++++----- .../filter/FilterChangedListener.java | 6 +-- .../tableview/handler/ColumnSortHandler.java | 17 ++++----- .../tableview/handler/FilterHandler.java | 32 ++++++++-------- .../tableview/handler/VisibilityHandler.java | 4 +- .../com/evrencoskun/tableview/model/IRow.java | 30 --------------- .../com/evrencoskun/tableview/model/Row.java | 38 ------------------- .../tableview/pagination/Pagination.java | 11 +++--- .../ColumnForRowHeaderSortComparator.java | 6 +-- .../tableview/sort/ColumnSortCallback.java | 8 ++-- .../sort/RowHeaderForCellSortComparator.java | 6 +-- .../tableviewutil/TableViewModel.java | 9 ++--- 16 files changed, 69 insertions(+), 159 deletions(-) delete mode 100644 tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java delete mode 100644 tableview/src/main/java/com/evrencoskun/tableview/model/Row.java diff --git a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java index 4e8ed827..00c9bbb0 100644 --- a/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java +++ b/tableview/src/androidTest/java/com/evrencoskun/tableview/test/data/SimpleData.java @@ -24,8 +24,6 @@ package com.evrencoskun.tableview.test.data; -import com.evrencoskun.tableview.model.IRow; -import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.test.models.Cell; import com.evrencoskun.tableview.test.models.ColumnHeader; import com.evrencoskun.tableview.test.models.RowHeader; @@ -34,7 +32,7 @@ import java.util.List; public class SimpleData { - private List> cells; + private List> cells; private List columnHeaders; private List rowHeaders; @@ -59,7 +57,7 @@ private void init(int columnSize, int rowSize) { cells = new ArrayList<>(); for (int i = 0; i < rowSize; i++) { - IRow cellList = new Row<>(); + List cellList = new ArrayList<>(); for (int j = 0; j < columnSize; j++) { String id = j + ":" + i; cellList.add(new Cell(id, "r:" + i + "c:" + j)); @@ -68,11 +66,11 @@ private void init(int columnSize, int rowSize) { } } - public List> getCells() { + public List> getCells() { return cells; } - public void setCells(List> cells) { + public void setCells(List> cells) { this.cells = cells; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java index 6478fe4e..45ef6354 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AbstractTableAdapter.java @@ -33,7 +33,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; @@ -60,7 +59,7 @@ public abstract class AbstractTableAdapter imp protected List mColumnHeaderItems; protected List mRowHeaderItems; - protected List> mCellItems; + protected List> mCellItems; private ITableView mTableView; private List> dataSetChangedListeners; @@ -111,7 +110,7 @@ public void setRowHeaderItems(@Nullable List rowHeaderItems) { dispatchRowHeaderDataSetChangesToListeners(mRowHeaderItems); } - public void setCellItems(@Nullable List> cellItems) { + public void setCellItems(@Nullable List> cellItems) { if (cellItems == null) { return; } @@ -128,7 +127,7 @@ public void setCellItems(@Nullable List> cellItems) { public void setAllItems( @Nullable List columnHeaderItems, @Nullable List rowHeaderItems, - @Nullable List> cellItems + @Nullable List> cellItems ) { // Set all items setColumnHeaderItems(columnHeaderItems); @@ -259,7 +258,7 @@ public RH getRowHeaderItem(int rowPosition) { @Deprecated @Nullable public C getCellItem(int columnPosition, int rowPosition) { - IRow row = getRowFromModel(rowPosition); + List row = getRowFromModel(rowPosition); if (row == null) { return null; } @@ -279,7 +278,7 @@ public C getCellItem(int columnPosition, int rowPosition) { * @param rowPosition */ @Deprecated - private IRow getRowFromModel(int rowPosition) { + private List getRowFromModel(int rowPosition) { int size = (mCellItems == null) ? 0 : mCellItems.size(); if (rowPosition < 0 || rowPosition >= size) { Log.i(tag,"getCellItems(row=" + rowPosition + @@ -290,7 +289,7 @@ private IRow getRowFromModel(int rowPosition) { } @Nullable - public IRow getCellRowItems(int rowPosition) { + public List getCellRowItems(int rowPosition) { return mCellRecyclerViewAdapter.getItem(rowPosition); } @@ -335,12 +334,12 @@ public void removeRowRange(int rowPositionStart, int itemCount, boolean updateRo mRowHeaderRecyclerViewAdapter.deleteItemRange(rowPositionStart, itemCount); } - public void addRow(int rowPosition, @Nullable RH rowHeaderItem, @Nullable IRow cellItems) { + public void addRow(int rowPosition, @Nullable RH rowHeaderItem, @Nullable List cellItems) { mCellRecyclerViewAdapter.addItem(rowPosition, cellItems); mRowHeaderRecyclerViewAdapter.addItem(rowPosition, rowHeaderItem); } - public void addRowRange(int rowPositionStart, @Nullable List rowHeaderItem, @Nullable List> cellItems) { + public void addRowRange(int rowPositionStart, @Nullable List rowHeaderItem, @Nullable List> cellItems) { mRowHeaderRecyclerViewAdapter.addItemRange(rowPositionStart, rowHeaderItem); mCellRecyclerViewAdapter.addItemRange(rowPositionStart, cellItems); } @@ -354,7 +353,7 @@ public void changeRowHeaderItemRange(int rowPositionStart, @Nullable List ro } public void changeCellItem(int columnPosition, int rowPosition, C cellModel) { - IRow cellItems = mCellRecyclerViewAdapter.getItem(rowPosition); + List cellItems = mCellRecyclerViewAdapter.getItem(rowPosition); if (cellItems != null && cellItems.size() > columnPosition) { // Update cell row items. cellItems.set(columnPosition, cellModel); @@ -418,7 +417,7 @@ private void dispatchRowHeaderDataSetChangesToListeners(@NonNull final List } } - private void dispatchCellDataSetChangesToListeners(@NonNull List> newCellItems) { + private void dispatchCellDataSetChangesToListeners(@NonNull List> newCellItems) { if (dataSetChangedListeners != null) { for (AdapterDataSetChangedListener listener : dataSetChangedListeners) { listener.onCellItemsChanged(newCellItems); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java index 80b4c59e..cf363c8a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/AdapterDataSetChangedListener.java @@ -26,8 +26,6 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.model.IRow; - import java.util.List; public abstract class AdapterDataSetChangedListener { @@ -53,7 +51,7 @@ public void onRowHeaderItemsChanged(@NonNull List rowHeaderItems) { * * @param cellItems The current cell items. */ - public void onCellItemsChanged(@NonNull List> cellItems) { + public void onCellItemsChanged(@NonNull List> cellItems) { } /** @@ -66,6 +64,6 @@ public void onCellItemsChanged(@NonNull List> cellItems) { public void onDataSetChanged( List columnHeaderItems, List rowHeaderItems, - List> cellItems) { + List> cellItems) { } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java index b402351d..c7241632 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java @@ -30,9 +30,9 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; -import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; +import java.util.ArrayList; import java.util.List; /** @@ -56,7 +56,7 @@ public AbstractRecyclerViewAdapter(@NonNull Context context, @Nullable List i mContext = context; if (itemList == null) { - mItemList = new Row<>(); + mItemList = new ArrayList<>(); } else { setItems(itemList); } @@ -77,7 +77,7 @@ public void setItems(@NonNull List itemList) { } public void setItems(@NonNull List itemList, boolean notifyDataSet) { - mItemList = new Row<>(itemList); + mItemList = new ArrayList<>(itemList); if (notifyDataSet) { this.notifyDataSetChanged(); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java index 30ab972d..7c4f4b42 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRecyclerViewAdapter.java @@ -32,9 +32,7 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; -import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; -import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder.SelectionState; import com.evrencoskun.tableview.handler.ScrollHandler; @@ -52,7 +50,7 @@ * The adapter contains a List of IRow-s of Cells */ -public class CellRecyclerViewAdapter extends AbstractRecyclerViewAdapter> { +public class CellRecyclerViewAdapter extends AbstractRecyclerViewAdapter> { @NonNull private final ITableView mTableView; @@ -62,7 +60,7 @@ public class CellRecyclerViewAdapter extends AbstractRecyclerViewAdapter> itemList, @NonNull ITableView tableView) { + public CellRecyclerViewAdapter(@NonNull Context context, @Nullable List> itemList, @NonNull ITableView tableView) { super(context, itemList); this.mTableView = tableView; @@ -124,7 +122,7 @@ public void onBindViewHolder(@NonNull AbstractViewHolder holder, int yPosition) .recyclerView.getAdapter(); // Get the list - IRow row = mItemList.get(yPosition); + List row = mItemList.get(yPosition); // Set Row position viewAdapter.setYPosition(yPosition); @@ -225,7 +223,7 @@ public List getVerticalItemsAtColumn(int columnPosition) { List columnItems = new ArrayList<>(); for (int i = 0; i < mItemList.size(); i++) { - IRow row = mItemList.get(i); + List row = mItemList.get(i); if (row.size() > columnPosition) { columnItems.add(row.get(columnPosition)); @@ -254,9 +252,9 @@ public void removeColumnItems(int column) { // Lets change the model list silently // Create a new list which the column is already removed. - List> cellItems = new ArrayList<>(); + List> cellItems = new ArrayList<>(); for (int i = 0; i < mItemList.size(); i++) { - IRow rowList = new Row<>(mItemList.get(i)); + List rowList = new ArrayList<>(mItemList.get(i)); if (rowList.size() > column) { rowList.remove(column); @@ -290,9 +288,9 @@ public void addColumnItems(int column, @NonNull List cellColumnItems) { // Lets change the model list silently - List> cellItems = new ArrayList<>(); + List> cellItems = new ArrayList<>(); for (int i = 0; i < mItemList.size(); i++) { - IRow rowList = new Row<>(mItemList.get(i)); + List rowList = new ArrayList<>(mItemList.get(i)); if (rowList.size() > column) { rowList.add(column, cellColumnItems.get(i)); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java index 2c3eec78..7fa4e51a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/filter/FilterChangedListener.java @@ -26,8 +26,6 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.model.IRow; - import java.util.List; public abstract class FilterChangedListener { @@ -38,7 +36,7 @@ public abstract class FilterChangedListener { * @param filteredCellItems The list of filtered cell items. * @param filteredRowHeaderItems The list of filtered row items. */ - public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull IRow filteredRowHeaderItems) { + public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull List filteredRowHeaderItems) { } /** @@ -47,6 +45,6 @@ public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull I * @param originalCellItems The unfiltered cell item list. * @param originalRowHeaderItems The unfiltered row header list. */ - public void onFilterCleared(@NonNull List> originalCellItems, @NonNull IRow originalRowHeaderItems) { + public void onFilterCleared(@NonNull List> originalCellItems, @NonNull List originalRowHeaderItems) { } } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java index 309446bf..bedfb7be 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/ColumnSortHandler.java @@ -28,7 +28,6 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.DiffUtil; -import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter; @@ -83,8 +82,8 @@ public void sortByRowHeader(@NonNull final SortState sortState) { List originalRowHeaderList = mRowHeaderRecyclerViewAdapter.getItems(); List sortedRowHeaderList = new ArrayList<>(originalRowHeaderList); - List> originalList = mCellRecyclerViewAdapter.getItems(); - List> sortedList = new ArrayList<>(originalList); + List> originalList = mCellRecyclerViewAdapter.getItems(); + List> sortedList = new ArrayList<>(originalList); if (sortState != SortState.UNSORTED) { // Do descending / ascending sort @@ -107,8 +106,8 @@ public void sortByRowHeader(@NonNull final SortState sortState) { } public void sort(int column, @NonNull SortState sortState) { - List> originalList = mCellRecyclerViewAdapter.getItems(); - List> sortedList = new ArrayList<>(originalList); + List> originalList = mCellRecyclerViewAdapter.getItems(); + List> sortedList = new ArrayList<>(originalList); List originalRowHeaderList = mRowHeaderRecyclerViewAdapter.getItems(); @@ -139,7 +138,7 @@ public void sort(int column, @NonNull SortState sortState) { private void swapItems(@NonNull List oldRowHeader, @NonNull List newRowHeader, - @NonNull List> newColumnItems, + @NonNull List> newColumnItems, @NonNull SortState sortState ) { @@ -161,7 +160,7 @@ private void swapItems(@NonNull List oldRowHeader, } } - private void swapItems(@NonNull List> oldItems, @NonNull List> + private void swapItems(@NonNull List> oldItems, @NonNull List> newItems, int column, @NonNull List newRowHeader, @NonNull SortState sortState) { // Set new items without calling notifyCellDataSetChanged method of CellRecyclerViewAdapter @@ -182,9 +181,9 @@ private void swapItems(@NonNull List> oldItems, @NonNull Li } } - public void swapItems(@NonNull List> newItems, int column) { + public void swapItems(@NonNull List> newItems, int column) { - List> oldItems = mCellRecyclerViewAdapter.getItems(); + List> oldItems = mCellRecyclerViewAdapter.getItems(); // Set new items without calling notifyCellDataSetChanged method of CellRecyclerViewAdapter mCellRecyclerViewAdapter.setItems(newItems, !mEnableAnimation); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java index bba8a122..82771ac8 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/FilterHandler.java @@ -26,9 +26,7 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; -import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; import com.evrencoskun.tableview.adapter.recyclerview.RowHeaderRecyclerViewAdapter; @@ -45,8 +43,8 @@ public class FilterHandler { private final CellRecyclerViewAdapter mCellRecyclerViewAdapter; private final RowHeaderRecyclerViewAdapter mRowHeaderRecyclerViewAdapter; - private List> originalCellDataStore; - private IRow originalRowDataStore; + private List> originalCellDataStore; + private List originalRowDataStore; private List> filterChangedListeners; @@ -64,20 +62,20 @@ public void filter(@NonNull Filter filter) { return; } - List> originalCellData = new ArrayList<>(originalCellDataStore); - IRow originalRowData = new Row<>(originalRowDataStore); - List> filteredCellList = new ArrayList<>(); - IRow filteredRowList = new Row<>(); + List> originalCellData = new ArrayList<>(originalCellDataStore); + List originalRowData = new ArrayList<>(originalRowDataStore); + List> filteredCellList = new ArrayList<>(); + List filteredRowList = new ArrayList<>(); if (filter.getFilterItems().isEmpty()) { filteredCellList = new ArrayList<>(originalCellDataStore); - filteredRowList = new Row<>(originalRowDataStore); + filteredRowList = new ArrayList<>(originalRowDataStore); dispatchFilterClearedToListeners(originalCellDataStore, originalRowDataStore); } else { for (int x = 0; x < filter.getFilterItems().size(); ) { final FilterItem filterItem = filter.getFilterItems().get(x); if (filterItem.getFilterType().equals(FilterType.ALL)) { - for (IRow itemsList : originalCellData) { + for (List itemsList : originalCellData) { for (T item : itemsList) { if (item .getFilterableKeyword() @@ -92,7 +90,7 @@ public void filter(@NonNull Filter filter) { } } } else { - for (IRow itemsList : originalCellData) { + for (List itemsList : originalCellData) { if (itemsList .get(filterItem .getColumn()) @@ -110,7 +108,7 @@ public void filter(@NonNull Filter filter) { // If this is the last filter to be processed, the filtered lists will not be cleared. if (++x < filter.getFilterItems().size()) { originalCellData = new ArrayList<>(filteredCellList); - originalRowData = new Row<>(filteredRowList); + originalRowData = new ArrayList<>(filteredRowList); filteredCellList.clear(); filteredRowList.clear(); } @@ -131,7 +129,7 @@ public void filter(@NonNull Filter filter) { new AdapterDataSetChangedListener() { @Override public void onRowHeaderItemsChanged(@NonNull List rowHeaderItems) { - originalRowDataStore = new Row<>(rowHeaderItems); + originalRowDataStore = new ArrayList<>(rowHeaderItems); } @Override @@ -141,8 +139,8 @@ public void onCellItemsChanged(@NonNull List cellItems) { }; private void dispatchFilterChangedToListeners( - @NonNull List> filteredCellItems, - @NonNull IRow filteredRowHeaderItems + @NonNull List> filteredCellItems, + @NonNull List filteredRowHeaderItems ) { if (filterChangedListeners != null) { for (FilterChangedListener listener : filterChangedListeners) { @@ -152,8 +150,8 @@ private void dispatchFilterChangedToListeners( } private void dispatchFilterClearedToListeners( - @NonNull List> originalCellItems, - @NonNull IRow originalRowHeaderItems + @NonNull List> originalCellItems, + @NonNull List originalRowHeaderItems ) { if (filterChangedListeners != null) { for (FilterChangedListener listener : filterChangedListeners) { diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java index a7e21c3d..d11b7276 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java @@ -30,9 +30,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AbstractTableAdapter; + import java.util.List; /** @@ -77,7 +77,7 @@ private void showRow(int row, boolean removeFromList) { if (hiddenRow != null) { // add row model to the adapter mTableView.getAdapter().addRow(row, hiddenRow.getRowHeaderModel(), - (IRow) hiddenRow.getCellModelList()); + hiddenRow.getCellModelList()); } else { Log.e(LOG_TAG, "This row is already visible."); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java b/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java deleted file mode 100644 index 33fd93d8..00000000 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/IRow.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 k3b - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.evrencoskun.tableview.model; - -import java.util.List; - -public interface IRow extends List { -} diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java deleted file mode 100644 index 381fa528..00000000 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/Row.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 k3b - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.evrencoskun.tableview.model; - -import java.util.ArrayList; -import java.util.List; - -public class Row extends ArrayList implements IRow { - public Row(List cs) { - super(cs); - } - - public Row() { - super(); - } -} diff --git a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java index 3ff56e95..44e8cc43 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/pagination/Pagination.java @@ -27,7 +27,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.evrencoskun.tableview.model.IRow; import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.AdapterDataSetChangedListener; import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter; @@ -52,7 +51,7 @@ public class Pagination implements IPagination { private int currentPage; private int pageCount; @NonNull - private List> originalCellData; + private List> originalCellData; @NonNull private List originalRowData; @Nullable @@ -117,7 +116,7 @@ private void reloadPages() { private void paginateData() { int start, end; - List> currentPageCellData = new ArrayList<>(); + List> currentPageCellData = new ArrayList<>(); List currentPageRowData = new ArrayList<>(); // No pagination if itemsPerPage is 0, all data will be loaded into the TableView. if (itemsPerPage == 0) { @@ -227,14 +226,14 @@ public void onCellItemsChanged(@NonNull List cellItems) { private final FilterChangedListener filterChangedListener = new FilterChangedListener() { @Override - public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull IRow filteredRowHeaderItems) { + public void onFilterChanged(@NonNull List> filteredCellItems, @NonNull List filteredRowHeaderItems) { originalCellData = new ArrayList<>(filteredCellItems); originalRowData = new ArrayList<>(filteredRowHeaderItems); reloadPages(); } @Override - public void onFilterCleared(@NonNull List> originalCellItems, @NonNull IRow originalRowHeaderItems) { + public void onFilterCleared(@NonNull List> originalCellItems, @NonNull List originalRowHeaderItems) { originalCellData = new ArrayList<>(originalCellItems); originalRowData = new ArrayList<>(originalRowHeaderItems); reloadPages(); @@ -257,7 +256,7 @@ public void onRowHeaderSortStatusChanged(@NonNull SortState sortState) { private void paginateOnColumnSort(int column, @NonNull SortState sortState) { List sortedRowHeaderList = new ArrayList<>(originalRowData); - List> sortedList = new ArrayList<>(originalCellData); + List> sortedList = new ArrayList<>(originalCellData); if (sortState != SortState.UNSORTED) { if (column == -1) { Collections.sort(sortedRowHeaderList, new RowHeaderSortComparator(sortState)); diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java index 7744dc9f..62443f13 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnForRowHeaderSortComparator.java @@ -26,8 +26,6 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.model.IRow; - import java.util.Comparator; import java.util.List; @@ -43,7 +41,7 @@ public class ColumnForRowHeaderSortComparator implements Comparator mRowHeaderList; @NonNull - private final List> mReferenceList; + private final List> mReferenceList; private final int column; @NonNull private final SortState mSortState; @@ -51,7 +49,7 @@ public class ColumnForRowHeaderSortComparator implements Comparator rowHeader, - @NonNull List> referenceList, + @NonNull List> referenceList, int column, @NonNull SortState sortState) { this.mRowHeaderList = rowHeader; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java index 7ee02d35..a2bbee5d 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/ColumnSortCallback.java @@ -28,8 +28,6 @@ import androidx.core.util.ObjectsCompat; import androidx.recyclerview.widget.DiffUtil; -import com.evrencoskun.tableview.model.IRow; - import java.util.List; /** @@ -38,12 +36,12 @@ public class ColumnSortCallback extends DiffUtil.Callback { @NonNull - private final List> mOldCellItems; + private final List> mOldCellItems; @NonNull - private final List> mNewCellItems; + private final List> mNewCellItems; private final int mColumnPosition; - public ColumnSortCallback(@NonNull List> oldCellItems, @NonNull List> + public ColumnSortCallback(@NonNull List> oldCellItems, @NonNull List> newCellItems, int column) { this.mOldCellItems = oldCellItems; this.mNewCellItems = newCellItems; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java index 30aa8884..4a6d8685 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/sort/RowHeaderForCellSortComparator.java @@ -26,8 +26,6 @@ import androidx.annotation.NonNull; -import com.evrencoskun.tableview.model.IRow; - import java.util.Comparator; import java.util.List; @@ -39,14 +37,14 @@ public class RowHeaderForCellSortComparator implements Comparator mReferenceList; @NonNull - private final List> mColumnList; + private final List> mColumnList; @NonNull private final SortState mSortState; @NonNull private final RowHeaderSortComparator mRowHeaderSortComparator; public RowHeaderForCellSortComparator(@NonNull List referenceList, - @NonNull List> columnList, + @NonNull List> columnList, @NonNull SortState sortState) { this.mReferenceList = referenceList; this.mColumnList = columnList; diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java index 99a42c3f..771f659e 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java @@ -28,9 +28,6 @@ import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableview.model.IColumnValueProvider; import com.evrencoskun.tableview.model.IModelWithId; -import com.evrencoskun.tableview.model.IRow; -import com.evrencoskun.tableview.model.IViewHolderFactory; -import com.evrencoskun.tableview.model.Row; import com.evrencoskun.tableview.model.RowHeader; import java.util.ArrayList; @@ -49,11 +46,11 @@ public TableViewModel(List> columnDefinitions, List } @NonNull - public List>> getCellList() { - List>> list = new ArrayList<>(); + public List>> getCellList() { + List>> list = new ArrayList<>(); int numberOfColumns = columnDefinitions.size(); for (POJO pojo : pojos) { - IRow> cellList = new Row<>(); + List> cellList = new ArrayList<>(); for (int colId = 0; colId < numberOfColumns; colId++) { IColumnValueProvider provider = columnDefinitions.get(colId).getPojoToCellValueProvider(); From 1b903999818966241a770a732d443c470d73698e Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Sat, 11 Mar 2023 14:18:17 +0100 Subject: [PATCH 32/35] Fixed Rowheader-pojo --- .../com/evrencoskun/tableviewutil/TableViewAdapter.java | 2 +- .../tableviewutil/holder/BoolDrawableCellViewHolder.java | 2 +- .../tableviewutil/holder/RowHeaderViewHolder.java | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java index 5fc815d0..9dcdc947 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java @@ -239,7 +239,7 @@ public void onBindRowHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nulla // Get the holder to update row header item text RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder; - rowHeaderViewHolder.row_header_textview.setText(String.valueOf(rowHeaderItemModel.getId())); + rowHeaderViewHolder.setCell(rowHeaderItemModel.getId(),-1, rowPosition, rowHeaderItemModel.getData()); } @NonNull diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java index cd651989..526e9b29 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java @@ -40,7 +40,7 @@ public class BoolDrawableCellViewHolder extends AbstractViewHolder { @NonNull - public final ImageView cell_image; + private final ImageView cell_image; @DrawableRes private final int mIdDrawableTrue; @DrawableRes private final int mIdDrawableFalse; diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/RowHeaderViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/RowHeaderViewHolder.java index 7adae523..4f796f4c 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/RowHeaderViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/RowHeaderViewHolder.java @@ -28,6 +28,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.evrencoskun.tableviewutil.R; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; @@ -38,10 +39,15 @@ public class RowHeaderViewHolder extends AbstractViewHolder { @NonNull - public final TextView row_header_textview; + private final TextView row_header_textview; public RowHeaderViewHolder(@NonNull View itemView) { super(itemView); row_header_textview = itemView.findViewById(R.id.row_header_textview); } + + public void setCell(@Nullable Object content, int columnPosition, int rowPosition, @Nullable Object pojo) { + super.setCell(content,columnPosition,rowPosition,pojo); + row_header_textview.setText(String.valueOf(content)); + } } From d724d1e0ecc198a93b943ecd1dd0f8448b420b11 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Sat, 11 Mar 2023 14:43:06 +0100 Subject: [PATCH 33/35] Fixed ColumnHeader --- .../tableview/TableViewListener.java | 24 +++++++++---------- .../tableviewutil/ColumnDefinition.java | 7 ++++++ .../tableviewutil/TableViewAdapter.java | 15 ++++++++---- .../holder/BoolDrawableCellViewHolder.java | 3 +++ .../holder/ColumnHeaderViewHolder.java | 5 +++- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java index 72862d70..fbaf1775 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TableViewListener.java @@ -62,12 +62,12 @@ public TableViewListener(@NonNull TableView tableView) { */ @Override public void onCellClicked(@NonNull RecyclerView.ViewHolder cellView, int column, int row) { - showToast("Cell " + getMessageContext(cellView, column, row, "clicked")); + showToast("onCellClicked" + getMessageContext(cellView, column, row)); } @NonNull - private String getMessageContext(RecyclerView.ViewHolder cellView, int column, int row, String action) { + private String getMessageContext(RecyclerView.ViewHolder cellView, int column, int row) { String data = ""; if (cellView instanceof AbstractViewHolder) { final Object pojo = ((AbstractViewHolder) cellView).getPojo(); @@ -75,9 +75,7 @@ private String getMessageContext(RecyclerView.ViewHolder cellView, int column, i data = pojo.toString(); } } - return "" + column + " " + row + " has been " + - action + - " for " + data + " [" + + return "(c=" + column + ",r=" + row + ") for " + data + " [" + cellView.getClass().getSimpleName() + ".]"; } @@ -91,7 +89,7 @@ private String getMessageContext(RecyclerView.ViewHolder cellView, int column, i @Override public void onCellDoubleClicked(@NonNull RecyclerView.ViewHolder cellView, int column, int row) { // Do what you want. - showToast("Cell " + getMessageContext(cellView, column, row, "double clicked")); + showToast("onCellDoubleClicked" + getMessageContext(cellView, column, row)); } /** @@ -105,7 +103,7 @@ public void onCellDoubleClicked(@NonNull RecyclerView.ViewHolder cellView, int c public void onCellLongPressed(@NonNull RecyclerView.ViewHolder cellView, final int column, int row) { // Do What you want - showToast("Cell " + getMessageContext(cellView, column, row, "long pressed")); + showToast("onCellLongPressed" + getMessageContext(cellView, column, row)); } /** @@ -118,7 +116,7 @@ public void onCellLongPressed(@NonNull RecyclerView.ViewHolder cellView, final i public void onColumnHeaderClicked(@NonNull RecyclerView.ViewHolder columnHeaderView, int column) { // Do what you want. - showToast("Column header " + getMessageContext(columnHeaderView, column, -1, "clicked")); + showToast("onColumnHeaderClicked" + getMessageContext(columnHeaderView, column, -1)); } /** @@ -130,7 +128,7 @@ public void onColumnHeaderClicked(@NonNull RecyclerView.ViewHolder columnHeaderV @Override public void onColumnHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder columnHeaderView, int column) { // Do what you want. - showToast("Column header " + getMessageContext(columnHeaderView, column, -1, "double clicked")); + showToast("onColumnHeaderDoubleClicked" + getMessageContext(columnHeaderView, column, -1)); } /** @@ -142,7 +140,7 @@ public void onColumnHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder columnH @Override public void onColumnHeaderLongPressed(@NonNull RecyclerView.ViewHolder columnHeaderView, int column) { - showToast("Column header " + getMessageContext(columnHeaderView, column, -1, "long pressed")); + showToast("onColumnHeaderLongPressed" + getMessageContext(columnHeaderView, column, -1)); if (columnHeaderView instanceof ColumnHeaderViewHolder) { // Create Long Press Popup @@ -162,7 +160,7 @@ public void onColumnHeaderLongPressed(@NonNull RecyclerView.ViewHolder columnHea @Override public void onRowHeaderClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) { // Do whatever you want. - showToast("Row header " + getMessageContext(rowHeaderView, -1, row, "clicked")); + showToast("onRowHeaderClicked" + getMessageContext(rowHeaderView, -1, row)); } /** @@ -174,7 +172,7 @@ public void onRowHeaderClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, i @Override public void onRowHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) { // Do whatever you want. - showToast("Row header " + getMessageContext(rowHeaderView, -1, row, "double clicked")); + showToast("onRowHeaderDoubleClicked" + getMessageContext(rowHeaderView, -1, row)); } /** @@ -185,7 +183,7 @@ public void onRowHeaderDoubleClicked(@NonNull RecyclerView.ViewHolder rowHeaderV */ @Override public void onRowHeaderLongPressed(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) { - showToast("Row header " + getMessageContext(rowHeaderView, -1, row, "long pressed")); + showToast("onRowHeaderLongPressed" + getMessageContext(rowHeaderView, -1, row)); // Create Long Press Popup RowHeaderLongPressPopup popup = new RowHeaderLongPressPopup(rowHeaderView, mTableView, row); diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java index ec278fae..8342cb7b 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java @@ -68,4 +68,11 @@ public ColumnDefinition( @Nullable public IViewHolderFactory getViewHolderFactory() { return viewHolderFactory; } + + @Override + public String toString() { + return "ColumnDefinition{" + + "columnHeaderText='" + columnHeaderText + '\'' + + '}'; + } } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java index 9dcdc947..e5c0b236 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java @@ -101,8 +101,7 @@ public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup pare @Override public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String columnHeader, int columnPosition) { - - holder.setCell(columnHeader, columnPosition,0, null); + holder.setCell(columnHeader, columnPosition,0, getColumnDefinition(columnPosition)); } /** @@ -139,8 +138,9 @@ public int getCellItemViewType(int columnNumber) { } private IViewHolderFactory getViewHolderFactory(int column,@Nullable IViewHolderFactory notFoundValue) { - if (columnDefinitions != null && column >= 0 && column < columnDefinitions.size()) { - IViewHolderFactory factory = columnDefinitions.get(column).getViewHolderFactory(); + ColumnDefinition definition = getColumnDefinition(column); + if (definition != null) { + IViewHolderFactory factory = definition.getViewHolderFactory(); if (factory != null) { return factory; } @@ -148,6 +148,13 @@ private IViewHolderFactory getViewHolderFactory(int column,@Nullable IViewHolder return notFoundValue; } + private ColumnDefinition getColumnDefinition(int column) { + if (columnDefinitions != null && column >= 0 && column < columnDefinitions.size()) { + return columnDefinitions.get(column); + } + return null; + } + /** * For cells that display a text * diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java index 526e9b29..57f5d9dd 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java @@ -56,6 +56,9 @@ public void setCell(@Nullable Object content, int columnPosition, int rowPositio setData(content == null ? null : (Boolean) content); } + /** + * @deprecated use {@link #setCell(Object, int, int, Object)} instead + */ public void setData(Boolean data) { if (data != null) { int moodDrawable = data ? mIdDrawableTrue : mIdDrawableFalse; diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java index 5e4b37a5..9a687eb7 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java @@ -66,13 +66,16 @@ public ColumnHeaderViewHolder(@NonNull View itemView, @Nullable ITableView table column_header_sortButton.setOnClickListener(mSortButtonClickListener); } + /** + * This method is called from onBindColumnHeaderHolder on TableViewAdapter + */ public void setCell(@Nullable Object content, int columnPosition, int rowPosition, Object pojo) { super.setCell(content, columnPosition, rowPosition, pojo); setColumnHeader(content == null ? "" : content.toString()); } /** - * This method is calling from onBindColumnHeaderHolder on TableViewAdapter + * @deprecated use {@link #setCell(Object, int, int, Object)} instead */ public void setColumnHeader(@Nullable String columnHeader) { column_header_textview.setText(columnHeader); From 08cd72152ad7f285a06e7871a9b6ed9d98df1c59 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Mon, 13 Mar 2023 09:18:31 +0100 Subject: [PATCH 34/35] Reverted ColumnHeader from String back to ColumnDefinition --- .../tableviewsample/MainFragment.java | 4 +-- .../tableviewsample/tableview/TestData.java | 2 +- .../com/evrencoskun/tableview/TableView.java | 16 +++++------ .../tableview/handler/VisibilityHandler.java | 4 ++- .../com/evrencoskun/tableview/model/Cell.java | 1 + .../tableview/model}/ColumnDefinition.java | 2 +- .../tableviewutil/TableViewAdapter.java | 27 +++++++++---------- .../tableviewutil/TableViewModel.java | 10 +++---- .../holder/BoolDrawableCellViewHolder.java | 15 ++++++++++- .../holder/ColumnHeaderViewHolder.java | 7 ++--- 10 files changed, 49 insertions(+), 39 deletions(-) rename {tableviewutil/src/main/java/com/evrencoskun/tableviewutil => tableview/src/main/java/com/evrencoskun/tableview/model}/ColumnDefinition.java (98%) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java index 1350787c..87344f66 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/MainFragment.java @@ -47,7 +47,7 @@ import com.evrencoskun.tableviewutil.TableViewModel; import com.evrencoskun.tableviewsample.tableview.TestData; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; -import com.evrencoskun.tableviewutil.ColumnDefinition; +import com.evrencoskun.tableview.model.ColumnDefinition; import java.util.List; @@ -129,7 +129,7 @@ private void initializeTableView() { TableViewModel tableViewModel = new TableViewModel(columnDefinitions, pojos); // Create TableView Adapter - TableViewAdapter tableViewAdapter = new TableViewAdapter<>(columnDefinitions); + TableViewAdapter tableViewAdapter = new TableViewAdapter<>(); mTableView.setAdapter(tableViewAdapter); mTableView.setTableViewListener(new TableViewListener(mTableView)); diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java index 3b228bf1..298f9c12 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java @@ -26,7 +26,7 @@ import com.evrencoskun.tableviewsample.R; import com.evrencoskun.tableviewsample.tableview.model.MySamplePojo; -import com.evrencoskun.tableviewutil.ColumnDefinition; +import com.evrencoskun.tableview.model.ColumnDefinition; import com.evrencoskun.tableviewutil.TableViewAdapter; import java.util.ArrayList; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java index 65876c54..2dc8a119 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java @@ -241,9 +241,9 @@ private void initialDefaultValues(@Nullable AttributeSet attrs) { public void initialize() { // Create Views - mColumnHeaderRecyclerView = createColumnHeaderRecyclerView(); - mRowHeaderRecyclerView = createRowHeaderRecyclerView(); - mCellRecyclerView = createCellRecyclerView(); + if (mColumnHeaderRecyclerView == null) mColumnHeaderRecyclerView = createColumnHeaderRecyclerView(); + if (mRowHeaderRecyclerView == null) mRowHeaderRecyclerView = createRowHeaderRecyclerView(); + if (mCellRecyclerView == null) mCellRecyclerView = createCellRecyclerView(); // Set some Id to help in identification mColumnHeaderRecyclerView.setId(R.id.ColumnHeaderRecyclerView); @@ -256,11 +256,11 @@ public void initialize() { addView(mCellRecyclerView); // Create Handlers - mSelectionHandler = new SelectionHandler(this); - mVisibilityHandler = new VisibilityHandler(this); - mScrollHandler = new ScrollHandler(this); - mPreferencesHandler = new PreferencesHandler(this); - mColumnWidthHandler = new ColumnWidthHandler(this); + if (mSelectionHandler == null) mSelectionHandler = new SelectionHandler(this); + if (mVisibilityHandler == null) mVisibilityHandler = new VisibilityHandler(this); + if (mScrollHandler == null) mScrollHandler = new ScrollHandler(this); + if (mPreferencesHandler == null) mPreferencesHandler = new PreferencesHandler(this); + if (mColumnWidthHandler == null) mColumnWidthHandler = new ColumnWidthHandler(this); initializeListeners(); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java index d11b7276..49a46a4a 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java @@ -45,7 +45,10 @@ public class VisibilityHandler { @NonNull private final ITableView mTableView; @NonNull + /** Remember all existing rows that are currently hidden */ private SparseArray mHideRowList = new SparseArray<>(); + + /** Remember all existing columns that are currently hidden */ @NonNull private SparseArray mHideColumnList = new SparseArray<>(); @@ -237,7 +240,6 @@ public Object getColumnHeaderModel() { public List getCellModelList() { return mCellModelList; } - } @NonNull diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java index 1eec584b..02f73095 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java @@ -46,6 +46,7 @@ public class Cell implements ISortableModel, IFiltera */ public Cell(@NonNull POJO data, IColumnValueProvider columnValueProvider) { this.mData = data; + //!!! TODO bug ??? wrong column content this.columnValueProvider = columnValueProvider; } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java b/tableview/src/main/java/com/evrencoskun/tableview/model/ColumnDefinition.java similarity index 98% rename from tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java rename to tableview/src/main/java/com/evrencoskun/tableview/model/ColumnDefinition.java index 8342cb7b..62ab6d14 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/ColumnDefinition.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/ColumnDefinition.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package com.evrencoskun.tableviewutil; +package com.evrencoskun.tableview.model; import androidx.annotation.NonNull; import androidx.annotation.Nullable; diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java index e5c0b236..30d1cf40 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java @@ -35,6 +35,7 @@ import com.evrencoskun.tableview.adapter.AbstractTableAdapter; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; +import com.evrencoskun.tableview.model.ColumnDefinition; import com.evrencoskun.tableview.model.IModelWithId; import com.evrencoskun.tableview.model.IViewHolderFactory; import com.evrencoskun.tableview.sort.SortState; @@ -45,23 +46,17 @@ import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableview.model.RowHeader; -import java.util.List; - /** * Generic adapter that translates a POJO to TableView-Cells. * * Defaultimplementation translates all columns to TextView fields. */ public class TableViewAdapter - extends AbstractTableAdapter> { - private static final String LOG_TAG = TableViewAdapter.class.getSimpleName(); - + extends AbstractTableAdapter, RowHeader, Cell> { public static final int COLUMN_TYPE_GENERIC = 9999; - @Nullable private final List> columnDefinitions; - public TableViewAdapter(@Nullable List> columnDefinitions) { + public TableViewAdapter() { super(); - this.columnDefinitions = columnDefinitions; } /** @@ -93,15 +88,17 @@ public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup pare * @param holder : This is one of your column header ViewHolders that was created * on ```onCreateColumnHeaderViewHolder``` method. In this example * we have created "ColumnHeaderViewHolder" holder. - * @param columnHeader : This is the column header located on this X - * position. In this example, the model class is "String". + * @param columnHeader : This is the column header located on this X position. In this + * example, the header is ColumnDefinition.getColumnHeaderText(). * @param columnPosition : This is the X (Column) position of the column header item. * @see #onCreateColumnHeaderViewHolder(ViewGroup, int) ; */ @Override - public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, @Nullable String - columnHeader, int columnPosition) { - holder.setCell(columnHeader, columnPosition,0, getColumnDefinition(columnPosition)); + public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, + @Nullable ColumnDefinition columnHeader, + int columnPosition) { + //!!! TODO + holder.setCell(columnHeader, columnPosition,-1, getColumnDefinition(columnPosition)); } /** @@ -149,8 +146,8 @@ private IViewHolderFactory getViewHolderFactory(int column,@Nullable IViewHolder } private ColumnDefinition getColumnDefinition(int column) { - if (columnDefinitions != null && column >= 0 && column < columnDefinitions.size()) { - return columnDefinitions.get(column); + if (mColumnHeaderItems != null && column >= 0 && column < mColumnHeaderItems.size()) { + return mColumnHeaderItems.get(column); } return null; } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java index 771f659e..875e09ef 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java @@ -26,6 +26,7 @@ import androidx.annotation.NonNull; import com.evrencoskun.tableview.model.Cell; +import com.evrencoskun.tableview.model.ColumnDefinition; import com.evrencoskun.tableview.model.IColumnValueProvider; import com.evrencoskun.tableview.model.IModelWithId; import com.evrencoskun.tableview.model.RowHeader; @@ -65,13 +66,8 @@ public List>> getCellList() { } @NonNull - public List getColumnHeaderList() { - List list = new ArrayList<>(); - - for (ColumnDefinition c : columnDefinitions) { - list.add(c.getColumnHeaderText()); - } - return list; + public List> getColumnHeaderList() { + return columnDefinitions; } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java index 57f5d9dd..67b7b023 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/BoolDrawableCellViewHolder.java @@ -24,6 +24,7 @@ package com.evrencoskun.tableviewutil.holder; +import android.util.Log; import android.view.View; import android.widget.ImageView; @@ -53,7 +54,19 @@ public BoolDrawableCellViewHolder(@NonNull View itemView, @DrawableRes int idDra public void setCell(@Nullable Object content, int columnPosition, int rowPosition, Object pojo) { super.setCell(content, columnPosition, rowPosition, pojo); - setData(content == null ? null : (Boolean) content); + if (content == null) { + setData(null); + } else if (!(content instanceof Boolean)) { + //!!! TODO bug ??? wrong column content + Log.w(this.getClass().getSimpleName(), "setCell('" + content + + "', " + columnPosition + ", " + + rowPosition + ", " + + pojo + + ")"); + setData(null); + } else { + setData((Boolean) content); + } } /** diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java index 9a687eb7..759d8057 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/holder/ColumnHeaderViewHolder.java @@ -35,6 +35,7 @@ import com.evrencoskun.tableview.ITableView; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder; +import com.evrencoskun.tableview.model.ColumnDefinition; import com.evrencoskun.tableview.sort.SortState; import com.evrencoskun.tableviewutil.R; @@ -71,14 +72,14 @@ public ColumnHeaderViewHolder(@NonNull View itemView, @Nullable ITableView table */ public void setCell(@Nullable Object content, int columnPosition, int rowPosition, Object pojo) { super.setCell(content, columnPosition, rowPosition, pojo); - setColumnHeader(content == null ? "" : content.toString()); + setColumnHeader((ColumnDefinition) pojo); } /** * @deprecated use {@link #setCell(Object, int, int, Object)} instead */ - public void setColumnHeader(@Nullable String columnHeader) { - column_header_textview.setText(columnHeader); + public void setColumnHeader(@Nullable ColumnDefinition columnHeader) { + column_header_textview.setText(columnHeader != null ? columnHeader.getColumnHeaderText() : null); // If your TableView should have auto resize for cells & columns. // Then you should consider the below lines. Otherwise, you can remove them. From a254f2fbb4d139068ff142ec1ac098d83d598858 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Fri, 17 Mar 2023 08:31:25 +0100 Subject: [PATCH 35/35] fix: reimplemented ViewHolderTypId so that show/hide column works --- .../tableviewsample/tableview/TestData.java | 18 ++++---- .../CellRowRecyclerViewAdapter.java | 3 +- .../com/evrencoskun/tableview/model/Cell.java | 15 +++--- .../tableview/model/ColumnDefinition.java | 24 +++++++++- .../tableviewutil/TableViewAdapter.java | 46 ++++++++++--------- .../tableviewutil/TableViewModel.java | 6 +-- 6 files changed, 68 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java index 298f9c12..471ee7b6 100644 --- a/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java +++ b/app/src/main/java/com/evrencoskun/tableviewsample/tableview/TestData.java @@ -45,9 +45,6 @@ public class TestData { public static final int COLUMN_INDEX_MOOD_HAPPY = 3; public static final int COLUMN_INDEX_GENDER_MALE = 4; - public static final int COLUMN_TYPE_GENERIC = TableViewAdapter.COLUMN_TYPE_GENERIC; - - // Constant size for dummy data sets private static final int COLUMN_SIZE = 500; private static final int ROW_SIZE = 500; @@ -65,15 +62,18 @@ public static List> createColumnDefinitions() { definitions.addAll( // column 0..4 userdefined Arrays.asList( - new ColumnDefinition<>("Random 0", r -> r.mRandom, null), - new ColumnDefinition<>("Short 1", r -> r.mRandomShort, null), - new ColumnDefinition<>("Text 2", r1 -> r1.mText, null), + new ColumnDefinition<>("Random 0", r -> r.mRandom), + new ColumnDefinition<>("Short 1", r -> r.mRandomShort), + new ColumnDefinition<>("Text 2", r1 -> r1.mText), // column 3..4 contain image new ColumnDefinition<>("Gender 3", r -> r.mGenderMale, - parent -> TableViewAdapter.createBoolDrawableCellViewHolder(parent, R.drawable.ic_male, R.drawable.ic_female)), + parent -> TableViewAdapter.createBoolDrawableCellViewHolder(parent, R.drawable.ic_male, R.drawable.ic_female), + COLUMN_INDEX_GENDER_MALE), new ColumnDefinition<>("Mood 4", r -> r.mMoodHappy, - parent -> TableViewAdapter.createBoolDrawableCellViewHolder(parent, R.drawable.ic_happy ,R.drawable.ic_sad)))); + parent -> TableViewAdapter.createBoolDrawableCellViewHolder(parent, R.drawable.ic_happy ,R.drawable.ic_sad), + COLUMN_INDEX_MOOD_HAPPY) + )); // column 5..500 contain generic text for (int i = 5; i < COLUMN_SIZE;i++) { @@ -81,7 +81,7 @@ public static List> createColumnDefinitions() { boolean large = new Random().nextBoolean(); definitions.add(new ColumnDefinition<>( (large ? "Lage Column " : "Column ") + i, - r -> r.getColumnValue(columnNumber), null)); + r -> r.getColumnValue(columnNumber))); } return definitions; } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java index 86c60367..bb47eb9d 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/CellRowRecyclerViewAdapter.java @@ -33,6 +33,7 @@ import com.evrencoskun.tableview.adapter.ITableAdapter; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder.SelectionState; +import com.evrencoskun.tableview.model.Cell; import com.evrencoskun.tableview.sort.ISortableModel; /** @@ -74,7 +75,7 @@ public void setYPosition(int rowPosition) { @Override public int getItemViewType(int position) { - return mTableAdapter.getCellItemViewType(position); + return ((Cell) getItem(position)).getColumnType(); } @Override diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java index 02f73095..3abaef61 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/Cell.java @@ -37,17 +37,15 @@ public class Cell implements ISortableModel, IFilterableModel { @NonNull private final POJO mData; - private final IColumnValueProvider columnValueProvider; + private final ColumnDefinition columnDefinition; /** - * * @param data the row where the cell data belongs to. - * @param columnValueProvider that gets the cell value out of the data-row + * @param columnDefinition defines mapping from pojo to content and optional viewHolderId for non standard viewholders */ - public Cell(@NonNull POJO data, IColumnValueProvider columnValueProvider) { + public Cell(@NonNull POJO data, ColumnDefinition columnDefinition) { this.mData = data; - //!!! TODO bug ??? wrong column content - this.columnValueProvider = columnValueProvider; + this.columnDefinition = columnDefinition; } /** @@ -67,9 +65,12 @@ public String getId() { @Nullable @Override public Object getContent() { - return columnValueProvider.get(mData); + return columnDefinition.getPojoToCellValueProvider().get(mData); } + public int getColumnType() { + return columnDefinition.getColumnType(); + } @Nullable public POJO getData() { return mData; diff --git a/tableview/src/main/java/com/evrencoskun/tableview/model/ColumnDefinition.java b/tableview/src/main/java/com/evrencoskun/tableview/model/ColumnDefinition.java index 62ab6d14..a3eabe1b 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/model/ColumnDefinition.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/model/ColumnDefinition.java @@ -24,6 +24,8 @@ package com.evrencoskun.tableview.model; +import android.util.SparseArray; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -35,23 +37,40 @@ * @param */ public class ColumnDefinition { + public static final int COLUMN_TYPE_GENERIC = 9999; @NonNull private final String columnHeaderText; @NonNull private final IColumnValueProvider pojoToCellValueProvider; @Nullable private final IViewHolderFactory viewHolderFactory; + private final int columnType; + + private static SparseArray typId2ViewHolderFactory = new SparseArray<>(); + /** * Constructor * @param columnHeaderText text to be displayed as column header * @param pojoToCellValueProvider translates POJO to cell column Text * @param viewHolderFactory creates view with viewholder for this column. null means default viewholder + * @param columnType id of the used viewHolderFactory (must be unique for each viewholder-type). COLUMN_TYPE_GENERIC means default viewholder */ public ColumnDefinition( @NonNull String columnHeaderText, @NonNull IColumnValueProvider pojoToCellValueProvider, - @Nullable IViewHolderFactory viewHolderFactory) { + @Nullable IViewHolderFactory viewHolderFactory, + int columnType) { this.columnHeaderText = columnHeaderText; this.pojoToCellValueProvider = pojoToCellValueProvider; this.viewHolderFactory = viewHolderFactory; + this.columnType = columnType; + if (columnType != COLUMN_TYPE_GENERIC) { + typId2ViewHolderFactory.append(columnType, viewHolderFactory); + } + } + + public ColumnDefinition( + @NonNull String columnHeaderText, + @NonNull IColumnValueProvider pojoToCellValueProvider) { + this(columnHeaderText,pojoToCellValueProvider,null, COLUMN_TYPE_GENERIC); } /** text to be displayed as column header */ @@ -75,4 +94,7 @@ public String toString() { "columnHeaderText='" + columnHeaderText + '\'' + '}'; } + public int getColumnType() { + return columnType; + } } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java index 30d1cf40..8a6c4189 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewAdapter.java @@ -53,7 +53,6 @@ */ public class TableViewAdapter extends AbstractTableAdapter, RowHeader, Cell> { - public static final int COLUMN_TYPE_GENERIC = 9999; public TableViewAdapter() { super(); @@ -64,13 +63,13 @@ public TableViewAdapter() { * Column Header RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given * type to represent an item. * - * @param viewType : This value comes from "getColumnHeaderItemViewType" method to support + * @param viewholderTypeId : This value comes from "getColumnHeaderItemViewType" method to support * different type of viewHolder as a Column Header item. * @see #getColumnHeaderItemViewType(int); */ @NonNull @Override - public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { + public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewholderTypeId) { View layout = LayoutInflater.from(parent.getContext()) .inflate(R.layout.table_view_column_header_layout, parent, false); @@ -106,36 +105,28 @@ public void onBindColumnHeaderViewHolder(@NonNull AbstractViewHolder holder, * RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given type to * represent an item. * - * @param viewType : This value comes from "getCellItemViewType" method to support different + * @param viewholderTypeId : This value comes from "getCellItemViewType" method to support different * type of viewHolder as a Cell item. * @see #getCellItemViewType(int); */ @NonNull @Override - public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int viewType) { - return getViewHolderFactory(viewType, TableViewAdapter::createGenericTextCellViewHolder).createViewHolder(parent); + public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int viewholderTypeId) { + return getViewHolderFactoryById(viewholderTypeId, TableViewAdapter::createGenericTextCellViewHolder).createViewHolder(parent); } /** - * Translates columnNumber to CellItemViewType. + * Translates columnNumber to CellItemViewType (viewholderTypeId). * * @return columnNumber or COLUMN_TYPE_GENERIC if there is no special CellItemViewType */ @Override public int getCellItemViewType(int columnNumber) { - IViewHolderFactory viewHolderFactory = getViewHolderFactory(columnNumber, null); - - if (viewHolderFactory != null) { - // if columnDefinitions found use columnNumber as returned viewtype - return columnNumber; - } - - // if no specialised viewType is found use generic - return COLUMN_TYPE_GENERIC; + return getViewHolderTypeId(columnNumber,ColumnDefinition.COLUMN_TYPE_GENERIC); } - private IViewHolderFactory getViewHolderFactory(int column,@Nullable IViewHolderFactory notFoundValue) { - ColumnDefinition definition = getColumnDefinition(column); + private IViewHolderFactory getViewHolderFactoryById(int viewholderTypeId, @Nullable IViewHolderFactory notFoundValue) { + ColumnDefinition definition = getColumnDefinition(viewholderTypeId); if (definition != null) { IViewHolderFactory factory = definition.getViewHolderFactory(); if (factory != null) { @@ -145,6 +136,17 @@ private IViewHolderFactory getViewHolderFactory(int column,@Nullable IViewHolder return notFoundValue; } + private int getViewHolderTypeId(int column, @Nullable int notFoundValue) { + ColumnDefinition definition = getColumnDefinition(column); + if (definition != null) { + int id = definition.getColumnType(); + if (id != ColumnDefinition.COLUMN_TYPE_GENERIC) { + return id; + } + } + return notFoundValue; + } + private ColumnDefinition getColumnDefinition(int column) { if (mColumnHeaderItems != null && column >= 0 && column < mColumnHeaderItems.size()) { return mColumnHeaderItems.get(column); @@ -209,13 +211,13 @@ public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable C * Row Header RecyclerView of the TableView needs a new RecyclerView.ViewHolder of the given * type to represent an item. * - * @param viewType : This value comes from "getRowHeaderItemViewType" method to support + * @param viewholderTypeId : This value comes from "getRowHeaderItemViewType" method to support * different type of viewHolder as a row Header item. * @see #getRowHeaderItemViewType(int); */ @NonNull @Override - public AbstractViewHolder onCreateRowHeaderViewHolder(@NonNull ViewGroup parent, int viewType) { + public AbstractViewHolder onCreateRowHeaderViewHolder(@NonNull ViewGroup parent, int viewholderTypeId) { // Get Row Header xml Layout View layout = LayoutInflater.from(parent.getContext()) .inflate(R.layout.table_view_row_header_layout, parent, false); @@ -272,7 +274,7 @@ public int getColumnHeaderItemViewType(int position) { // If you have different items for Cell View by X (Column) position, // then you should fill this method to be able create different // type of GenericTextCellViewHolder on "onCreateCellViewHolder" - return COLUMN_TYPE_GENERIC; + return ColumnDefinition.COLUMN_TYPE_GENERIC; } @Override @@ -281,6 +283,6 @@ public int getRowHeaderItemViewType(int position) { // If you have different items for Row Header View by Y (Row) position, // then you should fill this method to be able create different // type of RowHeaderViewHolder on "onCreateRowHeaderViewHolder" - return COLUMN_TYPE_GENERIC; + return ColumnDefinition.COLUMN_TYPE_GENERIC; } } diff --git a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java index 875e09ef..c4cd1077 100644 --- a/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java +++ b/tableviewutil/src/main/java/com/evrencoskun/tableviewutil/TableViewModel.java @@ -53,10 +53,8 @@ public List>> getCellList() { for (POJO pojo : pojos) { List> cellList = new ArrayList<>(); for (int colId = 0; colId < numberOfColumns; colId++) { - IColumnValueProvider provider = - columnDefinitions.get(colId).getPojoToCellValueProvider(); - - Cell cell = new Cell(pojo, provider); + ColumnDefinition columnDefinition = columnDefinitions.get(colId); + Cell cell = new Cell(pojo, columnDefinition); cellList.add(cell); } list.add(cellList);