Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam committed Jan 14, 2024
1 parent 8ea5b72 commit e1f5b5a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
37 changes: 36 additions & 1 deletion app/src/main/java/com/starry/myne/MyneApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,53 @@ 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
@ExperimentalComposeUiApi
@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()
}
}
27 changes: 1 addition & 26 deletions app/src/main/java/com/starry/myne/repo/BookRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -55,7 +55,6 @@ class BookRepository {
page: Long,
bookLanguage: BookLanguage = BookLanguage.AllBooks
): Result<BookSet> {
setApiUrlIfNotSetAlready()
var url = "${baseApiUrl}?page=$page"
if (bookLanguage != BookLanguage.AllBooks) {
url += "&languages=${bookLanguage.isoCode}"
Expand All @@ -65,7 +64,6 @@ class BookRepository {
}

suspend fun searchBooks(query: String): Result<BookSet> {
setApiUrlIfNotSetAlready()
val encodedString = withContext(Dispatchers.IO) {
URLEncoder.encode(query, "UTF-8")
}
Expand All @@ -74,7 +72,6 @@ class BookRepository {
}

suspend fun getBookById(bookId: String): Result<BookSet> {
setApiUrlIfNotSetAlready()
val request = Request.Builder().get().url("${baseApiUrl}?ids=$bookId").build()
return makeApiRequest(request)
}
Expand All @@ -84,7 +81,6 @@ class BookRepository {
page: Long,
bookLanguage: BookLanguage = BookLanguage.AllBooks
): Result<BookSet> {
setApiUrlIfNotSetAlready()
var url = "${baseApiUrl}?page=$page&topic=$category"
if (bookLanguage != BookLanguage.AllBooks) {
url += "&languages=${bookLanguage.isoCode}"
Expand Down Expand Up @@ -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")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,15 @@ 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)
* 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.
*/
/**
* 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()
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/22.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1f5b5a

Please sign in to comment.