Created
May 24, 2017 11:21
-
-
Save drobyshys/6531e06b6ce5ff11ccdd3381ffeaba41 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.example.kotlin | |
import android.app.Dialog | |
import android.support.design.widget.BottomSheetBehavior | |
import android.support.design.widget.BottomSheetDialogFragment | |
import android.support.design.widget.CoordinatorLayout | |
import android.util.Log | |
import android.view.View | |
import android.widget.TextView | |
import com.example.drobysh.kotlinrxjava.R | |
import rx.Observable | |
import rx.android.schedulers.AndroidSchedulers | |
import rx.observers.Subscribers | |
import rx.subscriptions.Subscriptions | |
import java.util.concurrent.TimeUnit | |
class NotHideableBottomSheetDialogFragment : BottomSheetDialogFragment() { | |
var subscription = Subscriptions.empty() | |
var tv: TextView? = null | |
override fun onResume() { | |
super.onResume() | |
Log.i("test", "onResume") | |
if (tv != null) { | |
subscription = Observable.interval(1, TimeUnit.SECONDS) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(Subscribers.create { | |
log("tick") | |
tv?.text = "$it" | |
}) | |
} | |
} | |
override fun onPause() { | |
super.onPause() | |
Log.i("test", "onPause") | |
subscription.unsubscribe() | |
} | |
override fun onDestroyView() { | |
Log.i("test", "onDestroyView") | |
tv = null | |
super.onDestroyView() | |
} | |
override fun setupDialog(dialog: Dialog, style: Int) { | |
Log.i("test", "setupDialog") | |
super.setupDialog(dialog, style) | |
val contentView = View.inflate(context, R.layout.sheet_dialog, null) | |
dialog.setContentView(contentView) | |
val height = arguments?.getInt("height", 300) ?: 300 | |
val behavior = ((contentView.parent as View).layoutParams as CoordinatorLayout.LayoutParams).behavior | |
tv = contentView.findViewById(R.id.tv_text) as TextView | |
contentView.findViewById(R.id.btn).setOnClickListener({ | |
}) | |
if (behavior != null && behavior is BottomSheetBehavior<*>) { | |
behavior.peekHeight = height | |
behavior.isHideable = false | |
} | |
val touchOutsideView = getDialog().window!!.decorView.findViewById(android.support.design.R.id.touch_outside) | |
touchOutsideView.setOnClickListener { dismiss() } | |
} | |
private fun log(s: String) { | |
Log.i("log", s) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment