Commit 9004fbf2 authored by MUTTINENI NAVYA's avatar MUTTINENI NAVYA

added newsfeed activity

parent cee9e24c
This diff is collapsed.
......@@ -18,8 +18,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".NewsFeedFound"></activity>
<activity android:name=".MyPostsFoundRV" />
<activity android:name=".RedirectMyPosts"/>
<activity android:name=".RedirectMyPosts" />
<activity android:name=".ItemDetails" />
<activity android:name=".MyPosts" />
<activity
......
......@@ -10,12 +10,13 @@ import androidx.drawerlayout.widget.DrawerLayout;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.navigation.NavigationView;
public class Navigation extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public class Navigation extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener {
private String username = null;
private DrawerLayout drawerLayout;
......@@ -26,6 +27,9 @@ public class Navigation extends AppCompatActivity implements NavigationView.OnNa
username = getIntent().getStringExtra("username");
findViewById(R.id.lost_button_newsfeed).setOnClickListener(this);
findViewById(R.id.found_button_newsfeed).setOnClickListener(this);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav);
......@@ -86,4 +90,28 @@ public class Navigation extends AppCompatActivity implements NavigationView.OnNa
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.lost_button_newsfeed:
Intent intent = new Intent(Navigation.this, MyPosts.class);
intent.putExtra("type", "lost");
intent.putExtra("username", username);
startActivity(intent);
break;
case R.id.found_button_newsfeed:
intent = new Intent(Navigation.this, NewsFeedFound.class);
intent.putExtra("username", username);
intent.putExtra("type", "found");
startActivity(intent);
break;
}
}
}
package com.example.instilostandfound;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.tasks.OnSuccessListener;
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.Query;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class NewsFeedFound extends AppCompatActivity implements NewsfeedAdaptor.OnItemClickListener, Serializable {
private RecyclerView mrecyclerView;
private NewsfeedAdaptor mAdaptor;
private DatabaseReference mDatabaseRef;
private FirebaseStorage mStorage;
private List<CreateFoundObject> mPosts;
private String username =null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news_feed_found);
username = getIntent().getStringExtra("username");
mrecyclerView = findViewById(R.id.my_posts_rv);
mrecyclerView.setHasFixedSize(true);
mrecyclerView.setLayoutManager(new LinearLayoutManager(this));
mPosts = new ArrayList<>();
mDatabaseRef = FirebaseDatabase.getInstance().getReference("FoundData");
mStorage = FirebaseStorage.getInstance();
//Query usernamequery = mDatabaseRef.orderByChild("ldap").equalTo((username+"@iitb.ac.in").toLowerCase());
//Log.v("query",usernamequery.toString());
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot postSnapShot : dataSnapshot.getChildren()){
CreateFoundObject post = postSnapShot.getValue(CreateFoundObject.class);
post.setKey(postSnapShot.getKey());
mPosts.add(post);
}
mAdaptor = new NewsfeedAdaptor(NewsFeedFound.this, mPosts);
mrecyclerView.setAdapter(mAdaptor);
mAdaptor.setOnItemClickListener(NewsFeedFound.this);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(NewsFeedFound.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onItemClick(int position) {
Toast.makeText(this, "Normal click at position: " + position, Toast.LENGTH_SHORT).show();
}
}
package com.example.instilostandfound;
import android.content.Context;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.squareup.picasso.Picasso;
import java.util.List;
public class NewsfeedAdaptor extends RecyclerView.Adapter<NewsfeedAdaptor.myViewHolder> {
private Context mcontext;
private List<CreateFoundObject> mUploads;
private OnItemClickListener mListener;
public NewsfeedAdaptor(Context context, List<CreateFoundObject> uploads){
mcontext = context;
mUploads=uploads;
}
@NonNull
@Override
public NewsfeedAdaptor.myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mcontext).inflate(R.layout.list_item, parent, false);
return new myViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull NewsfeedAdaptor.myViewHolder holder, int position) {
CreateFoundObject current_post = mUploads.get(position);
holder.textViewname.setText(current_post.getmTitle());
Picasso.with(mcontext).load(current_post.getImageUrl())
.fit()
.centerCrop()
.into(holder.imageView);
}
@Override
public int getItemCount() {
return mUploads.size();
}
public class myViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView textViewname;
public ImageView imageView;
public myViewHolder(@NonNull View itemView) {
super(itemView);
textViewname = itemView.findViewById(R.id.list_item_textview);
imageView = itemView.findViewById(R.id.list_item_imageview);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (mListener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
mListener.onItemClick(position);
}
}
}
}
public interface OnItemClickListener {
void onItemClick(int position);
}
public void setOnItemClickListener(OnItemClickListener listener) {
mListener = listener;
}
}
......@@ -8,8 +8,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Navigation"
tools:openDrawer="start"
android:background="@drawable/myposts_bg">
tools:openDrawer="start">
<LinearLayout
android:layout_height="match_parent"
......@@ -28,13 +27,15 @@
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:background="@drawable/lostfound">
<Button
android:id="@+id/lost_button_newsfeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="150dp"
android:layout_marginBottom="100dp"
android:layout_marginTop="400dp"
android:background="@color/colorPrimary"
android:textColor="@color/cardview_light_background"
android:text="Lost"
......@@ -46,13 +47,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="150dp"
android:layout_marginBottom="24dp"
android:text="Found"
android:layout_marginTop="450dp"
android:background="@color/colorPrimary"
android:text="Found"
android:textColor="@color/cardview_light_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</FrameLayout>
</LinearLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".NewsFeedFound">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/my_posts_rv"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment