Skip to content

Commit

Permalink
feat: cast to gravity
Browse files Browse the repository at this point in the history
  • Loading branch information
lz233 committed Jan 9, 2022
1 parent 696839e commit 502ccf0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
2 changes: 1 addition & 1 deletion neteasecloudmusic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdkVersion 19
targetSdkVersion 31
versionCode = date.format("yyyyMMdd").toInteger()
versionName "1.4.5"
versionName "1.5"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndkVersion '22.1.7171670'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.bumptech.glide.Glide
import com.zhy.mediaplayer_exo.playermanager.manager.MediaManager
import kotlinx.coroutines.launch
import moe.lz233.meizugravity.cloudmusic.R
import moe.lz233.meizugravity.cloudmusic.databinding.ActivityMainBinding
Expand All @@ -27,10 +28,12 @@ import moe.lz233.meizugravity.cloudmusic.ui.playlist.PlayListActivity
import moe.lz233.meizugravity.cloudmusic.utils.LogUtil
import moe.lz233.meizugravity.cloudmusic.utils.ViewPager2Util
import moe.lz233.meizugravity.cloudmusic.utils.ktx.adjustParam
import moe.lz233.meizugravity.cloudmusic.utils.ktx.toPlayListItem

class MainActivity : BaseActivity() {
private val mainMenuList by lazy { listOf("正在播放", "每日签到", "每日推荐", "我的歌单", "关于") }
private val viewBuilding by lazy { ActivityMainBinding.inflate(layoutInflater) }
var cast = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -79,19 +82,54 @@ class MainActivity : BaseActivity() {
else
ViewPager2Util.setCurrentItem(viewBuilding.mainViewPager2, viewBuilding.mainViewPager2.currentItem + 1, 100, 50)
}
KeyEvent.KEYCODE_ENTER -> {
when (viewBuilding.mainViewPager2.currentItem) {
0 -> PlayingActivity.actionStart(this)
1 -> checkIn()
2 -> DailyActivity.actionStart(this)
3 -> PlayListActivity.actionStart(this)
4 -> AboutActivity.actionStart(this)
KeyEvent.KEYCODE_ENTER -> if (event?.action == KeyEvent.ACTION_DOWN) {
//event.startTracking()
if (event.repeatCount == 0) {
cast = false
return false
} else {
cast = true
return true
}
}
}
return super.onKeyDown(keyCode, event)
}

override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_ENTER -> {
if (cast) {
when (viewBuilding.mainViewPager2.currentItem) {
0 -> launch {
LogUtil.toast("尝试进行魔法对接(")
val userPlaylistResponse = CloudMusicNetwork.getUserPlaylist(UserDao.id)
for (playList in userPlaylistResponse.playlists) {
if (playList.creator.userId == UserDao.id && playList.name == "Cast to Gravity") {
val playlistDetailResponse = CloudMusicNetwork.getPlaylistDetail(playList.id)
MediaManager.playlist(playlistDetailResponse.playlist.tracks.toPlayListItem(), 0)
MediaManager.play()
PlayingActivity.actionStart(this@MainActivity)
break
}
}
}
}

} else {
when (viewBuilding.mainViewPager2.currentItem) {
0 -> PlayingActivity.actionStart(this)
1 -> checkIn()
2 -> DailyActivity.actionStart(this)
3 -> PlayListActivity.actionStart(this)
4 -> AboutActivity.actionStart(this)
}
}
}
}
return super.onKeyUp(keyCode, event)
}

private fun checkIn() {
launch {
try {
Expand All @@ -114,7 +152,8 @@ class MainActivity : BaseActivity() {
musicianTasksResponse.data.tasks.forEach {
it.status?.let { status ->
if ((status == 20) and (it.userMissionId != null)) {
val obtainTasksResponse = CloudMusicNetwork.obtainMusicianTask(it.userMissionId!!, it.period)
val obtainTasksResponse =
CloudMusicNetwork.obtainMusicianTask(it.userMissionId!!, it.period)
if (obtainTasksResponse.code == 200) LogUtil.toast("完成音乐人任务:${it.name}\n获得 ${it.rewardWorth} 云豆")
}
}
Expand Down Expand Up @@ -152,7 +191,8 @@ class MainActivity : BaseActivity() {
}

companion object {
fun actionStart(context: Context) = context.startActivity(Intent(context, MainActivity::class.java))
fun actionStart(context: Context) =
context.startActivity(Intent(context, MainActivity::class.java))
}

inner class ViewPagerAdapter : RecyclerView.Adapter<ViewPagerAdapter.ViewHolder>() {
Expand All @@ -161,7 +201,9 @@ class MainActivity : BaseActivity() {
val textView: TextView = itemView.findViewById(R.id.mainItemTextView)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_main, parent, false))
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_main, parent, false)
)

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.textView.text = mainMenuList[position]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class PlayListActivity : BaseActivity() {
var pinnedPlaylistIndex = 0
userPlaylistResponse.playlists.forEach {
if (it.creator.userId == UserDao.id)
playLists.add(pinnedPlaylistIndex++, it)
else
if ((it.specialType == 100) && it.name.contains("雷达"))
if (it.name != "Cast to Gravity")
playLists.add(pinnedPlaylistIndex++, it)
else
playLists.add(it)
if ((it.specialType == 100) && it.name.contains("雷达"))
playLists.add(pinnedPlaylistIndex++, it)
else
playLists.add(it)
}
viewBuilding.progressBar.visibility = View.GONE
viewBuilding.playlistListView.adapter = playlistAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ class TimeActivity : BaseActivity() {
}
KeyEvent.KEYCODE_DPAD_DOWN -> {
}
KeyEvent.KEYCODE_ENTER -> finish()
KeyEvent.KEYCODE_ENTER -> {
MediaManager.play()
finish()
}
}
return super.onKeyDown(keyCode, event)
}

override fun onDestroy() {
super.onDestroy()
MediaManager.play()
}

private fun setScreenBrightnessValue(brightnessValue: Float) {
Expand Down

1 comment on commit 502ccf0

@vercel
Copy link

@vercel vercel bot commented on 502ccf0 Jan 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.