Skip to content
This repository was archived by the owner on Jul 17, 2023. It is now read-only.

M3 postwork 3 #18

Merged
merged 3 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation 'com.google.android.gms:play-services-location:17.0.0'
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package="com.example.myapplication">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
136 changes: 136 additions & 0 deletions app/src/main/java/com/example/myapplication/AddressFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.example.myapplication

import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.location.Geocoder
import android.location.LocationManager
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.core.app.ActivityCompat
import androidx.core.content.ContextCompat.getSystemService
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import java.util.*


class AddressFragment : BottomSheetDialogFragment() {


private lateinit var imageButtonClose :ImageView
private lateinit var buttonUpdateAddress : Button
private lateinit var tvActualDirection:TextView
private lateinit var tvOldDirection1 : TextView
private lateinit var tvOldDirection2 : TextView
private var sharedPreferences: SharedPreferences? = null
lateinit var mFusedLocationClient: FusedLocationProviderClient
private val PERMISSION_ID = 33

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_address, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

sharedPreferences = this.activity?.getSharedPreferences("org.bedu.sharedpreferences", Context.MODE_PRIVATE)
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity())

imageButtonClose = view.findViewById(R.id.imageButtonClose)
buttonUpdateAddress = view.findViewById(R.id.buttonUpdateAddress)
tvActualDirection = view.findViewById(R.id.tvActualDirection)
tvOldDirection1 = view.findViewById(R.id.tvOldDirection1)
tvOldDirection2 = view.findViewById(R.id.tvOldDirection2)

setSharedPreferencesAddress()

imageButtonClose.setOnClickListener {
dismiss()
}
buttonUpdateAddress.setOnClickListener {
getLocation()
}

}

private fun setSharedPreferencesAddress() {
tvActualDirection.text = sharedPreferences?.getString("USER_ACTUAL_ADDRESS","")
tvOldDirection1.text = sharedPreferences?.getString("USER_OLD_ADDRESS1","")
tvOldDirection2.text = sharedPreferences?.getString("USER_OLD_ADDRESS2","")
}


@SuppressLint("MissingPermission")
private fun getLocation() {
if (checkPermissions()) {
if (isLocationEnabled()) {

mFusedLocationClient.lastLocation.addOnSuccessListener(requireActivity()) { location ->

val geocoder = Geocoder(requireContext(), Locale.getDefault())
val addresses = location?.latitude?.let {
geocoder.getFromLocation(
it?.toDouble(),
location?.longitude.toDouble(),
1
)
}
val actualAddress = addresses?.get(0)?.getAddressLine(0)
if(tvActualDirection.text.toString() != actualAddress){
tvOldDirection2.text = tvOldDirection1.text.toString()
tvOldDirection1.text = tvActualDirection.text.toString()
tvActualDirection.text = actualAddress
sharedPreferences?.edit()
?.putString("USER_ACTUAL_ADDRESS",tvActualDirection.text.toString())
?.putString("USER_OLD_ADDRESS1",tvOldDirection1.text.toString())
?.putString("USER_OLD_ADDRESS2",tvOldDirection2.text.toString())
?.apply()
}
}
}
} else{
requestPermissions()
}
}


private fun isLocationEnabled(): Boolean {
var locationManager: LocationManager = requireActivity().getSystemService(Context.LOCATION_SERVICE) as LocationManager
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(
LocationManager.NETWORK_PROVIDER
)
}

private fun requestPermissions() {
ActivityCompat.requestPermissions(
requireActivity(),
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION),
PERMISSION_ID
)
}

private fun checkPermissions(): Boolean {
if ( checkGranted(Manifest.permission.ACCESS_COARSE_LOCATION) &&
checkGranted(Manifest.permission.ACCESS_COARSE_LOCATION) ){
return true
}
return false
}

private fun checkGranted(permission: String): Boolean{
return ActivityCompat.checkSelfPermission(requireContext(), permission) == PackageManager.PERMISSION_GRANTED
}

}
10 changes: 1 addition & 9 deletions app/src/main/java/com/example/myapplication/LoginFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ class LoginFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
sharedPreferences = this.activity?.getSharedPreferences("org.bedu.sharedpreferences", Context.MODE_PRIVATE)
if(sharedPreferences?.getBoolean("USER_ACCESS", false) == true){
findNavController().navigate(
R.id.action_loginFragment2_to_menuActivity,
null
)
}

return inflater.inflate(R.layout.fragment_login, container, false)
}

Expand All @@ -67,7 +59,7 @@ class LoginFragment : Fragment() {
loginProgressBar = view.findViewById(R.id.loginProgressBar)



sharedPreferences = this.activity?.getSharedPreferences("org.bedu.sharedpreferences", Context.MODE_PRIVATE)

setSharedPreferencesInputText()
setTextChangeActions()
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/com/example/myapplication/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
package com.example.myapplication

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import android.content.Intent




class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
supportActionBar?.hide()
val sharedPreferences = this.getSharedPreferences("org.bedu.sharedpreferences", Context.MODE_PRIVATE)
if(sharedPreferences?.getBoolean("USER_ACCESS", false) == true){
val intent = Intent(this, MenuActivity::class.java)
startActivity(intent)
}else{
setContentView(R.layout.activity_main)
supportActionBar?.hide()
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/myapplication/OptionAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.RecyclerView


class OptionAdapter(
private val click_listener: () -> Unit,
private val click_listener: (String) -> Unit,
private val options_list: List<Option>
): RecyclerView.Adapter<OptionAdapter.OptionHolder>() {

Expand All @@ -31,7 +31,7 @@ class OptionAdapter(
holder.render(currentOption)

holder.itemView.setOnClickListener{
click_listener()
click_listener(currentOption.name)
}

}
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/com/example/myapplication/ProfileFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ class ProfileFragment : Fragment() {
userImage = view.findViewById(R.id.user_shapeable_image)
userEmail = view.findViewById(R.id.user_email)

val clickListener: () -> Unit = {}

recycler.adapter = OptionAdapter( clickListener, getProfileOptions())
recycler.adapter = OptionAdapter( getOptionsClickListener(), getProfileOptions())
recycler.layoutManager = LinearLayoutManager(activity)

sharedPreferences =
Expand All @@ -63,5 +62,21 @@ class ProfileFragment : Fragment() {
Option("Cambiar contraseña",R.drawable.ic_lock),)
}

private fun getOptionsClickListener():(String) -> Unit{

val clickListener: (String) -> Unit = {
when(it){
"Mis direcciones" -> {
val addressFragment = AddressFragment()
addressFragment.show(this.parentFragmentManager,"fragment")
}

else -> {}
}
}

return clickListener
}


}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_close.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_my_location.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@android:color/black">
<path
android:fillColor="@android:color/black"
android:pathData="M12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94L23,13v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/round_corners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="@color/white"/>
<corners android:topLeftRadius="22dp"
android:topRightRadius="22dp"/>
</shape>
Loading