From b4b3382e0d6d21fa6937d92fe21460e54becf04b Mon Sep 17 00:00:00 2001 From: Aoudia Date: Sun, 17 Dec 2017 02:25:47 +0100 Subject: [PATCH] refactor(*) : Fix bugs after release Fix Heap size. Optimise export to CSV function. Add proguard rules. Update Room instrumented tests. Add new icon to export button. --- app/proguard-rules.pro | 5 ++- .../java/science/apolline/RoomDatabaseTest.kt | 2 +- app/src/main/AndroidManifest.xml | 1 + .../java/science/apolline/models/Device.kt | 2 +- .../apolline/service/database/SensorDao.kt | 4 +- .../java/science/apolline/utils/DataExport.kt | 36 ++---------------- .../apolline/view/Fragment/IOIOFragment.java | 6 +-- .../apolline/viewModel/SensorViewModel.kt | 2 +- .../res/drawable-hdpi/ic_save_white_48dp.png | Bin 0 -> 391 bytes .../res/drawable-mdpi/ic_save_white_48dp.png | Bin 0 -> 273 bytes .../res/drawable-xhdpi/ic_save_white_48dp.png | Bin 0 -> 504 bytes .../drawable-xxhdpi/ic_save_white_48dp.png | Bin 0 -> 751 bytes .../drawable-xxxhdpi/ic_save_white_48dp.png | Bin 0 -> 1031 bytes app/src/main/res/layout/fragment_ioio.xml | 2 +- 14 files changed, 18 insertions(+), 42 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_save_white_48dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_save_white_48dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_save_white_48dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_save_white_48dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_save_white_48dp.png diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 97e8559..d48495a 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -24,4 +24,7 @@ # hide the original source file name. #-renamesourcefileattribute SourceFile -keep class javax.** { *; } --keep class org.** { *; } \ No newline at end of file +-keep class org.** { *; } +-keepattributes EnclosingMethod +-keepattributes InnerClasses +#-dontoptimize \ No newline at end of file diff --git a/app/src/androidTest/java/science/apolline/RoomDatabaseTest.kt b/app/src/androidTest/java/science/apolline/RoomDatabaseTest.kt index 0652672..af0c24c 100644 --- a/app/src/androidTest/java/science/apolline/RoomDatabaseTest.kt +++ b/app/src/androidTest/java/science/apolline/RoomDatabaseTest.kt @@ -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)!!) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 379ed57..8134a62 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -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"> + @Query("SELECT * FROM Device WHERE id=:idDevice") + fun getSensorById(idDevice: Long): LiveData @Insert(onConflict = REPLACE) fun insertOne(device: Device) diff --git a/app/src/main/java/science/apolline/utils/DataExport.kt b/app/src/main/java/science/apolline/utils/DataExport.kt index 0a1bba4..e53ea88 100644 --- a/app/src/main/java/science/apolline/utils/DataExport.kt +++ b/app/src/main/java/science/apolline/utils/DataExport.kt @@ -40,7 +40,7 @@ class DataExport { return headerArray.toTypedArray() } - fun toJson(context:Context) { + fun exportToJson(context:Context) { val folder = File(getExternalStorageDirectory().toString()+"/Apolline") @@ -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) @@ -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> = 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> = mutableListOf() entries.add(toHeader(dataList[0].data)) diff --git a/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.java b/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.java index 7ba7b33..f53003f 100644 --- a/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.java +++ b/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.java @@ -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); diff --git a/app/src/main/java/science/apolline/viewModel/SensorViewModel.kt b/app/src/main/java/science/apolline/viewModel/SensorViewModel.kt index 902c0c5..2ff24e0 100644 --- a/app/src/main/java/science/apolline/viewModel/SensorViewModel.kt +++ b/app/src/main/java/science/apolline/viewModel/SensorViewModel.kt @@ -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 = api.savePost(BuildConfig.INFLUXDB_DBNAME,BuildConfig.INFLUXDB_USR,BuildConfig.INFLUXDB_PWD,requestBody) val postResponse: Response diff --git a/app/src/main/res/drawable-hdpi/ic_save_white_48dp.png b/app/src/main/res/drawable-hdpi/ic_save_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..3e0ce1a5f004065cb68947be0469e056e4457f28 GIT binary patch literal 391 zcmV;20eJq2P)Xo3#U&Y*@0w|JqSu;kW8`%L1_GX^wikkMku z+!nN<`{#6z$_n(rC9(4bD+|yj&iNr#+MqpM!jbj0K{JA|g)V3yf=0TarU+{5f*K+y z*9B$&4b&1r9bM2+1dVk;a}l)E1wrp9=N7a<6~#f$6D?x75&I%ZEatS z3r4ib$>}g=S;qtI3$1o(pck}Sr-AO#YLW)JV1q`lWa+;+-xWC5gj7%<=ZM1L^E>wD z_G`*BEKt%ZU=9!xlW_2kcwqhg@J~+L1PJQf&&tujU~xgSfq^Aq(NdMD@Qa448^br9 zJv*meXvT?xG}dmujKXrvIc=k>%>fl|gI;!tRK{Z;84l|>e7(Vy4L%kU(lfKjiFI>oQ3X>ech^2hYjIl+l`2ky&>*QB4^6n0*K)k|+u@KwRj8|gIuSonXGifXD@hgzG(ArnKXOJM6L_AqE6DYm(FCnptbPq+T{!( z$`WOdWLF&B!I?4Xj`;<~gFBS(I~1oaU_I}U&hq(Q;Y0C^*#e2X>l&vmV$l7~I;)Q< zXU9$SuO#M7{t_$y^xykFeM6~2YDJ~6JEqbwHpXGO$=88Pl39yG;HTWR3&|8v`l z4QJ%0mstJ1{Qr>LW5&OSlEZgZEZGrdvp~KgM_KNId(ob&NfvSe4>Zx*!GUm_tv5Qo74|<~`roRwH)EMs?TP3A}MQDxEm_|ISAf z<6chG&dM>!*|*D07#?R#m!Odcj;1A|Z{#B%+&jH$dGG;XLT2!E^>bP0l+XkK7U4GM literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_save_white_48dp.png b/app/src/main/res/drawable-xxxhdpi/ic_save_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..4243804ce3af8e69c453374306fbae377cc1ff5d GIT binary patch literal 1031 zcmeAS@N?(olHy`uVBq!ia0vp^2SAvE1xWt5x}=AJf%%-Li(^Oyvy59lpw4ROs2E_L?aqd#XQ&sM*0>Mz{Q_0kw;TI6icAYA^_| z;Wnr_pCO>M_T)5%!&e{kC_XxOQ9NPBG>(biS2H}VcC@u}XwGFkwavq0!)m4}+5IO~ z7=qt$2P~W2;u0;kz-RMG20e~|J7$VE`!*^&1b*k>{O-`ONNf_54p+dHn4pGA#;z_6xmN&^V`Enogv1P>4UAR@B`K0mJ`{R1Q*oUyR+{&D8PB)xsKwav`Xy*1%DkU z3uMm!EW;wP?W@Q7<@KkM1rny@xijwIX6o@X2>f`tUYupcC9AVs$NwEyaJah7!u-+9 z^Th%RZnbp_4WFc5=e^g&@bT8Otdp-FYt}7bR&aRpE%F)Dal3;3|CLU^Vdj{yPF8Ni z37g!s6@kfZW}kIFO^CfTU3S6o2Ww`_B}_jUscw5ft$B0r7lv$}b77a5Yfe9S6I9i} zR{!bWn}#Z@hDY=3H-;XvVA!|d`0mK*!H*d^{v6qT)AY~|2EPy1|If|~kd}8?;M!il zIed;vkFdgrsVx7$bm?w95u&;Z2O90*99u8uxdnfoAOz7$!<8M z>9qA|)%zdPVK){yPw(HWCu>rBp1S}5 literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/fragment_ioio.xml b/app/src/main/res/layout/fragment_ioio.xml index 64c43c4..8497e36 100644 --- a/app/src/main/res/layout/fragment_ioio.xml +++ b/app/src/main/res/layout/fragment_ioio.xml @@ -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"/> \ No newline at end of file