Skip to content

Commit

Permalink
- cleaned some things up
Browse files Browse the repository at this point in the history
- got the AnimeWorld DownloadViewerFragment.kt working again
- using coil for the banner. might see what else it can be used for but it will not be used for the manga reader
  • Loading branch information
jakepurple13 committed Nov 19, 2021
1 parent a8139e8 commit ceb7c71
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 56 deletions.
1 change: 1 addition & 0 deletions UIViews/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ dependencies {
implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist"
implementation "me.onebone:toolbar-compose:2.2.0"
implementation 'com.github.nanihadesuka:LazyColumnScrollbar:1.0.3'
implementation "io.coil-kt:coil-compose:1.4.0"

implementation datastore.datastore
}
30 changes: 15 additions & 15 deletions UIViews/src/main/java/com/programmersbox/uiviews/AllFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,20 @@ class AllFragment : BaseFragmentCompose() {
},
floatingActionButtonPosition = FabPosition.End
) { p ->
SwipeRefresh(
modifier = Modifier.padding(p),
state = refresh,
onRefresh = {
source?.let {
count = 1
sourceList.clear()
sourceLoadCompose(it, count, refresh)
if (sourceList.isEmpty()) {
info.ComposeShimmerItem()
} else {
SwipeRefresh(
modifier = Modifier.padding(p),
state = refresh,
onRefresh = {
source?.let {
count = 1
sourceList.clear()
sourceLoadCompose(it, count, refresh)
}
}
}
) {
if (sourceList.isEmpty()) {
info.ComposeShimmerItem()
} else {
) {
info.ItemListView(
list = sourceList,
listState = state,
Expand All @@ -329,8 +329,8 @@ class AllFragment : BaseFragmentCompose() {
}
}

if (source?.canScrollAll == true) {
InfiniteListHandler(listState = state, buffer = 1) {
if (source?.canScrollAll == true && sourceList.isNotEmpty()) {
InfiniteListHandler(listState = state, buffer = 2) {
source?.let {
count++
sourceLoadCompose(it, count, refresh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import androidx.compose.ui.window.DialogProperties
import androidx.compose.ui.zIndex
import androidx.core.graphics.ColorUtils
import androidx.fragment.app.Fragment
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
Expand All @@ -82,7 +81,6 @@ import io.reactivex.rxkotlin.subscribeBy
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import me.onebone.toolbar.CollapsingToolbarScaffold
import me.onebone.toolbar.ScrollStrategy
Expand Down Expand Up @@ -177,8 +175,6 @@ class DetailsFragment : Fragment() {
itemListener.findItemByUrlFlow(info.url),
dao.containsItemFlow(info.url)
) { f, d -> f || d }
.flowOn(Dispatchers.IO)
.flowWithLifecycle(lifecycle)
.collectAsState(initial = false)

val chapters by Flowables.combineLatest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastMap
import androidx.fragment.app.Fragment
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import androidx.navigation.fragment.navArgs
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.google.accompanist.placeholder.material.placeholder
Expand All @@ -66,7 +63,6 @@ import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import me.onebone.toolbar.CollapsingToolbarScaffold
import me.onebone.toolbar.ScrollStrategy
Expand Down Expand Up @@ -119,8 +115,6 @@ class GlobalSearchFragment : Fragment() {

val history by dao
.searchHistory("%$searchText%")
.flowOn(Dispatchers.IO)
.flowWithLifecycle(lifecycle)
.collectAsState(emptyList())

LaunchedEffect(Unit) {
Expand Down Expand Up @@ -415,7 +409,7 @@ class GlobalSearchFragment : Fragment() {
.map { SearchModel(a.serviceName, it) }
.toObservable()
}
) { (it as Array<SearchModel>).toList().filter { s -> s.data.isNotEmpty() } }
) { it.filterIsInstance<SearchModel>().filter { s -> s.data.isNotEmpty() } }
.doOnSubscribe {
searchListPublisher.clear()
onSubscribe()
Expand Down Expand Up @@ -459,15 +453,6 @@ class GlobalSearchFragment : Fragment() {
imageModel = model.imageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = {
Glide.with(LocalView.current)
.asDrawable()
//.override(360, 480)
.placeholder(placeHolder)
.error(error)
.fallback(placeHolder)
.transform(RoundedCorners(5))
},
modifier = Modifier
.align(Alignment.Center)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ class RecentFragment : BaseFragmentCompose() {
}
}

if (source?.canScroll == true) {
InfiniteListHandler(listState = state, buffer = 1) {
if (source?.canScroll == true && sourceList.isNotEmpty()) {
InfiniteListHandler(listState = state, buffer = 2) {
source?.let {
count++
sourceLoadCompose(it, count, refresh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap
import coil.annotation.ExperimentalCoilApi
import coil.compose.ImagePainter
import coil.compose.rememberImagePainter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.google.accompanist.placeholder.material.placeholder
Expand Down Expand Up @@ -285,15 +288,6 @@ fun M3CoverCard(
imageModel = imageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = {
Glide.with(LocalView.current)
.asDrawable()
//.override(360, 480)
.placeholder(placeHolder)
.error(error)
.fallback(placeHolder)
.transform(RoundedCorners(5))
},
modifier = Modifier
.align(Alignment.Center)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
Expand Down Expand Up @@ -421,6 +415,7 @@ fun M3PlaceHolderCoverCard(placeHolder: Int) {
}
}

@OptIn(ExperimentalCoilApi::class)
@ExperimentalMaterialApi
@Composable
fun M3OtakuBannerBox(
Expand All @@ -447,7 +442,7 @@ fun M3OtakuBannerBox(
) {
ListItem(
icon = {
GlideImage(
/*GlideImage(
imageModel = itemInfo.value?.imageUrl.orEmpty(),
contentDescription = null,
contentScale = ContentScale.Fit,
Expand All @@ -466,6 +461,56 @@ fun M3OtakuBannerBox(
modifier = Modifier.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
)*/
val painter = rememberImagePainter(data = itemInfo.value?.imageUrl.orEmpty())

when (painter.state) {
is ImagePainter.State.Loading -> {
Image(
bitmap = placeHolderImage,
contentDescription = null,
modifier = Modifier
.align(Alignment.Center)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
is ImagePainter.State.Error -> {
GlideImage(
imageModel = itemInfo.value?.imageUrl.orEmpty(),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.align(Alignment.Center)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
loading = {
Image(
bitmap = placeHolderImage,
contentDescription = null,
modifier = Modifier
.align(Alignment.Center)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
},
failure = {
Image(
bitmap = placeHolderImage,
contentDescription = null,
modifier = Modifier
.align(Alignment.Center)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
)
}
}

Image(
painter = painter,
contentDescription = null,
contentScale = ContentScale.Fit,
modifier = Modifier
.align(Alignment.Center)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
)
},
overlineText = { androidx.compose.material3.Text(itemInfo.value?.source?.serviceName.orEmpty()) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -247,18 +249,11 @@ class DownloadViewerFragment : BaseBottomSheetDialogFragment(), ActionListener {
if (items.isEmpty()) {
EmptyState()
} else {
AnimatedLazyColumn(
modifier = Modifier.padding(top = 5.dp),
contentPadding = p,
verticalArrangement = Arrangement.spacedBy(4.dp),
items = items.fastMap { AnimatedLazyListItem(it.id.toString(), it) { DownloadItem(it, this@DownloadViewerFragment) } }
)

/*LazyColumn(
LazyColumn(
modifier = Modifier.padding(top = 5.dp),
contentPadding = p,
verticalArrangement = Arrangement.spacedBy(4.dp)
) { items(items) { d -> DownloadItem(d, this@DownloadViewerFragment) } }*/
) { items(items) { d -> DownloadItem(d, this@DownloadViewerFragment) } }
}
}
}
Expand Down

0 comments on commit ceb7c71

Please sign in to comment.