Commit 7d68cfc1 authored by rahadi's avatar rahadi

Added Pemutakhiran Module

parent b9305b74
......@@ -2,7 +2,6 @@ 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;
......@@ -25,56 +24,60 @@ import java.util.List;
public class DsrtActivity extends DsrtMinImpActivity implements OnGenerateCompletedListener {
ProgressDialog progressDialog;
List<RutaModel> rutaModels;
private String formId;
private ProgressDialog progressDialog;
private List<RutaModel> rutaModels;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: 21/02/2018 RAHADI: Dynamize
formId = "VSEN18K.v2";
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.setTitle("Generate Kuesioner");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
progressDialog.setMessage("Harap Tunggu..");
progressDialog.setMax(rutaModels.size());
}
@Override
public void onGenerateMenuClicked(String bsUuid, String bsNks) {
public void onGenerateMenuClicked() {
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()));
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()));
GenerateTask task = new GenerateTask(formId, rutaUuid, rutaName, filename, keyValues,
DsrtActivity.this);
task.execute();
}
GenerateTask task = new GenerateTask(formId, getBsNks(), rutaModels, keyValues,
DsrtActivity.this);
task.execute(0);
}
@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()) {
public void onGenerateSucceed(int currentIdx, String rutaName) {
if (currentIdx == rutaModels.size() - 1) {
progressDialog.dismiss();
Toast.makeText(this, "Generate Selesai", Toast.LENGTH_LONG).show();
} else {
currentIdx++;
progressDialog.setProgress(currentIdx);
progressDialog.setMessage("Ruta: " + rutaName);
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()));
GenerateTask task = new GenerateTask(formId, getBsNks(), rutaModels, keyValues,
DsrtActivity.this);
task.execute(currentIdx);
}
}
......
......@@ -141,6 +141,7 @@ public class FormsProvider extends ContentProvider {
+ ((oldVersion != 3) ? ""
: (FormsColumns.BASE64_RSA_PUBLIC_KEY + ", "))
+ FormsColumns.JRCACHE_FILE_PATH
+ ", "
+ FormsColumns.EMPTY_INSTANCE_FILE_PATH
+ ") SELECT "
+ FormsColumns._ID
......@@ -174,7 +175,9 @@ public class FormsProvider extends ContentProvider {
+ ((oldVersion != 3) ? ""
: (FormsColumns.BASE64_RSA_PUBLIC_KEY + ", "))
+ FormsColumns.JRCACHE_FILE_PATH
+ FormsColumns.EMPTY_INSTANCE_FILE_PATH + " FROM "
+ ", "
+ FormsColumns.EMPTY_INSTANCE_FILE_PATH
+ " FROM "
+ FORMS_TABLE_NAME);
// risky failures here...
......@@ -203,7 +206,7 @@ public class FormsProvider extends ContentProvider {
+ FormsColumns.SUBMISSION_URI + ", "
+ FormsColumns.JR_VERSION + ", "
+ FormsColumns.BASE64_RSA_PUBLIC_KEY + ", "
+ FormsColumns.JRCACHE_FILE_PATH
+ FormsColumns.JRCACHE_FILE_PATH + ", "
+ FormsColumns.EMPTY_INSTANCE_FILE_PATH + ") SELECT "
+ FormsColumns._ID + ", "
+ FormsColumns.DISPLAY_NAME
......@@ -224,7 +227,7 @@ public class FormsProvider extends ContentProvider {
+ FormsColumns.SUBMISSION_URI + ", "
+ FormsColumns.JR_VERSION + ", "
+ FormsColumns.BASE64_RSA_PUBLIC_KEY + ", "
+ FormsColumns.JRCACHE_FILE_PATH
+ FormsColumns.JRCACHE_FILE_PATH + ", "
+ FormsColumns.EMPTY_INSTANCE_FILE_PATH + " FROM "
+ TEMP_FORMS_TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + TEMP_FORMS_TABLE_NAME);
......
......@@ -44,6 +44,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import timber.log.Timber;
import static org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import static org.odk.collect.android.provider.InstanceProviderAPI.LATEST_VERSION;
/**
* Background task for syncing form instances from the instances folder to the instances table.
......@@ -169,6 +170,7 @@ public class InstanceSyncTask extends AsyncTask<Void, String, String> {
? InstanceProviderAPI.STATUS_COMPLETE : InstanceProviderAPI.STATUS_INCOMPLETE);
values.put(InstanceColumns.CAN_EDIT_WHEN_COMPLETE, Boolean.toString(true));
values.put(InstanceColumns.INSTANCE_UUID, getInstanceIdFromInstance(candidateInstance));
values.put(InstanceColumns.LATEST, LATEST_VERSION);
// save the new instance object
Collect.getInstance().getContentResolver()
.insert(InstanceColumns.CONTENT_URI, values);
......
......@@ -82,7 +82,7 @@ public abstract class DsrtMinImpActivity extends AppCompatActivity {
if (menuId == android.R.id.home) {
onBackPressed();
} else if (menuId == R.id.generate_menu_item) {
onGenerateMenuClicked(bsUuid, bsNks);
onGenerateMenuClicked();
}
return true;
......@@ -103,6 +103,6 @@ public abstract class DsrtMinImpActivity extends AppCompatActivity {
return bsNks;
}
public abstract void onGenerateMenuClicked(String bsUuid, String bsNks);
public abstract void onGenerateMenuClicked();
}
......@@ -7,7 +7,7 @@ import android.net.Uri;
*/
public interface OnGenerateCompletedListener {
void onGenerateSucceed(Uri instanceUri, String rutaUuid, String rutaName);
void onGenerateSucceed(int currentIdx, String rutaName);
void onGenerateFailed(Exception e);
}
\ No newline at end of file
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