Skip to content

Instantly share code, notes, and snippets.

override suspend fun getVideos(): List<Video> = withContext(ioDispatcher) {
val videos = mutableListOf<Video>()
val uri: Uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
// Display videos in alphabetical order based on their display name.
val sortOrder = "${MediaStore.Video.Media.DISPLAY_NAME} ASC"
val cursor: Cursor? = contentResolver.query(uri, null, null, null, sortOrder)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:gravity="bottom"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
package com.unravelled.sm.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.unravelled.sm.data.model.item.ItemDao
class ItemListViewModelFactory(
private val dataSource: ItemDao
) : ViewModelProvider.Factory {
@Suppress("unchecked_cast")
package com.unravelled.sm.viewmodel
import androidx.lifecycle.*
import com.unravelled.sm.data.model.item.ItemDao
import com.unravelled.sm.data.model.item.ItemRepository
import com.unravelled.sm.domain.model.Item
class ItemListViewModel(
dataSource: ItemDao) :ViewModel() {
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/menu_home" />
<item
android:id="@+id/nav_about"
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
package com.unravelled.sm
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
@Varsha-Kulkarni
Varsha-Kulkarni / content_main.xml
Created June 6, 2020 07:49
Nav Host Fragment
<?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.unravelled.sm.MainActivity"
tools:showIn="@layout/activity_main">
@Varsha-Kulkarni
Varsha-Kulkarni / navigation.xml
Last active June 23, 2020 04:25
Navigation 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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation"
app:startDestination="@+id/nav_home">
<fragment
android:id="@+id/nav_home"
android:name="com.unravelled.sm.ui.HomeFragment"