diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-09-18 03:14:31 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-09-18 03:14:31 +0000 |
commit | ee4a0167a3b27755527023faba9a9bc00f5b91ee (patch) | |
tree | fe4bbd484f933e8036664ec8c3ac16dc21c9061b /app/src/main/java/ml/docilealligator | |
parent | 28400822af6024906fccd8fb9893594d283bee1e (diff) | |
download | infinity-for-reddit-ee4a0167a3b27755527023faba9a9bc00f5b91ee.tar infinity-for-reddit-ee4a0167a3b27755527023faba9a9bc00f5b91ee.tar.gz infinity-for-reddit-ee4a0167a3b27755527023faba9a9bc00f5b91ee.tar.bz2 infinity-for-reddit-ee4a0167a3b27755527023faba9a9bc00f5b91ee.tar.lz infinity-for-reddit-ee4a0167a3b27755527023faba9a9bc00f5b91ee.tar.xz infinity-for-reddit-ee4a0167a3b27755527023faba9a9bc00f5b91ee.tar.zst infinity-for-reddit-ee4a0167a3b27755527023faba9a9bc00f5b91ee.zip |
Fix https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/1508. Minor UI tweaks in SearchActivity.
Diffstat (limited to '')
3 files changed, 36 insertions, 30 deletions
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<Recy @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new RecentSearchQueryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recent_search_query, parent, false)); + return new RecentSearchQueryViewHolder(ItemRecentSearchQueryBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof RecentSearchQueryViewHolder) { if (recentSearchQueries != null && !recentSearchQueries.isEmpty() && position < recentSearchQueries.size()) { - ((RecentSearchQueryViewHolder) holder).recentSearchQueryTextView.setText(recentSearchQueries.get(position).getSearchQuery()); + ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setText(recentSearchQueries.get(position).getSearchQuery()); } } } @@ -68,22 +64,18 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy } class RecentSearchQueryViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.recent_search_query_text_view_item_recent_search_query) - TextView recentSearchQueryTextView; - @BindView(R.id.delete_image_view_item_recent_search_query) - ImageView deleteImageView; + ItemRecentSearchQueryBinding binding; - public RecentSearchQueryViewHolder(@NonNull View itemView) { - super(itemView); + public RecentSearchQueryViewHolder(@NonNull ItemRecentSearchQueryBinding binding) { + super(binding.getRoot()); + this.binding = binding; - ButterKnife.bind(this, itemView); - - recentSearchQueryTextView.setTextColor(primaryTextColor); - recentSearchQueryTextView.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null); - deleteImageView.setImageDrawable(deleteIcon); + binding.recentSearchQueryTextViewItemRecentSearchQuery.setTextColor(primaryTextColor); + binding.recentSearchQueryTextViewItemRecentSearchQuery.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null); + binding.deleteButtonItemRecentSearchQuery.setIcon(deleteIcon); if (activity.typeface != null) { - recentSearchQueryTextView.setTypeface(activity.typeface); + binding.recentSearchQueryTextViewItemRecentSearchQuery.setTypeface(activity.typeface); } itemView.setOnClickListener(view -> { @@ -92,7 +84,7 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy } }); - deleteImageView.setOnClickListener(view -> { + binding.deleteButtonItemRecentSearchQuery.setOnClickListener(view -> { itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition())); }); } |