Commit 75bfcb78 authored by rahadi's avatar rahadi

XmlUtils tested, performance so far so good

parent 13ac4e1b
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
// mavenCentral()
jcenter()
google()
}
......
......@@ -63,12 +63,12 @@ if (secretsFile.exists()) {
}
android {
compileSdkVersion(26)
compileSdkVersion(27)
buildToolsVersion('26.0.2')
defaultConfig {
applicationId('id.ac.stis.capi')
minSdkVersion(16)
targetSdkVersion(26)
targetSdkVersion(27)
versionName getVersionName()
testInstrumentationRunner('android.support.test.runner.AndroidJUnitRunner')
multiDexEnabled true
......@@ -140,9 +140,9 @@ allprojects {
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:design:27.1.0'
compile 'com.android.support:cardview-v7:27.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-analytics:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
......@@ -178,8 +178,8 @@ dependencies {
exclude group: 'org.apache.httpcomponents'
}
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'com.android.support:customtabs:26.1.0'
compile 'com.android.support:support-v13:26.1.0'
compile 'com.android.support:customtabs:27.1.0'
compile 'com.android.support:support-v13:27.1.0'
compile 'com.google.zxing:core:3.2.0'
compile 'com.journeyapps:zxing-android-embedded:3.5.0'
compile 'net.danlew:android.joda:2.9.9'
......@@ -209,9 +209,12 @@ dependencies {
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.6.0'
// tempat custom dependencies capi-stis, supaya gampang updatenya
// sudah ada ui-android, peta wb, revalidasi (soon)
compile('com.mikepenz:materialdrawer:6.0.7@aar') {
transitive = true
}
// compile('com.mikepenz:materialdrawer:6.0.7@aar') {
// transitive = true
// }
compile 'com.mikepenz:materialdrawer:6.0.7'
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar') {
transitive = true
}
......@@ -219,8 +222,8 @@ dependencies {
// compile project(':vsen_p')
compile 'org.apache.commons:commons-lang3:3.6'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:support-v4:27.1.0'
compile 'com.android.support:recyclerview-v7:27.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.mapbox.mapboxsdk:mapbox-android-services:2.1.2'
......
package id.ac.stis.capi.lessthink.activities;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
......@@ -14,15 +16,26 @@ import java.util.Map;
import id.ac.stis.capi.R;
import id.ac.stis.capi.lessthink.models.FormLabels;
import id.ac.stis.capi.lessthink.models.InstanceValues;
import id.ac.stis.capi.lessthink.utils.XmlUtils;
import id.ac.stis.capi.lessthink.views.TableFooterView;
import id.ac.stis.capi.lessthink.views.TableHeaderView;
import id.ac.stis.capi.lessthink.views.TableRowView;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.dao.InstancesDao;
import id.ac.stis.capi.odk.dto.Form;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
import timber.log.Timber;
public class ListingInstanceActivity extends AppCompatActivity {
private static final String FORM_ID_KEY = "formid";
private static final String FORMNAME = "formname";
private TableHeaderView tableHeaderView;
private TableRowView tableRowView;
private TableFooterView tableFooterView;
private String formId, formName;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -35,26 +48,33 @@ public class ListingInstanceActivity extends AppCompatActivity {
tableRowView = findViewById(R.id.row_view);
tableFooterView = findViewById(R.id.footer_view);
Map<String, String> headerList = new LinkedHashMap<>();
headerList.put("no_sls", "No. SLS");
headerList.put("no_bs", "No. BS");
headerList.put("no_bf", "No. BF");
headerList.put("no_nks", "No. NKS");
headerList.put("nama_krt", "Nama KRT");
FormLabels formLabels = new FormLabels("formId", headerList);
formId = getIntent().getStringExtra(FORM_ID_KEY);
formName = getIntent().getStringExtra(FORMNAME);
FormsDao formsDao = new FormsDao();
List<Form> forms = formsDao.getFormsFromCursor(formsDao.getFormsCursorForFormId(formId));
File file = new File(forms.get(0).getFormFilePath());
List<String> xPaths = XmlUtils.getInstanceXPathList(file);
FormLabels labels = XmlUtils.getFormLabels(formId, file, xPaths);
tableHeaderView.setColumns(formLabels);
tableHeaderView.setColumns(labels);
List<InstanceValues> instanceValues = new LinkedList<>();
for (int i = 0; i < 31; i++) {
Map<String, String> rowData = new LinkedHashMap<>();
rowData.put("no_sls", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("no_bs", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("no_bf", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("no_nks", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("nama_krt", "Nama KRT " + i);
instanceValues.add(new InstanceValues("instanceId" + i, "formId", rowData));
String selection = InstanceProviderAPI.InstanceColumns.LATEST + " =? AND " +
InstanceProviderAPI.InstanceColumns.JR_FORM_ID + " =?";
String[] selectionArgs = new String[]{InstanceProviderAPI.LATEST_VERSION, formId};
InstancesDao instancesDao = new InstancesDao();
// TODO: 30/06/2018 Sorting order
Cursor data = instancesDao.getInstancesCursor(null, selection, selectionArgs, null);
List<Instance> instanceList = instancesDao.getInstancesFromCursor(data);
for (Instance instance : instanceList) {
File f = new File(instance.getInstanceFilePath());
InstanceValues values = XmlUtils.getInstanceValues(instance.getInstanceUuid(), f, labels);
instanceValues.add(values);
}
tableRowView.setRows(instanceValues);
......
......@@ -45,4 +45,5 @@ public class InstanceValues implements Serializable {
public String getInstanceValue(String xPath) {
return instanceValue.get(xPath);
}
}
......@@ -36,7 +36,7 @@ import timber.log.Timber;
*/
public class XmlUtils {
public static List<String> getInstanceXPathList(File file, String startingNode) {
public static List<String> getInstanceXPathList(File file) {
InputStream is;
try {
......@@ -93,7 +93,7 @@ public class XmlUtils {
}
}
public static FormLabels getFromLabels(String formId, File file, List<String> xPaths) {
public static FormLabels getFormLabels(String formId, File file, List<String> xPaths) {
Map<String, String> titles = new LinkedHashMap<>();
InputStream is;
......@@ -169,10 +169,10 @@ public class XmlUtils {
Set<String> xPaths = formLabels.getXPaths();
for (String xPathString : xPaths) {
XPathExpression expression = xPath.compile(xPathString);
Object res = expression.evaluate(doc, XPathConstants.NODE);
Node node = (Node) res;
Object res = expression.evaluate(doc, XPathConstants.STRING);
String node = (String) res;
values.put(xPathString, node.getText(0));
values.put(xPathString, node);
}
} catch (Throwable throwable) {
Timber.e(throwable);
......@@ -183,7 +183,8 @@ public class XmlUtils {
private static List<String> getXPathByElement(Element element) {
List<String> target = new ArrayList<>();
getXPathToTarget(target, element, "/" + element.getName());
// getXPathToTarget(target, element, "/" + element.getName());
getXPathToTarget(target, element, "");
return target;
}
......
......@@ -26,6 +26,7 @@ import id.ac.stis.capi.R;
import id.ac.stis.capi.collectiva.preferences.Constants;
import id.ac.stis.capi.collectiva.fragment.CapiFormFragment;
import id.ac.stis.capi.collectiva.activity.CapiInstanceActivity;
import id.ac.stis.capi.lessthink.activities.ListingInstanceActivity;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.provider.FormsProviderAPI;
import id.ac.stis.capi.odk.utilities.ApplicationConstants;
......@@ -115,7 +116,8 @@ public class CapiFormAdapter extends RecyclerView.Adapter<CapiFormAdapter.ViewHo
}
private void seeListRespons(int position){
Intent intent = new Intent(context, CapiInstanceActivity.class);
// Intent intent = new Intent(context, CapiInstanceActivity.class);
Intent intent = new Intent(context, ListingInstanceActivity.class);
intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE,
ApplicationConstants.FormModes.VIEW_SENT);
intent.putExtra(FORM_ID_KEY, dataSet.get(position).get(FORM_ID_KEY));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment