...
 
Commits (2)
......@@ -225,6 +225,8 @@ dependencies {
compile 'com.mapbox.mapboxsdk:mapbox-android-services:2.1.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.firebase:firebase-messaging:10.0.1'
implementation 'me.texy.treeview:treeview_lib:1.0.3'
}
// Must be at bottom to prevent dependency collisions
......
......@@ -10,8 +10,8 @@ import org.junit.After;
import org.junit.Before;
import id.ac.stis.capi.TestUtils;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
......
......@@ -12,8 +12,8 @@ import java.util.Collections;
import java.util.Map;
import java.util.Set;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.provider.InstanceProviderAPI;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
public final class TestUtils {
private TestUtils() {}
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package id.ac.stis.capi.dao;
package id.ac.stis.capi.odk.dao;
import android.database.Cursor;
import android.support.test.runner.AndroidJUnit4;
......@@ -23,10 +23,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.dto.Form;
import id.ac.stis.capi.provider.FormsProviderAPI;
import id.ac.stis.capi.utilities.ResetUtility;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.dto.Form;
import id.ac.stis.capi.odk.provider.FormsProviderAPI;
import id.ac.stis.capi.odk.utilities.ResetUtility;
import java.io.File;
import java.io.IOException;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package id.ac.stis.capi.dao;
package id.ac.stis.capi.odk.dao;
import android.database.Cursor;
import android.support.test.runner.AndroidJUnit4;
......@@ -23,9 +23,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.dto.Instance;
import id.ac.stis.capi.provider.InstanceProviderAPI;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
import java.util.List;
......
package id.ac.stis.capi.tasks;
package id.ac.stis.capi.odk.tasks;
import org.junit.Test;
import id.ac.stis.capi.MockedServerTest;
import id.ac.stis.capi.logic.FormDetails;
import id.ac.stis.capi.odk.logic.FormDetails;
import java.util.Map;
......
package id.ac.stis.capi.tasks;
package id.ac.stis.capi.odk.tasks;
import android.net.Uri;
......@@ -9,10 +9,10 @@ import org.junit.Before;
import org.junit.Test;
import id.ac.stis.capi.MockedServerTest;
import id.ac.stis.capi.dao.InstancesDao;
import id.ac.stis.capi.dto.Instance;
import id.ac.stis.capi.provider.InstanceProviderAPI;
import id.ac.stis.capi.tasks.InstanceUploaderTask.Outcome;
import id.ac.stis.capi.odk.dao.InstancesDao;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
import id.ac.stis.capi.odk.tasks.InstanceUploaderTask.Outcome;
import okhttp3.mockwebserver.RecordedRequest;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package id.ac.stis.capi.utilities;
package id.ac.stis.capi.odk.utilities;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
......@@ -23,7 +23,7 @@ import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.odk.application.Collect;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package id.ac.stis.capi.utilities;
package id.ac.stis.capi.odk.utilities;
import android.content.Context;
import android.support.test.filters.Suppress;
......@@ -23,8 +23,8 @@ import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.logic.DatePickerDetails;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.logic.DatePickerDetails;
import java.util.Date;
import java.util.Locale;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package id.ac.stis.capi.utilities;
package id.ac.stis.capi.odk.utilities;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
......@@ -26,9 +26,9 @@ import org.javarosa.form.api.FormEntryPrompt;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.widgets.ImageWidget;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.widgets.ImageWidget;
import java.io.File;
import java.io.IOException;
......@@ -40,7 +40,7 @@ import timber.log.Timber;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static id.ac.stis.capi.utilities.ApplicationConstants.XML_OPENROSA_NAMESPACE;
import static id.ac.stis.capi.odk.utilities.ApplicationConstants.XML_OPENROSA_NAMESPACE;
@RunWith(AndroidJUnit4.class)
public class ImageConverterTest {
......
package id.ac.stis.capi.utilities;
package id.ac.stis.capi.odk.utilities;
import org.junit.Before;
import org.junit.Test;
import id.ac.stis.capi.MockedServerTest;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.odk.application.Collect;
import org.opendatakit.httpclientandroidlib.client.HttpClient;
import org.opendatakit.httpclientandroidlib.client.methods.HttpGet;
import org.opendatakit.httpclientandroidlib.protocol.HttpContext;
......
This diff is collapsed.
package id.ac.stis.capi.collectiva;
import id.ac.stis.capi.dto.Instance;
import id.ac.stis.capi.odk.dto.Instance;
import java.util.HashMap;
......
......@@ -2,7 +2,7 @@ package id.ac.stis.capi.collectiva;
import android.util.Log;
import id.ac.stis.capi.utilities.FileUtils;
import id.ac.stis.capi.odk.utilities.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
......
......@@ -43,43 +43,43 @@ import android.widget.Toast;
import org.apache.commons.lang3.ArrayUtils;
import id.ac.stis.capi.R;
import id.ac.stis.capi.activities.FormEntryActivity;
import id.ac.stis.capi.activities.GoogleSheetsUploaderActivity;
import id.ac.stis.capi.activities.InstanceUploaderActivity;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.odk.activities.FormEntryActivity;
import id.ac.stis.capi.odk.activities.GoogleSheetsUploaderActivity;
import id.ac.stis.capi.odk.activities.InstanceUploaderActivity;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.collectiva.CapiInstance;
import id.ac.stis.capi.collectiva.preferences.CapiInstancePreferences;
import id.ac.stis.capi.collectiva.ParseXml;
import id.ac.stis.capi.collectiva.preferences.Constants;
import id.ac.stis.capi.collectiva.adapter.CapiInstanceAdapter;
import id.ac.stis.capi.dao.FormsDao;
import id.ac.stis.capi.dao.InstancesDao;
import id.ac.stis.capi.dto.Instance;
import id.ac.stis.capi.listeners.DeleteInstancesListener;
import id.ac.stis.capi.listeners.DiskSyncListener;
import id.ac.stis.capi.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.preferences.PreferenceKeys;
import id.ac.stis.capi.provider.FormsProviderAPI;
import id.ac.stis.capi.provider.InstanceProviderAPI;
import id.ac.stis.capi.provider.InstanceProviderAPI.InstanceColumns;
import id.ac.stis.capi.receivers.NetworkReceiver;
import id.ac.stis.capi.tasks.DeleteInstancesTask;
import id.ac.stis.capi.tasks.InstanceSyncTask;
import id.ac.stis.capi.utilities.ApplicationConstants;
import id.ac.stis.capi.utilities.PlayServicesUtil;
import id.ac.stis.capi.utilities.ToastUtils;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.dao.InstancesDao;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.listeners.DeleteInstancesListener;
import id.ac.stis.capi.odk.listeners.DiskSyncListener;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.provider.FormsProviderAPI;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI.InstanceColumns;
import id.ac.stis.capi.odk.receivers.NetworkReceiver;
import id.ac.stis.capi.odk.tasks.DeleteInstancesTask;
import id.ac.stis.capi.odk.tasks.InstanceSyncTask;
import id.ac.stis.capi.odk.utilities.ApplicationConstants;
import id.ac.stis.capi.odk.utilities.PlayServicesUtil;
import id.ac.stis.capi.odk.utilities.ToastUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import static id.ac.stis.capi.utilities.ApplicationConstants.SortingOrder.BY_DATE_ASC;
import static id.ac.stis.capi.utilities.ApplicationConstants.SortingOrder.BY_DATE_DESC;
import static id.ac.stis.capi.utilities.ApplicationConstants.SortingOrder.BY_NAME_ASC;
import static id.ac.stis.capi.utilities.ApplicationConstants.SortingOrder.BY_NAME_DESC;
import static id.ac.stis.capi.utilities.ApplicationConstants.SortingOrder.BY_STATUS_ASC;
import static id.ac.stis.capi.utilities.ApplicationConstants.SortingOrder.BY_STATUS_DESC;
import static id.ac.stis.capi.odk.utilities.ApplicationConstants.SortingOrder.BY_DATE_ASC;
import static id.ac.stis.capi.odk.utilities.ApplicationConstants.SortingOrder.BY_DATE_DESC;
import static id.ac.stis.capi.odk.utilities.ApplicationConstants.SortingOrder.BY_NAME_ASC;
import static id.ac.stis.capi.odk.utilities.ApplicationConstants.SortingOrder.BY_NAME_DESC;
import static id.ac.stis.capi.odk.utilities.ApplicationConstants.SortingOrder.BY_STATUS_ASC;
import static id.ac.stis.capi.odk.utilities.ApplicationConstants.SortingOrder.BY_STATUS_DESC;
/**
* Responsible for displaying all the valid instances in the instance directory.
......
......@@ -2,29 +2,26 @@ package id.ac.stis.capi.collectiva.activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.GsonBuilder;
import com.rahadi.vsen.contexts.Vsen;
import com.rahadi.vsen.listeners.OnSynchronizationCompletedListener;
import com.rahadi.vsen.models.UserModel;
import com.rahadi.vsen.tasks.BSSynchronizationTask;
import com.rahadi.vsen.tasks.UserRegisterTask;
import org.json.JSONArray;
import org.json.JSONObject;
import id.ac.stis.capi.R;
import id.ac.stis.capi.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.preferences.PreferenceKeys;
import id.ac.stis.capi.preferences.PreferencesActivity;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.preferences.PreferencesActivity;
import id.ac.stis.capi.revalidasi.notifikasi.GetUuidTask;
import timber.log.Timber;
......@@ -44,7 +41,7 @@ public class CapiLoginActivity extends AppCompatActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.capi_activity_login);
TextView serverText = (TextView) findViewById(R.id.server_config_text);
final TextView serverText = (TextView) findViewById(R.id.server_config_text);
loginBtn = (Button) findViewById(R.id.btn_login);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
......
......@@ -48,11 +48,11 @@ import org.json.JSONArray;
import java.util.ArrayList;
import id.ac.stis.capi.R;
import id.ac.stis.capi.activities.SplashScreenActivity;
import id.ac.stis.capi.odk.activities.SplashScreenActivity;
import id.ac.stis.capi.collectiva.fragment.CapiFormFragment;
import id.ac.stis.capi.collectiva.preferences.CapiInstancePreferences;
import id.ac.stis.capi.database.ItemsetDbAdapter;
import id.ac.stis.capi.listeners.DiskSyncListener;
import id.ac.stis.capi.odk.database.ItemsetDbAdapter;
import id.ac.stis.capi.odk.listeners.DiskSyncListener;
import id.ac.stis.capi.pemutakhiran.fragments.BSFragment;
import id.ac.stis.capi.petawbdigital.activities.GeoPointMapboxRevoActivity;
import id.ac.stis.capi.petawbdigital.assets.VAR;
......@@ -60,11 +60,11 @@ import id.ac.stis.capi.petawbdigital.externals.AksesDataOdk;
import id.ac.stis.capi.petawbdigital.fragments.WbFragment;
import id.ac.stis.capi.petawbdigital.models.BlokSensus;
import id.ac.stis.capi.petawbdigital.models.Form;
import id.ac.stis.capi.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.revalidasi.fragments.DataDownloadFragment;
import id.ac.stis.capi.revalidasi.notifikasi.GetUuidTask;
import id.ac.stis.capi.tasks.DiskSyncTask;
import id.ac.stis.capi.odk.tasks.DiskSyncTask;
import timber.log.Timber;
/**
......
......@@ -31,11 +31,11 @@ import id.ac.stis.capi.R;
import id.ac.stis.capi.collectiva.CapiInstance;
import id.ac.stis.capi.collectiva.preferences.Constants;
import id.ac.stis.capi.collectiva.activity.CapiInstanceActivity;
import id.ac.stis.capi.dao.FormsDao;
import id.ac.stis.capi.dto.Instance;
import id.ac.stis.capi.provider.FormsProviderAPI.FormsColumns;
import id.ac.stis.capi.provider.InstanceProviderAPI;
import id.ac.stis.capi.utilities.ApplicationConstants;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.provider.FormsProviderAPI.FormsColumns;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
import id.ac.stis.capi.odk.utilities.ApplicationConstants;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
......
......@@ -33,12 +33,12 @@ import android.widget.TextView;
import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.data.IAnswerData;
import id.ac.stis.capi.R;
import id.ac.stis.capi.activities.FormEntryActivity;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.odk.activities.FormEntryActivity;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.collectiva.loader.ErrorHierarchy;
import id.ac.stis.capi.collectiva.loader.ErrorHierarchyAdapter;
import id.ac.stis.capi.collectiva.loader.ErrorHierarchyLoader;
import id.ac.stis.capi.logic.FormController;
import id.ac.stis.capi.odk.logic.FormController;
import java.util.ArrayList;
import java.util.HashMap;
......
......@@ -39,12 +39,12 @@ import org.javarosa.form.api.FormEntryCaption;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryPrompt;
import id.ac.stis.capi.R;
import id.ac.stis.capi.activities.FormEntryActivity;
import id.ac.stis.capi.adapters.HierarchyListAdapter;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.logic.FormController;
import id.ac.stis.capi.logic.HierarchyElement;
import id.ac.stis.capi.utilities.FormEntryPromptUtils;
import id.ac.stis.capi.odk.activities.FormEntryActivity;
import id.ac.stis.capi.odk.adapters.HierarchyListAdapter;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.logic.FormController;
import id.ac.stis.capi.odk.logic.HierarchyElement;
import id.ac.stis.capi.odk.utilities.FormEntryPromptUtils;
import java.util.ArrayList;
import java.util.List;
......
......@@ -10,9 +10,9 @@ import android.widget.TextView;
import org.javarosa.core.model.FormIndex;
import org.javarosa.form.api.FormEntryCaption;
import id.ac.stis.capi.R;
import id.ac.stis.capi.activities.FormEntryActivity;
import id.ac.stis.capi.application.Collect;
import id.ac.stis.capi.logic.FormController;
import id.ac.stis.capi.odk.activities.FormEntryActivity;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.logic.FormController;
import java.util.ArrayList;
......
......@@ -5,8 +5,8 @@ import android.content.Context;
import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.data.IAnswerData;
import id.ac.stis.capi.exception.JavaRosaException;
import id.ac.stis.capi.logic.FormController;
import id.ac.stis.capi.odk.exception.JavaRosaException;
import id.ac.stis.capi.odk.logic.FormController;
import java.util.ArrayList;
import java.util.HashMap;
......
......@@ -26,11 +26,11 @@ import com.rahadi.vsen.fragments.VsenPreferenceFragment;
import id.ac.stis.capi.R;
import id.ac.stis.capi.collectiva.ParseXml;
import id.ac.stis.capi.dao.FormsDao;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.petawbdigital.activities.KonfigurasiPeta;
import id.ac.stis.capi.preferences.PreferenceKeys;
import id.ac.stis.capi.preferences.PreferencesActivity;
import id.ac.stis.capi.provider.FormsProviderAPI;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.preferences.PreferencesActivity;
import id.ac.stis.capi.odk.provider.FormsProviderAPI;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
......
package id.ac.stis.capi.lessthink.binders;
import android.view.View;
import android.widget.TextView;
import id.ac.stis.capi.R;
import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class FirstLevelNodeViewBinder extends BaseNodeViewBinder {
private TextView mainText;
public FirstLevelNodeViewBinder(View itemView) {
super(itemView);
mainText = itemView.findViewById(R.id.text_main);
}
@Override
public int getLayoutId() {
return R.layout.item_node_first;
}
@Override
public void bindView(TreeNode treeNode) {
mainText.setText(treeNode.getValue().toString());
}
}
package id.ac.stis.capi.lessthink.binders;
import android.view.View;
import me.texy.treeview.base.BaseNodeViewBinder;
import me.texy.treeview.base.BaseNodeViewFactory;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class NodeViewFactory extends BaseNodeViewFactory {
@Override
public BaseNodeViewBinder getNodeViewBinder(View view, int level) {
switch (level) {
case 0:
return new FirstLevelNodeViewBinder(view);
case 1:
return new FirstLevelNodeViewBinder(view);
default:
return null;
}
}
}
package id.ac.stis.capi.lessthink.exceptions;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class DimensionInvalidException extends Exception {
public DimensionInvalidException(String message) {
super(message);
}
}
package id.ac.stis.capi.lessthink.listeners;
import java.util.HashMap;
import java.util.List;
import id.ac.stis.capi.odk.logic.FormDetails;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface DependenciesResolverListener {
void onDependenciesResolvingCompleted(HashMap<FormDetails, List<FormDetails>> result);
void onProgressUpdate(String currentFile, int progress, int total);
}
package id.ac.stis.capi.lessthink.listeners;
import java.util.HashMap;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface OnDownloadClickedListener {
void onDownloadClick(HashMap<String, String> formDetails);
}
package id.ac.stis.capi.lessthink.logics;
import java.io.Serializable;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class DependencyDetails implements Serializable {
private String formID;
private String formVersion;
private String formRootElement;
private String dependencyRule;
public DependencyDetails(String formID, String formVersion, String formRootElement, String dependencyRule) {
this.formID = formID;
this.formVersion = formVersion;
this.formRootElement = formRootElement;
this.dependencyRule = dependencyRule;
}
public String getFormID() {
return formID;
}
public String getFormVersion() {
return formVersion;
}
public String getFormRootElement() {
return formRootElement;
}
public String getDependencyRule() {
return dependencyRule;
}
}
package id.ac.stis.capi.lessthink.tasks;
import android.app.AlertDialog;
import android.os.AsyncTask;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import id.ac.stis.capi.lessthink.listeners.DependenciesResolverListener;
import id.ac.stis.capi.lessthink.logics.DependencyDetails;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.dto.Form;
import id.ac.stis.capi.odk.listeners.FormListDownloaderListener;
import id.ac.stis.capi.odk.logic.FormDetails;
import id.ac.stis.capi.odk.tasks.DownloadFormListTask;
import id.ac.stis.capi.odk.utilities.AuthDialogUtility;
import id.ac.stis.capi.odk.utilities.FileUtils;
import timber.log.Timber;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class DependenciesResolverTask extends AsyncTask<List<FormDetails>, String,
HashMap<FormDetails, List<DependencyDetails>>> implements DependenciesResolverListener {
private FormsDao formsDao;
private DependenciesResolverListener dependenciesResolverListener;
/**
* Set the dependencies resolver listener
*
* @param dependenciesResolverListener listener
*/
public void setDependenciesResolverListener(DependenciesResolverListener
dependenciesResolverListener) {
this.dependenciesResolverListener = dependenciesResolverListener;
}
@Override
protected HashMap<FormDetails, List<DependencyDetails>> doInBackground(List<FormDetails>... lists) {
formsDao = new FormsDao();
List<FormDetails> toResolve = lists[0];
HashMap<FormDetails, List<DependencyDetails>> result = new HashMap<>();
int total = toResolve.size();
int count = 1;
// Process the forms supplied by the execute() parameter
for (FormDetails fd : toResolve) {
List<DependencyDetails> details = processOneForm(fd, total, count++);
if (details.size() > 0) {
result.put(fd, details);
}
}
return result;
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
if (dependenciesResolverListener != null) {
dependenciesResolverListener.onProgressUpdate(values[0],
Integer.parseInt(values[1]),
Integer.parseInt(values[2]));
}
}
@Override
protected void onPostExecute(HashMap<FormDetails, List<DependencyDetails>> formDetailsListHashMap) {
super.onPostExecute(formDetailsListHashMap);
Timber.d("Unmatched Dependencies: %s", formDetailsListHashMap.toString());
if(formDetailsListHashMap.size() > 0) {
DependenciesMatcher matcher = new DependenciesMatcher();
matcher.setListener(this);
matcher.execute(formDetailsListHashMap);
} else {
onDependenciesResolvingCompleted(new HashMap<FormDetails, List<FormDetails>>());
}
}
/**
* Process to resolve the dependencies of a form
*
* @param formDetails the form to be processed
* @param total total number of forms to be processed
* @param count the current count of form(s) that are processed
* @return list of all dependencies in one form
*/
private List<DependencyDetails> processOneForm(FormDetails formDetails, int total, int count) {
publishProgress(formDetails.formName, String.valueOf(count), String.valueOf(total));
String formId = formDetails.formID;
// FormDetails contains only some basic information.
// To get the file path, we need to get the corresponding Form
Form form = formsDao.getFormsFromCursor(formsDao.getFormsCursorForFormId(formId)).get(0);
File file = new File(form.getFormFilePath());
// Parse the dependencies and save it as a list
// return the list of dependencies parsed from the XML form definition
return FileUtils.parseFormDependencies(file);
}
@Override
public void onDependenciesResolvingCompleted(HashMap<FormDetails, List<FormDetails>> result) {
if (dependenciesResolverListener != null) {
dependenciesResolverListener.onDependenciesResolvingCompleted(result);
}
}
@Override
public void onProgressUpdate(String currentFile, int progress, int total) {
onProgressUpdate(currentFile, String.valueOf(progress), String.valueOf(total));
}
private class DependenciesMatcher implements FormListDownloaderListener, AuthDialogUtility.AuthDialogUtilityResultListener {
private HashMap<String, FormDetails> formList;
private HashMap<FormDetails, List<DependencyDetails>> details;
private DependenciesResolverListener listener;
private DownloadFormListTask downloadFormListTask;
private FormsDao formsDao;
public void setListener(DependenciesResolverListener listener) {
this.listener = listener;
}
public void execute(HashMap<FormDetails, List<DependencyDetails>> details) {
this.details = details;
this.formsDao = new FormsDao();
Timber.d("Getting form list from the server..");
downloadFormListTask = new DownloadFormListTask();
downloadFormListTask.setDownloaderListener(this);
downloadFormListTask.execute();
}
@Override
public void formListDownloadingComplete(HashMap<String, FormDetails> value) {
if (value.containsKey(DownloadFormListTask.DL_AUTH_REQUIRED)) {
// Needs authentication
AlertDialog dialog = new AuthDialogUtility().createDialog(Collect.getInstance(),
this);
dialog.show();
} else if (value.containsKey(DownloadFormListTask.DL_ERROR_MSG)) {
// Download failed
// TODO: 19/03/2018 RAHADI: download failed
} else {
// Everything's fine
this.formList = value;
Timber.d("Form list downloaded. Trying to match with dependencies list..");
HashMap<FormDetails, List<FormDetails>> result = new HashMap<>();
Set<FormDetails> keys = details.keySet();
int total = keys.size();
int count = 1;
for (FormDetails k : keys) {
List<DependencyDetails> evaluateMe = details.get(k);
List<FormDetails> evaluated = evaluateOneFormDependencies(evaluateMe,
k.formName, total, count++);
if (evaluated.size() > 0) {
result.put(k, evaluated);
}
}
if (listener != null) {
listener.onDependenciesResolvingCompleted(result);
}
}
}
/**
* Check if the dependencies are valid and can be downloaded from the server
*
* @param dependencies the form's dependencies
* @return the form's resolved dependencies
*/
private List<FormDetails> evaluateOneFormDependencies(List<DependencyDetails> dependencies,
String currentFile, int total, int count) {
if (listener != null) {
listener.onProgressUpdate(currentFile, count, total);
}
// Compare the parsed dependencies to the forms available on the server
ArrayList<FormDetails> downloadList = new ArrayList<>();
for (int i = 0; i < dependencies.size(); i++) {
int start;
int max = formList.size();
ArrayList<String> keys = new ArrayList<>(formList.keySet());
DependencyDetails dependency = dependencies.get(i);
String key = "";
for (start = 0; start < max; start++) {
key = keys.get(start);
FormDetails availableForm = formList.get(key);
if (availableForm.formID.equals(dependency.getFormID())) {
break;
}
}
if (start < max && !key.isEmpty()) {
// Form founds in the server and can be downloaded
FormDetails cur = formList.get(key);
if (isFormDownloadNeeded(cur)) {
// Form needed to be downloaded
downloadList.add(cur);
}
} else {
// Form not founds in the server
// TODO: 19/03/2018 RAHADI: form not found handling
}
}
return downloadList;
}
private boolean isFormDownloadNeeded(FormDetails formDetails) {
return formDetails.isNewerFormVersionAvailable() || formDetails.areNewerMediaFilesAvailable()
|| formsDao.getFormsCursorForFormId(formDetails.formID).getCount() == 0;
}
@Override
public void updatedCredentials() {
downloadFormListTask.execute();
}
@Override
public void cancelledUpdatingCredentials() {
}
}
}
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by Rahadi on 24/11/2017.
*/
public class ExtendedRecyclerView extends RecyclerView {
private View emptyView;
private AdapterDataObserver dataObserver = new AdapterDataObserver() {
@Override
public void onChanged() {
Adapter<?> adapter = getAdapter();
if (adapter != null && emptyView != null) {
if (adapter.getItemCount() == 0) {
emptyView.setVisibility(View.VISIBLE);
ExtendedRecyclerView.this.setVisibility(View.GONE);
} else {
emptyView.setVisibility(View.GONE);
ExtendedRecyclerView.this.setVisibility(View.VISIBLE);
}
}
}
};
public ExtendedRecyclerView(Context context) {
super(context);
}
public ExtendedRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public ExtendedRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setEmptyView(View emptyView) {
this.emptyView = emptyView;
}
@Override
public void setAdapter(Adapter adapter) {
super.setAdapter(adapter);
if (adapter != null) {
adapter.registerAdapterDataObserver(dataObserver);
}
dataObserver.onChanged();
}
}
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import id.ac.stis.capi.R;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class ListingTableView extends View {
public static final int COLUMN_TYPE_HEADER = 1;
public static final int COLUMN_TYPE_BODY = 2;
public static final int SEP_TYPE_HEADER = 3;
public static final int SEP_TYPE_BODY = 4;
private static final int KEY_COLUMN_IDX = 0;
/*
The HashMap<String, String> should be in the form of:
key: header key
value: header name value
*/
private HashMap<String, String> headerList;
/*
ArrayList<> denotes as rows.
The HashMap<String, String> should be in the form of:
key: header key
value: row value
*/
private ArrayList<HashMap<String, String>> rowData;
private LinearLayout headerContainer, rowContainer;
public ListingTableView(Context context) {
super(context);
}
public ListingTableView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public ListingTableView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void init(HashMap<String, String> headerList, ArrayList<HashMap<String, String>> rowData) {
this.headerList = headerList;
this.rowData = rowData;
init();
}
private void init() {
// TODO: 06/06/2018 Proper exception
// if (headerList.size() != rowData.size()) {
// throw new DimensionInvalidException("Number of Column is Invalid");
// }
View v = LayoutInflater.from(getContext()).inflate(R.layout.view_listing_table,
null, false);
headerContainer = v.findViewById(R.id.header_container);
rowContainer = v.findViewById(R.id.row_container);
// Creates Header
int headerIdx = 0;
Set<String> headerKeySet = headerList.keySet();
for (String headerKey : headerKeySet) {
TextView header = createNewColumn(COLUMN_TYPE_HEADER, headerKey,
headerList.get(headerKey), headerIdx);
headerContainer.addView(header);
View separator = createNewSeparator(SEP_TYPE_HEADER, headerKey, headerIdx);
headerContainer.addView(separator);
headerIdx++;
}
// Creates Row
for (int i = 0; i < rowData.size(); i++) {
LinearLayout row = createNewRow(rowData.get(i), i);
rowContainer.addView(row);
}
}
private TextView createNewColumn(int type, String key, String value, int columnIdx) {
TextView column = new TextView(getContext());
column.setTag(key);
column.setTag(KEY_COLUMN_IDX, columnIdx);
column.setText(value);
switch (type) {
case COLUMN_TYPE_HEADER:
column.setContentDescription("h-" + columnIdx);
return column;
case COLUMN_TYPE_BODY:
column.setContentDescription("b-" + columnIdx);
column.setTag(key);
return column;
}
return null;
}
private View createNewSeparator(int type, String key, int columnIdx) {
View separator = new View(getContext());
separator.setTag(key);
separator.setTag(KEY_COLUMN_IDX, columnIdx);
switch (type) {
case SEP_TYPE_HEADER:
separator.setContentDescription("sh-" + columnIdx);
final TextView column = headerContainer.findViewWithTag(key);
column.measure(0, 0);
final int oriWidth = column.getMeasuredWidth();
final ArrayList<View> rowInBodyList = new ArrayList<>();
headerContainer.findViewsWithText(rowInBodyList, "b-" + columnIdx,
FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
separator.setOnTouchListener(new View.OnTouchListener() {
int prevX;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
prevX = (int) motionEvent.getRawX();
return true;
case MotionEvent.ACTION_MOVE:
if (column.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX >= oriWidth) {
column.setWidth(column.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
for (View rowInBody : rowInBodyList) {
((TextView) rowInBody).setWidth(rowInBody.getMeasuredWidth()
+ (int) motionEvent.getRawX() - prevX);
}
prevX = (int) motionEvent.getRawX();
}
return true;
}
return false;
}
});
return separator;
case SEP_TYPE_BODY:
separator.setContentDescription("sb-" + columnIdx);
return separator;
}
return null;
}
private LinearLayout createNewRow(HashMap<String, String> data, int rowIdx) {
LinearLayout row = new LinearLayout(getContext());
row.setContentDescription("r-" + rowIdx);
row.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
row.setLayoutParams(params);
Set<String> dataKeySet = data.keySet();
for (String dataKey : dataKeySet) {
int idxPosition = (Integer) headerContainer.findViewWithTag(dataKey).getTag(KEY_COLUMN_IDX);
TextView column = createNewColumn(COLUMN_TYPE_BODY, dataKey, data.get(dataKey), idxPosition);
row.addView(column);
View separator = createNewSeparator(SEP_TYPE_BODY, dataKey, idxPosition);
headerContainer.addView(separator);
}
return row;
}
// final HorizontalScrollView header = findViewById(R.id.header_layout);
// header.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
// return true;
// }
// });
//
// final TextView column1 = findViewById(R.id.column_1);
// column1.measure(0, 0);
//
// final TextView row1 = findViewById(R.id.row_1);
//
// final View dragme = findViewById(R.id.dragme);
// final int oriWidth = column1.getMeasuredWidth();
// dragme.setOnTouchListener(new View.OnTouchListener() {
//
// int prevX;
//
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
// view.getParent().requestDisallowInterceptTouchEvent(true);
// switch (motionEvent.getAction()) {
// case MotionEvent.ACTION_DOWN:
// prevX = (int) motionEvent.getRawX();
// return true;
// case MotionEvent.ACTION_MOVE:
// if(column1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX >= oriWidth) {
// column1.setWidth(column1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
// row1.setWidth(row1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
// prevX = (int) motionEvent.getRawX();
// }
// return true;
// }
// return false;
// }
// });
//
// final HorizontalScrollView scrollView = findViewById(R.id.scroll_view);
//
// scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
// @Override
// public void onScrollChanged() {
// header.scrollTo(scrollView.getScrollX(), 0);
// }
// });
}