Commit f5cc77af authored by rahadi's avatar rahadi

Added Pemutakhiran Module

parent f1ca714d
package org.odk.collect.android.capi;
import android.os.AsyncTask;
import android.util.Log;
import org.odk.collect.android.utilities.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
......@@ -15,10 +18,10 @@ import java.util.HashSet;
import javax.xml.parsers.DocumentBuilderFactory;
public class ParseXml{
public class ParseXml {
//dapetin instance berdasarkan idINstance dan variabel form
public static HashMap<String, String> getLoadedXmlValues(String dir, HashSet<String> arvar){
public static HashMap<String, String> getLoadedXmlValues(String dir, HashSet<String> arvar) {
int eventType;
String name;
XmlPullParserFactory xmlPullParserFactory;
......@@ -32,51 +35,54 @@ public class ParseXml{
FileInputStream is = new FileInputStream(new File(dir));
parser.setInput(is, null);
eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT){
if(eventType == XmlPullParser.START_TAG){
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
name = parser.getName();
if(arvar.contains(name)){
if (arvar.contains(name)) {
informasi.put(name, parser.nextText());
}
}
eventType = parser.next();
}
} catch (Exception e) {
Log.d("DEBUGC","error happen when parser value ");
Log.d("DEBUGC", "error happen when parser value ");
}
return informasi;
}
//cari variabel apa aja yg ada di form
public static ArrayList<String> getVariabelForm (String dir, String ids){
public static ArrayList<String> getVariabelForm(String dir, String ids) {
ArrayList<String> arrayVariabel = new ArrayList<>();
File xml = new File(dir);
try {
FileInputStream is = new FileInputStream(new File(dir));
FileInputStream is = new FileInputStream(xml);
Document doc = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(is);
.newInstance()
.newDocumentBuilder()
.parse(is);
NodeList nl = doc.getElementsByTagName(ids);
NodeList nld;
if(nl.item(0)!=null) {
if (nl.item(0) != null) {
nld = nl.item(0).getChildNodes();
} else {
nl = doc.getElementsByTagName("data");
// nl = doc.getElementsByTagName("data");
// RAHADI: modified
nl = doc.getElementsByTagName(FileUtils.parseXML(xml).get(FileUtils.TOP_ELEMENT));
nld = nl.item(0).getChildNodes();
}
addChildNode(arrayVariabel, nld);
} catch (Exception e) {
Log.d("DEBUGCOLL", "error because "+e.toString());
Log.d("DEBUGCOLL", "error because " + e.toString());
}
return arrayVariabel;
}
private static void addChildNode(ArrayList<String> arrayLists, NodeList nodeList){
for (int j=0; j<nodeList.getLength(); j++){
private static void addChildNode(ArrayList<String> arrayLists, NodeList nodeList) {
for (int j = 0; j < nodeList.getLength(); j++) {
Node ndcc = nodeList.item(j);
// if(ndcc.getAttributes()!=null && ndcc.getAttributes().getNamedItem("jr:template")!=null) {
......
......@@ -91,7 +91,7 @@ public class CapiLoginActivity extends AppCompatActivity
}
}
public void login(final String username, final String password){
public void login(final String username, final String password) {
//disable login button
loginBtn.setClickable(false);
loginBtn.setText("Proses login");
......@@ -111,53 +111,57 @@ public class CapiLoginActivity extends AppCompatActivity
@Override
public void loginDone(String result) {
final String username = (String) GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_USERNAME);
final String uuid = (String) GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_UNIQUES);
new UserRegisterTask(username, uuid).execute(new OnSynchronizationCompletedListener<JSONObject>() {
@Override
public void onSynchronizationCompleted(JSONObject result) {
UserModel r = new GsonBuilder().create().fromJson(result.toString(), UserModel.class);
Timber.d(r.toString());
Vsen.getInstance().setUserSession(r);
dialog.setMessage("Sinkronisasi Data..");
new BSSynchronizationTask(null, null).execute(username, uuid,
new OnSynchronizationCompletedListener<JSONArray>() {
@Override
public void onSynchronizationCompleted(JSONArray result) {
// TODO: 20/02/2018 RAHADI: dynamize
String formId = "VSEN18K.v2";
new GetGenerateTask(formId).execute(new OnSynchronizationCompletedListener<String>() {
@Override
public void onSynchronizationCompleted(String result) {
onLoginSucceed();
}
@Override
public void onSynchronizationFailed(Exception e) {
Timber.e(e);
onLoginFailed(e.toString());
}
});
}
@Override
public void onSynchronizationFailed(Exception e) {
Timber.e(e);
onLoginFailed(e.toString());
}
});
}
@Override
public void onSynchronizationFailed(Exception e) {
Timber.e(e);
onLoginFailed(e.toString());
}
});
if (result.equals(GetUuidTask.SUCCESS)) {
// RAHADI: Register ke Pemutakhiran, etc.
final String username = (String) GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_USERNAME);
final String uuid = (String) GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_UNIQUES);
new UserRegisterTask(username, uuid).execute(new OnSynchronizationCompletedListener<JSONObject>() {
@Override
public void onSynchronizationCompleted(JSONObject result) {
UserModel r = new GsonBuilder().create().fromJson(result.toString(), UserModel.class);
Timber.d(r.toString());
Vsen.getInstance().setUserSession(r);
dialog.setMessage("Sinkronisasi Data..");
new BSSynchronizationTask(null, null).execute(username, uuid,
new OnSynchronizationCompletedListener<JSONArray>() {
@Override
public void onSynchronizationCompleted(JSONArray result) {
String formId = Vsen.getInstance().getGenerateFormId();
new GetGenerateTask(formId).execute(new OnSynchronizationCompletedListener<String>() {
@Override
public void onSynchronizationCompleted(String result) {
onLoginSucceed();
}
@Override
public void onSynchronizationFailed(Exception e) {
Timber.e(e);
onLoginFailed(e.toString());
}
});
}
@Override
public void onSynchronizationFailed(Exception e) {
Timber.e(e);
onLoginFailed(e.toString());
}
});
}
@Override
public void onSynchronizationFailed(Exception e) {
Timber.e(e);
onLoginFailed(e.toString());
}
});
} else {
onLoginFailed(result);
}
}
private void onLoginSucceed() {
......@@ -175,6 +179,7 @@ public class CapiLoginActivity extends AppCompatActivity
private void onLoginFailed(String result) {
dialog.dismiss();
loginBtn.setClickable(true);
loginBtn.setText("LOGIN");
loginBtn.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
......
package org.odk.collect.android.capi.activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
......@@ -12,7 +13,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
......@@ -24,15 +24,27 @@ import com.mikepenz.materialdrawer.AccountHeader;
import com.mikepenz.materialdrawer.AccountHeaderBuilder;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
import com.rahadi.vsen.contexts.Vsen;
import com.rahadi.vsen.daos.BlokSensusDao;
import com.rahadi.vsen.daos.CatatanDao;
import com.rahadi.vsen.daos.DsrtDao;
import com.rahadi.vsen.daos.DsrtLogDao;
import com.rahadi.vsen.daos.GenerateDao;
import com.rahadi.vsen.daos.RutaDao;
import com.rahadi.vsen.listeners.OnSynchronizationCompletedListener;
import com.rahadi.vsen.models.UserModel;
import com.rahadi.vsen.tasks.BSSynchronizationTask;
import com.squareup.picasso.Picasso;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.odk.collect.android.R;
import org.odk.collect.android.activities.SplashScreenActivity;
import org.odk.collect.android.capi.fragment.CapiFormFragment;
......@@ -161,27 +173,57 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
}
private void logout() {
prefs.reset(PreferenceKeys.KEY_LOGIN_STATUS);
prefs.reset(PreferenceKeys.KEY_USERNAME);
prefs.reset(PreferenceKeys.KEY_PASSWORD);
prefs.reset(PreferenceKeys.KEY_USERGROUP);
prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP);
String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES);
if (StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid));
startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class));
finish();
final ProgressDialog pd = new ProgressDialog(this);
pd.setCancelable(false);
pd.setMessage("Logging Out..");
pd.show();
UserModel um = Vsen.getInstance().getUserSession();
new BSSynchronizationTask(null, null).execute(um.getIdUser(), um.getAuthToken(),
new OnSynchronizationCompletedListener<JSONArray>() {
@Override
public void onSynchronizationCompleted(JSONArray result) {
pd.dismiss();
Vsen.getInstance().clearUserSession();
new BlokSensusDao().deleteBlokSensus();
new CatatanDao().deleteCatatan();
new DsrtDao().deleteDsrt();
new DsrtLogDao().deleteDsrtLog();
new GenerateDao().deleteGenerate();
new RutaDao().deleteRuta();
prefs.reset(PreferenceKeys.KEY_LOGIN_STATUS);
prefs.reset(PreferenceKeys.KEY_USERNAME);
prefs.reset(PreferenceKeys.KEY_PASSWORD);
prefs.reset(PreferenceKeys.KEY_USERGROUP);
prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP);
String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES);
if (StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid));
startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class));
finish();
}
@Override
public void onSynchronizationFailed(Exception e) {
pd.dismiss();
Toast.makeText(CapiMainActivity.this, "Gagal Logout", Toast.LENGTH_LONG).show();
}
});
}
private void initializeDrawer(final Context context, Bundle savedInstanceState) {
//get user data
String username = (String) prefs.get(PreferenceKeys.KEY_USERNAME);
String userGroup = (String) prefs.get(PreferenceKeys.KEY_USERGROUP);
// String username = (String) prefs.get(PreferenceKeys.KEY_USERNAME);
// String userGroup = (String) prefs.get(PreferenceKeys.KEY_USERGROUP);
String username = (String) Vsen.getInstance().getUserSession().getNamaUser();
String userGroup = (String) Vsen.getInstance().getUserSession().getIdUser();
//build drawer header
AccountHeader accountHeader = new AccountHeaderBuilder()
.withActivity(this)
.withSelectionListEnabledForSingleProfile(false)
.withHeaderBackground(R.drawable.capi_header_drawer)
.addProfiles(new ProfileDrawerItem()
.withName(username)
......@@ -196,11 +238,17 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
.withToolbar(toolbar)
.withSavedInstance(savedInstanceState)
.withHasStableIds(true)
.withItemAnimator(new DefaultItemAnimator())
// .withItemAnimator(new DefaultItemAnimator())
.withAccountHeader(accountHeader)
.addDrawerItems(
new PrimaryDrawerItem().withName("Pemutakhiran").withIcon(R.drawable.wb_ic_edit_bs).withIdentifier(MENU_PEMUTAKHIRAN),
new DividerDrawerItem(),
new SectionDrawerItem()
.withName("Menu")
.withEnabled(true)
.withDivider(false),
new PrimaryDrawerItem()
.withName("Pemutakhiran")
.withIcon(R.drawable.wb_ic_edit_bs)
.withIdentifier(MENU_PEMUTAKHIRAN),
new PrimaryDrawerItem()
.withName("Daftar Kuesioner")
.withIcon(R.drawable.ic_survey)
......@@ -212,11 +260,16 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
new PrimaryDrawerItem()
.withName("Peta WB Digital")
.withIcon(R.drawable.wb_ic_map)
.withIdentifier(MENU_PETA_WB),
new DividerDrawerItem(),
new PrimaryDrawerItem().withName("Pengaturan").withIcon(R.drawable.ic_setting).withIdentifier(MENUSETTING),
new PrimaryDrawerItem().withName("Logout").withIcon(R.drawable.ic_logout).withIdentifier(MENULOGOUT)
)
.withIdentifier(MENU_PETA_WB)
).withStickyFooterDivider(true)
.withStickyFooterShadow(false)
.addStickyDrawerItems(
new SecondaryDrawerItem().withName("Pengaturan")
.withIcon(R.drawable.ic_setting)
.withIdentifier(MENUSETTING),
new SecondaryDrawerItem().withName("Logout")
.withIcon(R.drawable.ic_logout)
.withIdentifier(MENULOGOUT))
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
......
......@@ -436,7 +436,7 @@ public class CapiInstanceAdapter extends RecyclerView.Adapter<CapiInstanceAdapte
void selectItem(int layoutPosition){
boolean isSelected = selectedItem.contains(layoutPosition);
if (isSelected) selectedItem.remove(layoutPosition);
if (isSelected) selectedItem.remove(selectedItem.indexOf(layoutPosition));
else selectedItem.add(layoutPosition);
//check instance finalized or fail to upload
......
package org.odk.collect.android.pemutakhiran.activities;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.Toast;
import com.rahadi.vsen.activities.DsrtMinImpActivity;
import com.rahadi.vsen.contexts.Vsen;
import com.rahadi.vsen.daos.BlokSensusDao;
import com.rahadi.vsen.daos.RutaDao;
import com.rahadi.vsen.listeners.OnGenerateCompletedListener;
import com.rahadi.vsen.models.KeyValueModel;
......@@ -32,8 +35,7 @@ public class DsrtActivity extends DsrtMinImpActivity implements OnGenerateComple
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: 21/02/2018 RAHADI: Dynamize
formId = "VSEN18K.v2";
formId = Vsen.getInstance().getGenerateFormId();
RutaDao rutaDao = new RutaDao();
Cursor b = rutaDao.getRutaCursor(null, RutaProviderAPI.Columns.BS_UUID + "=?",
......@@ -64,6 +66,12 @@ public class DsrtActivity extends DsrtMinImpActivity implements OnGenerateComple
@Override
public void onGenerateSucceed(int currentIdx, String rutaName) {
if (currentIdx == rutaModels.size() - 1) {
ContentValues cv = new ContentValues();
cv.put(BSProviderAPI.Columns.STATUS_GENERATE, 1);
new BlokSensusDao().updateBlokSensus(cv, BSProviderAPI.Columns.UUID + "=?",
new String[]{getBsUuid()});
progressDialog.dismiss();
Toast.makeText(this, "Generate Selesai", Toast.LENGTH_LONG).show();
} else {
......@@ -73,7 +81,7 @@ public class DsrtActivity extends DsrtMinImpActivity implements OnGenerateComple
HashMap<String, KeyValueModel> keyValues = new HashMap<>();
keyValues.put(BSProviderAPI.Columns.CONTENT_TYPE, new KeyValueModel(BSProviderAPI.Columns.UUID, getBsUuid()));
keyValues.put(RutaProviderAPI.Columns.CONTENT_TYPE, new KeyValueModel(RutaProviderAPI.Columns.UUID, rutaModels.get(0).getUuid()));
keyValues.put(RutaProviderAPI.Columns.CONTENT_TYPE, new KeyValueModel(RutaProviderAPI.Columns.UUID, rutaModels.get(currentIdx).getUuid()));
GenerateTask task = new GenerateTask(formId, getBsNks(), rutaModels, keyValues,
DsrtActivity.this);
......
......@@ -25,7 +25,9 @@ public class ItemPanduanActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wb_activity_item_panduan);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
recyclerView = (RecyclerView) findViewById(R.id.rv_item_panduan);
Log.d(VAR.DEBUG, "get intent : " +getIntent().getIntExtra("panduan",-1) +"-" +getIntent().getStringExtra("item"));
prepareData(getIntent().getIntExtra("panduan",-1));
......
......@@ -54,7 +54,9 @@ public class KonfigurasiPeta extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wb_activity_konfigurasi_peta);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
ni = connectivityManager.getActiveNetworkInfo();
......@@ -119,7 +121,7 @@ public class KonfigurasiPeta extends AppCompatActivity {
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (ItemsetDbAdapter.getInstance(getApplicationContext()).deleteAllLm()){
if (ItemsetDbAdapter.getInstance(getApplicationContext()).deleteAllLm()) {
getDaftarBsNew();
}
}
......@@ -133,7 +135,7 @@ public class KonfigurasiPeta extends AppCompatActivity {
builder.show();
} else {
Toast.makeText(KonfigurasiPeta.this,"Tidak ada koneksi internet",Toast.LENGTH_SHORT).show();
Toast.makeText(KonfigurasiPeta.this, "Tidak ada koneksi internet", Toast.LENGTH_SHORT).show();
}
}
});
......@@ -163,7 +165,7 @@ public class KonfigurasiPeta extends AppCompatActivity {
private void setTextInfo() {
tvServer.setText(sm.getUrlServer());
tvTimestamp.setText(sm.getTimestampDataBs());
switch (sm.getStatusUpload()){
switch (sm.getStatusUpload()) {
case 0:
tvInfoSinkron.setText("Belum diunggah");
break;
......@@ -175,10 +177,10 @@ public class KonfigurasiPeta extends AppCompatActivity {
public void uploadUpdateBs() {
ArrayList<BlokSensus> bsupdate = ItemsetDbAdapter.getInstance(getApplicationContext()).getListBlokSensusUpdated();
if (bsupdate!=null&&bsupdate.size()>0){
if (bsupdate != null && bsupdate.size() > 0) {
try {
JSONArray ja = new JSONArray();
for (BlokSensus bs:bsupdate){
for (BlokSensus bs : bsupdate) {
JSONObject jo = new JSONObject();
jo.put("id_bs", bs.getIdBs());
jo.put("timestamp", bs.getTimestamp());
......@@ -187,17 +189,17 @@ public class KonfigurasiPeta extends AppCompatActivity {
ja.put(jo);
}
uploadBs(ja.toString(), bsupdate);
Log.d(VAR.DEBUG, "json upload bs -> " +ja.toString());
} catch (Exception e){
Log.d(VAR.DEBUG, "error upload bs " +e);
Log.d(VAR.DEBUG, "json upload bs -> " + ja.toString());
} catch (Exception e) {
Log.d(VAR.DEBUG, "error upload bs " + e);
}
}
ArrayList<LandMark> lmupdate = ItemsetDbAdapter.getInstance(KonfigurasiPeta.this).getListLandmarkUpdated();
if (lmupdate!=null&&lmupdate.size()>0){
if (lmupdate != null && lmupdate.size() > 0) {
try {
JSONArray jalm = new JSONArray();
for (LandMark lm:lmupdate){
for (LandMark lm : lmupdate) {
JSONObject jolm = new JSONObject();
jolm.put(VAR.IDLM, lm.getId());
jolm.put(VAR.STATUS, lm.getStatus());
......@@ -211,9 +213,9 @@ public class KonfigurasiPeta extends AppCompatActivity {
}
uploadLm(jalm.toString(), lmupdate);
Log.d(VAR.DEBUG, "json upload lm -> " +jalm.toString());
Log.d(VAR.DEBUG, "json upload lm -> " + jalm.toString());
} catch (Exception e) {
Log.d(VAR.DEBUG, "error upload lm " +e);
Log.d(VAR.DEBUG, "error upload lm " + e);
}
}
}
......@@ -221,33 +223,33 @@ public class KonfigurasiPeta extends AppCompatActivity {
private void uploadBs(final String json, final ArrayList<BlokSensus> blokSensuses) {
showProgres();
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest ubs = new StringRequest(Request.Method.POST, sm.getUrlServer()+ VAR.UPLOAD_BS, new Response.Listener<String>(){
StringRequest ubs = new StringRequest(Request.Method.POST, sm.getUrlServer() + VAR.UPLOAD_BS, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
Log.d(VAR.DEBUG,"upload bs response "+response);
if (jsonObject.getString("status").equals("sukses")){
for (BlokSensus blokSensus:blokSensuses){
Log.d(VAR.DEBUG, "upload bs response " + response);
if (jsonObject.getString("status").equals("sukses")) {
for (BlokSensus blokSensus : blokSensuses) {