Add option to change parent timezone

This commit is contained in:
Jonas Lochmann 2020-01-20 01:00:00 +01:00
parent ef744008b5
commit 1bc3f60e82
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
8 changed files with 143 additions and 65 deletions

View file

@ -38,10 +38,9 @@ import io.timelimit.android.ui.main.getActivityViewModel
import io.timelimit.android.ui.manage.child.ManageChildFragmentArgs
import io.timelimit.android.ui.manage.child.advanced.managedisabletimelimits.ManageDisableTimelimitsViewHelper
import io.timelimit.android.ui.manage.child.advanced.password.ManageChildPassword
import io.timelimit.android.ui.manage.child.advanced.timezone.SetChildTimezoneDialogFragment
import io.timelimit.android.ui.manage.child.advanced.timezone.UserTimezoneView
import io.timelimit.android.ui.manage.child.primarydevice.PrimaryDeviceView
import io.timelimit.android.ui.payment.RequiresPurchaseDialogFragment
import java.util.*
class ManageChildAdvancedFragment : Fragment() {
companion object {
@ -142,20 +141,14 @@ class ManageChildAdvancedFragment : Fragment() {
})
}
run {
// timezone
childEntry.observe(this, Observer {
binding.timezone = TimeZone.getTimeZone(it?.timeZone ?: "").displayName
})
binding.changeTimezoneButton.setOnClickListener {
if (auth.requestAuthenticationOrReturnTrue()) {
SetChildTimezoneDialogFragment.newInstance(
childId = params.childId
).show(fragmentManager!!)
}
}
}
UserTimezoneView.bind(
userEntry = childEntry,
view = binding.userTimezone,
fragmentManager = fragmentManager!!,
lifecycleOwner = this,
userId = params.childId,
auth = auth
)
binding.renameChildButton.setOnClickListener {
if (auth.requestAuthenticationOrReturnTrue()) {

View file

@ -1,5 +1,5 @@
/*
* TimeLimit Copyright <C> 2019 Jonas Lochmann
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -39,20 +39,20 @@ import io.timelimit.android.ui.main.ActivityViewModel
import io.timelimit.android.ui.main.getActivityViewModel
import java.util.*
class SetChildTimezoneDialogFragment : DialogFragment() {
class SetUserTimezoneDialogFragment : DialogFragment() {
companion object {
private const val EXTRA_CHILD_ID = "childId"
private const val DIALOG_TAG = "SetChildTimezoneDialogFragment"
private const val EXTRA_USER_ID = "userId"
private const val DIALOG_TAG = "SetUserTimezoneDialogFragment"
fun newInstance(childId: String) = SetChildTimezoneDialogFragment().apply {
fun newInstance(userId: String) = SetUserTimezoneDialogFragment().apply {
arguments = Bundle().apply {
putString(EXTRA_CHILD_ID, childId)
putString(EXTRA_USER_ID, userId)
}
}
}
val childId: String by lazy {
arguments!!.getString(EXTRA_CHILD_ID)!!
val userId: String by lazy {
arguments!!.getString(EXTRA_USER_ID)!!
}
val auth: ActivityViewModel by lazy {
@ -81,7 +81,7 @@ class SetChildTimezoneDialogFragment : DialogFragment() {
override fun onTimezoneClicked(timeZone: TimeZone) {
auth.tryDispatchParentAction(
SetUserTimezoneAction(
userId = childId,
userId = userId,
timezone = timeZone.id
)
)

View file

@ -0,0 +1,48 @@
/*
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package io.timelimit.android.ui.manage.child.advanced.timezone
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import io.timelimit.android.data.model.User
import io.timelimit.android.databinding.UserTimezoneViewBinding
import io.timelimit.android.ui.main.ActivityViewModel
import java.util.*
object UserTimezoneView {
fun bind(
userEntry: LiveData<User?>,
view: UserTimezoneViewBinding,
fragmentManager: FragmentManager,
lifecycleOwner: LifecycleOwner,
auth: ActivityViewModel,
userId: String
) {
userEntry.observe(lifecycleOwner, Observer {
view.timezone = TimeZone.getTimeZone(it?.timeZone ?: "").displayName
})
view.changeTimezoneButton.setOnClickListener {
if (auth.requestAuthenticationOrReturnTrue()) {
SetUserTimezoneDialogFragment.newInstance(
userId = userId
).show(fragmentManager)
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* TimeLimit Copyright <C> 2019 Jonas Lochmann
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -36,6 +36,7 @@ import io.timelimit.android.logic.DefaultAppLogic
import io.timelimit.android.ui.main.ActivityViewModelHolder
import io.timelimit.android.ui.main.AuthenticationFab
import io.timelimit.android.ui.main.FragmentWithCustomTitle
import io.timelimit.android.ui.manage.child.advanced.timezone.UserTimezoneView
import io.timelimit.android.ui.manage.parent.delete.DeleteParentView
class ManageParentFragment : Fragment(), FragmentWithCustomTitle {
@ -105,6 +106,15 @@ class ManageParentFragment : Fragment(), FragmentWithCustomTitle {
userEntry = parentUser
)
UserTimezoneView.bind(
view = binding.timezone,
userId = params.parentId,
lifecycleOwner = this,
fragmentManager = fragmentManager!!,
auth = activity.getActivityViewModel(),
userEntry = parentUser
)
binding.handlers = object: ManageParentFragmentHandlers {
override fun onChangePasswordClicked() {
navigation.safeNavigate(

View file

@ -1,5 +1,5 @@
<!--
TimeLimit Copyright <C> 2019 Jonas Lochmann
TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
@ -18,10 +18,6 @@
tools:context="io.timelimit.android.ui.manage.child.advanced.ManageChildAdvancedFragment">
<data>
<variable
name="timezone"
type="String" />
<import type="io.timelimit.android.BuildConfig" />
<import type="android.view.View" />
</data>
@ -94,38 +90,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.cardview.widget.CardView
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="@string/manage_child_timezone_title"
android:textAppearance="?android:textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:textAppearance="?android:textAppearanceMedium"
tools:text="GMT"
android:text="@{timezone}"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/change_timezone_button"
android:text="@string/manage_child_timezone_change_button"
android:layout_gravity="end"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<include android:id="@+id/user_timezone"
layout="@layout/user_timezone_view" />
<include android:id="@+id/password"
layout="@layout/manage_child_password" />

View file

@ -1,5 +1,5 @@
<!--
TimeLimit Copyright <C> 2019 Jonas Lochmann
TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
@ -157,6 +157,9 @@
<include android:id="@+id/manage_notifications"
layout="@layout/manage_parent_notifications" />
<include android:id="@+id/timezone"
layout="@layout/user_timezone_view" />
<androidx.cardview.widget.CardView
app:cardUseCompatPadding="true"
android:onClick="@{() -> handlers.onManageBlockedTimesClicked()}"

View file

@ -14,7 +14,7 @@
-->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="io.timelimit.android.ui.manage.child.advanced.timezone.SetChildTimezoneDialogFragment">
tools:context="io.timelimit.android.ui.manage.child.advanced.timezone.SetUserTimezoneDialogFragment">
<LinearLayout
android:orientation="vertical"

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<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="timezone"
type="String" />
</data>
<androidx.cardview.widget.CardView
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="@string/manage_child_timezone_title"
android:textAppearance="?android:textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:textAppearance="?android:textAppearanceMedium"
tools:text="GMT"
android:text="@{timezone}"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/change_timezone_button"
android:text="@string/manage_child_timezone_change_button"
android:layout_gravity="end"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</layout>