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

fixed and merged #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -33,6 +35,7 @@ class ApartmentDetailsFragment : Fragment(), InjectableFragment {
private lateinit var binding: FragmentApartmentDetailsBinding
private var apartmentId: Int = -1
private var phoneNumber: String = ""
private var getPhoneNumber = true

private lateinit var recyclerViewAdapter: RatingItemAdapter
private var recyclerViewInit = false
Expand Down Expand Up @@ -60,9 +63,30 @@ class ApartmentDetailsFragment : Fragment(), InjectableFragment {
super.onViewCreated(view, savedInstanceState)

call_button.setOnClickListener {
val callIntent = Intent(Intent.ACTION_DIAL)
callIntent.data = Uri.parse("tel:$phoneNumber")
startActivity(callIntent)
if(getPhoneNumber) {
viewModel?.getApartmentPhoneNumber(apartmentId)
getPhoneNumber = false
}

val builder = AlertDialog.Builder(activity as MainActivity)
builder.setTitle("Wybierz akcję")
builder.setItems(arrayOf("Zadzwoń", "Wyślij SMS")) { dialog, which ->
when(which){
0 -> { val callIntent = Intent(Intent.ACTION_DIAL)
callIntent.data = Uri.parse("tel:$phoneNumber")
phoneNumber = ""
startActivity(callIntent)
}
1 -> {
val smsIntent = Intent(Intent.ACTION_VIEW)
smsIntent.type = "vnd.android-dir/mms-sms"
smsIntent.putExtra("address", phoneNumber)
startActivity(smsIntent)
}
}
getPhoneNumber = true
}
builder.show()
}

apartment_map_fab.setOnClickListener {
Expand Down Expand Up @@ -101,6 +125,8 @@ class ApartmentDetailsFragment : Fragment(), InjectableFragment {
apartment_img_pager_tab_indicator.setupWithViewPager(apartment_img_pager, true)
}

viewModel?.observeApartmentPhoneNumber()

viewModel?.ratingListLiveData?.observe(this, Observer { handleNewRatingList(it) })
viewModel?.observeRatingListSubject()
viewModel?.requestNewRatings(apartmentId)
Expand All @@ -117,12 +143,12 @@ class ApartmentDetailsFragment : Fragment(), InjectableFragment {
recyclerViewAdapter.updateItems(ratings.toMutableList())
}

private fun handleNewApartmentPhoneNumber(phoneNumber: String?){
if(phoneNumber != null && phoneNumber.trim().isNotEmpty()){
this.phoneNumber = phoneNumber
call_button.isEnabled = true
call_button.isFocusable = true
call_button.isClickable = true
private fun handleNewApartmentPhoneNumber(tempPhoneNumber: String?){
if(tempPhoneNumber != null && tempPhoneNumber.trim().isNotEmpty()){
this.phoneNumber = tempPhoneNumber
getPhoneNumber = true
}else if(tempPhoneNumber!!.trim().isEmpty()){
Toast.makeText(activity,"Brak numeru telefonu", Toast.LENGTH_SHORT).show()
}
}

Expand Down