mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 04:39:04 +00:00
implement empty view for shops
This commit is contained in:
parent
ccc774f062
commit
6b7fdc963d
6 changed files with 148 additions and 5 deletions
25
Habitica/res/layout/empty_view_seasonal_shop.xml
Normal file
25
Habitica/res/layout/empty_view_seasonal_shop.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="21dp">
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/shop_empty_seasonal" />
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/come_back_soon"
|
||||
android:textSize="18sp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/gray_200"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/seasonal_closed_description"
|
||||
android:textColor="@color/gray_300"
|
||||
android:layout_marginTop="12dp"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"/>
|
||||
</LinearLayout>
|
||||
33
Habitica/res/layout/empty_view_timetravelers.xml
Normal file
33
Habitica/res/layout/empty_view_timetravelers.xml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="21dp">
|
||||
<ImageView
|
||||
android:src="@drawable/shop_empty_hourglass"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/subscribe_for_hourglasses"
|
||||
android:textSize="18sp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/gray_200"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/timetravelers_closed_description"
|
||||
android:textColor="@color/gray_300"
|
||||
android:layout_marginTop="12dp"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"/>
|
||||
<Button
|
||||
android:id="@+id/subscribeButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="38dp"
|
||||
android:text="@string/want_to_subscribe"
|
||||
android:textColor="@color/brand_400"
|
||||
android:background="@drawable/layout_rounded_bg_lighter_gray"
|
||||
android:layout_marginTop="18dp"/>
|
||||
</LinearLayout>
|
||||
38
Habitica/res/layout/fragment_shop.xml
Normal file
38
Habitica/res/layout/fragment_shop.xml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/coordinatorLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/FragmentDialogTitle"
|
||||
android:id="@+id/titleTextView"
|
||||
android:background="@color/brand_100"
|
||||
android:textColor="@android:color/white" />
|
||||
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:scrollbarSize="3dp"
|
||||
android:scrollbarThumbVertical="@color/md_grey_500"
|
||||
android:scrollbars="vertical"
|
||||
android:paddingBottom="?attr/actionBarSize" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/empty_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center" />
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
@ -660,4 +660,9 @@
|
|||
<string name="purchase_gems">Purchase gems</string>
|
||||
<string name="insufficientHourglasses">You\'ll need more Mystic Hourglasses to buy this item!</string>
|
||||
<string name="get_hourglasses">Get hourglasses</string>
|
||||
<string name="subscribe_for_hourglasses">Subscribe for Hourglasses</string>
|
||||
<string name="timetravelers_closed_description">Earn one Mystic Hourglass for every three months of consecutive subscription, then use them to unlock limited edition items, pets, and mounts from the past… and future!</string>
|
||||
<string name="want_to_subscribe">I want to Subscribe</string>
|
||||
<string name="seasonal_closed_description">The Grand Galas happen close to the solstices and equinoxes, so check back then to find a fun assortment of special seasonal items!</string>
|
||||
<string name="come_back_soon">Come back soon!</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import android.text.method.LinkMovementMethod;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ import com.facebook.imagepipeline.image.CloseableImage;
|
|||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand;
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.inventory.Item;
|
||||
import com.habitrpg.android.habitica.models.shops.Shop;
|
||||
|
|
@ -36,6 +38,8 @@ import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
|||
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.ShopItemViewHolder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -85,6 +89,10 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
.inflate(R.layout.shop_section_header, parent, false);
|
||||
|
||||
return new SectionViewHolder(view);
|
||||
} else if (viewType == 2) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(getEmptyViewResource(), parent, false);
|
||||
return new EmptyStateViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.row_shopitem, parent, false);
|
||||
|
|
@ -94,14 +102,26 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
}
|
||||
}
|
||||
|
||||
private int getEmptyViewResource() {
|
||||
if (Shop.SEASONAL_SHOP.equals(this.shopIdentifier)) {
|
||||
return R.layout.empty_view_seasonal_shop;
|
||||
} else if (Shop.TIME_TRAVELERS_SHOP.equals(this.shopIdentifier)) {
|
||||
return R.layout.empty_view_timetravelers;
|
||||
}
|
||||
return R.layout.simple_textview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (position > (this.items.size()-1)) {
|
||||
return;
|
||||
}
|
||||
Object obj = this.items.get(position);
|
||||
if (obj.getClass().equals(Shop.class)) {
|
||||
((ShopHeaderViewHolder) holder).bind((Shop) obj, shopSpriteSuffix);
|
||||
} else if (obj.getClass().equals(ShopCategory.class)) {
|
||||
((SectionViewHolder) holder).bind(((ShopCategory) obj).getText());
|
||||
} else {
|
||||
} else if (obj.getClass().equals(ShopItem.class)) {
|
||||
ShopItem item = (ShopItem) items.get(position);
|
||||
((ShopItemViewHolder) holder).bind(item, item.canBuy(user));
|
||||
if (ownedItems.containsKey(item.getKey())) {
|
||||
|
|
@ -113,18 +133,24 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (this.items.get(position).getClass().equals(Shop.class)) {
|
||||
if (position > (this.items.size()-1)) {
|
||||
return 2;
|
||||
} else if (this.items.get(position).getClass().equals(Shop.class)) {
|
||||
return 0;
|
||||
} else if (this.items.get(position).getClass().equals(ShopCategory.class)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return items != null ? items.size() : 0;
|
||||
int size = items != null ? items.size() : 0;
|
||||
if (size == 1) {
|
||||
return 2;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setOwnedItems(Map<String, Item> ownedItems) {
|
||||
|
|
@ -208,4 +234,19 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public static class EmptyStateViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.subscribeButton)
|
||||
@Nullable
|
||||
Button subscribeButton;
|
||||
|
||||
public EmptyStateViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
if (subscribeButton != null) {
|
||||
subscribeButton.setOnClickListener(view1 -> EventBus.getDefault().post(new OpenGemPurchaseFragmentCommand()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.support.v7.widget.GridLayoutManager;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
|
@ -74,7 +75,7 @@ public class ShopFragment extends BaseFragment {
|
|||
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
||||
@Override
|
||||
public int getSpanSize(int position) {
|
||||
if (adapter.getItemViewType(position) < 2) {
|
||||
if (adapter.getItemViewType(position) < 3) {
|
||||
return layoutManager.getSpanCount();
|
||||
} else {
|
||||
return 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue