Skip to content

Commit

Permalink
Merge pull request #78 from snehilrx/crash_and_playback_fixes
Browse files Browse the repository at this point in the history
Fixed video playback and crash issues with updater
  • Loading branch information
snehilrx authored Sep 17, 2023
2 parents c795d27 + ef2e252 commit 5653a3d
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 90 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = "1.4.7"
kotlinCompilerExtensionVersion = "1.5.3"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
Expand All @@ -67,7 +67,7 @@ android {

dependencies {
implementation project(path: ":base")
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.3.7'
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.4.2'
implementation 'com.google.firebase:firebase-analytics-ktx:21.3.0'
implementation "androidx.core:core-ktx:$versions.core_ktx"
implementation "androidx.appcompat:appcompat:$versions.appcompat"
Expand All @@ -78,7 +78,7 @@ dependencies {
implementation "androidx.hilt:hilt-work:$versions.work_hilt"
implementation "androidx.work:work-runtime-ktx:$versions.work"
implementation project(path: ':kickassanime')
implementation 'com.google.firebase:firebase-perf:20.3.3'
implementation 'com.google.firebase:firebase-perf:20.4.1'
androidTestImplementation "io.github.rascaler:assertj:$versions.assertJ"
testImplementation "junit:junit:$versions.junit"
androidTestImplementation "androidx.test.ext:junit:$versions.androidx_junit"
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/java/com/otaku/fetch/FetchApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import com.otaku.fetch.base.settings.dataStore
import com.otaku.fetch.base.ui.BindingActivity.Companion.REPO_LINK
import com.otaku.fetch.work.AnimeNotifier
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.net.UnknownHostException
import javax.inject.Inject


Expand Down Expand Up @@ -47,16 +44,14 @@ class FetchApplication : MultiDexApplication(), Configuration.Provider, AppModul
private fun checkForUpdates() {
kotlinx.coroutines.MainScope().launch {
dataStore.data.collectLatest {
withContext(Dispatchers.IO) {
try {
dataStore.edit { editable ->
editable[Settings.PREF_NEW_UPDATE_FOUND] =
ApkUpdater(this@FetchApplication, REPO_LINK).isNewUpdateAvailable()
?: false
}
} catch (e: UnknownHostException) {
// internet not connected
try {
dataStore.edit { editable ->
editable[Settings.PREF_NEW_UPDATE_FOUND] =
ApkUpdater(this@FetchApplication, REPO_LINK).isNewUpdateAvailable()
?: false
}
} catch (_: Exception) {
// internet not connected
}
}
}
Expand Down Expand Up @@ -86,7 +81,7 @@ class FetchApplication : MultiDexApplication(), Configuration.Provider, AppModul
newInstance.load(this)
}
count++
} catch (e: ClassNotFoundException) {
} catch (_: ClassNotFoundException) {
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = "1.4.7"
kotlinCompilerExtensionVersion = "1.5.3"
}
namespace 'com.otaku.fetch.base'
compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.io.File
import java.util.concurrent.TimeUnit
import javax.inject.Named
import javax.inject.Singleton

Expand All @@ -26,7 +27,8 @@ object ApplicationModule {

@Provides
@Singleton
fun getHttpLogger() = HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.HEADERS }
fun getHttpLogger() =
HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.HEADERS }


@Provides
Expand All @@ -39,7 +41,9 @@ object ApplicationModule {
override fun e(tag: String, s: String) {
android.util.Log.e(tag, s)
}
}).okHttpClient.addInterceptor(logger).build()
}).okHttpClient.callTimeout(4, TimeUnit.MINUTES)
.connectTimeout(4, TimeUnit.MINUTES)
.addInterceptor(logger).build()

private const val MAX_CACHE_SIZE: Long = 2000000000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,15 @@ class DownloadRepository @Inject constructor() {
val root = Root()


private val downloadItems: HashMap<String, DownloadItem> = HashMap()

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
suspend fun findEpisodes(downloads: HashMap<Uri, Download>) {
downloads.forEach loop@{ (t, u) ->
ModuleRegistry.getModulesList().forEach moduleLoop@{
val key = String(u.request.data)
val item = it.appModule?.findEpisode(key, t.toString(), u.request.mimeType ?: "")
?: return@moduleLoop

val item = downloadItems[key] ?: createItem(key, u, t, it) ?: return@moduleLoop
// update tree
var anime = Anime(item.animeKey, item.animeTitle, root)
val findAnime = root.findChild(anime)
Expand Down Expand Up @@ -277,6 +279,17 @@ class DownloadRepository @Inject constructor() {
}
}

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
private suspend fun createItem(
key: String, u: Download, t: Uri, moduleData: ModuleRegistry.ModuleData
): DownloadItem? {
val downloadItem =
(moduleData.appModule?.findEpisode(key, t.toString(), u.request.mimeType ?: "")
?: return null)
downloadItems[key] = downloadItem
return downloadItem
}

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
fun update(download: Download) {
val link = root.leafReference[download.request.id]
Expand Down
17 changes: 4 additions & 13 deletions base/src/main/java/com/otaku/fetch/base/download/DownloadUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.media3.datasource.cronet.CronetDataSource
import androidx.media3.datasource.cronet.CronetUtil
import androidx.media3.datasource.okhttp.OkHttpDataSource
import androidx.media3.exoplayer.offline.DownloadManager
import androidx.media3.exoplayer.offline.DownloadNotificationHelper
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import org.chromium.net.CronetEngine
Expand All @@ -36,7 +35,6 @@ class DownloadUtils constructor(
private lateinit var databaseProvider: DatabaseProvider
private lateinit var downloadManager: DownloadManager
private lateinit var downloadTracker: DownloadTracker
private lateinit var downloadNotificationHelper: DownloadNotificationHelper
private lateinit var httpDataSourceFactory: DataSource.Factory

@Synchronized
Expand Down Expand Up @@ -64,16 +62,6 @@ class DownloadUtils constructor(
return httpDataSourceFactory
}

@Synchronized
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
fun getDownloadNotificationHelper(): DownloadNotificationHelper {
if (!this::downloadNotificationHelper.isInitialized) {
downloadNotificationHelper =
DownloadNotificationHelper(context, DOWNLOAD_NOTIFICATION_CHANNEL_ID)
}
return downloadNotificationHelper
}

@Synchronized
fun getDownloadManager(): DownloadManager {
ensureDownloadManagerInitialized()
Expand Down Expand Up @@ -112,7 +100,6 @@ class DownloadUtils constructor(
}

companion object {
const val DOWNLOAD_NOTIFICATION_CHANNEL_ID = "download_channel"
private const val USE_CRONET_FOR_NETWORKING = false
}
}
Expand All @@ -124,6 +111,10 @@ fun OkHttpClient.changeOrigin(): OkHttpClient {

val request = original.newBuilder()
.header("origin", "https://kaavid.com")
.header(
"user-agent",
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
)
.method(original.method, original.body)
.build()

Expand Down
12 changes: 5 additions & 7 deletions base/src/main/java/com/otaku/fetch/base/utils/UiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,21 @@ object UiUtils {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
target: Target<Drawable>,
isFirstResource: Boolean
): Boolean {
after(null)
return false
}

override fun onResourceReady(
resource: Drawable?,
model: Any?,
resource: Drawable,
model: Any,
target: Target<Drawable>?,
dataSource: DataSource?,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
resource?.let {
after(it.toBitmap())
}
after(resource.toBitmap())
return false
}
}).submit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ object ImageViewBindings {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
target: Target<Drawable>,
isFirstResource: Boolean
): Boolean {
animatedVectorDrawable.stop()

return false
}

override fun onResourceReady(
resource: Drawable?,
model: Any?,
resource: Drawable,
model: Any,
target: Target<Drawable>?,
dataSource: DataSource?,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
animatedVectorDrawable.stop()
Expand Down
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ buildscript {
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:$versions.hilt"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$versions.nav"
classpath 'com.android.tools.build:gradle:3.4.3'
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.6'
classpath 'com.android.tools.build:gradle:8.0.2'
classpath 'com.google.gms:google-services:4.4.0'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
classpath 'com.google.firebase:perf-plugin:1.4.2'
}
repositories {
Expand All @@ -20,10 +20,10 @@ buildscript {
}

plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
id 'com.android.dynamic-feature' version '8.0.1' apply false
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
id 'com.android.dynamic-feature' version '8.0.2' apply false
id "org.sonarqube" version "4.2.1.3168"
}

Expand Down
40 changes: 20 additions & 20 deletions deps.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
ext.versions = [
paging : '3.2.0-rc01',
nav : '2.6.0',
leak_canary : '2.11',
paging : '3.2.1',
nav : '2.7.2',
leak_canary : '2.12',
lifecycle : '2.5.0-alpha05',
arch : '2.1.0',
coordinator_layout : '1.2.0',
appsearch : '1.0.0-alpha04',
hilt : '2.46.1',
hilt : '2.48',
hilt_common : '1.0.0',
hilt_compiler : '1.0.0',
retrofit : '2.9.0',
room : '2.6.0-alpha01',
core_ktx : '1.12.0-alpha05',
appcompat : '1.7.0-alpha02',
room : '2.6.0-beta01',
core_ktx : '1.12.0',
appcompat : '1.7.0-alpha03',
material : '1.9.0',
constraintlayout : '2.1.4',
junit : '4.13.2',
androidx_junit : '1.2.0-alpha01',
espresso_core : '3.5.1',
annotation : '1.4.0',
glide : '4.15.1',
glide_okhttp : '4.15.1',
glide : '4.16.0',
glide_okhttp : '4.16.0',
swipe_refresh_layout : '1.2.0-alpha01',
okhttp : '5.0.0-alpha.7',
okhttp_bom : '5.0.0-alpha.10',
Expand All @@ -36,30 +36,30 @@ ext.versions = [
work : '2.8.1',
work_hilt : '1.0.0',
multidex : '2.0.1',
recycler_view : '1.3.0',
livedata : '2.6.1',
preference : '1.2.0',
recycler_view : '1.3.1',
livedata : '2.6.2',
preference : '1.2.1',
shimmer : '0.5.0',
media3 : '1.0.2',
media3 : '1.1.1',
materialpreference : '3.8.0',
ok2curl : '0.8.0',
compose_bom : '2023.06.01',
compose_bom : '2023.09.00',
compose_activity : '1.7.2',
compose_lifecycle : '2.6.1',
compose_paging : '3.2.0-rc01',
compose_lifecycle : '2.6.2',
compose_paging : '3.2.1',
compose_shimmer : '1.0.5',
compose_glide : '1.0.0-alpha.1',
compose_material3 : '1.2.0-alpha03',
compose_vector_animations: '1.6.0-alpha01',
compose_text_flow : '1.1.0',
compose_material3 : '1.2.0-alpha07',
compose_vector_animations: '1.6.0-alpha05',
compose_text_flow : '1.1.1',
kotlin_okhttp : '1.0',
datastore : '1.0.0',
// test
composeVersion : "1.1.1",
assertJ : "1.0.1",
assertJCore : '3.24.2',
mockwebserver : "5.0.0-alpha.10",
jupiter : '5.9.1',
jupiter : '5.10.0',
]

// region automated versioning system
Expand Down
4 changes: 2 additions & 2 deletions kickassanime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = "1.4.7"
kotlinCompilerExtensionVersion = "1.5.3"
}

namespace 'com.otaku.kickassanime'
Expand Down Expand Up @@ -101,7 +101,7 @@ dependencies {
implementation "com.google.dagger:hilt-android:$versions.hilt"
kapt "com.google.dagger:hilt-compiler:$versions.hilt"

implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0'

/* tests dependencies */
androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espresso_core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class KickassAppModule @Inject constructor(
override val name: String
get() = "Kickass Anime"
override val notificationDeeplink: String
get() = "http://kaa.sm/recent"
get() = "kaa.sm/recent"

override fun onSearch(query: String) {
TODO("Not yet implemented... Will be used when multiple providers a available")
Expand Down
Loading

0 comments on commit 5653a3d

Please sign in to comment.