Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mylife: smoother myhealth birthdate (fixes #4929) #4930

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.ole.planet.myplanet.ui.myhealth

import android.app.DatePickerDialog
import android.os.Bundle
import android.text.TextUtils
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.Spinner
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -22,7 +24,8 @@ import org.ole.planet.myplanet.utilities.AndroidDecrypter.Companion.decrypt
import org.ole.planet.myplanet.utilities.AndroidDecrypter.Companion.encrypt
import org.ole.planet.myplanet.utilities.AndroidDecrypter.Companion.generateKey
import org.ole.planet.myplanet.utilities.Utilities

import java.util.Calendar
import java.util.Locale

class AddMyHealthActivity : AppCompatActivity() {
private lateinit var activityAddMyHealthBinding: ActivityAddMyHealthBinding
Expand Down Expand Up @@ -71,6 +74,16 @@ class AddMyHealthActivity : AppCompatActivity() {
spinner.adapter = adapter

initViews()
val datePickerClickListener = View.OnClickListener {
val now = Calendar.getInstance()
val dpd = DatePickerDialog(this, { _, year, month, dayOfMonth ->
val selectedDate = String.format(Locale.US, "%04d-%02d-%02d", year, month + 1, dayOfMonth)
activityAddMyHealthBinding.etBirthdateLayout.editText?.setText(selectedDate)
}, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH))
dpd.show()
}
activityAddMyHealthBinding.etBirthdateLayout.editText?.setOnClickListener(datePickerClickListener)
findViewById<ImageView>(R.id.iv_date_picker).setOnClickListener(datePickerClickListener)
}

private fun createMyHealth() {
Expand All @@ -80,7 +93,7 @@ class AddMyHealthActivity : AppCompatActivity() {
userModelB?.middleName = "${activityAddMyHealthBinding.etMname.editText?.text}".trim { it <= ' ' }
userModelB?.lastName = "${activityAddMyHealthBinding.etLname.editText?.text}".trim { it <= ' ' }
userModelB?.email = "${activityAddMyHealthBinding.etEmail.editText?.text}".trim { it <= ' ' }
userModelB?.dob = "${activityAddMyHealthBinding.etBirthdate.editText?.text}".trim { it <= ' ' }
userModelB?.dob = "${activityAddMyHealthBinding.etBirthdateLayout.editText?.text}".trim { it <= ' ' }
userModelB?.birthPlace = "${activityAddMyHealthBinding.etBirthplace.editText?.text}".trim { it <= ' ' }
userModelB?.phoneNumber = "${activityAddMyHealthBinding.etPhone.editText?.text}".trim { it <= ' ' }
health.emergencyContactName = "${activityAddMyHealthBinding.etEmergency.editText?.text}".trim { it <= ' ' }
Expand Down Expand Up @@ -130,7 +143,7 @@ class AddMyHealthActivity : AppCompatActivity() {
activityAddMyHealthBinding.etLname.editText?.setText(userModelB?.lastName)
activityAddMyHealthBinding.etEmail.editText?.setText(userModelB?.email)
activityAddMyHealthBinding.etPhone.editText?.setText(userModelB?.phoneNumber)
activityAddMyHealthBinding.etBirthdate.editText?.setText(userModelB?.dob)
activityAddMyHealthBinding.etBirthdateLayout.editText?.setText(userModelB?.dob)
activityAddMyHealthBinding.etBirthplace.editText?.setText(userModelB?.birthPlace)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ole.planet.myplanet.ui.myhealth

import android.app.DatePickerDialog
import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
Expand All @@ -25,6 +26,7 @@ import io.realm.Sort
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.databinding.AlertHealthListBinding
import org.ole.planet.myplanet.databinding.AlertMyPersonalBinding
import org.ole.planet.myplanet.databinding.EditProfileDialogBinding
import org.ole.planet.myplanet.databinding.FragmentVitalSignBinding
import org.ole.planet.myplanet.datamanager.DatabaseService
import org.ole.planet.myplanet.model.RealmMyHealth
Expand All @@ -33,7 +35,10 @@ import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.userprofile.BecomeMemberActivity
import org.ole.planet.myplanet.utilities.AndroidDecrypter
import org.ole.planet.myplanet.utilities.TimeUtils.getFormatedDate
import org.ole.planet.myplanet.utilities.Utilities
import java.util.Calendar
import java.util.Locale

/**
* A simple [Fragment] subclass.
Expand All @@ -59,7 +64,15 @@ class MyHealthFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
view.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.secondary_bg))
alertMyPersonalBinding = AlertMyPersonalBinding.inflate(LayoutInflater.from(context))

fragmentVitalSignBinding.txtDob.hint = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
fragmentVitalSignBinding.txtDob.setOnClickListener {
val now = Calendar.getInstance()
val dpd = DatePickerDialog(requireContext(), { _, year, month, dayOfMonth ->
val selectedDate = String.format(Locale.US, "%04d-%02d-%02dT00:00:00.000Z", year, month + 1, dayOfMonth)
fragmentVitalSignBinding.txtDob.setText(selectedDate)
}, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH))
dpd.show()
}
fragmentVitalSignBinding.rvRecords.addItemDecoration(DividerItemDecoration(activity, DividerItemDecoration.VERTICAL))
profileDbHandler = UserProfileDbHandler(alertMyPersonalBinding.root.context)
userId = if (TextUtils.isEmpty(profileDbHandler?.userModel?._id)) profileDbHandler?.userModel?.id else profileDbHandler?.userModel?._id
Expand All @@ -78,6 +91,8 @@ class MyHealthFragment : Fragment() {
fragmentVitalSignBinding.fabAddMember.setOnClickListener {
startActivity(Intent(activity, BecomeMemberActivity::class.java))
}

fragmentVitalSignBinding.txtDob.text = if (TextUtils.isEmpty(userModel?.dob)) getString(R.string.birth_date) else getFormatedDate(userModel?.dob, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
}

private fun getHealthRecords(memberId: String?) {
Expand Down
36 changes: 27 additions & 9 deletions app/src/main/res/layout/activity_add_my_health.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,39 @@
android:textColor="@color/daynight_textColor" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/et_birthdate"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="@color/hint_color">
android:orientation="horizontal"
android:gravity="center_vertical">

<EditText
<ImageView
android:id="@+id/iv_date_picker"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="8dp"
android:src="@drawable/ic_calendar"
android:padding="2dp" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/et_birthdate_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/birth_date"
android:padding="@dimen/padding_normal"
android:backgroundTint="@color/daynight_textColor"
android:textColor="@color/daynight_textColor" />
</com.google.android.material.textfield.TextInputLayout>
android:textColorHint="@color/hint_color">

<EditText
android:id="@+id/et_birthdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/birth_date"
android:padding="@dimen/padding_normal"
android:backgroundTint="@color/daynight_textColor"
android:textColor="@color/daynight_textColor"
android:focusable="false"
android:clickable="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</LinearLayout>

<LinearLayout
Expand Down
Loading