Merge new features from 4.2.3 to 4.2.5.

This commit is contained in:
Alex Ning 2021-02-12 19:21:34 +08:00
commit ff7281aa89
19 changed files with 217 additions and 119 deletions

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21
targetSdkVersion 30
versionCode 57
versionName "4.2.2"
versionCode 60
versionName "4.2.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
@ -32,6 +32,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
bundle {
language {
enableSplit = false
}
}
}
dependencies {

View File

@ -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;
}

View File

@ -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)

View File

@ -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 "";

View File

@ -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();
@ -231,6 +261,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

View File

@ -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;
}

View File

@ -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);
}

View File

@ -34,7 +34,7 @@ public class LoadSubredditIcon {
}
@Override
public void onFetchSubredditDataFail() {
public void onFetchSubredditDataFail(boolean isQuarantined) {
loadSubredditIconAsyncTaskListener.loadIconSuccess(null);
}
}));

View File

@ -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);
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());
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()));
}
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));
mCommentViewModel.hasComment().observe(getViewLifecycleOwner(), hasComment -> {
mSwipeRefreshLayout.setRefreshing(false);
if (hasComment) {
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
} else {
mFetchCommentInfoLinearLayout.setOnClickListener(view -> {
//Do nothing
});
showErrorView(R.string.no_comments);
}
});
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());
}
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));
mCommentViewModel.hasComment().observe(getViewLifecycleOwner(), hasComment -> {
mSwipeRefreshLayout.setRefreshing(false);
if (hasComment) {
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
} else {
mFetchCommentInfoLinearLayout.setOnClickListener(view -> {
//Do nothing
});
showErrorView(R.string.no_comments);
}
});
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());
}
public void changeSortType(SortType sortType) {

View File

@ -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();
}

View File

@ -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) {

View File

@ -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);
}
}
}

View File

@ -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();
}
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.containFlairs != null && !p.containFlairs.equals("")) {
stringBuilder = new StringBuilder(postFilter.containFlairs == null ? "" : postFilter.containFlairs);
stringBuilder.append(",").append(p.containFlairs);
postFilter.containFlairs = 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;

View File

@ -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 {

View File

@ -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 {

View File

@ -56,7 +56,7 @@ public class SubredditSubscription {
}
@Override
public void onFetchSubredditDataFail() {
public void onFetchSubredditDataFail(boolean isQuarantined) {
}
});

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"
android:fillColor="#ffffff"/>
</vector>

View File

@ -47,4 +47,12 @@
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_login_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_help_24dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1017,4 +1017,7 @@
<string name="choose_a_user">Choose a user</string>
<string name="have_trouble_login_title">Having Trouble Login</string>
<string name="have_trouble_login_message">Do you want to try another way to login?</string>
</resources>