SHARE
TWEET

MADEProvider

a guest Feb 17th, 2020 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package id.reiyan.madedicoding.provider
  2.  
  3. import android.content.ContentProvider
  4. import android.content.ContentValues
  5. import android.content.UriMatcher
  6. import android.database.Cursor
  7. import android.net.Uri
  8. import id.reiyan.madedicoding.repository.MoviesRepository
  9. import org.koin.android.ext.android.inject
  10. import org.koin.core.inject
  11.  
  12. class MADEProvider : ContentProvider() {
  13.  
  14.     private val repository: MoviesRepository by inject()
  15.  
  16.     companion object {
  17.         private const val FAVORITE = 1
  18.         private const val AUTHORITY = "id.reiyan.madedicoding"
  19.         private const val TABLE_FAVORITE = "fav"
  20.         private val uriMatcher: UriMatcher = UriMatcher(UriMatcher.NO_MATCH)
  21.     }
  22.  
  23.     override fun onCreate(): Boolean {
  24.         uriMatcher.addURI(AUTHORITY, TABLE_FAVORITE, FAVORITE)
  25.         return true
  26.     }
  27.  
  28.     override fun query(
  29.         uri: Uri, projection: Array<String>?, selection: String?,
  30.         selectionArgs: Array<String>?, sortOrder: String?
  31.     ): Cursor? {
  32.         if (uriMatcher.match(uri) == FAVORITE) {
  33.             return repository.getAllFavoriteMovies(true)
  34.         }
  35.         return null
  36.     }
  37.  
  38.     override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?): Int {
  39.         return 0
  40.     }
  41.  
  42.     override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
  43.         return 0
  44.     }
  45.  
  46.     override fun getType(uri: Uri): String? {
  47.         return null
  48.     }
  49.  
  50.     override fun insert(uri: Uri, values: ContentValues?): Uri? {
  51.         return null
  52.     }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top