aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-02-12 11:21:34 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-02-12 11:21:34 +0000
commitff7281aa890c43a21c90ec49c0e821e98956195a (patch)
tree4bd9f9d56ffc336aec84a31cf9cbf0453aabca6f /app/src/main/java
parentc0cb024eb99be74c36ea422df5731b09a0d5d570 (diff)
parent36a142f7b47cdc2dd707ec75c85dcb2998500fc7 (diff)
downloadinfinity-for-reddit-ff7281aa890c43a21c90ec49c0e821e98956195a.tar
infinity-for-reddit-ff7281aa890c43a21c90ec49c0e821e98956195a.tar.gz
infinity-for-reddit-ff7281aa890c43a21c90ec49c0e821e98956195a.tar.bz2
infinity-for-reddit-ff7281aa890c43a21c90ec49c0e821e98956195a.tar.lz
infinity-for-reddit-ff7281aa890c43a21c90ec49c0e821e98956195a.tar.xz
infinity-for-reddit-ff7281aa890c43a21c90ec49c0e821e98956195a.tar.zst
infinity-for-reddit-ff7281aa890c43a21c90ec49c0e821e98956195a.zip
Merge new features from 4.2.3 to 4.2.5.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java131
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java61
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java2
15 files changed, 186 insertions, 114 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java
index 8221b612..1ac3b368 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit;
+import android.content.SharedPreferences;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -13,6 +15,7 @@ import java.util.Map;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import okhttp3.Authenticator;
import okhttp3.Headers;
import okhttp3.Request;
@@ -24,10 +27,12 @@ import retrofit2.Retrofit;
class AccessTokenAuthenticator implements Authenticator {
private Retrofit mRetrofit;
private RedditDataRoomDatabase mRedditDataRoomDatabase;
+ private SharedPreferences mCurrentAccountSharedPreferences;
- AccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) {
+ AccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase, SharedPreferences currentAccountSharedPreferences) {
mRetrofit = retrofit;
mRedditDataRoomDatabase = accountRoomDatabase;
+ mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
}
@Nullable
@@ -77,6 +82,9 @@ class AccessTokenAuthenticator implements Authenticator {
} else {
mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getAccountName(), newAccessToken, newRefreshToken);
}
+ if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "").equals(account.getAccountName())) {
+ mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply();
+ }
return newAccessToken;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index 83cc3515..82796cec 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -144,9 +144,10 @@ class AppModule {
@Provides
@Singleton
- OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) {
+ OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase,
+ @Named("current_account") SharedPreferences currentAccountSharedPreferences) {
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
- okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, accountRoomDatabase))
+ okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, accountRoomDatabase, currentAccountSharedPreferences))
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
index a0017f1c..44668b13 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
@@ -56,6 +56,9 @@ public class PullNotificationWorker extends Worker {
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("current_account")
+ SharedPreferences mCurrentAccountSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
private Context context;
@@ -255,6 +258,9 @@ public class PullNotificationWorker extends Worker {
} else {
mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getAccountName(), newAccessToken, newRefreshToken);
}
+ if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "").equals(account.getAccountName())) {
+ mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply();
+ }
return newAccessToken;
}
return "";
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java
index 3fb9010e..21f49973 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java
@@ -11,6 +11,7 @@ import android.os.Handler;
import android.util.Log;
import android.view.InflateException;
import android.view.MenuItem;
+import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@@ -20,8 +21,11 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.core.app.ActivityCompat;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.r0adkll.slidr.Slidr;
import org.json.JSONException;
@@ -53,6 +57,8 @@ import retrofit2.Retrofit;
public class LoginActivity extends BaseActivity {
+ private static final String ENABLE_DOM_STATE = "EDS";
+
@BindView(R.id.coordinator_layout_login_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_login_activity)
@@ -63,6 +69,8 @@ public class LoginActivity extends BaseActivity {
TextView twoFAInfoTextView;
@BindView(R.id.webview_login_activity)
WebView webView;
+ @BindView(R.id.fab_login_activity)
+ FloatingActionButton fab;
@Inject
@Named("no_oauth")
Retrofit mRetrofit;
@@ -82,6 +90,7 @@ public class LoginActivity extends BaseActivity {
@Inject
Executor mExecutor;
private String authCode;
+ private boolean enableDom = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -112,7 +121,28 @@ public class LoginActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ if (savedInstanceState != null) {
+ enableDom = savedInstanceState.getBoolean(ENABLE_DOM_STATE);
+ }
+
+ fab.setOnClickListener(view -> {
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.have_trouble_login_title)
+ .setMessage(R.string.have_trouble_login_message)
+ .setPositiveButton(R.string.yes, (dialogInterface, i) -> {
+ enableDom = !enableDom;
+ ActivityCompat.recreate(this);
+ })
+ .setNegativeButton(R.string.no, null)
+ .show();
+ });
+
+ if (enableDom) {
+ twoFAInfoTextView.setVisibility(View.GONE);
+ }
+
webView.getSettings().setJavaScriptEnabled(true);
+ webView.getSettings().setDomStorageEnabled(enableDom);
Uri baseUri = Uri.parse(APIUtils.OAUTH_URL);
Uri.Builder uriBuilder = baseUri.buildUpon();
@@ -232,6 +262,12 @@ public class LoginActivity extends BaseActivity {
}
@Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(ENABLE_DOM_STATE, enableDom);
+ }
+
+ @Override
public SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@@ -248,6 +284,7 @@ public class LoginActivity extends BaseActivity {
twoFAInfoTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
Drawable infoDrawable = Utils.getTintedDrawable(this, R.drawable.ic_info_preference_24dp, mCustomThemeWrapper.getPrimaryIconColor());
twoFAInfoTextView.setCompoundDrawablesWithIntrinsicBounds(infoDrawable, null, null, null);
+ applyFABTheme(fab);
}
@Override
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 af97a15d..e076a293 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
@@ -520,7 +520,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
@Override
- public void onFetchSubredditDataFail() {
+ public void onFetchSubredditDataFail(boolean isQuarantined) {
makeSnackbar(R.string.cannot_fetch_subreddit_info, true);
mFetchSubredditInfoSuccess = false;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
index 1799ff57..67da922d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
@@ -346,4 +346,7 @@ public interface RedditAPI {
Call<String> addSubredditToMultiReddit(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params,
@Path(value = "multipath", encoded = true) String multipath, @Path("subredditName") String subredditName);
+ @FormUrlEncoded
+ @POST("/api/quarantine_optin?raw_json=1")
+ Call<String> optInQuarantinedSubreddit(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java
index 1d382255..0e1c981c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java
@@ -34,7 +34,7 @@ public class LoadSubredditIcon {
}
@Override
- public void onFetchSubredditDataFail() {
+ public void onFetchSubredditDataFail(boolean isQuarantined) {
loadSubredditIconAsyncTaskListener.loadIconSuccess(null);
}
}));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
index 9183fc1a..c730b4ba 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
@@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.View;
@@ -247,86 +248,88 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
- bindView(resources);
+ new Handler().postDelayed(() -> bindView(resources), 0);
return rootView;
}
private void bindView(Resources resources) {
- mLinearLayoutManager = new LinearLayoutManager(mActivity);
- mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
-
- mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper,
- getResources().getConfiguration().locale, mSharedPreferences,
- getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
- () -> mCommentViewModel.retryLoadingMore());
-
- String username = getArguments().getString(EXTRA_USERNAME);
- String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.name());
- if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
- String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.name());
- sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
- } else {
- sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
- }
+ if (mActivity != null && !mActivity.isFinishing() && !mActivity.isDestroyed()) {
+ mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
+
+ mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper,
+ getResources().getConfiguration().locale, mSharedPreferences,
+ getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
+ () -> mCommentViewModel.retryLoadingMore());
+
+ String username = getArguments().getString(EXTRA_USERNAME);
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.name());
+ if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
+ String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.name());
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
+ } else {
+ sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
+ }
- mCommentRecyclerView.setAdapter(mAdapter);
+ mCommentRecyclerView.setAdapter(mAdapter);
- if (mActivity instanceof RecyclerViewContentScrollingInterface) {
- mCommentRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
- if (dy > 0) {
- ((RecyclerViewContentScrollingInterface) mActivity).contentScrollDown();
- } else if (dy < 0) {
- ((RecyclerViewContentScrollingInterface) mActivity).contentScrollUp();
+ if (mActivity instanceof RecyclerViewContentScrollingInterface) {
+ mCommentRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ if (dy > 0) {
+ ((RecyclerViewContentScrollingInterface) mActivity).contentScrollDown();
+ } else if (dy < 0) {
+ ((RecyclerViewContentScrollingInterface) mActivity).contentScrollUp();
+ }
}
- }
- });
- }
-
- CommentViewModel.Factory factory;
-
- if (mAccessToken == null) {
- factory = new CommentViewModel.Factory(mRetrofit,
- resources.getConfiguration().locale, null, username, sortType,
- getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
- } else {
- factory = new CommentViewModel.Factory(mOauthRetrofit,
- resources.getConfiguration().locale, mAccessToken, username, sortType,
- getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
- }
+ });
+ }
- mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class);
- mCommentViewModel.getComments().observe(getViewLifecycleOwner(), comments -> mAdapter.submitList(comments));
+ CommentViewModel.Factory factory;
- mCommentViewModel.hasComment().observe(getViewLifecycleOwner(), hasComment -> {
- mSwipeRefreshLayout.setRefreshing(false);
- if (hasComment) {
- mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
+ if (mAccessToken == null) {
+ factory = new CommentViewModel.Factory(mRetrofit,
+ resources.getConfiguration().locale, null, username, sortType,
+ getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
} else {
- mFetchCommentInfoLinearLayout.setOnClickListener(view -> {
- //Do nothing
- });
- showErrorView(R.string.no_comments);
+ factory = new CommentViewModel.Factory(mOauthRetrofit,
+ resources.getConfiguration().locale, mAccessToken, username, sortType,
+ getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
}
- });
- mCommentViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> {
- if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
- mSwipeRefreshLayout.setRefreshing(false);
- } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class);
+ mCommentViewModel.getComments().observe(getViewLifecycleOwner(), comments -> mAdapter.submitList(comments));
+
+ mCommentViewModel.hasComment().observe(getViewLifecycleOwner(), hasComment -> {
mSwipeRefreshLayout.setRefreshing(false);
- mFetchCommentInfoLinearLayout.setOnClickListener(view -> refresh());
- showErrorView(R.string.load_comments_failed);
- } else {
- mSwipeRefreshLayout.setRefreshing(true);
- }
- });
+ if (hasComment) {
+ mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
+ } else {
+ mFetchCommentInfoLinearLayout.setOnClickListener(view -> {
+ //Do nothing
+ });
+ showErrorView(R.string.no_comments);
+ }
+ });
- mCommentViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> mAdapter.setNetworkState(networkState));
+ mCommentViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> {
+ if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
+ mSwipeRefreshLayout.setRefreshing(false);
+ } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mSwipeRefreshLayout.setRefreshing(false);
+ mFetchCommentInfoLinearLayout.setOnClickListener(view -> refresh());
+ showErrorView(R.string.load_comments_failed);
+ } else {
+ mSwipeRefreshLayout.setRefreshing(true);
+ }
+ });
+
+ mCommentViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> mAdapter.setNetworkState(networkState));
- mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh());
+ mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh());
+ }
}
public void changeSortType(SortType sortType) {
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 c9550531..0e76c543 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
@@ -199,7 +199,7 @@ public class SidebarFragment extends Fragment {
}
@Override
- public void onFetchSubredditDataFail() {
+ public void onFetchSubredditDataFail(boolean isQuarantined) {
swipeRefreshLayout.setRefreshing(false);
Toast.makeText(activity, R.string.cannot_fetch_sidebar, Toast.LENGTH_SHORT).show();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index 18b95b8b..f4f6e49c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -1200,7 +1200,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
@Override
- public void onFetchSubredditDataFail() {
+ public void onFetchSubredditDataFail(boolean isQuarantined) {
mRespectSubredditRecommendedSortType = false;
ViewPostDetailFragment.this.sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value.toUpperCase());
if (ViewPostDetailFragment.this.sortType != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
index 809f0806..2ba685eb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -403,7 +403,7 @@ public class ParsePost {
if (gfycatId.contains("-")) {
gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
}
- post.setGfycatId(gfycatId);
+ post.setGfycatId(gfycatId.toLowerCase());
} else if (authority != null && authority.contains("redgifs.com")) {
String gfycatId = url.substring(url.lastIndexOf("/") + 1);
if (gfycatId.contains("-")) {
@@ -411,7 +411,7 @@ public class ParsePost {
}
post.setIsRedgifs(true);
post.setVideoUrl(url);
- post.setGfycatId(gfycatId);
+ post.setGfycatId(gfycatId.toLowerCase());
}
} catch (IllegalArgumentException ignore) { }
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
@@ -449,16 +449,21 @@ public class ParsePost {
} else if (post.getPostType() == Post.LINK_TYPE) {
Uri uri = Uri.parse(url);
String authority = uri.getAuthority();
+
+ // Gyfcat ids must be lowercase to resolve to a video through the api, we are not
+ // guaranteed to get an id that is all lowercase.
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+
if (authority != null && (authority.contains("gfycat.com"))) {
post.setPostType(Post.VIDEO_TYPE);
post.setIsGfycat(true);
post.setVideoUrl(url);
- post.setGfycatId(url.substring(url.lastIndexOf("/") + 1));
+ post.setGfycatId(gfycatId);
} else if (authority != null && authority.contains("redgifs.com")) {
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(url);
- post.setGfycatId(url.substring(url.lastIndexOf("/") + 1));
+ post.setGfycatId(gfycatId);
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java
index 9c8dbcc8..99d40536 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java
@@ -170,7 +170,7 @@ public class PostFilter implements Parcelable {
if (postFilter.postTitleExcludesStrings != null && !postFilter.postTitleExcludesStrings.equals("")) {
String[] titles = postFilter.postTitleExcludesStrings.split(",", 0);
for (String t : titles) {
- if (!t.equals("") && post.getTitle().toLowerCase().contains(t.toLowerCase())) {
+ if (!t.trim().equals("") && post.getTitle().toLowerCase().contains(t.toLowerCase().trim())) {
return false;
}
}
@@ -178,7 +178,7 @@ public class PostFilter implements Parcelable {
if (postFilter.excludeSubreddits != null && !postFilter.excludeSubreddits.equals("")) {
String[] subreddits = postFilter.excludeSubreddits.split(",", 0);
for (String s : subreddits) {
- if (!s.equals("") && post.getSubredditName().equalsIgnoreCase(s)) {
+ if (!s.trim().equals("") && post.getSubredditName().equalsIgnoreCase(s.trim())) {
return false;
}
}
@@ -186,7 +186,7 @@ public class PostFilter implements Parcelable {
if (postFilter.excludeUsers != null && !postFilter.excludeUsers.equals("")) {
String[] users = postFilter.excludeUsers.split(",", 0);
for (String u : users) {
- if (!u.equals("") && post.getAuthor().equalsIgnoreCase(u)) {
+ if (!u.trim().equals("") && post.getAuthor().equalsIgnoreCase(u.trim())) {
return false;
}
}
@@ -194,7 +194,7 @@ public class PostFilter implements Parcelable {
if (postFilter.excludeFlairs != null && !postFilter.excludeFlairs.equals("")) {
String[] flairs = postFilter.excludeFlairs.split(",", 0);
for (String f : flairs) {
- if (!f.equals("") && post.getFlair().equalsIgnoreCase(f)) {
+ if (!f.trim().equals("") && post.getFlair().equalsIgnoreCase(f.trim())) {
return false;
}
}
@@ -202,7 +202,7 @@ public class PostFilter implements Parcelable {
if (postFilter.containFlairs != null && !postFilter.containFlairs.equals("")) {
String[] flairs = postFilter.containFlairs.split(",", 0);
for (String f : flairs) {
- if (!f.equals("") && post.getFlair().equalsIgnoreCase(f)) {
+ if (!f.trim().equals("") && post.getFlair().equalsIgnoreCase(f.trim())) {
return false;
}
}
@@ -212,10 +212,10 @@ public class PostFilter implements Parcelable {
}
public static PostFilter mergePostFilter(List<PostFilter> postFilterList) {
- PostFilter postFilter = new PostFilter();
if (postFilterList.size() == 1) {
return postFilterList.get(0);
}
+ PostFilter postFilter = new PostFilter();
StringBuilder stringBuilder;
postFilter.name = "Merged";
for (PostFilter p : postFilterList) {
@@ -229,30 +229,39 @@ public class PostFilter implements Parcelable {
postFilter.onlyNSFW = p.onlyNSFW ? p.onlyNSFW : postFilter.onlyNSFW;
postFilter.onlySpoiler = p.onlySpoiler ? p.onlySpoiler : postFilter.onlySpoiler;
- postFilter.postTitleExcludesRegex = p.postTitleExcludesRegex.equals("") ? postFilter.postTitleExcludesRegex : p.postTitleExcludesRegex;
- stringBuilder = new StringBuilder(postFilter.postTitleExcludesStrings);
- stringBuilder.append(",").append(p.postTitleExcludesStrings);
- postFilter.postTitleExcludesStrings = stringBuilder.toString();
+ if (p.postTitleExcludesRegex != null && !p.postTitleExcludesRegex.equals("")) {
+ postFilter.postTitleExcludesRegex = p.postTitleExcludesRegex;
+ }
- postFilter.excludeSubreddits = p.excludeSubreddits.equals("") ? postFilter.excludeSubreddits : p.postTitleExcludesRegex;
- stringBuilder = new StringBuilder(postFilter.excludeSubreddits);
- stringBuilder.append(",").append(p.excludeSubreddits);
- postFilter.excludeSubreddits = stringBuilder.toString();
+ if (p.postTitleExcludesStrings != null && !p.postTitleExcludesStrings.equals("")) {
+ stringBuilder = new StringBuilder(postFilter.postTitleExcludesStrings == null ? "" : postFilter.postTitleExcludesStrings);
+ stringBuilder.append(",").append(p.postTitleExcludesStrings);
+ postFilter.postTitleExcludesStrings = stringBuilder.toString();
+ }
- postFilter.excludeUsers = p.excludeUsers.equals("") ? postFilter.excludeUsers : p.postTitleExcludesRegex;
- stringBuilder = new StringBuilder(postFilter.excludeUsers);
- stringBuilder.append(",").append(p.excludeUsers);
- postFilter.excludeUsers = stringBuilder.toString();
+ if (p.excludeSubreddits != null && !p.excludeSubreddits.equals("")) {
+ stringBuilder = new StringBuilder(postFilter.excludeSubreddits == null ? "" : postFilter.excludeSubreddits);
+ stringBuilder.append(",").append(p.excludeSubreddits);
+ postFilter.excludeSubreddits = stringBuilder.toString();
+ }
- postFilter.containFlairs = p.containFlairs.equals("") ? postFilter.containFlairs : p.postTitleExcludesRegex;
- stringBuilder = new StringBuilder(postFilter.containFlairs);
- stringBuilder.append(",").append(p.containFlairs);
- postFilter.containFlairs = stringBuilder.toString();
+ if (p.excludeUsers != null && !p.excludeUsers.equals("")) {
+ stringBuilder = new StringBuilder(postFilter.excludeUsers == null ? "" : postFilter.excludeUsers);
+ stringBuilder.append(",").append(p.excludeUsers);
+ postFilter.excludeUsers = stringBuilder.toString();
+ }
+
+ if (p.containFlairs != null && !p.containFlairs.equals("")) {
+ stringBuilder = new StringBuilder(postFilter.containFlairs == null ? "" : postFilter.containFlairs);
+ stringBuilder.append(",").append(p.containFlairs);
+ postFilter.containFlairs = stringBuilder.toString();
+ }
- postFilter.excludeFlairs = p.excludeFlairs.equals("") ? postFilter.excludeFlairs : p.postTitleExcludesRegex;
- stringBuilder = new StringBuilder(postFilter.excludeFlairs);
- stringBuilder.append(",").append(p.excludeFlairs);
- postFilter.excludeFlairs = stringBuilder.toString();
+ if (p.excludeFlairs != null && !p.excludeFlairs.equals("")) {
+ stringBuilder = new StringBuilder(postFilter.excludeFlairs == null ? "" : postFilter.excludeFlairs);
+ stringBuilder.append(",").append(p.excludeFlairs);
+ postFilter.excludeFlairs = stringBuilder.toString();
+ }
postFilter.containTextType = p.containTextType || postFilter.containTextType;
postFilter.containLinkType = p.containLinkType || postFilter.containLinkType;
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 73839464..f1b9633e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
@@ -25,6 +25,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.provider.MediaStore;
+import android.util.Log;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
@@ -207,17 +208,18 @@ public class DownloadRedditVideoService extends Service {
updateNotification(R.string.downloading_reddit_video_audio_track, 0,
randomNotificationIdOffset, null);
+ String videoFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp4";
+ String savedVideoFilePath = writeResponseBodyToDisk(videoResponse.body(), videoFilePath);
+ if (savedVideoFilePath == null) {
+ downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
+ return;
+ }
+
Response<ResponseBody> audioResponse = downloadFile.downloadFile(audioUrl).execute();
if (audioResponse.isSuccessful() && audioResponse.body() != null) {
- String videoFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp4";
String audioFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp3";
String outputFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + ".mp4";
- String savedVideoFilePath = writeResponseBodyToDisk(videoResponse.body(), videoFilePath);
- if (savedVideoFilePath == null) {
- downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
- return;
- }
String savedAudioFilePath = writeResponseBodyToDisk(audioResponse.body(), audioFilePath);
if (savedAudioFilePath == null) {
downloadFinished(null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
@@ -246,8 +248,6 @@ public class DownloadRedditVideoService extends Service {
downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
}
} else {
- String videoFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp4";
-
updateNotification(R.string.downloading_reddit_video_save_file_to_public_dir, -1,
randomNotificationIdOffset, null);
try {
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 37587ede..b5e9b553 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java
@@ -31,17 +31,17 @@ public class FetchSubredditData {
@Override
public void onParseSubredditDataFail() {
- fetchSubredditDataListener.onFetchSubredditDataFail();
+ fetchSubredditDataListener.onFetchSubredditDataFail(false);
}
});
} else {
- fetchSubredditDataListener.onFetchSubredditDataFail();
+ fetchSubredditDataListener.onFetchSubredditDataFail(response.code() == 403);
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- fetchSubredditDataListener.onFetchSubredditDataFail();
+ fetchSubredditDataListener.onFetchSubredditDataFail(false);
}
});
}
@@ -84,7 +84,7 @@ public class FetchSubredditData {
public interface FetchSubredditDataListener {
void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers);
- void onFetchSubredditDataFail();
+ void onFetchSubredditDataFail(boolean isQuarantined);
}
interface FetchSubredditListingDataListener {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java
index 52664234..31615903 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java
@@ -56,7 +56,7 @@ public class SubredditSubscription {
}
@Override
- public void onFetchSubredditDataFail() {
+ public void onFetchSubredditDataFail(boolean isQuarantined) {
}
});