房间相册UI

This commit is contained in:
wzq
2023-10-13 19:37:38 +08:00
parent a6e6992b1a
commit 4a6892d0c6
18 changed files with 514 additions and 1 deletions

View File

@@ -212,6 +212,9 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View File

@@ -1086,6 +1086,8 @@
</intent-filter>
</activity>
<activity android:name=".avroom.activity.RoomAlbumActivity" />
</application>
</manifest>

View File

@@ -0,0 +1,145 @@
package com.yizhuan.erban.avroom.activity
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.graphics.Canvas
import android.graphics.LinearGradient
import android.graphics.Shader
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.yizhuan.erban.R
import com.yizhuan.erban.avroom.fragment.RoomAlbumFragment
import com.yizhuan.erban.avroom.model.RoomAlbumViewModel
import com.yizhuan.erban.base.BaseViewBindingActivity
import com.yizhuan.erban.databinding.ActivityRoomAlbumBinding
import com.yizhuan.erban.ui.widget.magicindicator.ViewPagerHelper
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.CommonNavigator
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.indicators.GradientLinePagerIndicator
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView
class RoomAlbumActivity : BaseViewBindingActivity<ActivityRoomAlbumBinding>() {
val viewModel: RoomAlbumViewModel by viewModels()
override fun init() {
initTitleBar(getString(R.string.room_album))
mTitleBar.setBackgroundResource(R.color.color_F5F6FA)
val titles = listOf("我的照片", "普通照片", "解鎖照片")
//binding.tvUpload.setImageResource(R.drawable.bg_activity_room_album_upload)
binding.indicator.navigator = CommonNavigator(this).apply {
isAdjustMode = true
adapter = object : CommonNavigatorAdapter() {
var startColor = ContextCompat.getColor(context, R.color.color_5CF1FF)
var endColor = ContextCompat.getColor(context, R.color.color_CF70FF)
override fun getCount(): Int {
return 3
}
override fun getTitleView(context: Context, index: Int): IPagerTitleView {
return ColorTransitionPagerTitleView(context).apply {
normalColor = ContextCompat.getColor(context, R.color.color_767585)
selectedColor = ContextCompat.getColor(context, R.color.color_1F1B4F)
text = titles[index]
}
}
override fun getIndicator(context: Context?): IPagerIndicator {
return object : GradientLinePagerIndicator(context) {
@SuppressLint("DrawAllocation")
override fun onDraw(canvas: Canvas) {
val g = LinearGradient(
lineRect.left,
lineRect.top,
lineRect.right,
lineRect.bottom,
intArrayOf(startColor, endColor),
null,
Shader.TileMode.CLAMP
)
paint.shader = g
canvas.drawRoundRect(lineRect, roundRadius, roundRadius, paint)
}
}.apply {
lineHeight = resources.getDimensionPixelOffset(R.dimen.dp_4).toFloat()
lineWidth = resources.getDimensionPixelOffset(R.dimen.dp_15).toFloat()
roundRadius = resources.getDimensionPixelOffset(R.dimen.dp_2).toFloat()
//yOffset = resources.getDimensionPixelOffset(R.dimen.dp_4).toFloat()
mode = LinePagerIndicator.MODE_EXACTLY
}
}
}
}
ViewPagerHelper.bind(binding.indicator, binding.vp)
val fragments = listOf(
RoomAlbumFragment.newInstance(),
RoomAlbumFragment.newInstance(),
RoomAlbumFragment.newInstance()
)
binding.vp.adapter = object : FragmentStateAdapter(this) {
override fun getItemCount(): Int {
return fragments.size
}
override fun createFragment(position: Int): Fragment {
return fragments[position]
}
}
//binding.vp.adapter = object :
// BaseQuickAdapter<String, BaseViewHolder>(R.layout.common_recyclerview, titles) {
// override fun convert(helper: BaseViewHolder, item: String) {
// val recyclerView = helper.getView<RecyclerView>(R.id.recycler_view)
// recyclerView.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
// recyclerView.layoutManager = GridLayoutManager(this@RoomAlbumActivity, 2)
// val offset = resources.getDimensionPixelOffset(R.dimen.dp_15)
// recyclerView.addItemDecoration(
// GridSpacingItemNewDecoration(
// offset,
// offset,
// true
// )
// )
// recyclerView.adapter =
// object : BaseQuickAdapter<Int, BaseViewHolder>(R.layout.item_room_album) {
// override fun convert(helper: BaseViewHolder, item: Int?) {
// ImageLoadUtils.loadImageWithBlur(
// context,
// "https://image.hfighting.com/FsElQzIALqAixbAT56riNMotkAZR?imageslim",
// helper.getView(R.id.iv_pic),
// 25, 4
// )
//
// }
// }.apply {
// val list = mutableListOf<Int>()
// for (i in 0 until 20) {
// list.add(0)
// }
// setNewData(list)
// }
// }
//}
}
companion object {
@JvmStatic
fun start(context: Context) {
val starter = Intent(context, RoomAlbumActivity::class.java)
context.startActivity(starter)
}
}
}

View File

@@ -39,7 +39,7 @@ class RoomPKBoardView @JvmOverloads constructor(
) : DragLayout(context, attrs, defStyleAttr) {
private val binding = LayoutRoomPkBoardViewBinding.inflate(LayoutInflater.from(context))
private val observer = Observer<RoomPkBean> { updateView(it) }
private val observer = Observer<RoomPkBean?> { updateView(it) }
private var disposable: Disposable? = null
private lateinit var helpPopupWindow: PopupWindow
private var roomPkBean: RoomPkBean? = null

View File

@@ -0,0 +1,51 @@
package com.yizhuan.erban.avroom.fragment
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yizhuan.erban.R
import com.yizhuan.erban.base.BaseViewBindingFragment
import com.yizhuan.erban.databinding.FragmentRoomAlbumBinding
import com.yizhuan.erban.ui.widget.recyclerview.decoration.GridSpacingItemNewDecoration
class RoomAlbumFragment : BaseViewBindingFragment<FragmentRoomAlbumBinding>() {
private val viewModel: RoomAlbumViewModel by viewModels()
override fun init() {
binding.recyclerView.layoutManager = GridLayoutManager(context, 2)
val offset = resources.getDimensionPixelOffset(R.dimen.dp_15)
binding.recyclerView.addItemDecoration(
GridSpacingItemNewDecoration(
offset,
offset,
true
)
)
binding.recyclerView.adapter =
object : BaseQuickAdapter<Int, BaseViewHolder>(R.layout.item_room_album) {
override fun convert(helper: BaseViewHolder, item: Int?) {
//ImageLoadUtils.loadImageWithBlur(
// context,
// "https://image.hfighting.com/FsElQzIALqAixbAT56riNMotkAZR?imageslim",
// helper.getView(R.id.iv_pic),
// 25, 4
//)
}
}.apply {
val list = mutableListOf<Int>()
for (i in 0 until 20) {
list.add(0)
}
setNewData(list)
}
}
companion object {
fun newInstance() = RoomAlbumFragment()
}
}

View File

@@ -0,0 +1,6 @@
package com.yizhuan.erban.avroom.fragment
import com.yizhuan.erban.base.BaseViewModel
class RoomAlbumViewModel : BaseViewModel() {
}

View File

@@ -0,0 +1,9 @@
package com.yizhuan.erban.avroom.model
import com.yizhuan.erban.base.BaseViewModel
class RoomAlbumViewModel :BaseViewModel(){
init {
}
}

View File

@@ -0,0 +1,92 @@
package com.yizhuan.erban.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import com.yizhuan.erban.R;
/**
* @author wzq
*/
public class ShadowFrameLayout extends FrameLayout {
private Paint mShadowPaint;
private float mCornerRadius;
/**
* 只有上面有阴影
*/
private boolean mShadowTop;
private float mShadowRadius;
private RectF mRectF;
public ShadowFrameLayout(@NonNull Context context) {
this(context, null);
}
public ShadowFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ShadowFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShadowFrameLayout);
int shadowColor = typedArray.getColor(R.styleable.ShadowFrameLayout_shadowColor,
ContextCompat.getColor(context, R.color.color_1E686868));
int backgroundColor = typedArray.getColor(R.styleable.ShadowFrameLayout_backgroundColor, Color.WHITE);
mShadowRadius = typedArray.getDimension(R.styleable.ShadowFrameLayout_shadowRadius, 0);
mCornerRadius = typedArray.getDimension(R.styleable.ShadowFrameLayout_cornerRadius, 0);
mShadowTop = typedArray.getBoolean(R.styleable.ShadowFrameLayout_shadowTop, false);
typedArray.recycle();
mShadowPaint = new Paint();
mShadowPaint.setShadowLayer(mShadowRadius, 0, 0, shadowColor);
mShadowPaint.setAntiAlias(true);
mShadowPaint.setColor(backgroundColor);
setLayerType(LAYER_TYPE_SOFTWARE, null);
mRectF = new RectF();
}
@Override
public void setBackgroundColor(@ColorInt int color) {
mShadowPaint.setColor(color);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
if (mShadowTop) {
// 矩形只有上方有阴影
mRectF.set(0, mShadowRadius, measuredWidth, measuredHeight + mCornerRadius);
} else {
// 环绕阴影
mRectF.set(mShadowRadius, mShadowRadius, measuredWidth - mShadowRadius, measuredHeight - mShadowRadius);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
canvas.drawRoundRect(mRectF, mCornerRadius, mCornerRadius, mShadowPaint);
super.dispatchDraw(canvas);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/black_transparent_60" />
<corners
android:bottomLeftRadius="@dimen/dp_8"
android:bottomRightRadius="@dimen/dp_8"
android:topRightRadius="@dimen/dp_8" />
</shape>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners
android:bottomLeftRadius="@dimen/dp_8"
android:topRightRadius="@dimen/dp_8" />
<solid android:color="@color/color_9168FA" />
</shape>
</item>
<item
android:bottom="@dimen/dp_8"
android:left="@dimen/dp_13"
android:right="@dimen/dp_13"
android:top="@dimen/dp_8">
<shape>
<solid android:color="@color/white" />
<corners android:radius="@dimen/dp_2" />
</shape>
</item>
<item
android:bottom="@dimen/dp_8"
android:left="@dimen/dp_8"
android:right="@dimen/dp_18"
android:top="@dimen/dp_8">
<shape>
<solid android:color="@color/white" />
<corners android:radius="@dimen/dp_2" />
</shape>
</item>
<item
android:bottom="@dimen/dp_8"
android:left="@dimen/dp_18"
android:right="@dimen/dp_8"
android:top="@dimen/dp_8">
<shape>
<solid android:color="@color/white" />
<corners android:radius="@dimen/dp_2" />
</shape>
</item>
</layer-list>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_F5F6FA">
<com.yizhuan.erban.base.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_constraintTop_toTopOf="parent" />
<com.yizhuan.erban.ui.widget.magicindicator.MagicIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_44"
app:layout_constraintTop_toBottomOf="@id/title_bar" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/indicator" />
<TextView
android:id="@+id/tv_upload"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_94"
android:layout_marginStart="@dimen/dp_36"
android:layout_marginEnd="@dimen/dp_36"
android:layout_marginBottom="@dimen/dp_40"
android:background="@drawable/bg_activity_room_album_upload"
android:gravity="center"
android:text="@string/upload_picture"
android:textColor="@color/white"
android:textSize="@dimen/sp_16"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadingEdge="vertical"
android:fadingEdgeLength="@dimen/dp_60"
android:requiresFadingEdge="vertical" />

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<com.yizhuan.erban.view.ShadowFrameLayout 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="@dimen/dp_170"
android:padding="@dimen/dp_4"
app:cornerRadius="@dimen/dp_8"
app:shadowRadius="@dimen/dp_4"
tools:layout_gravity="center"
tools:layout_width="@dimen/dp_170">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/default_cover"
app:riv_corner_radius="@dimen/dp_8" />
<ImageView
android:id="@+id/iv_lock"
android:layout_width="@dimen/dp_36"
android:layout_height="@dimen/dp_36"
android:src="@drawable/ic_lock_room_album"
app:layout_constraintBottom_toBottomOf="@id/iv_pic"
app:layout_constraintEnd_toEndOf="@id/iv_pic"
app:layout_constraintStart_toStartOf="@id/iv_pic"
app:layout_constraintTop_toTopOf="@id/iv_pic" />
<View
android:id="@+id/iv_action"
android:layout_width="@dimen/dp_28"
android:layout_height="@dimen/dp_18"
android:background="@drawable/bg_room_album_action"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/v_bottom_mask"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_32"
android:background="@drawable/bg_mask_room_album"
app:layout_constraintBottom_toBottomOf="parent" />
<ImageView
android:id="@+id/iv_gift"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:layout_marginStart="@dimen/dp_8"
android:src="@drawable/default_cover"
app:layout_constraintBottom_toBottomOf="@id/v_bottom_mask"
app:layout_constraintStart_toStartOf="@id/v_bottom_mask"
app:layout_constraintTop_toTopOf="@id/v_bottom_mask" />
<ImageView
android:id="@+id/iv_diamond"
android:layout_width="@dimen/dp_16"
android:layout_height="@dimen/dp_16"
android:layout_marginStart="@dimen/dp_6"
android:src="@mipmap/ic_charge_diamond"
app:layout_constraintBottom_toBottomOf="@id/v_bottom_mask"
app:layout_constraintStart_toEndOf="@id/iv_gift"
app:layout_constraintTop_toTopOf="@id/v_bottom_mask" />
<TextView
android:id="@+id/tv_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_2"
android:text="@string/zero"
android:textColor="@color/white"
android:textSize="@dimen/sp_14"
app:layout_constraintBottom_toBottomOf="@id/v_bottom_mask"
app:layout_constraintStart_toEndOf="@id/iv_diamond"
app:layout_constraintTop_toTopOf="@id/v_bottom_mask" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.yizhuan.erban.view.ShadowFrameLayout>

View File

@@ -420,4 +420,12 @@
</attr>
</declare-styleable>
<declare-styleable name="ShadowFrameLayout">
<attr name="shadowColor" format="color" />
<attr name="shadowRadius" format="dimension" />
<attr name="backgroundColor" format="color" />
<attr name="cornerRadius" format="dimension" />
<attr name="shadowTop" format="boolean" />
</declare-styleable>
</resources>

View File

@@ -700,5 +700,6 @@
<color name="color_A974FF">#A974FF</color>
<color name="color_C2A66FFF">#C2A66FFF</color>
<color name="color_306065">#306065</color>
<color name="color_1E686868">#1E686868</color>
</resources>

View File

@@ -5134,5 +5134,7 @@
<string name="please_input_quantity">輸入數量</string>
<string name="tips_fairy_resolve_low">分解普通精靈將隨機獲得80-100個碎片</string>
<string name="tips_fairy_resolve_high">分解傳說精靈將隨機獲得400-500個碎片</string>
<string name="upload_picture">上傳照片</string>
<string name="room_album">房間相冊</string>
</resources>