Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Refactored to Hilt beta,
Browse files Browse the repository at this point in the history
Updates gradle dependencies,
Updated version code,
lint checks refactor.
  • Loading branch information
Sharkaboi committed Mar 19, 2021
1 parent 4a442b3 commit f1570d2
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# <p align="center"><img src="./assets/logo.png" width="40"/><br>Jokes</p>
<p align="center">
<img src="https://github.com/Sharkaboi/Jokes/workflows/Gradle%20Build/badge.svg" alt="Gradle Build">
<img src="https://img.shields.io/badge/Kotlin-1.4.20-blue" alt="Kotlin Version">
<img src="https://img.shields.io/badge/Kotlin-1.4.31-blue" alt="Kotlin Version">
<img src="https://img.shields.io/badge/Min%20API-23-green" alt="Min API">
<img src="https://img.shields.io/badge/License-MIT-orange" alt="License">
<img src="https://img.shields.io/github/contributors/sharkaboi/jokes" alt="Contributors"><br>
Expand All @@ -19,7 +19,7 @@
* Gson
* ViewBinding
* Coroutines
* Hilt
* Hilt beta
* Jetpack navigation
* [razir/ProgressButton](https://github.com/razir/ProgressButton)
* [15Dkatz/official_joke_api](https://github.com/15Dkatz/official_joke_api)
Expand Down
36 changes: 17 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ plugins {
}

android {
compileSdkVersion 29
buildToolsVersion "30.0.2"
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.cybershark.jokes"
minSdkVersion 23
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionName "1.1"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -57,12 +57,12 @@ dependencies {

// Lifecycle dependencies
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"

// Design dependencies
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.github.razir.progressbutton:progressbutton:2.1.0'

Expand All @@ -72,30 +72,28 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

//room
implementation "androidx.room:room-runtime:2.2.5"
kapt "androidx.room:room-compiler:2.2.5"
implementation "androidx.room:room-ktx:2.2.5"
implementation "androidx.room:room-runtime:2.2.6"
kapt "androidx.room:room-compiler:2.2.6"
implementation "androidx.room:room-ktx:2.2.6"

// Navigation dependencies
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.4'

//hilt dependencies
implementation 'com.google.dagger:hilt-android:2.29.1-alpha'
kapt 'com.google.dagger:hilt-android-compiler:2.29.1-alpha'
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02'
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'
implementation 'com.google.dagger:hilt-android:2.33-beta'
kapt 'com.google.dagger:hilt-android-compiler:2.33-beta'

//coil dependencies
implementation "io.coil-kt:coil:1.0.0-rc3"

//coroutines dependencies
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'

// Testing dependencies
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/cybershark/jokes/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import com.cybershark.jokes.data.room.FavoriteJokeDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ApplicationComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton

@Module
@InstallIn(ApplicationComponent::class)
@InstallIn(SingletonComponent::class)
object DataModule {

@Provides
Expand Down Expand Up @@ -52,7 +52,7 @@ object DataModule {

@Provides
@Singleton
fun getRetrofit(@ApplicationContext context: Context): JokeApiService {
fun getRetrofit(): JokeApiService {
return Retrofit.Builder()
.baseUrl(ApiConstants.apiEndpoint)
.addConverterFactory(GsonConverterFactory.create())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.cybershark.jokes.ui.favorite

import androidx.hilt.Assisted
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.*
import com.cybershark.jokes.data.respositories.MainRepository
import com.cybershark.jokes.data.room.JokeEntity
import com.cybershark.jokes.util.*
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class FavoritesViewModel
@ViewModelInject
@Inject
constructor(
@Assisted savedStateHandle: SavedStateHandle,
private val savedStateHandle: SavedStateHandle,
private val mainRepository: MainRepository
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.fragment.app.viewModels
import coil.load
import com.cybershark.jokes.R
import com.cybershark.jokes.databinding.FragmentHomeBinding
import com.cybershark.jokes.ui.home.util.JokeState
import com.cybershark.jokes.util.UIState
import com.cybershark.jokes.util.makeVisible
import com.cybershark.jokes.util.observe
Expand Down
14 changes: 6 additions & 8 deletions app/src/main/java/com/cybershark/jokes/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.cybershark.jokes.ui.home

import androidx.hilt.Assisted
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.*
import com.cybershark.jokes.data.models.Joke
import com.cybershark.jokes.data.respositories.MainRepository
import com.cybershark.jokes.ui.home.util.JokeState
import com.cybershark.jokes.util.*
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class HomeViewModel
@ViewModelInject
@Inject
constructor(
@Assisted savedStateHandle: SavedStateHandle,
private val savedStateHandle: SavedStateHandle,
private val mainRepository: MainRepository
) : ViewModel() {

Expand Down Expand Up @@ -80,7 +82,3 @@ constructor(
}
}

data class JokeState(
val joke: Joke,
val isJokeFavorite: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cybershark.jokes.ui.home.util

import com.cybershark.jokes.data.models.Joke

data class JokeState(
val joke: Joke,
val isJokeFavorite: Boolean
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.cybershark.jokes.ui.settings

import androidx.hilt.Assisted
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.*
import com.cybershark.jokes.data.respositories.MainRepository
import com.cybershark.jokes.util.UIState
import com.cybershark.jokes.util.getDefault
import com.cybershark.jokes.util.setError
import com.cybershark.jokes.util.setSuccess
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SettingsViewModel
@ViewModelInject
@Inject
constructor(
@Assisted savedStateHandle: SavedStateHandle,
private val savedStateHandle: SavedStateHandle,
private val mainRepository: MainRepository
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ internal fun View.shortSnackBar(
message: String,
action: (Snackbar.() -> Unit)? = null
) {
val snackbar = Snackbar.make(this, message, Snackbar.LENGTH_SHORT)
action?.let { snackbar.it() }
snackbar.setAnchorView(R.id.bottomNavigation)
snackbar.show()
val snackBar = Snackbar.make(this, message, Snackbar.LENGTH_SHORT)
action?.let { snackBar.it() }
snackBar.setAnchorView(R.id.bottomNavigation)
snackBar.show()
}

internal fun Snackbar.action(message: String, action: (View) -> Unit) {
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.20"
ext.kotlin_version = "1.4.31"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.29.1-alpha'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.33-beta'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Nov 27 19:47:55 IST 2020
#Fri Mar 19 10:37:39 IST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

0 comments on commit f1570d2

Please sign in to comment.