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 { } else {
deepLinkError(uri); deepLinkError(uri);
} }
} else if (authority.contains("google.com") ){ } else if (authority.contains("google.com")) {
if ( path.matches(GOOGLE_AMP_PATTERN) ) { if ( path.matches(GOOGLE_AMP_PATTERN) ) {
String url = path.substring(11, path.length()); // skipping past amp straight to reddit String url = path.substring(11, path.length()); // skipping past amp straight to reddit
handleUri(Uri.parse("https://" + url)); handleUri(Uri.parse("https://" + url));

View File

@ -1175,7 +1175,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
.setNegativeButton(R.string.no, null) .setNegativeButton(R.string.no, null)
.show(); .show();
return true; 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)); startActivity(new Intent(this, EditProfileActivity.class));
return true; 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_POST_TITLE_KEY, post.getTitle());
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
mActivity.startActivity(intent); 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 intent = new Intent(mActivity, ViewImageOrGifActivity.class);
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName() intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".gif"); + "-" + post.getId() + ".gif");

View File

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

View File

@ -17,7 +17,7 @@ public class DeleteAllSortTypes {
Map<String,?> keys = defaultSharedPreferences.getAll(); Map<String,?> keys = defaultSharedPreferences.getAll();
SharedPreferences.Editor editor = defaultSharedPreferences.edit(); SharedPreferences.Editor editor = defaultSharedPreferences.edit();
for(Map.Entry<String,?> entry : keys.entrySet()){ for (Map.Entry<String,?> entry : keys.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
if (key.contains(SharedPreferencesUtils.SORT_TYPE_BEST_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_BEST_POST) 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) || 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; String sortType = getArguments() != null ? getArguments().getString(EXTRA_SORT_TYPE) : null;
if(sortType == null) { if (sortType == null) {
dismiss(); dismiss();
return rootView; return rootView;
} }

View File

@ -265,7 +265,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
String username = getArguments().getString(EXTRA_USERNAME); String username = getArguments().getString(EXTRA_USERNAME);
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.name()); 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()); 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())); sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
} else { } else {

View File

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

View File

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

View File

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

View File

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

View File

@ -114,7 +114,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); 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); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT);
} else { } else {
if (amoledDarkSwitch.isChecked()) { if (amoledDarkSwitch.isChecked()) {

View File

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

View File

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

View File

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