View Hilt.kt
@AndroidEntryPoint | |
class SettingsFragment : Fragment() { | |
private val settingsViewModel: SettingsViewModel by viewModels() | |
// ... | |
} | |
class SettingsViewModel @ViewModelInject constructor() : ViewModel() { | |
// ... | |
} |
View CustomTextView.kt
class CustomTextView : AppCompatTextView { | |
constructor(context: Context) : super(context) { | |
init(context) | |
} | |
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | |
init(context, attrs) | |
} |
View RecyclerViewOnScrollListener.java
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(); |
View FindVideosFirstFetchCallback.java
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."); |
View FindVideosNextFetchCallback.java
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) |
View SignInFieldsSubscription.java
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; | |
} |
View PasswordSubscription.java
Subscription passwordSubscription = | |
passwordChangeObservable | |
.doOnNext(new Action1<CharSequence>() { | |
@Override | |
public void call(CharSequence charSequence) { | |
hidePasswordError(); | |
} | |
}) | |
.debounce(400, TimeUnit.MILLISECONDS) | |
.filter(new Func1<CharSequence, Boolean>() { |
View EmailSubscription.java
Subscription emailSubscription = | |
emailChangeObservable | |
.doOnNext(new Action1<CharSequence>() { | |
@Override | |
public void call(CharSequence charSequence) { | |
hideEmailError(); | |
} | |
}) | |
.debounce(400, TimeUnit.MILLISECONDS) | |
.filter(new Func1<CharSequence, Boolean>() { |
View EmailUtils.kt
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 |
View RxLogging.kt
package com.getsomeheadspace.android.foundation.utils | |
// https://proandroiddev.com/briefly-about-rxjava-logging-20308b013e6d | |
import io.reactivex.* | |
import timber.log.Timber | |
inline fun <reified T> printEvent(tag: String, success: T?, error: Throwable?) = | |
when { | |
success == null && error == null -> Timber.d("$tag Complete") /* Only with Maybe */ |
NewerOlder