Skip to content

Instantly share code, notes, and snippets.

import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
val clickListener = View.OnClickListener {view ->
when (view.getId()) {
R.id.textview -> firstFun()
R.id.button -> secondFun()
}
}
fun <T> put(`object`: T, key: String) {
val jsonString = GsonBuilder().create().toJson(`object`)
preferences.edit().putString(key, jsonString).apply()
}
inline fun <reified T> get(key: String): T? {
val value = preferences.getString(key, null)
return GsonBuilder().create().fromJson(value, T::class.java)
}
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w("TAG", "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}
val token = task.result
Log.i("token",token)
})
//BaseFragment
abstract class BaseFragment<T : ViewBinding> : Fragment() {
private var _binding: T? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
fun showHidePassword(editText: EditText, imageView: ImageView, context: Context) {
if (boolPassword) {
editText.transformationMethod = HideReturnsTransformationMethod.getInstance()
imageView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_p_eye_off))
} else {
editText.transformationMethod = PasswordTransformationMethod.getInstance()
imageView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_p_eye))
}
boolPassword = !boolPassword
}
//Java
Glide.with(getApplicationContext())
.asBitmap()
.load(imgUrl) // url
.into(new CustomTarget<Bitmap>(150, 150) {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
image.setImageBitmap(resource); //imageview set bitmap
}
//Util class
import android.annotation.TargetApi
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Context.CONNECTIVITY_SERVICE
import android.content.Intent
import android.net.*
import android.os.Build
import androidx.lifecycle.LiveData
package com.astopia.app.utils
import android.content.Context
import android.util.Log
import com.google.android.gms.common.GoogleApiAvailability
object PlatformUtil {
fun getPlatformType(context: Context): PlatformType {
return when {
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C