From c0a8673e9f97fbeb565000fe85d2f1ce55f6e8c2 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 16 Sep 2020 10:21:33 -0300 Subject: Make apps work on API 21+ (except cashier that needs 23+) --- .../java/org/gnu/anastasis/ui/IntroFragment.kt | 1 - .../ui/authentication/AuthenticationFragment.kt | 1 - .../gnu/anastasis/ui/authentication/SmsFragment.kt | 3 ++- .../gnu/anastasis/ui/identity/IdentityFragment.kt | 30 ++++++++++++++-------- .../src/main/res/layout/fragment_identity.xml | 4 ++- .../src/main/res/layout/fragment_intro.xml | 4 ++- .../main/res/layout/fragment_security_question.xml | 8 +++--- anastasis-ui/src/main/res/layout/fragment_sms.xml | 2 +- .../src/main/res/layout/fragment_video.xml | 6 ++--- 9 files changed, 36 insertions(+), 23 deletions(-) (limited to 'anastasis-ui/src') diff --git a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/IntroFragment.kt b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/IntroFragment.kt index 1e5a8d1..d8f0185 100644 --- a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/IntroFragment.kt +++ b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/IntroFragment.kt @@ -21,7 +21,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import kotlinx.android.synthetic.main.fragment_intro.* diff --git a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/AuthenticationFragment.kt b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/AuthenticationFragment.kt index 5f7ab2e..59d0410 100644 --- a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/AuthenticationFragment.kt +++ b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/AuthenticationFragment.kt @@ -26,7 +26,6 @@ import android.widget.Toast.LENGTH_SHORT import androidx.annotation.IdRes import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import androidx.lifecycle.Observer import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController import com.google.android.material.card.MaterialCardView diff --git a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/SmsFragment.kt b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/SmsFragment.kt index 2daf14a..a5d872d 100644 --- a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/SmsFragment.kt +++ b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/authentication/SmsFragment.kt @@ -26,6 +26,7 @@ import android.view.View import android.view.ViewGroup import androidx.annotation.RequiresPermission import androidx.core.content.ContextCompat +import androidx.core.content.getSystemService import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController @@ -95,7 +96,7 @@ class SmsFragment : Fragment() { @SuppressLint("HardwareIds") @RequiresPermission(PERMISSION) private fun fillPhoneNumber() { - val telephonyService = requireContext().getSystemService(TelephonyManager::class.java) + val telephonyService = requireContext().getSystemService() telephonyService?.line1Number?.let { phoneNumber -> smsView.editText?.setText(phoneNumber) smsView.editText?.setSelection(phoneNumber.length) diff --git a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/identity/IdentityFragment.kt b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/identity/IdentityFragment.kt index bcfbf24..ad97ab6 100644 --- a/anastasis-ui/src/main/java/org/gnu/anastasis/ui/identity/IdentityFragment.kt +++ b/anastasis-ui/src/main/java/org/gnu/anastasis/ui/identity/IdentityFragment.kt @@ -18,15 +18,18 @@ package org.gnu.anastasis.ui.identity import android.annotation.SuppressLint import android.app.DatePickerDialog +import android.os.Build.VERSION.SDK_INT import android.os.Bundle import android.telephony.TelephonyManager import android.text.format.DateFormat.getDateFormat import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast +import android.widget.Toast.LENGTH_LONG +import androidx.core.content.getSystemService import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController import kotlinx.android.synthetic.main.fragment_identity.* import org.gnu.anastasis.ui.MainViewModel @@ -63,17 +66,22 @@ class AnastasisIdentityFragment : Fragment() { findNavController().navigate(R.id.action_nav_anastasis_identity_to_nav_change_location) } birthDateInput.editText?.setOnClickListener { - val picker = DatePickerDialog(requireContext()) - picker.datePicker.maxDate = System.currentTimeMillis() - DAYS.toMillis(365) * MIN_AGE - picker.setOnDateSetListener { _, year, month, dayOfMonth -> - val calender = Calendar.getInstance().apply { - set(year, month, dayOfMonth) + if (SDK_INT >= 24) { + val picker = DatePickerDialog(requireContext()) + picker.datePicker.maxDate = + System.currentTimeMillis() - DAYS.toMillis(365) * MIN_AGE + picker.setOnDateSetListener { _, year, month, dayOfMonth -> + val calender = Calendar.getInstance().apply { + set(year, month, dayOfMonth) + } + val date = Date(calender.timeInMillis) + val dateStr = getDateFormat(requireContext()).format(date) + birthDateInput.editText?.setText(dateStr) } - val date = Date(calender.timeInMillis) - val dateStr = getDateFormat(requireContext()).format(date) - birthDateInput.editText?.setText(dateStr) + picker.show() + } else { + Toast.makeText(requireContext(), "Needs newer phone", LENGTH_LONG).show() } - picker.show() } createIdentifierButton.setOnClickListener { findNavController().navigate(R.id.action_nav_anastasis_intro_to_nav_anastasis_authentication) @@ -82,7 +90,7 @@ class AnastasisIdentityFragment : Fragment() { @Suppress("unused") private fun getCountryName(): String { - val tm = requireContext().getSystemService(TelephonyManager::class.java)!! + val tm = requireContext().getSystemService()!! val countryIso = if (tm.networkCountryIso.isNullOrEmpty()) { if (tm.simCountryIso.isNullOrEmpty()) { if (Locale.getDefault().country.isNullOrEmpty()) "unknown" diff --git a/anastasis-ui/src/main/res/layout/fragment_identity.xml b/anastasis-ui/src/main/res/layout/fragment_identity.xml index bcf6e4d..4a48d32 100644 --- a/anastasis-ui/src/main/res/layout/fragment_identity.xml +++ b/anastasis-ui/src/main/res/layout/fragment_identity.xml @@ -16,6 +16,7 @@ @@ -31,7 +32,8 @@ android:layout_margin="16dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/ic_baseline_person" /> + app:srcCompat="@drawable/ic_baseline_person" + tools:ignore="ContentDescription" /> @@ -33,7 +34,8 @@ app:layout_constraintVertical_bias="1.0" app:layout_constraintVertical_chainStyle="spread" app:srcCompat="@drawable/ic_baseline_cloud_circle" - app:tint="@color/green" /> + app:tint="@color/green" + tools:ignore="ContentDescription" /> @@ -80,11 +81,12 @@ android:layout_height="wrap_content" android:layout_margin="16dp" android:background="?attr/selectableItemBackground" - android:drawableTint="?attr/colorOnPrimarySurface" android:src="@drawable/ic_add_circle" android:text="Save" + app:drawableTint="?attr/colorOnPrimarySurface" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toBottomOf="@+id/questionCard" /> + app:layout_constraintTop_toBottomOf="@+id/questionCard" + tools:ignore="ContentDescription" />