Skip to content

Commit

Permalink
Merge pull request #3 from Akashkamble/ktlint
Browse files Browse the repository at this point in the history
Added Ktlint and migrated to dev14.
  • Loading branch information
Akashkamble committed Jul 2, 2020
2 parents 34a0d2b + 3a5d6b5 commit b55e707
Show file tree
Hide file tree
Showing 29 changed files with 107 additions and 100 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {

composeOptions {
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
kotlinCompilerExtensionVersion "0.1.0-dev13"
kotlinCompilerExtensionVersion "0.1.0-dev14"
}
}

Expand Down Expand Up @@ -78,10 +78,10 @@ dependencies {
implementation "org.koin:koin-android-viewmodel:$koin_version"

/*---------------------ChromeCustomTab------------------------------*/
implementation 'androidx.browser:browser:1.3.0-alpha01'
implementation 'androidx.browser:browser:1.3.0-alpha04'

/*---------------------CoilImageLoader------------------------------*/
implementation "dev.chrisbanes.accompanist:accompanist-coil:0.1.5"
implementation "dev.chrisbanes.accompanist:accompanist-coil:0.1.6"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.akash.newzz_compose

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.akash.newzz_compose", appContext.packageName)
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/akash/newzz_compose/Category.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ internal annotation class Category {
const val BUSINESS = "business"
const val TECH = "technology"
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/akash/newzz_compose/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ object Constants {
get() = BuildConfig.API_KEY
val COUNTRY: String
get() = "in"
}
}
6 changes: 2 additions & 4 deletions app/src/main/java/com/akash/newzz_compose/NewsApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ class NewsApplication : Application() {
override fun onCreate() {
super.onCreate()
instances = this
startKoin{
startKoin {
androidLogger()
androidContext(this@NewsApplication)
modules(appModule)
}
}


companion object {
lateinit var instances: NewsApplication


fun isNetworkConnected(): Boolean {
val connectivityManager =
instances.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectivityManager.activeNetworkInfo
return networkInfo != null && networkInfo.isConnected
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package com.akash.newzz_compose.data.apiservice
import com.akash.newzz_compose.Constants
import com.akash.newzz_compose.NewsApplication
import com.akash.newzz_compose.data.response.NewsResponse
import java.io.File
import java.util.concurrent.TimeUnit
import okhttp3.Cache
import okhttp3.CacheControl
import okhttp3.Interceptor
Expand All @@ -15,26 +17,21 @@ import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.http.GET
import retrofit2.http.Query
import java.io.File
import java.util.concurrent.TimeUnit

interface NewsApiService {


@GET("top-headlines?sortBy=publishedAt&pageSize=25")
@GET("top-headlines?sortBy=publishedAt&pageSize=50")
suspend fun getArticlesByCateGoryAsync(
@Query("category") category: String,
@Query("country") country: String = Constants.COUNTRY
): Response<NewsResponse>


companion object {

private const val HEADER_CACHE_CONTROL = "Cache-Control"
private const val HEADER_PRAGMA = "Pragma"
private const val cacheSize = (5 * 1024 * 1024).toLong() // 5 MB


operator fun invoke(): NewsApiService {
val requestInterceptor = Interceptor { chain ->

Expand All @@ -58,7 +55,6 @@ interface NewsApiService {

val offlineInterceptor = Interceptor { chain ->


val url = chain.request()
.url
.newBuilder()
Expand Down Expand Up @@ -86,7 +82,6 @@ interface NewsApiService {
.removeHeader(HEADER_CACHE_CONTROL)
.cacheControl(cacheControl)
.build()

}

return@Interceptor chain.proceed(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import com.akash.newzz_compose.utils.Result
*/
interface NewsRepository {
suspend fun getArticlesByCategoryAsync(category: String, page: Int): Result<NewsResponse>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class NewsRepositoryImpl constructor(
)
}
}

} catch (e: Exception) {
e.printStackTrace()
var errorMessage = e.localizedMessage
Expand All @@ -53,5 +52,4 @@ class NewsRepositoryImpl constructor(
"apiKeyDisabled", "apiKeyExhausted", "apiKeyInvalid", "apiKeyMissing" -> false
else -> true
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ data class NewsArticle(
val url: String? = null,

val urlToImage: String? = null
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ data class NewsError(
val message: String,

val status: String
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data class NewsResponse(
var status: String,

val totalResults: Int
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class NewsSource(
val name: String?
)
)
4 changes: 2 additions & 2 deletions app/src/main/java/com/akash/newzz_compose/di/module.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.akash.newzz_compose.di

import com.akash.newzz_compose.viewmodel.NewzzViewModel
import com.akash.newzz_compose.data.apiservice.NewsApiService
import com.akash.newzz_compose.data.repository.NewsRepository
import com.akash.newzz_compose.data.repository.NewsRepositoryImpl
import com.akash.newzz_compose.viewmodel.NewzzViewModel
import com.squareup.moshi.Moshi
import org.koin.android.viewmodel.dsl.viewModel
import org.koin.dsl.module
Expand All @@ -17,4 +17,4 @@ val appModule = module {
single { NewsRepositoryImpl(get(), get()) as NewsRepository }
single { NewsApiService() }
single { Moshi.Builder().build() }
}
}
3 changes: 1 addition & 2 deletions app/src/main/java/com/akash/newzz_compose/style/TextStyle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.ui.unit.sp
* Created by Akash on 07/06/20
*/


val categoryTitleStyle = TextStyle(
fontWeight = FontWeight.Bold,
fontSize = 20.sp,
Expand All @@ -31,4 +30,4 @@ val dateTextStyle = TextStyle(
fontWeight = FontWeight.ExtraLight,
fontSize = 12.sp,
color = sourceTextColor
)
)
1 change: 0 additions & 1 deletion app/src/main/java/com/akash/newzz_compose/style/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ val darkThemeColor = darkColorPalette(
secondary = darkColor,
surface = darkColor
)

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.akash.newzz_compose.ui.home.Home
import com.akash.newzz_compose.viewmodel.NewzzViewModel
import org.koin.android.viewmodel.ext.android.viewModel


class NewzzActivity : AppCompatActivity() {
private val viewModel: NewzzViewModel by viewModel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ import androidx.ui.core.ContextAmbient
import androidx.ui.core.Modifier
import androidx.ui.foundation.Box
import androidx.ui.foundation.Text
import androidx.ui.foundation.VerticalScroller
import androidx.ui.foundation.clickable
import androidx.ui.layout.*
import androidx.ui.foundation.lazy.LazyColumnItems
import androidx.ui.layout.Column
import androidx.ui.layout.Row
import androidx.ui.layout.padding
import androidx.ui.layout.preferredHeight
import androidx.ui.layout.preferredWidth
import androidx.ui.material.Divider
import androidx.ui.text.style.TextOverflow
import androidx.ui.unit.dp
import com.akash.newzz_compose.data.response.NewsArticle
import com.akash.newzz_compose.style.*
import com.akash.newzz_compose.style.articleTitleStyle
import com.akash.newzz_compose.style.dateTextStyle
import com.akash.newzz_compose.style.dividerColor
import com.akash.newzz_compose.style.dividerColorDark
import com.akash.newzz_compose.style.sourceTextColorDark
import com.akash.newzz_compose.style.sourceTextStyle
import com.akash.newzz_compose.style.titleColorDark
import com.akash.newzz_compose.ui.common.HeightSpacer
import com.akash.newzz_compose.ui.common.RemoteImage
import com.akash.newzz_compose.ui.common.WidthSpacer
Expand Down Expand Up @@ -63,41 +73,21 @@ fun ArticleRow(article: NewsArticle, isDark: State<Boolean>, onClick: () -> Unit

@Composable
fun ArticleList(articles: List<NewsArticle>, isDark: State<Boolean>) {
/**
* App crashing while scrolling the AdapterList hence verticalScroller with Columns used.
* @see <a href="https://issuetracker.google.com/issues/154653504">Issue tracker</a>
* Not fixed in version 0.1.0-dev13
*/

val context = ContextAmbient.current
/*AdapterList(data = articles) { article ->
ArticleRow(
article = article,
isDark = isDark,
onClick = {
CustomTabUtil.launch(context, article.url.toString(), isDark.value)
}
)
HeightSpacer(value = 10.dp)
Divider(
color = if (isDark.value) dividerColorDark else dividerColor
)
}*/

VerticalScroller {
Column(modifier = Modifier.fillMaxWidth()) {
articles.forEach { article ->
ArticleRow(
article = article,
isDark = isDark,
onClick = {
CustomTabUtil.launch(context, article.url.toString(), isDark.value)
}
)
Divider(
color = if (isDark.value) dividerColorDark else dividerColor
)
}
LazyColumnItems(
items = articles,
itemContent = { article: NewsArticle ->
ArticleRow(
article = article,
isDark = isDark,
onClick = {
CustomTabUtil.launch(context, article.url.toString(), isDark.value)
}
)
HeightSpacer(value = 10.dp)
Divider(
color = if (isDark.value) dividerColorDark else dividerColor
)
}
}
}
)
}
7 changes: 5 additions & 2 deletions app/src/main/java/com/akash/newzz_compose/ui/common/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.graphics.Color
import androidx.ui.graphics.Shape
import androidx.ui.graphics.vector.VectorAsset
import androidx.ui.layout.*
import androidx.ui.layout.Spacer
import androidx.ui.layout.Stack
import androidx.ui.layout.fillMaxSize
import androidx.ui.layout.preferredHeight
import androidx.ui.layout.preferredWidth
import androidx.ui.material.CircularProgressIndicator
import androidx.ui.material.Surface
import androidx.ui.res.vectorResource
Expand Down Expand Up @@ -67,4 +71,3 @@ fun RemoteImage(
}
}
}

Loading

0 comments on commit b55e707

Please sign in to comment.