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 ++++++++-------------- app/src/main/res/layout/activity_search.xml | 25 ++++++++++------- .../main/res/layout/item_recent_search_query.xml | 16 ++++++----- 5 files changed, 60 insertions(+), 47 deletions(-) (limited to 'app') 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())); }); } diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index 1a4580c6..4589d6ac 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -87,11 +87,15 @@ android:id="@+id/search_in_text_view_search_activity" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_margin="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" + android:layout_centerVertical="true" + android:fontFamily="?attr/font_family" android:text="@string/search_in" android:textColor="?attr/colorAccent" - android:textSize="?attr/font_default" - android:fontFamily="?attr/font_family" /> + android:textSize="?attr/font_default" /> - + android:layout_centerVertical="true" + app:strokeWidth="0dp" + app:icon="@drawable/ic_delete_all_24" + app:iconSize="24dp" + style="?attr/materialIconButtonOutlinedStyle" /> diff --git a/app/src/main/res/layout/item_recent_search_query.xml b/app/src/main/res/layout/item_recent_search_query.xml index 8fdc502c..e23e7378 100644 --- a/app/src/main/res/layout/item_recent_search_query.xml +++ b/app/src/main/res/layout/item_recent_search_query.xml @@ -1,8 +1,8 @@ - @@ -13,19 +13,21 @@ android:layout_height="wrap_content" android:layout_weight="1" android:layout_gravity="center_vertical" + android:gravity="center_vertical" android:fontFamily="?attr/font_family" android:textSize="?attr/font_default" android:padding="16dp" android:drawablePadding="16dp" /> - + app:strokeWidth="0dp" + app:iconSize="24dp" + app:iconTint="@null" + style="?attr/materialIconButtonOutlinedStyle" /> \ No newline at end of file -- cgit v1.2.3