Migrate category settings fragment to data binding

This commit is contained in:
Jonas L 2019-01-24 20:00:42 +01:00
parent b8f5612231
commit 2f2d6cef44
2 changed files with 75 additions and 73 deletions

View file

@ -23,13 +23,13 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import io.timelimit.android.R import io.timelimit.android.R
import io.timelimit.android.databinding.FragmentCategorySettingsBinding
import io.timelimit.android.logic.AppLogic import io.timelimit.android.logic.AppLogic
import io.timelimit.android.logic.DefaultAppLogic import io.timelimit.android.logic.DefaultAppLogic
import io.timelimit.android.sync.actions.SetCategoryExtraTimeAction import io.timelimit.android.sync.actions.SetCategoryExtraTimeAction
import io.timelimit.android.ui.main.ActivityViewModel import io.timelimit.android.ui.main.ActivityViewModel
import io.timelimit.android.ui.main.getActivityViewModel import io.timelimit.android.ui.main.getActivityViewModel
import io.timelimit.android.ui.manage.category.ManageCategoryFragmentArgs import io.timelimit.android.ui.manage.category.ManageCategoryFragmentArgs
import kotlinx.android.synthetic.main.fragment_category_settings.*
class CategorySettingsFragment : Fragment() { class CategorySettingsFragment : Fragment() {
companion object { companion object {
@ -45,30 +45,25 @@ class CategorySettingsFragment : Fragment() {
private val auth: ActivityViewModel by lazy { getActivityViewModel(activity!!) } private val auth: ActivityViewModel by lazy { getActivityViewModel(activity!!) }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_category_settings, container, false) val binding = FragmentCategorySettingsBinding.inflate(inflater, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val categoryEntry = appLogic.database.category().getCategoryByChildIdAndId(params.childId, params.categoryId) val categoryEntry = appLogic.database.category().getCategoryByChildIdAndId(params.childId, params.categoryId)
btn_delete_category.setOnClickListener { deleteCategory() } binding.btnDeleteCategory.setOnClickListener { deleteCategory() }
binding.editCategoryTitleGo.setOnClickListener { renameCategory() }
edit_category_title_go.setOnClickListener { renameCategory() }
categoryEntry.observe(this, Observer { categoryEntry.observe(this, Observer {
if (it != null) { if (it != null) {
val roundedCurrentTimeInMillis = (it.extraTimeInMillis / (1000 * 60)) * (1000 * 60) val roundedCurrentTimeInMillis = (it.extraTimeInMillis / (1000 * 60)) * (1000 * 60)
if (extra_time_selection.timeInMillis != roundedCurrentTimeInMillis) { if (binding.extraTimeSelection.timeInMillis != roundedCurrentTimeInMillis) {
extra_time_selection.timeInMillis = roundedCurrentTimeInMillis binding.extraTimeSelection.timeInMillis = roundedCurrentTimeInMillis
} }
} }
}) })
extra_time_btn_ok.setOnClickListener { binding.extraTimeBtnOk.setOnClickListener {
val newExtraTime = extra_time_selection.timeInMillis val newExtraTime = binding.extraTimeSelection.timeInMillis
if ( if (
auth.tryDispatchParentAction( auth.tryDispatchParentAction(
@ -78,9 +73,11 @@ class CategorySettingsFragment : Fragment() {
) )
) )
) { ) {
Snackbar.make(view, R.string.category_settings_extra_time_change_toast, Snackbar.LENGTH_SHORT).show() Snackbar.make(binding.root, R.string.category_settings_extra_time_change_toast, Snackbar.LENGTH_SHORT).show()
} }
} }
return binding.root
} }
private fun renameCategory() { private fun renameCategory() {

View file

@ -13,12 +13,16 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="io.timelimit.android.ui.manage.category.settings.CategorySettingsFragment"> tools:context="io.timelimit.android.ui.manage.category.settings.CategorySettingsFragment">
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:padding="8dp" android:padding="8dp"
android:orientation="vertical" android:orientation="vertical"
@ -93,4 +97,5 @@
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</layout>