Lucas Goldner
Lucas Goldner

Reputation: 720

FireStoreRecyclerAdapter only showing results after something appearing before it?

This is going to be a longer post: So I have a Fragment "Feed" where all my posts are listed with a FireStoreRecyclerAdapter and this is working fine. Every post has a comments button where when I click on it it starts a new activity called "onClickPostActivity" where the post gets loaded again but in a bigger view with the ability to comment on it with the commentbar on the bottom of the screen. Below the post all comments should be listed then and if the user posts something it should immeadietly update and show the new comment under the post. Everything works fine the only problem here is the loading from the commments

This is the problem:

first picture

Picture number one shows the picture when the clickPostactivity is loaded you see the comments for some reason are not showing

second picture

So after pressing on the keyboard it apparently shows the posts ?

Third picture

After hiding the keyboard again it shows the comments as it is supposed to be from the start

When I leave the post with the back button and go again to the post the process repeats ?

Here is the relevant code for the clickPostActivity:



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_click_post );
        setUpRecyclerView();
}


    private void setUpRecyclerView() {
        Query query = commentsRef.orderBy("time", Query.Direction.DESCENDING);
        FirestoreRecyclerOptions<Comments> options = new FirestoreRecyclerOptions.Builder<Comments>().setQuery(query, Comments.class).build();
        adapter = new CommentsAdapter(options);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(clickPostActivity.this));
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        adapter.startListening();
    }

    @Override
    protected void onStop() {
        super.onStop();
        adapter.stopListening();
    }


And if it is the fault of the xml layout file for some weird reason here:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    tools:context=".clickPostActivity">

    <include
        android:id="@+id/toolbar"
        layout="@menu/toolbar"/>

    <include
        android:id="@+id/commentbar"
        layout="@menu/commentbar" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_marginTop="50dp">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/og_profileImage"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@drawable/ic_action_profile"
            android:scaleType="centerCrop"
            android:layout_marginLeft="4dp">
        </de.hdodenhof.circleimageview.CircleImageView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/og_userName"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:fontFamily="@font/abel"
                    android:maxLines="1"
                    android:text="username"
                    android:textAlignment="textStart"
                    android:textColor="@android:color/white"
                    android:textSize="16dp"
                    android:textStyle="bold"
                    android:layout_width="330dp" />

                <ImageButton
                    android:id="@+id/og_postOptions"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_action_options"></ImageButton>

            </LinearLayout>

            <TextView
                android:id="@+id/og_uploadTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="posted at 23:11 on Semptember 11th 2020"
                android:textSize="13dp"
                android:textColor="@android:color/white"></TextView>

        </LinearLayout>

    </LinearLayout>

        <TextView
            android:id="@+id/og_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Post description"
            android:layout_marginLeft="3dp"
            android:layout_marginRight="3dp"
            android:padding="3dp"
            android:textSize="14dp"
            android:textColor="@android:color/white" />

        <ImageView
            android:id="@+id/og_image"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_margin="3dp"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/og_commentList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></androidx.recyclerview.widget.RecyclerView>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/comment_delete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="60dp"
        android:background="#9A39B54A"
        android:orientation="vertical">

        <TextView
            android:id="@+id/post_delete_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/abel"
            android:text="Delete Post"
            android:textColor="@android:color/white"
            android:textSize="20dp"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <Button
                android:id="@+id/comment_delete_confirm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@color/colorPrimary"
                android:fontFamily="@font/abel"
                android:text="Confirm"
                android:textColor="@android:color/white" />

            <Button
                android:id="@+id/comment_delete_cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@color/colorPrimary"
                android:fontFamily="@font/abel"
                android:text="Cancel"
                android:textColor="@android:color/white" />
        </LinearLayout>


    </LinearLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Upvotes: 1

Views: 107

Answers (1)

Malik Ibrahim
Malik Ibrahim

Reputation: 26

I was facing the same problem and solved it by removing this part (It's in your clickPostActivity) :

recyclerView.setHasFixedSize(true);

Upvotes: 1

Related Questions