Merge commit 'd1e3c3f5f313057e5a81a4333906ef5d79adea83' as 'Android'
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package com.majinnaibu.monstercards.utils;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ChangeTrackedLiveData<T> extends MutableLiveData<T> {
|
||||
private final OnValueChangedCallback<T> mOnValueChangedCallback;
|
||||
private final OnValueDirtiedCallback mOnValueDirtiedCallback;
|
||||
private T mReferenceValue;
|
||||
|
||||
public ChangeTrackedLiveData(T initialValue, OnValueChangedCallback<T> onValueChanged, OnValueDirtiedCallback onValueDirtied) {
|
||||
super(initialValue);
|
||||
mReferenceValue = initialValue;
|
||||
mOnValueChangedCallback = onValueChanged;
|
||||
if (mOnValueChangedCallback != null) {
|
||||
mOnValueChangedCallback.onValueChanged(initialValue);
|
||||
}
|
||||
mOnValueDirtiedCallback = onValueDirtied;
|
||||
}
|
||||
|
||||
public ChangeTrackedLiveData(T initialValue, OnValueChangedCallback<T> callback) {
|
||||
this(initialValue, callback, null);
|
||||
}
|
||||
|
||||
public ChangeTrackedLiveData(T initialValue, OnValueDirtiedCallback callback) {
|
||||
this(initialValue, null, callback);
|
||||
}
|
||||
|
||||
public void setReferenceValue(T referenceValue) {
|
||||
mReferenceValue = referenceValue;
|
||||
}
|
||||
|
||||
public void setCurrentValueAsReference() {
|
||||
mReferenceValue = getValue();
|
||||
}
|
||||
|
||||
public void resetValue(T value) {
|
||||
mReferenceValue = value;
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
if (!Objects.equals(getValue(), value)) {
|
||||
super.setValue(value);
|
||||
|
||||
if (mOnValueChangedCallback != null) {
|
||||
mOnValueChangedCallback.onValueChanged(value);
|
||||
}
|
||||
if (!Objects.equals(mReferenceValue, value) && mOnValueDirtiedCallback != null) {
|
||||
mOnValueDirtiedCallback.onValueDirtied();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnValueDirtiedCallback {
|
||||
void onValueDirtied();
|
||||
}
|
||||
|
||||
public interface OnValueChangedCallback<T> {
|
||||
void onValueChanged(T value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.majinnaibu.monstercards.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Logger {
|
||||
public static final String LOG_TAG = "MonsterCards";
|
||||
|
||||
public static void logUnimplementedMethod() {
|
||||
Exception ex = new Exception();
|
||||
StackTraceElement[] stackTrace = ex.getStackTrace();
|
||||
|
||||
String location = stackTrace[1].getClassName() + "." + stackTrace[1].getMethodName() + ":" + stackTrace[1].getLineNumber();
|
||||
logDebug("Method not yet implemented " + location);
|
||||
}
|
||||
|
||||
public static void logUnhandledError(Throwable e) {
|
||||
StackTraceElement stackTraceElement = e.getStackTrace()[0];
|
||||
|
||||
String location = stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber();
|
||||
logDebug("Exception was caught but not properly handled " + location);
|
||||
}
|
||||
|
||||
public static void logUnimplementedFeature(String featureDescription) {
|
||||
Exception ex = new Exception();
|
||||
StackTraceElement[] stackTrace = ex.getStackTrace();
|
||||
|
||||
String location = stackTrace[1].getClassName() + "." + stackTrace[1].getMethodName() + ":" + stackTrace[1].getLineNumber();
|
||||
logDebug("Feature not yet implemented " + featureDescription + " at " + location);
|
||||
}
|
||||
|
||||
//region WTF
|
||||
public static void logWTF(String message) {
|
||||
Log.wtf(LOG_TAG, message);
|
||||
}
|
||||
|
||||
public static void logWTF(Throwable throwable) {
|
||||
StackTraceElement stackTraceElement = throwable.getStackTrace()[0];
|
||||
|
||||
String location = stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber();
|
||||
String message = String.format("Unexpected error occurred at %s.", location);
|
||||
Log.wtf(LOG_TAG, message, throwable);
|
||||
}
|
||||
|
||||
public static void logWTF(String message, Throwable throwable) {
|
||||
Log.wtf(LOG_TAG, message, throwable);
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Error
|
||||
public static void logError(String message) {
|
||||
Log.e(LOG_TAG, message);
|
||||
}
|
||||
|
||||
public static void logError(Throwable throwable) {
|
||||
StackTraceElement stackTraceElement = throwable.getStackTrace()[0];
|
||||
|
||||
String location = stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber();
|
||||
String message = String.format("Unexpected error occurred at %s.", location);
|
||||
Log.e(LOG_TAG, message, throwable);
|
||||
}
|
||||
|
||||
public static void logError(String message, Throwable throwable) {
|
||||
Log.e(LOG_TAG, message, throwable);
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Warning
|
||||
public static void logWarning(String message) {
|
||||
Log.w(LOG_TAG, message);
|
||||
}
|
||||
|
||||
public static void logWarning(Throwable throwable) {
|
||||
StackTraceElement stackTraceElement = throwable.getStackTrace()[0];
|
||||
|
||||
String location = stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber();
|
||||
String message = String.format("Unexpected error occurred at %s.", location);
|
||||
Log.w(LOG_TAG, message, throwable);
|
||||
}
|
||||
|
||||
public static void logWarning(String message, Throwable throwable) {
|
||||
Log.w(LOG_TAG, message, throwable);
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Info
|
||||
public static void logInfo(String message) {
|
||||
Log.i(LOG_TAG, message);
|
||||
}
|
||||
|
||||
public static void logInfo(Throwable throwable) {
|
||||
StackTraceElement stackTraceElement = throwable.getStackTrace()[0];
|
||||
|
||||
String location = stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber();
|
||||
String message = String.format("Unexpected error occurred at %s.", location);
|
||||
Log.i(LOG_TAG, message, throwable);
|
||||
}
|
||||
|
||||
public static void logInfo(String message, Throwable throwable) {
|
||||
Log.i(LOG_TAG, message, throwable);
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Debug
|
||||
public static void logDebug(String message) {
|
||||
Log.d(LOG_TAG, message);
|
||||
}
|
||||
|
||||
public static void logDebug(Throwable throwable) {
|
||||
StackTraceElement stackTraceElement = throwable.getStackTrace()[0];
|
||||
|
||||
String location = stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber();
|
||||
String message = String.format("Unexpected error occurred at %s.", location);
|
||||
Log.d(LOG_TAG, message, throwable);
|
||||
}
|
||||
|
||||
public static void logDebug(String message, Throwable throwable) {
|
||||
Log.d(LOG_TAG, message, throwable);
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Verbose
|
||||
public static void logVerbose(String message) {
|
||||
Log.v(LOG_TAG, message);
|
||||
}
|
||||
|
||||
public static void logVerbose(Throwable throwable) {
|
||||
StackTraceElement stackTraceElement = throwable.getStackTrace()[0];
|
||||
|
||||
String location = stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber();
|
||||
String message = String.format("Unexpected error occurred at %s.", location);
|
||||
Log.v(LOG_TAG, message, throwable);
|
||||
}
|
||||
|
||||
public static void logVerbose(String message, Throwable throwable) {
|
||||
Log.v(LOG_TAG, message, throwable);
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.majinnaibu.monstercards.utils;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TextChangedListener implements TextWatcher {
|
||||
|
||||
private final BeforeTextChangedCallback mBeforeTextChangedCallback;
|
||||
private final OnTextChangedCallback mOnTextChangedCallback;
|
||||
private final AfterTextChangedCallback mAfterTextChangedCallback;
|
||||
|
||||
public TextChangedListener(BeforeTextChangedCallback beforeTextChangedCallback, OnTextChangedCallback onTextChangedCallback, AfterTextChangedCallback afterTextChangedCallback) {
|
||||
mBeforeTextChangedCallback = beforeTextChangedCallback;
|
||||
mOnTextChangedCallback = onTextChangedCallback;
|
||||
mAfterTextChangedCallback = afterTextChangedCallback;
|
||||
}
|
||||
|
||||
public TextChangedListener(OnTextChangedCallback callback) {
|
||||
this(null, callback, null);
|
||||
}
|
||||
|
||||
public TextChangedListener(BeforeTextChangedCallback callback) {
|
||||
this(callback, null, null);
|
||||
}
|
||||
|
||||
public TextChangedListener(AfterTextChangedCallback callback) {
|
||||
this(null, null, callback);
|
||||
}
|
||||
|
||||
public TextChangedListener(BeforeTextChangedCallback beforeTextChangedCallback, OnTextChangedCallback onTextChangedCallback) {
|
||||
this(beforeTextChangedCallback, onTextChangedCallback, null);
|
||||
}
|
||||
|
||||
public TextChangedListener(BeforeTextChangedCallback beforeTextChangedCallback, AfterTextChangedCallback afterTextChangedCallback) {
|
||||
this(beforeTextChangedCallback, null, afterTextChangedCallback);
|
||||
}
|
||||
|
||||
public TextChangedListener(OnTextChangedCallback onTextChangedCallback, AfterTextChangedCallback afterTextChangedCallback) {
|
||||
this(null, onTextChangedCallback, afterTextChangedCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
if (mBeforeTextChangedCallback != null) {
|
||||
mBeforeTextChangedCallback.beforeTextChanged(s, start, count, after);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (mOnTextChangedCallback != null) {
|
||||
mOnTextChangedCallback.onTextChanged(s, start, before, count);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (mAfterTextChangedCallback != null) {
|
||||
mAfterTextChangedCallback.afterTextChanged(s);
|
||||
}
|
||||
}
|
||||
|
||||
public interface BeforeTextChangedCallback {
|
||||
void beforeTextChanged(CharSequence s, int start, int count, int after);
|
||||
}
|
||||
|
||||
public interface OnTextChangedCallback {
|
||||
void onTextChanged(CharSequence s, int start, int before, int count);
|
||||
}
|
||||
|
||||
public interface AfterTextChangedCallback {
|
||||
void afterTextChanged(Editable s);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user