Simple access to Firebase Realtime Database.

Related tags

App FbRemoteDb
Overview

FbRemoteDb

Simple access to Firebase Realtime Database.

Everything is inside a Bucket, there you can store your items. This is for simplifying the access to your data.

You can create a Bucket with a name, a password and a list of BucketItem. You can join a Bucket with a name, a password.

1. How to use in code

2. How to setup project

3. Limitations

4. Troubleshooting

5. Last words

6. License

How to use in code

Define a class for the content of the Buckets, which extends BucketItem and provides an empty constructor.

data class MyData(override val id: String, val secretCodes: List<String>) : BucketItem {
    constructor() : this("", emptyList())
}

Now you can get the repository and use it, e.g. in a ViewModel.

class AViewModel : ViewModel() {
    private val fbRepo by lazy {
        FbRemoteDb(MyData::class.java).apply {
            version = "1" // Optional
        }
    }

    fun createBuckets() {
        viewModelScope.launch {
            // TODO: Here do, what you need:  fbRepo. 
        }

    }
}

The signatures are like this. Everything throws a NoUidException if there is no with FirebaseAuth logged in user. Additionally, it is your responsibility to ensure that the correct user is logged in.

@Throws(NoUidException::class)
suspend fun deleteBucketForUser(name: String): Boolean

@Throws(NoUidException::class)
suspend fun fetchBucketsList(): List<Bucket<T>>

@Throws(NoUidException::class)
suspend fun fetchBucket(name: String): Bucket<T>?

@Throws(NoUidException::class)
suspend fun updateBucket(bucket: Bucket<T>): Boolean

@Throws(NoUidException::class)
suspend fun createBucket(name: String, password: String, bucketList: List<T>): Boolean

@Throws(NoUidException::class)
suspend fun joinPublicBucket(name: String, password: String): Boolean

@Throws(NoUidException::class)
suspend fun getBucketAsFlow(name: String): Flow<Bucket<T>>?

@Throws(NoUidException::class)
suspend fun getTAsFlow(name: String, id: String): Flow<T>?

How to setup project

  1. Add following to settings.gradle:
pluginManagement {
    plugins {
        id 'com.google.gms.google-services' version '4.3.10'
    }
}
dependencyResolutionManagement {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
  1. Add following to app/build.gradle:
plugins {
    id 'com.google.gms.google-services'
}
dependencies {
    implementation 'com.github.betafx:FbRemoteDb:{latest_version}'
}
  1. Register your app on https://console.firebase.google.com. Download google-services.json into project.

  2. Create a new Realtime Database on https://console.firebase.google.com. Change the rules to this:

{
  "rules": {
    ".read": "false",
    ".write": "false",
    "user": {
      ".read": "false",
      ".write": "false",
      "$user_id": {
        ".write": "$user_id === auth.uid",
        ".read": "$user_id === auth.uid"
      }
    },
    "buckets": {
      ".read": "false",
      ".write": "false",
      "$bucket": {
        ".read": "false",
        ".write": "false",
        "$version": {
          ".read": "false",
          ".write": "false",
          "$pw": {
            ".read": "auth.uid != null",
            ".write": "auth.uid != null"
          }
        }
      }
    }
  }
}

Limitations

  • Do not use this for sensitive data, seriously.
  • No login mechanism, the right user has to be logged in or nothing will work.
  • No server-side validation of data.
  • No encryption of the data stored on the Firebase-Server. Data in database is visible for you. Implement your custom encryption and store the key on the device.
  • Do not edit the database online on https://console.firebase.google.com, I don't know what will happen. Maybe your app will crash.

Troubleshooting

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.app.myapplication. Make sure to call FirebaseApp.initializeApp(Context) first.

You forgot to add id 'com.google.gms.google-services' in app/build.gradle.

Execution failed for task ':app:processDebugGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot function without it.

See step 3 in "How to setup project"

Last words

I was annoyed to move the same code over again, when using it in my own projects, so I decided to move it here. I am happy if you contribute, fork, clone or whatever to this repo, also opening issues is really appreciated. Feel free to contact my and happy coding :)

License

Copyright 2021 betafx

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You might also like...
Android app built with MVP architectural approach and uses Marvel Comics API that allows developers everywhere to access information about Marvel's vast library of comics. :zap:
Android app built with MVP architectural approach and uses Marvel Comics API that allows developers everywhere to access information about Marvel's vast library of comics. :zap:

Villains & Heroes Android app built with MVP architectural approach and uses Marvel Comics API that allows developers everywhere to access information

NativeScript empowers you to access native platform APIs from JavaScript directly. Angular, Capacitor, Ionic, React, Svelte, Vue and you name it compatible.
NativeScript empowers you to access native platform APIs from JavaScript directly. Angular, Capacitor, Ionic, React, Svelte, Vue and you name it compatible.

NativeScript empowers you to access native APIs from JavaScript directly. The framework currently provides iOS and Android runtimes for rich mobile de

Aplikasi-Kuliner-Jowo - Beta Access Aplikasi Kuliner Jowo (v1.1.0 BETA 1)
Aplikasi-Kuliner-Jowo - Beta Access Aplikasi Kuliner Jowo (v1.1.0 BETA 1)

Kuliner-Jowo Kuliner Jowo merupakan aplikasi resep masakan khas jawa yang dapat

A liteweight Android application to access your hanger!
A liteweight Android application to access your hanger!

星河避难所 这是一个星际公民 Android 客户端,可以简化部分官网操作以及信息查询。 A Star Citizen Android Application. 实现功能 官网登录相关 免代理登录/注册 多账号一键切换 光谱账号一键切换 官网信息相关 玩家个人信息显示 官网玩家查询 舰船信息查询 玩

MEGA Android Client - A fully-featured client to access your Cloud Storage provided by MEGA

A fully-featured client to access your Cloud Storage provided by MEGA. This document will guide you to build the application on a Linux machine with Android Studio.

an android app to send private secret SMS while terrorist Islamic republic of Iran banned internet access in Iran.

Mahsa An android application which is designed to deliver safe and encrypted messages using SMS while Islamic republic of Iran banned Iranian people a

 A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library.
A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library.

Expo Music Picker A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library. Supp

This is a Interview application which made by me in interview task what it do? that will give you the result from Api and also save data in the cache using RoomDb so that we can access it offline.
This is a Interview application which made by me in interview task what it do? that will give you the result from Api and also save data in the cache using RoomDb so that we can access it offline.

Clean-MVVM-App An Android application built using Clean + MVVM architecture. Components used in the app. Kotlin - As a programming language. Material

An easy way to create and access JSON Files!
An easy way to create and access JSON Files!

JsonFile This is the JsonFile API, this class is meant to facilitate the process of creating and accessing a JSON file UPDATES Updates Version About C

Comments
  • Change using of  classname as identifier

    Change using of classname as identifier

    The trick for linking butcketItems agains classes will not work with obfuscation, needs to be changed. See String.hashed()-extension: clazz.canonicalName?.filter { it.isLetter() }

    opened by betafx 1
Owner
null
Note taking application using Kotlin and Firebase Realtime Database.

Notes-Firebase-Kotlin Note taking application using Kotlin and Firebase Realtime Database. Features:- 1.Signup With Google 2.Create Note 3.Update Note

Shivam Kumar 4 Nov 9, 2022
The application uses Firebase Authentication and Realtime Database services

This is a Chik-Chika. Chick-Chicka is android app, which is based on popular social network - Twitter. The application uses Firebase Authentication and Realtime Database services.

Natro 9 Nov 6, 2022
Firebase Authentication and realtime database implementation in Android Kotlin

Androidfirebaseauthentication Firebase is Google’s mobile platform that helps you develop high-quality apps and provides hosted backend services such

Samwel Nyandoro 1 Mar 21, 2022
To learn how to build an e-commerce app for Android using the Firestore database from Google Firebase Technology

It is an adjustable e-commerce application that you can use to create your own online store or use it as a template to create an e-commerce app for your client. In this app we are covering such topics as Firebase basics how to upload and download data to and from an online database Displaying Images from the Cloud Creating User Profiles Uploading and displaying Products Building a Cart System Selecting images from your phone

Makaota 2 Jun 25, 2022
Retracer is a high performance, and near realtime REST API which used for Java/Android stack trace retracing by R8

Retracer is a high performance, and near realtime REST API which used for Java/Android stack trace retracing by R8 Getting Started docker

Johnson Lee 3 Aug 21, 2022
Realtime SOS Android Application. Location (GPS + Cellular Network) tracing application by alerting guardians of the User.

WomenSaftey Women Safety Android Application: Realtime SOS Android Application. Designed a Location (GPS + Cellular Network) tracing application by al

jatin kasera 6 Nov 19, 2022
This app to track realtime location

✨ hacktoberfest2021 ?? ?? Contributing to hacktoberfest 2021 Welcome to hacktoberfest 2021 Public Repository. ????‍?? A month-long celebration from Oc

aldhykohar 1 Nov 16, 2021
NetGuard provides simple and advanced ways to block access to the internet

NetGuard NetGuard provides simple and advanced ways to block access to the internet - no root required. Applications and addresses can individually be

Marcel Bokhorst 598 Dec 31, 2022
android-delicious Delicious Android is an Android app which helps you access and save bookmarks via Delicious. It's available over at Google Play.

Delicious Android Delicious Android is an Android app which helps you access and save bookmarks via Delicious. It's available over at Google Play. Fea

Alexander Blom 137 Nov 20, 2022