Skip to content

Instantly share code, notes, and snippets.

View gsrathoreniks's full-sized avatar
🖥️
Building solutions

Gajendra Singh Rathore gsrathoreniks

🖥️
Building solutions
View GitHub Profile
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
<activity android:launchMode="singleInstance"/>
<activity android:launchMode="singleTask"/>
<activity android:launchMode="singleTop"/>
<activity android:launchMode="standard"/>
package `in`.gsrathoreniks.validationdemo
import androidx.appcompat.widget.AppCompatEditText
import java.util.regex.Pattern
object ValidationUtil {
fun isValidUsername(view: AppCompatEditText, username: String?, regex: String = "^[a-zA-Z0-9._-]{3,20}$"): Boolean {
view.requestFocus()
when {
package `in`.gsrathoreniks.validationdemo
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputEditText
class MainActivity : AppCompatActivity() {
@gsrathoreniks
gsrathoreniks / FragmentProfile.kt
Created October 28, 2020 10:29
Sample code for VIEW BINDING in Fragments
private var _binding: FragmentProfileBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
@gsrathoreniks
gsrathoreniks / ProfileActivity.kt
Created October 28, 2020 10:23
ProfileActivity.kt for ViewBinding blog
private lateinit var binding: ActivityProfileBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//initializing binding
binding = ActivityProfileBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
}
@gsrathoreniks
gsrathoreniks / activity_profile.xml
Created October 28, 2020 10:16
A basic layout file
<LinearLayout ... >
<ImageView android:cropToPadding="true" />
<TextView android:id="@+id/tvName" />
<Button android:id="@+id/nextBtn"
android:background="@drawable/rounded_button" />
</LinearLayout>