-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-начат переход на чистую архитектуру(с Koin) -решен баг с зависающим снэкбаром при переходе на другой экран (dismiss()) -переведен room на чистую архитектуру -добавлена фича, что при работающем таймере будет запрос на прекращение тренировки, а если он не был включен - будет просто переход назад, для удобства. Tasks: -перевести таймер на чистую архитектуру -подумать над тем, чтобы сделать мульти таймеровое приложение, т.е. сделать возможность прекращать тренировку, а также пускать её на заднем фоне с кнопкой континью и минитаймером вместо start workout. Так можно будет вести несколько тренировок, но надо будет делать фабрики вместо синглов в дата слое и что-то придумать со звуками( в целом спорная фича) -почистить код от мусора(старого кода, лишних картинок, стрингов и тд) -сделать выбор при нажатии назад(отменить тренировку или нет) поменять кнопку старт на главной с старт на котинью
- Loading branch information
Showing
55 changed files
with
703 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
app/src/main/java/com/practice/getup/data/db/RoomStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 7 additions & 6 deletions
13
...com/practice/getup/database/WorkoutDao.kt → .../com/practice/getup/data/db/WorkoutDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
...ractice/getup/database/WorkoutDatabase.kt → ...practice/getup/data/db/WorkoutDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/practice/getup/data/db/dto/WorkoutDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/practice/getup/data/db/impl/RoomStorageImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/practice/getup/data/repositories/impl/SettingsRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.practice.getup.data.repositories.impl | ||
|
||
class SettingsRepositoryImpl { | ||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/practice/getup/data/repositories/impl/StorageRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/practice/getup/data/repositories/impl/TimerRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.practice.getup.data.repositories.impl | ||
|
||
class TimerRepositoryImpl { | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/practice/getup/data/settings/LocalSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.practice.getup.data.settings | ||
|
||
interface LocalSettings { | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/practice/getup/data/settings/impl/LocalSettingsImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.practice.getup.data.settings.impl | ||
|
||
class LocalSettingsImpl { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.practice.getup.data.timer | ||
|
||
interface Timer { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.practice.getup.data.timer | ||
|
||
class TimerImpl { | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/practice/getup/data/timer/TimerRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.practice.getup.data.timer | ||
|
||
class TimerRepositoryImpl { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())} | ||
} |
Oops, something went wrong.