From ca7f2d2d3d61ebc43a1f9d190f0aa720c5bd51d7 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sun, 12 Dec 2021 14:56:31 -0500 Subject: Remove no longer needed compat methods --- .../danoeh/antennapod/activity/MainActivity.java | 7 +++--- .../antennapod/adapter/DataFolderAdapter.java | 3 +-- .../antennapod/adapter/QueueRecyclerAdapter.java | 3 +-- .../adapter/SubscriptionsRecyclerAdapter.java | 6 ++--- .../antennapod/fragment/FeedInfoFragment.java | 6 ++--- .../antennapod/fragment/FeedItemlistFragment.java | 10 ++++---- .../danoeh/antennapod/fragment/ItemFragment.java | 10 +++----- .../antennapod/fragment/ItemPagerFragment.java | 3 +-- .../preferences/DownloadStatisticsFragment.java | 3 +-- .../ImportExportPreferencesFragment.java | 19 +------------- .../preferences/PlaybackStatisticsFragment.java | 5 ++-- .../antennapod/view/ToolbarIconTintManager.java | 3 +-- .../danoeh/antennapod/core/util/NetworkUtils.java | 3 +-- .../core/util/comparator/CompareCompat.java | 29 ---------------------- net/sync/model/build.gradle | 1 - .../antennapod/net/sync/model/EpisodeAction.java | 10 ++++---- 16 files changed, 31 insertions(+), 90 deletions(-) delete mode 100644 core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 7dc760e76..17411c7ce 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -27,7 +27,6 @@ import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; -import androidx.core.view.ViewCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -153,14 +152,14 @@ public class MainActivity extends CastEnabledActivity { } /** - * ViewCompat.generateViewId stores the current ID in a static variable. + * View.generateViewId stores the current ID in a static variable. * When the process is killed, the variable gets reset. * This makes sure that we do not get ID collisions * and therefore errors when trying to restore state from another view. */ @SuppressWarnings("StatementWithEmptyBody") private void ensureGeneratedViewIdGreaterThan(int minimum) { - while (ViewCompat.generateViewId() <= minimum) { + while (View.generateViewId() <= minimum) { // Generate new IDs } } @@ -168,7 +167,7 @@ public class MainActivity extends CastEnabledActivity { @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(KEY_GENERATED_VIEW_ID, ViewCompat.generateViewId()); + outState.putInt(KEY_GENERATED_VIEW_ID, View.generateViewId()); } private final BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java index bcad1b5a4..862dc2fe2 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java @@ -9,7 +9,6 @@ import android.widget.ProgressBar; import android.widget.RadioButton; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; import androidx.core.util.Consumer; import androidx.recyclerview.widget.RecyclerView; import de.danoeh.antennapod.R; @@ -74,7 +73,7 @@ public class DataFolderAdapter extends RecyclerView.Adapter getStorageEntries(Context context) { - File[] mediaDirs = ContextCompat.getExternalFilesDirs(context, null); + File[] mediaDirs = context.getExternalFilesDirs(null); final List entries = new ArrayList<>(mediaDirs.length); for (File dir : mediaDirs) { if (!isWritable(dir)) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index 383d670f1..42813c8d6 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -7,7 +7,6 @@ import android.view.MenuInflater; import android.view.MotionEvent; import android.view.View; -import androidx.core.view.ViewCompat; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -53,7 +52,7 @@ public class QueueRecyclerAdapter extends EpisodeItemListAdapter { }); holder.coverHolder.setOnTouchListener((v1, event) -> { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { - boolean isLtr = ViewCompat.getLayoutDirection(holder.itemView) == ViewCompat.LAYOUT_DIRECTION_LTR; + boolean isLtr = holder.itemView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR; float factor = isLtr ? 1 : -1; if (factor * event.getX() < factor * 0.5 * v1.getWidth()) { Log.d(TAG, "startDrag()"); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java index 4bf787db5..eb2239177 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java @@ -4,6 +4,7 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.text.TextUtils; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuInflater; @@ -18,8 +19,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.content.res.AppCompatResources; -import androidx.core.text.TextUtilsCompat; -import androidx.core.view.ViewCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.RecyclerView; @@ -222,8 +221,7 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter { if (controller != null && item.getMedia() != null && controller.getMedia() != null - && ObjectsCompat.equals(item.getMedia().getIdentifier(), controller.getMedia().getIdentifier())) { + && Objects.equals(item.getMedia().getIdentifier(), controller.getMedia().getIdentifier())) { controller.seekTo(time); } else { ((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.play_this_to_seek_position, @@ -189,8 +187,8 @@ public class ItemFragment extends Fragment { } private void showOnDemandConfigBalloon(boolean offerStreaming) { - boolean isLocaleRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) - == ViewCompat.LAYOUT_DIRECTION_RTL; + boolean isLocaleRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) + == View.LAYOUT_DIRECTION_RTL; Balloon balloon = new Balloon.Builder(getContext()) .setArrowOrientation(ArrowOrientation.TOP) .setArrowPosition(0.25f + ((isLocaleRtl ^ offerStreaming) ? 0f : 0.5f)) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java index 14f6ae875..cae49c63e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java @@ -9,7 +9,6 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; -import androidx.core.view.ViewCompat; import androidx.fragment.app.Fragment; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -78,7 +77,7 @@ public class ItemPagerFragment extends Fragment implements Toolbar.OnMenuItemCli // > When using FragmentStatePagerAdapter the host ViewPager must have a valid ID set. // When opening multiple ItemPagerFragments by clicking "item" -> "visit podcast" -> "item" -> etc, // the ID is no longer unique and FragmentStatePagerAdapter does not display any pages. - int newId = ViewCompat.generateViewId(); + int newId = View.generateViewId(); if (savedInstanceState != null && savedInstanceState.getInt(KEY_PAGER_ID, 0) != 0) { // Restore state by using the same ID as before. ID collisions are prevented in MainActivity. newId = savedInstanceState.getInt(KEY_PAGER_ID, 0); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java index 3059d7ad2..ff94cc20c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java @@ -17,7 +17,6 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.DownloadStatisticsListAdapter; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.StatisticsItem; -import de.danoeh.antennapod.core.util.comparator.CompareCompat; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -75,7 +74,7 @@ public class DownloadStatisticsFragment extends Fragment { Observable.fromCallable(() -> { List statisticsData = DBReader.getStatistics(); Collections.sort(statisticsData, (item1, item2) -> - CompareCompat.compareLong(item1.totalDownloadSize, item2.totalDownloadSize)); + Long.compare(item2.totalDownloadSize, item1.totalDownloadSize)); return statisticsData; }) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java index b72d1eb32..5156de432 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java @@ -8,9 +8,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; -import android.os.Build; import android.os.Bundle; -import android.os.Environment; import android.util.Log; import androidx.activity.result.ActivityResult; @@ -42,7 +40,6 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import java.io.File; -import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -169,21 +166,7 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { } private void exportDatabase() { - if (Build.VERSION.SDK_INT >= 19) { - backupDatabaseLauncher.launch(dateStampFilename(DATABASE_EXPORT_FILENAME)); - } else { - File sd = Environment.getExternalStorageDirectory(); - File backupDB = new File(sd, dateStampFilename(DATABASE_EXPORT_FILENAME)); - progressDialog.show(); - disposable = Completable.fromAction(() -> - DatabaseExporter.exportToStream(new FileOutputStream(backupDB), getContext())) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(() -> { - Snackbar.make(getView(), R.string.export_success_title, Snackbar.LENGTH_LONG).show(); - progressDialog.dismiss(); - }, this::showExportErrorDialog); - } + backupDatabaseLauncher.launch(dateStampFilename(DATABASE_EXPORT_FILENAME)); } private void importDatabase() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java index 04324f709..ba6164212 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java @@ -28,7 +28,6 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.StatisticsItem; -import de.danoeh.antennapod.core.util.comparator.CompareCompat; import io.reactivex.Completable; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -188,10 +187,10 @@ public class PlaybackStatisticsFragment extends Fragment { List statisticsData = DBReader.getStatistics(); if (countAll) { Collections.sort(statisticsData, (item1, item2) -> - CompareCompat.compareLong(item1.timePlayedCountAll, item2.timePlayedCountAll)); + Long.compare(item2.timePlayedCountAll, item1.timePlayedCountAll)); } else { Collections.sort(statisticsData, (item1, item2) -> - CompareCompat.compareLong(item1.timePlayed, item2.timePlayed)); + Long.compare(item2.timePlayed, item1.timePlayed)); } return statisticsData; } diff --git a/app/src/main/java/de/danoeh/antennapod/view/ToolbarIconTintManager.java b/app/src/main/java/de/danoeh/antennapod/view/ToolbarIconTintManager.java index 37d8db03e..621b6ea95 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/ToolbarIconTintManager.java +++ b/app/src/main/java/de/danoeh/antennapod/view/ToolbarIconTintManager.java @@ -6,7 +6,6 @@ import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.view.ContextThemeWrapper; import androidx.appcompat.widget.Toolbar; -import androidx.core.view.ViewCompat; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import de.danoeh.antennapod.R; @@ -25,7 +24,7 @@ public abstract class ToolbarIconTintManager implements AppBarLayout.OnOffsetCha @Override public void onOffsetChanged(AppBarLayout appBarLayout, int offset) { - boolean tint = (collapsingToolbar.getHeight() + offset) > (2 * ViewCompat.getMinimumHeight(collapsingToolbar)); + boolean tint = (collapsingToolbar.getHeight() + offset) > (2 * collapsingToolbar.getMinimumHeight()); if (isTinted != tint) { isTinted = tint; updateTint(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java index 4aeed734e..4cbd8b2c2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java @@ -8,7 +8,6 @@ import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; -import androidx.core.net.ConnectivityManagerCompat; import android.text.TextUtils; import android.util.Log; @@ -97,7 +96,7 @@ public class NetworkUtils { private static boolean isNetworkMetered() { ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - return ConnectivityManagerCompat.isActiveNetworkMetered(connManager); + return connManager.isActiveNetworkMetered(); } private static boolean isNetworkCellular() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java b/core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java deleted file mode 100644 index c189f2389..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.danoeh.antennapod.core.util.comparator; - -/** - * Some compare() methods are not available before API 19. - * This class provides fallbacks - */ -public class CompareCompat { - - private CompareCompat() { - // Must not be instantiated - } - - /** - * Compares two {@code long} values. Long.compare() is not available before API 19 - * - * @return 0 if long1 = long2, less than 0 if long1 < long2, - * and greater than 0 if long1 > long2. - */ - public static int compareLong(long long1, long long2) { - //noinspection UseCompareMethod - if (long1 > long2) { - return -1; - } else if (long1 < long2) { - return 1; - } else { - return 0; - } - } -} diff --git a/net/sync/model/build.gradle b/net/sync/model/build.gradle index e47040892..72d962536 100644 --- a/net/sync/model/build.gradle +++ b/net/sync/model/build.gradle @@ -5,5 +5,4 @@ dependencies { implementation project(':model') annotationProcessor "androidx.annotation:annotation:$annotationVersion" - implementation "androidx.appcompat:appcompat:$appcompatVersion" } diff --git a/net/sync/model/src/main/java/de/danoeh/antennapod/net/sync/model/EpisodeAction.java b/net/sync/model/src/main/java/de/danoeh/antennapod/net/sync/model/EpisodeAction.java index da398d83e..42fbdb310 100644 --- a/net/sync/model/src/main/java/de/danoeh/antennapod/net/sync/model/EpisodeAction.java +++ b/net/sync/model/src/main/java/de/danoeh/antennapod/net/sync/model/EpisodeAction.java @@ -4,7 +4,6 @@ import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; -import androidx.core.util.ObjectsCompat; import org.json.JSONException; import org.json.JSONObject; @@ -13,6 +12,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.Objects; import java.util.TimeZone; import de.danoeh.antennapod.model.feed.FeedItem; @@ -159,10 +159,10 @@ public class EpisodeAction { && position == that.position && total == that.total && action != that.action - && ObjectsCompat.equals(podcast, that.podcast) - && ObjectsCompat.equals(episode, that.episode) - && ObjectsCompat.equals(timestamp, that.timestamp) - && ObjectsCompat.equals(guid, that.guid); + && Objects.equals(podcast, that.podcast) + && Objects.equals(episode, that.episode) + && Objects.equals(timestamp, that.timestamp) + && Objects.equals(guid, that.guid); } @Override -- cgit v1.2.3