mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 10:49:29 +02:00
Migrate category settings fragment to data binding
This commit is contained in:
parent
b8f5612231
commit
2f2d6cef44
2 changed files with 75 additions and 73 deletions
|
@ -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() {
|
||||||
|
|
|
@ -13,84 +13,89 @@
|
||||||
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">
|
||||||
<LinearLayout
|
|
||||||
android:padding="8dp"
|
<ScrollView
|
||||||
android:orientation="vertical"
|
android:id="@+id/scroll"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<LinearLayout
|
||||||
app:cardUseCompatPadding="true"
|
android:padding="8dp"
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
<LinearLayout
|
|
||||||
android:padding="8dp"
|
<androidx.cardview.widget.CardView
|
||||||
android:orientation="vertical"
|
app:cardUseCompatPadding="true"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
<LinearLayout
|
||||||
<TextView
|
android:padding="8dp"
|
||||||
android:text="@string/category_settings_extra_time_title"
|
android:orientation="vertical"
|
||||||
android:textAppearance="?android:textAppearanceLarge"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:textAppearance="?android:textAppearanceMedium"
|
android:text="@string/category_settings_extra_time_title"
|
||||||
android:text="@string/category_settings_extra_time_info"
|
android:textAppearance="?android:textAppearanceLarge"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<io.timelimit.android.ui.view.SelectTimeSpanView
|
<TextView
|
||||||
android:id="@+id/extra_time_selection"
|
android:textAppearance="?android:textAppearanceMedium"
|
||||||
android:layout_width="match_parent"
|
android:text="@string/category_settings_extra_time_info"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<Button
|
<io.timelimit.android.ui.view.SelectTimeSpanView
|
||||||
android:id="@+id/extra_time_btn_ok"
|
android:id="@+id/extra_time_selection"
|
||||||
android:text="@string/category_settings_extra_time_change"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
<Button
|
||||||
</androidx.cardview.widget.CardView>
|
android:id="@+id/extra_time_btn_ok"
|
||||||
|
android:text="@string/category_settings_extra_time_change"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
</LinearLayout>
|
||||||
app:cardUseCompatPadding="true"
|
</androidx.cardview.widget.CardView>
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
<androidx.cardview.widget.CardView
|
||||||
<LinearLayout
|
app:cardUseCompatPadding="true"
|
||||||
android:padding="8dp"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
<LinearLayout
|
||||||
<TextView
|
android:padding="8dp"
|
||||||
android:textAppearance="?android:textAppearanceLarge"
|
android:orientation="vertical"
|
||||||
android:text="@string/generic_manage_card"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<Button
|
<TextView
|
||||||
android:id="@+id/edit_category_title_go"
|
android:textAppearance="?android:textAppearanceLarge"
|
||||||
android:text="@string/category_settings_rename"
|
android:text="@string/generic_manage_card"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_delete_category"
|
android:id="@+id/edit_category_title_go"
|
||||||
android:text="@string/category_settings_delete"
|
android:text="@string/category_settings_rename"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
<Button
|
||||||
</androidx.cardview.widget.CardView>
|
android:id="@+id/btn_delete_category"
|
||||||
|
android:text="@string/category_settings_delete"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</layout>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue