Skip to content

Commit

Permalink
Update project dependencies to recent version numbers. Remove anko de…
Browse files Browse the repository at this point in the history
…pendencies. Remove a dependency on realm from the ui layers
  • Loading branch information
yousuf-haque committed Dec 5, 2016
1 parent b90679e commit 0f6e720
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 73 deletions.
42 changes: 21 additions & 21 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ apply plugin: 'realm-android'


android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.1"

defaultConfig {
applicationId "com.yohaq.titan"
minSdkVersion 21
targetSdkVersion 23
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -28,6 +28,9 @@ android {
dataBinding {
enabled = true
}
dexOptions {
javaMaxHeapSize "12g"
}
}
kapt {
generateStubs = true
Expand All @@ -37,36 +40,33 @@ dependencies {

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

compile 'org.jetbrains.anko:anko-sdk21:0.9'
compile 'org.jetbrains.anko:anko-support-v4:0.9'
compile 'org.jetbrains.anko:anko-appcompat-v7:0.9'
compile 'org.jetbrains.anko:anko-cardview-v7:0.9'
compile 'org.jetbrains.anko:anko-gridlayout-v7:0.9'
compile 'org.jetbrains.anko:anko-recyclerview-v7:0.9'
compile 'org.jetbrains.anko:anko-design:0.9'



testCompile 'junit:junit:4.12'

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile "com.android.support:design:23.4.0"
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
compile "com.android.support:design:25.0.1"

compile 'com.google.dagger:dagger:2.0.2'
kapt 'com.google.dagger:dagger-compiler:2.0.2'
provided 'org.glassfish:javax.annotation:10.0-b28'
kapt 'com.google.guava:guava:19.0'
kapt 'com.google.dagger:dagger-compiler:2.8'
compile 'com.google.dagger:dagger:2.8'
provided 'javax.annotation:jsr250-api:1.0'
// provided 'org.glassfish:javax.annotation:10.0-b28'

compile 'com.roughike:bottom-bar:1.3.5'

compile 'io.reactivex:rxjava:1.0.10'

kapt 'com.android.databinding:compiler:2.1.2'
kapt 'com.android.databinding:compiler:1.0-rc4'


}

buildscript {
ext.kotlin_version = '1.0.2'
ext.kotlin_version = '1.0.5-2'
repositories {
mavenCentral()
}
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/kotlin/com/yohaq/titan/data/ExercisesManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import javax.inject.Inject
/**
* Created by yousufhaque on 6/7/16.
*/
class ExercisesManager @Inject constructor(val realm: Realm) {
class ExercisesManager @Inject constructor(val realmFactory: () -> Realm) {


fun createExercise(name: String) {

realm.executeTransaction {
val exercise = realm.createObject(Exercise::class.java)
exercise.name = name
realmFactory.invoke().executeTransaction {
realmFactory.invoke().copyToRealm(Exercise(name = name))
}

}

fun getExercises(): Observable<List<Exercise>> = realm.where(Exercise::class.java).findAllAsync().asObservable().map { realm.copyFromRealm(it) }
fun getExercises(): Observable<List<Exercise>> {
val realm = realmFactory.invoke()
return realm.where(Exercise::class.java).findAllAsync().asObservable().map { realm.copyFromRealm(it) }.doOnUnsubscribe { realm.close() }
}

}
16 changes: 10 additions & 6 deletions app/src/main/kotlin/com/yohaq/titan/data/WorkoutManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ import javax.inject.Inject
/**
* Created by yousufhaque on 6/8/16.
*/
class WorkoutManager @Inject constructor(val realm: Realm) {
class WorkoutManager @Inject constructor(val realmFactory: () -> Realm) {


fun createWorkout(dateCreated: Date, exercise: Exercise, sets: RealmList<WorkoutSet>) {
fun createWorkout(dateCreated: Date, exercise: Exercise, sets: List<WorkoutSet>) {

realm.executeTransaction {
val workout = Workout(date = dateCreated, exercise = exercise, sets = sets)
realmFactory.invoke().executeTransaction {
val workout = Workout( dateCreated, exercise, RealmList<WorkoutSet>(*sets.toTypedArray()))

realm.copyToRealmOrUpdate(workout)
realmFactory.invoke().copyToRealmOrUpdate(workout)
}

}

fun getWorkouts(): Observable<List<Workout>> = realm.where(Workout::class.java).findAllAsync().asObservable().map { realm.copyFromRealm(it) }
fun getWorkouts(): Observable<List<Workout>> {
val realm = realmFactory.invoke()

return realm.where(Workout::class.java).findAllAsync().asObservable().map { realm.copyFromRealm(it) }.doOnUnsubscribe { realm.close() }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package com.yohaq.titan.data.interactors
import com.yohaq.titan.data.WorkoutManager
import com.yohaq.titan.data.models.Exercise
import com.yohaq.titan.data.models.WorkoutSet
import io.realm.RealmList
import java.util.*
import javax.inject.Inject

/**
* Created by yousufhaque on 6/8/16.
*/
class CreateWorkoutInteractor @Inject constructor(private val workoutManager: WorkoutManager) {
fun createWorkout(dateCreated: Date, exercise: Exercise, sets: RealmList<WorkoutSet>) = workoutManager.createWorkout(dateCreated, exercise, sets)
fun createWorkout(dateCreated: Date, exercise: Exercise, sets: List<WorkoutSet>) = workoutManager.createWorkout(dateCreated, exercise, sets)
}
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/yohaq/titan/data/models/Exercise.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import java.util.*
*/
@RealmClass
open class Exercise(
@PrimaryKey
var id: String = UUID.randomUUID().toString(),
var name: String = ""
) : RealmModel {
@PrimaryKey
var id: String = UUID.randomUUID().toString()
}
10 changes: 6 additions & 4 deletions app/src/main/kotlin/com/yohaq/titan/data/models/Workout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import java.util.*

@RealmClass
open class Workout(

@PrimaryKey
var id: String = UUID.randomUUID().toString(),
var date: Date = Date(),
var exercise: Exercise? = null,
var sets: RealmList<WorkoutSet> = RealmList<WorkoutSet>()

) : RealmModel {
@PrimaryKey
var id: String

init {
id = UUID.randomUUID().toString()
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.yohaq.titan.injection.modules

import android.content.Context
import com.yohaq.titan.injection.scopes.ApplicationScope
import dagger.Module
import dagger.Provides
import io.realm.Realm
import io.realm.RealmConfiguration

/**
* Created by yousufhaque on 6/7/16.
*/
@Module
class ApplicationModule(val context: Context) {
init {
Realm.init(context)
}

@Provides
fun providesContext(): Context = context

@Provides
fun provideRealmConfiguration(context: Context) = RealmConfiguration.Builder(context)
.name("titan.realm")
@ApplicationScope
fun provideRealmConfiguration() = RealmConfiguration.Builder()
.name("titan.realmFactory")
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import io.realm.Realm
class RealmModule {

@Provides
fun providesRealm() = Realm.getDefaultInstance()
fun providesRealmFactory() = {Realm.getDefaultInstance()}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.yohaq.titan.injection.scopes

import javax.inject.Singleton
import javax.inject.Scope

/**
* Created by yousufhaque on 6/7/16.
*/
@Singleton
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ApplicationScope
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.yohaq.titan.data.models.Exercise
import com.yohaq.titan.data.models.WorkoutSet
import com.yohaq.titan.presenters.base.BasePresenter
import com.yohaq.titan.ui.views.interfaces.CreateWorkoutView
import io.realm.RealmList
import java.util.*
import javax.inject.Inject

Expand All @@ -15,7 +14,7 @@ import javax.inject.Inject
class CreateWorkoutPresenter
@Inject constructor(private val createWorkoutInteractor: CreateWorkoutInteractor): BasePresenter<CreateWorkoutView>() {

fun createWorkout(dateCreated: Date, exercise: Exercise, sets: RealmList<WorkoutSet>) {
fun createWorkout(dateCreated: Date, exercise: Exercise, sets: List<WorkoutSet>) {
createWorkoutInteractor.createWorkout(dateCreated, exercise, sets)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.yohaq.titan.ui.viewModels.ExerciseViewModel
import com.yohaq.titan.ui.viewModels.SetViewModel
import com.yohaq.titan.ui.views.interfaces.CreateWorkoutView
import com.yohaq.titan.ui.views.interfaces.ExerciseCatalogView
import io.realm.RealmList
import kotlinx.android.synthetic.main.activity_create_workout.*
import java.util.*
import javax.inject.Inject
Expand Down Expand Up @@ -48,7 +47,7 @@ class CreateWorkoutActivity : AppCompatActivity(), CreateWorkoutView, ExerciseCa

var selectedExercise: Exercise? = null

var sets = RealmList<WorkoutSet>()
var sets : MutableList<WorkoutSet> = mutableListOf()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.yohaq.titan.presenters.WorkoutHistoryPresenter
import com.yohaq.titan.ui.activities.CreateWorkoutActivity
import com.yohaq.titan.ui.adapters.WorkoutHistoryAdapter
import com.yohaq.titan.ui.views.interfaces.WorkoutHistoryByDateView
import io.realm.Realm
import kotlinx.android.synthetic.main.daily_workout_fragment.*
import java.util.*
import javax.inject.Inject
Expand All @@ -38,8 +37,6 @@ class WorkoutHistoryFragment : Fragment(), WorkoutHistoryByDateView {
@Inject
lateinit var workoutHistoryAdapter: WorkoutHistoryAdapter

@Inject
lateinit var realm: Realm

@Inject
lateinit var presenter: WorkoutHistoryPresenter
Expand All @@ -48,7 +45,6 @@ class WorkoutHistoryFragment : Fragment(), WorkoutHistoryByDateView {
override fun onDestroy() {
super.onDestroy()
presenter.detachView()
realm.close()
}

private fun handleCreateWorkoutButtonClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.yohaq.titan.presenters.ExerciseCatalogPresenter
import com.yohaq.titan.ui.activities.CreateExerciseActivity
import com.yohaq.titan.ui.adapters.ExercisesAdapter
import com.yohaq.titan.ui.views.interfaces.ExerciseCatalogView
import io.realm.Realm
import kotlinx.android.synthetic.main.view_exercises.view.*
import javax.inject.Inject

Expand All @@ -23,8 +22,6 @@ class ExerciseCatalog(context: Context?, attrs: AttributeSet?) : CoordinatorLayo
@Inject
lateinit var exerciseAdapter: ExercisesAdapter

@Inject
lateinit var realm: Realm

@Inject
lateinit var presenter : ExerciseCatalogPresenter
Expand All @@ -46,7 +43,6 @@ class ExerciseCatalog(context: Context?, attrs: AttributeSet?) : CoordinatorLayo
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
presenter.detachView()
realm.close()
}

override fun showExercises(exercises: List<Exercise>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.yohaq.titan.presenters.WorkoutHistoryPresenter
import com.yohaq.titan.ui.activities.CreateWorkoutActivity
import com.yohaq.titan.ui.adapters.WorkoutHistoryAdapter
import com.yohaq.titan.ui.views.interfaces.WorkoutHistoryView
import io.realm.Realm
import kotlinx.android.synthetic.main.view_workout_history.view.*
import javax.inject.Inject

Expand All @@ -21,8 +20,6 @@ class WorkoutHistory(context: Context?, attrs: AttributeSet?) : CoordinatorLayou
@Inject
lateinit var workoutHistoryAdapter: WorkoutHistoryAdapter

@Inject
lateinit var realm: Realm

@Inject
lateinit var presenter: WorkoutHistoryPresenter
Expand All @@ -41,7 +38,6 @@ class WorkoutHistory(context: Context?, attrs: AttributeSet?) : CoordinatorLayou
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
presenter.detachView()
realm.close()
}

private fun handleCreateWorkoutButtonClick() {
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.0.2'
ext.kotlin_version = '1.0.5-2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath "io.realm:realm-gradle-plugin:1.0.0"
classpath 'com.android.tools.build:gradle:2.2.2'
classpath "io.realm:realm-gradle-plugin:2.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Loading

0 comments on commit 0f6e720

Please sign in to comment.