Minor bugs fixed in ParsePost.

This commit is contained in:
Alex Ning 2021-12-03 21:04:19 +08:00
parent b0d9a15dfd
commit c809de6350
15 changed files with 25 additions and 25 deletions

View File

@ -269,7 +269,7 @@ public class LinkResolverActivity extends AppCompatActivity {
} else {
deepLinkError(uri);
}
} else if (authority.contains("google.com") ){
} else if (authority.contains("google.com")) {
if ( path.matches(GOOGLE_AMP_PATTERN) ) {
String url = path.substring(11, path.length()); // skipping past amp straight to reddit
handleUri(Uri.parse("https://" + url));

View File

@ -1175,7 +1175,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
.setNegativeButton(R.string.no, null)
.show();
return true;
} else if(itemId == R.id.action_edit_profile_view_user_detail_activity){
} else if (itemId == R.id.action_edit_profile_view_user_detail_activity) {
startActivity(new Intent(this, EditProfileActivity.class));
return true;
}

View File

@ -1908,7 +1908,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GIF_TYPE){
} else if (post.getPostType() == Post.GIF_TYPE) {
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".gif");

View File

@ -17,7 +17,7 @@ public class DeleteAllPostLayouts {
Map<String,?> keys = defaultSharedPreferences.getAll();
SharedPreferences.Editor editor = defaultSharedPreferences.edit();
for(Map.Entry<String,?> entry : keys.entrySet()){
for (Map.Entry<String,?> entry : keys.entrySet()) {
String key = entry.getKey();
if (key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE)
|| key.startsWith(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)

View File

@ -17,7 +17,7 @@ public class DeleteAllSortTypes {
Map<String,?> keys = defaultSharedPreferences.getAll();
SharedPreferences.Editor editor = defaultSharedPreferences.edit();
for(Map.Entry<String,?> entry : keys.entrySet()){
for (Map.Entry<String,?> entry : keys.entrySet()) {
String key = entry.getKey();
if (key.contains(SharedPreferencesUtils.SORT_TYPE_BEST_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_BEST_POST)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_ALL_POST_LEGACY) || key.contains(SharedPreferencesUtils.SORT_TIME_ALL_POST_LEGACY)

View File

@ -59,7 +59,7 @@ public class SortTimeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
}
String sortType = getArguments() != null ? getArguments().getString(EXTRA_SORT_TYPE) : null;
if(sortType == null) {
if (sortType == null) {
dismiss();
return rootView;
}

View File

@ -265,7 +265,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
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())) {
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 {

View File

@ -1260,8 +1260,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh());
showErrorView(R.string.load_posts_error);
}
if (!(refreshLoadState instanceof LoadState.Loading) // #563
&& appendLoadState instanceof LoadState.NotLoading) {
if (!(refreshLoadState instanceof LoadState.Loading) && appendLoadState instanceof LoadState.NotLoading) {
if (appendLoadState.getEndOfPaginationReached() && mAdapter.getItemCount() < 1) {
noPostFound();
}

View File

@ -292,7 +292,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
if (!captionUrlIsEmpty) {
String scheme = Uri.parse(captionUrl).getScheme();
String urlWithoutScheme = "";
if(!TextUtils.isEmpty(scheme)){
if (!TextUtils.isEmpty(scheme)) {
urlWithoutScheme = captionUrl.substring(scheme.length() + 3);
}
@ -330,7 +330,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
}
private void loadImage() {
if(isFallback) {
if (isFallback) {
imageView.showImage(Uri.parse(media.fallbackUrl));
}
else{

View File

@ -401,7 +401,7 @@ public class ParsePost {
previews.add(new Post.Preview(url, 0, 0, "", ""));
}
post.setPreviews(previews);
} else if (url.endsWith("gif")){
} else if (url.endsWith("gif")) {
//Gif post
int postType = Post.GIF_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
@ -564,15 +564,15 @@ public class ParsePost {
JSONObject galleryItem = galleryIdsArray.getJSONObject(i);
String galleryItemCaption = "";
String galleryItemCaptionUrl = "";
if(galleryItem.has(JSONUtils.CAPTION_KEY)){
if (galleryItem.has(JSONUtils.CAPTION_KEY)) {
galleryItemCaption = galleryItem.getString(JSONUtils.CAPTION_KEY).trim();
}
if(galleryItem.has(JSONUtils.CAPTION_URL_KEY)){
if (galleryItem.has(JSONUtils.CAPTION_URL_KEY)) {
galleryItemCaptionUrl = galleryItem.getString(JSONUtils.CAPTION_URL_KEY).trim();
}
if ((previews.isEmpty()) && mimeType.contains("jpg") || mimeType.contains("png")) {
if (previews.isEmpty() && (mimeType.contains("jpg") || mimeType.contains("png"))) {
previews.add(new Post.Preview(galleryItemUrl, singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.X_KEY),
singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY), galleryItemCaption, galleryItemCaptionUrl));
}
@ -581,7 +581,7 @@ public class ParsePost {
// For issue #558
// Construct a fallback image url
if(!TextUtils.isEmpty(galleryItemUrl) && !TextUtils.isEmpty(mimeType) && (mimeType.contains("jpg") || mimeType.contains("png"))) {
if (!TextUtils.isEmpty(galleryItemUrl) && !TextUtils.isEmpty(mimeType) && (mimeType.contains("jpg") || mimeType.contains("png"))) {
postGalleryItem.setFallbackUrl("https://i.redd.it/" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1));
postGalleryItem.setHasFallback(true);
}

View File

@ -214,7 +214,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
} else {
afterKey = loadParams.getKey();
}
if(sortType.getTime() != null) {
if (sortType.getTime() != null) {
bestPost = api.getBestPostsListenableFuture(sortType.getType().value, sortType.getTime().value, afterKey,
APIUtils.getOAuthHeader(accessToken));
} else {
@ -299,7 +299,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
searchPosts = api.searchPostsListenableFuture(query, loadParams.getKey(), sortType.getType().value, trendingSource);
}
} else {
if(sortType.getTime() != null) {
if (sortType.getTime() != null) {
searchPosts = api.searchPostsOauthListenableFuture(query, loadParams.getKey(), sortType.getType().value,
sortType.getTime().value, trendingSource, APIUtils.getOAuthHeader(accessToken));
} else {

View File

@ -114,7 +114,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
}
if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT);
} else {
if (amoledDarkSwitch.isChecked()) {

View File

@ -22,7 +22,7 @@ public class ParseUserData {
}
private static UserData parseUserDataBase(JSONObject userDataJson, boolean parseFullKarma) throws JSONException {
if(userDataJson == null) {
if (userDataJson == null) {
return null;
}

View File

@ -99,7 +99,7 @@ public class GlideImageGetter implements Html.ImageGetter {
@Override
public void onLoadStarted(@Nullable Drawable placeholderDrawable) {
if(placeholderDrawable != null) {
if (placeholderDrawable != null) {
setDrawable(placeholderDrawable);
}
}
@ -126,7 +126,7 @@ public class GlideImageGetter implements Html.ImageGetter {
@Override
public void onLoadCleared(@Nullable Drawable placeholderDrawable) {
if(placeholderDrawable != null) {
if (placeholderDrawable != null) {
setDrawable(placeholderDrawable);
}
}

View File

@ -150,8 +150,9 @@ public class Utils {
public static CharSequence trimTrailingWhitespace(CharSequence source) {
if(source == null)
if (source == null) {
return "";
}
int i = source.length();
@ -329,7 +330,7 @@ public class Utils {
}
}
public static float convertDpToPixel(float dp, Context context){
public static float convertDpToPixel(float dp, Context context) {
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
@ -392,7 +393,7 @@ public class Utils {
int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
cursor.moveToFirst();
String fileName = cursor.getString(nameIndex);
if(fileName != null && fileName.contains(".")) {
if (fileName != null && fileName.contains(".")) {
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
}
return fileName;