This file contains hidden or 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
private void createNotificationInOreo() { | |
String NOTIFICATION_CHANNEL_ID = "default"; | |
int id = (int) System.currentTimeMillis(); | |
Intent parentIntent = new Intent(this, ParentActivity.class); | |
Intent resultIntent = new Intent(this, SecondActivity.class); | |
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); | |
// Adds the back stack | |
stackBuilder.addParentStack(ParentActivity.class); |
This file contains hidden or 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
private static String uniqueID = null; | |
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID"; | |
public synchronized static String id(Context context) { | |
if (uniqueID == null) { | |
SharedPreferences sharedPrefs = context.getSharedPreferences( | |
PREF_UNIQUE_ID, Context.MODE_PRIVATE); | |
uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null); | |
if (uniqueID == null) { | |
uniqueID = UUID.randomUUID().toString(); |
This file contains hidden or 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
fun parseTime(value: String): String { | |
val dateTime = "2018-11-27 17:48:38.300" | |
val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault()) | |
try { | |
val calendar = Calendar.getInstance() | |
calendar.time = format.parse(value) | |
var hour = calendar.get(Calendar.HOUR_OF_DAY) | |
val minute = calendar.get(Calendar.MINUTE) | |
val timeString: String |
This file contains hidden or 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
private fun showDatePickerDialog() { | |
val c = Calendar.getInstance() | |
val year = c.get(Calendar.YEAR) | |
val month = c.get(Calendar.MONTH) | |
val day = c.get(Calendar.DAY_OF_MONTH) | |
getContext()?.let { it -> | |
// Create a new instance of DatePickerDialog and return it | |
val dpd = DatePickerDialog( | |
it, |
This file contains hidden or 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.xyz) | |
checkCameraPermission() | |
} | |
private fun checkCameraPermission() { | |
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) | |
!= PackageManager.PERMISSION_GRANTED) { |
This file contains hidden or 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
private fun translucentStatusBarWithFixedNavigationButtons() { | |
window.apply { | |
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) | |
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) | |
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
statusBarColor = Color.TRANSPARENT | |
} | |
} |
This file contains hidden or 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
const val APP_TAG = "Test App" | |
fun String.logVerbose(tag: String = APP_TAG) { | |
if (BuildConfig.DEBUG) | |
Log.v(tag, this) | |
} | |
fun String.logDebug(tag: String = APP_TAG) { | |
if (BuildConfig.DEBUG) | |
Log.d(tag, this) |
This file contains hidden or 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
private fun generateKeyHashFromSHA() { | |
try { | |
val info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES) | |
for (signature in info.signatures) { | |
val md = MessageDigest.getInstance("SHA") | |
md.update(signature.toByteArray()) | |
val hashKey = String(Base64.getEncoder().encode(md.digest())) | |
"key: $hashKey".logDebug(TAG) | |
Log.d(TAG, "generateSha1: $hashKey") | |
} |
This file contains hidden or 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
fun MainActivity.findDeviceModelManufacturerAndOS() { | |
val status = StringBuilder() | |
.append("\nOS Version: ${Build.VERSION.SDK_INT}") | |
.append("\nMANUFACTURER: ${Build.MANUFACTURER}") | |
.append("\nMODEL: ${Build.MODEL}") | |
"findDeviceModelManufacturerAndOS() $status".logWarn(TAG) | |
} | |
/** |
This file contains hidden or 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
enum class Status { | |
SUCCESS, | |
ERROR, | |
LOADING | |
} | |
data class APIResponse<out T>(val status: Status, val data: T?, val message: String?) { | |
companion object { | |
fun <T> success(data: T): APIResponse<T> = APIResponse( |
OlderNewer