Skip to content

Commit

Permalink
- FIX: Fixed an issue with preloaded traits. Since multiple dataset w…
Browse files Browse the repository at this point in the history
…ere introduced, this feature has been broken. With this commit, the functionality has been restored. You can now preload traits per dataset and they will be persistent even when switching between datasets.
  • Loading branch information
sebastian-raubach committed Apr 2, 2019
1 parent cc2d56f commit 889ecf9
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 67 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId "uk.ac.hutton.android.germinatescan"
minSdkVersion 16
targetSdkVersion 28
versionCode 35
versionName "1.19.02.05"
versionCode 37
versionName "1.19.04.02"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -55,6 +55,7 @@ dependencies {
implementation 'com.android.support:palette-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.andkulikov:transitionseverywhere:1.7.0'
implementation 'com.google.code.gson:gson:2.8.5'
// Supports Android 4.0.3 and later (API level 15)
implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
implementation 'com.google.zxing:core:3.2.0'
Expand Down
Binary file removed app/libs/gson-2.4.jar
Binary file not shown.
25 changes: 24 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,27 @@
-keep class **.R$*

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-dontwarn com.google.android.gms.**

##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

##---------------End: proguard configuration for Gson ----------
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,19 @@ public boolean onOptionsItemSelected(MenuItem item)
@Override
public void onClick(DialogInterface dialog, int which)
{
startActivityForResult(new Intent(getApplicationContext(), PhenotypeActivity.class), REQUEST_CODE_IMPORT_PHENOTYPES);
Intent intent = new Intent(BarcodeReader.this, PhenotypeActivity.class);
intent.putExtra(PhenotypeActivity.EXTRA_DATASET_ID, dataset.getId());
startActivityForResult(intent, REQUEST_CODE_IMPORT_PHENOTYPES);
}
})
.setNegativeButton(R.string.general_no, null)
.show();
}
else
{
startActivityForResult(new Intent(getApplicationContext(), PhenotypeActivity.class), REQUEST_CODE_IMPORT_PHENOTYPES);
Intent intent = new Intent(BarcodeReader.this, PhenotypeActivity.class);
intent.putExtra(PhenotypeActivity.EXTRA_DATASET_ID, dataset.getId());
startActivityForResult(intent, REQUEST_CODE_IMPORT_PHENOTYPES);
}
break;
}
Expand Down Expand Up @@ -722,8 +726,6 @@ public void onClick(DialogInterface dialog, int which)
}
else if (requestCode == REQUEST_DATA_SOURCE && resultCode == Activity.RESULT_OK)
{
prefs.remove(PreferenceUtils.PREFS_PRELOADED_PHENOTYPES);
prefs.remove(PreferenceUtils.PREFS_PRELOADED_PHENOTYPES_COUNTER);
override = true;
}
/* Return from preferences */
Expand All @@ -737,7 +739,9 @@ else if (requestCode == REQUEST_CODE_IMPORT_PHENOTYPES && resultCode == Activity
{
resetDatabase();

preloadedPhenotypes = data.getStringArrayListExtra(PhenotypeActivity.EXTRA_LIST);
DatasetManager datasetManager = new DatasetManager(this, dataset.getId());
dataset = datasetManager.getById(dataset.getId());
preloadedPhenotypes = dataset.getPreloadedPhenotypes();

updateHandler();
}
Expand Down Expand Up @@ -954,9 +958,6 @@ private void resetDatabase()

updateWelcomeMessageVisibility();

prefs.remove(PreferenceUtils.PREFS_PRELOADED_PHENOTYPES);
prefs.remove(PreferenceUtils.PREFS_PRELOADED_PHENOTYPES_COUNTER);

updateHandler();
}

Expand All @@ -965,7 +966,7 @@ private void updateHandler()
boolean restored = false;
if (preloadedPhenotypes == null)
{
preloadedPhenotypes = prefs.getListObject(PreferenceUtils.PREFS_PRELOADED_PHENOTYPES, String.class);
preloadedPhenotypes = dataset.getPreloadedPhenotypes();
restored = true;
}

Expand All @@ -976,7 +977,7 @@ private void updateHandler()

if (restored)
{
counter = prefs.getInt(PreferenceUtils.PREFS_PRELOADED_PHENOTYPES_COUNTER, 0);
counter = dataset.getCurrentPhenotype();
if (adapter.getItemCount() > 0)
currentPlant = adapter.getItemsInRow(adapter.getItem(adapter.getItemCount() - 1)).get(0).getBarcode();
}
Expand All @@ -989,7 +990,7 @@ else if (adapter.getItemCount() < 1)
.show();
}

handler = new PhenotypeBarcodeHandler(this, preloadedPhenotypes, currentPlant, counter)
handler = new PhenotypeBarcodeHandler(this, dataset, preloadedPhenotypes, currentPlant, counter)
{
@Override
protected Barcode getCurrentPlant()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
import butterknife.*;
import uk.ac.hutton.android.germinatescan.R;
import uk.ac.hutton.android.germinatescan.adapter.*;
import uk.ac.hutton.android.germinatescan.database.*;
import uk.ac.hutton.android.germinatescan.database.manager.*;
import uk.ac.hutton.android.germinatescan.util.*;

/**
* @author Sebastian Raubach
*/
public class PhenotypeActivity extends ThemedActivity
{
public static final String EXTRA_LIST = "PHENOTYPE_LIST";
public static final String EXTRA_DATASET_ID = "DATASET_ID";

@BindView(R.id.phenotype_text)
EditText phenotypeInput;
Expand All @@ -51,6 +53,8 @@ public class PhenotypeActivity extends ThemedActivity

private ItemTouchHelper helper;
private StringReorderDeleteAdapter adapter;
private DatasetManager datasetManager;
private Dataset dataset;

@Override
protected Integer getLayoutId()
Expand All @@ -71,6 +75,19 @@ protected void onCreate(Bundle savedInstanceState)

ButterKnife.bind(this);

Bundle extras = getIntent().getExtras();

if (extras != null)
{
long datasetId = extras.getLong(EXTRA_DATASET_ID, -1l);

if (datasetId != -1)
{
datasetManager = new DatasetManager(getApplicationContext(), datasetId);
dataset = datasetManager.getById(datasetId);
}
}

adapter = new StringReorderDeleteAdapter(this, new ArrayList<String>(), new StringReorderDeleteAdapter.OnStartDragListener()
{
@Override
Expand Down Expand Up @@ -174,7 +191,14 @@ private void finishImport()
List<String> items = adapter.getItems();

if (!CollectionUtils.isEmpty(items))
data.putStringArrayListExtra(EXTRA_LIST, new ArrayList<>(items));
{
dataset.setPreloadedPhenotypes(items);
}
else
{
dataset.setPreloadedPhenotypes(null);
}
datasetManager.update(dataset);

if (getParent() == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class DatabaseHandler extends SQLiteOpenHelper
+ KEY_MAIN_LNG + " REAL, " + KEY_MAIN_ALT + " REAL, " + KEY_MAIN_BARCODE + " TEXT, " + KEY_MAIN_ROW + " INTEGER, " + KEY_MAIN_COL + " INTEGER)";
private static final String CREATE_IMAGE_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_IMAGES + " (" + KEY_IMAGES_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_IMAGES_PATH + " TEXT, " + KEY_IMAGES_MAIN_ID
+ " INTEGER, FOREIGN KEY (" + KEY_IMAGES_MAIN_ID + ") REFERENCES " + TABLE_MAIN + " (" + KEY_MAIN_ID + "));" + ")";
public static DatabaseHandler INSTANCE;
private Context context;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@

package uk.ac.hutton.android.germinatescan.database;

import com.google.gson.*;
import com.google.gson.reflect.*;

import java.util.*;

import uk.ac.hutton.android.germinatescan.util.*;

/**
* @author Sebastian Raubach
*/

public class Dataset extends DatabaseObject
{
public static final String FIELD_NAME = "name";
public static final String FIELD_BARCODES_PER_ROW = "barcodes_per_row";
public static final String FIELD_NAME = "name";
public static final String FIELD_BARCODES_PER_ROW = "barcodes_per_row";
public static final String FIELD_PRELOADED_PHENOTYPES = "preloaded_phenotypes";
public static final String FIELD_CURRENT_PHENOTYPE = "current_phenotype";

private String name;
private int barcodesPerRow;
private String name;
private int barcodesPerRow;
private List<String> preloadedPhenotypes;
private Integer currentPhenotype;

public Dataset(String name)
{
Expand Down Expand Up @@ -73,4 +82,53 @@ public Dataset setBarcodesPerRow(int barcodesPerRow)
this.barcodesPerRow = barcodesPerRow;
return this;
}

public List<String> getPreloadedPhenotypes()
{
return preloadedPhenotypes;
}

public Dataset setPreloadedPhenotypes(List<String> preloadedPhenotypes)
{
this.preloadedPhenotypes = preloadedPhenotypes;
return this;
}

public String getPreloadedPhenotypesAsString()
{
if (!CollectionUtils.isEmpty(preloadedPhenotypes))
return new Gson().toJson(preloadedPhenotypes);
else
return null;
}

public Dataset setPreloadedPhenotypesAsString(String preloadedPhenotypesAsString)
{
if (!StringUtils.isEmpty(preloadedPhenotypesAsString))
{
try
{
preloadedPhenotypes = new Gson().fromJson(preloadedPhenotypesAsString, new TypeToken<List<String>>()
{
}.getType());
}
catch (JsonParseException e)
{
preloadedPhenotypes = null;
}
}

return this;
}

public Integer getCurrentPhenotype()
{
return currentPhenotype;
}

public Dataset setCurrentPhenotype(Integer currentPhenotype)
{
this.currentPhenotype = currentPhenotype;
return this;
}
}
Loading

0 comments on commit 889ecf9

Please sign in to comment.