Commit d1c3c607 authored by ankitasingh's avatar ankitasingh

filter activity partial changes

parent 151633ba
This diff is collapsed.
......@@ -123,7 +123,6 @@
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-v4:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.google.firebase:firebase-auth:19.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-extensions:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-maps:17.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: android.arch.navigation:navigation-fragment:1.0.0-alpha09@aar" level="project" />
<orderEntry type="library" name="Gradle: com.google.firebase:firebase-auth-interop:18.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-base:17.1.0@aar" level="project" />
......
......@@ -77,7 +77,7 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
Spinner category;
String username;
ImageView camera;
String[] items = new String[]{"Others","Electronics", "Documents", "Clothes"};
public static String[] items = new String[]{"Others","Electronics", "Documents", "Clothes","Furniture","Accessories"};
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
private static final int MY_CAMERA_PERMISSION_CODE = 100;
......@@ -144,6 +144,7 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
final String Place = place.getText().toString().trim();
final String Desc = desc.getText().toString().trim();
final String Date = date.getText().toString().trim();
final String Category = category.getSelectedItem().toString();
updatedata = false;
if (title.getText().toString().trim().isEmpty()) {
......@@ -218,11 +219,11 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
if(updatedata)
{
upload = new CreateFoundObject(username,Title ,tempUri,Place, Desc,
"category", Date,"found");
Category, Date,"found");
}
else {
upload = new CreateFoundObject(username, Title, uri.toString(), Place, Desc,
"category",Date, "found");
Category,Date, "found");
}
String uploadId = myRef.push().getKey();
Log.v("UploadID", uploadId);
......@@ -259,7 +260,7 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
Date datef = new Date();
Toast.makeText(FoundItem.this, "No file selected", Toast.LENGTH_SHORT).show();
CreateFoundObject upload = new CreateFoundObject(username,Title ,"NO-IMAGE","location", Desc,
"category", Date,"found");
Category, Date,"found");
String uploadId = myRef.push().getKey();
Log.v("UploadID", uploadId);
myRef.child(uploadId).setValue(upload);
......
package com.example.instilostandfound;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.MenuItemCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SearchView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnSuccessListener;
......@@ -27,7 +35,8 @@ import java.util.List;
public class NewsFeedFound extends AppCompatActivity implements NewsfeedAdaptor.OnItemClickListener, Serializable {
private RecyclerView mrecyclerView;
private NewsfeedAdaptor mAdaptor;
LinearLayoutManager mLayoutManager; //for sorting
SharedPreferences mSharedPref; //for saving sort settings
private DatabaseReference mDatabaseRef;
private FirebaseStorage mStorage;
private List<CreateFoundObject> mPosts;
......@@ -47,10 +56,42 @@ public class NewsFeedFound extends AppCompatActivity implements NewsfeedAdaptor.
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() {
//Actionbar
ActionBar actionBar = getSupportActionBar();
//set title
mSharedPref = getSharedPreferences("SortSettings", MODE_PRIVATE);
String mSorting = mSharedPref.getString("Sort", "Others");//where if no settingsis selected newest will be default
if (mSorting.equals("newest")) {
mDatabaseRef.orderByChild("mCategory").equalTo("category").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();
}
});
mLayoutManager = new LinearLayoutManager(this);
//this will load the items from bottom means newest first
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
} else if (mSorting.equals("oldest")) {
mDatabaseRef.orderByChild("mCategory").equalTo("nocategory").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot postSnapShot : dataSnapshot.getChildren()){
......@@ -73,7 +114,13 @@ public class NewsFeedFound extends AppCompatActivity implements NewsfeedAdaptor.
Toast.makeText(NewsFeedFound.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
};
mLayoutManager = new LinearLayoutManager(this);
//this will load the items from bottom means oldest first
mLayoutManager.setReverseLayout(false);
mLayoutManager.setStackFromEnd(false);
}
@Override
public void onItemClick(int position) {
Log.v("position =",String.valueOf(position));
......@@ -86,6 +133,81 @@ public class NewsFeedFound extends AppCompatActivity implements NewsfeedAdaptor.
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//inflate the menu; this adds items to the action bar if it present
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem item = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//firebaseSearch(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
//Filter as you type
//firebaseSearch(newText);
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//handle other action bar item clicks here
if (id == R.id.action_sort) {
//display alert dialog to choose sorting
showSortDialog();
return true;
}
return super.onOptionsItemSelected(item);
}
private void showSortDialog() {
//options to display in dialog
final String[] sortOptions = {"Others","Electronics", "Documents", "Clothes","Furniture","Accessories"};
//create alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Sort by") //set title
.setIcon(R.drawable.common_google_signin_btn_icon_dark_normal) //set icon
.setItems(sortOptions, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position of the selected item
// 0 means "Newest" and 1 means "oldest"
if (which == 0) {
//sort by newest
//Edit our shared preferences
SharedPreferences.Editor editor = mSharedPref.edit();
editor.putString("Sort", sortOptions[which]); //where 'Sort' is key & 'newest' is value
editor.apply(); // apply/save the value in our shared preferences
recreate(); //restart activity to take effect
} else {
{
//sort by oldest
//Edit our shared preferences
SharedPreferences.Editor editor = mSharedPref.edit();
editor.putString("Sort", sortOptions[which]); //where 'Sort' is key & 'oldest' is value
editor.apply(); // apply/save the value in our shared preferences
recreate(); //restart activity to take effect
}
}
}
});
builder.show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/common_google_signin_btn_icon_dark_focused"
android:title="Search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
<item
android:id="@+id/action_sort"
android:title="Sort"
app:showAsAction="never" />
</menu>
\ 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