From 5d66a149c269bdd26fe4c7a6e25b3d9fb44a1b33 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 01:25:58 +0530 Subject: [PATCH 1/8] Update gradle plugin Signed-off-by: Arka Prava Basu --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1a5ee412..d529c068 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:3.6.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } From 42a374f82f8247b7a92e74cba40bb66ce36e8383 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 01:28:49 +0530 Subject: [PATCH 2/8] Update dependencies Signed-off-by: Arka Prava Basu --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index d529c068..8c98ad8d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.61' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() @@ -145,10 +145,10 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0" - implementation 'androidx.preference:preference:1.1.0' + implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.annotation:annotation:1.1.0' - implementation 'com.google.android.material:material:1.2.0-alpha03' + implementation 'com.google.android.material:material:1.2.0-alpha06' implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.wdullaer:materialdatetimepicker:4.2.3' implementation 'com.github.guardianproject:signal-cli-android:v0.6.0-android-beta-1' From 8eb0342f81c832812a73c60c63b3d2c3b67eec66 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 10:28:54 +0530 Subject: [PATCH 3/8] Remove stateHidden flag for windowSoftInputMode - this flag prevented the dismissal of keyboard after an attempt to edit any EditTextPreference was made. We want the keyboard to dismiss after any edit for better UX Signed-off-by: Arka Prava Basu --- src/main/AndroidManifest.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 5087f976..ff9b5e38 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -61,8 +61,7 @@ android:name=".SettingsActivity" android:configChanges="orientation|screenSize" android:label="@string/settings" - android:theme="@style/SettingsTheme" - android:windowSoftInputMode="stateHidden" /> + android:theme="@style/SettingsTheme" /> From c5082c4ace5c71dfa79af5e84650cf54d4804cf2 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 10:31:40 +0530 Subject: [PATCH 4/8] Replace proper email - my work email got commited due to automatic signature from my work machine. Replace that with my personal email Signed-off-by: Arka Prava Basu --- .../org/havenapp/main/database/migration/RoomMigrationTest.kt | 2 +- .../org/havenapp/main/database/migration/SugarDbOpenHelper.kt | 2 +- .../org/havenapp/main/database/migration/SugarDbTestHelper.kt | 2 +- src/main/java/org/havenapp/main/database/DbConstants.kt | 2 +- src/main/java/org/havenapp/main/service/HavenJobCreator.kt | 2 +- .../java/org/havenapp/main/service/RemoveDeletedFilesJob.kt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/androidTest/java/org/havenapp/main/database/migration/RoomMigrationTest.kt b/src/androidTest/java/org/havenapp/main/database/migration/RoomMigrationTest.kt index eaa89451..1372cd2a 100644 --- a/src/androidTest/java/org/havenapp/main/database/migration/RoomMigrationTest.kt +++ b/src/androidTest/java/org/havenapp/main/database/migration/RoomMigrationTest.kt @@ -14,7 +14,7 @@ import org.junit.Rule import org.junit.Test /** - * Created by Arka Prava Basu on 27/10/18. + * Created by Arka Prava Basu on 27/10/18. */ class RoomMigrationTest { @get:Rule diff --git a/src/androidTest/java/org/havenapp/main/database/migration/SugarDbOpenHelper.kt b/src/androidTest/java/org/havenapp/main/database/migration/SugarDbOpenHelper.kt index e71a9be0..bb283ee5 100644 --- a/src/androidTest/java/org/havenapp/main/database/migration/SugarDbOpenHelper.kt +++ b/src/androidTest/java/org/havenapp/main/database/migration/SugarDbOpenHelper.kt @@ -5,7 +5,7 @@ import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper /** - * Created by Arka Prava Basu on 27/10/18. + * Created by Arka Prava Basu on 27/10/18. */ class SugarDbOpenHelper(context: Context, dbName: String) : SQLiteOpenHelper(context, dbName, null, 3) { diff --git a/src/androidTest/java/org/havenapp/main/database/migration/SugarDbTestHelper.kt b/src/androidTest/java/org/havenapp/main/database/migration/SugarDbTestHelper.kt index e013fffa..f27cf2f7 100644 --- a/src/androidTest/java/org/havenapp/main/database/migration/SugarDbTestHelper.kt +++ b/src/androidTest/java/org/havenapp/main/database/migration/SugarDbTestHelper.kt @@ -1,7 +1,7 @@ package org.havenapp.main.database.migration /** - * Created by Arka Prava Basu on 28/10/18. + * Created by Arka Prava Basu on 28/10/18. */ class SugarDbTestHelper { diff --git a/src/main/java/org/havenapp/main/database/DbConstants.kt b/src/main/java/org/havenapp/main/database/DbConstants.kt index 7ba25472..a127649f 100644 --- a/src/main/java/org/havenapp/main/database/DbConstants.kt +++ b/src/main/java/org/havenapp/main/database/DbConstants.kt @@ -1,7 +1,7 @@ package org.havenapp.main.database /** - * Created by Arka Prava Basu on 19/10/18. + * Created by Arka Prava Basu on 19/10/18. */ const val DB_INIT_START = 0x1 diff --git a/src/main/java/org/havenapp/main/service/HavenJobCreator.kt b/src/main/java/org/havenapp/main/service/HavenJobCreator.kt index f1a6f5ed..c57a3aa9 100644 --- a/src/main/java/org/havenapp/main/service/HavenJobCreator.kt +++ b/src/main/java/org/havenapp/main/service/HavenJobCreator.kt @@ -4,7 +4,7 @@ import com.evernote.android.job.Job import com.evernote.android.job.JobCreator /** - * Created by Arka Prava Basu on 04/11/18. + * Created by Arka Prava Basu on 04/11/18. */ class HavenJobCreator : JobCreator { override fun create(tag: String): Job? { diff --git a/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt b/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt index f2c3c954..864df32a 100644 --- a/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt +++ b/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt @@ -12,7 +12,7 @@ import java.io.File /** * A [Job] to delete files related to deleted logs. *

- * Created by Arka Prava Basu on 28/10/18. + * Created by Arka Prava Basu on 28/10/18. */ const val SERVICE_TAG = "HavenCleanupJob" From 039b70b00e12a5c35044f2fc345b6d41056a01ea Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 15:35:46 +0530 Subject: [PATCH 5/8] Make OnionCookie static - less memory per instance + no implicit ref to parent class Signed-off-by: Arka Prava Basu --- src/main/java/org/havenapp/main/service/WebServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/havenapp/main/service/WebServer.java b/src/main/java/org/havenapp/main/service/WebServer.java index fd749a76..ea421794 100644 --- a/src/main/java/org/havenapp/main/service/WebServer.java +++ b/src/main/java/org/havenapp/main/service/WebServer.java @@ -253,7 +253,7 @@ private boolean safeEquals (String a, String b) { return MessageDigest.isEqual(aByteArray, bByteArray); } - class OnionCookie extends Cookie + static class OnionCookie extends Cookie { public OnionCookie(String name, String value, int numDays) { From ec096cd7f3a3c56fd3a4649650bd2a343cbf4c7e Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 16:34:29 +0530 Subject: [PATCH 6/8] Override equals, hashcode and toString for data classes - helps in logging and better equality checks Signed-off-by: Arka Prava Basu --- .../java/org/havenapp/main/model/Event.kt | 28 +++++++++++++++++++ .../org/havenapp/main/model/EventTrigger.kt | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/main/java/org/havenapp/main/model/Event.kt b/src/main/java/org/havenapp/main/model/Event.kt index fc7607aa..d60872bd 100644 --- a/src/main/java/org/havenapp/main/model/Event.kt +++ b/src/main/java/org/havenapp/main/model/Event.kt @@ -1,5 +1,6 @@ package org.havenapp.main.model +import androidx.annotation.WorkerThread import androidx.lifecycle.LiveData import androidx.lifecycle.Transformations import androidx.room.ColumnInfo @@ -46,6 +47,7 @@ class Event { *

* When [eventTriggers] is empty this method performs a blocking db lookup. */ + @WorkerThread fun getEventTriggers() : MutableList { if (eventTriggers.size == 0) { @@ -63,4 +65,30 @@ class Event { fun getEventTriggerCount(): Int { return eventTriggerCountLD?.value?.second ?: 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Event + + if (id != other.id) return false + if (startTime != other.startTime) return false + if (eventTriggers != other.eventTriggers) return false + if (eventTriggerCountLD != other.eventTriggerCountLD) return false + + return true + } + + override fun hashCode(): Int { + var result = id?.hashCode() ?: 0 + result = 31 * result + (startTime?.hashCode() ?: 0) + result = 31 * result + eventTriggers.hashCode() + result = 31 * result + (eventTriggerCountLD?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "Event(id=$id, startTime=$startTime, eventTriggers=$eventTriggers, eventTriggerCountLD=$eventTriggerCountLD)" + } } diff --git a/src/main/java/org/havenapp/main/model/EventTrigger.kt b/src/main/java/org/havenapp/main/model/EventTrigger.kt index a2f468c4..64344585 100644 --- a/src/main/java/org/havenapp/main/model/EventTrigger.kt +++ b/src/main/java/org/havenapp/main/model/EventTrigger.kt @@ -106,4 +106,32 @@ class EventTrigger { return mimeType } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as EventTrigger + + if (id != other.id) return false + if (type != other.type) return false + if (time != other.time) return false + if (eventId != other.eventId) return false + if (path != other.path) return false + + return true + } + + override fun hashCode(): Int { + var result = id?.hashCode() ?: 0 + result = 31 * result + (type ?: 0) + result = 31 * result + (time?.hashCode() ?: 0) + result = 31 * result + (eventId?.hashCode() ?: 0) + result = 31 * result + (path?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "EventTrigger(id=$id, type=$type, time=$time, eventId=$eventId, path=$path)" + } } From c6ac8bac8a65b4c1fe5e59d527758b506e2c27b1 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 16:35:48 +0530 Subject: [PATCH 7/8] Settings Fragment code cleanup - add assertion to prevent Nullable warnings in lint Signed-off-by: Arka Prava Basu --- .../org/havenapp/main/SettingsFragment.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/havenapp/main/SettingsFragment.java b/src/main/java/org/havenapp/main/SettingsFragment.java index 81a0339c..af70e5f1 100644 --- a/src/main/java/org/havenapp/main/SettingsFragment.java +++ b/src/main/java/org/havenapp/main/SettingsFragment.java @@ -9,7 +9,6 @@ import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -25,6 +24,17 @@ import android.widget.Switch; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.preference.EditTextPreference; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.SwitchPreference; + import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; @@ -38,16 +48,6 @@ import java.io.File; import java.util.Locale; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; -import androidx.preference.EditTextPreference; -import androidx.preference.ListPreference; -import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.SwitchPreference; import info.guardianproject.netcipher.proxy.OrbotHelper; @@ -465,24 +465,28 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin break; case PreferenceManager.REMOTE_ACCESS_ONION: { - String text = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ONION)).getText(); + EditTextPreference preference = findPreference(PreferenceManager.REMOTE_ACCESS_ONION); + assert preference != null; + String text = preference.getText(); if (checkValidString(text)) { preferences.setRemoteAccessOnion(text.trim()); - findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT); + preference.setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT); } else { preferences.setRemoteAccessOnion(text); - findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(R.string.remote_access_hint); + preference.setSummary(R.string.remote_access_hint); } break; } case PreferenceManager.REMOTE_ACCESS_CRED: { - String text = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).getText(); + EditTextPreference preference = findPreference(PreferenceManager.REMOTE_ACCESS_CRED); + assert preference != null; + String text = preference.getText(); if (checkValidString(text)) { preferences.setRemoteAccessCredential(text.trim()); - findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.bullets); + preference.setSummary(R.string.bullets); } else { preferences.setRemoteAccessCredential(text); - findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.remote_access_credential_hint); + preference.setSummary(R.string.remote_access_credential_hint); } break; } From 7f1a4b5ecd219e808a7fcbb0b847020f75e5a29a Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 17 Apr 2020 16:36:30 +0530 Subject: [PATCH 8/8] Feed Date object DateFormat format() method - string representation of Date object is not allowed causing an IllegalStateException which prevented display of EventTriggers - fixes issue #410 Signed-off-by: Arka Prava Basu --- src/main/java/org/havenapp/main/service/WebServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/havenapp/main/service/WebServer.java b/src/main/java/org/havenapp/main/service/WebServer.java index ea421794..60b59e8c 100644 --- a/src/main/java/org/havenapp/main/service/WebServer.java +++ b/src/main/java/org/havenapp/main/service/WebServer.java @@ -180,7 +180,7 @@ private void showEvent (Event event, StringBuffer page) { { String title = eventTrigger.getStringType(new ResourceManager(mContext)); String desc = new SimpleDateFormat(Utils.DATE_TIME_PATTERN, - Locale.getDefault()).format(eventTrigger.getTime().toString()); + Locale.getDefault()).format(eventTrigger.getTime()); page.append(""); page.append(title).append("
");