aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-04-01 09:29:42 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-04-01 09:29:42 +0000
commitf0e2090db98722daec2a7dba295b8abf7d7a5514 (patch)
treeb6fac53cc1abf79ed3902fbd56634cda6a758fab /app
parent83b71b830402db198393970c2e75f1dc9a434d6f (diff)
downloadinfinity-for-reddit-f0e2090db98722daec2a7dba295b8abf7d7a5514.tar
infinity-for-reddit-f0e2090db98722daec2a7dba295b8abf7d7a5514.tar.gz
infinity-for-reddit-f0e2090db98722daec2a7dba295b8abf7d7a5514.tar.bz2
infinity-for-reddit-f0e2090db98722daec2a7dba295b8abf7d7a5514.tar.lz
infinity-for-reddit-f0e2090db98722daec2a7dba295b8abf7d7a5514.tar.xz
infinity-for-reddit-f0e2090db98722daec2a7dba295b8abf7d7a5514.tar.zst
infinity-for-reddit-f0e2090db98722daec2a7dba295b8abf7d7a5514.zip
Do not load subreddit data in SidebarFragment. Save subreddit data to the database in ViewSubredditDetailActivity.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java10
5 files changed, 15 insertions, 26 deletions
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 f63c1cd3..0f829906 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
@@ -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();
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
index d929aa0d..065dbf81 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -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);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
index 0b0c8465..1b701bfa 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
@@ -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() {
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 23d1ba30..9aa1f94e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java
@@ -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()) {
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 cc019ac4..604188b8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
@@ -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) {