Finish ChooseOsmAndBottomSheet
This commit is contained in:
parent
b341dbf5ef
commit
9c28f7d131
2 changed files with 42 additions and 4 deletions
|
@ -3,16 +3,26 @@ package net.osmand.telegram.ui
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.design.widget.BottomSheetBehavior
|
import android.support.design.widget.BottomSheetBehavior
|
||||||
import android.support.v4.app.DialogFragment
|
import android.support.v4.app.DialogFragment
|
||||||
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v4.app.FragmentManager
|
import android.support.v4.app.FragmentManager
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import net.osmand.telegram.R
|
import net.osmand.telegram.R
|
||||||
|
import net.osmand.telegram.TelegramApplication
|
||||||
|
import net.osmand.telegram.TelegramSettings
|
||||||
import net.osmand.telegram.ui.views.BottomSheetDialog
|
import net.osmand.telegram.ui.views.BottomSheetDialog
|
||||||
|
|
||||||
class ChooseOsmAndBottomSheet : DialogFragment() {
|
class ChooseOsmAndBottomSheet : DialogFragment() {
|
||||||
|
|
||||||
|
private val app: TelegramApplication
|
||||||
|
get() = activity?.application as TelegramApplication
|
||||||
|
|
||||||
|
private val settings get() = app.settings
|
||||||
|
private val uiUtils get() = app.uiUtils
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!)
|
override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!)
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
|
@ -36,7 +46,22 @@ class ChooseOsmAndBottomSheet : DialogFragment() {
|
||||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: inflate AppConn items
|
val itemsCont = mainView.findViewById<ViewGroup>(R.id.items_container)
|
||||||
|
for (appConn in TelegramSettings.AppConnect.getInstalledApps(requireContext())) {
|
||||||
|
inflater.inflate(R.layout.item_with_rb_and_btn, itemsCont, false).apply {
|
||||||
|
findViewById<ImageView>(R.id.icon).setImageDrawable(uiUtils.getIcon(appConn.iconId))
|
||||||
|
findViewById<TextView>(R.id.title).text = appConn.title
|
||||||
|
findViewById<View>(R.id.primary_btn_container).visibility = View.GONE
|
||||||
|
setOnClickListener {
|
||||||
|
settings.updateAppToConnect(appConn.appPackage)
|
||||||
|
targetFragment?.also { target ->
|
||||||
|
target.onActivityResult(targetRequestCode, OSMAND_CHOSEN_REQUEST_CODE, null)
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
itemsCont.addView(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mainView.findViewById<TextView>(R.id.secondary_btn).apply {
|
mainView.findViewById<TextView>(R.id.secondary_btn).apply {
|
||||||
setText(R.string.shared_string_cancel)
|
setText(R.string.shared_string_cancel)
|
||||||
|
@ -48,11 +73,16 @@ class ChooseOsmAndBottomSheet : DialogFragment() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
const val OSMAND_CHOSEN_REQUEST_CODE = 0
|
||||||
|
|
||||||
private const val TAG = "ChooseOsmAndBottomSheet"
|
private const val TAG = "ChooseOsmAndBottomSheet"
|
||||||
|
|
||||||
fun showInstance(fm: FragmentManager): Boolean {
|
fun showInstance(fm: FragmentManager, target: Fragment): Boolean {
|
||||||
return try {
|
return try {
|
||||||
ChooseOsmAndBottomSheet().show(fm, TAG)
|
ChooseOsmAndBottomSheet().apply {
|
||||||
|
setTargetFragment(target, OSMAND_CHOSEN_REQUEST_CODE)
|
||||||
|
show(fm, TAG)
|
||||||
|
}
|
||||||
true
|
true
|
||||||
} catch (e: RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
false
|
false
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.telegram.ui
|
package net.osmand.telegram.ui
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
|
@ -111,6 +112,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
stopLocationUpdate()
|
stopLocationUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
if (requestCode == ChooseOsmAndBottomSheet.OSMAND_CHOSEN_REQUEST_CODE) {
|
||||||
|
updateOpenOsmAndIcon()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onTelegramStatusChanged(
|
override fun onTelegramStatusChanged(
|
||||||
prevTelegramAuthorizationState: TelegramAuthorizationState,
|
prevTelegramAuthorizationState: TelegramAuthorizationState,
|
||||||
newTelegramAuthorizationState: TelegramAuthorizationState
|
newTelegramAuthorizationState: TelegramAuthorizationState
|
||||||
|
@ -209,7 +217,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
updateOpenOsmAndIcon()
|
updateOpenOsmAndIcon()
|
||||||
}
|
}
|
||||||
installedApps.size > 1 -> {
|
installedApps.size > 1 -> {
|
||||||
fragmentManager?.also { ChooseOsmAndBottomSheet.showInstance(it) }
|
fragmentManager?.also { ChooseOsmAndBottomSheet.showInstance(it, this) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue