From ee4a0167a3b27755527023faba9a9bc00f5b91ee Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 17 Sep 2023 23:14:31 -0400 Subject: Fix https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/1508. Minor UI tweaks in SearchActivity. --- .../infinityforreddit/FetchStreamableVideo.java | 19 ++++++++++--- .../activities/SearchActivity.java | 15 ++++++---- .../SearchActivityRecyclerViewAdapter.java | 32 ++++++++-------------- 3 files changed, 36 insertions(+), 30 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java index ef5629d4..f0b03e1b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java @@ -16,7 +16,6 @@ import ml.docilealligator.infinityforreddit.apis.StreamableAPI; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import retrofit2.Call; import retrofit2.Response; -import retrofit2.Retrofit; public class FetchStreamableVideo { public interface FetchStreamableVideoListener { @@ -34,7 +33,15 @@ public class FetchStreamableVideo { String title = jsonObject.getString(JSONUtils.TITLE_KEY); JSONObject filesObject = jsonObject.getJSONObject(JSONUtils.FILES_KEY); StreamableVideo.Media mp4 = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_KEY)); - StreamableVideo.Media mp4Mobile = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); + StreamableVideo.Media mp4MobileTemp = null; + if (filesObject.has(JSONUtils.MP4_MOBILE_KEY)) { + mp4MobileTemp = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); + } + if (mp4 == null && mp4MobileTemp == null) { + handler.post(fetchStreamableVideoListener::failed); + return; + } + StreamableVideo.Media mp4Mobile = mp4MobileTemp; handler.post(() -> fetchStreamableVideoListener.success(new StreamableVideo(title, mp4, mp4Mobile))); } else { handler.post(fetchStreamableVideoListener::failed); @@ -56,11 +63,15 @@ public class FetchStreamableVideo { String title = jsonObject.getString(JSONUtils.TITLE_KEY); JSONObject filesObject = jsonObject.getJSONObject(JSONUtils.FILES_KEY); StreamableVideo.Media mp4 = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_KEY)); - StreamableVideo.Media mp4Mobile = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); - if (mp4 == null && mp4Mobile == null) { + StreamableVideo.Media mp4MobileTemp = null; + if (filesObject.has(JSONUtils.MP4_MOBILE_KEY)) { + mp4MobileTemp = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); + } + if (mp4 == null && mp4MobileTemp == null) { handler.post(fetchStreamableVideoListener::failed); return; } + StreamableVideo.Media mp4Mobile = mp4MobileTemp; handler.post(() -> fetchStreamableVideoListener.success(new StreamableVideo(title, mp4, mp4Mobile))); } else { handler.post(fetchStreamableVideoListener::failed); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index 8cdb0920..5e3426f8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.activities; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.ColorStateList; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -27,6 +28,7 @@ import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.greenrobot.eventbus.EventBus; @@ -96,8 +98,8 @@ public class SearchActivity extends BaseActivity { ImageView clearSearchTextImageView; @BindView(R.id.link_handler_image_view_search_activity) ImageView linkHandlerImageView; - @BindView(R.id.delete_all_recent_searches_image_view_search_activity) - ImageView deleteAllSearchesImageView; + @BindView(R.id.delete_all_recent_searches_button_search_activity) + MaterialButton deleteAllSearchesButton; @BindView(R.id.subreddit_name_relative_layout_search_activity) RelativeLayout subredditNameRelativeLayout; @BindView(R.id.search_in_text_view_search_activity) @@ -161,7 +163,7 @@ public class SearchActivity extends BaseActivity { setSupportActionBar(toolbar); clearSearchTextImageView.setVisibility(View.GONE); - deleteAllSearchesImageView.setVisibility(View.GONE); + deleteAllSearchesButton.setVisibility(View.GONE); searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false); searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false); @@ -275,7 +277,7 @@ public class SearchActivity extends BaseActivity { } }); - deleteAllSearchesImageView.setOnClickListener(view -> { + deleteAllSearchesButton.setOnClickListener(view -> { new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) .setTitle(R.string.confirm) .setMessage(R.string.confirm_delete_all_recent_searches) @@ -343,10 +345,10 @@ public class SearchActivity extends BaseActivity { mRecentSearchQueryViewModel.getAllRecentSearchQueries().observe(this, recentSearchQueries -> { if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) { divider.setVisibility(View.VISIBLE); - deleteAllSearchesImageView.setVisibility(View.VISIBLE); + deleteAllSearchesButton.setVisibility(View.VISIBLE); } else { divider.setVisibility(View.GONE); - deleteAllSearchesImageView.setVisibility(View.GONE); + deleteAllSearchesButton.setVisibility(View.GONE); } adapter.setRecentSearchQueries(recentSearchQueries); }); @@ -411,6 +413,7 @@ public class SearchActivity extends BaseActivity { linkHandlerImageView.setColorFilter(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); int colorAccent = mCustomThemeWrapper.getColorAccent(); searchInTextView.setTextColor(colorAccent); + deleteAllSearchesButton.setIconTint(ColorStateList.valueOf(mCustomThemeWrapper.getPrimaryIconColor())); subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); divider.setBackgroundColor(mCustomThemeWrapper.getDividerColor()); if (typeface != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java index 51a8fb63..776c00ef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java @@ -2,21 +2,17 @@ package ml.docilealligator.infinityforreddit.adapters; import android.graphics.drawable.Drawable; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemRecentSearchQueryBinding; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQuery; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -45,14 +41,14 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter { @@ -92,7 +84,7 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter { + binding.deleteButtonItemRecentSearchQuery.setOnClickListener(view -> { itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition())); }); } -- cgit v1.2.3