Skip to content

Commit

Permalink
refactor: 网络接口调整
Browse files Browse the repository at this point in the history
  • Loading branch information
SOCK-MAGIC committed Feb 27, 2024
1 parent 715fa59 commit abad519
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 412 deletions.
317 changes: 129 additions & 188 deletions app/src/main/java/com/imcys/bilibilias/base/network/NetworkService.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ object DialogUtils {
launchIO {
flow {
bangumiPageMutableList.forEach {
val dashBangumiPlayBean = networkService.n1(it.cid, qn)
val dashBangumiPlayBean = networkService.pgcPlayUrl(it.cid, qn)
emit(VideoData(dashBangumiPlayBean, it))
}
}.collect {
Expand Down Expand Up @@ -1271,7 +1271,7 @@ object DialogUtils {
launchIO {
flow {
videoPageMutableList.forEach {
val dashVideoPlayBean = networkService.n2(videoBaseBean.data.bvid, it.cid, qn)
val dashVideoPlayBean = networkService.viewDash(videoBaseBean.data.bvid, it.cid, qn)

emit(VideoData(dashVideoPlayBean, it)) // 生产者发送数据
}
Expand Down Expand Up @@ -1363,7 +1363,7 @@ object DialogUtils {
launchIO {
flow {
videoPageMutableList.forEach {
val videoPlayBean = networkService.n3(videoBaseBean.data.bvid, it.cid, qn)
val videoPlayBean = networkService.viewFlv(videoBaseBean.data.bvid, it.cid, qn)
emit(VideoData(videoPlayBean, it))
}
}.collect {
Expand Down Expand Up @@ -1410,7 +1410,7 @@ object DialogUtils {
launchIO {
flow {
bangumiPageMutableList.forEach {
val bangumiPlayBean = networkService.n4(it.cid, qn)
val bangumiPlayBean = networkService.flvPgcPlayUrl(it.cid, qn)
emit(VideoData(bangumiPlayBean, it))
}
}.collect {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,53 @@
package com.imcys.bilibilias.home.ui.activity

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.annotation.*
import android.content.*
import android.content.pm.*
import android.graphics.*
import android.os.*
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import cn.jzvd.JZDataSource
import cn.jzvd.Jzvd
import cn.jzvd.JzvdStd
import com.baidu.mobstat.StatService
import com.imcys.asbottomdialog.bottomdialog.AsDialog
import android.view.*
import androidx.activity.*
import androidx.core.view.*
import androidx.databinding.*
import androidx.recyclerview.widget.*
import cn.jzvd.*
import com.baidu.mobstat.*
import com.imcys.asbottomdialog.bottomdialog.*
import com.imcys.bilibilias.R
import com.imcys.bilibilias.base.BaseActivity
import com.imcys.bilibilias.base.network.NetworkService
import com.imcys.bilibilias.base.utils.DialogUtils
import com.imcys.bilibilias.base.utils.TokenUtils
import com.imcys.bilibilias.base.view.AppAsJzvdStd
import com.imcys.bilibilias.common.base.api.BilibiliApi
import com.imcys.bilibilias.base.*
import com.imcys.bilibilias.base.network.*
import com.imcys.bilibilias.base.utils.*
import com.imcys.bilibilias.base.view.*
import com.imcys.bilibilias.common.base.api.*
import com.imcys.bilibilias.common.base.app.BaseApplication.Companion.asUser
import com.imcys.bilibilias.common.base.constant.BILIBILI_URL
import com.imcys.bilibilias.common.base.constant.BROWSER_USER_AGENT
import com.imcys.bilibilias.common.base.constant.COOKIE
import com.imcys.bilibilias.common.base.constant.REFERER
import com.imcys.bilibilias.common.base.constant.USER_AGENT
import com.imcys.bilibilias.common.base.extend.launchUI
import com.imcys.bilibilias.common.base.utils.VideoNumConversion
import com.imcys.bilibilias.common.base.view.JzbdStdInfo
import com.imcys.bilibilias.common.network.base.ResBean
import com.imcys.bilibilias.danmaku.BiliDanmukuParser
import com.imcys.bilibilias.databinding.ActivityAsVideoBinding
import com.imcys.bilibilias.home.ui.adapter.BangumiSubsectionAdapter
import com.imcys.bilibilias.home.ui.adapter.SubsectionAdapter
import com.imcys.bilibilias.common.base.constant.*
import com.imcys.bilibilias.common.base.extend.*
import com.imcys.bilibilias.common.base.utils.*
import com.imcys.bilibilias.common.base.view.*
import com.imcys.bilibilias.common.network.base.*
import com.imcys.bilibilias.danmaku.*
import com.imcys.bilibilias.databinding.*
import com.imcys.bilibilias.home.ui.adapter.*
import com.imcys.bilibilias.home.ui.model.*
import com.imcys.bilibilias.home.ui.viewmodel.AsVideoViewModel
import dagger.hilt.android.AndroidEntryPoint
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import master.flame.danmaku.controller.IDanmakuView
import master.flame.danmaku.danmaku.loader.IllegalDataException
import master.flame.danmaku.danmaku.loader.android.DanmakuLoaderFactory
import master.flame.danmaku.danmaku.model.BaseDanmaku
import master.flame.danmaku.danmaku.model.DanmakuTimer
import master.flame.danmaku.danmaku.model.GlobalFlagValues
import master.flame.danmaku.danmaku.model.IDisplayer
import master.flame.danmaku.danmaku.model.android.DanmakuContext
import master.flame.danmaku.danmaku.model.android.Danmakus
import master.flame.danmaku.danmaku.parser.BaseDanmakuParser
import okio.BufferedSink
import okio.buffer
import okio.sink
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileInputStream
import com.imcys.bilibilias.home.ui.viewmodel.*
import dagger.hilt.android.*
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import kotlinx.coroutines.*
import master.flame.danmaku.controller.*
import master.flame.danmaku.danmaku.loader.*
import master.flame.danmaku.danmaku.loader.android.*
import master.flame.danmaku.danmaku.model.*
import master.flame.danmaku.danmaku.model.android.*
import master.flame.danmaku.danmaku.parser.*
import okio.*
import java.io.*
import java.io.IOException
import java.io.InputStream
import java.util.zip.Inflater
import javax.inject.Inject
import java.util.zip.*
import javax.inject.*
import kotlin.collections.set


@AndroidEntryPoint
Expand Down Expand Up @@ -116,10 +96,6 @@ class AsVideoActivity : BaseActivity() {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}

// override fun attachBaseContext(newBase: Context?) {
// super.attachBaseContext(newBase)
//
// }
/**
* 加载用户信息,为了确保会员视频及时通知用户
*/
Expand Down Expand Up @@ -168,7 +144,7 @@ class AsVideoActivity : BaseActivity() {
"video" -> {
launchUI {
// 获取播放信息
val videoPlayBean = networkService.n9(bvid, cid)
val videoPlayBean = networkService.viewFlv(bvid, cid, 64)
// 设置布局视频播放数据
binding.videoPlayBean = videoPlayBean
// 有部分视频不存在flv接口下的mp4,无法提供播放服务,需要及时通知。
Expand All @@ -185,7 +161,7 @@ class AsVideoActivity : BaseActivity() {
}
}.show()
} else {
val dashVideoPlayBean = networkService.n10(bvid, cid)
val dashVideoPlayBean = networkService.viewDash(bvid, cid, 64)
if (dashVideoPlayBean.code != 0) {
setAsJzvdConfig(videoPlayBean.data.durl[0].url, "")
}
Expand Down Expand Up @@ -223,7 +199,7 @@ class AsVideoActivity : BaseActivity() {
"bangumi" -> {
launchIO {

val bangumiPlayBean = networkService.n16(epid)
val bangumiPlayBean = networkService.flvPgcPlayUrl(epid, 64)

launchUI {
// 设置布局视频播放数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import com.baidu.mobstat.StatService
import com.imcys.bilibilias.R
import com.imcys.bilibilias.base.BaseActivity
import com.imcys.bilibilias.base.network.NetworkService
import com.imcys.bilibilias.common.base.api.BilibiliApi
import com.imcys.bilibilias.common.base.app.BaseApplication.Companion.asUser
import com.imcys.bilibilias.common.base.constant.COOKIE
import com.imcys.bilibilias.common.base.utils.RecyclerViewUtils
import com.imcys.bilibilias.common.base.utils.http.HttpUtils
import com.imcys.bilibilias.databinding.ActivityPlayHistoryBinding
import com.imcys.bilibilias.home.ui.adapter.PlayHistoryAdapter
import com.imcys.bilibilias.home.ui.model.PlayHistoryBean
Expand Down Expand Up @@ -61,7 +57,7 @@ class PlayHistoryActivity : BaseActivity() {
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)

launchUI {
networkService.getPlayHistory(0, 0, "archive").let {
networkService.getPlayHistory(0, 0).let {
max = it.data.cursor.max
viewAt = it.data.cursor.view_at
playHistoryDataMutableList.addAll(it.data.list)
Expand All @@ -81,7 +77,7 @@ class PlayHistoryActivity : BaseActivity() {

private fun loadPlayHistory() {
launchUI {
networkService.getPlayHistory(max, viewAt, "archive").let {
networkService.getPlayHistory(max, viewAt).let {
max = it.data.cursor.max
viewAt = it.data.cursor.view_at
playHistoryDataMutableList.addAll(it.data.list)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
package com.imcys.bilibilias.home.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.baidu.mobstat.StatService
import android.os.*
import android.view.*
import android.widget.*
import androidx.databinding.*
import androidx.recyclerview.widget.*
import com.baidu.mobstat.*
import com.imcys.bilibilias.R
import com.imcys.bilibilias.base.network.NetworkService
import com.imcys.bilibilias.base.utils.TokenUtils
import com.imcys.bilibilias.base.utils.asToast
import com.imcys.bilibilias.common.base.BaseFragment
import com.imcys.bilibilias.base.network.*
import com.imcys.bilibilias.base.utils.*
import com.imcys.bilibilias.common.base.*
import com.imcys.bilibilias.common.base.app.BaseApplication.Companion.asUser
import com.imcys.bilibilias.common.base.extend.launchUI
import com.imcys.bilibilias.databinding.FragmentUserBinding
import com.imcys.bilibilias.home.ui.adapter.UserDataAdapter
import com.imcys.bilibilias.home.ui.adapter.UserWorksAdapter
import com.imcys.bilibilias.home.ui.model.UpStatBeam
import com.imcys.bilibilias.home.ui.model.UserBaseBean
import com.imcys.bilibilias.home.ui.model.UserCardBean
import com.imcys.bilibilias.home.ui.model.UserViewItemBean
import com.imcys.bilibilias.home.ui.model.UserWorksBean
import com.zackratos.ultimatebarx.ultimatebarx.addStatusBarTopPadding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.async
import me.dkzwm.widget.srl.RefreshingListenerAdapter
import javax.inject.Inject
import kotlin.math.ceil
import com.imcys.bilibilias.common.base.extend.*
import com.imcys.bilibilias.databinding.*
import com.imcys.bilibilias.home.ui.adapter.*
import com.imcys.bilibilias.home.ui.model.*
import com.zackratos.ultimatebarx.ultimatebarx.*
import dagger.hilt.android.*
import kotlinx.coroutines.*
import me.dkzwm.widget.srl.*
import javax.inject.*
import kotlin.math.*

@AndroidEntryPoint
class UserFragment : BaseFragment() {
Expand Down Expand Up @@ -120,7 +110,6 @@ class UserFragment : BaseFragment() {
private fun loadUserWorks() {
val oldMutableList = userWorksBean.data.list.vlist
launchIO {

val userWorksBean = networkService.n20(userWorksBean.data.page.pn + 1)

this@UserFragment.userWorksBean = userWorksBean
Expand Down Expand Up @@ -179,10 +168,10 @@ class UserFragment : BaseFragment() {
val userBaseBean = async { getUserData() }

// 用户卡片信息
val userCardBean = async { getUserCardBean() }
val userCardBean = getUserCardBean()

// 获取up状态
val userUpStat = async { getUpStat() }
val userUpStat = async { networkService.getUpStat(userCardBean.data.card.mid) }

if (userBaseBean.await().code == 0) {
userDataMutableList.add(
Expand All @@ -197,12 +186,12 @@ class UserFragment : BaseFragment() {
userDataRvAd.submitList(userDataMutableList + mutableListOf())
}

if (userCardBean.await().code == 0 && userUpStat.await().code == 0) {
if (userUpStat.await().code == 0) {
userDataMutableList.add(
UserViewItemBean(
2,
upStatBeam = userUpStat.await(),
userCardBean = userCardBean.await(),
userCardBean = userCardBean,
),
)
}
Expand All @@ -226,15 +215,6 @@ class UserFragment : BaseFragment() {
return networkService.n22(paramsStr)
}

/**
* 获取用户状态信息
* @return UpStatBeam
*/
private suspend fun getUpStat(): UpStatBeam {

return networkService.n23()
}

/**
* 获取用户基础信息
* @return UserBaseBean
Expand Down
Loading

0 comments on commit abad519

Please sign in to comment.