Skip to content

Commit

Permalink
Code quality and other improvements (#97)
Browse files Browse the repository at this point in the history
* Remove depreciated stuff from navigation graph and cleanup duplicate code
* Remove 'others' package and move items in utils
* Fix reader menu not appearing due to text selection and some other improvements
---------
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam authored Dec 16, 2023
1 parent 7f1ce9e commit ece3bb7
Show file tree
Hide file tree
Showing 34 changed files with 244 additions and 362 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.2'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2"
implementation "androidx.navigation:navigation-compose:2.7.6"
// Jetpack compose.
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.ui:ui-tooling-preview"
Expand All @@ -94,7 +95,6 @@ dependencies {
implementation "androidx.compose.material3:material3"
// Accompanist compose.
implementation "com.google.accompanist:accompanist-systemuicontroller:0.28.0"
implementation "com.google.accompanist:accompanist-navigation-animation:0.33.1-alpha"
// Recycler View for reader.
implementation "androidx.recyclerview:recyclerview:1.3.2"
// Material theme for main activity.
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/starry/myne/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import androidx.core.app.ActivityCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.ViewModelProvider
import coil.annotation.ExperimentalCoilApi
import com.starry.myne.others.NetworkObserver
import com.starry.myne.ui.screens.main.MainScreen
import com.starry.myne.ui.screens.settings.viewmodels.SettingsViewModel
import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode
import com.starry.myne.ui.theme.MyneTheme
import com.starry.myne.utils.NetworkObserver
import dagger.hilt.android.AndroidEntryPoint

@ExperimentalMaterialApi
Expand All @@ -64,7 +64,7 @@ class MainActivity : AppCompatActivity() {
settingsViewModel = ViewModelProvider(this)[SettingsViewModel::class.java]
mainViewModel = ViewModelProvider(this)[MainViewModel::class.java]

ThemeMode.entries.find { it.ordinal == settingsViewModel.getThemeValue()}
ThemeMode.entries.find { it.ordinal == settingsViewModel.getThemeValue() }
?.let { settingsViewModel.setTheme(it) }
settingsViewModel.setMaterialYou(settingsViewModel.getMaterialYouValue())

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/starry/myne/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.starry.myne.others.WelcomeDataStore
import com.starry.myne.ui.navigation.BottomBarScreen
import com.starry.myne.ui.navigation.Screens
import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand All @@ -42,6 +42,7 @@ class MainViewModel @Inject constructor(private val welcomeDataStore: WelcomeDat

init {
viewModelScope.launch {
// Check if user has completed onboarding.
welcomeDataStore.readOnBoardingState().collect { completed ->
if (completed) {
_startDestination.value = BottomBarScreen.Home.route
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/starry/myne/database/MyneDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.starry.myne.database.library.LibraryDao
import com.starry.myne.database.library.LibraryItem
import com.starry.myne.database.reader.ReaderDao
import com.starry.myne.database.reader.ReaderItem
import com.starry.myne.others.Constants
import com.starry.myne.utils.Constants

@Database(
entities = [LibraryItem::class, ReaderItem::class],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ limitations under the License.
package com.starry.myne.database.library

import androidx.lifecycle.LiveData
import androidx.room.*
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface LibraryDao {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.

package com.starry.myne.database.reader

import androidx.room.*
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface ReaderDao {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/starry/myne/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package com.starry.myne.di

import android.content.Context
import com.starry.myne.database.MyneDatabase
import com.starry.myne.others.WelcomeDataStore
import com.starry.myne.repo.BookRepository
import com.starry.myne.utils.BookDownloader
import com.starry.myne.ui.screens.welcome.viewmodels.WelcomeDataStore
import com.starry.myne.utils.PreferenceUtil
import com.starry.myne.utils.book.BookDownloader
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down
66 changes: 0 additions & 66 deletions app/src/main/java/com/starry/myne/others/BookLanguage.kt

This file was deleted.

24 changes: 9 additions & 15 deletions app/src/main/java/com/starry/myne/repo/BookRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package com.starry.myne.repo

import com.google.gson.Gson
import com.starry.myne.others.BookLanguage
import com.starry.myne.repo.models.BookSet
import com.starry.myne.repo.models.ExtraInfo
import com.starry.myne.utils.book.BookLanguage
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.Call
Expand All @@ -43,9 +43,11 @@ class BookRepository {
private val googleBooksUrl = "https://www.googleapis.com/books/v1/volumes"
private val googleApiKey = "AIzaSyBCaXx-U0sbEpGVPWylSggC4RaR4gCGkVE"


private val okHttpClient = OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS).readTimeout(100, TimeUnit.SECONDS).build()
private val okHttpClient = OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.build()

private val gsonClient = Gson()

Expand Down Expand Up @@ -102,9 +104,7 @@ class BookRepository {
response.use {
continuation.resume(
Result.success(
gsonClient.fromJson(
response.body!!.string(), BookSet::class.java
)
gsonClient.fromJson(response.body!!.string(), BookSet::class.java)
)
)
}
Expand All @@ -124,9 +124,7 @@ class BookRepository {

override fun onResponse(call: Call, response: Response) {
response.use {
continuation.resume(
parseExtraInfoJson(response.body!!.string())
)
continuation.resume(parseExtraInfoJson(response.body!!.string()))
}
}
})
Expand Down Expand Up @@ -175,11 +173,7 @@ class BookRepository {
}

override fun onResponse(call: Call, response: Response) {
response.use {
continuation.resume(
response.body!!.string()
)
}
response.use { continuation.resume(response.body!!.string()) }
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ sealed class BottomBarScreen(
val title: Int,
val icon: Int
) {
object Home : BottomBarScreen(
data object Home : BottomBarScreen(
route = "home",
title = R.string.navigation_home,
icon = R.drawable.ic_nav_home
)

object Categories : BottomBarScreen(
data object Categories : BottomBarScreen(
route = "categories",
title = R.string.navigation_categories,
icon = R.drawable.ic_nav_categories
)

object Library : BottomBarScreen(
data object Library : BottomBarScreen(
route = "library",
title = R.string.navigation_library,
icon = R.drawable.ic_nav_library
)

object Settings : BottomBarScreen(
data object Settings : BottomBarScreen(
route = "settings",
title = R.string.navigation_settings,
icon = R.drawable.ic_nav_settings
Expand Down
Loading

0 comments on commit ece3bb7

Please sign in to comment.