Created
July 23, 2020 22:58
-
-
Save brh/be3222513ef7c9baa5f820020beedcaa to your computer and use it in GitHub Desktop.
This file contains 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
import android.content.Context | |
import android.util.AttributeSet | |
import android.view.View | |
import android.widget.Toast | |
import androidx.annotation.NonNull | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.observe | |
import com.google.android.material.floatingactionbutton.FloatingActionButton | |
class NetworkConnectionFab: FloatingActionButton { | |
constructor(ctx: Context) : super(ctx) | |
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, R.attr.floatingActionButtonStyle) | |
constructor(@NonNull context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) | |
init { | |
setImageResource(R.drawable.ic_wifi_off) | |
size = SIZE_MINI | |
setOnClickListener { | |
Toast.makeText(context, R.string.no_network, Toast.LENGTH_SHORT).show() | |
} | |
} | |
override fun onAttachedToWindow() { | |
super.onAttachedToWindow() | |
NetworkDetectorLiveData.observe(context as LifecycleOwner){ | |
if (it){ | |
visibility = View.INVISIBLE | |
} | |
else { | |
visibility = View.VISIBLE | |
} | |
} | |
} | |
override fun onDetachedFromWindow() { | |
super.onDetachedFromWindow() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment