forked from organicmaps/organicmaps
[android] Cian adapter
This commit is contained in:
parent
08a47fd0df
commit
a2303fd205
2 changed files with 148 additions and 0 deletions
54
android/res/layout/item_cian_product.xml
Normal file
54
android/res/layout/item_cian_product.xml
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:layout_width="@dimen/viator_product_width"
|
||||
android:layout_height="@dimen/viator_product_height"
|
||||
android:orientation="vertical"
|
||||
android:foreground="?clickableBackground">
|
||||
<TextView
|
||||
android:id="@+id/tv__price"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_half_plus"
|
||||
android:layout_marginLeft="@dimen/margin_half_plus"
|
||||
android:layout_marginRight="@dimen/margin_half_plus"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:textColor="?colorAccent"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
tools:text="370 000 ₽/мес."/>
|
||||
<TextView
|
||||
android:id="@+id/tv__title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_half_plus"
|
||||
android:layout_marginLeft="@dimen/margin_half_plus"
|
||||
android:layout_marginRight="@dimen/margin_half_plus"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3.Primary"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
tools:text="3-комн. кв, 215 м²"/>
|
||||
<TextView
|
||||
android:id="@+id/tv__address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="@dimen/margin_half_plus"
|
||||
android:layout_marginLeft="@dimen/margin_half_plus"
|
||||
android:layout_marginRight="@dimen/margin_half_plus"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body4"
|
||||
android:ellipsize="end"
|
||||
tools:text="Чапаевский пер., 3"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/height_block_base"
|
||||
android:textAppearance="@style/MwmTextAppearance.Button"
|
||||
android:gravity="center"
|
||||
android:background="?windowBackgroundForced"
|
||||
android:text="@string/details"/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
94
android/src/com/mapswithme/maps/cian/CianAdapter.java
Normal file
94
android/src/com/mapswithme/maps/cian/CianAdapter.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
package com.mapswithme.maps.cian;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseSponsoredAdapter;
|
||||
import com.mapswithme.maps.widget.placepage.Sponsored;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class CianAdapter extends BaseSponsoredAdapter
|
||||
{
|
||||
public CianAdapter(@NonNull RentPlace[] items, @NonNull String cityUrl,
|
||||
@Nullable ItemSelectedListener listener)
|
||||
{
|
||||
super(Sponsored.TYPE_CIAN, convertItems(items), cityUrl, listener);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static List<Item> convertItems(@NonNull RentPlace[] items)
|
||||
{
|
||||
List<Item> viewItems = new ArrayList<>();
|
||||
for (RentPlace place : items)
|
||||
{
|
||||
RentOffer product = place.getOffers().get(0);
|
||||
// Context context = MwmApplication.get();
|
||||
// String title = context.getString(R.string.room, Integer.toString(product.getRoomsCount()))
|
||||
// + " " + Integer.toString(product.getFloorNumber()) + context.getString(R.string.area);
|
||||
// String price = context.getString(R.string.rub_month);
|
||||
// viewItems.add(new Item(title, product.getUrl(), price, product.getAddress()));
|
||||
}
|
||||
|
||||
return viewItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
protected BaseSponsoredAdapter.ViewHolder createViewHolder(@NonNull LayoutInflater inflater,
|
||||
@NonNull ViewGroup parent)
|
||||
{
|
||||
return new ProductViewHolder(inflater.inflate(R.layout.item_cian_product, parent, false),
|
||||
this);
|
||||
}
|
||||
|
||||
private static final class ProductViewHolder extends ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
TextView mPrice;
|
||||
@NonNull
|
||||
TextView mAddress;
|
||||
|
||||
ProductViewHolder(@NonNull View itemView, @NonNull CianAdapter adapter)
|
||||
{
|
||||
super(itemView, adapter);
|
||||
mPrice = (TextView) itemView.findViewById(R.id.tv__price);
|
||||
mAddress = (TextView) itemView.findViewById(R.id.tv__address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(@NonNull BaseSponsoredAdapter.Item item)
|
||||
{
|
||||
super.bind(item);
|
||||
|
||||
Item product = (Item) item;
|
||||
UiUtils.setTextAndHideIfEmpty(mPrice, product.mPrice);
|
||||
UiUtils.setTextAndHideIfEmpty(mAddress, product.mAddress);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Item extends BaseSponsoredAdapter.Item
|
||||
{
|
||||
@NonNull
|
||||
private final String mPrice;
|
||||
@NonNull
|
||||
private final String mAddress;
|
||||
|
||||
private Item(@NonNull String title, @NonNull String url, @NonNull String price,
|
||||
@NonNull String address)
|
||||
{
|
||||
super(TYPE_PRODUCT, Sponsored.TYPE_CIAN, title, url);
|
||||
mPrice = price;
|
||||
mAddress = address;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue