@@ -5,6 +5,7 @@ import android.content.Context
5
5
import android.location.Geocoder
6
6
import androidx.lifecycle.*
7
7
import androidx.work.*
8
+ import com.example.basicapp.R
8
9
import com.example.basicapp.data.model.TaskPriority
9
10
import com.example.basicapp.data.room.TaskDao
10
11
import com.example.basicapp.data.model.Task
@@ -19,6 +20,7 @@ import java.util.concurrent.TimeUnit
19
20
20
21
class TaskViewModel (private val taskDao : TaskDao , application : Application ) : ViewModel() {
21
22
23
+ val context: Context = application.applicationContext
22
24
private val tasksSortedByDate: LiveData <List <Task >> = taskDao.getItemsByTime().asLiveData()
23
25
private val tasksSortedByPriority: LiveData <List <Task >> =
24
26
taskDao.getItemByPriority().asLiveData()
@@ -152,9 +154,9 @@ class TaskViewModel(private val taskDao: TaskDao, application: Application) : Vi
152
154
153
155
fun setSelectedPriority (menuItemPosition : Int ) {
154
156
when (menuItemPosition) {
155
- 0 -> _selectedPriority .value = " Low priority "
156
- 1 -> _selectedPriority .value = " Medium priority "
157
- else -> _selectedPriority .value = " High priority "
157
+ 0 -> _selectedPriority .value = context.getString( R .string.low_priority)
158
+ 1 -> _selectedPriority .value = context.getString( R .string.medium_priority)
159
+ else -> _selectedPriority .value = context.getString( R .string.high_priority)
158
160
}
159
161
}
160
162
@@ -168,19 +170,17 @@ class TaskViewModel(private val taskDao: TaskDao, application: Application) : Vi
168
170
169
171
fun taskPriority (selectedPriority : String ): TaskPriority {
170
172
return when (selectedPriority) {
171
- " Low priority" -> TaskPriority .LOW
172
- " Prioridad baja" -> TaskPriority .LOW
173
- " Medium priority" -> TaskPriority .MEDIUM
174
- " Prioridad mediana" -> TaskPriority .MEDIUM
173
+ context.getString(R .string.low_priority) -> TaskPriority .LOW
174
+ context.getString(R .string.medium_priority) -> TaskPriority .MEDIUM
175
175
else -> TaskPriority .HIGH
176
176
}
177
177
}
178
178
179
179
fun taskPriorityString (taskPriority : TaskPriority ): String {
180
180
return when (taskPriority) {
181
- TaskPriority .LOW -> " Low priority "
182
- TaskPriority .MEDIUM -> " Medium priority "
183
- else -> " High priority "
181
+ TaskPriority .LOW -> context.getString( R .string.low_priority)
182
+ TaskPriority .MEDIUM -> context.getString( R .string.medium_priority)
183
+ else -> context.getString( R .string.high_priority)
184
184
}
185
185
}
186
186
0 commit comments