Adaptive Table Layout: Implementation, Useful Features and Development Process

Open source projects are of great importance for the software development industry. By using various features from open source libraries available on GitHub, coders can enhance their apps.

One of the exciting projects on GitHub is called Adaptive Table Layout Library. This tool allows coders to manage and sort CSV files efficiently. In this article, you will find out how to implement the Adaptive Table Layout Library into your app and use it for a better app performance. Also, you will find the main benefits and features of this open-source project.

First things first, let’s find out the definition of CSV file. It is a file format that stores text data in tabular form. Files of this format can be exported or imported from programs like MS Excel. In this case, CSV stands for Comma Separated Values. Because files of this type are plain-text, it is quite easy to import data into any spreadsheet program or database regardless of what kind of hardware or software program users have.

When we talk about a CSV library, it is better to describe it as a place where developers can store different properties to work with CSV files.

What can users do with the help of apps with AdaptiveTableLayout?

The list of main features is the following:

  • Convenient navigation: a user can make vertical, horizontal and diagonal scrolls;
  • It works fast and seamlessly with both small and large files;
  • Ability to read and edit CSV files;
  • Drag-and-drop feature;
  • Ability to pin headers to the edges;
  • Reshuffling columns and rows;
  • Solid rows – when a user moves row header up or down, it changes its number.

What’s more, AdaptiveTableLayout consists of 2 base data adapters:

BaseDataAdaptiveTableLayoutAdapter – this adapter is ideal for working with light data. The data will be saved automatically after switching to each row and column.

LinkedAdaptiveTableAdapter, in contrast, works with heavy data. It uses matrix with changed items with links on it. This type of adapter cannot change data, for this purpose you should use AdaptiveTableLayout.getLinkedAdapterRowsModifications() and AdaptiveTableLayout.getLinkedAdapterColumnsModifications().

How to add AdaptiveTableLayout to your project

The full code of AdaptiveTableLayout can be found on the GitHub repository. To implement the library into your Android application, add the following lines of code:

dependencies {

compile "com.cleveroad:adaptivetablelayout:1.1.1"

}

The following code set the properties of the AdaptiveTableLayout:

<com.cleveroad.adaptivetablelayout.AdaptiveTableLayout
        android:id="@+id/tableLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"      
        app:cellMargin="1dp"
        app:fixedHeaders="true"
        app:solidRowHeaders="true"
        app:dragAndDropEnabled="true"/>

In the following lines of code, attribute cellMargin set the margin between cells, fixedHeaders is a boolean value that enables or disables fixed headers mode. If the mode is enabled, users can see row headers after dragging row. Drag and drop feature works only if the dragAndDropEnabled value is true.

To set fixed headers mode, you should add the following line to your code:

void setHeaderFixed(boolean headerFixed)

If you want to set solid rows mode, use this line of code:

void setSolidRowHeader(boolean solidRowHeader)

The code for setting drag-and-drop mode is the following:

void setDragAndDrow(boolean enabled)

Adapter with mutable data cannot be used for big data. Before setting this adapter, you need to implement switch columns and rows method. And then add the following line of code:

void setAdapter(@Nullable DataAdaptiveTableLayoutAdapter adapter)

You can also notify registered observers that the item has changed. For this purpose, add the following line of code:

void notifyItemChanged(int rowIndex, int columnIndex)

To do the same with modified row or column, use

void notifyRowChanged(int rowIndex) 
void notifyColumnChanged(int columnIndex)

respectively.

How it was created: market research

Let’s discover the results of market research that our company launched a year ago. Before creating Adaptive table Layout, we tried to find the best CSV library that will perfectly fit all developers needs and work smoothly on Android devices. As a result, we’ve discovered three Android libraries for CSV files.

The first one is a CSV Viewer. This tool allowed users to open, manage and edit files with CSV format. It even let users import or export data directly from their phone contacts. But this tool also had several drawbacks. Developers decided to monetize their app, so the app had an advertisement.

What’s more, there were no dynamic indicators. Users were unable to fix headlines and scroll this library diagonally. Unfortunately, this app was deleted from Google Play.

To replace it, developers created Lightweight CSV Viewer. This tool has a wide range of different features. It supports various data delimiters including not only Comma but also semicolon, Tab, and Space. This tool also allows users to view data from ZIP archives, specify header location and set filters. But this app also contains an advertisement. What’s even more, you have no opportunity to reshuffle columns and rows. There is also no drag-and-drop feature.

And the last robust competitor available on the market is Easy CSV Reader. The name of this app really describes it – Easy CSV Reader is quite simple and consists of only the most essential features. But simplicity can be both benefit and drawback of this app. It allows the user just to read CSV files without the possibility to edit them.

After we did comprehensive research, we came up with an idea to make own CSV library that will meet all the requirements of Android developers. And that’s how AdaptiveTableLayout has appeared.

What distinguishes AdaptiveTableLayout from other CSV editors?

Several libraries allow working with CSV files. When creating the library, we wanted to make it outstanding by adding a couple of new features. The list of AdaptiveTableLayout advantages include:

  • Diagonal scrolling and solid rows, as it was stated earlier;
  • Ability to align the needed information;
  • Ability to display pictures via links;
  • Drag-n-drop feature;
  • Ability to fix headers to the edge.

How it was created: development steps

Talking about development tools, the project was made using Android SDK and API level 16. First, the RecyclerView was implemented. With the help of this technology, users can scroll the table.

After that, it was crucial to create the sample of the future library. It helped the company to understand how the app will look and work.

Then followed the process of testing and debugging. When everything worked seamlessly, developers geared towards making project outstanding. The final stage involved creating documentation with a detailed description of each feature. The main aim was to make the library as easy to implement as possible.

You can find our CSV Editor on Google Play and AdaptiveTableLayout repository on GitHub.

Challenges during development

During the development process, every developer faces obstacles. But it isn’t the reason to give up. When developing AdaptiveTableLayout, we have encountered several problems but quickly got rid of them. We had to answer the following questions:

How to calculate the position of elements?

One of the most crucial challenges was to define the position of each element with the highest possible accuracy. For this purpose, our developers had to perform a lot of calculations.

How to integrate scrolling?

Most CSV libraries have only horizontal and vertical scrolling. To make AdaptiveTableLayout outstanding, we implemented comfortable diagonal scrolling which helps users quickly find required information. After hours of hard work, we finally added this feature, but the code looked terrible. As it was mentioned earlier, we used RecyclerView. This fact has complicated the process of implementing obliquely scrolling. So we decided to get rid of this component and use it only in our app called CSV Reader.

How to correct the moving process?

It wasn’t an obstacle that is hard to overcome. But to make the library work seamlessly, we spent time thinking through this question.

How to develop adapters?

Creating the adapters mentioned above was quite complicated. But it was the components that make it easy to work with large CSV files.

In perspective, we want to add zooming, pinch-out and pinch-in features. What’s more, we plan to add a right to left writing model for users from Middle Eastern countries.

AdaptiveTableLayout is a library with a wide range of features that will help you create a powerful CSV reader app for Android. It is easy to implement and use, so will be an ideal solution for both newbie and skilled developers.