Skip to content

Commit

Permalink
Merge pull request #96 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Jul 1, 2024
2 parents eb6d139 + 0f5b27c commit 3083fd1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {
create("config") {
keyAlias = "moviesapp"
keyPassword = "Sheikh"
storeFile = file("/media/sheikh/hdd/AndroidStudioProjects/AndroidStudioProjects/MoviesApp/app/keystore.jks")
storeFile = file("/Users/sheikh/StudioProjects/MoviesApp/app/keystore.jks")
storePassword = "Sheikh"
enableV4Signing = true
}
Expand All @@ -53,8 +53,8 @@ android {
applicationId = "com.application.moviesapp"
minSdk = 24
targetSdk = 33
versionCode = 25
versionName = "1.0.24"
versionCode = 26
versionName = "1.0.25"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.application.moviesapp.data.api

import com.application.moviesapp.BuildConfig
import kotlinx.coroutines.delay
import okhttp3.Interceptor
import okhttp3.Response
import javax.inject.Inject
Expand All @@ -10,6 +11,12 @@ class NetworkInterceptor @Inject constructor(@Named("movies_api_key") private va
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request().newBuilder()
request.addHeader(name = "Authorization", value = "Bearer $apiKey")

try {
Thread.sleep(2_000L) // Introduce delay
} catch (e: InterruptedException) {
e.printStackTrace()
}
return chain.proceed(request.build())
}
}
Expand All @@ -18,6 +25,12 @@ class YoutubeNetworkInterceptor @Inject constructor(@Named("youtube_api_key") pr
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request().url.newBuilder()
request.addQueryParameter(name = "key", value = apiKey)

try {
Thread.sleep(2_000L) // Introduce delay
} catch (e: InterruptedException) {
e.printStackTrace()
}
return chain.proceed(chain.request().newBuilder().url(request.build()).build())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.application.moviesapp.data.api.MoviesApi
import com.application.moviesapp.data.api.response.MovieNowPlayingDto
import kotlinx.coroutines.delay

class MovieNowPlayingPagingSource(private val moviesApi: MoviesApi): PagingSource<Int, MovieNowPlayingDto.Result>() {
override fun getRefreshKey(state: PagingState<Int, MovieNowPlayingDto.Result>): Int? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.time.Duration
import java.util.concurrent.TimeUnit
import javax.inject.Named
import javax.inject.Singleton

Expand All @@ -46,7 +48,12 @@ object NetworkModule {
@Singleton
@Named("movies_http_client")
fun providesOKHttpClient(networkInterceptor: NetworkInterceptor): OkHttpClient {
return OkHttpClient.Builder().addInterceptor(networkInterceptor).build()
return OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.addInterceptor(networkInterceptor)
.build()
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fun NowPlayingMoviesScreen(modifier: Modifier = Modifier,
top = bottomPadding.calculateTopPadding(),
bottom = bottomPadding.calculateBottomPadding()
).pullRefresh(pullRefreshState)) {
Column {
Column(modifier = modifier.fillMaxSize()) {
when (moviesFlow.loadState.refresh) {
is LoadState.Error -> Column(modifier = modifier
.fillMaxSize()
Expand Down Expand Up @@ -140,7 +140,9 @@ fun NowPlayingMoviesScreen(modifier: Modifier = Modifier,
is LoadState.NotLoading -> {

if (searchClicked) {
LazyVerticalGrid(columns = GridCells.Fixed(2),
LazyVerticalGrid(
modifier = modifier.weight(1f),
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
Expand All @@ -151,7 +153,9 @@ fun NowPlayingMoviesScreen(modifier: Modifier = Modifier,
}
}
} else {
LazyVerticalGrid(columns = GridCells.Fixed(2),
LazyVerticalGrid(
modifier = modifier.weight(1f),
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
Expand All @@ -164,6 +168,24 @@ fun NowPlayingMoviesScreen(modifier: Modifier = Modifier,
}
}
}

when (moviesFlow.loadState.append) {
is LoadState.Loading -> {
CircularProgressIndicator(modifier = modifier
.fillMaxWidth()
.wrapContentWidth(align = Alignment.CenterHorizontally)
.padding(16.dp))
}
is LoadState.NotLoading -> { }
is LoadState.Error -> {
Text(text = if (moviesFlow.loadState.append.endOfPaginationReached) "You have reached the end" else "",
style = MaterialTheme.typography.displayMedium,
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.SemiBold,
modifier = modifier.fillMaxWidth().wrapContentWidth(align = Alignment.CenterHorizontally).padding(16.dp),
textAlign = TextAlign.Center)
}
}
}

PullRefreshIndicator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fun NowPlayingSeriesScreen(modifier: Modifier = Modifier,
top = bottomPadding.calculateTopPadding(),
bottom = bottomPadding.calculateBottomPadding()
).pullRefresh(pullRefreshState)) {
Column {
Column(modifier = modifier.fillMaxSize()) {
when (tvSeriesFlow.loadState.refresh) {
is LoadState.Error -> Column(modifier = modifier
.fillMaxSize()
Expand Down Expand Up @@ -131,7 +131,9 @@ fun NowPlayingSeriesScreen(modifier: Modifier = Modifier,
}
is LoadState.NotLoading -> {
if (searchClicked) {
LazyVerticalGrid(columns = GridCells.Fixed(2),
LazyVerticalGrid(
modifier = modifier.weight(1f),
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
Expand All @@ -142,7 +144,9 @@ fun NowPlayingSeriesScreen(modifier: Modifier = Modifier,
}
}
} else {
LazyVerticalGrid(columns = GridCells.Fixed(2),
LazyVerticalGrid(
modifier = modifier.weight(1f),
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
Expand All @@ -156,6 +160,23 @@ fun NowPlayingSeriesScreen(modifier: Modifier = Modifier,
}
}

when (tvSeriesFlow.loadState.append) {
is LoadState.Loading -> {
CircularProgressIndicator(modifier = modifier
.fillMaxWidth()
.wrapContentWidth(align = Alignment.CenterHorizontally)
.padding(16.dp))
}
is LoadState.NotLoading -> { }
is LoadState.Error -> {
Text(text = if (tvSeriesFlow.loadState.append.endOfPaginationReached) "You have reached the end" else "",
style = MaterialTheme.typography.displayMedium,
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.SemiBold,
modifier = modifier.fillMaxWidth().wrapContentWidth(align = Alignment.CenterHorizontally).padding(16.dp),
textAlign = TextAlign.Center)
}
}
}

PullRefreshIndicator(
Expand Down

0 comments on commit 3083fd1

Please sign in to comment.