Skip to content

Commit

Permalink
replace threetenabp and threetenbp with built-in desugaring mechanism…
Browse files Browse the repository at this point in the history
… so java.time is usable now even when the API level is below 24; reduce lint warnings
  • Loading branch information
mathisdt committed Apr 3, 2022
1 parent 9117d28 commit 884cabb
Show file tree
Hide file tree
Showing 44 changed files with 167 additions and 162 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ android {
compileSdkVersion 31

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
Expand Down Expand Up @@ -82,9 +83,9 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'net.sf.supercsv:super-csv:2.4.0'
implementation 'org.tinylog:tinylog:1.3.6'
implementation 'com.jakewharton.threetenabp:threetenabp:1.4.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.1.3'
testImplementation 'org.threeten:threetenbp:1.6.0'

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
4 changes: 4 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<lint>
<issue id="Deprecated" severity="informational" />
<issue id="LongLogTag" severity="ignore" />
<issue id="InvalidResourceFolder" severity="ignore" />
<issue id="ApplySharedPref" severity="ignore" />
</lint>
15 changes: 3 additions & 12 deletions app/src/main/java/org/zephyrsoft/trackworktime/Basics.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
import org.pmw.tinylog.policies.DailyPolicy;
import org.pmw.tinylog.writers.LogcatWriter;
import org.pmw.tinylog.writers.RollingFileWriter;
import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneId;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.location.CoordinateUtil;
import org.zephyrsoft.trackworktime.location.LocationCallback;
Expand All @@ -66,6 +63,9 @@
import org.zephyrsoft.trackworktime.util.PreferencesUtil;

import java.io.File;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
Expand All @@ -90,15 +90,6 @@ public class Basics extends BroadcastReceiver {

private static Basics instance = null;

/**
* Creates an instance of this class.
*/
public Basics() {
if (instance == null) {
instance = this;
}
}

/**
* Fetches the singleton.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import androidx.appcompat.app.AppCompatActivity;

import org.pmw.tinylog.Logger;
import org.threeten.bp.ZoneId;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.databinding.ActivityDebugBinding;

import java.time.ZoneId;

public class DebugActivity extends AppCompatActivity {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import androidx.documentfile.provider.DocumentFile;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDate;
import org.zephyrsoft.trackworktime.util.PermissionsUtil;

import java.io.BufferedOutputStream;
Expand All @@ -40,6 +39,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.time.LocalDate;
import java.util.Objects;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.databinding.ListActivityBinding;
import org.zephyrsoft.trackworktime.databinding.ListItemBinding;
Expand All @@ -55,6 +53,8 @@
import org.zephyrsoft.trackworktime.util.DateTimeUtil;
import org.zephyrsoft.trackworktime.weektimes.WeekIndexConverter;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import androidx.core.util.Consumer;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDate;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.databinding.DefaultTimesBinding;
import org.zephyrsoft.trackworktime.model.Target;
Expand All @@ -38,6 +37,7 @@
import org.zephyrsoft.trackworktime.ui.DateTextViewController;
import org.zephyrsoft.trackworktime.ui.TargetTimeValidityCheck;

import java.time.LocalDate;
import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.zephyrsoft.trackworktime;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Expand All @@ -31,7 +32,6 @@
import androidx.preference.PreferenceFragmentCompat;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDate;
import org.zephyrsoft.trackworktime.backup.WorkTimeTrackerBackupManager;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.options.CheckIntervalPreference;
Expand All @@ -47,6 +47,7 @@
import org.zephyrsoft.trackworktime.util.PreferencesUtil;

import java.text.DateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -203,6 +204,7 @@ && getActivity() != null) {
}
}

@SuppressLint("deprecation")
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == Constants.MISSING_PRIVILEGE_ACCESS_LOCATION_ID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import org.apache.commons.lang3.StringUtils;
import org.pmw.tinylog.Logger;
import org.threeten.bp.ZonedDateTime;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.databinding.ReportsBinding;
import org.zephyrsoft.trackworktime.model.Event;
Expand All @@ -51,6 +50,7 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import android.os.Bundle;

import org.pmw.tinylog.Logger;
import org.threeten.bp.OffsetDateTime;
import org.zephyrsoft.trackworktime.model.TypeEnum;
import org.zephyrsoft.trackworktime.timer.TimerManager;

import java.time.OffsetDateTime;

/**
* This technically is an activity but it only receives intents from shortcuts
* and the directly exits again. No UI is ever shown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
import androidx.appcompat.app.AppCompatActivity;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDate;
import org.threeten.bp.format.DateTimeFormatter;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.databinding.TargetBinding;
import org.zephyrsoft.trackworktime.model.Target;
import org.zephyrsoft.trackworktime.model.TargetEnum;
import org.zephyrsoft.trackworktime.timer.TimerManager;
import org.zephyrsoft.trackworktime.util.DateTimeUtil;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import android.os.Bundle;

import org.pmw.tinylog.Logger;
import org.threeten.bp.OffsetDateTime;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.model.Task;
import org.zephyrsoft.trackworktime.model.TypeEnum;
import org.zephyrsoft.trackworktime.timer.TimerManager;

import java.time.OffsetDateTime;

/**
* Hook for clock-in with third-party apps like Tasker or Llama.
* Also handles actions triggered directly from the notification and from the widget of TWT.
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/zephyrsoft/trackworktime/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
import androidx.core.content.ContextCompat;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDate;
import org.zephyrsoft.trackworktime.model.PeriodEnum;
import org.zephyrsoft.trackworktime.timer.TimerManager;
import org.zephyrsoft.trackworktime.util.DateTimeUtil;

import java.time.LocalDate;

public class Widget extends AppWidgetProvider {

private static final String ACTION_UPDATE = BuildConfig.APPLICATION_ID + ".WIDGET_UPDATE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
import com.google.android.material.navigation.NavigationView;

import org.pmw.tinylog.Logger;
import org.threeten.bp.DayOfWeek;
import org.threeten.bp.LocalDate;
import org.zephyrsoft.trackworktime.backup.BackupFileInfo;
import org.zephyrsoft.trackworktime.database.DAO;
import org.zephyrsoft.trackworktime.databinding.ActivityMainBinding;
Expand All @@ -85,6 +83,8 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.List;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;

import com.jakewharton.threetenabp.AndroidThreeTen;

import org.acra.ACRA;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.DialogConfigurationBuilder;
Expand All @@ -62,8 +60,6 @@ public class WorkTimeTrackerApplication extends Application {
public void onCreate() {
Logger.info("creating application");

AndroidThreeTen.init(this);

NotificationChannel notificationChannel = null;
NotificationChannel serviceNotificationChannel = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/org/zephyrsoft/trackworktime/database/DAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@
import androidx.annotation.VisibleForTesting;

import org.pmw.tinylog.Logger;
import org.threeten.bp.Instant;
import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.LocalTime;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.ResolverStyle;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.TemporalAccessor;
import org.zephyrsoft.trackworktime.Basics;
import org.zephyrsoft.trackworktime.UpgradeActivity;
import org.zephyrsoft.trackworktime.backup.WorkTimeTrackerBackupManager;
Expand All @@ -86,6 +71,21 @@
import java.io.IOException;
import java.io.Writer;
import java.lang.ref.WeakReference;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
import androidx.appcompat.app.AppCompatActivity;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.LocalTime;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.temporal.ChronoUnit;
import org.zephyrsoft.trackworktime.Basics;
import org.zephyrsoft.trackworktime.Constants;
import org.zephyrsoft.trackworktime.EventListActivity;
Expand All @@ -49,6 +42,13 @@
import org.zephyrsoft.trackworktime.timer.TimerManager;
import org.zephyrsoft.trackworktime.ui.DateTextViewController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import androidx.annotation.Nullable;
import androidx.core.util.Consumer;

import org.threeten.bp.LocalTime;
import org.zephyrsoft.trackworktime.Basics;
import org.zephyrsoft.trackworktime.util.DateTimeUtil;

import java.time.LocalTime;

public class TimeTextViewController {

private final TextView view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import androidx.annotation.Nullable;

import org.pmw.tinylog.Logger;
import org.threeten.bp.LocalDateTime;
import org.zephyrsoft.trackworktime.util.PermissionsUtil;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.zephyrsoft.trackworktime.model;

import org.threeten.bp.LocalDate;

import org.zephyrsoft.trackworktime.database.DAO;

import java.time.LocalDate;

/**
* Data class for an event.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package org.zephyrsoft.trackworktime.model;

import org.threeten.bp.OffsetDateTime;
import org.zephyrsoft.trackworktime.database.DAO;

import java.time.OffsetDateTime;

/**
* Data class for an event.
*
Expand Down
Loading

0 comments on commit 884cabb

Please sign in to comment.