Commit 94555bd3 authored by rahadi's avatar rahadi

Added Pemutakhiran Module

parent 67b4f6f8
...@@ -367,14 +367,14 @@ the specific language governing permissions and limitations under the License. ...@@ -367,14 +367,14 @@ the specific language governing permissions and limitations under the License.
android:parentActivityName=".capi.activity.CapiMainActivity" /> android:parentActivityName=".capi.activity.CapiMainActivity" />
<activity <activity
android:name=".pemutakhiran.BSActivity" android:name=".pemutakhiran.activities.BSActivity"
android:theme="@style/VsenAppTheme" /> android:theme="@style/VsenAppTheme" />
<activity <activity
android:name=".pemutakhiran.RutaActivity" android:name=".pemutakhiran.activities.RutaActivity"
android:theme="@style/VsenAppTheme" /> android:theme="@style/VsenAppTheme" />
<activity <activity
android:name=".pemutakhiran.DsrtActivity" android:name=".pemutakhiran.activities.DsrtActivity"
android:theme="@style/VsenAppTheme" /> android:theme="@style/VsenAppTheme" />
</application> </application>
......
...@@ -33,8 +33,8 @@ import org.odk.collect.android.BuildConfig; ...@@ -33,8 +33,8 @@ import org.odk.collect.android.BuildConfig;
import org.odk.collect.android.R; import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect; import org.odk.collect.android.application.Collect;
import org.odk.collect.android.capi.activity.CapiLoginActivity; import org.odk.collect.android.capi.activity.CapiLoginActivity;
import org.odk.collect.android.capi.activity.CapiMainActivity;
import org.odk.collect.android.capi.preferences.CapiInstancePreferences; import org.odk.collect.android.capi.preferences.CapiInstancePreferences;
import org.odk.collect.android.pemutakhiran.BSActivity;
import org.odk.collect.android.preferences.GeneralSharedPreferences; import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.preferences.PreferenceKeys; import org.odk.collect.android.preferences.PreferenceKeys;
...@@ -80,8 +80,8 @@ public class SplashScreenActivity extends AppCompatActivity { ...@@ -80,8 +80,8 @@ public class SplashScreenActivity extends AppCompatActivity {
} }
if (preferences.getBoolean(PreferenceKeys.KEY_LOGIN_STATUS, false)) { if (preferences.getBoolean(PreferenceKeys.KEY_LOGIN_STATUS, false)) {
// startActivity(new Intent(this, CapiMainActivity.class)); startActivity(new Intent(this, CapiMainActivity.class));
startActivity(new Intent(this, BSActivity.class)); // startActivity(new Intent(this, BSActivity.class));
} else { } else {
startActivity(new Intent(this, CapiLoginActivity.class)); startActivity(new Intent(this, CapiLoginActivity.class));
} }
......
...@@ -80,6 +80,9 @@ public class Collect extends Application { ...@@ -80,6 +80,9 @@ public class Collect extends Application {
public static final String DEFAULT_FONTSIZE = "16"; public static final String DEFAULT_FONTSIZE = "16";
public static final String OFFLINE_LAYERS = ODK_ROOT + File.separator + "layers"; public static final String OFFLINE_LAYERS = ODK_ROOT + File.separator + "layers";
public static final String SETTINGS = ODK_ROOT + File.separator + "settings"; public static final String SETTINGS = ODK_ROOT + File.separator + "settings";
public static final String EMPTY_INSTANCES_PATH = ODK_ROOT + File.separator + "instances" + File.separator + "empty";
private static Collect singleton = null; private static Collect singleton = null;
static { static {
...@@ -122,7 +125,8 @@ public class Collect extends Application { ...@@ -122,7 +125,8 @@ public class Collect extends Application {
} }
String[] dirs = { String[] dirs = {
ODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH, OFFLINE_LAYERS ODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH, OFFLINE_LAYERS,
EMPTY_INSTANCES_PATH
}; };
for (String dirName : dirs) { for (String dirName : dirs) {
......
...@@ -14,17 +14,17 @@ import android.widget.EditText; ...@@ -14,17 +14,17 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.gson.GsonBuilder;
import com.rahadi.vsen.contexts.Vsen; import com.rahadi.vsen.contexts.Vsen;
import com.rahadi.vsen.listeners.OnSynchronizationCompletedListener; import com.rahadi.vsen.listeners.OnSynchronizationCompletedListener;
import com.rahadi.vsen.listeners.OnSynchronizationErrorListener;
import com.rahadi.vsen.models.UserModel; import com.rahadi.vsen.models.UserModel;
import com.rahadi.vsen.tasks.BSSynchronizationTask; import com.rahadi.vsen.tasks.BSSynchronizationTask;
import com.rahadi.vsen.tasks.GetGenerateTask;
import com.rahadi.vsen.tasks.UserRegisterTask; import com.rahadi.vsen.tasks.UserRegisterTask;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.odk.collect.android.R; import org.odk.collect.android.R;
import org.odk.collect.android.pemutakhiran.BSActivity;
import org.odk.collect.android.preferences.GeneralSharedPreferences; import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.preferences.PreferenceKeys; import org.odk.collect.android.preferences.PreferenceKeys;
import org.odk.collect.android.preferences.PreferencesActivity; import org.odk.collect.android.preferences.PreferencesActivity;
...@@ -112,16 +112,10 @@ public class CapiLoginActivity extends AppCompatActivity ...@@ -112,16 +112,10 @@ public class CapiLoginActivity extends AppCompatActivity
new UserRegisterTask(username, uuid).execute(new OnSynchronizationCompletedListener<JSONObject>() { new UserRegisterTask(username, uuid).execute(new OnSynchronizationCompletedListener<JSONObject>() {
@Override @Override
public void onSynchronizationCompleted(JSONObject result) { public void onSynchronizationCompleted(JSONObject result) {
// TODO: 22/01/2018 RAHADI: FILL IN THE BLANK UserModel r = new GsonBuilder().create().fromJson(result.toString(), UserModel.class);
Timber.d("UserRegister: " + result.toString()); Timber.d(r.toString());
Vsen.getInstance().setUserSession(new UserModel.Builder()
.setIdUser(username) Vsen.getInstance().setUserSession(r);
.setNamaUser("")
.setIdSupervisor("")
.setNamaSupervisor("")
.setPrivilege(0)
.setAuthToken(uuid)
.build());
dialog.setMessage("Sinkronisasi Data.."); dialog.setMessage("Sinkronisasi Data..");
...@@ -129,12 +123,25 @@ public class CapiLoginActivity extends AppCompatActivity ...@@ -129,12 +123,25 @@ public class CapiLoginActivity extends AppCompatActivity
new OnSynchronizationCompletedListener<JSONArray>() { new OnSynchronizationCompletedListener<JSONArray>() {
@Override @Override
public void onSynchronizationCompleted(JSONArray result) { public void onSynchronizationCompleted(JSONArray result) {
Timber.d("BSSync: " + result.toString()); // TODO: 20/02/2018 RAHADI: dynamize
onLoginSucceed(); 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 @Override
public void onSynchronizationFailed(Exception e) { public void onSynchronizationFailed(Exception e) {
Timber.e(e);
onLoginFailed(e.toString()); onLoginFailed(e.toString());
} }
}); });
...@@ -142,13 +149,8 @@ public class CapiLoginActivity extends AppCompatActivity ...@@ -142,13 +149,8 @@ public class CapiLoginActivity extends AppCompatActivity
@Override @Override
public void onSynchronizationFailed(Exception e) { public void onSynchronizationFailed(Exception e) {
Timber.e(e);
} onLoginFailed(e.toString());
}, new OnSynchronizationErrorListener() {
@Override
public void onSynchronizationError(Exception exception) {
Timber.e(exception);
onLoginFailed("Fail to get id on server : " + exception.getMessage());
} }
}); });
} }
...@@ -159,7 +161,8 @@ public class CapiLoginActivity extends AppCompatActivity ...@@ -159,7 +161,8 @@ public class CapiLoginActivity extends AppCompatActivity
loginBtn.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); loginBtn.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
GeneralSharedPreferences.getInstance().save(PreferenceKeys.KEY_LOGIN_STATUS, true); GeneralSharedPreferences.getInstance().save(PreferenceKeys.KEY_LOGIN_STATUS, true);
Intent toMain = new Intent(this, BSActivity.class); // Intent toMain = new Intent(this, BSActivity.class);
Intent toMain = new Intent(this, CapiMainActivity.class);
startActivity(toMain); startActivity(toMain);
finish(); finish();
} }
......
...@@ -3,21 +3,19 @@ package org.odk.collect.android.capi.activity; ...@@ -3,21 +3,19 @@ package org.odk.collect.android.capi.activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.FirebaseMessaging;
...@@ -28,45 +26,35 @@ import com.mikepenz.materialdrawer.DrawerBuilder; ...@@ -28,45 +26,35 @@ import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.model.DividerDrawerItem; import com.mikepenz.materialdrawer.model.DividerDrawerItem;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.ProfileDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
import com.mikepenz.materialdrawer.util.DrawerImageLoader; import com.mikepenz.materialdrawer.util.DrawerImageLoader;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.odk.collect.android.R; import org.odk.collect.android.R;
import org.odk.collect.android.activities.FileManagerTabs;
import org.odk.collect.android.capi.preferences.Constants;
import org.odk.collect.android.capi.fragment.CapiFormFragment;
import org.odk.collect.android.activities.InstanceChooserList;
import org.odk.collect.android.activities.InstanceUploaderList;
import org.odk.collect.android.activities.SplashScreenActivity; import org.odk.collect.android.activities.SplashScreenActivity;
import org.odk.collect.android.capi.fragment.CapiFormFragment;
import org.odk.collect.android.capi.preferences.CapiInstancePreferences; import org.odk.collect.android.capi.preferences.CapiInstancePreferences;
import org.odk.collect.android.capi.Helper;
import org.odk.collect.android.capi.ModelResponse;
import org.odk.collect.android.capi.ModelSurvey;
import org.odk.collect.android.listeners.DiskSyncListener; import org.odk.collect.android.listeners.DiskSyncListener;
import org.odk.collect.android.pemutakhiran.activities.BSActivity;
import org.odk.collect.android.preferences.GeneralSharedPreferences; import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.preferences.PreferenceKeys; import org.odk.collect.android.preferences.PreferenceKeys;
import org.odk.collect.android.revalidasi.activities.DataDownloadActivity; import org.odk.collect.android.revalidasi.activities.DataDownloadActivity;
import org.odk.collect.android.revalidasi.notifikasi.GetUuidTask; import org.odk.collect.android.revalidasi.notifikasi.GetUuidTask;
import org.odk.collect.android.tasks.DiskSyncTask; import org.odk.collect.android.tasks.DiskSyncTask;
import org.odk.collect.android.utilities.ApplicationConstants;
import java.util.ArrayList;
import timber.log.Timber; import timber.log.Timber;
/** /**
* @author Muhammad Tohir * @author Muhammad Tohir
* edit Mahendri Dwicahyo * edit Mahendri Dwicahyo
*/ */
public class CapiMainActivity extends AppCompatActivity implements DiskSyncListener { public class CapiMainActivity extends AppCompatActivity implements DiskSyncListener {
//Identifier //Identifier
private static final int MENU_PEMUTAKHIRAN = 3;
private static final int MENUSURVEY = 4; private static final int MENUSURVEY = 4;
private static final int MENU_UPDATE = 5; private static final int MENU_UPDATE = 5;
private static final int MENUSETTING = 8; private static final int MENUSETTING = 8;
...@@ -91,7 +79,7 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe ...@@ -91,7 +79,7 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
getSupportActionBar().setTitle("Daftar Kuesioner"); getSupportActionBar().setTitle("Daftar Kuesioner");
diskSyncTask = (DiskSyncTask) getLastCustomNonConfigurationInstance(); diskSyncTask = (DiskSyncTask) getLastCustomNonConfigurationInstance();
if (diskSyncTask == null){ if (diskSyncTask == null) {
Timber.i("Starting new disk sync task"); Timber.i("Starting new disk sync task");
diskSyncTask = new DiskSyncTask(); diskSyncTask = new DiskSyncTask();
diskSyncTask.setDiskSyncListener(this); diskSyncTask.setDiskSyncListener(this);
...@@ -103,18 +91,18 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe ...@@ -103,18 +91,18 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
initializeDrawer(this, savedInstanceState); initializeDrawer(this, savedInstanceState);
} }
private void openFragment(Fragment fragment){ private void openFragment(Fragment fragment) {
try { try {
if(fragment != null){ if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_main_menu, fragment).commit(); fragmentManager.beginTransaction().replace(R.id.content_main_menu, fragment).commit();
} }
}catch (Exception e){ } catch (Exception e) {
Log.d("DEBUG", e.getMessage()); Log.d("DEBUG", e.getMessage());
} }
} }
private void initLoader(){ private void initLoader() {
//init when url has been found //init when url has been found
DrawerImageLoader.init(new AbstractDrawerImageLoader() { DrawerImageLoader.init(new AbstractDrawerImageLoader() {
@Override @Override
...@@ -140,7 +128,7 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe ...@@ -140,7 +128,7 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
diskSyncTask.setDiskSyncListener(this); diskSyncTask.setDiskSyncListener(this);
super.onResume(); super.onResume();
if (diskSyncTask.getStatus() == AsyncTask.Status.FINISHED){ if (diskSyncTask.getStatus() == AsyncTask.Status.FINISHED) {
syncComplete(diskSyncTask.getStatusMessage()); syncComplete(diskSyncTask.getStatusMessage());
} }
} }
...@@ -169,13 +157,13 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe ...@@ -169,13 +157,13 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
prefs.reset(PreferenceKeys.KEY_USERGROUP); prefs.reset(PreferenceKeys.KEY_USERGROUP);
prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP); prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP);
String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES); String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES);
if(StringUtils.isNotEmpty(uuid)) if (StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid)); FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid));
startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class)); startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class));
finish(); finish();
} }
private void initializeDrawer(final Context context, Bundle savedInstanceState){ private void initializeDrawer(final Context context, Bundle savedInstanceState) {
//get user data //get user data
String username = (String) prefs.get(PreferenceKeys.KEY_USERNAME); String username = (String) prefs.get(PreferenceKeys.KEY_USERNAME);
...@@ -201,6 +189,8 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe ...@@ -201,6 +189,8 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
.withItemAnimator(new DefaultItemAnimator()) .withItemAnimator(new DefaultItemAnimator())
.withAccountHeader(accountHeader) .withAccountHeader(accountHeader)
.addDrawerItems( .addDrawerItems(
new PrimaryDrawerItem().withName("Pemutakhiran").withIcon(R.drawable.wb_ic_edit_bs).withIdentifier(MENU_PEMUTAKHIRAN),
new DividerDrawerItem(),
new PrimaryDrawerItem().withName("Daftar Kuesioner").withIcon(R.drawable.ic_survey).withIdentifier(MENUSURVEY), new PrimaryDrawerItem().withName("Daftar Kuesioner").withIcon(R.drawable.ic_survey).withIdentifier(MENUSURVEY),
new PrimaryDrawerItem().withName("Update Isian").withIcon(R.drawable.ic_assignment_done).withIdentifier(MENU_UPDATE), new PrimaryDrawerItem().withName("Update Isian").withIcon(R.drawable.ic_assignment_done).withIdentifier(MENU_UPDATE),
new DividerDrawerItem(), new DividerDrawerItem(),
...@@ -210,7 +200,11 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe ...@@ -210,7 +200,11 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override @Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
switch ((int) drawerItem.getIdentifier()){ switch ((int) drawerItem.getIdentifier()) {
case MENU_PEMUTAKHIRAN:
startActivity(new Intent(context, BSActivity.class));
break;
case MENUSURVEY: case MENUSURVEY:
getSupportActionBar().setTitle("Daftar Kuesioner"); getSupportActionBar().setTitle("Daftar Kuesioner");
openFragment(capiListForms); openFragment(capiListForms);
......
package org.odk.collect.android.pemutakhiran;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import com.rahadi.vsen.activities.DsrtImpActivity;
import com.rahadi.vsen.models.DsrtModel;
/**
* Created by Rahadi on 27/01/2018.
*/
public class DsrtActivity extends DsrtImpActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onDsrtActionButtonClick(View v, DsrtModel model, String mode, boolean isPml) {
}
}
package org.odk.collect.android.pemutakhiran; package org.odk.collect.android.pemutakhiran.activities;
import android.os.Bundle; import android.os.Bundle;
......
package org.odk.collect.android.pemutakhiran.activities;
import android.app.ProgressDialog;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
import com.rahadi.vsen.activities.DsrtMinImpActivity;
import com.rahadi.vsen.daos.RutaDao;
import com.rahadi.vsen.listeners.OnGenerateCompletedListener;
import com.rahadi.vsen.models.KeyValueModel;
import com.rahadi.vsen.models.RutaModel;
import com.rahadi.vsen.providers.BSProviderAPI;
import com.rahadi.vsen.providers.RutaProviderAPI;
import org.odk.collect.android.pemutakhiran.tasks.GenerateTask;
import java.util.HashMap;
import java.util.List;
/**
* Created by Rahadi on 27/01/2018.
*/
public class DsrtActivity extends DsrtMinImpActivity implements OnGenerateCompletedListener {
ProgressDialog progressDialog;
List<RutaModel> rutaModels;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RutaDao rutaDao = new RutaDao();
Cursor b = rutaDao.getRutaCursor(null, RutaProviderAPI.Columns.BS_UUID + "=?",
new String[]{getBsUuid()}, null);
rutaModels = rutaDao.getRutaListFromCursor(b);
progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Menggenerate Kuesioner");
progressDialog.setCancelable(false);
progressDialog.setMessage("Harap Tunggu..");
progressDialog.setMax(rutaModels.size());
}
@Override
public void onGenerateMenuClicked(String bsUuid, String bsNks) {
progressDialog.show();
// TODO: 20/02/2018 RAHADI: dynamize
String formId = "VSEN18K.v2";
for (RutaModel r : rutaModels) {
String rutaUuid = r.getUuid();
String rutaName = r.getNamaKrt();
String filename = formId + "_" + bsNks + "_" + rutaName;
HashMap<String, KeyValueModel> keyValues = new HashMap<>();
keyValues.put(BSProviderAPI.Columns.CONTENT_TYPE, new KeyValueModel(BSProviderAPI.Columns.UUID, bsUuid));
keyValues.put(RutaProviderAPI.Columns.CONTENT_TYPE, new KeyValueModel(RutaProviderAPI.Columns.UUID, r.getUuid()));
GenerateTask task = new GenerateTask(formId, rutaUuid, rutaName, filename, keyValues,
DsrtActivity.this);
task.execute();
}
}
@Override
public void onGenerateSucceed(Uri instanceUri, String rutaUuid, String rutaName) {
int progress = progressDialog.getProgress() + 1;
progressDialog.setProgress(progress);
progressDialog.setMessage("Ruta: " + rutaName);
if (progress == progressDialog.getMax()) {
progressDialog.dismiss();
Toast.makeText(this, "Generate Selesai", Toast.LENGTH_LONG).show();
}
}
@Override
public void onGenerateFailed(Exception e) {
progressDialog.dismiss();
Toast.makeText(this, "Generate Gagal : " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
package org.odk.collect.android.pemutakhiran; package org.odk.collect.android.pemutakhiran.activities;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
......
package org.odk.collect.android.pemutakhiran.tasks;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import com.rahadi.vsen.contexts.Vsen;
import com.rahadi.vsen.daos.GenerateDao;
import com.rahadi.vsen.listeners.OnGenerateCompletedListener;
import com.rahadi.vsen.models.GenerateModel;
import com.rahadi.vsen.models.KeyValueModel;
import com.rahadi.vsen.providers.GenerateProviderAPI;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.dao.FormsDao;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.utilities.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import timber.log.Timber;
/**
* Created by Rahadi on 20/02/2018.
*/
public class GenerateTask extends AsyncTask<Void, Void, Void> {
private String filename, formId, rutaUuid, rutaName;
private HashMap<String, KeyValueModel> keyValues;
private OnGenerateCompletedListener onGenerateCompletedListener;
public GenerateTask(String formId, String rutaUuid, String rutaName, String filename,
HashMap<String, KeyValueModel> keyValues,
OnGenerateCompletedListener onGenerateCompletedListener) {
this.filename = filename;
this.formId = formId;
this.rutaUuid = rutaUuid;
this.rutaName = rutaName;
this.keyValues = keyValues;
this.onGenerateCompletedListener = onGenerateCompletedListener;
}
@Override
protected Void doInBackground(Void... voids) {
try {
Cursor f = new FormsDao().getFormsCursor(
new String[]{FormsProviderAPI.FormsColumns.EMPTY_INSTANCE_FILE_PATH},
FormsProviderAPI.FormsColumns.JR_FORM_ID + "=?", new String[]{formId},
null);
String emptyInstancePath = f.getString(f.getColumnIndex(
FormsProviderAPI.FormsColumns.EMPTY_INSTANCE_FILE_PATH));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(emptyInstancePath));
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
Cursor g = new GenerateDao().getGenerateCursor(null,
GenerateProviderAPI.Columns.FORM_ID + "=?", new String[]{formId}, null);
List<GenerateModel> gms = new GenerateDao().getGenerateListFromCursor(g);
for (GenerateModel gm : gms) {
String value = null;
Uri uri = Uri.parse(gm.getTableUri());
String type = Vsen.getInstance().getContentResolver().getType(uri);
KeyValueModel kv = keyValues.get(type);
Cursor c = Vsen.getInstance().getContentResolver().query(uri, new String[]{gm.getCursorName()},