From 4fb21002aa107a82fa00dddf378d3964be4d1d62 Mon Sep 17 00:00:00 2001 From: vice Date: Sat, 19 Sep 2020 19:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E4=B8=8D?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E7=A6=8F=E5=88=A9=E7=89=87=EF=BC=8C=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E5=8F=AF=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 5 ++ .../vicedev/zy_player_android/common/SPKey.kt | 11 ++++ .../zy_player_android/event/OpenFLEvent.kt | 14 +++++ .../ui/home/HomeSourceFragment.kt | 9 +++- .../ui/home/NewHomeFragment.kt | 34 +++++++++++- .../zy_player_android/ui/mine/MineFragment.kt | 6 +++ .../ui/reward/RewardActivity.kt | 3 +- .../ui/setting/SettingActivity.kt | 32 +++++++++++ .../ui/setting/SettingFragment.kt | 53 +++++++++++++++++++ .../zy_player_android/widgets/SetItemView.kt | 11 +++- app/src/main/res/layout/fragment_mine.xml | 22 +++++--- app/src/main/res/layout/fragment_setting.xml | 24 +++++++++ app/src/main/res/layout/set_item_view.xml | 20 +++++-- app/src/main/res/values/attrs.xml | 1 + 15 files changed, 233 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/vicedev/zy_player_android/common/SPKey.kt create mode 100644 app/src/main/java/com/vicedev/zy_player_android/event/OpenFLEvent.kt create mode 100644 app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingActivity.kt create mode 100644 app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingFragment.kt create mode 100644 app/src/main/res/layout/fragment_setting.xml diff --git a/app/build.gradle b/app/build.gradle index 9fd1ae0..3fcf695 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,6 +102,8 @@ dependencies { implementation 'org.greenrobot:eventbus:3.2.0' implementation 'cn.jzvd:jiaozivideoplayer:7.4.2' + + implementation 'com.github.zcweng:switch-button:0.0.3@aar' } android.applicationVariants.all { variant -> diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 62f3259..5623d84 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -60,6 +60,11 @@ android:launchMode="singleTop" android:screenOrientation="portrait" /> + + - !classify.id.isNullOrBlank() && !classify.name.isNullOrBlank() + !classify.id.isNullOrBlank() && !classify.name.isNullOrBlank() && + //筛去福利 + (if (openFL) true else (!classify.name.contains("福利") && !classify.name.contains( + "伦理" + ))) } as ArrayList) viewpager.adapter = ViewPageAdapter() viewpager.offscreenPageLimit = 100 diff --git a/app/src/main/java/com/vicedev/zy_player_android/ui/home/NewHomeFragment.kt b/app/src/main/java/com/vicedev/zy_player_android/ui/home/NewHomeFragment.kt index 8656b9c..721f01d 100644 --- a/app/src/main/java/com/vicedev/zy_player_android/ui/home/NewHomeFragment.kt +++ b/app/src/main/java/com/vicedev/zy_player_android/ui/home/NewHomeFragment.kt @@ -1,19 +1,24 @@ package com.vicedev.zy_player_android.ui.home import android.os.Bundle +import com.blankj.utilcode.util.SPUtils import com.lxj.xpopup.XPopup import com.lxj.xpopup.core.BasePopupView import com.lxj.xpopup.interfaces.OnSelectListener import com.vicedev.zy_player_android.R import com.vicedev.zy_player_android.common.ConfigManager +import com.vicedev.zy_player_android.common.SP_OPEN_FL import com.vicedev.zy_player_android.common.gone import com.vicedev.zy_player_android.common.textOrDefault +import com.vicedev.zy_player_android.event.OpenFLEvent import com.vicedev.zy_player_android.sources.BaseSource import com.vicedev.zy_player_android.ui.BaseFragment import com.vicedev.zy_player_android.ui.search.SearchActivity import com.wuhenzhizao.titlebar.widget.CommonTitleBar -import kotlinx.android.synthetic.main.fragment_home.* import kotlinx.android.synthetic.main.fragment_home_new.* +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode /** * @author vicedev @@ -25,6 +30,8 @@ class NewHomeFragment : BaseFragment() { private var selectSourceDialog: BasePopupView? = null + private var openFL = false + override fun getLayoutId(): Int = R.layout.fragment_home_new override fun initTitleBar(titleBar: CommonTitleBar?) { @@ -43,6 +50,8 @@ class NewHomeFragment : BaseFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) source = ConfigManager.curUseSourceConfig() + + openFL = SPUtils.getInstance().getBoolean(SP_OPEN_FL) } override fun initListener() { @@ -78,4 +87,27 @@ class NewHomeFragment : BaseFragment() { .commitNowAllowingStateLoss() } + override fun onStart() { + super.onStart() + EventBus.getDefault().register(this) + } + + override fun onStop() { + super.onStop() + if (EventBus.getDefault().isRegistered(this)) { + EventBus.getDefault().unregister(this) + } + } + + @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) + fun onMessageEvent(event: OpenFLEvent) { + if (openFL == event.open) { + //与当前一样,return + return + } + openFL = event.open + //不一样时重新加载数据 + initData() + } + } \ No newline at end of file diff --git a/app/src/main/java/com/vicedev/zy_player_android/ui/mine/MineFragment.kt b/app/src/main/java/com/vicedev/zy_player_android/ui/mine/MineFragment.kt index ddbeb13..3a6f305 100644 --- a/app/src/main/java/com/vicedev/zy_player_android/ui/mine/MineFragment.kt +++ b/app/src/main/java/com/vicedev/zy_player_android/ui/mine/MineFragment.kt @@ -6,6 +6,7 @@ import com.lxj.xpopup.interfaces.OnSelectListener import com.vicedev.zy_player_android.R import com.vicedev.zy_player_android.ui.BaseFragment import com.vicedev.zy_player_android.ui.reward.RewardActivity +import com.vicedev.zy_player_android.ui.setting.SettingActivity import com.vicedev.zy_player_android.utils.Utils import com.wuhenzhizao.titlebar.widget.CommonTitleBar import kotlinx.android.synthetic.main.fragment_mine.* @@ -60,5 +61,10 @@ class MineFragment : BaseFragment() { setFeedback.setOnClickListener { Utils.openBrowser(requireActivity(), "https://support.qq.com/product/281859") } + + //设置 + setSetting.setOnClickListener { + SettingActivity.jump(requireActivity()) + } } } diff --git a/app/src/main/java/com/vicedev/zy_player_android/ui/reward/RewardActivity.kt b/app/src/main/java/com/vicedev/zy_player_android/ui/reward/RewardActivity.kt index d2c4acc..89ac08e 100644 --- a/app/src/main/java/com/vicedev/zy_player_android/ui/reward/RewardActivity.kt +++ b/app/src/main/java/com/vicedev/zy_player_android/ui/reward/RewardActivity.kt @@ -12,11 +12,12 @@ import com.vicedev.zy_player_android.ui.search.SEARCH * @date 2020/9/13 0:40 * @desc 打赏 */ +const val REWARD = "reward" class RewardActivity : BaseActivity() { override fun initView() { supportFragmentManager .beginTransaction() - .replace(R.id.container, RewardFragment(), SEARCH) + .replace(R.id.container, RewardFragment(), REWARD) .commitAllowingStateLoss() } diff --git a/app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingActivity.kt b/app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingActivity.kt new file mode 100644 index 0000000..d91ac38 --- /dev/null +++ b/app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingActivity.kt @@ -0,0 +1,32 @@ +package com.vicedev.zy_player_android.ui.setting + +import android.app.Activity +import android.content.Intent +import com.vicedev.zy_player_android.R +import com.vicedev.zy_player_android.ui.BaseActivity + +/** + * @author vicedev + * @email vicedev1001@gmail.com + * @date 2020/9/13 0:40 + * @desc 设置 + */ +const val REWARD = "reward" + +class SettingActivity : BaseActivity() { + override fun initView() { + supportFragmentManager + .beginTransaction() + .replace(R.id.container, SettingFragment(), REWARD) + .commitAllowingStateLoss() + } + + override fun getLayoutId(): Int = R.layout.container_layout + + companion object { + fun jump(activity: Activity) { + activity.startActivity(Intent(activity, SettingActivity::class.java)) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingFragment.kt b/app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingFragment.kt new file mode 100644 index 0000000..249f019 --- /dev/null +++ b/app/src/main/java/com/vicedev/zy_player_android/ui/setting/SettingFragment.kt @@ -0,0 +1,53 @@ +package com.vicedev.zy_player_android.ui.setting + +import com.blankj.utilcode.util.SPUtils +import com.vicedev.zy_player_android.R +import com.vicedev.zy_player_android.common.SP_OPEN_FL +import com.vicedev.zy_player_android.event.OpenFLEvent +import com.vicedev.zy_player_android.ui.BaseFragment +import com.wuhenzhizao.titlebar.widget.CommonTitleBar +import kotlinx.android.synthetic.main.fragment_setting.* +import kotlinx.android.synthetic.main.set_item_view.view.* +import org.greenrobot.eventbus.EventBus + +/** + * @author vicedev + * @email vicedev1001@gmail.com + * @date 2020/9/19 16:57 + * @desc 设置页面 + */ +class SettingFragment : BaseFragment() { + override fun getLayoutId(): Int = R.layout.fragment_setting + + override fun initTitleBar(titleBar: CommonTitleBar?) { + titleBar?.run { + centerTextView.text = "设置" + + setListener { v, action, extra -> + when (action) { + CommonTitleBar.ACTION_LEFT_BUTTON -> { + requireActivity().finish() + } + } + } + } + } + + override fun initView() { + super.initView() + //开启福利 + val openFL = SPUtils.getInstance().getBoolean(SP_OPEN_FL) + setOpenFL.switchBtn.isChecked = openFL + } + + override fun initListener() { + super.initListener() + //开启福利开关 + setOpenFL.switchBtn.setOnCheckedChangeListener { view, isChecked -> + SPUtils.getInstance().put(SP_OPEN_FL, isChecked) + EventBus.getDefault().removeStickyEvent(OpenFLEvent(isChecked)) + EventBus.getDefault().postSticky(OpenFLEvent(isChecked)) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/vicedev/zy_player_android/widgets/SetItemView.kt b/app/src/main/java/com/vicedev/zy_player_android/widgets/SetItemView.kt index 5fb85ba..5ba5c8d 100644 --- a/app/src/main/java/com/vicedev/zy_player_android/widgets/SetItemView.kt +++ b/app/src/main/java/com/vicedev/zy_player_android/widgets/SetItemView.kt @@ -36,10 +36,17 @@ class SetItemView @JvmOverloads constructor( } else { divideLine.gone() } - if (ta.getBoolean(R.styleable.SetItemView_needRightArrow, true)) { + + val needRightArrow = ta.getBoolean(R.styleable.SetItemView_needRightArrow, false) + val needSwitchBtn = ta.getBoolean(R.styleable.SetItemView_needSwitchBtn, false) + + //右侧箭头图标与开关互斥 + if (needRightArrow) { ivArrowRight.visible() - } else { + switchBtn.gone() + } else if (needSwitchBtn) { ivArrowRight.gone() + switchBtn.visible() } ta.recycle() } diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index da512cc..17d206d 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -37,31 +37,41 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:itemName="赏个star" - app:needDivideLine="false" /> + app:needDivideLine="false" + app:needRightArrow="true" /> + app:itemName="打赏一波" + app:needRightArrow="true" /> + app:itemName="历史版本下载" + app:needRightArrow="true" /> + app:itemName="问题反馈" + app:needRightArrow="true" /> + + + app:itemName="版本 v1.0.0" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_setting.xml b/app/src/main/res/layout/fragment_setting.xml new file mode 100644 index 0000000..ec6c78a --- /dev/null +++ b/app/src/main/res/layout/fragment_setting.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/set_item_view.xml b/app/src/main/res/layout/set_item_view.xml index 04fabbc..a27a7d5 100644 --- a/app/src/main/res/layout/set_item_view.xml +++ b/app/src/main/res/layout/set_item_view.xml @@ -11,11 +11,11 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:background="#ffffff" + android:lines="1" android:padding="12dp" + android:paddingRight="30dp" android:textColor="@color/normalFontColor" android:textSize="14sp" - android:lines="1" - android:paddingRight="30dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" @@ -35,8 +35,22 @@ android:layout_height="16dp" android:layout_marginRight="12dp" android:src="@drawable/arrow_right_black" + android:visibility="gone" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="@id/tvName" + tools:visibility="visible" /> + + + + app:layout_constraintTop_toTopOf="parent" + app:sb_checked_color="@color/black" + tools:visibility="visible" /> \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 47dcacb..b3caa3f 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -3,6 +3,7 @@ + \ No newline at end of file