Skip to content

Commit

Permalink
Integrated detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
rob729 committed Dec 3, 2023
1 parent 7031514 commit 14f6e36
Show file tree
Hide file tree
Showing 46 changed files with 945 additions and 83 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build debug APK
on:
workflow_dispatch:
push:
branches:
- '**'
paths-ignore:
- 'README.md'
- 'assets/**'
- '.github/**/*.md'
jobs:
detekt:
runs-on: ubuntu-latest

steps:
- name: Check out source code
uses: actions/checkout@v4

- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'

- name: Run Detekt
run: ./gradlew detekt
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.ksp)
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.androidx.baselineprofile)
alias(libs.plugins.detekt)
}

def final debugAppSuffix = ".debug"
Expand All @@ -13,7 +14,7 @@ android {
experimentalProperties["android.experimental.r8.dex-startup-optimization"] = true
signingConfigs {
release {
storeFile file('/Users/robinsingh/Keystore')
storeFile file('/Users/robinsingh/Keystore')
storePassword 'q1w2e3r4t5y'
}
}
Expand Down Expand Up @@ -140,4 +141,4 @@ dependencies {
debugImplementation libs.bundle.core
benchmarkImplementation libs.bundle.core.no.op
releaseImplementation libs.bundle.core.no.op
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.rob729.newsfeed

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.rob729.newsfeed", appContext.packageName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ class DataConverter {
val jsonAdapter: JsonAdapter<ArticleDbData> = moshi.adapter(ArticleDbData::class.java)
return jsonAdapter.fromJson(json)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class NewsDBDataSource(private val newsDao: NewsDao) {
return newsDao.getNewsSourceDomainFetchTimeInMillis(newsSourceDomain)
}

}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/rob729/newsfeed/database/NewsDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ interface NewsDao {

@Query("DELETE FROM news_source_table where news_source_domain = :newsSourceDomain")
suspend fun removeSavedNewsArticlesListForNews(newsSourceDomain: String)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ abstract class NewsDatabase : RoomDatabase() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ class KoinInitializer : Initializer<KoinApplication> {
override fun dependencies(): MutableList<Class<out Initializer<*>>> {
return mutableListOf()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class NewsSourceImagesPrefetch : Initializer<Unit> {
WorkManagerInitializer::class.java
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class PlutoInitializer : Initializer<Unit> {
override fun dependencies(): MutableList<Class<out Initializer<*>>> {
return mutableListOf()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ sealed class NewsResource {
data class Success<T>(val data: T) : NewsResource()
data object Loading : NewsResource()
data class Error(val message: String) : NewsResource()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data class NetworkArticle(
@Json(name = "urlToImage") val imageUrl: String?,
@Json(name = "description") val description: String?,
@Json(name = "publishedAt") val publishedAt: String
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ data class ArticleDbData(
@ColumnInfo(name = "urlToImage") val imageUrl: String?,
@ColumnInfo(name = "description") val description: String?,
@ColumnInfo(name = "publishedAt") val publishedAt: String
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ data class NewsSourceDbData(
@ColumnInfo(name = "news_source_domain") val newsSourceDomain: String,
@ColumnInfo(name = "news_article") val newsArticle: ArticleDbData,
@ColumnInfo(name = "news_source_fetch_time") val newsSourceFetchTimeInMillis: Long,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ fun mapNetworkArticleToArticleDbData(networkArticle: NetworkArticle): ArticleDbD
}

fun mapArticleDbDataToNewsArticleUiData(articleDbData: ArticleDbData): NewsArticleUiData? {
if (articleDbData.title.isNullOrBlank() || articleDbData.description.isNullOrBlank() || articleDbData.imageUrl.isNullOrBlank())
if (articleDbData.title.isNullOrBlank()
|| articleDbData.description.isNullOrBlank()
|| articleDbData.imageUrl.isNullOrBlank()
)
return null
return NewsArticleUiData(
articleDbData.title,
Expand All @@ -27,7 +30,10 @@ fun mapArticleDbDataToNewsArticleUiData(articleDbData: ArticleDbData): NewsArtic
}

fun mapNetworkArticleToNewsArticleUiData(networkArticle: NetworkArticle): NewsArticleUiData? {
if (networkArticle.title.isNullOrBlank() || networkArticle.description.isNullOrBlank() || networkArticle.imageUrl.isNullOrBlank())
if (networkArticle.title.isNullOrBlank()
|| networkArticle.description.isNullOrBlank()
|| networkArticle.imageUrl.isNullOrBlank()
)
return null
return NewsArticleUiData(
networkArticle.title,
Expand All @@ -36,4 +42,4 @@ fun mapNetworkArticleToNewsArticleUiData(networkArticle: NetworkArticle): NewsAr
networkArticle.url,
networkArticle.publishedAt
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ sealed class HomeFeedSideEffect {
data class FeedItemClicked(val selectedItemUrl: String) : HomeFeedSideEffect()
data object NewsSourceFabClicked : HomeFeedSideEffect()
data object ScrollToTopClicked : HomeFeedSideEffect()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import com.rob729.newsfeed.model.state.UiStatus
data class SearchState(
val uiStatus: UiStatus = UiStatus.EmptyScreen,
val searchQuery: String = "",
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.TimeZone
import kotlinx.datetime.minus
import kotlinx.datetime.todayIn
import okio.IOException
import retrofit2.HttpException

class NewsApiDataSourceImpl(
private val newsApi: NewsApi
Expand Down Expand Up @@ -55,9 +57,14 @@ class NewsApiDataSourceImpl(
"${Constants.ERROR_MESSAGE_PREFIX} ${result.message()}"
)
}
} catch (exception: Exception) {
exception.printStackTrace()
NewsResource.Error("${Constants.ERROR_MESSAGE_PREFIX} ${exception.message}")
} catch (httpException: HttpException) {
// Handle HTTP exceptions (non-2xx responses)
httpException.printStackTrace()
NewsResource.Error("${Constants.ERROR_MESSAGE_PREFIX} ${httpException.message}")
} catch (ioException: IOException) {
// Handle network or I/O exceptions
ioException.printStackTrace()
NewsResource.Error("${Constants.ERROR_MESSAGE_PREFIX} ${ioException.message}")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.rob729.newsfeed.ui
enum class NavigationScreens(val routeName: String) {
HOME("home"),
SEARCH("search")
}
}
17 changes: 9 additions & 8 deletions app/src/main/java/com/rob729/newsfeed/ui/NewsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.rob729.newsfeed.ui.screen.HomeScreen
import com.rob729.newsfeed.ui.screen.SearchScreen
import com.rob729.newsfeed.ui.theme.NewsFeedTheme
import com.rob729.newsfeed.utils.Constants
import com.rob729.newsfeed.utils.Constants.ANIMATION_DURATION
import com.rob729.newsfeed.utils.NotificationHelper

@OptIn(ExperimentalComposeUiApi::class)
Expand Down Expand Up @@ -62,25 +63,25 @@ class NewsActivity : ComponentActivity() {
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
},
popEnterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
},
popExitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
}) {
HomeScreen(navController, paddingValues = paddingValues) {
Expand All @@ -92,25 +93,25 @@ class NewsActivity : ComponentActivity() {
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
},
popEnterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
},
popExitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(500)
animationSpec = tween(ANIMATION_DURATION)
)
}) {
SearchScreen(navController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import com.rob729.newsfeed.ui.components.NewsSourceBottomSheetContent
Expand Down Expand Up @@ -35,4 +34,4 @@ fun NewsSourceBottomSheet(
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ fun ScrollToTopFab(modifier: Modifier, onClick: () -> Unit) {
contentDescription = Constants.FAB_TITLE
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import com.rob729.newsfeed.utils.Constants.GRADIENT_START_COORDINATE

@Composable
fun LoadingShimmer() {
Expand All @@ -33,11 +34,11 @@ fun LoadingShimmer() {
)
val brush = Brush.linearGradient(
colors = gradient,
start = Offset(200f, 200f),
start = Offset(GRADIENT_START_COORDINATE, GRADIENT_START_COORDINATE),
end = Offset(
x = translateAnimation.value,
y = translateAnimation.value
)
)
ShimmerListItem(brush = brush)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package com.rob729.newsfeed.ui.components

import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import com.rob729.newsfeed.utils.Constants.SHIMMER_ITEM_COUNT

@Composable
fun LoadingView() {
LazyColumn {
repeat(4) {
repeat(SHIMMER_ITEM_COUNT) {
item {
LoadingShimmer()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import coil.request.CachePolicy
import coil.request.ImageRequest
import com.rob729.newsfeed.model.ui.NewsArticleUiData
import com.rob729.newsfeed.ui.theme.lexendDecaFontFamily
import com.rob729.newsfeed.utils.Constants.NEWS_FEED_ITEM_IMAGE_CROSS_FADE_DURATION
import kotlinx.datetime.Clock
import kotlinx.datetime.toInstant

Expand Down Expand Up @@ -78,7 +79,7 @@ fun NewsFeedItem(
model = ImageRequest.Builder(LocalContext.current)
.data(newsArticleUiData.imageUrl)
.crossfade(true)
.crossfade(200)
.crossfade(NEWS_FEED_ITEM_IMAGE_CROSS_FADE_DURATION)
.networkCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.diskCachePolicy(CachePolicy.DISABLED)
Expand Down Expand Up @@ -166,4 +167,4 @@ fun shareArticle(context: Context, articleUrl: String) {

val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(context, shareIntent, null)
}
}
Loading

0 comments on commit 14f6e36

Please sign in to comment.