Skip to content

Instantly share code, notes, and snippets.

View vamjakuldip's full-sized avatar

vamjakuldip

  • Rajkot,Gujrat,India
View GitHub Profile
@vamjakuldip
vamjakuldip / OnSingleClickListener.kt
Created October 30, 2021 08:22
This class is used to prevent twice function issue on click event
class OnSingleClickListener(private val clickListener: View.OnClickListener, private val intervalMs: Long = 1000L) : View.OnClickListener {
private var canClick = AtomicBoolean(true)
override fun onClick(v: View?) {
if (canClick.getAndSet(false)) {
v?.run {
postDelayed({
canClick.set(true)
}, intervalMs)
clickListener.onClick(v)
@vamjakuldip
vamjakuldip / ThemeHelper.kt
Created October 30, 2021 08:18
Used this theme helper to change app then between light and drak manually.
object ThemeHelper {
const val LIGHT_MODE = "light"
const val DARK_MODE = "dark"
const val DEFAULT_MODE = "default"
fun applyTheme(theme: String) {
when (theme) {
LIGHT_MODE -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
DARK_MODE -> {
@vamjakuldip
vamjakuldip / debug over wifi.txt
Created October 8, 2020 03:31
Follow below commant to connect your device over wifi.
1) Write the below command to restart adb in tcpip mode:
$ adb tcpip 5555
2) Find out the IP address of the Android device:
Go to phone Settings -> About phone/tablet -> Status -> IP address
3) Step 5 Connect device to Computer:
@vamjakuldip
vamjakuldip / mongodb commands
Last active September 26, 2020 10:44
mongodb create databse, create admin user, create database user, create database url
// After install mongo db.
// commmand to start mongodb service
mongo
// go to admin databse
use admin
// Create the root user
db.createUser({user:"admin", pwd:"password", roles:[{role:"root", db:"admin"}]})
@vamjakuldip
vamjakuldip / Utils.kt
Created July 1, 2020 14:36
- get location fro geo Uri.
private fun parseGeoIntent(uri: Uri): Location? {
var schemeSpecific: String = uri.schemeSpecificPart ?: ""
if (uri.schemeSpecificPart.contains("%2B")) {
schemeSpecific = schemeSpecific.replace("+", "%2B")
}
var name: String? = null
val namePattern: Pattern = Pattern.compile("[\\+\\s]*\\((.*)\\)[\\+\\s]*$")
val nameMatcher: Matcher = namePattern.matcher(schemeSpecific)
@vamjakuldip
vamjakuldip / websocket_Config.kt
Created May 30, 2020 09:44
RxWebsocket used for connect to websocket, its used retrofit libraby to connect websocket and handle try connection of websocket.
package com.websocket
import okhttp3.OkHttpClient
class Config private constructor() {
var client = OkHttpClient()
class Builder {
private val config: Config = Config()
@vamjakuldip
vamjakuldip / LocalIpAddress.java
Created May 7, 2020 08:45
Android studio get local ip address programtically
public static String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
return inetAddress.getHostAddress();
}
}
@vamjakuldip
vamjakuldip / RxUtils.kt
Created March 13, 2020 11:04
Delay Each item with specific delay.
fun <T> Observable<T>.delayEach(interval: Long, timeUnit: TimeUnit): Observable<T> = Observable.zip(this, Observable.interval(interval, timeUnit), BiFunction { item, _ -> item })
@vamjakuldip
vamjakuldip / LoadJsonFile.kt
Created March 13, 2020 08:44
this extension use for load json from file
fun Context.loadJSONFromAsserts(fileName: String): String {
return applicationContext.assets.open(fileName).bufferedReader().use { reader ->
reader.readText()
}
}
@vamjakuldip
vamjakuldip / ObservableWithDelayItem.kt
Created January 31, 2020 06:36
RxJava, Observable With Delay Item example.
Observable.fromIterable<Int>(Arrays.asList(1, 2, 3))
.zipWith(Observable.interval(200, TimeUnit.MILLISECONDS), BiFunction { item:Int, _:Long -> item })
.subscribe { integers: Int -> Log.d(TAG, "item $integers") }