Skip to content

Commit

Permalink
fix onair
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed May 20, 2021
1 parent b2b87d5 commit d9bd4ea
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 41 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp-brotli:$okhttpVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"

implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"

implementation "androidx.core:core-ktx:1.2.0"
implementation "androidx.core:core-ktx:1.3.1"
implementation "androidx.preference:preference:1.1.0"
testImplementation "junit:junit:4.12"
androidTestImplementation "androidx.test:runner:1.2.0"
Expand All @@ -115,6 +114,7 @@ dependencies {
implementation "am.util:viewpager:25.3.0"
implementation "com.jakewharton:disklrucache:2.0.2"
implementation "com.caverock:androidsvg-aar:1.4"
implementation "com.umeng.umsdk:analytics:8.0.0"
implementation "com.umeng.umsdk:common:2.0.0"
implementation "com.umeng.umsdk:common:9.3.8"
implementation "com.umeng.umsdk:asms:1.2.2"
implementation "com.umeng.umsdk:apm:1.2.0"
}
27 changes: 2 additions & 25 deletions app/src/main/java/soko/ekibun/bangumi/api/github/Github.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,24 @@ object Github {
*/
suspend fun bangumiCalendar(): List<BangumiCalendarItem> {
return withContext(Dispatchers.IO) {
if (latestTag.isEmpty()) updateOnAirLatestTag()
JsonUtil.toEntity<List<BangumiCalendarItem>>(
HttpUtil.fetch(
"$JSDELIVR_SERVER_API/gh/ekibun/bangumi_onair$latestTag/calendar.json",
"$JSDELIVR_SERVER_API/gh/ekibun/bangumi_onair/calendar.json",
JSDELIVR_REQUEST_OPTION
).body!!.string()
)!!
}
}

private var latestTag = ""
get() = if (field.isEmpty()) "" else "@$field"
private var lastUpdate = 0L
private suspend fun updateOnAirLatestTag() {
withContext(Dispatchers.IO) {
try {
val curTime = System.currentTimeMillis()
if (curTime - lastUpdate < 60 * 60 * 1000L) return@withContext
lastUpdate = curTime
latestTag = HttpUtil.fetch(
"https://github.com/ekibun/bangumi_onair/releases/latest", HttpUtil.RequestOption(
followRedirect = false
)
).headers["Location"]?.substringAfterLast('/') ?: latestTag
} catch (e: Throwable) {
e.printStackTrace()
}
}
}

/**
* 播放源
* @param id Int
*/
suspend fun onAirInfo(id: Int): OnAirInfo? {
return withContext(Dispatchers.IO) {
updateOnAirLatestTag()
JsonUtil.toEntity<OnAirInfo>(
HttpUtil.fetch(
"$JSDELIVR_SERVER_API/gh/ekibun/bangumi_onair$latestTag/onair/${id / 1000}/$id.json",
"$JSDELIVR_SERVER_API/gh/ekibun/bangumi_onair/onair/${id / 1000}/$id.json",
JSDELIVR_REQUEST_OPTION
).body?.string() ?: ""
)
Expand All @@ -95,7 +73,6 @@ object Github {
*/
suspend fun getSeason(id: Int): List<Subject>? {
return withContext(Dispatchers.IO) {
updateOnAirLatestTag()
val mapId = HttpUtil.fetch(
"$JSDELIVR_SERVER_API/gh/ekibun/bangumi_link/node/${id / 1000}/$id",
JSDELIVR_REQUEST_OPTION
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/soko/ekibun/bangumi/model/UserModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ object UserModel {
}
}
HttpUtil.formhash = it.formhash
} ?: {
} ?: run {
HttpUtil.formhash = ""
}()
}
App.app.sp.edit().putString(PREF_USER, JsonUtil.toJson(userList)).apply()
}
cookieManager.flush()
Expand All @@ -73,8 +73,7 @@ object UserModel {
}

fun current(): UserInfo? {
val current = userList.users[userList.current]?.user
return current
return userList.users[userList.current]?.user
}

fun removeUser(user: UserInfo): Boolean {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/soko/ekibun/bangumi/ui/main/DrawerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DrawerView(private val context: MainActivity, onLogout: () -> Unit) {
R.id.nav_history to findOrCreateFragmentByClassName(HistoryFragment::class.java)
)

val toggle = {
val toggle = run {
context.setSupportActionBar(context.toolbar)
val toggle = ActionBarDrawerToggle(
context, context.drawer_layout, context.toolbar,
Expand All @@ -58,7 +58,7 @@ class DrawerView(private val context: MainActivity, onLogout: () -> Unit) {
context.resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE
toggle.syncState()
toggle
}()
}

var navigationItemSelectedListener = { it: MenuItem ->
context.drawer_layout.closeDrawers()
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlinVersion = '1.4.21'
ext.kotlinVersion = '1.4.31'
repositories {
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
google()
jcenter()
maven { url 'https://dl.bintray.com/umsdk/release' }
maven { url 'https://repo1.maven.org/maven2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
Expand All @@ -20,7 +20,7 @@ allprojects {
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://jitpack.io' }
maven { url 'https://dl.bintray.com/umsdk/release' }
maven { url 'https://repo1.maven.org/maven2/' }
jcenter()
google()
}
Expand All @@ -36,7 +36,7 @@ ext {
roomVersion = '2.2.3'
glideVersion = '4.11.0'
okhttpVersion = '4.5.0'
coroutinesVersion = '1.2.1'
coroutinesVersion = '1.4.3'
appCompatVersion = '1.1.0'
archLifecycleVersion = '2.2.0-rc02'
archLifecycleVersion = '2.3.0'
}

0 comments on commit d9bd4ea

Please sign in to comment.