[android] Support drawable in PlaceHolderView

Signed-off-by: Jean-Baptiste <jeanbaptiste.charron@outlook.fr>
This commit is contained in:
Jean-Baptiste
2025-10-26 14:29:49 +01:00
committed by x7z4w
parent d4ac51cc02
commit 2b5930dff8
14 changed files with 26 additions and 11 deletions

View File

@@ -282,11 +282,11 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<ConcatAdapter
{ {
if (isEmptySearchResults()) if (isEmptySearchResults())
{ {
requirePlaceholder().setContent(R.string.search_not_found, R.string.search_not_found_query); requirePlaceholder().setContent(R.string.search_not_found, R.string.search_not_found_query, R.drawable.ic_search_fail);
} }
else if (isEmpty()) else if (isEmpty())
{ {
requirePlaceholder().setContent(R.string.bookmarks_empty_list_title, R.string.bookmarks_empty_list_message); requirePlaceholder().setContent(R.string.bookmarks_empty_list_title, R.string.bookmarks_empty_list_message, R.drawable.ic_bookmarks);
} }
boolean isEmptyRecycler = isEmpty() || isEmptySearchResults(); boolean isEmptyRecycler = isEmpty() || isEmptySearchResults();

View File

@@ -222,10 +222,10 @@ public class DownloaderFragment
return; return;
if (mAdapter != null && mAdapter.isSearchResultsMode()) if (mAdapter != null && mAdapter.isSearchResultsMode())
placeholder.setContent(R.string.search_not_found, R.string.search_not_found_query); placeholder.setContent(R.string.search_not_found, R.string.search_not_found_query, R.drawable.ic_search_fail);
else else
placeholder.setContent(R.string.downloader_no_downloaded_maps_title, placeholder.setContent(R.string.downloader_no_downloaded_maps_title,
R.string.downloader_no_downloaded_maps_message); R.string.downloader_no_downloaded_maps_message, R.drawable.ic_download);
} }
@Override @Override

View File

@@ -273,7 +273,7 @@ public class SearchFragment extends BaseMwmFragment implements SearchListener, C
RecyclerView mResults = mResultsFrame.findViewById(R.id.recycler); RecyclerView mResults = mResultsFrame.findViewById(R.id.recycler);
setRecyclerScrollListener(mResults); setRecyclerScrollListener(mResults);
mResultsPlaceholder = mResultsFrame.findViewById(R.id.placeholder); mResultsPlaceholder = mResultsFrame.findViewById(R.id.placeholder);
mResultsPlaceholder.setContent(R.string.search_not_found, R.string.search_not_found_query); mResultsPlaceholder.setContent(R.string.search_not_found, R.string.search_not_found_query, R.drawable.ic_search_fail);
mSearchAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() mSearchAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver()
{ {

View File

@@ -47,7 +47,7 @@ public class SearchHistoryFragment extends BaseMwmRecyclerFragment<SearchHistory
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
getRecyclerView().setLayoutManager(new LinearLayoutManager(view.getContext())); getRecyclerView().setLayoutManager(new LinearLayoutManager(view.getContext()));
mPlaceHolder = view.findViewById(R.id.placeholder); mPlaceHolder = view.findViewById(R.id.placeholder);
mPlaceHolder.setContent(R.string.search_history_title, R.string.search_history_text); mPlaceHolder.setContent(R.string.search_history_title, R.string.search_history_text, R.drawable.ic_search_recent);
getAdapter().registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { getAdapter().registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override @Override

View File

@@ -3,6 +3,7 @@ package app.organicmaps.widget;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -11,6 +12,7 @@ import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import com.google.android.material.imageview.ShapeableImageView; import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.textview.MaterialTextView; import com.google.android.material.textview.MaterialTextView;
@@ -176,9 +178,10 @@ public class PlaceholderView extends LinearLayout
return view.getMeasuredHeight() + params.bottomMargin + params.topMargin; return view.getMeasuredHeight() + params.bottomMargin + params.topMargin;
} }
public void setContent(@StringRes int titleRes, @StringRes int subtitleRes) public void setContent(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes)
{ {
mTitle.setText(titleRes); mTitle.setText(titleRes);
mSubtitle.setText(subtitleRes); mSubtitle.setText(subtitleRes);
mImage.setImageDrawable(ContextCompat.getDrawable(getContext(), iconRes));
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 B

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="m280,708 l56,57q6,6 14,6t14,-6q6,-6 6,-14.5t-6,-14.5l-56,-56 57,-57q6,-6 6,-14t-6,-14q-6,-6 -14,-6t-14,6l-57,57 -57,-57q-6,-6 -14,-6t-14,6q-6,6 -6,14t6,14l57,57 -57,57q-6,6 -6,14t6,14q6,6 14,6t14,-6l57,-57ZM280,880q-83,0 -141.5,-58.5T80,680q0,-83 58.5,-141.5T280,480q83,0 141.5,58.5T480,680q0,83 -58.5,141.5T280,880ZM568,584q-12,-13 -25.5,-26.5T516,532q38,-24 61,-64t23,-88q0,-75 -52.5,-127.5T420,200q-75,0 -127.5,52.5T240,380q0,6 0.5,11.5T242,403q-18,2 -39.5,8T164,425q-2,-11 -3,-22t-1,-23q0,-109 75.5,-184.5T420,120q109,0 184.5,75.5T680,380q0,43 -13.5,81.5T629,532l223,224q11,11 11.5,27.5T852,812q-11,11 -28,11t-28,-11L568,584Z"
android:fillColor="@android:color/white"/>
</vector>

View File

@@ -29,7 +29,7 @@
android:paddingStart="@dimen/margin_double_and_half" android:paddingStart="@dimen/margin_double_and_half"
android:paddingTop="@dimen/placeholder_margin_top" android:paddingTop="@dimen/placeholder_margin_top"
android:paddingEnd="@dimen/margin_double_and_half" android:paddingEnd="@dimen/margin_double_and_half"
app:imgSrcDefault="@drawable/img_empty_bookmarks" app:imgSrcDefault="@drawable/ic_close"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

View File

@@ -2,8 +2,11 @@
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image" android:id="@+id/image"
android:layout_width="@dimen/placeholder_size" android:layout_width="@dimen/placeholder_size"
android:layout_height="@dimen/placeholder_size" android:layout_height="@dimen/placeholder_size"
android:layout_marginTop="@dimen/placeholder_size"
android:layout_marginBottom="@dimen/margin_half_plus" android:layout_marginBottom="@dimen/margin_half_plus"
app:tint="?iconTint"
tools:src="@drawable/ic_search" /> tools:src="@drawable/ic_search" />

View File

@@ -54,8 +54,8 @@
<dimen name="panel_width">360dp</dimen> <dimen name="panel_width">360dp</dimen>
<dimen name="button_width">240dp</dimen> <dimen name="button_width">240dp</dimen>
<dimen name="placeholder_size">200dp</dimen> <dimen name="placeholder_size">100dp</dimen>
<dimen name="placeholder_size_small">160dp</dimen> <dimen name="placeholder_size_small">80dp</dimen>
<dimen name="width_dialog_base">300dp</dimen> <dimen name="width_dialog_base">300dp</dimen>