Skip to content

Instantly share code, notes, and snippets.

View prasannajeet's full-sized avatar
💭
I may be slow to respond.

Prasan prasannajeet

💭
I may be slow to respond.
  • Toronto, Ontario, Canada
View GitHub Profile
@prasannajeet
prasannajeet / hilt-app-dependencies.gradle
Last active July 26, 2020 01:56
Adding Hilt to Android
apply plugin: 'dagger.hilt.android.plugin'
// Since these are alpha dependencies and subject to change they will remain outside of the
// dependencies.gradle script till they reach 1.0.0
implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02'
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'
apply plugin: 'dagger.hilt.android.plugin'
// Since these are alpha dependencies and subject to change they will remain outside of the
// dependencies.gradle script till they reach 1.0.0
implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02'
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'
@prasannajeet
prasannajeet / dependencies.gradle
Created July 17, 2020 14:07
Dependency file containing all commonly used dependencies along with their latest versions as of 17 June 2020
ext {
androidXCore="1.3.0"
androidXAppcompat="1.1.0"
constraintLayout="1.1.3"
kotlinVersion="1.3.72"
moshiVersion="1.8.0"
retrofit2_version = "2.9.0"
okhttp3_version = "3.12.0"
kotlinCoroutineVersion = "1.3.5"
public class RecaptchaVerifyResponse {
private boolean success;
private String challenge_ts;
private String apk_package_name;
@SerializedName("error-codes")
private List<String> errorCodes;
public boolean isSuccess() {
return success;
public class RecaptchaRepository {
public LiveData<RecaptchaVerifyResponse> doRecaptchaValidation(@NonNull String baseUrl, @NonNull String response, @NonNull String key) {
final MutableLiveData<RecaptchaVerifyResponse> data = new MutableLiveData<>();
Map<String, String> params = new HashMap<>();
params.put("response", response);
params.put("secret", key);
getRecaptchaValidationService(baseUrl).verifyResponse(params).enqueue(new Callback<RecaptchaVerifyResponse>() {
@Override
public interface RecaptchaVerificationService {
@Headers("Content-Type: application/x-www-form-urlencoded; charset=utf-8")
@POST("/recaptcha/api/siteverify")
Call<RecaptchaVerifyResponse> verifyResponse(@QueryMap Map<String, String> params);
}
public class SuccessListener implements OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse> {
@Override
public void onSuccess(final SafetyNetApi.RecaptchaTokenResponse recaptchaTokenResponse) {
String userResponseToken = recaptchaTokenResponse.getTokenResult();
if (!userResponseToken.isEmpty()) {
RecaptchaResponseViewModel mViewModel = ViewModelProviders.of(MainActivity.this).get(RecaptchaResponseViewModel.class);
mViewModel.getmRecaptchaObservable("https://www.google.com", userResponseToken, **SECRET KEY GOES HERE**).observe(MainActivity.this, new Observer<RecaptchaVerifyResponse>() {
public class FailureListener implements OnFailureListener {
@Override
public void onFailure(@NonNull Exception e) {
// Handle failure scenario
}
}
package com.praszapps.mysamplenavapp
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_destination.*
package com.praszapps.mysamplenavapp
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.fragment_main.*