Viewpager added onto the products page for images

This commit is contained in:
gilokimu 2019-03-14 05:48:50 +03:00
parent 74362552b3
commit c161bc454a
7 changed files with 164 additions and 92 deletions

View File

@ -85,5 +85,7 @@ dependencies {
implementation 'com.miguelcatalan:materialsearchview:1.4.0'
implementation 'me.relex:circleindicator:1.2.2@aar'
}

View File

@ -14,6 +14,12 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
startActivity(Intent(baseContext, HomeActivity::class.java))
// val intent = Intent(baseContext, ProductActivity::class.java)
// intent.putExtra("productId", 63)
//
// startActivity(intent)
finish()
}

View File

@ -0,0 +1,48 @@
package me.gilo.wc.adapter
import android.content.Context
import android.support.v4.view.PagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.squareup.picasso.Picasso
import me.gilo.wc.R
import me.gilo.woodroid.models.Image
class ImagePagerAdapter(val context: Context, private val images: List<Image>) : PagerAdapter() {
override fun instantiateItem(collection: ViewGroup, position: Int): View {
val inflater = LayoutInflater.from(context)
val layout = inflater.inflate(R.layout.single_product_image, collection, false)
val ivImage = layout.findViewById<ImageView>(R.id.ivImage)
val image = images[position]
if (image != null) {
Picasso
.with(context)
.load(image!!.src)
.into(ivImage)
}
collection.addView(layout)
return layout
}
override fun destroyItem(container: ViewGroup, position: Int, view: Any) {
container.removeView(view as View)
}
override fun getCount(): Int {
return this.images.size
}
override fun isViewFromObject(view: View, obj: Any): Boolean {
return view == obj
}
}

View File

@ -3,10 +3,10 @@ package me.gilo.wc.ui.product
import android.os.Bundle
import android.text.Html
import android.view.View
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.activity_product.*
import kotlinx.android.synthetic.main.content_product.*
import me.gilo.wc.R
import me.gilo.wc.adapter.ImagePagerAdapter
import me.gilo.wc.common.BaseActivity
import me.gilo.wc.common.Status
import me.gilo.wc.ui.state.ProgressDialogFragment
@ -93,7 +93,10 @@ class ProductActivity : BaseActivity() {
tvDescription.text = Html.fromHtml(product.description)
if (product.images != null && product.images.isNotEmpty()){
Picasso.with(baseContext).load(product.images[0].src).into(ivImage)
vpImages.offscreenPageLimit = product.images.size
vpImages.adapter = ImagePagerAdapter(baseContext, product.images)
indicator.setViewPager(vpImages)
}
if (product.isOn_sale) {
@ -101,7 +104,7 @@ class ProductActivity : BaseActivity() {
tvOnSale.visibility = View.VISIBLE
}else{
tvCallToAction.text = Html.fromHtml(product.price_html)
tvCallToAction.text = Html.fromHtml(product.price_html).trim()
tvOnSale.visibility = View.GONE
}
}

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="@color/bg"
android:elevation="2dp"
android:orientation="vertical"
@ -12,34 +12,31 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rect_white"
android:elevation="2dp"
android:orientation="vertical"
tools:ignore="MissingPrefix">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="200dp">
android:layout_height="320dp"
android:layout_marginBottom="16dp"
<ImageView
android:id="@+id/ivImage"
>
<android.support.v4.view.ViewPager
android:id="@+id/vpImages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_height="match_parent"/>
<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="8dp"
android:layout_margin="16dp"
app:ci_height="4dp"
app:ci_width="4dp"
android:layout_gravity="bottom|center"
/>
<TextView
@ -56,6 +53,17 @@
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_margin="16dp"
android:layout_height="wrap_content"
android:background="@drawable/rect_white"
android:elevation="2dp"
android:orientation="vertical"
tools:ignore="MissingPrefix">
<TextView
android:id="@+id/tvTitle"
fontPath="@string/font_medium"
@ -77,10 +85,9 @@
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:gravity="left"
android:maxLines="2"
android:lineSpacingMultiplier="1.2"
android:textColor="@color/text_black_5"
android:textSize="14sp"/>
android:textSize="16sp"/>
<TextView
android:id="@+id/tvCallToAction"
@ -98,7 +105,5 @@
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ivImage"
android:scaleType="centerCrop"/>

View File

@ -52,4 +52,5 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.0.0-RC1'
}