Skip to content

Commit

Permalink
14.06.2023
Browse files Browse the repository at this point in the history
-начат переход на чистую архитектуру(с Koin)
-решен баг с зависающим снэкбаром при переходе на другой экран (dismiss())
-переведен room на чистую архитектуру
-добавлена фича, что при работающем таймере будет запрос на прекращение тренировки, а если он не был включен - будет просто переход назад, для удобства.

Tasks:

-перевести таймер на чистую архитектуру

-подумать над тем, чтобы сделать мульти таймеровое приложение, т.е. сделать возможность прекращать тренировку, а также пускать её на заднем фоне с кнопкой континью и минитаймером вместо start workout. Так можно будет вести несколько тренировок, но надо будет делать фабрики вместо синглов в дата слое и что-то придумать со звуками( в целом спорная фича)

-почистить код от мусора(старого кода, лишних картинок, стрингов и тд)

-сделать выбор при нажатии назад(отменить тренировку или нет) поменять кнопку старт на главной с старт на котинью
  • Loading branch information
alexxk2 committed Jun 14, 2023
1 parent 953dab9 commit fe32d50
Show file tree
Hide file tree
Showing 55 changed files with 703 additions and 199 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'kotlin-parcelize'
// Navigation
id 'androidx.navigation.safeargs.kotlin'
//Room
//Kotlin annotation processing tool for Room
id 'kotlin-kapt'
}

Expand All @@ -14,7 +14,7 @@ android {

defaultConfig {
applicationId "com.practice.getup"
minSdk 22
minSdk 23
targetSdk 33
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -70,4 +70,9 @@ dependencies {
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
//Koin
implementation "io.insert-koin:koin-core:$koin_version"
implementation "io.insert-koin:koin-android:$koin_version"
testImplementation "io.insert-koin:koin-test:$koin_version"

}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".App"
android:name=".app.App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -14,7 +14,7 @@
android:theme="@style/Theme.GetUp"
tools:targetApi="31">
<activity
android:name=".ui.MainActivity"
android:name=".presentation.main.ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/java/com/practice/getup/App.kt

This file was deleted.

29 changes: 29 additions & 0 deletions app/src/main/java/com/practice/getup/app/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.practice.getup.app

import android.app.Application
import com.practice.getup.data.db.WorkoutDatabase
import com.practice.getup.di.dataModule
import com.practice.getup.di.domainModule
import com.practice.getup.di.presentationModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level

class App: Application() {
val workoutDatabase: WorkoutDatabase by lazy { WorkoutDatabase.getDataBase(this) }

override fun onCreate() {
super.onCreate()

startKoin {
androidContext(this@App)
androidLogger(Level.DEBUG)
modules(listOf(
dataModule,
domainModule,
presentationModule
))
}
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/practice/getup/data/db/RoomStorage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.practice.getup.data.db

import com.practice.getup.data.db.dto.WorkoutDto

import kotlinx.coroutines.flow.Flow

interface RoomStorage {

suspend fun addNewWorkout(workoutDto: WorkoutDto)

suspend fun deleteAllWorkouts()

suspend fun deleteWorkout(workoutDto: WorkoutDto)

fun getAllWorkouts(): Flow<List<WorkoutDto>>

suspend fun getWorkout(id: Int): WorkoutDto

suspend fun updateWorkout(workoutDto: WorkoutDto)
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package com.practice.getup.database
package com.practice.getup.data.db

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.practice.getup.data.db.dto.WorkoutDto
import kotlinx.coroutines.flow.Flow


@Dao
interface WorkoutDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insert(workout: Workout)
suspend fun insert(workout: WorkoutDto)

@Update
suspend fun update(workout: Workout)
suspend fun update(workout: WorkoutDto)

@Delete
suspend fun delete(workout: Workout)
suspend fun delete(workout: WorkoutDto)

@Query("SELECT * FROM workout ORDER BY name ASC")
fun getAll(): Flow<List<Workout>>
fun getAll(): Flow<List<WorkoutDto>>

@Query("SELECT * FROM workout WHERE id =:id")
fun getWorkout(id: Int): Flow<Workout>
suspend fun getWorkout(id: Int): WorkoutDto

@Query("DELETE FROM workout")
suspend fun deleteAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.practice.getup.database
package com.practice.getup.data.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.practice.getup.data.db.dto.WorkoutDto
import com.practice.getup.database.Workout

@Database(entities = [Workout::class], version = 1, exportSchema = false)
@Database(entities = [WorkoutDto::class], version = 1, exportSchema = false)
abstract class WorkoutDatabase() : RoomDatabase() {

abstract fun workoutDao(): WorkoutDao
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/practice/getup/data/db/dto/WorkoutDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.practice.getup.data.db.dto

import android.os.Parcelable
import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize

@Parcelize
@Entity(tableName = "workout")
data class WorkoutDto(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
@NonNull @ColumnInfo val name: String,
@NonNull @ColumnInfo("preparing_time") val preparingTime: Int,
@NonNull @ColumnInfo("work_time") val workTime: Int,
@NonNull @ColumnInfo("rest_time") val restTime: Int,
@NonNull @ColumnInfo("number_of_sets") val numberOfSets: Int
): Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.practice.getup.data.db.impl

import android.content.Context
import com.practice.getup.app.App
import com.practice.getup.data.db.RoomStorage
import com.practice.getup.data.db.WorkoutDao
import com.practice.getup.data.db.dto.WorkoutDto
import kotlinx.coroutines.flow.Flow

class RoomStorageImpl(context: Context) : RoomStorage {

private val workoutDao: WorkoutDao = (context as App).workoutDatabase.workoutDao()


override suspend fun addNewWorkout(workoutDto: WorkoutDto) {
workoutDao.insert(workoutDto)
}

override suspend fun deleteAllWorkouts() {
workoutDao.deleteAll()
}

override suspend fun deleteWorkout(workoutDto: WorkoutDto) {
workoutDao.delete(workoutDto)
}

override fun getAllWorkouts(): Flow<List<WorkoutDto>> = workoutDao.getAll()

override suspend fun getWorkout(id: Int): WorkoutDto = workoutDao.getWorkout(id)

override suspend fun updateWorkout(workoutDto: WorkoutDto) {
workoutDao.update(workoutDto)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.practice.getup.data.repositories.impl

class SettingsRepositoryImpl {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.practice.getup.data.repositories.impl

import com.practice.getup.data.db.RoomStorage
import com.practice.getup.data.db.dto.WorkoutDto
import com.practice.getup.database.Workout
import com.practice.getup.domain.repositories.StorageRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class StorageRepositoryImpl(private val roomStorage: RoomStorage): StorageRepository {

override suspend fun addNewWorkout(workout: Workout) {
val workoutDto = mapToData(workout)
roomStorage.addNewWorkout(workoutDto)
}

override suspend fun deleteAllWorkouts() {
roomStorage.deleteAllWorkouts()
}

override suspend fun deleteWorkout(workout: Workout) {
val workoutDto = mapToData(workout)
roomStorage.deleteWorkout(workoutDto)
}

override fun getAllWorkouts(): Flow<List<Workout>> {
val resultFromData = roomStorage.getAllWorkouts()

return resultFromData.map {

it.map { workoutDto ->
mapToDomain(workoutDto)
}

}
}

override suspend fun getWorkout(id: Int): Workout {
val resultFromData = roomStorage.getWorkout(id)
return mapToDomain(resultFromData)

}

override suspend fun updateWorkout(workout: Workout) {
val workoutDto = mapToData(workout)
roomStorage.updateWorkout(workoutDto)
}

private fun mapToData(workout: Workout): WorkoutDto {
with(workout) {
return WorkoutDto(
id = id,
name = name,
preparingTime = preparingTime,
workTime = workTime,
restTime = restTime,
numberOfSets = numberOfSets
)
}
}

private fun mapToDomain(workoutDto: WorkoutDto): Workout{

with(workoutDto) {
return Workout(
id = id,
name = name,
preparingTime = preparingTime,
workTime = workTime,
restTime = restTime,
numberOfSets = numberOfSets
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.practice.getup.data.repositories.impl

class TimerRepositoryImpl {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.practice.getup.data.settings

interface LocalSettings {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.practice.getup.data.settings.impl

class LocalSettingsImpl {
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/practice/getup/data/timer/Timer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.practice.getup.data.timer

interface Timer {
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/practice/getup/data/timer/TimerImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.practice.getup.data.timer

class TimerImpl {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.practice.getup.data.timer

class TimerRepositoryImpl {
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/practice/getup/database/Workout.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.practice.getup.database

import android.os.Parcelable
import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize

@Parcelize
data class Workout(
val id: Int = 0,
val name: String,
val preparingTime: Int,
val workTime: Int,
val restTime: Int,
val numberOfSets: Int
) : Parcelable

/*
@Parcelize
@Entity(tableName = "workout")
data class Workout(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
@NonNull @ColumnInfo val name: String,
@NonNull @ColumnInfo("preparing_time") val preparingTime: Int,
@NonNull @ColumnInfo("work_time") val workTime: Int,
@NonNull @ColumnInfo("rest_time") val restTime: Int,
@NonNull @ColumnInfo("number_of_sets") val numberOfSets: Int
): Parcelable*/
14 changes: 14 additions & 0 deletions app/src/main/java/com/practice/getup/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.practice.getup.di

import com.practice.getup.data.db.RoomStorage
import com.practice.getup.data.db.impl.RoomStorageImpl
import com.practice.getup.data.repositories.impl.StorageRepositoryImpl
import com.practice.getup.domain.repositories.StorageRepository
import org.koin.dsl.module

val dataModule = module {

single<RoomStorage> {RoomStorageImpl(context = get())}

single<StorageRepository>{StorageRepositoryImpl(roomStorage = get())}
}
Loading

0 comments on commit fe32d50

Please sign in to comment.