Skip to content

Instantly share code, notes, and snippets.

View lawloretienne's full-sized avatar
💭
Check out the surf report app I'm working on https://pitted.app

Etienne Lawlor lawloretienne

💭
Check out the surf report app I'm working on https://pitted.app
View GitHub Profile
object EmailUtils {
fun getEmailIntent(context: Context): Intent {
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"))
val bodyText = getEmailBody(context)
val emailAddy = EMAIL_SUPPORT
val subject = context.resources.getString(R.string.email_subject)
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(emailAddy))
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
intent.putExtra(Intent.EXTRA_TEXT, bodyText)
return intent
@lawloretienne
lawloretienne / EmailSubscription.java
Last active February 29, 2020 16:54
EmailChangeObservable
Subscription emailSubscription =
emailChangeObservable
.doOnNext(new Action1<CharSequence>() {
@Override
public void call(CharSequence charSequence) {
hideEmailError();
}
})
.debounce(400, TimeUnit.MILLISECONDS)
.filter(new Func1<CharSequence, Boolean>() {
@lawloretienne
lawloretienne / PasswordSubscription.java
Created February 29, 2020 17:32
PasswordChangeObservable
Subscription passwordSubscription =
passwordChangeObservable
.doOnNext(new Action1<CharSequence>() {
@Override
public void call(CharSequence charSequence) {
hidePasswordError();
}
})
.debounce(400, TimeUnit.MILLISECONDS)
.filter(new Func1<CharSequence, Boolean>() {
@lawloretienne
lawloretienne / SignInFieldsSubscription.java
Created February 29, 2020 17:34
SignInFieldsSubscription
Subscription signInFieldsSubscription =
Observable.combineLatest(emailChangeObservable, passwordChangeObservable,
new Func2<CharSequence, CharSequence, Boolean>() {
@Override
public Boolean call(CharSequence email, CharSequence password) {
boolean isEmailValid = validateEmail(email.toString());
boolean isPasswordValid = validatePassword(password.toString());
return isEmailValid && isPasswordValid;
}
@lawloretienne
lawloretienne / FindVideosNextFetchCallback.java
Created February 29, 2020 17:38
FindVideosNextFetchCallback
private Callback<VideosCollection> findVideosNextFetchCallback = new Callback<VideosCollection>() {
@Override
public void onResponse(Call<VideosCollection> call, Response<VideosCollection> response) {
videosAdapter.removeFooter();
isLoading = false;
if (!response.isSuccessful()) {
int responseCode = response.code();
switch (responseCode){
case 504: // 504 Unsatisfiable Request (only-if-cached)
@lawloretienne
lawloretienne / FindVideosFirstFetchCallback.java
Created February 29, 2020 17:39
FindVideosFirstFetchCallback
private Callback<VideosCollection> findVideosFirstFetchCallback = new Callback<VideosCollection>() {
@Override
public void onResponse(Call<VideosCollection> call, Response<VideosCollection> response) {
loadingImageView.setVisibility(View.GONE);
isLoading = false;
if (!response.isSuccessful()) {
int responseCode = response.code();
if(responseCode == 504) { // 504 Unsatisfiable Request (only-if-cached)
errorTextView.setText("Can't load data.\nCheck your network connection.");
@lawloretienne
lawloretienne / RecyclerViewOnScrollListener.java
Created February 29, 2020 17:40
RecyclerViewOnScrollListener
private RecyclerView.OnScrollListener recyclerViewOnScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = layoutManager.getChildCount();
class CustomTextView : AppCompatTextView {
constructor(context: Context) : super(context) {
init(context)
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(context, attrs)
}
@AndroidEntryPoint
class SettingsFragment : Fragment() {
private val settingsViewModel: SettingsViewModel by viewModels()
// ...
}
class SettingsViewModel @ViewModelInject constructor() : ViewModel() {
// ...
}
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.location.Location
import android.os.Looper
import androidx.core.app.ActivityCompat
import androidx.lifecycle.LiveData
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.location.*
import com.google.android.gms.maps.model.LatLng