mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 19:38:22 +01:00
Do not load subreddit data in SidebarFragment. Save subreddit data to the database in ViewSubredditDetailActivity.
This commit is contained in:
parent
83b71b8304
commit
f0e2090db9
@ -248,7 +248,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
private int fabOption;
|
||||
private SlidrInterface mSlidrInterface;
|
||||
private MaterialAlertDialogBuilder nsfwWarningBuilder;
|
||||
private boolean isOnCreateActivity;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -371,7 +370,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
|
||||
checkNewAccountAndBindView();
|
||||
|
||||
isOnCreateActivity = true;
|
||||
fetchSubredditData();
|
||||
|
||||
String title = "r/" + subredditName;
|
||||
@ -602,13 +600,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
|
||||
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers));
|
||||
if (isOnCreateActivity) {
|
||||
mFetchSubredditInfoSuccess = true;
|
||||
isOnCreateActivity = false;
|
||||
} else {
|
||||
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
subredditData, () -> mFetchSubredditInfoSuccess = true);
|
||||
}
|
||||
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
subredditData, () -> mFetchSubredditInfoSuccess = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1619,14 +1612,16 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
|
||||
public void refresh(boolean refreshSubredditData) {
|
||||
Fragment fragment = getCurrentFragment();
|
||||
Fragment fragment = fragmentManager.findFragmentByTag("f0");
|
||||
if (fragment instanceof PostFragment) {
|
||||
((PostFragment) fragment).refresh();
|
||||
if (refreshSubredditData) {
|
||||
mFetchSubredditInfoSuccess = false;
|
||||
fetchSubredditData();
|
||||
}
|
||||
} else if (fragment instanceof SidebarFragment) {
|
||||
}
|
||||
fragment = fragmentManager.findFragmentByTag("f1");
|
||||
if (fragment instanceof SidebarFragment) {
|
||||
((SidebarFragment) fragment).fetchSubredditData();
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -39,7 +38,6 @@ import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestBuilder;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.DecodeFormat;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
@ -1556,9 +1554,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
url = preview.getPreviewUrl();
|
||||
}
|
||||
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(((PostWithPreviewTypeViewHolder) holder).glideRequestListener);
|
||||
if (post.getAuthor().startsWith("GLIBG10")) {
|
||||
Log.i("sssssaffd", "s " + url + " " + ((PostWithPreviewTypeViewHolder) holder).imageView.getRatio());
|
||||
}
|
||||
if (blurImage) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostWithPreviewTypeViewHolder) holder).imageView);
|
||||
|
@ -48,7 +48,6 @@ import me.saket.bettermovementmethod.BetterLinkMovementMethod;
|
||||
import ml.docilealligator.infinityforreddit.Infinity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
|
||||
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
|
||||
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
|
||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData;
|
||||
@ -84,7 +83,7 @@ public class SidebarFragment extends Fragment {
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
private BaseActivity activity;
|
||||
private ViewSubredditDetailActivity activity;
|
||||
private String mAccessToken;
|
||||
private String subredditName;
|
||||
private LinearLayoutManagerBugFixed linearLayoutManager;
|
||||
@ -199,7 +198,7 @@ public class SidebarFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
mSubredditViewModel = new ViewModelProvider(this,
|
||||
mSubredditViewModel = new ViewModelProvider(activity,
|
||||
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, subredditName))
|
||||
.get(SubredditViewModel.class);
|
||||
mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
|
||||
@ -222,7 +221,7 @@ public class SidebarFragment extends Fragment {
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
activity = (BaseActivity) context;
|
||||
activity = (ViewSubredditDetailActivity) context;
|
||||
}
|
||||
|
||||
public void fetchSubredditData() {
|
||||
|
@ -27,7 +27,7 @@ public class FetchSubredditData {
|
||||
RedditAPI oauthApi = oauthRetrofit.create(RedditAPI.class);
|
||||
subredditData = oauthApi.getSubredditDataOauth(subredditName, APIUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
subredditData.enqueue(new Callback<String>() {
|
||||
subredditData.enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
|
@ -105,15 +105,15 @@ public final class Utils {
|
||||
StringBuilder regexed = new StringBuilder(regexedMarkdown);
|
||||
boolean hasBracket = false;
|
||||
int nCarets = 0;
|
||||
int new_lines = 0;
|
||||
int newLines = 0;
|
||||
for (int i = 0; i < regexed.length(); i++) {
|
||||
char currentChar = regexed.charAt(i);
|
||||
if (hasBracket && currentChar == '\n') {
|
||||
new_lines++;
|
||||
if (new_lines > 1) {
|
||||
newLines++;
|
||||
if (newLines > 1) {
|
||||
hasBracket = false;
|
||||
nCarets = 0;
|
||||
new_lines = 0;
|
||||
newLines = 0;
|
||||
}
|
||||
} else if (currentChar == '^') {
|
||||
if (!(i > 0 && regexed.charAt(i - 1) == '\\')) {
|
||||
@ -147,7 +147,7 @@ public final class Utils {
|
||||
}
|
||||
nCarets = 0;
|
||||
} else {
|
||||
new_lines = 0;
|
||||
newLines = 0;
|
||||
}
|
||||
}
|
||||
if (!hasBracket) {
|
||||
|
Loading…
Reference in New Issue
Block a user