This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Validator { | |
public static boolean isValidEmailAddress(String email) { | |
String emailRegex; | |
String stricterFilterString = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; | |
String laxString = ".+@.+\\.[A-Za-z]{2}[A-Za-z]*"; | |
if (true) { | |
emailRegex = stricterFilterString; | |
} else { | |
emailRegex = laxString; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v4.view.MotionEventCompat; | |
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
public class Hash { | |
public static String getHash(String txt, String hashType) { | |
try { | |
byte[] array = MessageDigest.getInstance(hashType).digest(txt.getBytes()); | |
StringBuffer sb = new StringBuffer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TimeUtils { | |
public static final long DAY = 86400000; | |
public static final long HOUR = 3600000; | |
public static final long MINUTE = 60000; | |
public static final long SECOND = 1000; | |
public static long getMinuteDifference(long startTime, long endTime) { | |
return (endTime - startTime) / MINUTE; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void convertMinuteToHour(int totalMinute, TextView textView) { | |
if (totalMinute >= 60) { | |
int hours = (int) Math.floor((double) (totalMinute / 60)); | |
totalMinute %= 60; | |
if (totalMinute == 0) { | |
textView.setText("طول بازدید: " + persianNumbers(String.valueOf(hours)) + " ساعت "); | |
return; | |
} else { | |
textView.setText("طول بازدید: " + persianNumbers(String.valueOf(hours)) + " ساعت و " + persianNumbers(String.valueOf(totalMinute)) + " دقیقه "); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final String md5(String s) { | |
String MD5 = CommonUtils.MD5_INSTANCE; | |
try { | |
MessageDigest digest = MessageDigest.getInstance(io.fabric.sdk.android.services.common.CommonUtils.MD5_INSTANCE); | |
digest.update(s.getBytes()); | |
byte[] messageDigest = digest.digest(); | |
StringBuilder hexString = new StringBuilder(); | |
for (byte aMessageDigest : messageDigest) { | |
String h = Integer.toHexString(aMessageDigest & 255); | |
while (h.length() < 2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String encode(String s, String key) { | |
if (s != null) | |
return base64Encode(xorWithKey(s.getBytes(), key.getBytes())); | |
else | |
return null; | |
} | |
public String decode(String s, String key) { | |
if (s != null) | |
return new String(xorWithKey(base64Decode(s), key.getBytes())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObservableRxList<T> { | |
protected final List<T> list; | |
protected final PublishSubject<List<T>> subject; | |
public ObservableRxList() { | |
this.list = new ArrayList<T>(); | |
this.subject = PublishSubject.create(); | |
} | |
public void add(T value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LiveDataList<T> extends LiveData<List<T>> { | |
public void addAll(List<T> items) { | |
if (getValue() != null && items != null) { | |
getValue().addAll(items); | |
setValue(getValue()); | |
} | |
} | |
public void clear() { | |
if (getValue() != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyFragment extends Fragment { | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// This callback will only be called when MyFragment is at least Started. | |
OnBackPressedCallback callback = new OnBackPressedCallback(true /* enabled by default */) { | |
@Override | |
public void handleOnBackPressed() { |