Skip to content

Commit

Permalink
Merge pull request #1135 from PhenoApps/bugs_v6.0.3
Browse files Browse the repository at this point in the history
Bugs v6.0.3
  • Loading branch information
trife authored Jan 22, 2025
2 parents fdd861a + 684d029 commit 9b1c3a6
Show file tree
Hide file tree
Showing 27 changed files with 371 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
import com.fieldbook.tracker.views.TraitBoxView;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetSequence;
import com.google.firebase.crashlytics.CustomKeysAndValues;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.serenegiant.widget.UVCCameraTextureView;
Expand Down Expand Up @@ -296,6 +298,8 @@ public class CollectActivity extends ThemedActivity
private AlertDialog dialogPrecisionLoss;
private boolean mlkitEnabled;

private AlertDialog dialogCrashReport;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Expand Down Expand Up @@ -2806,4 +2810,77 @@ public void onRotationEvent(@NonNull SensorHelper.RotationModel rotation) {
public SensorHelper.RotationModel getRotationRelativeToDevice() {
return rotationModel;
}

@Override
public void askUserSendCrashReport(@NonNull Exception e) {
if (getWindow().isActive()) {
try {
if (dialogCrashReport != null) {
dialogCrashReport.dismiss();
}

dialogCrashReport = new AlertDialog.Builder(this, R.style.AppAlertDialog)
.setTitle(getString(R.string.dialog_crash_report_title))
.setMessage(getString(R.string.dialog_crash_report_message))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
sendCrashReport(e);
dialog.dismiss();
})
.setNegativeButton(android.R.string.no, (dialog, which) -> {
FirebaseCrashlytics.getInstance().recordException(e);
dialog.dismiss();
})
.create();

dialogCrashReport.show();

} catch (Exception ignore) {
}
}
}

private void sendCrashReport(Exception e) {

try {

FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();

crashlytics.setCrashlyticsCollectionEnabled(true);

int studyId = preferences.getInt(GeneralKeys.SELECTED_FIELD_ID, 0);
Log.e(TAG, "Current Study ID: " + studyId);

CustomKeysAndValues.Builder builder = new CustomKeysAndValues.Builder()
.putString("Current Study ID", Integer.toString(studyId));

int count = 0;
FieldObject[] fieldObjects = database.getAllFieldObjects().toArray(new FieldObject[0]);
for (FieldObject fo : fieldObjects) {
Log.e(TAG, "Field ID: " + count + " " + fo.getExp_id());
Log.e(TAG, "Field Name: " + count + " " + fo.getExp_name());
Log.e(TAG, "Field Unique ID: " + count + " " + fo.getUnique_id());

builder.putString("Field ID " + count, Integer.toString(fo.getExp_id()));
builder.putString("Field Name " + count, fo.getExp_name());
builder.putString("Field Unique ID " + count, fo.getUnique_id());

List<String> attributes = Arrays.asList(database.getAllObservationUnitAttributeNames(fo.getExp_id()));
Log.e(TAG, attributes.toString());
builder.putString("Observation Unit Attributes " + count, attributes.toString());

count = count + 1;
}

crashlytics.setCustomKeys(builder.build());

crashlytics.recordException(e);

crashlytics.sendUnsentReports();

} catch (Exception ex) {

Log.e(TAG, "Error logging study entry attributes: " + ex);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ private void resolveFuzzySearchResult(FieldObject f, @Nullable String plotId) {

}

Intent intent = new Intent(this, CollectActivity.class);
CollectActivity.reloadData = true;

if (plotId != null) {
Expand All @@ -437,10 +436,21 @@ private void resolveFuzzySearchResult(FieldObject f, @Nullable String plotId) {

}

startActivity(intent);
startCollectActivity();

}

private void startCollectActivity() {

int selectedField = preferences.getInt(GeneralKeys.SELECTED_FIELD_ID, -1);
FieldObject field = database.getFieldObject(selectedField);

if (field != null && field.getDate_import() != null && !field.getDate_import().isEmpty()) {
Intent intent = new Intent(this, CollectActivity.class);
startActivity(intent);
}
}

@Nullable
private FieldObject searchStudiesForBarcode(String barcode) {

Expand Down Expand Up @@ -590,11 +600,7 @@ public void collectDataFilePermission() {

if (EasyPermissions.hasPermissions(this, perms)
&& (EasyPermissions.hasPermissions(this, finePerms) || EasyPermissions.hasPermissions(this, coarsePerms))) {
Intent intent = new Intent();

intent.setClassName(ConfigActivity.this,
CollectActivity.class.getName());
startActivity(intent);
startCollectActivity();
} else {
// Do not have permissions, request them now
EasyPermissions.requestPermissions(this, getString(R.string.permission_rationale_trait_features),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.MenuItem
import android.view.View
import android.widget.ProgressBar
import androidx.constraintlayout.widget.Group
import androidx.core.database.getStringOrNull
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.evrencoskun.tableview.TableView
Expand Down Expand Up @@ -249,16 +250,29 @@ class DataGridActivity : ThemedActivity(), CoroutineScope by MainScope(), ITable

do { //iterate over cursor results and populate lists of plot ids and related trait values

val rowHeaderIndex = cursor.getColumnIndex(rowHeader)
val rowData = arrayListOf<String?>()
val columns = arrayListOf<String>()
val columnCount = cursor.columnCount

for (i in 0 until columnCount) {
try {
columns.add(cursor.getColumnName(i))
rowData.add(cursor.getStringOrNull(i))
} catch (e: Exception) {
e.printStackTrace()
}
}

val rowHeaderIndex = columns.indexOf(rowHeader)

//unique name column is always the first column
val uniqueIndex = cursor.getColumnIndex(study.unique_id)
val uniqueIndex = columns.indexOf(uniqueHeader)

if (uniqueIndex > -1) { //if it doesn't exist skip this row

val id = cursor.getString(uniqueIndex)
val id = rowData[uniqueIndex] ?: ""

val header = cursor.getString(rowHeaderIndex)
val header = if (rowHeaderIndex > -1) columns[rowHeaderIndex] else ""

val dataList = arrayListOf<CellData>()

Expand All @@ -268,19 +282,16 @@ class DataGridActivity : ThemedActivity(), CoroutineScope by MainScope(), ITable

mTraits.forEachIndexed { _, variable ->

val index = cursor.getColumnIndex(variable.name)
val index = columns.indexOf(DataHelper.replaceIdentifiers(variable.name))

if (index > -1) {

val value = cursor.getString(index) ?: ""
val value = rowData[index] ?: ""

val t = traits.find { it.format in setOf("categorical", "multicat", "qualitative") }

val repeatedValues =
database.getRepeatedValues(studyId.toString(), id, variable.id)
if (repeatedValues.size > 1) {
println("$studyId $id $variable has repeated values...!")
}

var cellValue = value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,7 @@ class FieldDetailFragment : Fragment(), FieldSyncController {
)
}
if (EasyPermissions.hasPermissions(requireActivity(), *perms)) {
val intent = Intent()
intent.setClassName(
requireActivity(),
"com.fieldbook.tracker.activities.CollectActivity"
)
startActivity(intent)
startCollectActivity()
} else {
// Do not have permissions, request them now
EasyPermissions.requestPermissions(
Expand All @@ -499,4 +494,14 @@ class FieldDetailFragment : Fragment(), FieldSyncController {
}
}

private fun startCollectActivity() {
val selectedField = preferences.getInt(GeneralKeys.SELECTED_FIELD_ID, -1)
val field = database.getFieldObject(selectedField)

if (field != null && field.date_import != null && field.date_import.isNotEmpty()) {
val intent = Intent(context, CollectActivity::class.java)
startActivity(intent)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public void loadLocal() {
public void loadBrAPI() {

if (Utils.isConnected(this)) {
if (prefs.getBoolean(GeneralKeys.EXPERIMENTAL_NEW_BRAPI_UI, false)) {
if (prefs.getBoolean(GeneralKeys.EXPERIMENTAL_NEW_BRAPI_UI, true)) {
Intent intent = new Intent(this, BrapiStudyFilterActivity.class);
BrapiFilterCache.Companion.checkClearCache(this);
startActivityForResult(intent, REQUEST_BRAPI_IMPORT_ACTIVITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ private void showImportDialog() {
public void startBrapiTraitActivity(boolean fromTraitCreator) {

if (Utils.isConnected(this)) {
if (prefs.getBoolean(GeneralKeys.EXPERIMENTAL_NEW_BRAPI_UI, false)) {
if (prefs.getBoolean(GeneralKeys.EXPERIMENTAL_NEW_BRAPI_UI, true)) {
Intent intent = new Intent(this, BrapiTraitFilterActivity.class);
BrapiFilterCache.Companion.checkClearCache(this);
startActivity(intent);
Expand Down
Loading

0 comments on commit 9b1c3a6

Please sign in to comment.