Skip to content

Instantly share code, notes, and snippets.

View gabriel-TheCode's full-sized avatar
🏠
Working from home

Gabriel TEKOMBO gabriel-TheCode

🏠
Working from home
View GitHub Profile
@gabriel-TheCode
gabriel-TheCode / NavigationExtensions.kt
Created October 13, 2023 10:04
NavigationExtensions
private fun View.goTo(
@IdRes id: Int, bundle: Bundle? = null, navOptions: NavOptions? = null,
navigatorExtras: Navigator.Extras? = null
) {
if (mayNavigate(id)) findNavController().navigate(id, bundle, navOptions, navigatorExtras)
}
private fun Fragment.goTo(
@IdRes id: Int, bundle: Bundle? = null, navOptions: NavOptions? = null,
navigatorExtras: Navigator.Extras? = null
class NavigationManager {
fun goToMainActivity(activity: Activity) {
val intent = Intent(activity, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
activity.startActivity(intent)
}
fun popBackStack(navController: NavController) {
navController.popBackStack()
@gabriel-TheCode
gabriel-TheCode / build.gradle
Last active April 25, 2022 07:53
Using KSP
plugins {
id 'com.android.application'
id 'kotlin-android'
// id 'kotlin-kapt' not needed anymore
id "com.google.devtools.ksp" version "1.6.10-1.0.2"
}
dependencies {
...
implementation "androidx.room:room-runtime:$room_version"
@gabriel-TheCode
gabriel-TheCode / TimberExtensions.kt
Created November 8, 2021 08:48
TimberExtensions.kt
import timber.log.Timber
inline fun logDebug(message: () -> String) {
Timber.d(message())
}
inline fun logInfo(message: () -> String) {
Timber.i(message())
}
@gabriel-TheCode
gabriel-TheCode / LiveDataExtensions.kt
Created October 29, 2021 22:10
LiveDataExtensions.kt
import androidx.lifecycle.*
inline fun <T> Resource<T>.mapData(crossinline mapper: (T) -> T?): Resource<T> {
val data = this.toData() ?: return this
val processedData = mapper(data)
return when (this) {
is Resource.Progress -> Resource.loading(progression, processedData)
is Resource.Success -> Resource.success(processedData)
is Resource.Failure -> Resource.failure(this.throwable, processedData)
@gabriel-TheCode
gabriel-TheCode / ExtensionCollection.kt
Created July 7, 2021 08:21
A bunch of utilities extensions
import android.content.Context
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
@gabriel-TheCode
gabriel-TheCode / FabBottomNavigationView.kt
Created June 25, 2021 10:53
Custom FabBottomNavigationView
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Paint
import android.util.AttributeSet
import androidx.core.content.ContextCompat
import com.google.android.material.bottomappbar.BottomAppBarTopEdgeTreatment
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
@gabriel-TheCode
gabriel-TheCode / Movie.java
Created June 25, 2021 10:49
A Java Object Parcelable class
@Entity(tableName = "favorites")
public class Movie implements Parcelable {
@Ignore
private double popularity;
private int vote_count;
private boolean video;
private String poster_path;
private int id;
@Ignore
class BlogAdapter(private val listener: BlogItemListener) : RecyclerView.Adapter<BlogViewHolder>() {
interface BlogItemListener {
fun onClickedBlog(blogTitle: CharSequence)
}
private val items = ArrayList<Blog>()
private lateinit var blog: Blog
fun setItems(items: ArrayList<Blog>) {
@ExperimentalCoroutinesApi
@AndroidEntryPoint
class MainActivity : AppCompatActivity(), BlogAdapter.BlogItemListener {
private val viewModel: MainViewModel by viewModels()
private lateinit var adapter: BlogAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupRecyclerView()