Add title menu and todo list / add todo fragments
|
|
@ -64,4 +64,7 @@ dependencies {
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||||
|
|
||||||
|
// Material Library for NavDrawer
|
||||||
|
implementation 'com.google.android.material:material:1.0.0'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<activity android:name=".MainActivity">
|
<activity android:name=".MainActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 21 KiB |
|
|
@ -1,23 +1,17 @@
|
||||||
package com.taymath.tutortoolkit.addgrade
|
package com.taymath.tutortoolkit.addgrade
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Editable
|
|
||||||
import android.text.TextWatcher
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.EditText
|
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.taymath.tutortoolkit.R
|
import com.taymath.tutortoolkit.R
|
||||||
import com.taymath.tutortoolkit.addstudent.AddStudentFragmentDirections
|
|
||||||
import com.taymath.tutortoolkit.databinding.FragmentAddGradeBindingImpl
|
import com.taymath.tutortoolkit.databinding.FragmentAddGradeBindingImpl
|
||||||
import com.taymath.tutortoolkit.databinding.FragmentAddStudentBindingImpl
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabase
|
|
||||||
import kotlinx.android.synthetic.main.fragment_add_grade.*
|
|
||||||
|
|
||||||
class AddGradeFragment : Fragment() {
|
class AddGradeFragment : Fragment() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
package com.taymath.tutortoolkit.addgrade
|
package com.taymath.tutortoolkit.addgrade
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MediatorLiveData
|
import androidx.lifecycle.MediatorLiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Grade
|
import com.taymath.tutortoolkit.database.Grade
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import com.taymath.tutortoolkit.database.Student
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
class AddGradeViewModel(
|
class AddGradeViewModel(
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ package com.taymath.tutortoolkit.addgrade
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
|
||||||
|
|
||||||
class AddGradeViewModelFactory(
|
class AddGradeViewModelFactory(
|
||||||
private val student_id: Long,
|
private val student_id: Long,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import androidx.lifecycle.ViewModelProviders
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.taymath.tutortoolkit.R
|
import com.taymath.tutortoolkit.R
|
||||||
import com.taymath.tutortoolkit.databinding.FragmentAddStudentBindingImpl
|
import com.taymath.tutortoolkit.databinding.FragmentAddStudentBindingImpl
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabase
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
|
|
||||||
class AddStudentFragment : Fragment() {
|
class AddStudentFragment : Fragment() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,10 @@
|
||||||
package com.taymath.tutortoolkit.addstudent
|
package com.taymath.tutortoolkit.addstudent
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import android.widget.ImageView
|
|
||||||
import androidx.databinding.BindingAdapter
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MediatorLiveData
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.taymath.tutortoolkit.R
|
import com.taymath.tutortoolkit.database.Student
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
|
||||||
import com.taymath.tutortoolkit.studentdetail.StudentDetailFragmentArgs
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.taymath.tutortoolkit.addstudent
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
|
||||||
class AddStudentViewModelFactory(
|
class AddStudentViewModelFactory(
|
||||||
private val dataSource: StudentDatabaseDao
|
private val dataSource: StudentDatabaseDao
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import androidx.lifecycle.ViewModelProviders
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.taymath.tutortoolkit.R
|
import com.taymath.tutortoolkit.R
|
||||||
import com.taymath.tutortoolkit.databinding.FragmentChooseIconBinding
|
import com.taymath.tutortoolkit.databinding.FragmentChooseIconBinding
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabase
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that displays a list of clickable icons,
|
* Fragment that displays a list of clickable icons,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.taymath.tutortoolkit.chooseicon
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.taymath.tutortoolkit.chooseicon
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is pretty much boiler plate code for a ViewModel Factory.
|
* This is pretty much boiler plate code for a ViewModel Factory.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.taymath.tutortoolkit.studentdatabase
|
package com.taymath.tutortoolkit.database
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.taymath.tutortoolkit.studentdatabase
|
package com.taymath.tutortoolkit.database
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
|
@ -14,14 +14,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.taymath.tutortoolkit.studentdatabase
|
package com.taymath.tutortoolkit.database
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
|
|
||||||
@Database(entities = [Student::class, Grade::class], version = 1, exportSchema = false)
|
@Database(entities = [Student::class, Grade::class, Todo::class], version = 1, exportSchema = false)
|
||||||
abstract class StudentDatabase : RoomDatabase() {
|
abstract class StudentDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract val studentDatabaseDao: StudentDatabaseDao
|
abstract val studentDatabaseDao: StudentDatabaseDao
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.taymath.tutortoolkit.studentdatabase
|
package com.taymath.tutortoolkit.database
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
|
|
@ -83,5 +83,27 @@ interface StudentDatabaseDao {
|
||||||
@Query("SELECT * from grade_table WHERE student_id_long = :studentId")
|
@Query("SELECT * from grade_table WHERE student_id_long = :studentId")
|
||||||
fun getGradesWithStudentId(studentId: Long): LiveData<List<Grade>>
|
fun getGradesWithStudentId(studentId: Long): LiveData<List<Grade>>
|
||||||
|
|
||||||
|
// Todo Table Dao
|
||||||
|
@Insert
|
||||||
|
fun insertTodo(night: Todo)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun updateTodo(night: Todo)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM todo_list_table WHERE todoId= :key")
|
||||||
|
fun get(key: Long) : Todo?
|
||||||
|
|
||||||
|
@Query("DELETE FROM todo_list_table")
|
||||||
|
fun clearTodos()
|
||||||
|
|
||||||
|
@Query("SELECT * FROM todo_list_table ORDER BY todoId DESC LIMIT 1")
|
||||||
|
fun getTodo(): Todo?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM todo_list_table ORDER BY todoId DESC")
|
||||||
|
fun getAllTodos(): LiveData<List<Todo>>
|
||||||
|
|
||||||
|
@Query("DELETE FROM todo_list_table WHERE todoId= :key")
|
||||||
|
fun deleteTodoById(key: Long)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018, The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.taymath.tutortoolkit.database
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "todo_list_table")
|
||||||
|
data class Todo (
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
var todoId: Long = 0L,
|
||||||
|
|
||||||
|
@ColumnInfo(name = "todo_string")
|
||||||
|
var todoString : String = "CHECK_TODO.KT"
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018, The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.taymath.tutortoolkit.gettodo
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.lifecycle.ViewModelProviders
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import com.taymath.tutortoolkit.R
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
|
import com.taymath.tutortoolkit.databinding.FragmentGetTodoBinding
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment that displays a list of clickable icons,
|
||||||
|
* each representing a sleep quality rating.
|
||||||
|
* Once the user taps an icon, the quality is set in the current sleepNight
|
||||||
|
* and the database is updated.
|
||||||
|
*/
|
||||||
|
class GetTodoFragment : Fragment() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the Fragment is ready to display content to the screen.
|
||||||
|
*
|
||||||
|
* This function uses DataBindingUtil to inflate R.layout.fragment_get_todo.
|
||||||
|
*/
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
|
// Get a reference to the binding object and inflate the fragment views.
|
||||||
|
val binding: FragmentGetTodoBinding = DataBindingUtil.inflate(
|
||||||
|
inflater, R.layout.fragment_get_todo, container, false)
|
||||||
|
|
||||||
|
val application = requireNotNull(this.activity).application
|
||||||
|
|
||||||
|
val dataSource = StudentDatabase.getInstance(application).studentDatabaseDao
|
||||||
|
|
||||||
|
val viewModelFactory = GetTodoViewModelFactory(dataSource)
|
||||||
|
|
||||||
|
val getTodoViewModel =
|
||||||
|
ViewModelProviders.of(
|
||||||
|
this, viewModelFactory).get(GetTodoViewModel::class.java)
|
||||||
|
|
||||||
|
binding.getTodoViewModel = getTodoViewModel
|
||||||
|
|
||||||
|
getTodoViewModel.navigateToTodoList.observe(viewLifecycleOwner, Observer {
|
||||||
|
if (it == true) { // Observed state is true.
|
||||||
|
this.findNavController().navigate(
|
||||||
|
GetTodoFragmentDirections.actionGetTodoFragmentToTodoListFragment())
|
||||||
|
getTodoViewModel.doneNavigating()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018, The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.taymath.tutortoolkit.gettodo
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
import com.taymath.tutortoolkit.database.Todo
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
class GetTodoViewModel(
|
||||||
|
val database: StudentDatabaseDao) : ViewModel() {
|
||||||
|
|
||||||
|
private val viewModelJob = Job()
|
||||||
|
private val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob)
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
viewModelJob.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _navigateToTodoList = MutableLiveData<Boolean?>()
|
||||||
|
|
||||||
|
val navigateToTodoList: LiveData<Boolean?>
|
||||||
|
get() = _navigateToTodoList
|
||||||
|
|
||||||
|
fun doneNavigating() {
|
||||||
|
_navigateToTodoList.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun insert(todo: Todo) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
database.insertTodo(todo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onEnterTodo(todoString: String) {
|
||||||
|
uiScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val newTodo = Todo()
|
||||||
|
newTodo.todoString = todoString
|
||||||
|
insert(newTodo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_navigateToTodoList.value = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018, The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.taymath.tutortoolkit.gettodo
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
|
||||||
|
class GetTodoViewModelFactory(
|
||||||
|
private val dataSource: StudentDatabaseDao
|
||||||
|
) : ViewModelProvider.Factory {
|
||||||
|
|
||||||
|
@Suppress("unchecked_cast")
|
||||||
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
|
if (modelClass.isAssignableFrom(GetTodoViewModel::class.java)) {
|
||||||
|
return GetTodoViewModel(dataSource) as T
|
||||||
|
}
|
||||||
|
throw IllegalArgumentException("Unknown ViewModel class")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.taymath.tutortoolkit.databinding.ListItemGradeBinding
|
import com.taymath.tutortoolkit.databinding.ListItemGradeBinding
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Grade
|
import com.taymath.tutortoolkit.database.Grade
|
||||||
|
|
||||||
class GradeAdapter : ListAdapter<Grade,
|
class GradeAdapter : ListAdapter<Grade,
|
||||||
GradeAdapter.ViewHolder>(GradeDiffCallback()) {
|
GradeAdapter.ViewHolder>(GradeDiffCallback()) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.taymath.tutortoolkit.studentdetail
|
||||||
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.databinding.BindingAdapter
|
import androidx.databinding.BindingAdapter
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Grade
|
import com.taymath.tutortoolkit.database.Grade
|
||||||
|
|
||||||
@BindingAdapter("gradeFloat")
|
@BindingAdapter("gradeFloat")
|
||||||
fun TextView.setGradeFloat(item: Grade?){
|
fun TextView.setGradeFloat(item: Grade?){
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,7 @@ import androidx.lifecycle.ViewModelProviders
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.taymath.tutortoolkit.R
|
import com.taymath.tutortoolkit.R
|
||||||
import com.taymath.tutortoolkit.databinding.FragmentStudentDetailBinding
|
import com.taymath.tutortoolkit.databinding.FragmentStudentDetailBinding
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabase
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
import com.taymath.tutortoolkit.studentlist.StudentListFragmentDirections
|
|
||||||
import com.taymath.tutortoolkit.studentlist.StudentListener
|
|
||||||
|
|
||||||
class StudentDetailFragment: Fragment() {
|
class StudentDetailFragment: Fragment() {
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.taymath.tutortoolkit.studentdetail
|
package com.taymath.tutortoolkit.studentdetail
|
||||||
|
|
||||||
import androidx.lifecycle.*
|
import androidx.lifecycle.*
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import com.taymath.tutortoolkit.database.Student
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
class StudentDetailViewModel(
|
class StudentDetailViewModel(
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ package com.taymath.tutortoolkit.studentdetail
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
|
||||||
|
|
||||||
class StudentDetailViewModelFactory(
|
class StudentDetailViewModelFactory(
|
||||||
private val dataSource: StudentDatabaseDao,
|
private val dataSource: StudentDatabaseDao,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.taymath.tutortoolkit.databinding.ListItemStudentBinding
|
import com.taymath.tutortoolkit.databinding.ListItemStudentBinding
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import com.taymath.tutortoolkit.database.Student
|
||||||
|
|
||||||
class StudentAdapter(val clickListener: StudentListener) : ListAdapter<Student, StudentAdapter.ViewHolder>(StudentDiffCallback()) {
|
class StudentAdapter(val clickListener: StudentListener) : ListAdapter<Student, StudentAdapter.ViewHolder>(StudentDiffCallback()) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.databinding.BindingAdapter
|
import androidx.databinding.BindingAdapter
|
||||||
import com.taymath.tutortoolkit.R
|
import com.taymath.tutortoolkit.R
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import com.taymath.tutortoolkit.database.Student
|
||||||
|
|
||||||
@BindingAdapter("subjectText")
|
@BindingAdapter("subjectText")
|
||||||
fun TextView.setSubjectText(item: Student?){
|
fun TextView.setSubjectText(item: Student?){
|
||||||
|
|
@ -31,15 +31,22 @@ fun TextView.setGradeLevelText(item: Student?){
|
||||||
fun ImageView.setStudentImage(item: Student?) {
|
fun ImageView.setStudentImage(item: Student?) {
|
||||||
item?.let {
|
item?.let {
|
||||||
setImageResource(when (item.iconNumber) {
|
setImageResource(when (item.iconNumber) {
|
||||||
1 -> R.drawable.icon_1
|
1 -> R.drawable.face1
|
||||||
2 -> R.drawable.icon_2
|
2 -> R.drawable.face2
|
||||||
3 -> R.drawable.icon_3
|
3 -> R.drawable.face3
|
||||||
4 -> R.drawable.icon_4
|
4 -> R.drawable.face4
|
||||||
5 -> R.drawable.icon_5
|
5 -> R.drawable.face5
|
||||||
6 -> R.drawable.icon_6
|
6 -> R.drawable.face6
|
||||||
7 -> R.drawable.icon_7
|
7 -> R.drawable.face7
|
||||||
8 -> R.drawable.icon_8
|
8 -> R.drawable.face8
|
||||||
else -> R.drawable.icon_1
|
9 -> R.drawable.face9
|
||||||
|
10 -> R.drawable.face10
|
||||||
|
11 -> R.drawable.face11
|
||||||
|
12 -> R.drawable.face12
|
||||||
|
13 -> R.drawable.face13
|
||||||
|
14 -> R.drawable.face14
|
||||||
|
15 -> R.drawable.face15
|
||||||
|
else -> R.drawable.face1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@ import androidx.lifecycle.ViewModelProviders
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.taymath.tutortoolkit.R
|
import com.taymath.tutortoolkit.R
|
||||||
import com.taymath.tutortoolkit.databinding.FragmentStudentListBinding
|
import com.taymath.tutortoolkit.databinding.FragmentStudentListBinding
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabase
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
import kotlinx.android.synthetic.main.fragment_add_student.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment with buttons to record start and end times for sleep, which are saved in
|
* A fragment with buttons to record start and end times for sleep, which are saved in
|
||||||
|
|
@ -40,7 +39,7 @@ class StudentListFragment : Fragment() {
|
||||||
val dataSource = StudentDatabase.getInstance(application).studentDatabaseDao
|
val dataSource = StudentDatabase.getInstance(application).studentDatabaseDao
|
||||||
|
|
||||||
// Create instance of viewModelFactory using DAO and application
|
// Create instance of viewModelFactory using DAO and application
|
||||||
val viewModelFactory = StudentListViewModelFactory(dataSource, application)
|
val viewModelFactory = StudentListViewModelFactory(dataSource)
|
||||||
|
|
||||||
// Get reference to viewModel
|
// Get reference to viewModel
|
||||||
val studentListViewModel =
|
val studentListViewModel =
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
package com.taymath.tutortoolkit.studentlist
|
package com.taymath.tutortoolkit.studentlist
|
||||||
|
|
||||||
import android.app.Application
|
|
||||||
import androidx.lifecycle.AndroidViewModel
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Student
|
import androidx.lifecycle.ViewModel
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
class StudentListViewModel(
|
class StudentListViewModel(
|
||||||
val database: StudentDatabaseDao,
|
val database: StudentDatabaseDao
|
||||||
application: Application
|
) : ViewModel() {
|
||||||
) : AndroidViewModel(application) {
|
|
||||||
|
|
||||||
/** Coroutine setup variables */
|
/** Coroutine setup variables */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
package com.taymath.tutortoolkit.studentlist
|
package com.taymath.tutortoolkit.studentlist
|
||||||
|
|
||||||
import android.app.Application
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
|
||||||
class StudentListViewModelFactory(
|
class StudentListViewModelFactory(
|
||||||
private val dataSource: StudentDatabaseDao,
|
private val dataSource: StudentDatabaseDao) : ViewModelProvider.Factory {
|
||||||
private val application: Application) : ViewModelProvider.Factory {
|
|
||||||
@Suppress("unchecked_cast")
|
@Suppress("unchecked_cast")
|
||||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
if (modelClass.isAssignableFrom(StudentListViewModel::class.java)) {
|
if (modelClass.isAssignableFrom(StudentListViewModel::class.java)) {
|
||||||
return StudentListViewModel(dataSource, application) as T
|
return StudentListViewModel(dataSource) as T
|
||||||
}
|
}
|
||||||
throw IllegalArgumentException("Unknown ViewModel class")
|
throw IllegalArgumentException("Unknown ViewModel class")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.taymath.tutortoolkit.titlemenu
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.lifecycle.ViewModelProviders
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import com.taymath.tutortoolkit.R
|
||||||
|
import com.taymath.tutortoolkit.databinding.FragmentTitleMenuBinding
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
|
|
||||||
|
class TitleMenuFragment: Fragment() {
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View?{
|
||||||
|
|
||||||
|
// Get a reference to the binding object and inflate the fragment views.
|
||||||
|
val binding: FragmentTitleMenuBinding = DataBindingUtil.inflate(
|
||||||
|
inflater, R.layout.fragment_title_menu, container, false)
|
||||||
|
|
||||||
|
// Get reference to application
|
||||||
|
val application = requireNotNull(this.activity).application
|
||||||
|
|
||||||
|
// Get a reference to the DAO
|
||||||
|
val dataSource = StudentDatabase.getInstance(application).studentDatabaseDao
|
||||||
|
|
||||||
|
// Create instance of viewModelFactory using DAO and application
|
||||||
|
val viewModelFactory = TitleMenuViewModelFactory(dataSource, application)
|
||||||
|
|
||||||
|
// Get reference to viewModel
|
||||||
|
val titleMenuViewModel =
|
||||||
|
ViewModelProviders.of(
|
||||||
|
this, viewModelFactory).get(TitleMenuViewModel::class.java)
|
||||||
|
|
||||||
|
// Add ViewModel to our binding
|
||||||
|
binding.titleMenuViewModel = titleMenuViewModel
|
||||||
|
|
||||||
|
binding.setLifecycleOwner(this)
|
||||||
|
|
||||||
|
// Add an Observer to the state variable for Navigating when Add Student button is clicked.
|
||||||
|
titleMenuViewModel.navigateToStudentList.observe(viewLifecycleOwner, Observer {
|
||||||
|
if (it == true) { // Observed state is true.
|
||||||
|
this.findNavController().navigate(
|
||||||
|
TitleMenuFragmentDirections.actionTitleMenuFragmentToStudentListFragment())
|
||||||
|
titleMenuViewModel.onNavigated()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Add an Observer to the state variable for Navigating when Add Student button is clicked.
|
||||||
|
titleMenuViewModel.navigateToTodoList.observe(viewLifecycleOwner, Observer {
|
||||||
|
if (it == true) { // Observed state is true.
|
||||||
|
this.findNavController().navigate(
|
||||||
|
TitleMenuFragmentDirections.actionTitleMenuFragmentToTodoListFragment())
|
||||||
|
titleMenuViewModel.onNavigated()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.taymath.tutortoolkit.titlemenu
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
|
||||||
|
class TitleMenuViewModel(
|
||||||
|
val database: StudentDatabaseDao,
|
||||||
|
application: Application): AndroidViewModel(application) {
|
||||||
|
|
||||||
|
private val _navigateToStudentList = MutableLiveData<Boolean?>()
|
||||||
|
val navigateToStudentList: LiveData<Boolean?>
|
||||||
|
get() = _navigateToStudentList
|
||||||
|
|
||||||
|
private val _navigateToTodoList = MutableLiveData<Boolean?>()
|
||||||
|
val navigateToTodoList: LiveData<Boolean?>
|
||||||
|
get() = _navigateToTodoList
|
||||||
|
|
||||||
|
fun onNavigateToStudentList() {
|
||||||
|
_navigateToStudentList.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onNavigateToTodoList(){
|
||||||
|
_navigateToTodoList.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onNavigated() {
|
||||||
|
_navigateToStudentList.value = false
|
||||||
|
_navigateToTodoList.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.taymath.tutortoolkit.titlemenu
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
|
||||||
|
class TitleMenuViewModelFactory(
|
||||||
|
private val dataSource: StudentDatabaseDao,
|
||||||
|
private val application: Application
|
||||||
|
) : ViewModelProvider.Factory {
|
||||||
|
@Suppress("unchecked_cast")
|
||||||
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
|
if (modelClass.isAssignableFrom(TitleMenuViewModel::class.java)) {
|
||||||
|
return TitleMenuViewModel(dataSource, application) as T
|
||||||
|
}
|
||||||
|
throw IllegalArgumentException("Unknown ViewModel class")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.taymath.tutortoolkit.todolist
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.taymath.tutortoolkit.database.Todo
|
||||||
|
import com.taymath.tutortoolkit.databinding.ListItemTodoBinding
|
||||||
|
|
||||||
|
class TodoAdapter(val clickListener: TodoListener) : ListAdapter<Todo, TodoAdapter.ViewHolder>(
|
||||||
|
TodoDiffCallback()
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
return ViewHolder.from(
|
||||||
|
parent
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bind(clickListener, getItem(position)!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ViewHolder private constructor(val binding: ListItemTodoBinding): RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
|
fun bind(clickListener: TodoListener,item: Todo) {
|
||||||
|
binding.todo = item
|
||||||
|
binding.clickListener = clickListener
|
||||||
|
binding.executePendingBindings()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(parent: ViewGroup): ViewHolder {
|
||||||
|
val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
|
val binding = ListItemTodoBinding.inflate(layoutInflater, parent, false)
|
||||||
|
return ViewHolder(
|
||||||
|
binding
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TodoDiffCallback : DiffUtil.ItemCallback<Todo>() {
|
||||||
|
override fun areItemsTheSame(oldItem: Todo, newItem: Todo): Boolean {
|
||||||
|
return oldItem.todoId == newItem.todoId
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: Todo, newItem: Todo): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TodoListener(val clickListener: (todoId: Long) -> Unit) {
|
||||||
|
fun onClick(todo: Todo) = clickListener(todo.todoId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.taymath.tutortoolkit.todolist
|
||||||
|
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.databinding.BindingAdapter
|
||||||
|
import com.taymath.tutortoolkit.database.Todo
|
||||||
|
|
||||||
|
@BindingAdapter("todoText")
|
||||||
|
fun TextView.setGradeLevelText(item: Todo?){
|
||||||
|
item?.let {
|
||||||
|
text =item.todoString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.taymath.tutortoolkit.todolist
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.lifecycle.ViewModelProviders
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import com.taymath.tutortoolkit.R
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
|
import com.taymath.tutortoolkit.databinding.FragmentTodoListBinding
|
||||||
|
|
||||||
|
class TodoListFragment : Fragment() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the Fragment is ready to display content to the screen.
|
||||||
|
*
|
||||||
|
* This function uses DataBindingUtil to inflate R.layout.fragment_get_todo.
|
||||||
|
*/
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
|
// Get a reference to the binding object and inflate the fragment views.
|
||||||
|
val binding: FragmentTodoListBinding = DataBindingUtil.inflate(
|
||||||
|
inflater, R.layout.fragment_todo_list, container, false)
|
||||||
|
|
||||||
|
// Get reference to application
|
||||||
|
val application = requireNotNull(this.activity).application
|
||||||
|
|
||||||
|
// Get a reference to the DAO
|
||||||
|
val dataSource = StudentDatabase.getInstance(application).studentDatabaseDao
|
||||||
|
|
||||||
|
// Create instance of viewModelFactory using DAO
|
||||||
|
val viewModelFactory = TodoListViewModelFactory(dataSource)
|
||||||
|
|
||||||
|
// Get reference to viewModel
|
||||||
|
val todoListViewModel =
|
||||||
|
ViewModelProviders.of(
|
||||||
|
this, viewModelFactory).get(TodoListViewModel::class.java)
|
||||||
|
|
||||||
|
binding.todoListViewModel = todoListViewModel
|
||||||
|
|
||||||
|
binding.setLifecycleOwner(this)
|
||||||
|
|
||||||
|
todoListViewModel.navigateToAddTodo.observe(viewLifecycleOwner, Observer {
|
||||||
|
if (it == true) { // Observed state is true.
|
||||||
|
this.findNavController().navigate(
|
||||||
|
TodoListFragmentDirections.actionTodoListFragmentToGetTodoFragment())
|
||||||
|
todoListViewModel.doneNavigating()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Initialize adapter and add to studentList
|
||||||
|
val adapter = TodoAdapter(TodoAdapter.TodoListener {
|
||||||
|
todoId -> todoListViewModel.onDeleteTodo(todoId)
|
||||||
|
})
|
||||||
|
binding.todoList.adapter = adapter
|
||||||
|
|
||||||
|
// If we have a list of grades, send it to the adapter
|
||||||
|
todoListViewModel.todos.observe(viewLifecycleOwner, Observer {
|
||||||
|
it?.let {
|
||||||
|
adapter.submitList(it)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.taymath.tutortoolkit.todolist
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.*
|
||||||
|
import com.taymath.tutortoolkit.database.Student
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
import com.taymath.tutortoolkit.database.Todo
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
class TodoListViewModel(
|
||||||
|
val database: StudentDatabaseDao
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
|
// Grab grades from grades_table with StudentId
|
||||||
|
val todos = database.getAllTodos()
|
||||||
|
|
||||||
|
|
||||||
|
private val viewModelJob = Job()
|
||||||
|
|
||||||
|
// Initialize uiScope
|
||||||
|
private val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob)
|
||||||
|
|
||||||
|
// Add variable to navigation signaller
|
||||||
|
private val _navigateToAddTodo = MutableLiveData<Boolean?>()
|
||||||
|
val navigateToAddTodo: LiveData<Boolean?>
|
||||||
|
get() = _navigateToAddTodo
|
||||||
|
|
||||||
|
private val _deleteTodo = MutableLiveData<Boolean?>()
|
||||||
|
val deleteTodo: LiveData<Boolean?>
|
||||||
|
get() = _deleteTodo
|
||||||
|
|
||||||
|
val students = database.getAllStudents()
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
viewModelJob.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDeleteTodo(todoId: Long) {
|
||||||
|
uiScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
database.deleteTodoById(todoId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set navigate to student to be true when clicked
|
||||||
|
fun onNavToAddStudent() {
|
||||||
|
_navigateToAddTodo.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset nav value after navigation
|
||||||
|
fun doneNavigating() {
|
||||||
|
_navigateToAddTodo.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.taymath.tutortoolkit.todolist
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is pretty much boiler plate code for a ViewModel Factory.
|
||||||
|
*
|
||||||
|
* Provides the SleepDatabaseDao and context to the ViewModel.
|
||||||
|
*/
|
||||||
|
class TodoListViewModelFactory(
|
||||||
|
private val dataSource: StudentDatabaseDao) : ViewModelProvider.Factory {
|
||||||
|
@Suppress("unchecked_cast")
|
||||||
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
|
if (modelClass.isAssignableFrom(TodoListViewModel::class.java)) {
|
||||||
|
return TodoListViewModel(dataSource) as T
|
||||||
|
}
|
||||||
|
throw IllegalArgumentException("Unknown ViewModel class")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
|
@ -11,7 +11,7 @@
|
||||||
type="com.taymath.tutortoolkit.addgrade.AddGradeViewModel"/>
|
type="com.taymath.tutortoolkit.addgrade.AddGradeViewModel"/>
|
||||||
<variable
|
<variable
|
||||||
name="grade"
|
name="grade"
|
||||||
type="com.taymath.tutortoolkit.studentdatabase.Grade" />
|
type="com.taymath.tutortoolkit.database.Grade" />
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
type="com.taymath.tutortoolkit.addstudent.AddStudentViewModel"/>
|
type="com.taymath.tutortoolkit.addstudent.AddStudentViewModel"/>
|
||||||
<variable
|
<variable
|
||||||
name="student"
|
name="student"
|
||||||
type="com.taymath.tutortoolkit.studentdatabase.Student" />
|
type="com.taymath.tutortoolkit.database.Student" />
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
|
@ -97,7 +97,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="@dimen/margin"
|
android:layout_margin="@dimen/margin"
|
||||||
android:onClick="@{() -> addStudentViewModel.onChooseIcon(studentNameText.getText().toString(), subjectText.getText().toString(), gradeText.getText().toString(), addressText.getText().toString(), emailText.getText().toString())}"
|
android:onClick="@{() -> addStudentViewModel.onChooseIcon(studentNameText.getText().toString(), subjectText.getText().toString(), gradeText.getText().toString(), addressText.getText().toString(), emailText.getText().toString())}"
|
||||||
app:srcCompat="@drawable/icon_1"
|
app:srcCompat="@drawable/face3"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.5"
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(1)}"
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(1)}"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
||||||
app:srcCompat="@drawable/icon_1" />
|
app:srcCompat="@drawable/face1" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/icon_two_image"
|
android:id="@+id/icon_two_image"
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
app:layout_constraintEnd_toStartOf="@+id/icon_three_image"
|
app:layout_constraintEnd_toStartOf="@+id/icon_three_image"
|
||||||
app:layout_constraintStart_toEndOf="@+id/icon_one_image"
|
app:layout_constraintStart_toEndOf="@+id/icon_one_image"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
||||||
app:srcCompat="@drawable/icon_2" />
|
app:srcCompat="@drawable/face2" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/icon_three_image"
|
android:id="@+id/icon_three_image"
|
||||||
|
|
@ -61,7 +61,7 @@
|
||||||
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(3)}"
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(3)}"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
||||||
app:srcCompat="@drawable/icon_3" />
|
app:srcCompat="@drawable/face3" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/icon_four_image"
|
android:id="@+id/icon_four_image"
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(4)}"
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(4)}"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/icon_two_image"
|
app:layout_constraintTop_toBottomOf="@+id/icon_two_image"
|
||||||
app:srcCompat="@drawable/icon_4" />
|
app:srcCompat="@drawable/face4" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/icon_five_image"
|
android:id="@+id/icon_five_image"
|
||||||
|
|
@ -86,7 +86,7 @@
|
||||||
app:layout_constraintEnd_toStartOf="@+id/icon_six_image"
|
app:layout_constraintEnd_toStartOf="@+id/icon_six_image"
|
||||||
app:layout_constraintStart_toEndOf="@+id/icon_four_image"
|
app:layout_constraintStart_toEndOf="@+id/icon_four_image"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/icon_two_image"
|
app:layout_constraintTop_toBottomOf="@+id/icon_two_image"
|
||||||
app:srcCompat="@drawable/icon_5" />
|
app:srcCompat="@drawable/face5" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/icon_six_image"
|
android:id="@+id/icon_six_image"
|
||||||
|
|
@ -97,7 +97,7 @@
|
||||||
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(6)}"
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(6)}"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/icon_two_image"
|
app:layout_constraintTop_toBottomOf="@+id/icon_two_image"
|
||||||
app:srcCompat="@drawable/icon_6" />
|
app:srcCompat="@drawable/face6" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/icon_seven_image"
|
android:id="@+id/icon_seven_image"
|
||||||
|
|
@ -108,20 +108,81 @@
|
||||||
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(7)}"
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(7)}"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/icon_five_image"
|
app:layout_constraintTop_toBottomOf="@+id/icon_five_image"
|
||||||
app:srcCompat="@drawable/icon_7" />
|
app:srcCompat="@drawable/face7" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/icon_eight_image"
|
android:id="@+id/icon_eight_image"
|
||||||
android:layout_width="@dimen/icon_size"
|
android:layout_width="@dimen/icon_size"
|
||||||
android:layout_height="@dimen/icon_size"
|
android:layout_height="@dimen/icon_size"
|
||||||
android:layout_margin="@dimen/triple_margin"
|
android:layout_margin="@dimen/triple_margin"
|
||||||
android:layout_marginTop="105dp"
|
android:layout_marginTop="48dp"
|
||||||
|
android:layout_marginEnd="106dp"
|
||||||
android:contentDescription="@string/icon_1"
|
android:contentDescription="@string/icon_1"
|
||||||
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(8)}"
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(8)}"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toStartOf="@+id/icon_nine_image"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintHorizontal_bias="0.505"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/icon_seven_image"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/icon_five_image"
|
app:layout_constraintTop_toBottomOf="@+id/icon_five_image"
|
||||||
app:srcCompat="@drawable/icon_8" />
|
app:srcCompat="@drawable/face8" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/icon_nine_image"
|
||||||
|
style="@style/choose_icon_image_style"
|
||||||
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(9)}"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/icon_five_image"
|
||||||
|
app:srcCompat="@drawable/face9" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/icon_ten_image"
|
||||||
|
style="@style/choose_icon_image_style"
|
||||||
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(10)}"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/icon_seven_image"
|
||||||
|
app:srcCompat="@drawable/face10" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/icon_eleven_image"
|
||||||
|
style="@style/choose_icon_image_style"
|
||||||
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(11)}"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/icon_ten_image"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/icon_eight_image"
|
||||||
|
app:srcCompat="@drawable/face11" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/icon_twelve_image"
|
||||||
|
style="@style/choose_icon_image_style"
|
||||||
|
android:layout_marginTop="48dp"
|
||||||
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(12)}"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/icon_eight_image"
|
||||||
|
app:srcCompat="@drawable/face12" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/icon_thirteen_image"
|
||||||
|
style="@style/choose_icon_image_style"
|
||||||
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(13)}"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/icon_eleven_image"
|
||||||
|
app:srcCompat="@drawable/face13" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/icon_fourteen_image"
|
||||||
|
style="@style/choose_icon_image_style"
|
||||||
|
android:layout_marginTop="48dp"
|
||||||
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(14)}"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/icon_thirteen_image"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/icon_eleven_image"
|
||||||
|
app:srcCompat="@drawable/face14" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/icon_fifteen_image"
|
||||||
|
style="@style/choose_icon_image_style"
|
||||||
|
android:onClick="@{() -> chooseIconViewModel.onChooseIcon(15)}"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/icon_eleven_image"
|
||||||
|
app:srcCompat="@drawable/face15" />
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
|
~ Copyright 2018, The Android Open Source Project
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Wrapping the layout into /layout to make it available with data binding. -->
|
||||||
|
<layout 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">
|
||||||
|
|
||||||
|
<!-- Data to make available to the XML via data binding. In this case,
|
||||||
|
the whole ViewModel, so that we can access the LiveData,
|
||||||
|
click handlers, and state variables. -->
|
||||||
|
<data>
|
||||||
|
<variable
|
||||||
|
name="getTodoViewModel"
|
||||||
|
type="com.taymath.tutortoolkit.gettodo.GetTodoViewModel" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<!-- Start of the visible fragment layout using ConstraintLayout -->
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".gettodo.GetTodoFragment">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/todo_text"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/margin"
|
||||||
|
android:autofillHints=""
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/enter_todo_item_here"
|
||||||
|
android:inputType="textMultiLine"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/enter_button"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/enter_button"
|
||||||
|
style="@style/AddButtons"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/margin"
|
||||||
|
android:onClick="@{() -> getTodoViewModel.onEnterTodo(todoText.getText().toString())}"
|
||||||
|
android:text="@string/enter"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</layout>
|
||||||
|
|
@ -33,9 +33,10 @@
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/gradeList"
|
android:id="@+id/gradeList"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:layout_margin="@dimen/margin"
|
android:layout_margin="@dimen/margin"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/clear_grades_button"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="1.0"
|
app:layout_constraintHorizontal_bias="1.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
@ -51,10 +52,10 @@
|
||||||
android:onClick="@{() -> studentDetailViewModel.onClear()}"
|
android:onClick="@{() -> studentDetailViewModel.onClear()}"
|
||||||
android:text="@string/clear_grades"
|
android:text="@string/clear_grades"
|
||||||
app:backgroundTint="@color/orange_color"
|
app:backgroundTint="@color/orange_color"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/delete_student_button"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.5"
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
app:layout_constraintTop_toBottomOf="@+id/gradeList" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/grade_float_text"
|
android:id="@+id/grade_float_text"
|
||||||
|
|
@ -69,12 +70,12 @@
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/delete_student_button"
|
android:id="@+id/delete_student_button"
|
||||||
|
style="@style/AddButtons"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="@dimen/margin"
|
android:layout_margin="@dimen/margin"
|
||||||
android:onClick="@{() -> studentDetailViewModel.onDeleteStudent()}"
|
android:onClick="@{() -> studentDetailViewModel.onDeleteStudent()}"
|
||||||
android:text="@string/delete_student"
|
android:text="@string/delete_student"
|
||||||
style="@style/AddButtons"
|
|
||||||
app:backgroundTint="@color/red_color"
|
app:backgroundTint="@color/red_color"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,13 @@
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/student_list"
|
android:id="@+id/student_list"
|
||||||
android:layout_width="409dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/add_student_button"
|
app:layout_constraintTop_toBottomOf="@+id/add_student_button" />
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
</layout>
|
</layout>
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout 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">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<!-- Get reference to titleMenuViewModel -->
|
||||||
|
<variable
|
||||||
|
name="titleMenuViewModel"
|
||||||
|
type="com.taymath.tutortoolkit.titlemenu.TitleMenuViewModel"/>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/main_icon_image"
|
||||||
|
android:layout_width="187dp"
|
||||||
|
android:layout_height="187dp"
|
||||||
|
android:layout_margin="@dimen/triple_margin"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
||||||
|
app:srcCompat="@drawable/main_icon"
|
||||||
|
android:contentDescription="@string/image_of_main_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/triple_margin"
|
||||||
|
android:text="@string/tutortoolkit"
|
||||||
|
android:textSize="28sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/student_list_button"
|
||||||
|
style="@style/AddButtons"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/triple_margin"
|
||||||
|
android:onClick="@{() -> titleMenuViewModel.onNavigateToStudentList()}"
|
||||||
|
android:text="@string/student_list"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/main_icon_image" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/todo_list_button"
|
||||||
|
style="@style/AddButtons"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/triple_margin"
|
||||||
|
android:layout_marginTop="@dimen/margin"
|
||||||
|
android:layout_marginEnd="@dimen/triple_margin"
|
||||||
|
android:text="@string/todo_list"
|
||||||
|
android:onClick="@{() -> titleMenuViewModel.onNavigateToTodoList()}"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/student_list_button" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</layout>
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout 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">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<!-- Get reference to titleMenuViewModel -->
|
||||||
|
<variable
|
||||||
|
name="todoListViewModel"
|
||||||
|
type="com.taymath.tutortoolkit.todolist.TodoListViewModel"/>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/add_todo_button"
|
||||||
|
style="@style/AddButtons"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="@{() -> todoListViewModel.onNavToAddStudent()}"
|
||||||
|
android:text="@string/add_todo"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/todo_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/add_todo_button" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</layout>
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<data>
|
<data>
|
||||||
<variable
|
<variable
|
||||||
name="grade"
|
name="grade"
|
||||||
type="com.taymath.tutortoolkit.studentdatabase.Grade" />
|
type="com.taymath.tutortoolkit.database.Grade" />
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<data>
|
<data>
|
||||||
<variable
|
<variable
|
||||||
name="student"
|
name="student"
|
||||||
type="com.taymath.tutortoolkit.studentdatabase.Student" />
|
type="com.taymath.tutortoolkit.database.Student" />
|
||||||
<variable
|
<variable
|
||||||
name="clickListener"
|
name="clickListener"
|
||||||
type="com.taymath.tutortoolkit.studentlist.StudentListener"/>
|
type="com.taymath.tutortoolkit.studentlist.StudentListener"/>
|
||||||
|
|
@ -61,6 +61,7 @@
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="@dimen/margin"
|
android:layout_margin="@dimen/margin"
|
||||||
|
android:layout_marginStart="225dp"
|
||||||
android:hint="@string/grade_level"
|
android:hint="@string/grade_level"
|
||||||
app:gradeLevelText="@{student}"
|
app:gradeLevelText="@{student}"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<layout 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">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<variable
|
||||||
|
name="todo"
|
||||||
|
type="com.taymath.tutortoolkit.database.Todo" />
|
||||||
|
<variable
|
||||||
|
name="clickListener"
|
||||||
|
type="com.taymath.tutortoolkit.todolist.TodoAdapter.TodoListener"/>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/delete_button"
|
||||||
|
style="@style/AddButtons"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/triple_margin"
|
||||||
|
android:text="@string/delete"
|
||||||
|
android:onClick="@{() -> clickListener.onClick(todo)}"
|
||||||
|
app:backgroundTint="@color/red_color"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/todo_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/triple_margin"
|
||||||
|
android:hint="@string/todo_item"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/delete_button"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:todoText="@{todo}" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</layout>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
|
@ -3,8 +3,8 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/navigation"
|
android:id="@+id/navigation"
|
||||||
app:startDestination="@id/studentListFragment"
|
tools:ignore="ExtraText"
|
||||||
tools:ignore="ExtraText">
|
app:startDestination="@id/titleMenuFragment">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/addGradeFragment"
|
android:id="@+id/addGradeFragment"
|
||||||
|
|
@ -49,6 +49,9 @@
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_studentListFragment_to_addStudentFragment"
|
android:id="@+id/action_studentListFragment_to_addStudentFragment"
|
||||||
app:destination="@id/addStudentFragment" />
|
app:destination="@id/addStudentFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_studentListFragment_to_titleMenuFragment"
|
||||||
|
app:destination="@id/titleMenuFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -60,5 +63,32 @@
|
||||||
android:id="@+id/action_chooseIconFragment_to_studentListFragment"
|
android:id="@+id/action_chooseIconFragment_to_studentListFragment"
|
||||||
app:destination="@id/studentListFragment" />
|
app:destination="@id/studentListFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/titleMenuFragment"
|
||||||
|
android:name="com.taymath.tutortoolkit.titlemenu.TitleMenuFragment"
|
||||||
|
android:label="TitleMenuFragment" >
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_titleMenuFragment_to_studentListFragment"
|
||||||
|
app:destination="@id/studentListFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_titleMenuFragment_to_todoListFragment"
|
||||||
|
app:destination="@id/todoListFragment" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/todoListFragment"
|
||||||
|
android:name="com.taymath.tutortoolkit.todolist.TodoListFragment"
|
||||||
|
android:label="TodoListFragment" >
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_todoListFragment_to_getTodoFragment"
|
||||||
|
app:destination="@id/getTodoFragment" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/getTodoFragment"
|
||||||
|
android:name="com.taymath.tutortoolkit.gettodo.GetTodoFragment"
|
||||||
|
android:label="GetTodoFragment" >
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_getTodoFragment_to_todoListFragment"
|
||||||
|
app:destination="@id/todoListFragment" />
|
||||||
|
</fragment>
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="margin">16dp</dimen>
|
<dimen name="margin">16dp</dimen>
|
||||||
<dimen name="icon_size">64dp</dimen>
|
<dimen name="icon_size">76dp</dimen>
|
||||||
<dimen name="title_text_size">20sp</dimen>
|
<dimen name="title_text_size">20sp</dimen>
|
||||||
<dimen name="triple_margin">48dp</dimen>
|
<dimen name="triple_margin">48dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,13 @@
|
||||||
<string name="student_image_icon_choice">Student Image Icon Choice</string>
|
<string name="student_image_icon_choice">Student Image Icon Choice</string>
|
||||||
<string name="icon_1">Icon 1</string>
|
<string name="icon_1">Icon 1</string>
|
||||||
<string name="choose_your_icon">Choose Your Icon!</string>
|
<string name="choose_your_icon">Choose Your Icon!</string>
|
||||||
|
<string name="student_list">Student List</string>
|
||||||
|
<string name="tutortoolkit">TutorToolkit</string>
|
||||||
|
<string name="todo_list">Todo List</string>
|
||||||
|
<string name="image_of_main_icon">Image of main icon</string>
|
||||||
|
<string name="add_todo">Add Todo</string>
|
||||||
|
<string name="enter_todo_item_here">Enter Todo Item Here</string>
|
||||||
|
<string name="enter_student_name_here">Enter Student Name Here</string>
|
||||||
|
<string name="enter">Enter</string>
|
||||||
|
<string name="todo_item">Todo Item</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,17 @@
|
||||||
<style name="Buttons" parent="Widget.AppCompat.Button.Colored">
|
<style name="Buttons" parent="Widget.AppCompat.Button.Colored">
|
||||||
<item name="android:textStyle">bold</item>
|
<item name="android:textStyle">bold</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="choose_icon_image_style">
|
||||||
|
<item name="android:layout_width">@dimen/icon_size</item>
|
||||||
|
<item name="android:layout_height">@dimen/icon_size</item>
|
||||||
|
<item name="android:layout_margin">@dimen/triple_margin</item>
|
||||||
|
<item name="android:layout_marginTop">48dp</item>
|
||||||
|
<item name="android:contentDescription">@string/icon_1</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.NoActionBar">
|
||||||
|
<item name="windowActionBar">false</item>
|
||||||
|
<item name="windowNoTitle">true</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package com.taymath.tutortoolkit
|
package com.taymath.tutortoolkit
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import com.taymath.tutortoolkit.studentdatabase.Grade
|
import com.taymath.tutortoolkit.database.Grade
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabase
|
import com.taymath.tutortoolkit.database.StudentDatabase
|
||||||
import com.taymath.tutortoolkit.studentdatabase.StudentDatabaseDao
|
import com.taymath.tutortoolkit.database.StudentDatabaseDao
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
import org.hamcrest.CoreMatchers.equalTo
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
|
||||||