mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 21:42:44 +01:00
Add school quick actions (#570)
This commit is contained in:
parent
125a010f03
commit
a71a183160
@ -10,6 +10,8 @@ import io.github.wulkanowy.ui.base.BaseFragment
|
|||||||
import io.github.wulkanowy.ui.modules.main.MainView
|
import io.github.wulkanowy.ui.modules.main.MainView
|
||||||
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersChildView
|
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersChildView
|
||||||
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersFragment
|
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersFragment
|
||||||
|
import io.github.wulkanowy.utils.dialPhone
|
||||||
|
import io.github.wulkanowy.utils.openMapLocation
|
||||||
import kotlinx.android.synthetic.main.fragment_school.*
|
import kotlinx.android.synthetic.main.fragment_school.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -35,12 +37,17 @@ class SchoolFragment : BaseFragment(), SchoolView, MainView.TitledView, SchoolAn
|
|||||||
|
|
||||||
override fun initView() {
|
override fun initView() {
|
||||||
schoolSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
|
schoolSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
|
||||||
|
|
||||||
|
schoolAddressButton.setOnClickListener { presenter.onAddressSelected() }
|
||||||
|
schoolTelephoneButton.setOnClickListener { presenter.onTelephoneSelected() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateData(data: School) {
|
override fun updateData(data: School) {
|
||||||
schoolName.text = data.name
|
schoolName.text = data.name
|
||||||
schoolAddress.text = data.address.ifBlank { "-" }
|
schoolAddress.text = data.address.ifBlank { "-" }
|
||||||
|
schoolAddressButton.visibility = if (data.address.isNotBlank()) View.VISIBLE else View.GONE
|
||||||
schoolTelephone.text = data.contact.ifBlank { "-" }
|
schoolTelephone.text = data.contact.ifBlank { "-" }
|
||||||
|
schoolTelephoneButton.visibility = if (data.contact.isNotBlank()) View.VISIBLE else View.GONE
|
||||||
schoolHeadmaster.text = data.headmaster
|
schoolHeadmaster.text = data.headmaster
|
||||||
schoolPedagogue.text = data.pedagogue
|
schoolPedagogue.text = data.pedagogue
|
||||||
}
|
}
|
||||||
@ -77,4 +84,12 @@ class SchoolFragment : BaseFragment(), SchoolView, MainView.TitledView, SchoolAn
|
|||||||
presenter.onDetachView()
|
presenter.onDetachView()
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun openMapsLocation(location: String) {
|
||||||
|
context?.openMapLocation(location)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dialPhone(phone: String) {
|
||||||
|
context?.dialPhone(phone)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,10 @@ class SchoolPresenter @Inject constructor(
|
|||||||
private val analytics: FirebaseAnalyticsHelper
|
private val analytics: FirebaseAnalyticsHelper
|
||||||
) : BasePresenter<SchoolView>(errorHandler, studentRepository, schedulers) {
|
) : BasePresenter<SchoolView>(errorHandler, studentRepository, schedulers) {
|
||||||
|
|
||||||
|
private var address: String? = null
|
||||||
|
|
||||||
|
private var contact: String? = null
|
||||||
|
|
||||||
override fun onAttachView(view: SchoolView) {
|
override fun onAttachView(view: SchoolView) {
|
||||||
super.onAttachView(view)
|
super.onAttachView(view)
|
||||||
view.initView()
|
view.initView()
|
||||||
@ -34,6 +38,14 @@ class SchoolPresenter @Inject constructor(
|
|||||||
loadData(forceRefresh)
|
loadData(forceRefresh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onAddressSelected() {
|
||||||
|
address?.let{ view?.openMapsLocation(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onTelephoneSelected() {
|
||||||
|
contact?.let { view?.dialPhone(it) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadData(forceRefresh: Boolean = false) {
|
private fun loadData(forceRefresh: Boolean = false) {
|
||||||
Timber.i("Loading school info started")
|
Timber.i("Loading school info started")
|
||||||
disposable.add(studentRepository.getCurrentStudent()
|
disposable.add(studentRepository.getCurrentStudent()
|
||||||
@ -51,6 +63,8 @@ class SchoolPresenter @Inject constructor(
|
|||||||
}.subscribe({
|
}.subscribe({
|
||||||
Timber.i("Loading teachers result: Success")
|
Timber.i("Loading teachers result: Success")
|
||||||
view?.run {
|
view?.run {
|
||||||
|
address = it.address.ifBlank { null }
|
||||||
|
contact = it.contact.ifBlank { null }
|
||||||
updateData(it)
|
updateData(it)
|
||||||
showContent(true)
|
showContent(true)
|
||||||
showEmpty(false)
|
showEmpty(false)
|
||||||
|
@ -19,4 +19,8 @@ interface SchoolView : BaseView, SchoolAndTeachersChildView {
|
|||||||
fun showContent(show: Boolean)
|
fun showContent(show: Boolean)
|
||||||
|
|
||||||
fun hideRefresh()
|
fun hideRefresh()
|
||||||
|
|
||||||
|
fun openMapsLocation(location: String)
|
||||||
|
|
||||||
|
fun dialPhone(phone: String)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import androidx.annotation.ColorInt
|
|||||||
import androidx.annotation.ColorRes
|
import androidx.annotation.ColorRes
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import io.github.wulkanowy.R
|
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
fun Context.getThemeAttrColor(@AttrRes colorAttr: Int): Int {
|
fun Context.getThemeAttrColor(@AttrRes colorAttr: Int): Int {
|
||||||
@ -41,4 +40,18 @@ fun Context.openEmail(chooserTitle: String, email: String, subject: String?, bod
|
|||||||
startActivity(Intent.createChooser(emailIntent, chooserTitle))
|
startActivity(Intent.createChooser(emailIntent, chooserTitle))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.openMapLocation(location: String) {
|
||||||
|
val intentUri = Uri.parse("geo:0,0?q=${Uri.encode(location)}")
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, intentUri)
|
||||||
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.dialPhone(phone: String) {
|
||||||
|
val intentUri = Uri.parse("tel:$phone")
|
||||||
|
val intent = Intent(Intent.ACTION_DIAL, intentUri)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.dpToPx(dp: Float) = dp * resources.displayMetrics.densityDpi / DENSITY_DEFAULT
|
fun Context.dpToPx(dp: Float) = dp * resources.displayMetrics.densityDpi / DENSITY_DEFAULT
|
||||||
|
9
app/src/main/res/drawable/ic_school_directions.xml
Normal file
9
app/src/main/res/drawable/ic_school_directions.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFF"
|
||||||
|
android:pathData="M22.43,10.59l-9.01,-9.01c-0.75,-0.75 -2.07,-0.76 -2.83,0l-9,9c-0.78,0.78 -0.78,2.04 0,2.82l9,9c0.39,0.39 0.9,0.58 1.41,0.58 0.51,0 1.02,-0.19 1.41,-0.58l8.99,-8.99c0.79,-0.76 0.8,-2.02 0.03,-2.82zM12.01,20.99l-9,-9 9,-9 9,9 -9,9zM8,11v4h2v-3h4v2.5l3.5,-3.5L14,7.5L14,10L9,10c-0.55,0 -1,0.45 -1,1z"/>
|
||||||
|
</vector>
|
9
app/src/main/res/drawable/ic_school_phone.xml
Normal file
9
app/src/main/res/drawable/ic_school_phone.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFF"
|
||||||
|
android:pathData="M6.54,5c0.06,0.89 0.21,1.76 0.45,2.59l-1.2,1.2c-0.41,-1.2 -0.67,-2.47 -0.76,-3.79h1.51m9.86,12.02c0.85,0.24 1.72,0.39 2.6,0.45v1.49c-1.32,-0.09 -2.59,-0.35 -3.8,-0.75l1.2,-1.19M7.5,3H4c-0.55,0 -1,0.45 -1,1 0,9.39 7.61,17 17,17 0.55,0 1,-0.45 1,-1v-3.49c0,-0.55 -0.45,-1 -1,-1 -1.24,0 -2.45,-0.2 -3.57,-0.57 -0.1,-0.04 -0.21,-0.05 -0.31,-0.05 -0.26,0 -0.51,0.1 -0.71,0.29l-2.2,2.2c-2.83,-1.45 -5.15,-3.76 -6.59,-6.59l2.2,-2.2c0.28,-0.28 0.36,-0.67 0.25,-1.02C8.7,6.45 8.5,5.25 8.5,4c0,-0.55 -0.45,-1 -1,-1z"/>
|
||||||
|
</vector>
|
@ -60,55 +60,95 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="horizontal">
|
||||||
android:paddingStart="12dp"
|
<LinearLayout
|
||||||
android:paddingLeft="12dp"
|
android:layout_width="0dp"
|
||||||
android:paddingTop="7dp"
|
|
||||||
android:paddingEnd="12dp"
|
|
||||||
android:paddingRight="12dp"
|
|
||||||
android:paddingBottom="7dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/school_address"
|
android:layout_weight="1"
|
||||||
android:textColor="?android:textColorSecondary"
|
android:orientation="vertical"
|
||||||
android:textSize="12sp" />
|
android:paddingStart="12dp"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingTop="7dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:paddingRight="12dp"
|
||||||
|
android:paddingBottom="7dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/schoolAddress"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/school_address"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/schoolAddress"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:textSize="17sp"
|
||||||
|
tools:text="@tools:sample/full_names" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/schoolAddressButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textIsSelectable="true"
|
app:srcCompat="@drawable/ic_school_directions"
|
||||||
android:textSize="17sp"
|
android:contentDescription="@string/school_address_button"
|
||||||
tools:text="@tools:sample/full_names" />
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:tint="?colorPrimary"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_gravity="center_vertical" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="horizontal">
|
||||||
android:paddingStart="12dp"
|
<LinearLayout
|
||||||
android:paddingLeft="12dp"
|
android:layout_width="0dp"
|
||||||
android:paddingTop="7dp"
|
|
||||||
android:paddingEnd="12dp"
|
|
||||||
android:paddingRight="12dp"
|
|
||||||
android:paddingBottom="7dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/school_telephone"
|
android:layout_weight="1"
|
||||||
android:textColor="?android:textColorSecondary"
|
android:orientation="vertical"
|
||||||
android:textSize="12sp" />
|
android:paddingStart="12dp"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingTop="7dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:paddingRight="12dp"
|
||||||
|
android:paddingBottom="7dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/schoolTelephone"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/school_telephone"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/schoolTelephone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:textSize="17sp"
|
||||||
|
tools:text="@tools:sample/full_names" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/schoolTelephoneButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textIsSelectable="true"
|
app:srcCompat="@drawable/ic_school_phone"
|
||||||
android:textSize="17sp"
|
android:contentDescription="@string/school_telephone_button"
|
||||||
tools:text="@tools:sample/full_names" />
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:tint="?colorPrimary"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_gravity="center_vertical" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -232,6 +232,8 @@
|
|||||||
<string name="school_telephone">Telefon</string>
|
<string name="school_telephone">Telefon</string>
|
||||||
<string name="school_headmaster">Imię i nazwisko dyrektora</string>
|
<string name="school_headmaster">Imię i nazwisko dyrektora</string>
|
||||||
<string name="school_pedagogue">Imię i nazwisko pedagoga</string>
|
<string name="school_pedagogue">Imię i nazwisko pedagoga</string>
|
||||||
|
<string name="school_address_button">Pokaż na mpaie</string>
|
||||||
|
<string name="school_telephone_button">Zadzwoń</string>
|
||||||
|
|
||||||
|
|
||||||
<!--Teacher-->
|
<!--Teacher-->
|
||||||
|
@ -218,6 +218,8 @@
|
|||||||
<string name="school_telephone">Telephone</string>
|
<string name="school_telephone">Telephone</string>
|
||||||
<string name="school_headmaster">Name of headmaster</string>
|
<string name="school_headmaster">Name of headmaster</string>
|
||||||
<string name="school_pedagogue">Name of pedagogue</string>
|
<string name="school_pedagogue">Name of pedagogue</string>
|
||||||
|
<string name="school_address_button">Show on map</string>
|
||||||
|
<string name="school_telephone_button">Call</string>
|
||||||
|
|
||||||
|
|
||||||
<!--Teacher-->
|
<!--Teacher-->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user