Changes on product layout
This commit is contained in:
parent
db41825cc3
commit
c3697b297f
10
.idea/codeStyles/Project.xml
generated
10
.idea/codeStyles/Project.xml
generated
@ -1,8 +1,18 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<AndroidXmlCodeStyleSettings>
|
||||
<option name="USE_CUSTOM_SETTINGS" value="true" />
|
||||
</AndroidXmlCodeStyleSettings>
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
|
||||
@ -12,15 +12,18 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".ui.product.ProductActivity"
|
||||
android:label="@string/title_activity_product"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.product.ProductSearchActivity"
|
||||
android:label="@string/title_activity_product_search"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH"/>
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.coupon.CouponActivity"
|
||||
|
||||
@ -1,14 +1,23 @@
|
||||
package me.gilo.wc.adapter.viewholder
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.text.Html
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.squareup.picasso.Picasso
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.woodroid.models.Product
|
||||
import android.text.Spannable
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.SpannableString
|
||||
import android.graphics.Color
|
||||
import kotlinx.android.synthetic.main.content_product.*
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.ui.coupon.CouponActivity
|
||||
import me.gilo.wc.ui.product.ProductActivity
|
||||
|
||||
|
||||
class ProductViewHolder(val context: Context, itemView: View) :
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
@ -18,14 +27,35 @@ class ProductViewHolder(val context: Context, itemView: View) :
|
||||
val tvTitle = itemView.findViewById<TextView>(R.id.tvTitle)
|
||||
val tvDescription = itemView.findViewById<TextView>(R.id.tvDescription)
|
||||
val tvCallToAction = itemView.findViewById<TextView>(R.id.tvCallToAction)
|
||||
val tvOnSale = itemView.findViewById<TextView>(R.id.tvOnSale)
|
||||
|
||||
tvTitle.text = product.name
|
||||
tvDescription.text = Html.fromHtml(product.description)
|
||||
tvCallToAction.text = Html.fromHtml(product.price_html)
|
||||
|
||||
if (product.images != null && product.images.isNotEmpty()){
|
||||
Picasso.with(context).load(product.images[0].src).into(ivImage)
|
||||
}
|
||||
|
||||
val regularPrice = product.regular_price
|
||||
val salePrice = product.sale_price
|
||||
|
||||
val price = SpannableString("$$regularPrice $$salePrice")
|
||||
if (product.isOn_sale) {
|
||||
tvCallToAction.text = Html.fromHtml(product.price_html)
|
||||
|
||||
tvOnSale.visibility = View.VISIBLE
|
||||
}else{
|
||||
tvCallToAction.text = Html.fromHtml(product.price_html)
|
||||
tvOnSale.visibility = View.GONE
|
||||
}
|
||||
|
||||
itemView.setOnClickListener{
|
||||
val intent = Intent(context, ProductActivity::class.java)
|
||||
intent.putExtra("productId", product.id)
|
||||
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,10 @@ import android.annotation.SuppressLint;
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Context;
|
||||
import dagger.android.support.DaggerAppCompatActivity;
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
|
||||
import me.gilo.wc.ui.state.ProgressDialogFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -22,4 +25,9 @@ public class BaseActivity extends DaggerAppCompatActivity {
|
||||
public <T extends ViewModel> T getViewModel(final Class<T> cls) {
|
||||
return ViewModelProviders.of(this, viewModelFactory).get(cls);
|
||||
}
|
||||
|
||||
|
||||
public void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package me.gilo.wc.di;
|
||||
import dagger.Module;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
import me.gilo.wc.MainActivity;
|
||||
import me.gilo.wc.ui.product.ProductActivity;
|
||||
import me.gilo.wc.ui.product.ShopActivity;
|
||||
|
||||
@Module
|
||||
@ -14,4 +15,7 @@ abstract class ActivitiesModule {
|
||||
@ContributesAndroidInjector
|
||||
abstract ShopActivity contributesShopActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract ProductActivity contributesProductActivity();
|
||||
|
||||
}
|
||||
|
||||
@ -22,6 +22,14 @@ public class ProductRepository extends WoocommerceRepository {
|
||||
}
|
||||
|
||||
|
||||
public WooLiveData<Product> product(int productId) {
|
||||
final WooLiveData<Product> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.ProductRepository().product(productId).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
|
||||
public WooLiveData<List<Product>> search(String term) {
|
||||
final WooLiveData<List<Product>> callBack = new WooLiveData();
|
||||
|
||||
|
||||
107
app/src/main/java/me/gilo/wc/ui/product/ProductActivity.kt
Normal file
107
app/src/main/java/me/gilo/wc/ui/product/ProductActivity.kt
Normal file
@ -0,0 +1,107 @@
|
||||
package me.gilo.wc.ui.product
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Html
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.squareup.picasso.Picasso
|
||||
import me.gilo.wc.R
|
||||
|
||||
import kotlinx.android.synthetic.main.activity_product.*
|
||||
import kotlinx.android.synthetic.main.content_product.*
|
||||
import me.gilo.wc.common.BaseActivity
|
||||
import me.gilo.wc.common.Status
|
||||
import me.gilo.wc.ui.state.ProgressDialogFragment
|
||||
import me.gilo.wc.viewmodels.ProductViewModel
|
||||
import me.gilo.woodroid.models.Product
|
||||
|
||||
class ProductActivity : BaseActivity() {
|
||||
|
||||
lateinit var viewModel: ProductViewModel
|
||||
val TAG = this::getLocalClassName
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_product)
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
viewModel = getViewModel(ProductViewModel::class.java)
|
||||
|
||||
title = "Product"
|
||||
|
||||
val productId = intent.getIntExtra("productId", 0)
|
||||
|
||||
if (productId != 0){
|
||||
product(productId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun product(productId : Int) {
|
||||
viewModel.product(productId).observe(this, android.arch.lifecycle.Observer { response ->
|
||||
when (response!!.status()) {
|
||||
Status.LOADING -> {
|
||||
|
||||
}
|
||||
|
||||
Status.SUCCESS -> {
|
||||
val product = response.data()
|
||||
setUpPage(product)
|
||||
|
||||
}
|
||||
|
||||
Status.ERROR -> {
|
||||
|
||||
}
|
||||
|
||||
Status.EMPTY -> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun setUpPage(product: Product) {
|
||||
tvTitle.text = product.name
|
||||
tvDescription.text = Html.fromHtml(product.description)
|
||||
|
||||
if (product.images != null && product.images.isNotEmpty()){
|
||||
Picasso.with(baseContext).load(product.images[0].src).into(ivImage)
|
||||
}
|
||||
|
||||
if (product.isOn_sale) {
|
||||
tvCallToAction.text = Html.fromHtml(product.price_html)
|
||||
|
||||
tvOnSale.visibility = View.VISIBLE
|
||||
}else{
|
||||
tvCallToAction.text = Html.fromHtml(product.price_html)
|
||||
tvOnSale.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var progressDialog: ProgressDialogFragment
|
||||
|
||||
fun showLoading(title: String, message: String) {
|
||||
val manager = supportFragmentManager
|
||||
progressDialog = ProgressDialogFragment.newInstance(title, message)
|
||||
progressDialog.isCancelable = false
|
||||
progressDialog.show(manager, "progress")
|
||||
}
|
||||
|
||||
fun showLoading() {
|
||||
showLoading("This will only take a sec", "Loading")
|
||||
}
|
||||
|
||||
fun stopShowingLoading() {
|
||||
progressDialog.dismiss()
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,6 +21,10 @@ public final class ProductViewModel extends ViewModel {
|
||||
return productRepository.products();
|
||||
}
|
||||
|
||||
public WooLiveData<Product> product(int productId) {
|
||||
return productRepository.product(productId);
|
||||
}
|
||||
|
||||
public WooLiveData<List<Product>> search(String term) {
|
||||
return productRepository.search(term);
|
||||
}
|
||||
|
||||
34
app/src/main/res/layout/activity_product.xml
Normal file
34
app/src/main/res/layout/activity_product.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.product.ProductActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"/>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_product"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
app:srcCompat="@android:drawable/ic_dialog_email"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
103
app/src/main/res/layout/content_product.xml
Normal file
103
app/src/main/res/layout/content_product.xml
Normal file
@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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"
|
||||
tools:ignore="MissingPrefix"
|
||||
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">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvOnSale"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|left"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="#ffffff"
|
||||
android:text="SALE!"
|
||||
fontPath="@string/font_medium"
|
||||
android:padding="8dp"
|
||||
/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:gravity="left"
|
||||
android:textColor="@color/text"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDescription"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
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"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCallToAction"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="0dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:gravity="left"
|
||||
android:padding="16dp"
|
||||
android:textColor="#1c5c9a"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@ -12,13 +12,31 @@
|
||||
android:orientation="vertical"
|
||||
tools:ignore="MissingPrefix">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvOnSale"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|left"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="#ffffff"
|
||||
android:text="SALE!"
|
||||
fontPath="@string/font_medium"
|
||||
android:padding="8dp"
|
||||
/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
fontPath="@string/font_medium"
|
||||
|
||||
@ -13,5 +13,6 @@
|
||||
<string name="search_title">search</string>
|
||||
<string name="search_hint">Search product</string>
|
||||
<string name="title_activity_product_search">ProductSearchActivity</string>
|
||||
<string name="title_activity_product">ProductActivity</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user