diff --git a/app/build.gradle b/app/build.gradle index ec878f75..051bee80 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId "com.starry.myne" minSdk 26 targetSdk 34 - versionCode 21 - versionName "2.7.0" + versionCode 22 + versionName "2.8.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { @@ -82,9 +82,9 @@ dependencies { // Android core components. implementation 'androidx.core:core-ktx:1.12.0' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0' implementation 'androidx.activity:activity-compose:1.8.2' - implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2" + implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0" implementation "androidx.navigation:navigation-compose:2.7.6" // Jetpack compose. implementation "androidx.compose.ui:ui" diff --git a/app/src/main/java/com/starry/myne/MyneApp.kt b/app/src/main/java/com/starry/myne/MyneApp.kt index aa6f3a93..89a5207a 100644 --- a/app/src/main/java/com/starry/myne/MyneApp.kt +++ b/app/src/main/java/com/starry/myne/MyneApp.kt @@ -21,8 +21,16 @@ import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.ui.ExperimentalComposeUiApi import cat.ereza.customactivityoncrash.config.CaocConfig +import coil.ImageLoader +import coil.ImageLoaderFactory import coil.annotation.ExperimentalCoilApi +import coil.disk.DiskCache +import coil.memory.MemoryCache +import coil.request.CachePolicy +import coil.util.DebugLogger import dagger.hilt.android.HiltAndroidApp +import okhttp3.OkHttpClient +import java.util.concurrent.TimeUnit @ExperimentalCoilApi @@ -30,9 +38,36 @@ import dagger.hilt.android.HiltAndroidApp @ExperimentalMaterial3Api @ExperimentalMaterialApi @HiltAndroidApp -class MyneApp : Application() { +class MyneApp : Application(), ImageLoaderFactory { override fun onCreate() { super.onCreate() CaocConfig.Builder.create().restartActivity(MainActivity::class.java).apply() } + + override fun newImageLoader(): ImageLoader { + val coilOkhttpClient = OkHttpClient.Builder() + .connectTimeout(60, TimeUnit.SECONDS) + .writeTimeout(60, TimeUnit.SECONDS) + .readTimeout(100, TimeUnit.SECONDS) + .build() + + return ImageLoader(this).newBuilder() + .memoryCachePolicy(CachePolicy.ENABLED) + .memoryCache { + MemoryCache.Builder(this) + .maxSizePercent(0.25) + .strongReferencesEnabled(true) + .build() + } + .diskCachePolicy(CachePolicy.ENABLED) + .diskCache { + DiskCache.Builder() + .maxSizePercent(0.05) + .directory(cacheDir) + .build() + } + .okHttpClient(coilOkhttpClient) + .logger(DebugLogger()) + .build() + } } \ No newline at end of file diff --git a/app/src/main/java/com/starry/myne/repo/BookRepository.kt b/app/src/main/java/com/starry/myne/repo/BookRepository.kt index f09998d4..170fa510 100644 --- a/app/src/main/java/com/starry/myne/repo/BookRepository.kt +++ b/app/src/main/java/com/starry/myne/repo/BookRepository.kt @@ -39,7 +39,7 @@ import kotlin.coroutines.suspendCoroutine class BookRepository { - private lateinit var baseApiUrl: String + private val baseApiUrl = "https://www.pooloftears.cf/books" private val googleBooksUrl = "https://www.googleapis.com/books/v1/volumes" private val googleApiKey = "AIzaSyBCaXx-U0sbEpGVPWylSggC4RaR4gCGkVE" @@ -55,7 +55,6 @@ class BookRepository { page: Long, bookLanguage: BookLanguage = BookLanguage.AllBooks ): Result { - setApiUrlIfNotSetAlready() var url = "${baseApiUrl}?page=$page" if (bookLanguage != BookLanguage.AllBooks) { url += "&languages=${bookLanguage.isoCode}" @@ -65,7 +64,6 @@ class BookRepository { } suspend fun searchBooks(query: String): Result { - setApiUrlIfNotSetAlready() val encodedString = withContext(Dispatchers.IO) { URLEncoder.encode(query, "UTF-8") } @@ -74,7 +72,6 @@ class BookRepository { } suspend fun getBookById(bookId: String): Result { - setApiUrlIfNotSetAlready() val request = Request.Builder().get().url("${baseApiUrl}?ids=$bookId").build() return makeApiRequest(request) } @@ -84,7 +81,6 @@ class BookRepository { page: Long, bookLanguage: BookLanguage = BookLanguage.AllBooks ): Result { - setApiUrlIfNotSetAlready() var url = "${baseApiUrl}?page=$page&topic=$category" if (bookLanguage != BookLanguage.AllBooks) { url += "&languages=${bookLanguage.isoCode}" @@ -161,25 +157,4 @@ class BookRepository { } } - private suspend fun setApiUrlIfNotSetAlready() { - if (!this::baseApiUrl.isInitialized) { - val request = Request.Builder().get() - .url("https://raw.githubusercontent.com/starry-shivam/stuffs/main/myne-api-url") - .build() - val response = suspendCoroutine { continuation -> - okHttpClient.newCall(request).enqueue(object : Callback { - override fun onFailure(call: Call, e: IOException) { - continuation.resumeWithException(e) - } - - override fun onResponse(call: Call, response: Response) { - response.use { continuation.resume(response.body!!.string()) } - } - }) - } - val jsonObj = JSONObject(response) - baseApiUrl = jsonObj.getString("api_url") - } - } - } \ No newline at end of file diff --git a/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt index 884b729a..1ca95dba 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/categories/viewmodels/CategoryViewModel.kt @@ -100,6 +100,7 @@ class CategoryViewModel @Inject constructor( state = state.copy(error = it?.localizedMessage ?: "unknown-error") }, onSuccess = { bookSet, newPage -> + /** * usually bookSet.books is not nullable and API simply returns empty list * when browsing books all books (i.e. without passing language parameter) @@ -107,14 +108,7 @@ class CategoryViewModel @Inject constructor( * this: {"detail": "Invalid page."}. Hence the [BookSet] attributes become * null in this case and can cause crashes. */ - /** - * usually bookSet.books is not nullable and API simply returns empty list - * when browsing books all books (i.e. without passing language parameter) - * however, when browsing by language it returns a response which looks like - * this: {"detail": "Invalid page."}. Hence the [BookSet] attributes become - * null in this case and can cause crashes. - */ - val books = if (bookSet.books != null) { + @Suppress("SENSELESS_COMPARISON") val books = if (bookSet.books != null) { bookSet.books.filter { it.formats.applicationepubzip != null } } else { emptyList() diff --git a/build.gradle b/build.gradle index a84ee4cb..a5cf4cc4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ buildscript { ext { kotlin_version = '1.9.21' - gradle_version = '8.2.0' + gradle_version = '8.2.1' hilt_version = '2.49' room_version = '2.6.1' } @@ -12,7 +12,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:8.2.0' + classpath 'com.android.tools.build:gradle:8.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/fastlane/metadata/android/en-US/changelogs/22.txt b/fastlane/metadata/android/en-US/changelogs/22.txt new file mode 100644 index 00000000..c9fbdd5e --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/22.txt @@ -0,0 +1,3 @@ +- Fix loading issues due to github raw domain being blocked by indian ISPs for god knows what reason. +- Fix Images failing to load due to timeout error. +- Added German translations, thanks to @vrifox \ No newline at end of file