Skip to content

Update database access modifiers #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* This class implements an array-like collection on top of a Firebase location.
*/
class FirebaseArray implements ChildEventListener {
Copy link
Collaborator Author

@SUPERCILEX SUPERCILEX Sep 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed everything below to be no modifier since the class itself shouldn't be accessed from anywhere outside of the package, I don't see why the methods inside shouldn't follow along.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of SOLID programming, shouldn't at least the class itself be at least public for it to be open to extension? Building another adapter as an add-on to FirebaseUI using FirebaseArray wouldn't be possible with this configuration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think about that. Thanks! I'll update this PR when I get home.

public interface OnChangedListener {
interface OnChangedListener {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should definitely be changed, I don't know why it's not at least protected.

enum EventType { Added, Changed, Removed, Moved }
void onChanged(EventType type, int index, int oldIndex);
void onCancelled(DatabaseError databaseError);
Expand All @@ -35,21 +35,21 @@ enum EventType { Added, Changed, Removed, Moved }
private OnChangedListener mListener;
private ArrayList<DataSnapshot> mSnapshots;

public FirebaseArray(Query ref) {
FirebaseArray(Query ref) {
mQuery = ref;
mSnapshots = new ArrayList<DataSnapshot>();
mQuery.addChildEventListener(this);
}

public void cleanup() {
void cleanup() {
mQuery.removeEventListener(this);
}

public int getCount() {
int getCount() {
return mSnapshots.size();

}
public DataSnapshot getItem(int index) {
DataSnapshot getItem(int index) {
return mSnapshots.get(index);
}

Expand Down Expand Up @@ -100,21 +100,21 @@ public void onCancelled(DatabaseError databaseError) {
}
// End of ChildEventListener methods

public void setOnChangedListener(OnChangedListener listener) {
void setOnChangedListener(OnChangedListener listener) {
mListener = listener;
}

protected void notifyChangedListeners(OnChangedListener.EventType type, int index) {
void notifyChangedListeners(OnChangedListener.EventType type, int index) {
notifyChangedListeners(type, index, -1);
}

protected void notifyChangedListeners(OnChangedListener.EventType type, int index, int oldIndex) {
void notifyChangedListeners(OnChangedListener.EventType type, int index, int oldIndex) {
if (mListener != null) {
mListener.onChanged(type, index, oldIndex);
}
}

protected void notifyCancelledListeners(DatabaseError databaseError) {
void notifyCancelledListeners(DatabaseError databaseError) {
if (mListener != null) {
mListener.onCancelled(databaseError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
*/
public abstract class FirebaseListAdapter<T> extends BaseAdapter {

private Activity mActivity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had some cases in the past where I wanted to use the activity and layout in my concrete implementation. I'm not sure if these still apply, but would prefer to keep these protected for now.

private final Class<T> mModelClass;
protected int mLayout;
protected Activity mActivity;
FirebaseArray mSnapshots;
private int mLayout;
private FirebaseArray mSnapshots;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
*/
public abstract class FirebaseRecyclerAdapter<T, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

Class<T> mModelClass;
protected int mModelLayout;
Class<VH> mViewHolderClass;
FirebaseArray mSnapshots;
private Class<T> mModelClass;
private int mModelLayout;
private Class<VH> mViewHolderClass;
private FirebaseArray mSnapshots;

/**
* @param modelClass Firebase will marshall the data at a location into an instance of a class that you provide
Expand Down