diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/IntroFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/IntroFragment.kt index eff7fae..f8ff1a6 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/IntroFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/IntroFragment.kt @@ -1,224 +1,224 @@ package it.reyboz.bustorino.fragments import android.content.Context import android.graphics.* import android.graphics.text.LineBreaker import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button import android.widget.ImageView import android.widget.TextView import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat import androidx.fragment.app.Fragment import it.reyboz.bustorino.R import it.reyboz.bustorino.backend.utils import it.reyboz.bustorino.util.Permissions import it.reyboz.bustorino.util.ViewUtils import java.lang.IllegalStateException // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private const val SCREEN_INDEX = "screenindex" class IntroFragment : Fragment() { private var screenIndex = 1 private lateinit var imageHolder: ImageView private lateinit var textView: TextView private lateinit var listener: IntroListener private lateinit var interactButton: Button private val locationRequestResLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()){ res -> //onActivityResult(res: map) if(res.get(Permissions.LOCATION_PERMISSIONS[0])==true || res.get(Permissions.LOCATION_PERMISSIONS[1])==true) setInteractButtonState(ButtonState.LOCATION,false) } private val notificationsReqLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { if (it) setInteractButtonState(ButtonState.NOTIFICATIONS, false) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) arguments?.let { screenIndex = it.getInt(SCREEN_INDEX) } } override fun onAttach(context: Context) { super.onAttach(context) if(context !is IntroListener){ throw IllegalStateException("Context must implement IntroListener") } listener = context } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment val root= inflater.inflate(R.layout.fragment_intro, container, false) imageHolder = root.findViewById(R.id.image_tutorial) textView = root.findViewById(R.id.tutorialTextView) interactButton = root.findViewById(R.id.permissionButton) when(screenIndex){ 0 -> { setImageBitmap(imageHolder, R.drawable.tuto_busto, 300f) textView.text = utils.convertHtml(getString(R.string.tutorial_first)) } 1->{ setImageBitmap(imageHolder, R.drawable.tuto_search) setTextHtmlDescription(R.string.tutorial_search) } 2 ->{ setImageBitmap(imageHolder, R.drawable.tuto_arrivals) textView.text = utils.convertHtml(getString(R.string.tutorial_arrivals)) } 3 ->{ setImageBitmap(imageHolder, R.drawable.tuto_stops) textView.text = utils.convertHtml(getString(R.string.tutorial_stops)) } 4 ->{ - setImageBitmap(imageHolder, R.drawable.tuto_map) + setImageBitmap(imageHolder, R.drawable.tuto_map, 300f) textView.text = utils.convertHtml(getString(R.string.tutorial_map)) if (Build.VERSION.SDK_INT >= 23) { //only show if running on Android M or above val permGranted = (Permissions.anyLocationPermissionsGranted(requireContext())) setInteractButtonState(ButtonState.LOCATION, !permGranted) interactButton.setOnClickListener { //ask location permission locationRequestResLauncher.launch(Permissions.LOCATION_PERMISSIONS) } interactButton.visibility = View.VISIBLE } } 5 ->{ - setImageBitmap(imageHolder, R.drawable.tuto_line_det) + setImageBitmap(imageHolder, R.drawable.tuto_line_det, 300f) textView.text = utils.convertHtml(getString(R.string.tutorial_line)) } 6-> { setImageBitmap(imageHolder,R.drawable.tuto_menu) setTextHtmlDescription(R.string.tutorial_menu) //this is the cheapest trick ever lol if(!Permissions.isNotificationPermissionNeeded()){ //no other screen needed val button = root.findViewById