Skip to content

Commit

Permalink
Merge pull request #367 from jakepurple13/develop
Browse files Browse the repository at this point in the history
New Update!
  • Loading branch information
jakepurple13 authored Jan 18, 2022
2 parents dffc0b5 + 15f9b29 commit 435fe6f
Show file tree
Hide file tree
Showing 62 changed files with 358 additions and 2,066 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.rememberLazyGridState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand Down Expand Up @@ -214,7 +214,7 @@ class AllFragment : BaseFragmentCompose() {
scope.launch { scaffoldState.bottomSheetState.collapse() }
}

val state = rememberLazyListState()
val state = rememberLazyGridState()
val showButton by remember { derivedStateOf { state.firstVisibleItemIndex > 0 } }
val scrollBehaviorTop = remember { TopAppBarDefaults.pinnedScrollBehavior() }
Scaffold(
Expand Down Expand Up @@ -334,7 +334,7 @@ class AllFragment : BaseFragmentCompose() {
) {
info.SearchListView(
list = searchList,
listState = rememberLazyListState(),
listState = rememberLazyGridState(),
favorites = allVm.favoriteList,
onLongPress = { item, c ->
itemInfo.value = if (c == ComponentState.Pressed) item else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class DetailsFragment : Fragment() {
currentDetailsUrl = info.url
setContent {

//TODO: Change all this to its own function so we can preview it

val localContext = LocalContext.current
val details: DetailViewModel = viewModel(factory = factoryCreate { DetailViewModel(info, localContext) })

Expand Down Expand Up @@ -244,7 +246,6 @@ class DetailsFragment : Fragment() {
}

private fun setup(info: InfoModel) {

viewModelScope.launch(Dispatchers.IO) {
combine(
itemListener.findItemByUrlFlow(info.url),
Expand All @@ -261,7 +262,6 @@ class DetailsFragment : Fragment() {
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy { chapters = it }
.addTo(disposable)

}

override fun onCleared() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class FavoriteFragment : Fragment() {

val scrollBehavior = remember { TopAppBarDefaults.pinnedScrollBehavior() }


CollapsingToolbarScaffold(
modifier = Modifier,
state = rememberCollapsingToolbarScaffoldState(),
Expand Down Expand Up @@ -323,7 +322,7 @@ class FavoriteFragment : Fragment() {
contentPadding = p,
verticalArrangement = Arrangement.spacedBy(4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
state = rememberLazyListState()
state = rememberLazyGridState()
) {
items(
showing
Expand Down
16 changes: 9 additions & 7 deletions UIViews/src/main/java/com/programmersbox/uiviews/GenericInfo.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.programmersbox.uiviews

import android.content.Context
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.lazy.LazyGridState
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -31,40 +32,41 @@ interface GenericInfo {
fun sourceList(): List<ApiService>
fun searchList(): List<ApiService> = sourceList()
fun toSource(s: String): ApiService?
fun customPreferences(preferenceScreen: SettingsDsl) = Unit
fun composeCustomPreferences(navController: NavController): ComposeSettingsDsl.() -> Unit = {}
fun downloadChapter(model: ChapterModel, allChapters: List<ChapterModel>, infoModel: InfoModel, context: Context)

@Composable
fun DetailActions(infoModel: InfoModel, tint: Color) {
}
fun DetailActions(infoModel: InfoModel, tint: Color) = Unit

@Composable
fun ComposeShimmerItem()

@ExperimentalFoundationApi
@Composable
fun ItemListView(
list: List<ItemModel>,
favorites: List<DbModel>,
listState: LazyListState,
listState: LazyGridState,
onLongPress: (ItemModel, ComponentState) -> Unit,
onClick: (ItemModel) -> Unit
)

@ExperimentalFoundationApi
@Composable
fun AllListView(
list: List<ItemModel>,
favorites: List<DbModel>,
listState: LazyListState,
listState: LazyGridState,
onLongPress: (ItemModel, ComponentState) -> Unit,
onClick: (ItemModel) -> Unit
) = ItemListView(list, favorites, listState, onLongPress, onClick)

@ExperimentalFoundationApi
@Composable
fun SearchListView(
list: List<ItemModel>,
favorites: List<DbModel>,
listState: LazyListState,
listState: LazyGridState,
onLongPress: (ItemModel, ComponentState) -> Unit,
onClick: (ItemModel) -> Unit
) = ItemListView(list, favorites, listState, onLongPress, onClick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.findNavController
import androidx.navigation.fragment.navArgs
import coil.compose.rememberImagePainter
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.google.accompanist.placeholder.material.placeholder
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
Expand All @@ -58,7 +58,6 @@ import com.programmersbox.favoritesdatabase.HistoryItem
import com.programmersbox.models.ItemModel
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.uiviews.utils.*
import com.skydoves.landscapist.glide.GlideImage
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
Expand Down Expand Up @@ -442,11 +441,12 @@ class GlobalSearchFragment : Fragment() {
}
LazyRow(
horizontalArrangement = Arrangement.spacedBy(4.dp),
modifier = Modifier.padding(horizontal = 4.dp)
modifier = Modifier
.padding(horizontal = 4.dp)
.padding(bottom = 4.dp)
) {
items(i.data) { m ->
SearchCoverCard(
modifier = Modifier.padding(bottom = 4.dp),
model = m,
placeHolder = mainLogo,
onLongPress = { c ->
Expand Down Expand Up @@ -502,22 +502,17 @@ class GlobalSearchFragment : Fragment() {
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
GlideImage(
imageModel = model.imageUrl,
contentDescription = null,
contentScale = ContentScale.FillBounds,
loading = {
Image(
painter = rememberDrawablePainter(drawable = placeHolder),
contentDescription = model.title
)
Image(
painter = rememberImagePainter(data = model.imageUrl) {
placeholder(placeHolder)
error(error)
crossfade(true)
lifecycle(LocalLifecycleOwner.current)
size(ComposableUtils.IMAGE_WIDTH_PX, ComposableUtils.IMAGE_HEIGHT_PX)
},
failure = {
Image(
painter = rememberDrawablePainter(drawable = error),
contentDescription = model.title
)
}
contentDescription = model.title,
contentScale = ContentScale.FillBounds,
modifier = Modifier.matchParentSize()
)

Box(
Expand Down
31 changes: 13 additions & 18 deletions UIViews/src/main/java/com/programmersbox/uiviews/HistoryFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.exponentialDecay
Expand Down Expand Up @@ -33,7 +32,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -45,12 +44,11 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.fragment.findNavController
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import coil.compose.rememberImagePainter
import com.programmersbox.favoritesdatabase.HistoryDatabase
import com.programmersbox.favoritesdatabase.RecentModel
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.uiviews.utils.*
import com.skydoves.landscapist.glide.GlideImage
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
Expand Down Expand Up @@ -322,20 +320,17 @@ class HistoryFragment : Fragment() {
secondaryText = { Text(requireContext().getSystemDateTimeFormat().format(item.timestamp)) },
icon = {
Surface(shape = MaterialTheme.shapes.medium) {
GlideImage(
imageModel = item.imageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
failure = {
Image(
painter = rememberDrawablePainter(AppCompatResources.getDrawable(LocalContext.current, logo.logoId)),
contentDescription = null,
modifier = Modifier
.padding(5.dp)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
Image(
painter = rememberImagePainter(data = item.imageUrl) {
placeholder(logo.logoId)
error(logo.logoId)
crossfade(true)
lifecycle(LocalLifecycleOwner.current)
size(ComposableUtils.IMAGE_WIDTH_PX, ComposableUtils.IMAGE_HEIGHT_PX)
},
contentScale = ContentScale.FillBounds,
contentDescription = item.title,
modifier = Modifier.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.*
Expand All @@ -28,10 +27,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.platform.*
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastMap
Expand All @@ -44,9 +40,7 @@ import androidx.work.Data
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import coil.compose.rememberImagePainter
import com.google.android.material.composethemeadapter.MdcTheme
import com.google.android.material.datepicker.CalendarConstraints
import com.google.android.material.datepicker.DateValidatorPointForward
Expand All @@ -59,15 +53,13 @@ import com.programmersbox.gsonutils.toJson
import com.programmersbox.helpfulutils.notificationManager
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.uiviews.utils.*
import com.skydoves.landscapist.glide.GlideImage
import io.reactivex.Completable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.subscribeBy
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
Expand Down Expand Up @@ -184,27 +176,17 @@ class NotificationFragment : BaseBottomSheetDialogFragment() {
ListItem(
modifier = Modifier.padding(5.dp),
icon = {
GlideImage(
imageModel = item.imageUrl.orEmpty(),
contentDescription = "",
contentScale = ContentScale.Crop,
requestBuilder = {
Glide.with(LocalView.current)
.asDrawable()
.override(360, 480)
.thumbnail(0.5f)
.transform(RoundedCorners(15))
Image(
painter = rememberImagePainter(data = item.imageUrl.orEmpty()) {
placeholder(logo.logoId)
error(logo.logoId)
crossfade(true)
lifecycle(LocalLifecycleOwner.current)
size(ComposableUtils.IMAGE_WIDTH_PX, ComposableUtils.IMAGE_HEIGHT_PX)
},
modifier = Modifier.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
failure = {
Image(
painter = rememberDrawablePainter(AppCompatResources.getDrawable(LocalContext.current, logo.logoId)),
contentDescription = item.notiTitle,
modifier = Modifier
.padding(5.dp)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
contentScale = ContentScale.FillBounds,
contentDescription = item.notiTitle,
modifier = Modifier.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
},
overlineText = { Text(item.source) },
Expand Down Expand Up @@ -383,22 +365,18 @@ class NotificationFragment : BaseBottomSheetDialogFragment() {
) {

Row {
GlideImage(
imageModel = item.imageUrl.orEmpty(),
contentDescription = "",
Image(
painter = rememberImagePainter(data = item.imageUrl.orEmpty()) {
placeholder(logo.logoId)
error(logo.logoId)
crossfade(true)
lifecycle(LocalLifecycleOwner.current)
},
contentScale = ContentScale.Crop,
contentDescription = item.notiTitle,
modifier = Modifier
.align(Alignment.CenterVertically)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
failure = {
Image(
painter = rememberDrawablePainter(AppCompatResources.getDrawable(LocalContext.current, logo.logoId)),
contentDescription = item.notiTitle,
modifier = Modifier
.padding(5.dp)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)

Column(
Expand Down
Loading

0 comments on commit 435fe6f

Please sign in to comment.