Skip to content

Commit

Permalink
Documented code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jora committed Dec 25, 2017
1 parent 82b64b3 commit 07a9038
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* Created by jora on 11/25/17.
*/

/**
* Use to annotate classes which store {@link RespirationRepository} fields.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface RespirationModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,38 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Use it to annotate classes which extend GeneralRepository or ListRepository from respiration
* library. Also annotation can be used for fields inside a annotated with {@link RespirationModule}
* class.
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE, ElementType.FIELD})
public @interface RespirationRepository {
/**
* Use it as database reference children. If you got to use firebase userId as database reference
* path you must always reset this path on each firebase auth state change. Or you can just use
* this constant to avoid boring auth listening.
*/
String USER_ID = "user_id";

/**
* Give me firebase model class.
*/
Class<?> dataSnapshotType();

/**
* Set firebaseDatabaseRef.setPersistenceEnabled(). Can be set only one time.
*/
boolean persistence() default false;

/**
* Firebase database reference children.
*/
String[] children() default "";

/**
* Set as true if the repository can be accessed only by authenticated users.
*/
boolean isAccessPrivate() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,23 @@ public void subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> on
behaviorSubject.subscribe(tNotification -> onNext.accept(tNotification.getValue()), onError, onComplete, onSubscribe);
}

/**
* Unleash all reactive power.
*/
public Observable<Notification<T>> asObservable() {
return behaviorSubject;
}

/**
* @return true if user is authenticated to firebase.
*/
public boolean isUserAuthenticated() {
return firebaseAuth.getCurrentUser() != null;
}

/**
* @return firebase user id.
*/
public String getUserId() {
if (isUserAuthenticated()) {
return firebaseAuth.getCurrentUser().getUid();
Expand All @@ -96,6 +105,10 @@ public String getUserId() {

protected abstract void initRepository();

/**
* Reset firebase database reference children.
* @param databaseChildren new children to replace the old ones.
*/
public abstract void resetRepository(String... databaseChildren);

/**
Expand All @@ -106,6 +119,9 @@ public T getValue() {
return behaviorSubject.getValue().getValue();
}

/**
* @return {@link FirebaseAuth}
*/
public FirebaseAuth getFirebaseAuth() {
return firebaseAuth;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public void resetRepository(String... databaseChildren) {
initRepository();
}

/**
* Use this method instead of {@link super.asObservable()}
*/
public Observable<Notification<Map<String, T>>> asListObservable() {
return behaviorSubject;
}
Expand Down

0 comments on commit 07a9038

Please sign in to comment.