Skip to content

Commit

Permalink
Merge pull request #25 from ImaginativeShohag/dev
Browse files Browse the repository at this point in the history
Fix paging example API issue and empty view not showing correctly issue
  • Loading branch information
ImaginativeShohag committed Jul 1, 2023
2 parents a61fe5f + 7dc18e2 commit b12fee3
Show file tree
Hide file tree
Showing 78 changed files with 1,838 additions and 25 deletions.
26 changes: 26 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/*
* Copyright 2023 Md. Mahmudul Hasan Shohag
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ------------------------------------------------------------------------
*
* Project: Why Not Compose!
* Developed by: @ImaginativeShohag
*
* Md. Mahmudul Hasan Shohag
* [email protected]
*
* Source: https://github.com/ImaginativeShohag/Why-Not-Compose
*/

plugins {
id(Libs.Android.application)
kotlin("android")
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
~ [email protected]
~
~ Source: https://github.com/ImaginativeShohag/Why-Not-Compose
-->
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -47,7 +48,9 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.Card
import androidx.compose.material.Colors
Expand All @@ -66,6 +69,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -151,7 +155,8 @@ fun DataFetchAndPagingScreenSkeletonPreview() {
MockData.dummyGithubRepo
)
)
).collectAsLazyPagingItems()
).collectAsLazyPagingItems(),
searchTFV = remember { mutableStateOf(TextFieldValue("Lorem")) }
)
}
}
Expand All @@ -173,7 +178,8 @@ fun DataFetchAndPagingScreenSkeletonPreviewDark() {
MockData.dummyGithubRepo
)
)
).collectAsLazyPagingItems()
).collectAsLazyPagingItems(),
searchTFV = remember { mutableStateOf(TextFieldValue("Lorem")) }
)
}
}
Expand All @@ -183,7 +189,7 @@ fun DataFetchAndPagingScreenSkeleton(
showLoadingView: Boolean = false,
showMessage: Event<String>? = null,
repos: LazyPagingItems<GithubRepo>,
searchTFV: MutableState<TextFieldValue> = remember { mutableStateOf(TextFieldValue()) },
searchTFV: MutableState<TextFieldValue>,
openSearch: Boolean = false,
goBack: () -> Unit = {},
setOpenSearch: (Boolean) -> Unit = {},
Expand Down Expand Up @@ -249,11 +255,25 @@ fun DataFetchAndPagingScreenSkeleton(
contentAlignment = Alignment.Center
) {
repos.apply {
EmptyView(
modifier = Modifier,
loadState = loadState,
itemCount = this.itemCount
)
Column(
Modifier.verticalScroll(rememberScrollState())
) {
EmptyView(
modifier = Modifier,
loadState = loadState,
itemCount = repos.itemCount,
title = if (searchTFV.value.text.isBlank()) {
"No search keyword!"
} else {
"Nothing found!"
},
message = if (searchTFV.value.text.isBlank()) {
"Enter anything to the search field."
} else {
"No repository found for \"${searchTFV.value.text}\"."
}
)
}
}

LazyColumn(
Expand Down Expand Up @@ -354,18 +374,23 @@ fun DataFetchAndPagingScreenSkeleton(

Box(
Modifier
.padding(horizontal = 8.dp)
.fillMaxWidth()
.height(56.dp)
.shadow(
elevation = 4.dp,
shape = RoundedCornerShape(24.dp, 24.dp, 24.dp, 24.dp)
)
.background(
MaterialTheme.colors.primary,
MaterialTheme.colors.surface,
RoundedCornerShape(24.dp, 24.dp, 24.dp, 24.dp)
)
) {
val searchBackgroundColor by animateColorAsState(
targetValue = if (searchTFV.value.text.isBlank()) {
MaterialTheme.colors.searchErrorInputBackground
} else {
MaterialTheme.colors.surface
MaterialTheme.colors.background
}
)

Expand All @@ -376,6 +401,11 @@ fun DataFetchAndPagingScreenSkeleton(
color = searchBackgroundColor,
shape = RoundedCornerShape(20.dp)
)
.border(
width = 1.dp,
color = MaterialTheme.colors.onSurface.copy(alpha = 0.05f),
shape = RoundedCornerShape(20.dp)
)
) {
SearchTextInputField(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.text.input.TextFieldValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.LoadState
import androidx.paging.LoadStates
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
Expand All @@ -44,6 +46,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import org.imaginativeworld.whynotcompose.base.models.Event
import org.imaginativeworld.whynotcompose.base.models.github.GithubRepo
Expand Down Expand Up @@ -146,7 +149,15 @@ class DataFetchAndPagingViewModel @Inject constructor(
// --------------------------------

if (query.isNullOrBlank()) {
_items.value = emptyFlow()
_items.value = flowOf(
PagingData.empty(
sourceLoadStates = LoadStates(
refresh = LoadState.NotLoading(true),
prepend = LoadState.NotLoading(true),
append = LoadState.NotLoading(true)
)
)
)

return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fun EmptyView(
) {
Column(
Modifier
.padding(start = 32.dp, end = 32.dp, bottom = 24.dp),
.padding(start = 32.dp, top = 32.dp, end = 32.dp, bottom = 32.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_arrow_down.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2023 Md. Mahmudul Hasan Shohag
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ========================================================================
~
~ Project: Why Not Compose!
~ Developed by: @ImaginativeShohag
~
~ Md. Mahmudul Hasan Shohag
~ [email protected]
~
~ Source: https://github.com/ImaginativeShohag/Why-Not-Compose
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_arrow_left.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2023 Md. Mahmudul Hasan Shohag
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ========================================================================
~
~ Project: Why Not Compose!
~ Developed by: @ImaginativeShohag
~
~ Md. Mahmudul Hasan Shohag
~ [email protected]
~
~ Source: https://github.com/ImaginativeShohag/Why-Not-Compose
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_arrow_left_single.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2023 Md. Mahmudul Hasan Shohag
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ========================================================================
~
~ Project: Why Not Compose!
~ Developed by: @ImaginativeShohag
~
~ Md. Mahmudul Hasan Shohag
~ [email protected]
~
~ Source: https://github.com/ImaginativeShohag/Why-Not-Compose
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_brightness_high.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2023 Md. Mahmudul Hasan Shohag
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ========================================================================
~
~ Project: Why Not Compose!
~ Developed by: @ImaginativeShohag
~
~ Md. Mahmudul Hasan Shohag
~ [email protected]
~
~ Source: https://github.com/ImaginativeShohag/Why-Not-Compose
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_car.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2023 Md. Mahmudul Hasan Shohag
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ========================================================================
~
~ Project: Why Not Compose!
~ Developed by: @ImaginativeShohag
~
~ Md. Mahmudul Hasan Shohag
~ [email protected]
~
~ Source: https://github.com/ImaginativeShohag/Why-Not-Compose
-->

<vector android:height="64dp"
android:viewportHeight="256"
android:viewportWidth="256"
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_close.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2023 Md. Mahmudul Hasan Shohag
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ========================================================================
~
~ Project: Why Not Compose!
~ Developed by: @ImaginativeShohag
~
~ Md. Mahmudul Hasan Shohag
~ [email protected]
~
~ Source: https://github.com/ImaginativeShohag/Why-Not-Compose
-->

<vector android:height="24dp"
android:viewportHeight="18"
android:viewportWidth="18"
Expand Down
Loading

0 comments on commit b12fee3

Please sign in to comment.