Skip to content

Commit

Permalink
Merge pull request #35 from furkanaskin/dev
Browse files Browse the repository at this point in the history
Prepare new release
  • Loading branch information
nuhkoca authored Aug 4, 2021
2 parents 100ff19 + 0ba38ba commit adce6cc
Show file tree
Hide file tree
Showing 41 changed files with 582 additions and 788 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Weatherapp
![appicon](https://user-images.githubusercontent.com/22769589/68296145-f7305d80-00a4-11ea-9cbe-24b18222bfa9.png)

Weatherapp is a simple weather forecast app, which uses some APIs to fetch 5 day / 3 hour forecast data from the [OpenWeatherMap](https://openweathermap.org/forecast5) and to fetch places,cities,counties,coords etc. from [Algolia Places](https://community.algolia.com/places/). The main goal of this app is to be a sample of how to build an high quality Android application that uses the Architecture components, Dagger etc. in Kotlin.
Weatherapp is a simple weather forecast app, which uses some APIs to fetch 5 day / 3 hour forecast data from the [OpenWeatherMap](https://openweathermap.org/forecast5) and to fetch places,cities,counties,coords etc. from [Algolia Places](https://community.algolia.com/places/). The main goal of this app is to be a sample of how to build an high quality Android application that uses the Architecture components, Hilt etc. in Kotlin.

<h2 id="Outputs">Outputs</h2>
<p><img height= "200" src="https://user-images.githubusercontent.com/22769589/68296813-82f6b980-00a6-11ea-80bc-7a0e36e6336f.gif" alt="Gif1" />
Expand All @@ -26,10 +26,10 @@ Weatherapp is a simple weather forecast app, which uses some APIs to fetch 5 day
<li><a href="https://developer.android.com/reference/androidx/lifecycle/Transformations">Transformations</a></li>
<li><a href="https://developer.android.com/topic/libraries/data-binding">Data Binding</a></li>
<li><a href="https://developer.android.com/topic/libraries/architecture/room">RoomDB</a></li>
<li><a href="https://developer.android.com/training/dependency-injection/hilt-android">Hilt</a></li>
<li><a href="https://github.com/ReactiveX/RxJava">RxJava</a></li>
<li><a href="https://github.com/ReactiveX/RxAndroid">RxAndroid</a></li>
<li><a href="https://github.com/ReactiveX/RxKotlin">RxKotlin</a></li>
<li><a href="https://github.com/google/dagger">Dagger 2</a></li>
<li><a href="https://square.github.io/retrofit/">Retrofit</a></li>
<li><a href="https://github.com/square/okhttp">OkHttp</a></li>
<li><a href="https://github.com/square/moshi">Moshi</a></li>
Expand Down
143 changes: 81 additions & 62 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'kotlin-parcelize'
apply plugin: 'org.jlleitschuh.gradle.ktlint'
apply plugin: 'dagger.hilt.android.plugin'

buildscript {
repositories {
Expand All @@ -27,20 +28,19 @@ repositories {
}

android {

compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion Configs.compileSdkVersion
buildToolsVersion Configs.buildToolsVersion

defaultConfig {
applicationId "com.faskn.app.weatherapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2
versionName "1.0.0"
applicationId Configs.applicationId
minSdkVersion Configs.minSdkVersion
targetSdkVersion Configs.targetSdkVersion
versionCode Configs.versionCode
versionName Configs.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField STRING, BUILD_TIME, "\"${rootProject.ext.buildTime}\""
buildConfigField STRING, BUILD_TIME, "\"${Configs.buildTime}\""

setProperty("archivesBaseName", "${rootProject.ext.archivesBaseName}")
setProperty("archivesBaseName", "${Configs.archivesBaseName}")
}
buildTypes {
release {
Expand Down Expand Up @@ -94,65 +94,84 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation rootProject.ext.supportv4
implementation rootProject.ext.appCompat
implementation rootProject.ext.materialDesign
implementation rootProject.ext.recyclerView
implementation rootProject.ext.cardView
implementation rootProject.ext.coreKtx
implementation rootProject.ext.threetenabp
implementation rootProject.ext.timber
implementation rootProject.ext.navigationFragment
implementation rootProject.ext.navigationUI
implementation rootProject.ext.algolia
implementation rootProject.ext.dagger
implementation rootProject.ext.daggerAndroid
implementation rootProject.ext.daggerSupport
kapt rootProject.ext.daggerKapt
kapt rootProject.ext.daggerAnnotation
implementation rootProject.ext.rxJava
implementation rootProject.ext.rxKotlin
implementation rootProject.ext.rxAndroid
implementation rootProject.ext.rxAnimations
implementation rootProject.ext.retrofit
implementation rootProject.ext.okHttp
implementation rootProject.ext.moshi
implementation rootProject.ext.moshiConverter
implementation rootProject.ext.moshiKotlin
kapt rootProject.ext.moshiKapt
implementation rootProject.ext.rxJavaAdapter
implementation rootProject.ext.picasso
implementation rootProject.ext.shadowView
implementation rootProject.ext.lifecycleExt
kapt rootProject.ext.lifecycleAnnotation
implementation rootProject.ext.liveDataKtx
implementation rootProject.ext.lifecycleViewModelKtx
implementation rootProject.ext.roomRuntime
kapt rootProject.ext.roomCompiler
implementation rootProject.ext.stethoCore
implementation rootProject.ext.stethoOkHttp
implementation rootProject.ext.stethoUrlConnection
implementation rootProject.ext.kotlinJdk8
implementation rootProject.ext.kotlinReflect

testImplementation rootProject.ext.junit
testImplementation rootProject.ext.junitTestExt
androidTestImplementation rootProject.ext.androidxTestRunner
androidTestImplementation rootProject.ext.androidxTestRules
androidTestImplementation rootProject.ext.espressoCore
testImplementation rootProject.ext.truthExt
testImplementation rootProject.ext.truth
testImplementation rootProject.ext.mockK
testImplementation rootProject.ext.coreTesting
testImplementation rootProject.ext.robolectric
// kotlin
implementation Dependencies.kotlin
implementation Dependencies.kotlinReflect

// android supports
implementation Dependencies.supportv4
implementation Dependencies.appCompat
implementation Dependencies.materialDesign
implementation Dependencies.recyclerView
implementation Dependencies.cardView
implementation Dependencies.coreKtx

// architecture components
implementation Dependencies.navigationUI
implementation Dependencies.navigationFragment
implementation Dependencies.lifecycleExt
kapt Dependencies.lifecycleAnnotation
implementation Dependencies.liveDataKtx
implementation Dependencies.lifecycleViewModelKtx
implementation Dependencies.roomRuntime
kapt Dependencies.roomCompiler

// di
implementation Dependencies.hilt
kapt Dependencies.hiltKapt

// rx
implementation Dependencies.rxJava
implementation Dependencies.rxKotlin
implementation Dependencies.rxAndroid
implementation Dependencies.rxAnimations

// network
implementation Dependencies.retrofit
implementation Dependencies.okHttp
implementation Dependencies.moshi
implementation Dependencies.moshiConverter
implementation Dependencies.moshiKotlin
kapt Dependencies.moshiKapt
implementation Dependencies.rxJavaAdapter

// image
implementation Dependencies.picasso

// debug
implementation Dependencies.stethoCore
implementation Dependencies.stethoOkHttp
implementation Dependencies.stethoUrlConnection
implementation Dependencies.timber

// shadow view
implementation Dependencies.shadowView

// date & time
implementation Dependencies.threetenabp

// search
implementation Dependencies.algolia

// test
testImplementation Dependencies.junit
testImplementation Dependencies.junitTestExt
androidTestImplementation Dependencies.androidxTestRunner
androidTestImplementation Dependencies.androidxTestRules
androidTestImplementation Dependencies.espressoCore
testImplementation Dependencies.truthExt
testImplementation Dependencies.truth
testImplementation Dependencies.mockK
testImplementation Dependencies.coreTesting
testImplementation Dependencies.robolectric
}

ktlint {
android = true
outputToConsole = true
ignoreFailures = true
enableExperimentalRules = true
version = rootProject.ext.ktlint
version = Versions.klintVersion
kotlinScriptAdditionalPaths {
include fileTree("scripts/")
}
Expand Down
16 changes: 4 additions & 12 deletions app/src/main/java/com/faskn/app/weatherapp/WeatherApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ package com.faskn.app.weatherapp
import android.app.Application
import android.os.Build
import com.facebook.stetho.Stetho
import com.faskn.app.weatherapp.di.AppInjector
import com.jakewharton.threetenabp.AndroidThreeTen
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector
import javax.inject.Inject
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

class WeatherApp : Application(), HasAndroidInjector {

@Inject
lateinit var androidInjector: DispatchingAndroidInjector<Any>

override fun androidInjector(): AndroidInjector<Any> = androidInjector
@HiltAndroidApp
class WeatherApp : Application() {

override fun onCreate() {
super.onCreate()
Expand All @@ -26,11 +18,11 @@ class WeatherApp : Application(), HasAndroidInjector {
Stetho.initializeWithDefaults(this)
}

AppInjector.init(this)
AndroidThreeTen.init(this)
}

private fun isRoboUnitTest(): Boolean {
return "robolectric" == Build.FINGERPRINT
}

}
53 changes: 13 additions & 40 deletions app/src/main/java/com/faskn/app/weatherapp/core/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,33 @@ package com.faskn.app.weatherapp.core

import android.os.Bundle
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.databinding.library.baseAdapters.BR
import androidx.lifecycle.ViewModelProvider
import dagger.android.AndroidInjection
import dagger.android.support.DaggerAppCompatActivity
import javax.inject.Inject

/**
* Created by Furkan on 2019-10-16
*/

abstract class BaseActivity<VM : BaseViewModel, DB : ViewDataBinding>(
private val mViewModelClass: Class<VM>
) :
DaggerAppCompatActivity() {

@Inject
internal lateinit var viewModelProviderFactory: ViewModelProvider.Factory
@LayoutRes private val layoutResId: Int,
viewModelClass: Class<VM>
) : AppCompatActivity() {

@LayoutRes
abstract fun getLayoutRes(): Int

val binding by lazy {
DataBindingUtil.setContentView(this, getLayoutRes()) as DB
}
protected lateinit var binding: DB

val viewModel by lazy {
ViewModelProvider(this, viewModelProviderFactory).get(mViewModelClass)
val viewModel: VM by lazy {
ViewModelProvider(this).get(viewModelClass)
}

/**
* If you want to inject Dependency Injection
* on your activity, you can override this.
*/
open fun onInject() {}

override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
initViewModel(viewModel)
onInject()
setupBindingLifecycleOwner()
binding = DataBindingUtil.setContentView(this, layoutResId) as DB
binding.run {
setVariable(BR.viewModel, viewModel)
lifecycleOwner = this@BaseActivity
}
}

/**
*
* You need override this method.
* And you need to set viewModel to binding: binding.viewModel = viewModel
*
*/

abstract fun initViewModel(viewModel: VM)

private fun setupBindingLifecycleOwner() {
binding.lifecycleOwner = this
}
}
37 changes: 10 additions & 27 deletions app/src/main/java/com/faskn/app/weatherapp/core/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,41 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingComponent
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.databinding.library.baseAdapters.BR
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.Navigation
import dagger.android.AndroidInjection

/**
* Created by Furkan on 2019-10-16
*/

abstract class BaseFragment<VM : BaseViewModel, DB : ViewDataBinding>(
@LayoutRes val layout: Int,
@LayoutRes private val layoutResId: Int,
viewModelClass: Class<VM>
) : Fragment() {

open lateinit var binding: DB
lateinit var dataBindingComponent: DataBindingComponent
private fun init(inflater: LayoutInflater, container: ViewGroup) {
binding = DataBindingUtil.inflate(inflater, layout, container, false)
binding.lifecycleOwner = viewLifecycleOwner
binding.setVariable(BR.viewModel, viewModel)
}
protected lateinit var binding: DB
private set

open fun init() {}

private val viewModel by lazy {
(activity as? BaseActivity<*, *>)?.viewModelProviderFactory?.let {
ViewModelProvider(
this,
it
).get(viewModelClass)
}
}

open fun onInject() {}

override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(activity)
super.onCreate(savedInstanceState)
protected val viewModel: VM by lazy {
ViewModelProvider(this).get(viewModelClass)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
init(inflater, container!!)
binding = DataBindingUtil.inflate(inflater, layoutResId, container, false)
binding.run {
setVariable(BR.viewModel, viewModel)
lifecycleOwner = viewLifecycleOwner
}
init()
super.onCreateView(inflater, container, savedInstanceState)
return binding.root
}

Expand Down
Loading

0 comments on commit adce6cc

Please sign in to comment.