Coder Social home page Coder Social logo

saifkhichi96 / android-database Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 27 KB

A reusable Android module for local and remote database management.

Home Page: https://saifkhichi.com/android-database/

Kotlin 100.00%
android android-database api

android-database's Introduction

layout title permalink code
project
Android Database
/
saifkhichi96/android-database

Android Database

This package provides an extensible interface for creating and managing databases in Android apps. This includes both local and remote databases.

By default, the package provides implementation for a Firebase Realtime Database, and a local SharedPreferences-based database. More database implementations can be added by extending the LocalDatabase and RemoteDatabase classes.

Installation

The compiled package is only available internally via GitHubPackages at the moment, and can be added to your project dependencies (only if you have internal access) as follows:

dependencies {
    implementation 'io.github.saifkhichi96:android-database:1.0.0'
}

In the future, the package would be made publicly available via Maven Central.

For now, please clone the repository as a submodule of your project as follows:

git submodule add https://github.com/saifkhichi96/android-database database

This will import the package as a local module in your project.

Then add the following to your build.gradle file:

dependencies {
    implementation project(path: ':database')
}

Usage

The package can be used with Hilt to automatically inject the database dependencies where required. To achieve this, create the following singleton class in your app:

@Module
@InstallIn(ViewModelComponent::class) // ApplicationComponent::class, FragmentComponent::class, etc.
object DatabaseModule {
    @Provides
    fun provideLocalDatabase(context: Context): LocalDatabase {
        return PrefsDatabase(context)  // return the implementation you want to use
    }

    @Provides
    fun provideRemoteDatabase(context: Context): RemoteDatabase {
        return FirebaseDatabase(context)  // return the implementation you want to use
    }
}

Then in your ViewModel, for example, use the @Inject annotation to inject the database dependencies:

@Inject
lateinit var localDatabase: LocalDatabase

@Inject
lateinit var remoteDatabase: RemoteDatabase

It is also possible to use the package without Hilt, in which case you can simply initialize the databases yourself where required.

To get started with the package, see the LocalDatabase and RemoteDatabase classes, or read the API documentation.

android-database's People

Contributors

saifkhichi96 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.