From 03b61f7d1d7803a4930a5990f9330846a19501b4 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 1 Jul 2020 07:37:53 +0530 Subject: [PATCH] Use Java 8 Date/Time API instead of the legacy API. --- .../Helpers/SecurityHelpers/SslHelper.java | 17 +++++++++-------- .../Plugins/PhotoPlugin/PhotoActivity.java | 14 +++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java index e0229e11..de2a7b74 100644 --- a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java @@ -55,8 +55,10 @@ import java.security.PublicKey; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; import java.util.Formatter; import java.util.Locale; @@ -126,16 +128,15 @@ public class SslHelper { nameBuilder.addRDN(BCStyle.CN, deviceId); nameBuilder.addRDN(BCStyle.OU, "KDE Connect"); nameBuilder.addRDN(BCStyle.O, "KDE"); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.YEAR, -1); - Date notBefore = calendar.getTime(); - calendar.add(Calendar.YEAR, 10); - Date notAfter = calendar.getTime(); + final LocalDate localDate = LocalDate.now().minusYears(1); + final Instant notBefore = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant(); + final Instant notAfter = localDate.plusYears(10).atStartOfDay(ZoneId.systemDefault()) + .toInstant(); X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder( nameBuilder.build(), BigInteger.ONE, - notBefore, - notAfter, + Date.from(notBefore), + Date.from(notAfter), nameBuilder.build(), publicKey ); diff --git a/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java b/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java index 92e8fcbf..5a88ed7f 100644 --- a/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java +++ b/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java @@ -5,16 +5,16 @@ import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.FileProvider; + import org.kde.kdeconnect.BackgroundService; import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.FileProvider; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; public class PhotoActivity extends AppCompatActivity { @@ -45,7 +45,7 @@ public class PhotoActivity extends AppCompatActivity { private File createImageFile() throws IOException { // Create an image file name - String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + String timeStamp = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss").format(LocalDateTime.now()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); return File.createTempFile(