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
/** | |
* Place the file at $HOME/.gradle/init.d/speak.gradle | |
**/ | |
gradle.ext.projectName = "" | |
gradle.ext.taskMapping = [ | |
'assembleDevDebug': 'Running debug build', | |
'connectedCheck': 'Running UI Tests', | |
'connectedDevDebugAndroidTest': 'Running UI Tests - with dev flavour and debug mode', | |
'connectedProdDebugAndroidTest': 'Running UI Tests - with prod flavour and debug mode', |
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
var job: Job? = null | |
fun makeApiCall() { | |
if (job?.isActive == true) { | |
job?.cancel() | |
} | |
job = viewModelScope.launch { | |
// ... your API call | |
} | |
} |
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
plugins { | |
id 'com.android.application' | |
id 'org.jetbrains.kotlin.android' | |
id 'kotlin-kapt' | |
} | |
dependencies { | |
def room_version = "2.4.3" |
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
class MViewModelFactory(private val todoDao: TodoDao) : ViewModelProvider.Factory { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
return when(modelClass) { | |
MainViewModel::class.java -> { | |
MainViewModel(todoDao) as T | |
} | |
CreateViewModel::class.java -> { | |
CreateViewModel(todoDao) as T | |
} | |
else -> { |
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
class MainViewModel(private val todoDao: TodoDao) : ViewModel() { | |
fun getTodos() = todoDao.getList().asLiveData() | |
fun toggleTodoStatus(id: Int, updatedStatus: Boolean) { | |
viewModelScope.launch { | |
todoDao.toggleTodo(id, updatedStatus) | |
} | |
} |
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
class CreateViewModel(private val todoDao: TodoDao) : ViewModel() { | |
fun create(task: String) { | |
viewModelScope.launch { | |
todoDao.insert(NewTodo(task)) | |
} | |
} | |
} |
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
package com.mohammadfayaz.todo.ui.create | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.Button | |
import android.widget.EditText | |
import com.mohammadfayaz.todo.R | |
import com.mohammadfayaz.todo.data.DbService | |
import com.mohammadfayaz.todo.data.NewTodo | |
import com.mohammadfayaz.todo.data.TodoDao |
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
class CreateTodoActivity : AppCompatActivity() { | |
lateinit var taskField: EditText | |
lateinit var saveButton: Button | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_create_todo) | |
taskField = findViewById(R.id.newTodoTextField) |
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
class MainActivity : AppCompatActivity() { | |
lateinit var recyclerView: RecyclerView | |
lateinit var adapter: TodoAdapter | |
lateinit var fab: FloatingActionButton | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
NewerOlder