Skip to content

Commit

Permalink
FIX: convert kt
Browse files Browse the repository at this point in the history
  • Loading branch information
SummerRock committed Apr 2, 2024
1 parent 374255e commit 2494913
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class DashboardFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?, savedInstanceState: Bundle?
): View {
val viewModel = ViewModelProvider(this).get(
DashboardViewModel::class.java
)
val viewModel = ViewModelProvider(this)[DashboardViewModel::class.java]
binding = FragmentDashboardBinding.inflate(inflater, container, false)
val root: View = binding!!.getRoot()
val textView = binding!!.textDashboard
Expand Down Expand Up @@ -54,9 +52,9 @@ class DashboardFragment : Fragment() {
}
}

suspend fun ioCode1() {
private suspend fun ioCode1() {
withContext(Dispatchers.IO) {
LogUtils.v("");
LogUtils.v("io opera 1");
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.myapplication.main.ui.dashboard

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.myapplication.main.ui.dashboard.CounterIntent.Decrement
import com.example.myapplication.main.ui.dashboard.model.CounterModel

class DashboardViewModel : ViewModel() {
val counterModelLiveData = MutableLiveData(CounterModel(0))
fun getCounterModelLiveData(): LiveData<CounterModel> {
return counterModelLiveData
}

fun processIntent(intent: CounterIntent?) {
val currentModel = counterModelLiveData.getValue()
var newModel: CounterModel? = null
if (intent is CounterIntent.Increment) {
newModel = CounterModel(currentModel!!.count + 1)
} else if (intent is Decrement) {
newModel = CounterModel(currentModel!!.count - 1)
}
if (newModel != null) {
counterModelLiveData.value = newModel
}
}
}

0 comments on commit 2494913

Please sign in to comment.