Use application context for Glide

This commit is contained in:
Balazs Toldi 2023-08-18 23:35:07 +02:00
parent db9edc47c0
commit 0f3197d7e4
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
17 changed files with 37 additions and 38 deletions

View File

@ -204,7 +204,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
builder.linkColor(linkColor);
}
};
Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(getApplication(),
miscPlugin, parentTextColor, parentSpoilerBackgroundColor, null);
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
binding.commentContentMarkdownView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
@ -226,7 +226,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
setSupportActionBar(binding.commentToolbar);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
if (savedInstanceState != null) {
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);

View File

@ -172,7 +172,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
contentEditText.setText(mPost.getSelfText());
linkEditText.setText(mPost.getUrl());
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
if (mPost.getUrl() != null && mPost.getUrl().matches(picturePattern)) {
loadImage();
@ -354,7 +354,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
Uri imageUri = data.getData();
mExecutor.execute(() -> {
try {
Bitmap bitmap = Glide.with(this).asBitmap().load(imageUri).submit().get();
Bitmap bitmap = Glide.with(getApplication()).asBitmap().load(imageUri).submit().get();
String imageUrlOrError = UploadImageUtils.uploadImage(mRetrofit, mAccessToken, bitmap);
handler.post(() -> {
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {

View File

@ -38,7 +38,6 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
@ -52,6 +51,7 @@ import eu.toldi.infinityforlemmy.user.UserViewModel;
import eu.toldi.infinityforlemmy.utils.EditProfileUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@ -135,7 +135,7 @@ public class EditProfileActivity extends BaseActivity {
startPickImage(PICK_IMAGE_AVATAR_REQUEST_CODE);
});
final RequestManager glide = Glide.with(this);
final RequestManager glide = Glide.with(getApplication());
final UserViewModel.Factory userViewModelFactory =
new UserViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName);
final UserViewModel userViewModel =

View File

@ -29,12 +29,6 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
@ -45,6 +39,12 @@ import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
public class FullMarkdownActivity extends BaseActivity {
@ -138,7 +138,7 @@ public class FullMarkdownActivity extends BaseActivity {
builder.linkColor(linkColor);
}
};
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this,
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(getApplication(),
miscPlugin, markdownColor, spoilerBackgroundColor, null);
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();

View File

@ -214,7 +214,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);

View File

@ -228,7 +228,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);

View File

@ -217,7 +217,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);

View File

@ -219,7 +219,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);

View File

@ -208,7 +208,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);

View File

@ -216,7 +216,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
player = new ExoPlayer.Builder(this).build();
videoPlayerView.setPlayer(player);

View File

@ -204,7 +204,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);

View File

@ -127,7 +127,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
mSwipeRefreshLayout.setEnabled(false);

View File

@ -152,7 +152,7 @@ public class TrendingActivity extends BaseActivity {
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
@ -201,7 +201,7 @@ public class TrendingActivity extends BaseActivity {
isRefreshing = true;
errorLinearLayout.setVisibility(View.GONE);
Glide.with(this).clear(errorImageView);
Glide.with(getApplication()).clear(errorImageView);
swipeRefreshLayout.setRefreshing(true);
trendingSearches = null;
adapter.setTrendingSearches(null);

View File

@ -161,7 +161,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
Slidr.attach(this, new SlidrConfig.Builder().position(SlidrPosition.VERTICAL).distanceThreshold(0.125f).build());
}
glide = Glide.with(this);
glide = Glide.with(getApplication());
handler = new Handler();

View File

@ -506,7 +506,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
setSupportActionBar(toolbar);
setToolbarGoToTop(toolbar);
glide = Glide.with(this);
glide = Glide.with(getApplication());
Locale locale = getResources().getConfiguration().locale;
MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() {

View File

@ -434,7 +434,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
});
}
glide = Glide.with(this);
glide = Glide.with(getApplication());
Locale locale = getResources().getConfiguration().locale;
MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() {

View File

@ -35,16 +35,9 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.bottomsheetfragments.UrlMenuBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
@ -57,10 +50,16 @@ import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.utils.JSONUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
public class WikiActivity extends BaseActivity {
@ -139,7 +138,7 @@ public class WikiActivity extends BaseActivity {
}
}
mGlide = Glide.with(this);
mGlide = Glide.with(getApplication());
swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
swipeRefreshLayout.setOnRefreshListener(this::loadWiki);
@ -176,7 +175,7 @@ public class WikiActivity extends BaseActivity {
urlMenuBottomSheetFragment.show(getSupportFragmentManager(), null);
return true;
};
markwon = MarkdownUtils.createFullRedditMarkwon(this,
markwon = MarkdownUtils.createFullRedditMarkwon(getApplication(),
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
markwonAdapter = MarkdownUtils.createTablesAdapter();
@ -219,7 +218,7 @@ public class WikiActivity extends BaseActivity {
swipeRefreshLayout.setRefreshing(true);
Glide.with(this).clear(mFetchWikiInfoImageView);
Glide.with(getApplication()).clear(mFetchWikiInfoImageView);
mFetchWikiInfoLinearLayout.setVisibility(View.GONE);
retrofit.getRetrofit().create(RedditAPI.class).getWikiPage(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME), getIntent().getStringExtra(EXTRA_WIKI_PATH)).enqueue(new Callback<String>() {