Merge pull request #229 from TacoTheDank/master

Miscellaneous improvements
This commit is contained in:
Docile-Alligator 2020-12-24 14:27:20 +08:00 committed by GitHub
commit c979e79ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 207 additions and 189 deletions

View File

@ -11,7 +11,7 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {
arguments = [ eventBusIndex : 'ml.docilealligator.infinityforreddit.EventBusIndex' ] arguments = [eventBusIndex: 'ml.docilealligator.infinityforreddit.EventBusIndex']
} }
} }
} }
@ -35,79 +35,133 @@ android {
} }
dependencies { dependencies {
/** AndroidX **/
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.browser:browser:1.2.0' implementation 'androidx.biometric:biometric:1.1.0-rc01'
implementation 'androidx.browser:browser:1.3.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
// Lifecycle components def lifecycleVersion = "2.2.0"
def lifecycleVersion = '2.2.0' implementation "androidx.lifecycle:lifecycle-livedata:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycleVersion"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
implementation 'androidx.paging:paging-runtime:2.1.2' implementation 'androidx.paging:paging-runtime:2.1.2'
implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.preference:preference:1.1.1'
// Room components def roomVersion = "2.2.6"
def roomVersion = '2.2.5'
implementation "androidx.room:room-runtime:$roomVersion" implementation "androidx.room:room-runtime:$roomVersion"
annotationProcessor "androidx.room:room-compiler:$roomVersion" annotationProcessor "androidx.room:room-compiler:$roomVersion"
implementation 'androidx.work:work-runtime:2.4.0' implementation 'androidx.work:work-runtime:2.4.0'
implementation 'com.google.android.material:material:1.3.0-alpha04' implementation 'com.google.android.material:material:1.3.0-alpha04'
implementation 'com.google.android.exoplayer:exoplayer-core:2.10.8' /** ExoPlayer **/
implementation 'com.google.android.exoplayer:exoplayer-hls:2.10.8' def exoplayerVersion = "2.10.8"
implementation 'com.google.android.exoplayer:exoplayer-dash:2.10.8' implementation "com.google.android.exoplayer:exoplayer-core:$exoplayerVersion"
implementation 'com.google.android.exoplayer:exoplayer-ui:2.10.8' implementation "com.google.android.exoplayer:exoplayer-dash:$exoplayerVersion"
implementation 'com.alexvasilkov:gesture-views:2.6.0' implementation "com.google.android.exoplayer:exoplayer-hls:$exoplayerVersion"
implementation 'com.github.bumptech.glide:glide:4.11.0' implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayerVersion"
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' def toroVersion = "3.7.0.2010003"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.20'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
implementation 'jp.wasabeef:glide-transformations:4.1.0'
implementation 'com.google.dagger:dagger:2.29.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.29.1'
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9'
implementation 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'
implementation 'io.noties.markwon:core:4.5.0'
implementation 'io.noties.markwon:linkify:4.5.0'
implementation 'io.noties.markwon:ext-strikethrough:4.5.0'
implementation 'io.noties.markwon:simple-ext:4.5.0'
implementation 'io.noties.markwon:recycler-table:4.5.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
implementation 'com.github.Ferfalk:SimpleSearchView:0.1.4'
def eventbusVersion = '3.2.0'
implementation "org.greenrobot:eventbus:$eventbusVersion"
annotationProcessor "org.greenrobot:eventbus-annotation-processor:$eventbusVersion"
implementation 'com.libRG:customtextview:2.4'
implementation 'com.github.Deishelon:RoundedBottomSheet:1.0.1'
implementation 'com.github.livefront:bridge:v1.2.1'
implementation 'com.evernote:android-state:1.4.1'
annotationProcessor 'com.evernote:android-state-processor:1.4.1'
implementation 'com.nex3z:flow-layout:1.3.0'
implementation 'com.r0adkll:slidableactivity:2.1.0'
implementation 'com.atlassian.commonmark:commonmark:0.14.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'me.zhanghai.android.fastscroll:library:1.1.2'
implementation "com.thefuntasty.hauler:core:3.1.0"
implementation 'com.github.Piasy:BigImageViewer:1.6.5'
implementation 'androidx.biometric:biometric:1.1.0-rc01'
implementation 'com.airbnb.android:lottie:3.4.4'
implementation 'com.melegy.redscreenofdeath:red-screen-of-death:0.1.2'
// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
def toroVersion = '3.7.0.2010003'
implementation "im.ene.toro3:toro:$toroVersion" implementation "im.ene.toro3:toro:$toroVersion"
implementation("im.ene.toro3:toro-ext-exoplayer:$toroVersion") { implementation("im.ene.toro3:toro-ext-exoplayer:$toroVersion") {
exclude module: 'extension-ima' exclude module: 'extension-ima'
} }
testImplementation 'junit:junit:4.13.1' /** Third-party **/
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' /**** Backend logic ****/
// Reactive stuff for event and async related
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.20'
// HTTP clients
def retrofitVersion = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion"
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
// Dependency injection
def daggerVersion = "2.30.1"
implementation "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
// Binding
// NOTE: Deprecated in favor of viewbinding
def butterknifeVersion = "10.2.3"
implementation "com.jakewharton:butterknife:$butterknifeVersion"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
// Events
def eventbusVersion = "3.2.0"
implementation "org.greenrobot:eventbus:$eventbusVersion"
annotationProcessor "org.greenrobot:eventbus-annotation-processor:$eventbusVersion"
// TransactionTooLargeException avoidance
implementation 'com.github.livefront:bridge:v1.3.0'
// Bundle-saving without boilerplate
// NOTE: Deprecated
def stateVersion = "1.4.1"
implementation "com.evernote:android-state:$stateVersion"
annotationProcessor "com.evernote:android-state-processor:$stateVersion"
// Object to JSON
// NOTE: Replace with Squareup's Moshi?
implementation 'com.google.code.gson:gson:2.8.6'
/**** User Interface (frontend) ****/
//Image loading
def glideVersion = "4.11.0"
implementation "com.github.bumptech.glide:glide:$glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
def bivVersion = "1.7.0"
implementation "com.github.Piasy.BigImageViewer:BigImageViewer:$bivVersion"
implementation "com.github.Piasy.BigImageViewer:GlideImageLoader:$bivVersion"
implementation "com.github.Piasy.BigImageViewer:GlideImageViewFactory:$bivVersion"
// Markdown
def markwonVersion = "4.6.0"
implementation "io.noties.markwon:core:$markwonVersion"
implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
implementation "io.noties.markwon:linkify:$markwonVersion"
implementation "io.noties.markwon:recycler-table:$markwonVersion"
implementation "io.noties.markwon:simple-ext:$markwonVersion"
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.14.0'
// Animations
implementation 'com.airbnb.android:lottie:3.4.4'
// Loading ProgressBar
implementation 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'
// SearchView
implementation 'com.github.Ferfalk:SimpleSearchView:0.1.4'
// Customizable TextView
implementation 'com.libRG:customtextview:2.4'
// Dismiss gesturing
implementation 'com.r0adkll:slidableactivity:2.1.0'
implementation 'com.thefuntasty.hauler:core:3.1.0'
// Bottom sheet with rounded corners
implementation 'com.github.Deishelon:RoundedBottomSheet:1.0.1'
// FlowLayout (auto-spacing)
implementation 'com.nex3z:flow-layout:1.3.3'
// RecyclerView fast scrolling
implementation 'me.zhanghai.android.fastscroll:library:1.1.5'
// Crash screen
implementation 'com.melegy.redscreenofdeath:red-screen-of-death:0.1.2'
/**** Builds and flavors ****/
// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
} }

View File

@ -15,8 +15,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2; import androidx.viewpager2.widget.ViewPager2;
@ -199,7 +199,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
} }
private void initializeViewPager() { private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2); viewPager2.setOffscreenPageLimit(2);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); 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 { private class SectionsPagerAdapter extends FragmentStateAdapter {
SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { SectionsPagerAdapter(FragmentActivity fa) {
super(fm, lifecycle); super(fa);
} }
@NonNull @NonNull

View File

@ -14,6 +14,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -248,7 +249,7 @@ public class CustomThemeListingActivity extends BaseActivity implements
@Subscribe @Subscribe
public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) {
recreate(); ActivityCompat.recreate(this);
} }
@Override @Override

View File

@ -10,7 +10,9 @@ import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsIntent;
import androidx.browser.customtabs.CustomTabsService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -23,8 +25,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION;
public class LinkResolverActivity extends AppCompatActivity { public class LinkResolverActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@ -276,7 +276,7 @@ public class LinkResolverActivity extends AppCompatActivity {
ArrayList<ResolveInfo> packagesSupportingCustomTabs = new ArrayList<>(); ArrayList<ResolveInfo> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) { for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent(); Intent serviceIntent = new Intent();
serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName); serviceIntent.setPackage(info.activityInfo.packageName);
// Check if this package also resolves the Custom Tabs service. // Check if this package also resolves the Custom Tabs service.
if (pm.resolveService(serviceIntent, 0) != null) { if (pm.resolveService(serviceIntent, 0) != null) {
@ -291,8 +291,11 @@ public class LinkResolverActivity extends AppCompatActivity {
if (!resolveInfos.isEmpty()) { if (!resolveInfos.isEmpty()) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
// add share action to menu list // add share action to menu list
builder.addDefaultShareMenuItem(); builder.setShareState(CustomTabsIntent.SHARE_STATE_ON);
builder.setToolbarColor(mCustomThemeWrapper.getColorPrimary()); builder.setDefaultColorSchemeParams(
new CustomTabColorSchemeParams.Builder()
.setToolbarColor(mCustomThemeWrapper.getColorPrimary())
.build());
CustomTabsIntent customTabsIntent = builder.build(); CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName);
if (uri.getScheme() == null) { if (uri.getScheme() == null) {

View File

@ -27,11 +27,12 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -772,7 +773,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
int tabCount = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_COUNT, 3); 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); 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); 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); mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits);
viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(1); viewPager2.setOffscreenPageLimit(1);
@ -1144,7 +1145,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Subscribe @Subscribe
public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) {
recreate(); ActivityCompat.recreate(this);
} }
@Subscribe @Subscribe
@ -1313,8 +1314,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
List<SubscribedSubredditData> favoriteSubscribedSubreddits; List<SubscribedSubredditData> favoriteSubscribedSubreddits;
List<SubscribedSubredditData> subscribedSubreddits; List<SubscribedSubredditData> subscribedSubreddits;
SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle, int tabCount, boolean showFavoriteSubscribedSubreddits, boolean showSubscribedSubreddits) { SectionsPagerAdapter(FragmentActivity fa, int tabCount, boolean showFavoriteSubscribedSubreddits, boolean showSubscribedSubreddits) {
super(fm, lifecycle); super(fa);
this.tabCount = tabCount; this.tabCount = tabCount;
favoriteSubscribedSubreddits = new ArrayList<>(); favoriteSubscribedSubreddits = new ArrayList<>();
subscribedSubreddits = new ArrayList<>(); subscribedSubreddits = new ArrayList<>();

View File

@ -22,6 +22,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
@ -528,11 +529,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
} }
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.startForegroundService(this, intent);
startForegroundService(intent);
} else {
startService(intent);
}
return true; return true;
} }

View File

@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; 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_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
startService(intent); ContextCompat.startForegroundService(this, intent);
return true; return true;
} }

View File

@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; 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_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
startService(intent); ContextCompat.startForegroundService(this, intent);
return true; return true;
} }

View File

@ -20,6 +20,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
@ -27,7 +28,7 @@ import com.bumptech.glide.request.RequestOptions;
import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer; 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.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
@ -424,7 +425,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
constraintLayout.setVisibility(View.GONE); constraintLayout.setVisibility(View.GONE);
selectAgainTextView.setVisibility(View.VISIBLE); selectAgainTextView.setVisibility(View.VISIBLE);
videoPlayerView.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); player.setPlayWhenReady(true);
wasPlaying = true; wasPlaying = true;
} }
@ -528,11 +529,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.startForegroundService(this, intent);
startForegroundService(intent);
} else {
startService(intent);
}
return true; return true;
} }

View File

@ -16,8 +16,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2; import androidx.viewpager2.widget.ViewPager2;
@ -221,7 +221,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
} }
private void initializeViewPager() { private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(3); viewPager2.setOffscreenPageLimit(3);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); 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 { private class SectionsPagerAdapter extends FragmentStateAdapter {
public SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { public SectionsPagerAdapter(FragmentActivity fa) {
super(fm, lifecycle); super(fa);
} }
@NonNull @NonNull

View File

@ -7,6 +7,7 @@ import android.view.MenuItem;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
@ -192,6 +193,6 @@ public class SettingsActivity extends BaseActivity implements
@Subscribe @Subscribe
public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) {
recreate(); ActivityCompat.recreate(this);
} }
} }

View File

@ -21,6 +21,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; 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_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_CROSSPOST); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_CROSSPOST);
startService(intent); ContextCompat.startForegroundService(this, intent);
return true; return true;
} }

View File

@ -283,7 +283,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
isDownloading = true; isDownloading = true;
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != 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_MEDIA_TYPE, isGif ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF : DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, mImageFileName); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, mImageFileName);
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, mSubredditName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, mSubredditName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.startForegroundService(this, intent);
startForegroundService(intent);
} else {
startService(intent);
}
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
} }

View File

@ -28,8 +28,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2; import androidx.viewpager2.widget.ViewPager2;
@ -842,7 +842,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
}).execute(); }).execute();
sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
@ -1233,8 +1233,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private class SectionsPagerAdapter extends FragmentStateAdapter { private class SectionsPagerAdapter extends FragmentStateAdapter {
SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { SectionsPagerAdapter(FragmentActivity fa) {
super(fm, lifecycle); super(fa);
} }
@NonNull @NonNull

View File

@ -31,8 +31,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2; import androidx.viewpager2.widget.ViewPager2;
@ -604,7 +604,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
} }
private void initializeViewPager() { private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle()); sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2); viewPager2.setOffscreenPageLimit(2);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); 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 { private class SectionsPagerAdapter extends FragmentStateAdapter {
SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { SectionsPagerAdapter(FragmentActivity fa) {
super(fm, lifecycle); super(fa);
} }
@NonNull @NonNull

View File

@ -419,7 +419,7 @@ public class ViewVideoActivity extends AppCompatActivity {
} }
isDownloading = true; isDownloading = true;
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
@ -472,29 +472,20 @@ public class ViewVideoActivity extends AppCompatActivity {
private void download() { private void download() {
isDownloading = false; isDownloading = false;
Intent intent;
if (videoType != VIDEO_TYPE_NORMAL) { 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_URL, videoDownloadUrl);
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO); intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, videoFileName); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, videoFileName);
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent);
} else {
startService(intent);
}
} else { } 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_VIDEO_URL, videoDownloadUrl);
intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id); intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id);
intent.putExtra(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName); 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(); Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
} }

View File

@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -49,7 +50,7 @@ public class SetAsWallpaperBottomSheetFragment extends RoundedBottomSheetDialogF
dismiss(); 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); homeScreenTextvView.setVisibility(View.VISIBLE);
lockScreenTextView.setVisibility(View.VISIBLE); lockScreenTextView.setVisibility(View.VISIBLE);

View File

@ -21,7 +21,8 @@ public class LollipopBugFixedWebView extends WebView{
// To fix Android Lollipop WebView problem create a new configuration on that Android version only // To fix Android Lollipop WebView problem create a new configuration on that Android version only
private static Context getFixedContext(Context context) { 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.createConfigurationContext(new Configuration());
return context; return context;
} }

View File

@ -157,7 +157,7 @@ public class ViewImgurImageFragment extends Fragment {
isDownloading = true; isDownloading = true;
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(activity, if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
@ -238,11 +238,7 @@ public class ViewImgurImageFragment extends Fragment {
intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink()); intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink());
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName()); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.startForegroundService(activity, intent);
activity.startForegroundService(intent);
} else {
activity.startService(intent);
}
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
} }

View File

@ -149,7 +149,7 @@ public class ViewImgurVideoFragment extends Fragment {
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_download_view_imgur_video_fragment) { if (item.getItemId() == R.id.action_download_view_imgur_video_fragment) {
isDownloading = true; isDownloading = true;
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(activity, if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
@ -189,11 +189,7 @@ public class ViewImgurVideoFragment extends Fragment {
intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink()); intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink());
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO); intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName()); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.startForegroundService(activity, intent);
activity.startForegroundService(intent);
} else {
activity.startService(intent);
}
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
} }

View File

@ -223,7 +223,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
isDownloading = true; isDownloading = true;
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(activity, if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != 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_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_FILE_NAME, media.fileName);
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.startForegroundService(activity, intent);
activity.startForegroundService(intent);
} else {
activity.startService(intent);
}
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
} }

View File

@ -152,7 +152,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_download_view_reddit_gallery_video_fragment) { if (item.getItemId() == R.id.action_download_view_reddit_gallery_video_fragment) {
isDownloading = true; isDownloading = true;
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(activity, if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != 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_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, galleryVideo.fileName); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, galleryVideo.fileName);
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.startForegroundService(activity, intent);
activity.startForegroundService(intent);
} else {
activity.startService(intent);
}
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
} }

View File

@ -142,7 +142,7 @@ public class DownloadMediaService extends Service {
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
String destinationFileDirectory = getDownloadLocation(mediaType); String destinationFileDirectory = getDownloadLocation(mediaType);
if (destinationFileDirectory.equals("")) { 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); File directory = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
if (directory != null) { if (directory != null) {
String directoryPath = separateDownloadFolder && subredditName != null && !subredditName.equals("") ? directory.getAbsolutePath() + "/Infinity/" + subredditName + "/" : directory.getAbsolutePath() + "/Infinity/"; 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 { int mediaType) throws IOException {
ContentResolver contentResolver = getContentResolver(); ContentResolver contentResolver = getContentResolver();
if (isDefaultDestination) { 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(); InputStream inputStream = body.byteStream();
OutputStream outputStream = new FileOutputStream(destinationFileUriString); OutputStream outputStream = new FileOutputStream(destinationFileUriString);
byte[] fileReader = new byte[4096]; byte[] fileReader = new byte[4096];

View File

@ -146,7 +146,7 @@ public class DownloadRedditVideoService extends Service {
String destinationFileUriString; String destinationFileUriString;
boolean isDefaultDestination; boolean isDefaultDestination;
if (destinationFileDirectory.equals("")) { 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); File destinationDirectory = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
if (destinationDirectory != null) { if (destinationDirectory != null) {
String destinationDirectoryPath = separateDownloadFolder ? destinationDirectory.getAbsolutePath() + "/Infinity/" + subredditName + "/" : destinationDirectory.getAbsolutePath() + "/Infinity/"; String destinationDirectoryPath = separateDownloadFolder ? destinationDirectory.getAbsolutePath() + "/Infinity/" + subredditName + "/" : destinationDirectory.getAbsolutePath() + "/Infinity/";
@ -396,7 +396,7 @@ public class DownloadRedditVideoService extends Service {
boolean isDefaultDestination) throws IOException { boolean isDefaultDestination) throws IOException {
ContentResolver contentResolver = getContentResolver(); ContentResolver contentResolver = getContentResolver();
if (isDefaultDestination) { 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); InputStream in = new FileInputStream(srcPath);
OutputStream out = new FileOutputStream(destinationFileUriString); OutputStream out = new FileOutputStream(destinationFileUriString);
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
@ -30,7 +31,7 @@ public class FontPreferenceFragment extends PreferenceFragmentCompat {
if (fontFamilyPreference != null) { if (fontFamilyPreference != null) {
fontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> { fontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new RecreateActivityEvent()); EventBus.getDefault().post(new RecreateActivityEvent());
activity.recreate(); ActivityCompat.recreate(activity);
return true; return true;
}); });
} }
@ -52,7 +53,7 @@ public class FontPreferenceFragment extends PreferenceFragmentCompat {
if (fontSizePreference != null) { if (fontSizePreference != null) {
fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new RecreateActivityEvent()); EventBus.getDefault().post(new RecreateActivityEvent());
activity.recreate(); ActivityCompat.recreate(activity);
return true; return true;
}); });
} }

View File

@ -9,6 +9,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
@ -109,7 +110,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> { amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) { if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) {
EventBus.getDefault().post(new RecreateActivityEvent()); EventBus.getDefault().post(new RecreateActivityEvent());
activity.recreate(); ActivityCompat.recreate(activity);
} }
return true; return true;
}); });

View File

@ -2,9 +2,9 @@ package ml.docilealligator.infinityforreddit.subreddit;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.facebook.common.internal.ImmutableMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.apis.RedditAPI;
@ -50,7 +50,8 @@ public class FetchSubredditData {
boolean nsfw, final FetchSubredditListingDataListener fetchSubredditListingDataListener) { boolean nsfw, final FetchSubredditListingDataListener fetchSubredditListingDataListener) {
RedditAPI api = retrofit.create(RedditAPI.class); RedditAPI api = retrofit.create(RedditAPI.class);
Map<String, String> headers = accessToken != null ? APIUtils.getOAuthHeader(accessToken) : ImmutableMap.of(); Map<String, String> map = new HashMap<>();
Map<String, String> headers = accessToken != null ? APIUtils.getOAuthHeader(accessToken) : Collections.unmodifiableMap(map);
Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw ? 1 : 0, headers); Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw ? 1 : 0, headers);
subredditDataCall.enqueue(new Callback<String>() { subredditDataCall.enqueue(new Callback<String>() {
@Override @Override

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.utils;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.os.Build;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; import androidx.core.app.NotificationManagerCompat;
@ -36,7 +37,7 @@ public class NotificationUtils {
Context context, String title, String content, Context context, String title, String content,
String summary, String channelId, String channelName, String summary, String channelId, String channelName,
String group, int color) { 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); NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
} }
@ -56,7 +57,7 @@ public class NotificationUtils {
public static NotificationCompat.Builder buildSummaryNotification(Context context, NotificationManagerCompat notificationManager, public static NotificationCompat.Builder buildSummaryNotification(Context context, NotificationManagerCompat notificationManager,
String title, String content, String channelId, String title, String content, String channelId,
String channelName, String group, int color) { 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); NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
} }

View File

@ -8,7 +8,6 @@ import android.net.Network;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Build; import android.os.Build;
import android.text.Html;
import android.text.Spannable; import android.text.Spannable;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -17,6 +16,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.text.HtmlCompat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
@ -135,13 +135,10 @@ public class Utils {
} }
public static void setHTMLWithImageToTextView(TextView textView, String content, boolean enlargeImage) { public static void setHTMLWithImageToTextView(TextView textView, String content, boolean enlargeImage) {
Spannable html;
GlideImageGetter glideImageGetter = new GlideImageGetter(textView, enlargeImage); GlideImageGetter glideImageGetter = new GlideImageGetter(textView, enlargeImage);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { Spannable html = (Spannable) HtmlCompat.fromHtml(
html = (Spannable) Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); content, HtmlCompat.FROM_HTML_MODE_LEGACY, glideImageGetter, null);
} else {
html = (Spannable) Html.fromHtml(content, glideImageGetter, null);
}
textView.setText(html); textView.setText(html);
} }

View File

@ -6,7 +6,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.android.tools.build:gradle:4.1.1'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

Binary file not shown.

View File

@ -1,6 +1,5 @@
#Wed Oct 14 22:46:37 CST 2020
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

2
gradlew vendored
View File

@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath # We build the pattern for arguments to be converted via cygpath

22
gradlew.bat vendored
View File

@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto execute
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@ -64,28 +64,14 @@ echo location of your Java installation.
goto fail goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell