Мой PostImage не отображается в recycleview мой текст и изображение профиля отражается от базы данных Firebase положить Постимаж не отражает - PullRequest
0 голосов
/ 19 октября 2019

PostImage не отображается из базы данных Firebase в RicklerView.PostImage отображается в базе данных FireBase, но не в RecycleView View. 3 текстовых поля и 1 CircleImageView отображаются в программе повторного просмотра.

Нет ошибки синхронизации и build.no ошибки при установке, нет сбоя приложения.

Основная активность

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;

import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import java.util.Objects;

import de.hdodenhof.circleimageview.CircleImageView;
import swiftstartechnology.co.prasa.Posts;
import swiftstartechnology.co.prasa.R;

public class MediaActivity extends AppCompatActivity {


    private NavigationView navigationView;
    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle actionBarDrawerToggle;
    private RecyclerView postList;
    private Toolbar mToolbar;

    private CircleImageView NavProfileImage;
    private TextView NavProfileUserName;
    private ImageButton AddNewPostButton;

    private FirebaseAuth mAuth;
    private DatabaseReference UsersRef;
    private DatabaseReference PostsRef;

    String currentUserID;


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


        mAuth = FirebaseAuth.getInstance ();
        currentUserID = mAuth.getCurrentUser ().getUid ();
        UsersRef = FirebaseDatabase.getInstance ().getReference ().child ("Users");
        PostsRef = FirebaseDatabase.getInstance ().getReference ().child ("Posts");
        AddNewPostButton = (ImageButton) findViewById (R.id.add_new_post_button);



        mToolbar = (Toolbar) findViewById (R.id.media_page_toolbar);
        setSupportActionBar (mToolbar);
        getSupportActionBar ().setTitle ("Home");

        AddNewPostButton = (ImageButton) findViewById (R.id.add_new_post_button);



        drawerLayout = (DrawerLayout) findViewById (R.id.drawable_layout);
        actionBarDrawerToggle = new ActionBarDrawerToggle (MediaActivity.this, drawerLayout, R.string.drawer_open, R.string.drawer_close);
        drawerLayout.addDrawerListener (actionBarDrawerToggle);
        actionBarDrawerToggle.syncState ();
        getSupportActionBar ().setDisplayHomeAsUpEnabled (true);
        navigationView = (NavigationView) findViewById (R.id.navigation_view);

        postList = (RecyclerView) findViewById (R.id.all_users_post_list);
        postList.setHasFixedSize (true);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager (this);
        linearLayoutManager.setReverseLayout (true);
        linearLayoutManager.setStackFromEnd (true);
        postList.setLayoutManager (linearLayoutManager);

        View navView = navigationView.inflateHeaderView (R.layout.navigation_header);
        NavProfileImage = (CircleImageView) navView.findViewById (R.id.nav_profile_image);
        NavProfileUserName = (TextView) navView.findViewById (R.id.nav_user_full_name);

        UsersRef.child (currentUserID).addValueEventListener (new ValueEventListener () {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                if (dataSnapshot.exists ()) {
                    if (dataSnapshot.hasChild ("fullname")) {
                        String fullname = dataSnapshot.child ("fullname").getValue ().toString ();
                        NavProfileUserName.setText (fullname);
                    }
                    if (dataSnapshot.hasChild ("profileimage")) {
                        String image = dataSnapshot.child ("profileimage").getValue ().toString ();
                        Picasso.get ().load (image).placeholder (R.drawable.profilenew).into (NavProfileImage);
                    } else {
                        Toast.makeText (MediaActivity.this, "Profile name do not exists...", Toast.LENGTH_SHORT).show ();
                    }
        }
    }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });

        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item)
            {
                UserMenuSelector(item);
                return false;
            }
        });
        AddNewPostButton.setOnClickListener (new View.OnClickListener () {
            @Override
            public void onClick(View v) {

                SendUserToPostActivity ();
            }
        });

        DisplayAllUsersPosts();
    }

    private void DisplayAllUsersPosts() {

        FirebaseRecyclerOptions<Posts> options=new FirebaseRecyclerOptions.Builder<Posts>().setQuery(PostsRef,Posts.class).build();
        FirebaseRecyclerAdapter<Posts, PostsViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<Posts, PostsViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull PostsViewHolder holder, int position, @NonNull Posts model) {
                holder.username.setText(model.getFullname());
                holder.time.setText(" " +model.getTime());
                holder.date.setText(" "+model.getDate());
                holder.description.setText(model.getDescription());
                Picasso.get().load(model.getProfileimage()).into(holder.user_profile_image);
                Picasso.get().load(model.getPostimage()).into(holder.postImage);



            }

            @NonNull
            @Override
            public PostsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.all_posts_layout,parent,false);
                PostsViewHolder viewHolder=new PostsViewHolder(view);
                return viewHolder;
            }
        };
        postList.setAdapter(firebaseRecyclerAdapter);
        firebaseRecyclerAdapter.startListening();
    }
    public static class PostsViewHolder extends RecyclerView.ViewHolder{
        ImageView postImage;
        TextView username,date,time,description;
        CircleImageView user_profile_image;
        public PostsViewHolder(View itemView) {
            super(itemView);

            username=itemView.findViewById(R.id.post_user_name);
            date=itemView.findViewById(R.id.post_date);
            time=itemView.findViewById(R.id.post_time);
            description=itemView.findViewById(R.id.post_description);
            postImage=itemView.findViewById(R.id.post_image);
            user_profile_image=itemView.findViewById(R.id.post_User_image);
        }
    }


    private void SendUserToPostActivity()
    {
        Intent addNewPostIntent = new Intent(MediaActivity.this, PostActivity.class);
        startActivity(addNewPostIntent);
    }


    @Override
    protected void onStart() {
        super.onStart();

        FirebaseUser currentUser = mAuth.getCurrentUser();
        UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");

        if(currentUser == null)
        {
            SendUserToLoginActivity();
        }
        else
        {
            CheckUserExistence();
        }

    }

    private void CheckUserExistence() {
        final String current_user_id = mAuth.getCurrentUser().getUid();

        UsersRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                if(!dataSnapshot.hasChild(current_user_id))
                {
                    SendUserToSetupActivity();
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });


    }

    private void SendUserToSetupActivity() {

        Intent setupIntent = new Intent(MediaActivity.this, SetupActivity.class);
        setupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(setupIntent);
        finish();
    }

    private void SendUserToLoginActivity()
    {
        Intent loginIntent = new Intent(MediaActivity.this, LoginActivity.class);
        loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(loginIntent);
        finish();
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void UserMenuSelector(MenuItem item)
    {
        switch (item.getItemId())
        {
            case R.id.nav_post:
                SendUserToPostActivity();
                break;

            case R.id.nav_profile:
                Toast.makeText(this, "Profile", Toast.LENGTH_SHORT).show();
                break;

            case R.id.nav_home:
                Toast.makeText(this, "Home", Toast.LENGTH_SHORT).show();
                break;

            case R.id.nav_friends:
                Toast.makeText(this, "Friend List", Toast.LENGTH_SHORT).show();
                break;

            case R.id.nav_find_friends:
                Toast.makeText(this, "Find Friends", Toast.LENGTH_SHORT).show();
                break;

            case R.id.nav_messages:
                Toast.makeText(this, "Messages", Toast.LENGTH_SHORT).show();
                break;

            case R.id.nav_settings:
                Toast.makeText(this, "Settings", Toast.LENGTH_SHORT).show();
                break;

            case R.id.nav_Logout:
                mAuth.signOut();
                SendUserToLoginActivity();
                break;
        }
    }
}

без сообщения об ошибке. Мне просто нужно, чтобы изображение отображалось в программе повторного просмотра, когда отображается изображение профиля и другой текст.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...