Sample implementation of list

Here is an sample implementation of an List. It is based on single line row elements without any actions.

You can use our list directly in your layout XML.

Layout

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.software.gsd.gsdandroidsdk.MainActivity">


    <com.gsd.software.sdk.recyclerview.GSDRecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.constraint.ConstraintLayout>

Than in activity/fragment you can identify list by id that was set in XML file. When you want to use it, just simply use findViewById. Next step is to set layout manager and than assign list adapter to help list with rendering elements.

Sample Activity:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
public class SampleActivity extends AppCompatActivity{
    private GSDRecyclerView recyclerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.sample_activity);
        this.recyclerView = (GSDRecyclerView) findViewById(R.id.recyclerView);
        this.recyclerView.setLayoutManager(new LinearLayoutManager(this));

        ListProvider provider = new ListProvider(this);

        GSDDefaultAdapter adapter = new GSDDefaultAdapter(this, provider);


        this.recyclerView.setAdapter(adapter);
    }

}

Sample list model

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class ModelObject {
    private String title;
    private String description;
    private String image;
    private boolean selected;
    private boolean state;
    private String infoTop;
    private String infoBottom;

    public String getTitle(){
        return this.title;
    }

    public String getDescription(){
        return this.description;
    }

    public String getImage(){
        return this.image;
    }

    public boolean isSelected(){
        return this.selected;
    }

    public void setState(boolean state){
        this.state = state;
    }

    public boolean getState(){
        return this.state;
    }

    public String getInfoTop(){
        return this.infoTop;
    }

    public String getInfoBottom(){
        return this.infoBottom;
    }
}

List data provider:

Provider class is a class that have information about current state of objects that are displayed in list amd how to display those objects.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public class ListProvider implements RecyclerViewContract.Provider {
    List<ModelObject> elements;

    public ListProvider(){

    }

    public void setElements(List<ModelObject> elements){
        this.elements = elements;
    }

    @Override
    public int getCount() {
        if(this.elements != null){
            return this.elements.size();
        }
        return 0;
    }


    @Override
    public int getViewType(int position) {
        if(this.elements != null){
            return this.elements.size();
        }
        return 0;
    }

    @Override
    public RowConfig getConfigForRow(int position) {
        if(this.elements != null){
            ModelObject obj = this.elements.get(position);
            RowConfig.Builder row = new RowConfig.Builder();

            row.setTitle(obj.getTitle())
                .setDescription(obj.getDescription())
                .setImage(obj.getImage())

                // Here we can use three types of rowType. 
                // GSDRecyclerView.SINGLE_LINE_ROW,
                // GSDRecyclerView.DOUBLE_LINE_ROW and 
                // GSDRecyclerView.COMPLEX_ROW (4 text fields)
                .setRowType(GSDRecyclerView.SINGLE_LINE_ROW)
                .setInfoTop(obj.getInfoTop());
                .setInfoBottom(obj.getInfoBottom())
                .setAction
                .setSelected(obj.isSelected())

            return row.build();
        }
    }

    @Override
    public void removeElement(int position) {
        this.elements.remove(position);
    }   
}