Skip to content

Adds Report Model and Report Adapter #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.recyclerview:recyclerview:1.0.0"

implementation project(':roksky-reporting')

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//for lifecycle and LiveData and ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:2.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import androidx.appcompat.app.AppCompatActivity;

import com.roksky.android.tools.reporting.model.DashBoard;
import com.roksky.android.tools.reporting.utils.FileReaderUtil;
import com.roksky.android.tools.reporting.ReportingLibrary;
import com.roksky.android.tools.reporting.model.xml.DashBoard;

public class MainActivity extends AppCompatActivity {

Expand All @@ -19,7 +19,11 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
try {
DashBoard dashBoard = FileReaderUtil.getDashBoard("reporting/reports.xml", getApplication());
DashBoard dashBoard = ReportingLibrary.getInstance()
.withContext(getApplicationContext())
.withFilePath("reporting/reports.xml")
.getDashBoard();
//FileReaderUtil.getDashBoard("reporting/reports.xml", getApplication());
System.out.print(dashBoard.name);
} catch (Exception e) {
e.printStackTrace();
Expand Down
5 changes: 5 additions & 0 deletions roksky-reporting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ android {
includeAndroidResources = true
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

}

Expand All @@ -82,6 +86,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.roksky.android.tools.reporting;

import android.content.Context;

import com.roksky.android.tools.reporting.model.xml.DashBoard;
import com.roksky.android.tools.reporting.utils.FileReaderUtil;

public class ReportingLibrary {
private static ReportingLibrary reportingLibrary;
private String filePath;
private DashBoard dashBoard;
private Context context;

private ReportingLibrary() {
}

public static ReportingLibrary getInstance() {
if (reportingLibrary == null) {
reportingLibrary = new ReportingLibrary();
}
return reportingLibrary;
}

public ReportingLibrary withFilePath(String filePath) {
this.filePath = filePath;
return reportingLibrary;
}

public ReportingLibrary withContext(Context context) {
this.context = context;
return reportingLibrary;
}

public DashBoard getDashBoard() throws Exception {
if (dashBoard == null) {
dashBoard = FileReaderUtil.getDashBoard(filePath, context);
}
return dashBoard;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.roksky.android.tools.reporting.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.RecyclerView;
import com.roksky.android.tools.reporting.R;
import com.roksky.android.tools.reporting.model.Report;
import java.util.List;


public class ReportAdapter extends RecyclerView.Adapter<ReportAdapter.ReportAdapterViewHolder>{
private LiveData<List<Report>> reportList;

public ReportAdapter(LiveData<List<Report>> reportList) {
this.reportList = reportList;
}

@NonNull
@Override
public ReportAdapterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.report_details, parent, false);
return new ReportAdapterViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ReportAdapterViewHolder holder, int position) {
com.roksky.android.tools.reporting.model.Report report = reportList.getValue().get(position);
holder.tvTitle.setText(report.getName());
holder.tvTotal.setText(report.getCount());
holder.tvTotal.setText(R.string.app_name);
}

@Override
public int getItemCount() {
return reportList.getValue().size();
}

public class ReportAdapterViewHolder extends RecyclerView.ViewHolder{
TextView tvTitle;
TextView tvTotal;
TextView tvViewContent;

public ReportAdapterViewHolder(@NonNull View itemView) {
super(itemView);
tvTitle = itemView.findViewById(R.id.title);
tvTotal = itemView.findViewById(R.id.total);
tvViewContent = itemView.findViewById(R.id.viewContent);

}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.roksky.android.tools.reporting.datasource;

import com.roksky.android.tools.reporting.model.Query;
import com.roksky.android.tools.reporting.model.QueryParameter;
import com.roksky.android.tools.reporting.model.QueryResult;
import com.roksky.android.tools.reporting.model.xml.Query;
import com.roksky.android.tools.reporting.model.xml.QueryParameter;
import com.roksky.android.tools.reporting.model.xml.QueryResult;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.roksky.android.tools.reporting.datasource;

import com.roksky.android.tools.reporting.model.Query;
import com.roksky.android.tools.reporting.model.QueryParameter;
import com.roksky.android.tools.reporting.model.QueryResult;
import com.roksky.android.tools.reporting.model.xml.Query;
import com.roksky.android.tools.reporting.model.xml.QueryParameter;
import com.roksky.android.tools.reporting.model.xml.QueryResult;

import java.util.List;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.roksky.android.tools.reporting.model;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
public class Report {

import java.util.List;
private String name;
private Integer count;

@Element
public final class Report {
public String getName() {
return name;
}

@Element(required = false)
public String type;
public void setName(String name) {
this.name = name;
}

@Element(name = "query-source", required = false)
public String querySource;
public Integer getCount() {
return count;
}

@Element(required = false)
public String name;

@ElementList(name = "report-header", required = false)
public List<ReportColumn> reportHeader;

@ElementList(name = "report-footers", required = false)
public List<ReportFooter> reportFooters;
public void setCount(Integer count) {
this.count = count;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.roksky.android.tools.reporting.model;
package com.roksky.android.tools.reporting.model.xml;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.ElementList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.roksky.android.tools.reporting.model;
package com.roksky.android.tools.reporting.model.xml;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.roksky.android.tools.reporting.model;
package com.roksky.android.tools.reporting.model.xml;

import org.simpleframework.xml.Element;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.roksky.android.tools.reporting.model.xml;

public final class QueryResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.roksky.android.tools.reporting.model.xml;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;

import java.util.List;

@Element
public final class Report {

@Element(required = false)
public String type;

@Element(name = "query-source", required = false)
public String querySource;

@Element(required = false)
public String name;

@ElementList(name = "report-header", required = false)
public List<ReportColumn> reportHeader;

@ElementList(name = "report-footers", required = false)
public List<ReportFooter> reportFooters;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.roksky.android.tools.reporting.model;
package com.roksky.android.tools.reporting.model.xml;

import org.simpleframework.xml.Element;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.roksky.android.tools.reporting.model;
package com.roksky.android.tools.reporting.model.xml;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.roksky.android.tools.reporting.model;
package com.roksky.android.tools.reporting.model.xml;

import org.simpleframework.xml.Element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.view.View;

import com.roksky.android.tools.reporting.model.Report;
import com.roksky.android.tools.reporting.model.xml.Report;

public interface ReportView {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import androidx.annotation.Nullable;

import com.roksky.android.tools.reporting.model.DashBoard;
import com.roksky.android.tools.reporting.model.xml.DashBoard;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.view.View;

import com.roksky.android.tools.reporting.model.DashBoard;
import com.roksky.android.tools.reporting.model.xml.DashBoard;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.roksky.android.tools.reporting.view;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.roksky.android.tools.reporting.R;
import com.roksky.android.tools.reporting.adapter.ReportAdapter;
import com.roksky.android.tools.reporting.model.Report;
import com.roksky.android.tools.reporting.viewmodel.ReportViewModel;

import java.util.List;

public class ReportActivity extends AppCompatActivity {

LiveData<List<Report>> reports;
ReportViewModel reportViewModel = new ReportViewModel();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reports);

RecyclerView recyclerView = findViewById(R.id.reports);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

reports = reportViewModel.getReports();
ReportAdapter adapter = new ReportAdapter(reports);
recyclerView.setAdapter(adapter);
}
}
Loading