Skip to content

Instantly share code, notes, and snippets.

public int countSubstrings(String s) {
int c = 0;
for (int i = 0; i < s.length(); i++) {
StringBuilder sb = new StringBuilder();
for (int j = i; j < s.length(); j++) {
if (isPal(sb.append(s.charAt(j)).toString())) c++;
}
}
return c;
view_terms.setOnClickListener {
val dialogView = requireContext().showOneButtonDialog(
getString(R.string.connection_terms),
getString(R.string.terms_description),
true
) { view, rootLayout ->
beginDelayedTransition(rootLayout, view.getTransform(view_terms))
}
beginDelayedTransition(root_layout, it.getTransform(dialogView))
}
fun Context.showOneButtonDialog(
title: String,
message: String,
isRegistrationDialog: Boolean,
transitionFunction: (View, ConstraintLayout) -> (Unit)
): View {
val dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_one_button, null)
val builder = AlertDialog.Builder(this).setView(dialogView)
val alertDialog = builder.show()
private fun addProductQuantity() {
beginDelayedTransition(scan, pick_window.getTransform(btn_complete))
btn_complete.visible()
pick_window.gone()
pick_bg.gone()
requireView().hideKeyboard()
when (it.clickStatus) {
0 -> {
beginDelayedTransition(scan, btn_complete.getTransform(pick_window))
btn_complete.gone()
pick_window.visible()
lastProduct = it
}
fun View.getTransform(mEndView: View) = MaterialContainerTransform().apply {
startView = this@getTransform
endView = mEndView
addTarget(mEndView)
pathMotion = MaterialArcMotion()
duration = 550
scrimColor = Color.TRANSPARENT
}
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:layout_marginTop="@dimen/margin_8dp"
android:layout_marginBottom="@dimen/margin_8dp">
<ImageView
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
class HomeFragment : Fragment(R.layout.fragment_home) {
private var binding: FragmentHomeBinding? = null
private val viewModel by inject<HomeViewModel>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentHomeBinding.bind(view)
viewModel.pictures.observe(viewLifecycleOwner) {
class FeedAdapter(
private val pictures: List<Hit>,
) : ListAdapter<Hit, FeedAdapter.FeedViewHolder>(ItemDiffCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = FeedViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_feed, parent, false)
)
override fun onBindViewHolder(holder: FeedViewHolder, position: Int) {
val pic = pictures[position]