Commit 8097f831 by wjg

init

parent daa586fa
......@@ -24,8 +24,6 @@ import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHolder> {
private Context mContext;
......@@ -74,16 +72,16 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
Glide.with(mContext).load(goods.getPics().getThumbnail()).apply(options).into(imgThumbnail);
}
Sku sku = getDefaultSku(goods.getSkus());
Sku sku = Utils.getDefaultSku(goods.getSkus());
if (sku == null) {
helper.setText(R.id.txt_price, String.valueOf(goods.getPrice()));
helper.setText(R.id.txt_discount, String.valueOf(goods.getDiscount()));
helper.setText(R.id.txt_price, Utils.toString(goods.getPrice()));
helper.setText(R.id.txt_discount, Utils.toString(goods.getDiscount()));
helper.setGone(R.id.txt_sellout, true);
helper.setGone(R.id.butn_add, false);
} else {
helper.setText(R.id.txt_price, String.valueOf(sku.getPrice()));
helper.setText(R.id.txt_discount, String.valueOf(sku.getDiscount()));
helper.setText(R.id.txt_price, Utils.toString(sku.getPrice()));
helper.setText(R.id.txt_discount, Utils.toString(sku.getDiscount()));
if (Base.TRUE.equals(sku.getState())) {
helper.setGone(R.id.txt_sellout, false);
......@@ -105,10 +103,10 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
helper.setGone(R.id.img_recommend, false);
}
TextView icoDiscount = helper.getView(R.id.ico_discount);
TextView txtDiscount = helper.getView(R.id.txt_discount);
icoDiscount.setPaintFlags(icoDiscount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtDiscount.setPaintFlags(txtDiscount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
TextView icoPrice = helper.getView(R.id.ico_price);
TextView txtPrice = helper.getView(R.id.txt_price);
icoPrice.setPaintFlags(icoPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtPrice.setPaintFlags(txtPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
View layoutItem = helper.getView(R.id.layout_item);
layoutItem.setOnClickListener(v -> Utils.showGoodsDetail(mContext, goods));
......@@ -123,22 +121,6 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
}
}
/** 获取SKU,优选获取默认的SKU */
private Sku getDefaultSku(List<Sku> skus) {
if (CollectionUtils.isEmpty(skus)) {
return null;
}
Optional<Sku> optional = skus.stream().filter(x -> Base.TRUE.equals(x.getIsDefault()) && Base.TRUE.equals(x.getState())).findAny();
if (optional.isPresent()) {
return optional.get();
}
optional = skus.stream().filter(x -> Base.TRUE.equals(x.getState())).findAny();
if (optional.isPresent()) {
return optional.get();
}
return skus.get(0);
}
private boolean trolleyState = false;
public boolean isTrolleyState() {
......
......@@ -38,9 +38,9 @@ public class TrolleyAdapter extends BaseAdapter {
ImageView imgThumbnail = convertView.findViewById(R.id.img_thumbnail);
TextView txtName = convertView.findViewById(R.id.txt_name);
TextView txtOptions = convertView.findViewById(R.id.txt_options);
TextView icoPrice = convertView.findViewById(R.id.ico_price);
TextView txtPrice = convertView.findViewById(R.id.txt_price);
TextView txtDiscount = convertView.findViewById(R.id.txt_discount);
TextView icoDiscount = convertView.findViewById(R.id.ico_discount);
View butnSubtract = convertView.findViewById(R.id.butn_subtract);
TextView txtCount = convertView.findViewById(R.id.txt_count);
View butnAdd = convertView.findViewById(R.id.butn_add);
......@@ -67,11 +67,11 @@ public class TrolleyAdapter extends BaseAdapter {
txtOptions.setVisibility(View.GONE);
}
txtPrice.setText(goods.getPrice().toString());
txtDiscount.setText(goods.getDiscount().toString());
txtPrice.setText(Utils.toString(goods.getPrice()));
txtDiscount.setText(Utils.toString(goods.getDiscount()));
icoDiscount.setPaintFlags(icoDiscount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtDiscount.setPaintFlags(txtDiscount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
icoPrice.setPaintFlags(icoPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtPrice.setPaintFlags(txtPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtCount.setText(goods.getCount().toString());
butnSubtract.setOnClickListener(v -> trolleyView.subtractGoods(position));
butnAdd.setOnClickListener(v -> trolleyView.addGoods(position));
......
package com.ihaoin.hooloo.device.component;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import java.util.List;
public class IntroViewPager extends ViewPager {
public IntroViewPager(@NonNull Context context) {
super(context);
}
public IntroViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (getAdapter() == null) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}
int index = getCurrentItem();
int height = 0;
View v = getView(index);
if (v != null) {
v.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
height = v.getMeasuredHeight();
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
private List<View> introViews;
public void setIntroViews(List<View> introViews) {
this.introViews = introViews;
this.setAdapter(pagerAdapter);
}
public View getView(int index) {
if (CollectionUtils.isEmpty(introViews)) {
return null;
}
return introViews.get(index);
}
public int getCount() {
if (pagerAdapter == null) {
return 0;
}
return pagerAdapter.getCount();
}
private PagerAdapter pagerAdapter = new PagerAdapter() {
@Override
public int getCount() {
return CollectionUtils.isEmpty(introViews) ? 0 : introViews.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
View view = introViews.get(position);
container.removeView(view);
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
if (CollectionUtils.isEmpty(introViews)) {
return null;
}
View view = introViews.get(position);
container.addView(view);
return view;
}
};
}
......@@ -8,6 +8,7 @@ import android.util.DisplayMetrics;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import androidx.coordinatorlayout.widget.ViewGroupUtils;
......@@ -22,7 +23,10 @@ import com.ihaoin.hooloo.device.view.GoodsDetailDialog;
import com.ihaoin.hooloo.device.view.SettingsActivity;
import com.ihaoin.hooloo.device.view.TipsDialog;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Optional;
public class Utils {
......@@ -123,4 +127,39 @@ public class Utils {
}));
group.setTouchDelegate(composite);
}
public static String toString(BigDecimal num) {
DecimalFormat df = new DecimalFormat("#.00");
return df.format(num);
}
/** 获取SKU,优选获取默认的SKU */
public static Sku getDefaultSku(List<Sku> skus) {
if (CollectionUtils.isEmpty(skus)) {
return null;
}
Optional<Sku> optional = skus.stream().filter(x -> Base.TRUE.equals(x.getIsDefault()) && Base.TRUE.equals(x.getState())).findAny();
if (optional.isPresent()) {
return optional.get();
}
optional = skus.stream().filter(x -> Base.TRUE.equals(x.getState())).findAny();
if (optional.isPresent()) {
return optional.get();
}
return skus.get(0);
}
public static void check(RadioGroup group, int position) {
if (group == null) {
return;
}
if (group.getChildCount() < position) {
return;
}
View v = group.getChildAt(position);
if (v == null) {
return;
}
group.check(v.getId());
}
}
......@@ -73,13 +73,12 @@ public class LauncherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(AppConfig.DEBUG_TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
mContext = this;
setMachineCode();
requestPermissions();
trolleyView = findViewById(R.id.view_trolley);
......@@ -87,7 +86,6 @@ public class LauncherActivity extends Activity {
recGoods = findViewById(R.id.rec_right);
recRecommends = findViewById(R.id.rec_recommend);
initRecommends();
setRecommendsData();
......@@ -347,15 +345,28 @@ public class LauncherActivity extends Activity {
@Override
protected void onDestroy() {
Log.d(AppConfig.DEBUG_TAG, "onDestroy");
super.onDestroy();
exit();
}
private void exit() {
Log.d(AppConfig.DEBUG_TAG, "exit");
this.unregistTrolleyGoodsChangedReceiver();
this.unregistTrolleyStateChangedReceiver();
this.unregistSettingChangedReceiver();
System.exit(0);
}
@Override
public void onBackPressed() {
super.onBackPressed();
exit();
}
private TrolleyGoodsChangedReceiver trolleyGoodsChangedReceiver = null;
private TrolleyStateChangedReceiver trolleyStateChangedReceiver = null;
private SettingChangedReceiver settingChangedReceiver;
/** 注册购物车广播 */
private void registTrolleyGoodsChangedReceiver() {
......@@ -426,9 +437,6 @@ public class LauncherActivity extends Activity {
}
}
private SettingChangedReceiver settingChangedReceiver;
private void registSettingChangedReceiver() {
settingChangedReceiver = new SettingChangedReceiver();
IntentFilter filter = new IntentFilter();
......
......@@ -174,7 +174,7 @@ public class TrolleyView extends RelativeLayout {
public void goodsChanged() {
this.trolleyAdapter.notifyDataSetChanged();
this.txtCount.setText(getCheckedCount().toString());
this.txtTotal.setText(getCheckedTotal().toString());
this.txtTotal.setText(Utils.toString(getCheckedTotal()));
this.setView();
this.measureListHeight();
}
......
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!-- <corners android:radius="2dp" />-->
<solid
android:width="1dp"
android:color="@color/textSecondPrimary" />
</shape>
</item>
<!-- <item-->
<!-- android:bottom="10dp"-->
<!-- android:left="10dp"-->
<!-- android:right="10dp"-->
<!-- android:top="10dp">-->
<!-- <bitmap-->
<!-- android:gravity="center"-->
<!-- android:src="@mipmap/jiahao_2x" />-->
<!-- </item>-->
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/textDisable" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<item android:drawable="@drawable/ic_dot" android:state_checked="true" />
<item android:drawable="@drawable/ic_dot_unchecked" />
</selector>
......@@ -63,7 +63,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding3">
<TextView
android:id="@+id/ico_price"
android:id="@+id/ico_discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
......@@ -72,32 +72,32 @@
android:textColor="@color/textRed"
android:textSize="@dimen/ts_goods_item_price" />
<TextView
android:id="@+id/txt_price"
android:id="@+id/txt_discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/ico_price"
android:layout_toRightOf="@id/ico_discount"
android:text="19.9"
android:textColor="@color/textRed"
android:textSize="@dimen/ts_goods_item_price"
android:textStyle="bold" />
<TextView
android:id="@+id/ico_discount"
android:id="@+id/ico_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="@dimen/padding5"
android:layout_toEndOf="@id/txt_price"
android:layout_toEndOf="@id/txt_discount"
android:text="¥"
android:textColor="@color/textSecondPrimary"
android:textSize="@dimen/ts_goods_item_discount" />
<TextView
android:id="@+id/txt_discount"
android:id="@+id/txt_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toEndOf="@id/ico_discount"
android:layout_toEndOf="@id/ico_price"
android:text="29.9"
android:textColor="@color/textSecondPrimary"
android:textSize="@dimen/ts_goods_item_discount" />
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_item"
android:layout_width="match_parent"
android:layout_height="wrap_content">
......@@ -8,25 +9,32 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding20"
android:layout_marginStart="@dimen/padding20"
android:layout_marginTop="@dimen/padding20"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="@dimen/ts_recommend_name"
android:textStyle="bold" />
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_intro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_name"
android:layout_marginStart="@dimen/padding20"
android:layout_marginTop="@dimen/padding10"
android:layout_marginBottom="@dimen/padding15"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="@dimen/ts_recommend_desc"
android:textStyle="bold" />
</RelativeLayout>
\ No newline at end of file
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txt_recommend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_spec_recommend"
android:paddingHorizontal="@dimen/padding5"
android:paddingVertical="@dimen/padding3"
android:text="推荐"
android:textColor="@color/white"
android:textSize="@dimen/ts_detail_spec_rec" />
......@@ -50,14 +50,14 @@
android:gravity="bottom"
android:orientation="horizontal">
<TextView
android:id="@+id/ico_price"
android:id="@+id/ico_discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="¥"
android:textColor="@color/textRed"
android:textSize="@dimen/ts_goods_item_price" />
<TextView
android:id="@+id/txt_price"
android:id="@+id/txt_discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="19.9"
......@@ -65,7 +65,7 @@
android:textSize="@dimen/ts_goods_item_price"
android:textStyle="bold" />
<TextView
android:id="@+id/ico_discount"
android:id="@+id/ico_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/padding5"
......@@ -73,7 +73,7 @@
android:textColor="@color/textSecondPrimary"
android:textSize="@dimen/ts_goods_item_discount" />
<TextView
android:id="@+id/txt_discount"
android:id="@+id/txt_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_root"
android:layout_width="@dimen/dialog_detail_width"
android:layout_height="match_parent">
......@@ -17,13 +18,27 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/padding10">
<ImageView
android:id="@+id/img_intro"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding10"
android:layout_weight="1"
android:adjustViewBounds="true" />
android:layout_weight="1">
<com.ihaoin.hooloo.device.component.IntroViewPager
android:id="@+id/intro_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioGroup
android:id="@+id/intro_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/padding10"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
......@@ -43,6 +58,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding10"
android:text="商品详细"
android:textColor="@color/textPrimary"
android:textSize="@dimen/ts_detail_spec"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/layout_images"
android:layout_width="match_parent"
......@@ -72,14 +95,14 @@
android:gravity="bottom"
android:orientation="horizontal">
<TextView
android:id="@+id/ico_price"
android:id="@+id/ico_discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="¥"
android:textColor="@color/textRed"
android:textSize="@dimen/ts_detail_price" />
<TextView
android:id="@+id/txt_price"
android:id="@+id/txt_discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
......@@ -89,7 +112,7 @@
android:textStyle="bold" />
<TextView
android:id="@+id/ico_discount"
android:id="@+id/ico_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/padding5"
......@@ -97,7 +120,7 @@
android:textColor="@color/textSecondPrimary"
android:textSize="@dimen/ts_detail_discount" />
<TextView
android:id="@+id/txt_discount"
android:id="@+id/txt_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment