diff --git a/app/app.iml b/app/app.iml index f030532..f149e77 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,9 +1,11 @@ - + @@ -17,30 +19,29 @@ - + - - - - + + - - + + @@ -62,13 +63,6 @@ - - - - - - - @@ -76,48 +70,46 @@ - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 982f8e8..441cbe6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,9 +6,9 @@ android { defaultConfig { applicationId "org.iphukan.ubforms" minSdkVersion 16 - targetSdkVersion 27 - versionCode 17 - versionName "1.17" + targetSdkVersion 29 + versionCode 19 + versionName "1.19" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -27,4 +27,5 @@ dependencies { compile 'com.android.support:appcompat-v7:27.0.1' //compile 'com.android.support:appcompat-v7:27.+' testCompile 'junit:junit:4.12' + compile 'com.karumi:dexter:4.2.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 94573fb..b94055f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,10 +1,10 @@ + android:versionCode="19" + android:versionName="1.19"> - + diff --git a/app/src/main/java/org/iphukan/ubforms/AttributeDetailsActivity.java b/app/src/main/java/org/iphukan/ubforms/AttributeDetailsActivity.java index e422d52..b5d32f5 100644 --- a/app/src/main/java/org/iphukan/ubforms/AttributeDetailsActivity.java +++ b/app/src/main/java/org/iphukan/ubforms/AttributeDetailsActivity.java @@ -1,9 +1,9 @@ package org.iphukan.ubforms; -import org.iphukan.ubforms.data.Attribute; -import org.iphukan.ubforms.data.AttributeDao; -import org.iphukan.ubforms.data.Entity; - +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Context; +import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; @@ -15,6 +15,10 @@ import android.widget.Spinner; import android.widget.TextView; +import org.iphukan.ubforms.data.Attribute; +import org.iphukan.ubforms.data.AttributeDao; +import org.iphukan.ubforms.data.Entity; + public class AttributeDetailsActivity extends BaseActivity { private Attribute currentAttribute = null; @@ -38,7 +42,7 @@ public void onCreate(Bundle savedInstanceState) { LinearLayout fieldDetails = new LinearLayout(this); fieldDetails.setOrientation(LinearLayout.VERTICAL); - fieldDetails.setMinimumWidth(COL_MIN_WIDTH); + //fieldDetails.setMinimumWidth(COL_MIN_WIDTH); setContentView(fieldDetails); Button btnSave = new Button(this); @@ -118,6 +122,33 @@ public void onClick(View view) { fieldDetails.addView(tvExample); etValidationExample = new EditText(this); fieldDetails.addView(etValidationExample); + + Button btnDel = new Button(this); + btnDel.setText(R.string.del_field_def); + btnDel.setTextSize(TEXT_SIZE_LARGE); + btnDel.setBackgroundColor(Color.parseColor("#A00000")); + final Context context = this; + btnDel.setOnClickListener(new OnClickListener(){ + public void onClick(View view) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(getString(R.string.are_sure_delete_item)) + .setCancelable(false) + .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + delField(); + } + }) + .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + } + }); + + fieldDetails.addView(btnDel); Bundle bundle = getIntent().getExtras(); @@ -153,6 +184,31 @@ private void saveFieldDetails() { sqlHelper.close(); } } + + private void delField() { + if (currentAttribute == null) return; + /*currentAttribute.setAttributeName(etFieldName.getText().toString()); + currentAttribute.setAttributeDesc(etFieldDescription.getText().toString()); + int position = spDatatype.getSelectedItemPosition(); + currentAttribute.setDataType(Attribute.DATA_TYPES[position]); + currentAttribute.setRefEntityName(etRefType.getText().toString()); + currentAttribute.setPrimaryKeyPart(cbKey.isChecked()); + currentAttribute.setRequired(cbRequired.isChecked()); + currentAttribute.setSearchable(cbSearchable.isChecked()); + currentAttribute.setListable(cbListable.isChecked()); + currentAttribute.setEntityDescription(cbEntityDescription.isChecked()); + currentAttribute.setChoices(etChoices.getText().toString()); + currentAttribute.setValidationRegex(etValidationRegex.getText().toString()); + currentAttribute.setValidationExample(etValidationExample.getText().toString()); + */ + try { + new AttributeDao(sqlHelper.getWritableDatabase()).delete(currentAttribute); + makeToast(getString(R.string.deleted)); + finish(); + } finally { + sqlHelper.close(); + } + } private void readFieldDetails(Attribute attribute) { etFieldDescription.setText(attribute.getAttributeDesc()); diff --git a/app/src/main/java/org/iphukan/ubforms/BackupRestoreActivity.java b/app/src/main/java/org/iphukan/ubforms/BackupRestoreActivity.java index 3e7af17..cbd4287 100644 --- a/app/src/main/java/org/iphukan/ubforms/BackupRestoreActivity.java +++ b/app/src/main/java/org/iphukan/ubforms/BackupRestoreActivity.java @@ -1,19 +1,7 @@ package org.iphukan.ubforms; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import android.Manifest; +import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -29,6 +17,15 @@ import android.widget.Spinner; import android.widget.TextView; +import com.karumi.dexter.Dexter; +import com.karumi.dexter.MultiplePermissionsReport; +import com.karumi.dexter.PermissionToken; +import com.karumi.dexter.listener.PermissionRequest; +import com.karumi.dexter.listener.multi.MultiplePermissionsListener; + +import org.iphukan.ubforms.common.DialogUtils; +import org.iphukan.ubforms.common.IDialogClickListener; +import org.iphukan.ubforms.common.IGrantPermissionCallback; import org.iphukan.ubforms.data.Attribute; import org.iphukan.ubforms.data.AttributeDao; import org.iphukan.ubforms.data.BlobData; @@ -37,11 +34,27 @@ import org.iphukan.ubforms.data.Entity; import org.iphukan.ubforms.data.EntityDao; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class BackupRestoreActivity extends BaseActivity { private String storagePath; + public File blobDir = null; + @Override @@ -157,6 +170,27 @@ public void onClick(DialogInterface dialog, int id) { } + private void checkStoragePermission(Activity activity, final IGrantPermissionCallback callback) { + Dexter.withActivity(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE) + .withListener(new MultiplePermissionsListener() { + @Override + public void onPermissionsChecked(MultiplePermissionsReport report) { + if (callback == null) return; + if (report.isAnyPermissionPermanentlyDenied()) { + callback.denied(); + } else { + callback.granted(); + } + } + + @Override + public void onPermissionRationaleShouldBeShown(List permissions, PermissionToken token) { + token.continuePermissionRequest(); + } + }).check(); + } + private void doDeleteEntity() { final Context context = this; @@ -225,9 +259,10 @@ public void onClick(DialogInterface dialog, int whichButton) { } private File getBlobExportDir() { - File blobdir = new File(storagePath + "/blob_data"); - blobdir.mkdirs(); - return blobdir; + + File blobDir = new File(storagePath + "/blob_data"); + blobDir.mkdirs(); + return blobDir; } private String getBlobMetadataFileName() { @@ -316,115 +351,148 @@ private BlobData getMetadataRow(BufferedReader in, int rowCount) throws IOExcept private void doBlobExport() throws IOException { - File blobdir = getBlobExportDir(); + File blobDir = getBlobExportDir(); - // Delete any existing exported blob data first - File[] files = blobdir.listFiles(); - for (File file: files) file.delete(); + // Delete any existing exported blob data first + File[] files = blobDir.listFiles(); + for (File file: files) file.delete(); - File metadata = new File(blobdir, getBlobMetadataFileName()); - if (metadata.exists()) metadata.delete(); - Writer out = new BufferedWriter(new FileWriter(metadata)); + File metadata = new File(blobDir, getBlobMetadataFileName()); + if (metadata.exists()) metadata.delete(); + Writer out = null; + try{ + out = new BufferedWriter(new FileWriter(metadata)); + }catch (java.io.IOException ex){} - // header - String header = "\"giud\",\"fileName\",\"mimeType\",\"size\"\n"; - out.write(header); - - SQLiteDatabase database = sqlHelper.getWritableDatabase(); - BlobDataDao blobDataDao = new BlobDataDao(database); - try { + // header + String header = "\"giud\",\"fileName\",\"mimeType\",\"size\"\n"; + try{ + out.write(header); + }catch (java.io.IOException ex){} - Cursor cursor = database.query(BlobDataDao.TABLE_NAME, BlobDataDao.ALL_FIELDS, null, null, null, null, null); - cursor.moveToFirst(); - while (!cursor.isAfterLast()) { + SQLiteDatabase database = sqlHelper.getWritableDatabase(); + BlobDataDao blobDataDao = new BlobDataDao(database); + try { - BlobData data = blobDataDao.mapObject(cursor); + Cursor cursor = database.query(BlobDataDao.TABLE_NAME, BlobDataDao.ALL_FIELDS, null, null, null, null, null); - String line = "\""+ data.getGuid() - +"\",\""+ csvEscape(data.getFileName()) - +"\",\""+ csvEscape(data.getMimeType()) - +"\",\""+ data.getSize()+"\"\n"; + cursor.moveToFirst(); + while (!cursor.isAfterLast()) { - out.write(line); + BlobData data = blobDataDao.mapObject(cursor); - File datfile = new File(blobdir, data.getGuid() + ".dat"); - if (datfile.exists()) datfile.delete(); - FileOutputStream datout = new FileOutputStream(datfile); - datout.write(data.getBlobData()); - datout.close(); + String line = "\""+ data.getGuid() + +"\",\""+ csvEscape(data.getFileName()) + +"\",\""+ csvEscape(data.getMimeType()) + +"\",\""+ data.getSize()+"\"\n"; - cursor.moveToNext(); - } + try{ + out.write(line); + }catch (java.io.IOException ex){} - cursor.close(); - - } finally { - sqlHelper.close(); - out.flush(); - out.close(); - } - } - private void doExport() { + File datfile = new File(blobDir, data.getGuid() + ".dat"); + if (datfile.exists()) datfile.delete(); + try{ + FileOutputStream datout = new FileOutputStream(datfile); + datout.write(data.getBlobData()); + datout.close(); + }catch (java.io.IOException ex){} - try { - List entities = getEntities(); - for (Entity entity: entities) { + cursor.moveToNext(); + } - List attributes = getAttributes(entity); - entity.setAttributes(attributes); - File file = getEntityFile(entity); - if (file.exists()) file.delete(); - Writer out = new BufferedWriter(new FileWriter(file)); - try { + cursor.close(); - //header record - out.write("\"_id\""); - for (Attribute attribute: attributes) { - out.write(","); - out.write("\""+csvEscape(attribute.getAttributeName())+"\""); - } - out.write("\r\n"); + } finally { + sqlHelper.close(); + try{ + out.flush(); + out.close(); + }catch (java.io.IOException ex){} + } - SQLiteDatabase database = sqlHelper.getWritableDatabase(); - DataDao dataDao = new DataDao(database); - try { - List> results = dataDao.searchNoLimits(entity, new HashMap()); - for (Map row: results) { - out.write("\""+row.get("_id")+"\""); - for (Attribute attribute: attributes) { - String name = attribute.getAttributeName(); - String value = row.get(name); - if (value == null) value = ""; - value = csvEscape(value); - String field = ",\"" + value + "\""; - out.write(field); - } - out.write("\r\n"); - } - - } finally { - sqlHelper.close(); - } - - } finally { - out.flush(); - out.close(); - } - } - - doBlobExport(); + } - makeToast(getString(R.string.data_files_exported,entities.size())); + private void doExport() { - doExportForms(); + final Activity activity = this; + checkStoragePermission(activity, new IGrantPermissionCallback() { + @Override + public void granted() { + DialogUtils.displayChooseOkNoDialog(activity, R.string.allow_storage, + R.string.permission_granted, new IDialogClickListener() { + @Override + public void onOK() { + try { + + List entities = getEntities(); + for (Entity entity: entities) { + + List attributes = getAttributes(entity); + entity.setAttributes(attributes); + File file = getEntityFile(entity); + if (file.exists()) file.delete(); + Writer out = new BufferedWriter(new FileWriter(file)); + try { + + //header record + out.write("\"_id\""); + for (Attribute attribute: attributes) { + out.write(","); + out.write("\""+csvEscape(attribute.getAttributeName())+"\""); + } + out.write("\r\n"); + + SQLiteDatabase database = sqlHelper.getWritableDatabase(); + DataDao dataDao = new DataDao(database); + try { + List> results = dataDao.searchNoLimits(entity, new HashMap()); + for (Map row: results) { + out.write("\""+row.get("_id")+"\""); + for (Attribute attribute: attributes) { + String name = attribute.getAttributeName(); + String value = row.get(name); + if (value == null) value = ""; + value = csvEscape(value); + String field = ",\"" + value + "\""; + out.write(field); + } + out.write("\r\n"); + } + + } finally { + sqlHelper.close(); + } + + } finally { + out.flush(); + out.close(); + } + } + + doBlobExport(); + + makeToast(getString(R.string.data_files_exported,entities.size())); + + doExportForms(); + + } catch (Exception e) { + makeToast(e.getMessage()); + } + } + }); + } + + @Override + public void denied() { + + } + }); - } catch (Exception e) { - makeToast(e.getMessage()); - } } private void doExportForms() { diff --git a/app/src/main/java/org/iphukan/ubforms/BaseActivity.java b/app/src/main/java/org/iphukan/ubforms/BaseActivity.java index fd25f36..a4fd51c 100644 --- a/app/src/main/java/org/iphukan/ubforms/BaseActivity.java +++ b/app/src/main/java/org/iphukan/ubforms/BaseActivity.java @@ -1,8 +1,5 @@ package org.iphukan.ubforms; -import java.util.List; -import java.util.Map; - import android.app.Activity; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; @@ -21,6 +18,9 @@ import org.iphukan.ubforms.data.EntityDao; import org.iphukan.ubforms.data.UrSqlHelper; +import java.util.List; +import java.util.Map; + public class BaseActivity extends Activity { public final static String TAG = "ubforms"; @@ -32,7 +32,7 @@ public class BaseActivity extends Activity { public static final String SELECT_MODE_SELECT = "select"; public static String FILE_NAME = "_fileName"; - public static int COL_MIN_WIDTH = 300; + public static int COL_MIN_WIDTH = 150; public static int TEXT_SIZE_SMALL = 7; public static int TEXT_SIZE_MEDIUM = 9; public static int TEXT_SIZE_LARGE = 11; @@ -111,7 +111,7 @@ public void makeToast(String message) { Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } - protected Bundle getEntitySelectedBundle(Entity entity) { + protected static Bundle getEntitySelectedBundle(Entity entity) { Bundle bundle = new Bundle(); if (entity != null) { bundle.putString(EnterDataActivity.ENTITY_NAME, entity.getName()); diff --git a/app/src/main/java/org/iphukan/ubforms/EditDataActivity.java b/app/src/main/java/org/iphukan/ubforms/EditDataActivity.java index bbf51c4..3070eca 100644 --- a/app/src/main/java/org/iphukan/ubforms/EditDataActivity.java +++ b/app/src/main/java/org/iphukan/ubforms/EditDataActivity.java @@ -401,7 +401,7 @@ private byte[] getThumbnail(byte[] contents) { try { - final int THUMBNAIL_SIZE = 128; + final int THUMBNAIL_SIZE = 256; //128 InputStream fis = new ByteArrayInputStream(contents); Bitmap imageBitmap = BitmapFactory.decodeStream(fis); diff --git a/app/src/main/java/org/iphukan/ubforms/EditViewFactory.java b/app/src/main/java/org/iphukan/ubforms/EditViewFactory.java index 93ae5c8..84d2e70 100644 --- a/app/src/main/java/org/iphukan/ubforms/EditViewFactory.java +++ b/app/src/main/java/org/iphukan/ubforms/EditViewFactory.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; +import android.Manifest; import android.app.Activity; import android.app.DatePickerDialog; import android.app.TimePickerDialog; @@ -32,6 +33,15 @@ import android.widget.TextView; import android.widget.TimePicker; +import com.karumi.dexter.Dexter; +import com.karumi.dexter.MultiplePermissionsReport; +import com.karumi.dexter.PermissionToken; +import com.karumi.dexter.listener.PermissionRequest; +import com.karumi.dexter.listener.multi.MultiplePermissionsListener; + +import org.iphukan.ubforms.common.DialogUtils; +import org.iphukan.ubforms.common.IDialogClickListener; +import org.iphukan.ubforms.common.IGrantPermissionCallback; import org.iphukan.ubforms.data.Attribute; import org.iphukan.ubforms.data.BlobData; import org.iphukan.ubforms.data.BlobDataDao; @@ -298,7 +308,24 @@ public void onClick(View v) { final BlobData fblobData = blobData; dl.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - saveCopyFile(fblobData); + checkStoragePermission(activity, new IGrantPermissionCallback() { + @Override + public void granted() { + DialogUtils.displayChooseOkNoDialog(activity, R.string.allow_storage, + R.string.permission_granted, new IDialogClickListener() { + @Override + public void onOK() { + saveCopyFile(fblobData); + + } + }); + } + + @Override + public void denied() { + + } + }); } }); dp2.addView(dl); @@ -348,6 +375,26 @@ private void saveCopyFile(BlobData blobData) { } } + private static void checkStoragePermission(Activity activity, final IGrantPermissionCallback callback) { + Dexter.withActivity(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE) + .withListener(new MultiplePermissionsListener() { + @Override + public void onPermissionsChecked(MultiplePermissionsReport report) { + if (callback == null) return; + if (report.isAnyPermissionPermanentlyDenied()) { + callback.denied(); + } else { + callback.granted(); + } + } + + @Override + public void onPermissionRationaleShouldBeShown(List permissions, PermissionToken token) { + token.continuePermissionRequest(); + } + }).check(); + } private BlobData getBlob(String guid) { BlobDataDao dataDao = new BlobDataDao(sqlHelper.getWritableDatabase()); diff --git a/app/src/main/java/org/iphukan/ubforms/SearchResultsActivity.java b/app/src/main/java/org/iphukan/ubforms/SearchResultsActivity.java index c7c7e08..790616e 100644 --- a/app/src/main/java/org/iphukan/ubforms/SearchResultsActivity.java +++ b/app/src/main/java/org/iphukan/ubforms/SearchResultsActivity.java @@ -1,15 +1,8 @@ package org.iphukan.ubforms; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; @@ -23,6 +16,14 @@ import org.iphukan.ubforms.data.DataDao; import org.iphukan.ubforms.data.Entity; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class SearchResultsActivity extends BaseActivity { @@ -111,7 +112,47 @@ private void doSearch() { } - private boolean isListable(Attribute attribute) { + private static final class RefByData { + public String id; + public String title; + } + + private List getRefByData(String refEntityName, String refAttributeName, String entityid) { + List result = new ArrayList(); + try { + Entity refEntity = new Entity(); + refEntity.setName(refEntityName); + refEntity.setAttributes(this.getAttributes(refEntity)); + Map refValues = new HashMap(); + refValues.put(refAttributeName, entityid); + + List> results; + DataDao dataDao = new DataDao(sqlHelper.getWritableDatabase()); + try { + results = dataDao.searchExact(refEntity, refValues); + } finally { + sqlHelper.close(); + } + for (Map row: results) { + SearchResultsActivity.RefByData rbd = new SearchResultsActivity.RefByData(); + if((!(row.get(refAttributeName)==null))?row.get(refAttributeName).equals(entityid):false){ + rbd.id = row.get("_id"); + rbd.title = this.getTitle(refEntityName, Long.valueOf(rbd.id), refAttributeName); + result.add(rbd); + } + else if(row.get("_id").equals(entityid)) { + rbd.id = row.get("_id"); + rbd.title = this.getTitle(refEntityName, Long.valueOf(rbd.id), refAttributeName); + result.add(rbd); + } + } + } catch (Exception e) { + Log.e(TAG, e.getMessage()); + } + return result; + } + + private static boolean isListable(Attribute attribute) { return attribute.isListable() && ( attribute.getDataType().equals(Attribute.STRING_TYPE) @@ -133,26 +174,121 @@ private void populateResultsView(Entity entity, List> result List attributes = getAttributes(entity); List entities = new ArrayList(); - + List bentities = new ArrayList(); for (Map result: results) { - + Map result_ref = new HashMap(); for (Attribute attribute: attributes) { if (isListable(attribute)) { if (!result.containsKey(attribute.getAttributeName())) { + result_ref.put(attribute.getAttributeName(), ""); result.put(attribute.getAttributeName(), ""); } + else { + if(attribute.getDataType().equals(Attribute.REF_TYPE) || attribute.getDataType().equals(Attribute.REF_BY_TYPE)) { //attribute.getDataType().equals(Attribute.REF_BY_TYPE) || + + //// + String ref = attribute.getRefEntityName(); + + if (!(ref == null || ref.trim().length() == 0)) // || ref.indexOf(" ") == -1)) + { + String[] sa = ref.split(" "); + String refEntityName = sa[0]; + String refAttributeName = ""; + String sid_str = ""; + if(attribute.getDataType().equals(Attribute.REF_BY_TYPE)) + { + Entity refEntity = new Entity(); + refEntity.setName(refEntityName); + List refAttributes = this.getAttributes(refEntity); + for(Attribute ref_attribute: refAttributes) { + if (ref_attribute.getDataType().equals(Attribute.REF_TYPE)) { + String ref2 = ref_attribute.getRefEntityName(); + String[] sa2 = ref2.split(" "); + if(!entity.getName().equals(sa2[0])) + { + refAttributeName = sa[1]; + //refEntityName_new = sa2[0]; + sid_str = result.get("_id"); //result.get("_id"); //result.get(ref_attribute.getAttributeName()); + } + } + } + } + else { + Entity refEntity = new Entity(); + refEntity.setName(refEntityName); + List refAttributes = this.getAttributes(refEntity); + for(Attribute ref_attribute: refAttributes) + { + if(ref_attribute.getDataType().equals(Attribute.REF_BY_TYPE)) + { + + String ref2 = ref_attribute.getRefEntityName(); + String[] sa2 = ref2.split(" "); + if(entity.getName().equals(sa2[0])) + { + refAttributeName = sa2[1]; + sid_str = result.get(attribute.getAttributeName()); + } + } + } + //refAttributeName = "meeting"; //entity.getName(); //.getAttributeName(); + } + List list = new ArrayList(); + //String sid_str = result.get(attribute.getAttributeName()); + //int sid = Integer.parseInt(sid_str); + //if (sid_str != null) { + if(attribute.getDataType().equals(Attribute.REF_TYPE)) + { + list = getRefByData(refEntityName, refAttributeName, sid_str); + } + else + { + list = getRefByData(refEntityName, refAttributeName, sid_str); + } + //} + String txt = ""; + for (SearchResultsActivity.RefByData rbd : list) { + txt += "(" + rbd.id + ") " + rbd.title + "\r\n"; + } + if (txt.length() > 2) { + txt = txt.substring(0, txt.length() - 2); + } + + ///// + result_ref.put(attribute.getAttributeName(), txt); + } + else { + result_ref.put(attribute.getAttributeName(), result.get(attribute.getAttributeName())); + } + } + else + { + result_ref.put(attribute.getAttributeName(), result.get(attribute.getAttributeName())); + } + } } else { result.remove(attribute.getAttributeName()); + //result_ref.remove(attribute.getAttributeName()); } } + //Must copy id also... + result_ref.put("_id", result.get("_id")); + Entity aentity = new Entity(); aentity.setName(entity.getName()); aentity.setAttributes(attributes); - aentity.setValues(result); + aentity.setValues(result_ref); entities.add(aentity); + + Entity bentity = new Entity(); + bentity.setName(entity.getName()); + bentity.setAttributes(attributes); + bentity.setValues(result); + bentities.add(bentity); + } if (mSortOn != null) { @@ -225,7 +361,16 @@ public void onClick(View v) { bv = new Button(this); bv.setText(getString(R.string.entity_arrow,getSelectText())); bv.setTextSize(TEXT_SIZE_LARGE); - final Entity fentity = aentity; + String aid = aentity.getValues().get("_id"); + Entity mbentity=null; + for(Entity bentity:bentities){ + if(aid.equals(bentity.getValues().get("_id"))) { + mbentity=bentity; + break; + } + } + final Entity fentity = mbentity; + View.OnClickListener ocl; if (this.mSelectMode == null) { ocl = new View.OnClickListener() { @@ -261,7 +406,7 @@ public void onClick(View v) { } - private boolean isAlphaSort(Attribute attribute) { + private static boolean isAlphaSort(Attribute attribute) { /*String v = attribute.getValidationExample(); if (v == null || v.trim().length() == 0) return true; for (int i = 0; i < v.length(); i++) { diff --git a/app/src/main/java/org/iphukan/ubforms/common/DialogUtils.java b/app/src/main/java/org/iphukan/ubforms/common/DialogUtils.java new file mode 100644 index 0000000..c7c8299 --- /dev/null +++ b/app/src/main/java/org/iphukan/ubforms/common/DialogUtils.java @@ -0,0 +1,39 @@ +package org.iphukan.ubforms.common; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.support.annotation.StringRes; + +import org.iphukan.ubforms.R; + +public class DialogUtils { + + public static void displayChooseOkNoDialog(final Activity activity, @StringRes int title, + @StringRes int message, + final IDialogClickListener callBack) { + if (activity == null) return; + displayChooseOkNoDialog(activity, activity.getString(title), activity.getString(message), callBack); + } + + public static void displayChooseOkNoDialog(final Activity activity, String title, String message, + final IDialogClickListener callBack) { + if (activity == null) return; + new AlertDialog.Builder(activity) + .setTitle(title) + .setMessage(message) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + callBack.onOK(); + } + }) + .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + + } + }).create().show(); + } + +} diff --git a/app/src/main/java/org/iphukan/ubforms/common/IDialogClickListener.java b/app/src/main/java/org/iphukan/ubforms/common/IDialogClickListener.java new file mode 100644 index 0000000..9e23147 --- /dev/null +++ b/app/src/main/java/org/iphukan/ubforms/common/IDialogClickListener.java @@ -0,0 +1,7 @@ +package org.iphukan.ubforms.common; + +public interface IDialogClickListener { + + void onOK(); + +} diff --git a/app/src/main/java/org/iphukan/ubforms/common/IGrantPermissionCallback.java b/app/src/main/java/org/iphukan/ubforms/common/IGrantPermissionCallback.java new file mode 100644 index 0000000..7565a25 --- /dev/null +++ b/app/src/main/java/org/iphukan/ubforms/common/IGrantPermissionCallback.java @@ -0,0 +1,9 @@ +package org.iphukan.ubforms.common; + +public interface IGrantPermissionCallback { + + void granted(); + + void denied(); + +} diff --git a/app/src/main/java/org/iphukan/ubforms/data/BlobDataDao.java b/app/src/main/java/org/iphukan/ubforms/data/BlobDataDao.java index 0d4c53d..a80ab45 100644 --- a/app/src/main/java/org/iphukan/ubforms/data/BlobDataDao.java +++ b/app/src/main/java/org/iphukan/ubforms/data/BlobDataDao.java @@ -41,7 +41,7 @@ public BlobDataDao(SQLiteDatabase database) { "blob_data" }; - public BlobData mapObject(Cursor cursor) { + public static BlobData mapObject(Cursor cursor) { BlobData data = new BlobData(); data.setId(cursor.getInt(0)); data.setGuid(cursor.getString(1)); diff --git a/app/src/main/java/org/iphukan/ubforms/data/EntityDao.java b/app/src/main/java/org/iphukan/ubforms/data/EntityDao.java index 5db4628..a562691 100644 --- a/app/src/main/java/org/iphukan/ubforms/data/EntityDao.java +++ b/app/src/main/java/org/iphukan/ubforms/data/EntityDao.java @@ -29,7 +29,7 @@ public EntityDao(SQLiteDatabase database) { "entity_name" }; - public Entity mapObject(Cursor cursor) { + public static Entity mapObject(Cursor cursor) { Entity entity = new Entity(); entity.setId(cursor.getInt(0)); entity.setName(cursor.getString(1)); diff --git a/app/src/main/java/org/iphukan/ubforms/data/SampleDataPopulator.java b/app/src/main/java/org/iphukan/ubforms/data/SampleDataPopulator.java index a7bafbf..56f29f6 100644 --- a/app/src/main/java/org/iphukan/ubforms/data/SampleDataPopulator.java +++ b/app/src/main/java/org/iphukan/ubforms/data/SampleDataPopulator.java @@ -20,7 +20,7 @@ public void addSampleData(UrSqlHelper sqlHelper) { } - private void addSampleData(EntityDao entityDao, AttributeDao attributeDao, DataDao dataDao) { + private static void addSampleData(EntityDao entityDao, AttributeDao attributeDao, DataDao dataDao) { Entity entity; Attribute attribute; diff --git a/app/src/main/java/org/iphukan/ubforms/data/Validator.java b/app/src/main/java/org/iphukan/ubforms/data/Validator.java index 15c7b64..74bf5b9 100644 --- a/app/src/main/java/org/iphukan/ubforms/data/Validator.java +++ b/app/src/main/java/org/iphukan/ubforms/data/Validator.java @@ -72,7 +72,7 @@ public String validate(List attributes, Map values) { return null; } - public String validate_dontcare_unique(List attributes, Map values) { + public static String validate_dontcare_unique(List attributes, Map values) { List keys = new ArrayList(); for (Attribute attribute: attributes) { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2db0ff1..86c8d22 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,7 +17,7 @@ android:id="@+id/android:button3" android:layout_width="fill_parent" android:layout_height="fill_parent" - android:gravity="center" + android:gravity="left" android:lines="2" android:maxLines="4" /> diff --git a/app/src/main/res/values-af/strings.xml b/app/src/main/res/values-af/strings.xml index 528770c..6cc777a 100644 --- a/app/src/main/res/values-af/strings.xml +++ b/app/src/main/res/values-af/strings.xml @@ -16,8 +16,8 @@ Soek Keuses Bevestig: Vervang alle vorm definisies? (Dit mag alle data beinvloed!) - %1$d data dokumente uitgevoer - %1$d data dokumente ingevoer + %1$s data dokumente uitgevoer + %1$s data dokumente ingevoer Data tipe datum Vernietig @@ -68,6 +68,7 @@ Stoor Stoor kopie Stoor Veld Definisie + Wis Veld Gestoor soek Soek vir: %1$s @@ -91,4 +92,6 @@ Validasie Voorbeeld Validasie RegEx Ja + Laat stoor toe? + Staan toe \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0263b97..adad247 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -35,6 +35,7 @@ Feld Beschr. Feldname Felddefinition speichern + Feld löschen Absagen OK Geben Sie einen neuen Feldnamen ein @@ -98,4 +99,6 @@ Ein Datensatz existiert bereits für, Schlüssel: %1$s %1$s ist erforderlich %1$s-Feldwert %2$s ist ungültig. Beispiel %3$s + Erlaube Speicherberechtigung? + Genehmigung erteilen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 92d1d5c..bd44ced 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,6 +35,7 @@ Field Desc. Field Name Save Field Definition + Delete Field Cancel OK Enter new field name @@ -98,4 +99,6 @@ A record already exists for, key: %1$s %1$s is required %1$s value %2$s is invalid. Example: %3$s + Allow storage permission? + Grant Permission \ No newline at end of file