Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
增加默认不展示福利片,设置中可开启
Browse files Browse the repository at this point in the history
  • Loading branch information
vicedev committed Sep 19, 2020
1 parent 83be0c4 commit 4fb2100
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
android:launchMode="singleTop"
android:screenOrientation="portrait" />

<activity
android:name=".ui.setting.SettingActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" />


<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/vicedev/zy_player_android/common/SPKey.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.vicedev.zy_player_android.common

/**
* @author vicedev
* @email [email protected]
* @date 2020/9/19 17:14
* @desc sp的key值
*/

//打开福利
const val SP_OPEN_FL = "sp_open_fl"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.vicedev.zy_player_android.event

/**
* @author vicedev
* @email [email protected]
* @date 2020/9/19 18:42
* @desc 开启福利的事件
*/

class OpenFLEvent(val open: Boolean) {
override fun equals(other: Any?): Boolean {
return other is OpenFLEvent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.vicedev.zy_player_android.ui.home
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.blankj.utilcode.util.SPUtils
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.sources.BaseSource
import com.vicedev.zy_player_android.sources.bean.Classify
import com.vicedev.zy_player_android.ui.BaseFragment
Expand Down Expand Up @@ -53,10 +55,15 @@ class HomeSourceFragment : BaseFragment() {
statusView.setFailStatus()
return@requestHomeData
}
val openFL = SPUtils.getInstance().getBoolean(SP_OPEN_FL)
classifyList.clear()
classifyList.add(Classify("new", "最新"))
classifyList.addAll(it.classifyList.filter { classify ->
!classify.id.isNullOrBlank() && !classify.name.isNullOrBlank()
!classify.id.isNullOrBlank() && !classify.name.isNullOrBlank() &&
//筛去福利
(if (openFL) true else (!classify.name.contains("福利") && !classify.name.contains(
"伦理"
)))
} as ArrayList<Classify>)
viewpager.adapter = ViewPageAdapter()
viewpager.offscreenPageLimit = 100
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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?) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -60,5 +61,10 @@ class MineFragment : BaseFragment() {
setFeedback.setOnClickListener {
Utils.openBrowser(requireActivity(), "https://support.qq.com/product/281859")
}

//设置
setSetting.setOnClickListener {
SettingActivity.jump(requireActivity())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 [email protected]
* @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))
}
}

}
Original file line number Diff line number Diff line change
@@ -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 [email protected]
* @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))
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
22 changes: 16 additions & 6 deletions app/src/main/res/layout/fragment_mine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<com.vicedev.zy_player_android.widgets.SetItemView
android:id="@+id/setReward"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemName="打赏一波" />
app:itemName="打赏一波"
app:needRightArrow="true" />

<com.vicedev.zy_player_android.widgets.SetItemView
android:id="@+id/setHistoryDownload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemName="历史版本下载" />
app:itemName="历史版本下载"
app:needRightArrow="true" />

<com.vicedev.zy_player_android.widgets.SetItemView
android:id="@+id/setFeedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemName="问题反馈" />
app:itemName="问题反馈"
app:needRightArrow="true" />

<com.vicedev.zy_player_android.widgets.SetItemView
android:id="@+id/setSetting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemName="设置"
app:needRightArrow="true" />

<com.vicedev.zy_player_android.widgets.SetItemView
android:id="@+id/setVersion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemName="版本 v1.0.0"
app:needRightArrow="false" />
app:itemName="版本 v1.0.0" />

</LinearLayout>
24 changes: 24 additions & 0 deletions app/src/main/res/layout/fragment_setting.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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="match_parent"
android:orientation="vertical">

<com.wuhenzhizao.titlebar.widget.CommonTitleBar
android:id="@id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:centerText="社会"
app:centerType="textView"
app:leftType="imageButton" />

<com.vicedev.zy_player_android.widgets.SetItemView
android:id="@+id/setOpenFL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemName="开启福利"
app:needRightArrow="false"
app:needSwitchBtn="true" />

</LinearLayout>
Loading

0 comments on commit 4fb2100

Please sign in to comment.