Commit 03b6befb authored by jyx's avatar jyx

代码优化

parent 447910b6
......@@ -9,8 +9,11 @@ import com.mints.helivideo.manager.UserManager
import com.mints.helivideo.mvp.model.UserBean
import com.mints.helivideo.mvp.presenters.MyPresenter
import com.mints.helivideo.mvp.views.MyView
import com.mints.helivideo.ui.activitys.SettingsActivity
import com.mints.helivideo.ui.adapter.TasksAdapter
import com.mints.helivideo.ui.fragment.base.LazyLoadBaseFragment
import com.mints.helivideo.ui.fragment.draw.DrawCashDialog
import com.mints.helivideo.utils.SpanUtils
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.fragment_main_my.*
......@@ -25,6 +28,8 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
private val userManager by lazy { UserManager.getInstance() }
private var tasksAdapter: TasksAdapter? = null
private var drawCashDialog: DrawCashDialog? = null
override fun getContentViewLayoutID() = R.layout.fragment_main_my
override fun initViewsAndEvents() {
......@@ -68,11 +73,18 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
override fun onClick(v: View?) {
if (AntiShake.check(v?.id)) return
// when (v?.id) {
// R.id.tv_my_btn -> {
// }
// }
when (v?.id) {
R.id.civ_my -> { // 跳转设置页
readyGo(SettingsActivity::class.java)
}
R.id.btn_my_draw -> { // 提现
showDrawCashDialog()
}
R.id.btn_task -> { // 任务,领金元宝
}
R.id.tv_my_explain -> { // 收益说明
}
}
}
override fun getUserSuc(data: UserBean) {
......@@ -80,52 +92,44 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
}
private fun loginStatus(consumer: UserBean) {
// // 1-匹配用户
// if (consumer.activiteFlag == 1) {
// // 匹配
// ll_my_vip.visibility = View.VISIBLE
// ll_my_payrecord.visibility = View.VISIBLE
// ll_contactus.visibility = View.VISIBLE
// line_my_payrecord.visibility = View.VISIBLE
// line_my_contactus.visibility = View.VISIBLE
// } else {
// // 未匹配
// ll_my_vip.visibility = View.GONE
// ll_my_payrecord.visibility = View.GONE
// ll_contactus.visibility = View.GONE
// line_my_payrecord.visibility = View.GONE
// line_my_contactus.visibility = View.GONE
// }
//
// // 2-是否有手机号
// if (!TextUtils.isEmpty(userManager.mobile)) {
// tv_my_account.text = "手机号:" + consumer.mobile.substring(0,3)+"****"+consumer.mobile.substring(consumer.mobile.length-4)
// iv_my_bind.visibility = View.GONE
// } else {
// tv_my_account.text = "绑定手机号"
// iv_my_bind.visibility = View.VISIBLE
// }
// tv_my_id.text = "用户ID:"+consumer.idcode
//
// // 3-vip
// if (consumer.expireTime > 0) {
// tv_my_vip.text = "VIP会员"
// tv_my_btn.visibility = View.GONE
// if (consumer.isForever) {
// tv_my_status.text = "有效期: 永久有效"
// } else {
// tv_my_status.text =
// "到期时间 ${TimeRender.formatDate(consumer.expireTime, TimeRender.ALL_FORMAT_LINE)}"
// }
// } else {
// tv_my_vip.text = "开通VIP会员"
// tv_my_status.text = "解锁全部短剧"
// tv_my_btn.visibility = View.VISIBLE
// tv_my_btn.text = "立即开通"
// }
}
private fun initListener() {
btn_my_draw.setOnClickListener(this)
btn_task.setOnClickListener(this)
tv_my_explain.setOnClickListener(this)
civ_my.setOnClickListener(this)
rg_my_income.setOnCheckedChangeListener { group, checkedId ->
if (checkedId == R.id.rb_my_cash) {
tv_my_title.text = "红包余额(元)"
tv_my_money.text = SpanUtils()
.setFontSize(30, true)
.append(" ")
.setFontSize(14, true)
.append(" ≈ ")
.create()
} else {
tv_my_title.text = "金元宝余额(个)"
tv_my_money.text = SpanUtils()
.setFontSize(30, true)
.append(" ")
.setFontSize(14, true)
.append(" ≈ ")
.create()
}
}
}
private fun showDrawCashDialog() {
drawCashDialog = DrawCashDialog()
drawCashDialog?.let {
if (!it.isAdded && !it.isVisible && !it.isRemoving) {
it.show(supportFragmentManager, this.javaClass.simpleName)
} else {
supportFragmentManager.beginTransaction().show(it)
}
}
}
}
\ No newline at end of file
......@@ -8,6 +8,10 @@ class RedpkgFragment : LazyLoadBaseFragment() {
override fun getContentViewLayoutID() = R.layout.fragment_redpkg
override fun initViewsAndEvents() {
}
}
\ No newline at end of file
package com.mints.helivideo.ui.fragment.draw
import android.graphics.Typeface
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import com.google.android.material.tabs.TabLayoutMediator
import com.mints.helivideo.R
import com.mints.helivideo.ui.widgets.bottomsheet.BaseBottomSheetDialog
/**
*
* @desc 提现弹框
*/
class DrawCashDialog : BaseBottomSheetDialog() {
private lateinit var tabLayout: TabLayout
private lateinit var vp2: ViewPager2
private val tabsData = mutableListOf<Int>()
private var vpAdapter: DrawPageAdapter? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val rootView = inflater.inflate(R.layout.dialog_drawcash, container)
initView(rootView)
return rootView
}
private fun initView(rootView: View) {
tabsData.add(DrawCashFragment.DRAW_TYPE_CASH)
tabsData.add(DrawCashFragment.DRAW_TYPE_GOLD)
tabLayout = rootView.findViewById(R.id.tab_draw)
vp2 = rootView.findViewById(R.id.vp2_draw)
vpAdapter = DrawPageAdapter(tabsData, this)
vp2.adapter = vpAdapter
// 处理嵌套滑动冲突
(vp2.getChildAt(0) as RecyclerView).isNestedScrollingEnabled = false
TabLayoutMediator(tabLayout, vp2) { tab, position ->
// 初始化Tab
tab.id = position
if (tabsData.size > 0) {
tab.customView = getTabView(tabsData[position])
}
}.attach()
tabLayout.addOnTabSelectedListener(object : OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
updateTab(tab, true)
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
updateTab(tab, false)
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
})
}
private fun updateTab(tab: TabLayout.Tab?, isSelected: Boolean) {
tab?.customView?.let {
val text = it.findViewById<TextView>(R.id.item_tv)
val indicator = it.findViewById<View>(R.id.item_indicator)
if (isSelected) {
indicator.visibility = View.VISIBLE
text.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
text.setTextColor(ContextCompat.getColor(requireContext(), R.color.black_text))
} else {
indicator.visibility = View.INVISIBLE
text.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
text.setTextColor(ContextCompat.getColor(requireContext(), R.color.color_8D8F90))
}
}
}
private fun getTabView(type: Int): View {
val view = LayoutInflater.from(requireContext()).inflate(R.layout.item_draw_tab, null)
if (type == DrawCashFragment.DRAW_TYPE_CASH) {
view.findViewById<View>(R.id.item_indicator).visibility = View.VISIBLE
view.findViewById<TextView>(R.id.item_tv).text = "红包提现"
} else {
view.findViewById<View>(R.id.item_indicator).visibility = View.INVISIBLE
view.findViewById<TextView>(R.id.item_tv).text = "金元宝提现"
}
return view
}
// 提现
private fun drawCash() {
// if (rbWechat.isChecked) wechatDrawCash()
// else alipayDrawCash()
}
// 微信提现
private fun wechatDrawCash() {
}
// 支付宝提现
private fun alipayDrawCash() {
}
}
\ No newline at end of file
package com.mints.helivideo.ui.fragment.draw
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.mints.helivideo.R
import com.mints.helivideo.ui.fragment.base.BaseFragment
import com.mints.helivideo.utils.SpanUtils
import kotlinx.android.synthetic.main.fragment_draw.*
class DrawCashFragment : BaseFragment() {
companion object {
const val DRAW_TYPE = "DRAW_TYPE"
const val DRAW_TYPE_CASH = 0x001
const val DRAW_TYPE_GOLD = 0x002
fun newInstance(type: Int): Fragment {
val args = Bundle()
args.putInt(DRAW_TYPE, type)
val fragment = DrawCashFragment()
fragment.arguments = args
return fragment
}
}
private var drawType = DRAW_TYPE_CASH
override fun initViewsAndEvents() {
arguments?.let {
drawType = it.getInt(DRAW_TYPE, DRAW_TYPE_CASH)
}
if (drawType == DRAW_TYPE_CASH) {
tv_title.text = "红包余额(元)"
tv_cash.text = SpanUtils()
.append("90.00")
.setFontSize(30, true)
.append("≈ 900000个")
.setFontSize(16, true)
.create()
} else {
tv_title.text = "金元宝余额(个)"
tv_cash.text = SpanUtils()
.append("90.00")
.setFontSize(30, true)
.append("≈ 0.00元")
.setFontSize(16, true)
.create()
}
}
override fun getContentViewLayoutID() = R.layout.fragment_draw
}
\ No newline at end of file
package com.mints.helivideo.ui.fragment.draw
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
class DrawPageAdapter(
private val data: List<Int>,
fragment: Fragment
) :
FragmentStateAdapter(fragment) {
private val fragments = mutableMapOf<Int, Fragment>()
override fun getItemId(position: Int): Long {
return data[position].toLong()
}
override fun getItemCount() = data.size
override fun createFragment(position: Int): Fragment {
val newFragment = DrawCashFragment.newInstance(data[position])
fragments[position] = newFragment
return newFragment
}
override fun containsItem(itemId: Long): Boolean {
data.forEach {
if (it.toLong() == itemId) {
return true
}
}
return false
}
fun getFragments(): MutableMap<Int, Fragment> {
return fragments
}
}
\ No newline at end of file
package com.mints.helivideo.ui.widgets.bottomsheet
import android.widget.FrameLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.mints.helivideo.R
open class BaseBottomSheetDialog : BottomSheetDialogFragment() {
private var bottomSheet: FrameLayout? = null
private var behavior: BottomSheetBehavior<FrameLayout>? = null
override fun onStart() {
super.onStart()
val dialog = dialog as BottomSheetDialog?
bottomSheet = dialog!!.delegate.findViewById(com.google.android.material.R.id.design_bottom_sheet)
if (bottomSheet != null) {
val layoutParams = bottomSheet!!.layoutParams as CoordinatorLayout.LayoutParams
layoutParams.height = CoordinatorLayout.LayoutParams.WRAP_CONTENT
bottomSheet!!.layoutParams = layoutParams
behavior = BottomSheetBehavior.from(bottomSheet!!)
behavior!!.peekHeight = getHeight()
// 初始为展开状态
behavior!!.state = BottomSheetBehavior.STATE_EXPANDED
}
}
override fun getTheme(): Int {
return R.style.BottomDialog
}
protected open fun getHeight(): Int {
return resources.displayMetrics.heightPixels
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:background="@drawable/shape_tab_friends"
android:orientation="vertical"
android:padding="@dimen/dp_10">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_draw"
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabBackground="@null"
app:tabIndicatorColor="@color/color_F61F03"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabRippleColor="@null"
app:tabSelectedTextColor="@color/black"
app:tabTextColor="@color/gray" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vp2_draw"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="红包余额(元)" />
<TextView
android:id="@+id/tv_cash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="90.00 ≈ 900000个"
android:textColor="@color/black"
android:textSize="20sp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ry_draw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/dp_10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="提现方式"
android:textColor="@color/black" />
<RadioGroup
android:id="@+id/rg_draw"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:padding="10dp">
<RadioButton
android:id="@+id/rb_wechat"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:text="微信" />
<RadioButton
android:id="@+id/rb_alipay"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:text="支付宝" />
</RadioGroup>
<Button
android:id="@+id/btn_draw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginEnd="@dimen/dp_10"
android:text="去提现" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/item_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:textColor="@color/color_8D8F90"
android:textSize="16sp"
android:textStyle="bold" />
<View
android:id="@+id/item_indicator"
android:layout_width="30dp"
android:layout_height="2dp"
android:background="@color/red"
android:visibility="invisible" />
</LinearLayout>
\ No newline at end of file
......@@ -77,5 +77,18 @@
<item name="android:button">@drawable/checkbox_style</item>
</style>
<style name="BottomDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowAnimationStyle">@style/BottomDialog.AnimationStyle</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
<style name="BottomDialog.AnimationStyle" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/push_bottom_in</item>
<item name="android:windowExitAnimation">@anim/push_bottom_out</item>
</style>
</resources>
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