From 94202097b7c133823ea2b3fb9d45f4b8f67eb796 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Wed, 23 Dec 2020 17:35:41 -0500 Subject: Reorganize and remove unused libraries --- .../infinityforreddit/subreddit/FetchSubredditData.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java index a7a9eb21..37587ede 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java @@ -2,9 +2,9 @@ package ml.docilealligator.infinityforreddit.subreddit; import androidx.annotation.NonNull; -import com.facebook.common.internal.ImmutableMap; - import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import ml.docilealligator.infinityforreddit.apis.RedditAPI; @@ -50,7 +50,8 @@ public class FetchSubredditData { boolean nsfw, final FetchSubredditListingDataListener fetchSubredditListingDataListener) { RedditAPI api = retrofit.create(RedditAPI.class); - Map headers = accessToken != null ? APIUtils.getOAuthHeader(accessToken) : ImmutableMap.of(); + Map map = new HashMap<>(); + Map headers = accessToken != null ? APIUtils.getOAuthHeader(accessToken) : Collections.unmodifiableMap(map); Call subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw ? 1 : 0, headers); subredditDataCall.enqueue(new Callback() { @Override -- cgit v1.2.3 From 90df8e42bb9f885dbc408bc0c674c2e7e814b0e9 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Wed, 23 Dec 2020 17:35:56 -0500 Subject: Correct existing ViewPager2 implementations --- .../infinityforreddit/activities/AccountSavedThingActivity.java | 8 ++++---- .../infinityforreddit/activities/MainActivity.java | 8 ++++---- .../infinityforreddit/activities/SearchResultActivity.java | 8 ++++---- .../infinityforreddit/activities/ViewSubredditDetailActivity.java | 8 ++++---- .../infinityforreddit/activities/ViewUserDetailActivity.java | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index c33104ac..a87c10d0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -15,8 +15,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.Lifecycle; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -199,7 +199,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT } private void initializeViewPager() { - sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); + sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setOffscreenPageLimit(2); viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); @@ -345,8 +345,8 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT private class SectionsPagerAdapter extends FragmentStateAdapter { - SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { - super(fm, lifecycle); + SectionsPagerAdapter(FragmentActivity fa) { + super(fa); } @NonNull diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 2d139293..b621b583 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -30,8 +30,8 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -772,7 +772,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb int tabCount = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_COUNT, 3); mShowFavoriteSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false); mShowSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false); - sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle(), tabCount, + sectionsPagerAdapter = new SectionsPagerAdapter(this, tabCount, mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits); viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setOffscreenPageLimit(1); @@ -1313,8 +1313,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb List favoriteSubscribedSubreddits; List subscribedSubreddits; - SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle, int tabCount, boolean showFavoriteSubscribedSubreddits, boolean showSubscribedSubreddits) { - super(fm, lifecycle); + SectionsPagerAdapter(FragmentActivity fa, int tabCount, boolean showFavoriteSubscribedSubreddits, boolean showSubscribedSubreddits) { + super(fa); this.tabCount = tabCount; favoriteSubscribedSubreddits = new ArrayList<>(); subscribedSubreddits = new ArrayList<>(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index b605aedb..a3ca8889 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -16,8 +16,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.Lifecycle; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -221,7 +221,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } private void initializeViewPager() { - sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); + sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setOffscreenPageLimit(3); viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); @@ -381,8 +381,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect private class SectionsPagerAdapter extends FragmentStateAdapter { - public SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { - super(fm, lifecycle); + public SectionsPagerAdapter(FragmentActivity fa) { + super(fa); } @NonNull diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 1771b8dc..4852c32d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -28,8 +28,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.ViewModelProvider; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -842,7 +842,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } }).execute(); - sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); + sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override public void onPageSelected(int position) { @@ -1233,8 +1233,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp private class SectionsPagerAdapter extends FragmentStateAdapter { - SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { - super(fm, lifecycle); + SectionsPagerAdapter(FragmentActivity fa) { + super(fa); } @NonNull diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 3ddf99f5..9c77e0a9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -31,8 +31,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.ViewModelProvider; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -604,7 +604,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } private void initializeViewPager() { - sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); + sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setOffscreenPageLimit(2); viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); @@ -1308,8 +1308,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele private class SectionsPagerAdapter extends FragmentStateAdapter { - SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { - super(fm, lifecycle); + SectionsPagerAdapter(FragmentActivity fa) { + super(fa); } @NonNull -- cgit v1.2.3 From 4528b3d749fcd5b978d570159ebba13c5400284d Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Wed, 23 Dec 2020 17:36:09 -0500 Subject: Fix an ExoPlayer deprecation --- .../infinityforreddit/activities/PostVideoActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index b2b28948..b9562b46 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -27,7 +27,7 @@ import com.bumptech.glide.request.RequestOptions; import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.exoplayer2.source.ExtractorMediaSource; +import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; @@ -424,7 +424,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF constraintLayout.setVisibility(View.GONE); selectAgainTextView.setVisibility(View.VISIBLE); videoPlayerView.setVisibility(View.VISIBLE); - player.prepare(new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(videoUri)); + player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(videoUri)); player.setPlayWhenReady(true); wasPlaying = true; } -- cgit v1.2.3 From 6247868949e0469c4916ff859f1c7b87c7bc20b9 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Wed, 23 Dec 2020 17:36:22 -0500 Subject: Update some libraries --- .../infinityforreddit/activities/LinkResolverActivity.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index bac8f3da..27fa8298 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -10,7 +10,9 @@ import android.os.Bundle; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; +import androidx.browser.customtabs.CustomTabColorSchemeParams; import androidx.browser.customtabs.CustomTabsIntent; +import androidx.browser.customtabs.CustomTabsService; import java.util.ArrayList; import java.util.List; @@ -23,8 +25,6 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION; - public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; @@ -276,7 +276,7 @@ public class LinkResolverActivity extends AppCompatActivity { ArrayList packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); - serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); + serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); // Check if this package also resolves the Custom Tabs service. if (pm.resolveService(serviceIntent, 0) != null) { @@ -291,8 +291,11 @@ public class LinkResolverActivity extends AppCompatActivity { if (!resolveInfos.isEmpty()) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); // add share action to menu list - builder.addDefaultShareMenuItem(); - builder.setToolbarColor(mCustomThemeWrapper.getColorPrimary()); + builder.setShareState(CustomTabsIntent.SHARE_STATE_ON); + builder.setDefaultColorSchemeParams( + new CustomTabColorSchemeParams.Builder() + .setToolbarColor(mCustomThemeWrapper.getColorPrimary()) + .build()); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); if (uri.getScheme() == null) { -- cgit v1.2.3 From b98291c05ddf81f0eae410127e7d125fd8139d7a Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Wed, 23 Dec 2020 19:10:49 -0500 Subject: Use some Compat classes --- .../activities/CustomThemeListingActivity.java | 3 ++- .../infinityforreddit/activities/MainActivity.java | 3 ++- .../activities/PostImageActivity.java | 7 ++----- .../activities/PostLinkActivity.java | 3 ++- .../activities/PostTextActivity.java | 3 ++- .../activities/PostVideoActivity.java | 7 ++----- .../activities/SettingsActivity.java | 3 ++- .../activities/SubmitCrosspostActivity.java | 3 ++- .../activities/ViewImageOrGifActivity.java | 8 ++------ .../activities/ViewVideoActivity.java | 19 +++++-------------- .../SetAsWallpaperBottomSheetFragment.java | 3 ++- .../customviews/LollipopBugFixedWebView.java | 3 ++- .../fragments/ViewImgurImageFragment.java | 8 ++------ .../fragments/ViewImgurVideoFragment.java | 8 ++------ .../ViewRedditGalleryImageOrGifFragment.java | 8 ++------ .../fragments/ViewRedditGalleryVideoFragment.java | 8 ++------ .../services/DownloadMediaService.java | 4 ++-- .../services/DownloadRedditVideoService.java | 4 ++-- .../settings/FontPreferenceFragment.java | 5 +++-- .../settings/ThemePreferenceFragment.java | 3 ++- .../infinityforreddit/utils/NotificationUtils.java | 5 +++-- .../infinityforreddit/utils/Utils.java | 11 ++++------- 22 files changed, 51 insertions(+), 78 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java index c30cc188..03f6ae9e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java @@ -14,6 +14,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.app.ActivityCompat; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -248,7 +249,7 @@ public class CustomThemeListingActivity extends BaseActivity implements @Subscribe public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { - recreate(); + ActivityCompat.recreate(this); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index b621b583..fe9da437 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -27,6 +27,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.app.ActivityCompat; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; @@ -1144,7 +1145,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Subscribe public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { - recreate(); + ActivityCompat.recreate(this); } @Subscribe diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java index a8517925..85601581 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java @@ -22,6 +22,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import com.bumptech.glide.Glide; @@ -528,11 +529,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } + ContextCompat.startForegroundService(this, intent); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index 2f76cd9d..c53d43c5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -17,6 +17,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; @@ -449,7 +450,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK); - startService(intent); + ContextCompat.startForegroundService(this, intent); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index 31814057..7d04e456 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -17,6 +17,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -466,7 +467,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK); - startService(intent); + ContextCompat.startForegroundService(this, intent); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index b9562b46..6d8e8f26 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -20,6 +20,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; @@ -528,11 +529,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } + ContextCompat.startForegroundService(this, intent); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java index 699946a5..df889ed7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java @@ -7,6 +7,7 @@ import android.view.MenuItem; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; +import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; @@ -192,6 +193,6 @@ public class SettingsActivity extends BaseActivity implements @Subscribe public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { - recreate(); + ActivityCompat.recreate(this); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java index 04c70dc4..fb7e5a0b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java @@ -21,6 +21,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; @@ -520,7 +521,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_CROSSPOST); - startService(intent); + ContextCompat.startForegroundService(this, intent); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java index f336f94f..a86e2c86 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java @@ -283,7 +283,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa isDownloading = true; - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { @@ -341,11 +341,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, isGif ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF : DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, mImageFileName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, mSubredditName); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } + ContextCompat.startForegroundService(this, intent); Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index df48ab26..417d8de7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -419,7 +419,7 @@ public class ViewVideoActivity extends AppCompatActivity { } isDownloading = true; - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { @@ -472,29 +472,20 @@ public class ViewVideoActivity extends AppCompatActivity { private void download() { isDownloading = false; + Intent intent; if (videoType != VIDEO_TYPE_NORMAL) { - Intent intent = new Intent(this, DownloadMediaService.class); + intent = new Intent(this, DownloadMediaService.class); intent.putExtra(DownloadMediaService.EXTRA_URL, videoDownloadUrl); intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, videoFileName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } } else { - Intent intent = new Intent(this, DownloadRedditVideoService.class); + intent = new Intent(this, DownloadRedditVideoService.class); intent.putExtra(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl); intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id); intent.putExtra(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } } + ContextCompat.startForegroundService(this, intent); Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java index 05d31cf3..1dd45fe2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; import android.app.Activity; import android.content.Context; +import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -49,7 +50,7 @@ public class SetAsWallpaperBottomSheetFragment extends RoundedBottomSheetDialogF dismiss(); }); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { homeScreenTextvView.setVisibility(View.VISIBLE); lockScreenTextView.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LollipopBugFixedWebView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LollipopBugFixedWebView.java index 6392902d..71387a2f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LollipopBugFixedWebView.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LollipopBugFixedWebView.java @@ -21,7 +21,8 @@ public class LollipopBugFixedWebView extends WebView{ // To fix Android Lollipop WebView problem create a new configuration on that Android version only private static Context getFixedContext(Context context) { - if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) // Android Lollipop 5.0 & 5.1 + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP + || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) // Android Lollipop 5.0 & 5.1 return context.createConfigurationContext(new Configuration()); return context; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java index d97fedd4..51bfeb6c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java @@ -157,7 +157,7 @@ public class ViewImgurImageFragment extends Fragment { isDownloading = true; - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { @@ -238,11 +238,7 @@ public class ViewImgurImageFragment extends Fragment { intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink()); intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - activity.startForegroundService(intent); - } else { - activity.startService(intent); - } + ContextCompat.startForegroundService(activity, intent); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java index 3af97f85..01961e17 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java @@ -149,7 +149,7 @@ public class ViewImgurVideoFragment extends Fragment { public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_download_view_imgur_video_fragment) { isDownloading = true; - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { @@ -189,11 +189,7 @@ public class ViewImgurVideoFragment extends Fragment { intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink()); intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - activity.startForegroundService(intent); - } else { - activity.startService(intent); - } + ContextCompat.startForegroundService(activity, intent); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index 12e4a884..585730d5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -223,7 +223,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { isDownloading = true; - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { @@ -272,11 +272,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, media.mediaType == Post.Gallery.TYPE_GIF ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF: DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, media.fileName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - activity.startForegroundService(intent); - } else { - activity.startService(intent); - } + ContextCompat.startForegroundService(activity, intent); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java index 9530823d..a1258ce2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java @@ -152,7 +152,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment { public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_download_view_reddit_gallery_video_fragment) { isDownloading = true; - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { @@ -193,11 +193,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment { intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, galleryVideo.fileName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - activity.startForegroundService(intent); - } else { - activity.startService(intent); - } + ContextCompat.startForegroundService(activity, intent); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java index 1246634a..a326d81f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java @@ -142,7 +142,7 @@ public class DownloadMediaService extends Service { if (response.isSuccessful() && response.body() != null) { String destinationFileDirectory = getDownloadLocation(mediaType); if (destinationFileDirectory.equals("")) { - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { File directory = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (directory != null) { String directoryPath = separateDownloadFolder && subredditName != null && !subredditName.equals("") ? directory.getAbsolutePath() + "/Infinity/" + subredditName + "/" : directory.getAbsolutePath() + "/Infinity/"; @@ -235,7 +235,7 @@ public class DownloadMediaService extends Service { int mediaType) throws IOException { ContentResolver contentResolver = getContentResolver(); if (isDefaultDestination) { - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { InputStream inputStream = body.byteStream(); OutputStream outputStream = new FileOutputStream(destinationFileUriString); byte[] fileReader = new byte[4096]; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java index c4f37aca..73839464 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java @@ -146,7 +146,7 @@ public class DownloadRedditVideoService extends Service { String destinationFileUriString; boolean isDefaultDestination; if (destinationFileDirectory.equals("")) { - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { File destinationDirectory = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (destinationDirectory != null) { String destinationDirectoryPath = separateDownloadFolder ? destinationDirectory.getAbsolutePath() + "/Infinity/" + subredditName + "/" : destinationDirectory.getAbsolutePath() + "/Infinity/"; @@ -396,7 +396,7 @@ public class DownloadRedditVideoService extends Service { boolean isDefaultDestination) throws IOException { ContentResolver contentResolver = getContentResolver(); if (isDefaultDestination) { - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { InputStream in = new FileInputStream(srcPath); OutputStream out = new FileOutputStream(destinationFileUriString); byte[] buf = new byte[1024]; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java index 2d608ca5..0d43e619 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.os.Bundle; import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; @@ -30,7 +31,7 @@ public class FontPreferenceFragment extends PreferenceFragmentCompat { if (fontFamilyPreference != null) { fontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new RecreateActivityEvent()); - activity.recreate(); + ActivityCompat.recreate(activity); return true; }); } @@ -52,7 +53,7 @@ public class FontPreferenceFragment extends PreferenceFragmentCompat { if (fontSizePreference != null) { fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new RecreateActivityEvent()); - activity.recreate(); + ActivityCompat.recreate(activity); return true; }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java index e28cd52f..fba59d25 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java @@ -9,6 +9,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; +import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.preference.ListPreference; @@ -109,7 +110,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat { amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> { if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) { EventBus.getDefault().post(new RecreateActivityEvent()); - activity.recreate(); + ActivityCompat.recreate(activity); } return true; }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java index 75cc004a..3c3255de 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.utils; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; +import android.os.Build; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; @@ -36,7 +37,7 @@ public class NotificationUtils { Context context, String title, String content, String summary, String channelId, String channelName, String group, int color) { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } @@ -56,7 +57,7 @@ public class NotificationUtils { public static NotificationCompat.Builder buildSummaryNotification(Context context, NotificationManagerCompat notificationManager, String title, String content, String channelId, String channelName, String group, int color) { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 8d51256d..2a59f2a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -8,7 +8,6 @@ import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.os.Build; -import android.text.Html; import android.text.Spannable; import android.util.DisplayMetrics; import android.view.inputmethod.InputMethodManager; @@ -17,6 +16,7 @@ import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.core.graphics.drawable.DrawableCompat; +import androidx.core.text.HtmlCompat; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -135,13 +135,10 @@ public class Utils { } public static void setHTMLWithImageToTextView(TextView textView, String content, boolean enlargeImage) { - Spannable html; GlideImageGetter glideImageGetter = new GlideImageGetter(textView, enlargeImage); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { - html = (Spannable) Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); - } else { - html = (Spannable) Html.fromHtml(content, glideImageGetter, null); - } + Spannable html = (Spannable) HtmlCompat.fromHtml( + content, HtmlCompat.FROM_HTML_MODE_LEGACY, glideImageGetter, null); + textView.setText(html); } -- cgit v1.2.3