Skip to content

Commit

Permalink
19.05.2023
Browse files Browse the repository at this point in the history
-добавлена кнопка назад и диалог на неё в таймер
-исправлен баг, когда состоняие вьюмодели не менялось после дестроя фрагмента
-изменены парамерты editText в опциях
-исправлен баг с крашем приложение при вводе пустой строки в опции
-добавлен голый topAppBar

-добавлен переход в таймер и изенена логика для таймера(работает)
-добавлен альтернативный лэйаут для портреного режима таймера

Tasks:
-добавить экран настроек (язык и темная тема)

-добавить переход на экран настроек

-добавить скролабл поведение на appBar, чтобы он уезжал когда ты крутишь ресайкл вниз

-удалить лишние вью с главного (титул старый и кнопку настроек старую)

- изменить поведение крестиков на editText в опциях с цифрами, надо чтобы они уходили, когда фокус не на окне

- сдвинуть ближе кнопки в опциях, но чтобы сохранился эффек смены

- настроить цвета в таймере

-настроить обработку ошибок ввода более точечно в опциях

-сделать по кнопке назад(добавить) из таймера отключение таймера

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

-сделать выбор при нажатии назад(отменить тренировку или нет) поменять кнопку старт на главной с старт на котинью
  • Loading branch information
alexxk2 committed May 19, 2023
1 parent c301f9b commit 2aa2d95
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class WorkoutAdapter(

if (item.hasFocus) {
holder.binding.stageName.setTextColor(Color.parseColor("#737373"))
holder.binding.numberOfSetsLeft.setTextColor(Color.parseColor("#63F44336"))
holder.binding.numberOfSetsLeft.setTextColor(Color.parseColor("#1769AA"))
holder.binding.constraintLayout.scaleX = 1.3f
holder.binding.constraintLayout.scaleY = 1.3f
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class OptionsFragment : Fragment() {
editSetsNumber.setText(workout.numberOfSets.toString(), TextView.BufferType.SPANNABLE)
editWorkTime.setText(workout.workTime.toString(), TextView.BufferType.SPANNABLE)
editRestTime.setText(workout.restTime.toString(), TextView.BufferType.SPANNABLE)
//добавить клик листенер на апдейт объекта

optionsDeleteButton.setOnClickListener { showDeleteConfirmationDialog() }
optionsAddUpdateButton.setOnClickListener { updateWorkout() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.addCallback
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Priority
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.practice.getup.App
import com.practice.getup.R
import com.practice.getup.activities.ViewModelFactoryFragments
Expand All @@ -31,7 +35,7 @@ class WorkoutFragment : Fragment() {
private var _binding: FragmentWorkoutBinding? = null
private val binding get() = _binding!!
private lateinit var options: Options
private val viewModel: WorkoutViewModel by activityViewModels {
private val viewModel: WorkoutViewModel by viewModels {
ViewModelFactoryFragments(workout)
}
private lateinit var adapter: WorkoutAdapter
Expand All @@ -48,6 +52,11 @@ class WorkoutFragment : Fragment() {
it.getParcelable(WORKOUT, Workout::class.java)!!
} else it.getParcelable(WORKOUT)!!
}

val callback = requireActivity().onBackPressedDispatcher.addCallback(this){
showFinishConfirmationDialog()
}

}

override fun onCreateView(
Expand Down Expand Up @@ -107,6 +116,9 @@ class WorkoutFragment : Fragment() {
}
binding.pauseButton.setOnClickListener { viewModel.pauseTimer() }
binding.restartButton.setOnClickListener { viewModel.restartTimer() }
binding.backButton.setOnClickListener {
showFinishConfirmationDialog()
}

}

Expand Down Expand Up @@ -182,13 +194,28 @@ class WorkoutFragment : Fragment() {
}
}

private fun showFinishConfirmationDialog(){
MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.alert_dialog_title))
.setMessage(getString(R.string.alert_dialog_message_finish))
.setCancelable(false)
.setNegativeButton(getString(R.string.answer_no)){_,_ ->}
.setPositiveButton(getString(R.string.answer_yes)){_,_ ->
val action = WorkoutFragmentDirections.actionWorkoutFragmentToMainFragment()
findNavController().navigate(action)
}
.show()
}

private fun createMediaPlayer(soundRes: Int){
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(context, soundRes)
mediaPlayer?.start()
}
}



override fun onDestroy() {
super.onDestroy()
mediaPlayer?.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class OptionsViewModel : ViewModel() {
}

fun getPreparationTimeInput(input: Editable?) {
preparationTimeInput = input.toString().toInt()
preparationTimeInput = input.toString().toIntOrNull() ?: 0
}

fun getWorkTimeInput(input: Editable?) {
workTimeInput = input.toString().toInt()
workTimeInput = input.toString().toIntOrNull() ?: 0
}

fun getRestTimeInput(input: Editable?) {
restTimeInput = input.toString().toInt()
restTimeInput = input.toString().toIntOrNull() ?: 0
}

fun getSetsNumberInput(input: Editable?) {
numberOfSetsInput = input.toString().toInt()
numberOfSetsInput = input.toString().toIntOrNull() ?: 0
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,5 @@ class WorkoutViewModel(private val workout: Workout) : ViewModel() {
tempList[tempList.size - 1] = updatedStage
_stageList.value = tempList
}

}
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_settings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="28dp" android:tint="#000000"
<vector android:height="28dp" android:tint="@color/white"
android:viewportHeight="24" android:viewportWidth="24"
android:width="28dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/workout_list_item_background.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/main_app_color_super_soft"/>
<solid android:color="@color/light_blue"/>
<corners android:radius="20dp" />
</shape>
132 changes: 132 additions & 0 deletions app/src/main/res/layout-land/fragment_workout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.WorkoutFragment">

<ImageButton
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_arrow_back"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="64dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@id/local_timer_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/back_button" />

<TextView
android:layout_marginStart="48dp"
android:id="@+id/local_timer_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="start"
android:gravity="center"
android:singleLine="true"
android:text="@string/default_total_time"
android:textAlignment="center"
android:textColor="@color/hard_grey"
android:textSize="75sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/general_timer_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:text="@string/default_total_time"
android:textAlignment="center"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/total_time_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:ellipsize="end"
android:lines="1"
android:text="@string/total_time_title"
android:textColor="@color/grey"
android:textSize="15sp"
app:layout_constraintBaseline_toBaselineOf="@id/general_timer_view"
app:layout_constraintBottom_toBottomOf="@+id/general_timer_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/general_timer_view" />

<Button
android:id="@+id/start_button"
style="@style/GeneralRedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_button"

app:layout_constraintBottom_toBottomOf="@+id/local_timer_view"
app:layout_constraintStart_toEndOf="@id/local_timer_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/local_timer_view" />

<Button
android:id="@+id/pause_button"
style="@style/GeneralRedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pause_button"
android:visibility="invisible"

app:layout_constraintBottom_toBottomOf="@+id/local_timer_view"
app:layout_constraintStart_toEndOf="@id/local_timer_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/local_timer_view" />

<Button
android:id="@+id/restart_button"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:text="@string/restart_button"
android:textColor="@color/dark_blue"
android:textSize="18sp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/local_timer_view"
app:layout_constraintStart_toEndOf="@id/local_timer_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/local_timer_view"
app:strokeColor="@color/dark_blue" />


<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/global_progress_indicator"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="20dp"
android:contentDescription="@string/progress_indicator"
app:indicatorColor="@color/dark_blue"
app:indicatorDirectionLinear="startToEnd"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/general_timer_view"
app:trackColor="@color/light_blue"
app:trackCornerRadius="8dp"
app:trackThickness="10dp" />


</androidx.constraintlayout.widget.ConstraintLayout>
57 changes: 31 additions & 26 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,33 @@

tools:context=".fragments.MainFragment">


<com.google.android.material.appbar.AppBarLayout
android:id="@+id/top_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/dark_blue"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/topAppBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:menu="@menu/top_app_bar"
app:title="@string/my_workouts"
app:titleTextColor="@color/white" />

</com.google.android.material.appbar.AppBarLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:text="@string/my_workouts"
android:textSize="30sp"
android:textColor="@color/dark_blue"
android:textSize="30sp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/settings_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/settings_button" />
Expand All @@ -26,6 +46,7 @@
android:layout_marginEnd="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_settings"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand All @@ -36,11 +57,11 @@
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
app:srcCompat="@drawable/ic_add"
app:backgroundTint="@color/dark_blue"
app:tint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_add"
app:tint="@color/white" />


<com.google.android.material.floatingactionbutton.FloatingActionButton
Expand All @@ -57,39 +78,28 @@
app:srcCompat="@drawable/ic_delete"
app:tint="@color/white" />

<!--<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/floating_button"
android:layout_width="180dp"
android:layout_height="60dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:text="@string/add_workout"
app:icon="@drawable/ic_add"
app:iconGravity="start"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />-->


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="24dp"
android:paddingHorizontal="12dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/settings_button"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toBottomOf="@id/top_app_bar"
app:layout_constraintVertical_bias="0.0"

/>

<LinearLayout
android:id="@+id/empty_list_views"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -101,9 +111,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_weight"
android:contentDescription="@string/weight_image"
/>
android:src="@drawable/ic_weight" />

<TextView
android:id="@+id/empty_list_message"
Expand All @@ -116,8 +125,4 @@
</LinearLayout>






</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 2aa2d95

Please sign in to comment.