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
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
arguments?.let { | |
val args = MessageListFragmentArgs.fromBundle(it) | |
val userId = args.userId | |
} | |
... |
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
... | |
override fun onBindViewHolder(vh: ViewHolder, position: Int) { | |
val itemData = getData(position) | |
vh.textView.setTextFuture(PrecomputedTextCompat.getTextFuture( | |
itemData.text, | |
TextViewCompat.getTextMetricsParams(textView), | |
/*optional custom executor*/ null) | |
) |
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
fun setTextAsync(textView: TextView, longString: String) { | |
val params = textView.textMetricsParams | |
val ref = WeakReference(textView) | |
CoroutineScope.launch(Dispatchers.Default) { | |
val pText = PrecomputedText.create(longString, params) | |
withContext(Dispatchers.Main) { | |
ref.get()?.let { textView -> | |
textView.text = pText | |
} |
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
@ExperimentalCoroutinesApi | |
fun notifyNetwork() = channelFlow<Boolean> { | |
val networkRequest = NetworkRequest.Builder() | |
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI) | |
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) | |
.build() | |
val connectivityManager: ConnectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
connectivityManager.registerNetworkCallback(networkRequest, object : ConnectivityManager.NetworkCallback() { |
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
class HeadsetConnectionReceiver(private val actionPlugged: (Boolean) -> Unit) : BroadcastReceiver() { | |
override fun onReceive(context: Context?, intent: Intent?) { | |
intent?.run { | |
if (Intent.ACTION_HEADSET_PLUG == action) { | |
when (getIntExtra("state", -1)) { | |
0 -> actionPlugged(false) | |
1 -> actionPlugged(true) | |
} | |
} | |
} |
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
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@drawable/bg_gradient" | |
tools:context=".MainActivity"> | |
<androidx.cardview.widget.CardView | |
android:id="@+id/rvSentenceCard" |
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
itemView.setOnLongClickListener { view -> | |
val data = ClipData.newPlainText("", word) | |
val shadowBuilder = View.DragShadowBuilder(view) | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { | |
view.startDragAndDrop(data, shadowBuilder, view, 0) | |
} else { | |
view.startDrag(data, shadowBuilder, view, 0) | |
} | |
true | |
} |