-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from gdsc-nits-org/dev
Navigation and Profile Page Integrated
- Loading branch information
Showing
62 changed files
with
1,959 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 67 additions & 12 deletions
79
app/src/main/java/com/example/deliveryapp/Fragments/AccessLocation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,105 @@ | ||
package com.example.deliveryapp.Fragments | ||
|
||
import android.Manifest | ||
import android.app.AlertDialog | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.activity.OnBackPressedCallback | ||
import androidx.core.app.ActivityCompat | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.NavController | ||
import androidx.navigation.Navigation | ||
import com.example.deliveryapp.R | ||
import com.example.deliveryapp.databinding.FragmentAccessLocationBinding | ||
|
||
|
||
class AccessLocation : Fragment() { | ||
|
||
|
||
private lateinit var binding: FragmentAccessLocationBinding | ||
private lateinit var navController: NavController | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
): View { | ||
binding = FragmentAccessLocationBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
navController= Navigation.findNavController(view) | ||
|
||
navController = Navigation.findNavController(view) | ||
binding.btnAccessLocation.setOnClickListener { | ||
navController.navigate(R.id.action_accessLocation_to_animatedScreen) | ||
|
||
if (checkLocationPermission()) { | ||
// Permission granted, navigate to the next screen | ||
navController.navigate(R.id.animatedScreen) | ||
} | ||
} | ||
|
||
val callback = object : OnBackPressedCallback(true) { | ||
override fun handleOnBackPressed() { | ||
// Log.d("TAG", "Pressed...") | ||
// Do nothing or handle as needed | ||
} | ||
} | ||
|
||
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback) | ||
|
||
// Check for permission on fragment start | ||
} | ||
|
||
private fun checkLocationPermission(): Boolean { | ||
val context = requireContext() | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | ||
// Runtime permissions not required below Android M | ||
return true | ||
} | ||
if (ContextCompat.checkSelfPermission( | ||
context, | ||
Manifest.permission.ACCESS_FINE_LOCATION | ||
) != PackageManager.PERMISSION_GRANTED | ||
) { | ||
// Permission not granted, request it | ||
if (ActivityCompat.shouldShowRequestPermissionRationale( | ||
requireActivity(), | ||
Manifest.permission.ACCESS_FINE_LOCATION | ||
) | ||
) { | ||
// Show an explanation to the user if they have denied permission previously | ||
AlertDialog.Builder(context) | ||
.setTitle("Location Permission Needed") | ||
.setMessage("This app needs the Location permission to function properly. Please allow.") | ||
.setPositiveButton("OK") { _, _ -> | ||
requestLocationPermission() | ||
} | ||
.setNegativeButton("Cancel") { dialog, _ -> | ||
dialog.dismiss() | ||
} | ||
.create() | ||
.show() | ||
} else { | ||
// No explanation needed, request the permission | ||
requestLocationPermission() | ||
} | ||
return false | ||
} | ||
// Permission already granted | ||
return true | ||
} | ||
|
||
private fun requestLocationPermission() { | ||
ActivityCompat.requestPermissions( | ||
requireActivity(), | ||
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), | ||
LOCATION_PERMISSION_REQUEST_CODE | ||
) | ||
} | ||
|
||
} | ||
companion object { | ||
private const val LOCATION_PERMISSION_REQUEST_CODE = 1001 | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/example/deliveryapp/Fragments/LocationFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.example.deliveryapp.Fragments | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.activity.OnBackPressedCallback | ||
import androidx.navigation.NavController | ||
import androidx.navigation.Navigation | ||
import com.example.deliveryapp.R | ||
import com.example.deliveryapp.databinding.FragmentLocationBinding | ||
|
||
class LocationFragment : Fragment() { | ||
|
||
private lateinit var navController: NavController | ||
private lateinit var binding:FragmentLocationBinding | ||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
binding=FragmentLocationBinding.inflate(inflater,container,false) | ||
return binding.root | ||
|
||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
navController=Navigation.findNavController(view) | ||
|
||
|
||
|
||
binding.btnAddLocation.setOnClickListener { | ||
navController.navigate(R.id.action_locationFragment_to_addressFragment) | ||
} | ||
|
||
val callback = object : OnBackPressedCallback(true) { | ||
override fun handleOnBackPressed() { | ||
// Log.d("TAG", "Pressed...") | ||
} | ||
} | ||
|
||
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.