Skip to content

Instantly share code, notes, and snippets.

View wajahatkarim3's full-sized avatar
:octocat:
Subscribe to my newsletter: remotekaro.substack.com

Wajahat Karim wajahatkarim3

:octocat:
Subscribe to my newsletter: remotekaro.substack.com
View GitHub Profile
@wajahatkarim3
wajahatkarim3 / TimerSplashActivity.kt
Created December 25, 2019 12:21
Splash screen with Timer
package com.wajahatkarim.splashscreen
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.cancel
import java.util.*
import kotlin.concurrent.schedule
class TimerSplashActivity : AppCompatActivity() {
@wajahatkarim3
wajahatkarim3 / CoroutinesSplashActivity.kt
Created December 25, 2019 13:05
Splash screen with Kotlin Coroutines
package com.wajahatkarim.splashscreen
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.*
class CoroutinesSplashActivity : AppCompatActivity() {
val activityScope = CoroutineScope(Dispatchers.Main)
@wajahatkarim3
wajahatkarim3 / build.gradle
Created January 5, 2020 21:20
Adding Navigation Components in Android app
def nav_version = "2.1.0"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
// For BottomNavigationView from Material Components
implementation 'com.google.android.material:material:1.0.0'
@wajahatkarim3
wajahatkarim3 / activity_main.xml
Created January 5, 2020 21:27
The layout of main bottom navigation activity for navigation components
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
@wajahatkarim3
wajahatkarim3 / activity_main.xml
Created January 5, 2020 21:58
NavHostFragment element
<fragment
android:id="@+id/fragNavHost"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/bottom_nav_graph" />
@wajahatkarim3
wajahatkarim3 / bottom_nav_graph.xml
Created January 12, 2020 20:28
Empty Bottom Nav Graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/bottom_nav_graph.xml">
</navigation>
@wajahatkarim3
wajahatkarim3 / bottom_nav_graph.xml
Created January 12, 2020 20:58
The navigation with bottom 4 screens
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottom_nav_graph.xml"
app:startDestination="@id/homeFragment2">
<fragment
android:id="@+id/homeFragment2"
android:name="com.wajahatkarim3.bottomnavigationdemo.HomeFragment"
fun setupViews()
{
// Finding the Navigation Controller
var navController = findNavController(R.id.fragNavHost)
// Setting Navigation Controller with the BottomNavigationView
bottomNavView.setupWithNavController(navController)
}
fun setupViews()
{
// Finding the Navigation Controller
var navController = findNavController(R.id.fragNavHost)
// Setting Navigation Controller with the BottomNavigationView
bottomNavView.setupWithNavController(navController)
// Setting Up ActionBar with Navigation Controller
setupActionBarWithNavController(navController)
fun setupViews()
{
// Finding the Navigation Controller
var navController = findNavController(R.id.fragNavHost)
// Setting Navigation Controller with the BottomNavigationView
bottomNavView.setupWithNavController(navController)
// Setting Up ActionBar with Navigation Controller
// Pass the IDs of top-level destinations in AppBarConfiguration