Skip to content

Commit

Permalink
Added empty cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Corwin-Kh committed Feb 6, 2025
1 parent 000691a commit 7230464
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 41 deletions.
48 changes: 48 additions & 0 deletions OsmAnd/res/layout/empty_nearby_places.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/empty_nearby_places"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
android:contentDescription="@string/shared_string_no_internet_connection"
android:tint="?attr/default_icon_color"
app:srcCompat="@drawable/ic_action_desert" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding"
android:orientation="vertical">

<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding"
android:gravity="start"
android:text="@string/no_places_available"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:textStyle="normal" />

<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_half"
android:layout_marginBottom="@dimen/content_padding"
android:gravity="start"
android:text="@string/no_photo_for_location_desc"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="normal" />

</LinearLayout>

</LinearLayout>
88 changes: 53 additions & 35 deletions OsmAnd/res/layout/nearby_places_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:scaleType="center" />
</LinearLayout>
</LinearLayout> <!--Title-->

<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="@+id/progress_bar"
Expand All @@ -47,45 +47,63 @@
app:mpb_useIntrinsicPadding="false"
tools:visibility="visible" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/nearByList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:padding="0dp" />

<FrameLayout
android:id="@+id/show_all_button"
android:id="@+id/card_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:minHeight="@dimen/route_info_list_item_height"
android:orientation="vertical">
android:layout_height="wrap_content">

<View
android:id="@+id/divider_list"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="top"
android:layout_marginStart="@dimen/content_padding"
android:background="?attr/divider_color_basic" />

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_all_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_marginStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_padding"
android:paddingBottom="@dimen/list_header_padding"
android:text="@string/shared_string_show_all"
android:textAllCaps="true"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_sub_text_size"
app:typefaceWeight="medium"
tools:text="SHOW ALL"
tools:visibility="visible" />
</FrameLayout>
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/nearByList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:padding="0dp" />

<FrameLayout
android:id="@+id/show_all_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:minHeight="@dimen/route_info_list_item_height"
android:orientation="vertical">

<View
android:id="@+id/divider_list"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="top"
android:layout_marginStart="@dimen/content_padding"
android:background="?attr/divider_color_basic" />

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_all_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_marginStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_padding"
android:paddingBottom="@dimen/list_header_padding"
android:text="@string/shared_string_show_all"
android:textAllCaps="true"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_sub_text_size"
app:typefaceWeight="medium"
tools:text="SHOW ALL"
tools:visibility="visible" />
</FrameLayout>

</LinearLayout>

</FrameLayout> <!--Card content-->

<include layout="@layout/nearby_places_no_internet" />

<include layout="@layout/empty_nearby_places" />

<include layout="@layout/list_item_divider" />

Expand Down
57 changes: 57 additions & 0 deletions OsmAnd/res/layout/nearby_places_no_internet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/no_internet"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:orientation="horizontal"
android:visibility="gone">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
android:contentDescription="@string/shared_string_no_internet_connection"
android:tint="?attr/default_icon_color"
app:srcCompat="@drawable/ic_action_wifi_off" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding"
android:gravity="start"
android:text="@string/shared_string_no_internet_connection"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:textStyle="normal" />

<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_half"
android:gravity="start"
android:text="@string/no_internet_descr"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="normal" />

<net.osmand.plus.widgets.dialogbutton.DialogButton
android:id="@+id/try_again_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
app:dialogButtonTopMargin="@dimen/content_padding"
app:dialogButtonBottomMargin="@dimen/content_padding"
app:dialogButtonTitle="@string/try_again"
app:dialogButtonType="secondary"
/>

</LinearLayout>
</LinearLayout>
2 changes: 2 additions & 0 deletions OsmAnd/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- For wording and consistency, please note https://docs.osmand.net/docs/technical/contributions/translating-osmand
Thx - Hardy
-->
<string name="no_places_available">No places available</string>
<string name="no_photo_for_location_desc">No user photos have been added to this location yet</string>
<string name="popular_places_nearby">Popular places nearby</string>
<string name="recently_visited">Recently visited</string>

Expand Down
35 changes: 29 additions & 6 deletions OsmAnd/src/net/osmand/plus/search/listitems/NearbyPlacesCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class NearbyPlacesCard extends FrameLayout implements NearbyPlacesListene
private OsmandApplication app;
private NearbyPlacesAdapter.NearbyItemClickListener clickListener;
private MapActivity mapActivity;
private View noInternetCard;
private View emptyView;
private View cardContent;
private boolean isLoadingItems;


public NearbyPlacesCard(@NonNull MapActivity mapActivity, @NonNull NearbyPlacesAdapter.NearbyItemClickListener clickListener) {
super(mapActivity);
Expand All @@ -52,6 +57,15 @@ private void init() {
explicitIndicator = findViewById(R.id.explicit_indicator);
titleContainer = findViewById(R.id.nearby_title_container);
showAllBtnContainer = findViewById(R.id.show_all_button);
noInternetCard = findViewById(R.id.no_internet);
emptyView = findViewById(R.id.empty_nearby_places);
cardContent = findViewById(R.id.card_content);
noInternetCard.findViewById(R.id.try_again_button).setOnClickListener((v) -> {
if(app.getSettings().isInternetConnectionAvailable(true)) {
startLoadingNearbyPlaces();
updateExpandState();
}
});

setupRecyclerView();
setupShowAllNearbyPlacesBtn();
Expand Down Expand Up @@ -81,11 +95,15 @@ private void setupRecyclerView() {
private void updateExpandState() {
int iconRes = collapsed ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up;
explicitIndicator.setImageDrawable(app.getUIUtilities().getIcon(iconRes, !app.getSettings().isLightContent()));
AndroidUiHelper.updateVisibility(nearByList, !collapsed);
AndroidUiHelper.updateVisibility(showAllBtnContainer, !collapsed && getNearbyAdapter().getItemCount() > 0);
boolean internetAvailable = app.getSettings().isInternetConnectionAvailable();
boolean nearbyPointFound = getNearbyAdapter().getItemCount() > 0;
AndroidUiHelper.updateVisibility(cardContent, !collapsed && nearbyPointFound && internetAvailable);
AndroidUiHelper.updateVisibility(noInternetCard, !collapsed && !internetAvailable);
AndroidUiHelper.updateVisibility(emptyView, !collapsed && internetAvailable && !nearbyPointFound && !isLoadingItems);
}

public void updateNearbyItems() {
isLoadingItems = false;
AndroidUiHelper.updateVisibility(progressBar, false);
adapter.setItems(NearbyPlacesHelper.INSTANCE.getDataCollection());
adapter.notifyDataSetChanged();
Expand Down Expand Up @@ -114,14 +132,19 @@ public void onPause() {
}

private void onNearbyPlacesCollapseChanged() {
updateExpandState();
if (!collapsed) {
AndroidUiHelper.updateVisibility(progressBar, true);
NearbyPlacesHelper.INSTANCE.startLoadingNearestPhotos();
if (!collapsed && app.getSettings().isInternetConnectionAvailable()) {
startLoadingNearbyPlaces();
}
updateExpandState();
app.getSettings().EXPLORE_NEARBY_ITEMS_ROW_COLLAPSED.set(collapsed);
}

private void startLoadingNearbyPlaces() {
isLoadingItems = true;
AndroidUiHelper.updateVisibility(progressBar, true);
NearbyPlacesHelper.INSTANCE.startLoadingNearestPhotos();
}

private void setupExpandNearbyPlacesIndicator() {
collapsed = app.getSettings().EXPLORE_NEARBY_ITEMS_ROW_COLLAPSED.get();
explicitIndicator = findViewById(R.id.explicit_indicator);
Expand Down

0 comments on commit 7230464

Please sign in to comment.