Skip to content

Commit

Permalink
improve webview and fix loading issue in detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kazemcodes committed Jan 20, 2022
1 parent 0be0659 commit 6aa0eb0
Show file tree
Hide file tree
Showing 45 changed files with 1,282 additions and 166 deletions.
6 changes: 6 additions & 0 deletions .idea/misc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data class ExploreBook(
val rating: Int = 0,
val source: String? = null,
val isExploreMode:Boolean = false,
val lastUpdated:Long = 0
) {
fun toBook(): Book {
return Book(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface LibraryBookDao {
suspend fun getAllExploreBook(): List<ExploreBook?>

@Query("SELECT * FROM explore_books_table WHERE id =:id")
fun getExploreBookById(id:String): Flow<ExploreBook?>
fun getExploreBookById(id: String): Flow<ExploreBook?>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAllExploredBook(bookEntity: List<ExploreBook?>)
Expand All @@ -25,50 +25,52 @@ interface LibraryBookDao {
fun deleteAllExploredBook()



@Query("""SELECT * FROM book_table WHERE inLibrary = 1
ORDER BY
CASE WHEN :isAsc = 1 AND :sortByAbs = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByAbs = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByDateAdded = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByDateAdded = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByLastRead = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByLastRead = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByDownloads = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByDownloads = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByTotalChapter = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByTotalChapter = 1 THEN bookName END DESC
CASE WHEN :isAsc = 1 AND :sortByDateAdded = 1 THEN dataAdded END ASC,
CASE WHEN :isAsc = 0 AND :sortByDateAdded = 1 THEN dataAdded END DESC,
CASE WHEN :isAsc = 1 AND :sortByLastRead = 1 THEN lastRead END ASC,
CASE WHEN :isAsc = 0 AND :sortByLastRead = 1 THEN lastRead END DESC,
CASE WHEN :isAsc = 1 AND :sortByDownloads = 1 THEN download END ASC,
CASE WHEN :isAsc = 0 AND :sortByDownloads = 1 THEN download END DESC,
CASE WHEN :isAsc = 1 AND :sortByTotalChapter = 1 THEN totalChapters END ASC,
CASE WHEN :isAsc = 0 AND :sortByTotalChapter = 1 THEN totalChapters END DESC
""")
fun getAllLocalBooksForPagingSortedBySort(
sortByAbs: Boolean =false,
sortByDateAdded: Boolean =false,
sortByLastRead:Boolean = false,
sortByDownloads:Boolean = false,
sortByTotalChapter:Boolean = false,
sortByAbs: Boolean = false,
sortByDateAdded: Boolean = false,
sortByLastRead: Boolean = false,
sortByDownloads: Boolean = false,
sortByTotalChapter: Boolean = false,
isAsc: Boolean = false,
): PagingSource<Int,BookEntity>
): PagingSource<Int, BookEntity>



@Query("""SELECT * FROM book_table WHERE inLibrary = 1 AND unread = 1
ORDER BY
CASE WHEN :isAsc = 1 AND :sortByAbs = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByAbs = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByDateAdded = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByDateAdded = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByLastRead = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByLastRead = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByDownloads = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByDownloads = 1 THEN bookName END DESC,
CASE WHEN :isAsc = 1 AND :sortByTotalChapter = 1 THEN bookName END ASC,
CASE WHEN :isAsc = 0 AND :sortByTotalChapter = 1 THEN bookName END DESC
CASE WHEN :isAsc = 1 AND :sortByDateAdded = 1 THEN dataAdded END ASC,
CASE WHEN :isAsc = 0 AND :sortByDateAdded = 1 THEN dataAdded END DESC,
CASE WHEN :isAsc = 1 AND :sortByLastRead = 1 THEN lastRead END ASC,
CASE WHEN :isAsc = 0 AND :sortByLastRead = 1 THEN lastRead END DESC,
CASE WHEN :isAsc = 1 AND :sortByDownloads = 1 THEN download END ASC,
CASE WHEN :isAsc = 0 AND :sortByDownloads = 1 THEN download END DESC,
CASE WHEN :isAsc = 1 AND :sortByTotalChapter = 1 THEN totalChapters END ASC,
CASE WHEN :isAsc = 0 AND :sortByTotalChapter = 1 THEN totalChapters END DESC
""")
fun getAllLocalBooksForPagingSortedBySortAndFilter(
sortByAbs: Boolean =false,
sortByDateAdded: Boolean =false,
sortByLastRead:Boolean = false,
sortByDownloads:Boolean = false,
sortByTotalChapter:Boolean = false,
sortByAbs: Boolean = false,
sortByDateAdded: Boolean = false,
sortByLastRead: Boolean = false,
sortByDownloads: Boolean = false,
sortByTotalChapter: Boolean = false,
isAsc: Boolean = false,
): PagingSource<Int,BookEntity>
): PagingSource<Int, BookEntity>


@Query("SELECT * FROM book_table")
fun getAllBooks(): Flow<List<BookEntity>?>
Expand All @@ -86,7 +88,7 @@ interface LibraryBookDao {
suspend fun insertBook(bookEntity: BookEntity)

@Query("SELECT * FROM book_table WHERE bookName LIKE'%' || :query || '%'")
fun searchBook(query:String): PagingSource<Int,BookEntity>
fun searchBook(query: String): PagingSource<Int, BookEntity>

@Query("DELETE FROM book_table WHERE id = :bookId ")
suspend fun deleteBook(bookId: String)
Expand All @@ -100,4 +102,10 @@ interface LibraryBookDao {

}

data class InLibraryUpdate(val id: String, val inLibrary:Boolean, val totalChapters:Int, val lastRead:Long, val unread: Boolean)
data class InLibraryUpdate(
val id: String,
val inLibrary: Boolean,
val totalChapters: Int,
val lastRead: Long,
val unread: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import kotlinx.coroutines.flow.flow
import retrofit2.HttpException
import timber.log.Timber
import java.io.IOException
import java.util.*

class LocalBookRepositoryImpl(
private val bookDao: LibraryBookDao,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PreferencesHelper @Inject constructor(
const val SAVED_ORIENTATION = "orientation_reader"
const val SORT_LIBRARY_SCREEN = "sort_library_screen"
const val FILTER_LIBRARY_SCREEN = "filter_library_screen"
const val Last_UPDATE_CHECK = "last_update_check"

/** Setting Pref**/
const val SAVED_DOH_KEY = "SAVED_DOH_KEY"
Expand All @@ -46,6 +47,7 @@ class PreferencesHelper @Inject constructor(
val paragraphIndent = flowPrefs.getInt(SAVED_PARAGRAPH_INDENT, 8)
val sortLibraryScreen = flowPrefs.getInt(SORT_LIBRARY_SCREEN, 0)
val filterLibraryScreen = flowPrefs.getInt(FILTER_LIBRARY_SCREEN, 0)
val lastUpdateCheck = flowPrefs.getLong(Last_UPDATE_CHECK, 0)

fun setFontScale(fontSize: Int) {
readerFontScale.set(fontSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ class RemoteRepositoryImpl(
override fun getRemoteBooksUseCase(
source: Source,
exploreType: ExploreType,
query: String?
): Flow<PagingData<ExploreBook>> {
return Pager(
config = PagingConfig(pageSize = Constants.DEFAULT_PAGE_SIZE,
maxSize = Constants.MAX_PAGE_SIZE),
pagingSourceFactory = {
localBookRepository.getAllExploreBook()
}, remoteMediator = ExploreRemoteMediator(
source = source,
database = database,
exploreType = exploreType,
query = query
)
).flow
query: String?,
): Flow<PagingData<ExploreBook>> {
return Pager(
config = PagingConfig(pageSize = Constants.DEFAULT_PAGE_SIZE,
maxSize = Constants.MAX_PAGE_SIZE),
pagingSourceFactory = {
localBookRepository.getAllExploreBook()
}, remoteMediator = ExploreRemoteMediator(
source = source,
database = database,
exploreType = exploreType,
query = query
),
).flow
}


Expand All @@ -128,8 +128,8 @@ class RemoteRepositoryImpl(
source: Source,
): Flow<Resource<List<Chapter>>> =
flow {
emit(Resource.Loading())
try {
emit(Resource.Loading())
Timber.d("Timber: GetRemoteChaptersUseCase was Called")
val chapters = mutableListOf<Chapter>()
var currentPage = 1
Expand Down Expand Up @@ -171,7 +171,9 @@ class RemoteRepositoryImpl(
Timber.d("Timber: GetRemoteReadingContentUseCase was Called")
val content = source.fetchContent(chapter)

if (content.content.joinToString().isBlank() || content.content.contains(Constants.CLOUDFLARE_LOG)) {
if (content.content.joinToString()
.isBlank() || content.content.contains(Constants.CLOUDFLARE_LOG)
) {
emit(Resource.Error<ChapterPage>(message = "Can't Get The Chapter Content."))
} else {
Timber.d("Timber: GetRemoteReadingContentUseCase was Finished Successfully")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ data class Book(
val download:Boolean =false,
val lastRead:Long = 0,
val totalChapters:Int = 0,
val unread:Boolean = true
val unread:Boolean = true,
val lastUpdated:Long = 0
) : Parcelable {

companion object {
Expand Down Expand Up @@ -76,7 +77,8 @@ data class Book(
lastRead = lastRead,
download = download,
totalChapters = totalChapters,
unread = unread
unread = unread,
lastUpdated = lastUpdated
)
}
fun toExploreBook(): ExploreBook {
Expand All @@ -91,7 +93,8 @@ data class Book(
category = category,
source = source,
id = id,
rating = rating
rating = rating,
lastUpdated = lastUpdated
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ data class BookEntity(
val download:Boolean =false,
val lastRead:Long = 0,
val totalChapters:Int = 0,
val unread:Boolean
val unread:Boolean,
val lastUpdated:Long = 0
) {


Expand All @@ -46,7 +47,8 @@ data class BookEntity(
totalChapters = totalChapters,
download = download,
lastRead = lastRead,
dataAdded = dataAdded
dataAdded = dataAdded,
lastUpdated = lastUpdated
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ data class Chapter(
var haveBeenRead: Boolean = false,
var lastRead: Boolean = false,
var source: String,
var inLibrary:Boolean=false,
var inLibrary: Boolean = false,
var id: Int? = null,
) : Parcelable {


companion object {
fun create(): Chapter {
return Chapter(
Expand All @@ -25,6 +27,7 @@ data class Chapter(
}
}


fun toChapterEntity(): ChapterEntity {
return ChapterEntity(
bookName = bookName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import coil.annotation.ExperimentalCoilApi
import coil.compose.rememberImagePainter
import coil.request.CachePolicy
import com.zhuinden.simplestackcomposeintegration.core.LocalBackstack
import com.zhuinden.simplestackextensions.servicesktx.lookup
import ir.kazemcodes.infinity.R
Expand All @@ -31,6 +32,8 @@ fun BookImageComposable(
crossfade(durationMillis = 700)
placeholder(R.drawable.ic_no_image_placeholder)
error(R.drawable.ic_no_image_placeholder)
memoryCachePolicy(CachePolicy.ENABLED)
diskCachePolicy(CachePolicy.READ_ONLY)

}
Image(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fun TopAppBarTitle(
textAlign = TextAlign.Center,
)
}

@Composable
fun MidTextComposable(
modifier: Modifier = Modifier,
Expand All @@ -50,6 +51,7 @@ fun MidTextComposable(
style: TextStyle? = null,
fontWeight: FontWeight? = null,
overflow: TextOverflow? = null,
maxLine: Int = Int.MAX_VALUE,
) {
Text(
modifier = modifier,
Expand All @@ -59,6 +61,28 @@ fun MidTextComposable(
fontWeight = fontWeight ?: FontWeight.SemiBold,
overflow = overflow ?: TextOverflow.Ellipsis,
textAlign = TextAlign.Center,
maxLines = maxLine
)
}
@Composable
fun SmallTextComposable(
modifier: Modifier = Modifier,
title: String,
color: Color? = null,
style: TextStyle? = null,
fontWeight: FontWeight? = null,
overflow: TextOverflow? = null,
maxLine: Int = Int.MAX_VALUE,
) {
Text(
modifier = modifier,
text = title,
color = color ?: MaterialTheme.colors.onBackground,
style = style ?: MaterialTheme.typography.caption,
fontWeight = fontWeight ?: FontWeight.SemiBold,
overflow = overflow ?: TextOverflow.Ellipsis,
textAlign = TextAlign.Center,
maxLines = maxLine
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ object Constants {

const val CLOUDFLARE_PROTECTION_ERROR = "Cloudflare site protection is enable"

const val UNKNOWN_ERROR = "Unknown Error Happened"



}
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/ir/kazemcodes/infinity/core/utils/Event.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ir.kazemcodes.infinity.core.utils

import androidx.annotation.StringRes
import ir.kazemcodes.infinity.feature_detail.presentation.book_detail.Constants

abstract class Event

sealed class UiEvent : Event() {
data class ShowSnackbar(val uiText: UiText) : UiEvent()
data class Navigate(val route: String) : UiEvent()
object NavigateUp : UiEvent()
object OnLogin : UiEvent()
}

sealed class UiText {
data class DynamicString(val value: String) : UiText()
data class StringResource(@StringRes val id: Int) : UiText()

companion object {
fun unknownError(): String {
return Constants.UNKNOWN_ERROR
}
}
}

Loading

0 comments on commit 6aa0eb0

Please sign in to comment.