Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
refactor(*) : Fix bugs after release
Browse files Browse the repository at this point in the history
Fix Heap size.
Optimise export to CSV function.
Add proguard rules.
Update Room instrumented tests.
Add new icon to export button.
  • Loading branch information
aoudiamoncef committed Dec 17, 2017
1 parent be2880e commit b4b3382
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 42 deletions.
5 changes: 4 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class org.** { *; }
-keepattributes EnclosingMethod
-keepattributes InnerClasses
#-dontoptimize
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RoomDatabaseTest {
val gson = Gson()
val dataListObject = gson.fromJson(dataList, JsonObject::class.java)
val positionInitObject = Position("GPS", 152.36, 142.36, "Train")
val sensor = Device("Arduino", "WedSep2614:23:28EST2017", positionInitObject, dataListObject )
val sensor =Device("ffffffff-c9cf-31db-0000-00006c125b14","Arduino", "1422568543702900257", positionInitObject, dataListObject )

sensorDao?.insertOne(sensor)
val sensorTest = getValue(sensorDao?.getSensorById(sensor.id)!!)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
android:icon="@drawable/logoandroidpng"
android:label="@string/app_name"
android:roundIcon="@drawable/logoandroidpng"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-library
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/science/apolline/models/Device.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class Device(
@SerializedName("device_id")
@Expose
@PrimaryKey(autoGenerate = true)
var id=0
var id: Long = 0



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ interface SensorDao {
@Query("SELECT count(*) FROM Device")
fun getSensorCount(): Int

@Query("SELECT * FROM Device WHERE id=:id")
fun getSensorById(id: Int?): LiveData<Device>
@Query("SELECT * FROM Device WHERE id=:idDevice")
fun getSensorById(idDevice: Long): LiveData<Device>

@Insert(onConflict = REPLACE)
fun insertOne(device: Device)
Expand Down
36 changes: 4 additions & 32 deletions app/src/main/java/science/apolline/utils/DataExport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DataExport {
return headerArray.toTypedArray()
}

fun toJson(context:Context) {
fun exportToJson(context:Context) {

val folder = File(getExternalStorageDirectory().toString()+"/Apolline")

Expand All @@ -54,7 +54,7 @@ class DataExport {
val sensorDao = AppDatabase.getInstance(context)
val fw = FileWriter(filename)
val dataList = sensorDao.dumpSensor()
Log.e("export",dataList.size.toString())
Log.e("exportToCsv",dataList.size.toString())
val gson = GsonBuilder().setPrettyPrinting().create()
val jsonFile = gson.toJson(dataList)
fw.write(jsonFile)
Expand All @@ -64,47 +64,19 @@ class DataExport {
}
}

fun toCsv(context:Context) {

val folder = File(getExternalStorageDirectory().toString() + "/Apolline")
if (!folder.exists())
folder.mkdir()
val filename = folder.toString() + "/" + "data.csv"

doAsync {

val sensorDao = AppDatabase.getInstance(context)
val dataList = sensorDao.dumpSensor()
val entries: MutableList<Array<String>> = mutableListOf()
entries.add(toHeader(dataList[0].data))
dataList.forEach {
entries.add(it.toArray())
}

CSVWriter(FileWriter(filename)).use { writer -> writer.writeAll(entries) }
uiThread {
context.toast("data exported to CSV")
}
}
}

fun export(context:Context) {
fun exportToCsv(context:Context) {

val folder = File(getExternalStorageDirectory().toString()+"/Apolline")
if (!folder.exists())
folder.mkdir()
val filenameCSV = folder.toString() + "/" + "data.csv"
val filenameJSON = folder.toString() + "/" + "data.json"

doAsync {

val sensorDao = AppDatabase.getInstance(context)
val fw = FileWriter(filenameJSON)
val dataList = sensorDao.dumpSensor()
Log.e("export",dataList.size.toString())
val gson = GsonBuilder().setPrettyPrinting().create()
val jsonFile = gson.toJson(dataList)
fw.write(jsonFile)
Log.e("exportToCsv",dataList.size.toString())

val entries: MutableList<Array<String>> = mutableListOf()
entries.add(toHeader(dataList[0].data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
save_fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// export.toJson(getActivity().getApplication());
// export.toCsv(getActivity().getApplication());
export.export(getActivity().getApplication());
// exportToCsv.toJson(getActivity().getApplication());
// exportToCsv.toCsv(getActivity().getApplication());
export.exportToCsv(getActivity().getApplication());
}
});
// mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.fragment_ioio_map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SensorViewModel(application: Application) : AndroidViewModel(application),
doAsync {
if(isConnectingToInternet(getApplication())){
val requestBody: String = RequestParser.createRequestBody(device)
info(requestBody)
// info(requestBody)
val api : ApiService = ApiUtils.apiService
val postCall : Call<InfluxBody> = api.savePost(BuildConfig.INFLUXDB_DBNAME,BuildConfig.INFLUXDB_USR,BuildConfig.INFLUXDB_PWD,requestBody)
val postResponse: Response<InfluxBody>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_ioio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_menu_save"
app:srcCompat="@drawable/ic_save_white_48dp"
android:layout_gravity="bottom|end"/>

</android.support.design.widget.CoordinatorLayout>

0 comments on commit b4b3382

Please sign in to comment.