You need to sign in or sign up before continuing.
Commit 4cb4265b authored by ankitasingh's avatar ankitasingh

Edit bug fix and small UI changes

parent a3575408
This diff is collapsed.
......@@ -28,6 +28,7 @@ import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.FirebaseAuth;
import com.squareup.picasso.Picasso;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
......@@ -51,6 +52,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.net.URL;
import java.util.Date;
......@@ -58,7 +60,7 @@ import java.util.Random;
//import static android.app.Activity.RESULT_OK;
//import com.squareup.picasso.Picasso;
public class FoundItem extends AppCompatActivity implements View.OnClickListener{
public class FoundItem extends AppCompatActivity implements View.OnClickListener, Serializable {
//private FirebaseAuth mAuth;
EditText title;
EditText place;
......@@ -75,14 +77,18 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
public Uri mImageUri;
public Uri uploadSessionUri;
int PICK_IMAGE_REQUEST = 111;
public String callingclass;
ProgressDialog pd;
private StorageTask mUploadTask;
private boolean updatedata;
public String tempUri;
// ...
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = FirebaseDatabase.getInstance().getReference("FoundData");
StorageReference mStorage = FirebaseStorage.getInstance().getReference("Images");
FirebaseStorage mStorageRef = FirebaseStorage.getInstance();
@Override
......@@ -92,6 +98,7 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
username = getIntent().getStringExtra("username");
callingclass = getIntent().getStringExtra("CallingClass");
title = findViewById(R.id.title);
place = findViewById(R.id.place);
desc = findViewById(R.id.desc);
......@@ -102,6 +109,19 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
pd = new ProgressDialog(this);
pd.setMessage("Uploading....");
if(callingclass.equals("MyPosts"))
{
CreateFoundObject objectfound = (CreateFoundObject)getIntent().getSerializableExtra("FoundObject");
Log.v("desc",objectfound.getmDescription());
title.setText(objectfound.getmTitle());
place.setText(objectfound.getmLocation());
desc.setText(objectfound.getmDescription());
date.setText(objectfound.getDate());
Picasso.with(FoundItem.this).load(objectfound.getImageUrl())
.fit()
.centerCrop()
.into(camera);
}
findViewById(R.id.submit).setOnClickListener(this);
......@@ -116,6 +136,7 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
final String Desc = desc.getText().toString().trim();
final String Date = date.getText().toString().trim();
updatedata = false;
if (title.getText().toString().trim().isEmpty()) {
title.setError("Please enter title");
title.requestFocus();
......@@ -127,7 +148,40 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
place.requestFocus();
return;
}
if (mImageUri != null) {
if(callingclass.equals("MyPosts"))
{
final CreateFoundObject objectfound = (CreateFoundObject)getIntent().getSerializableExtra("FoundObject");
if(objectfound.getImageUrl().equals("NO-IMAGE"))
{
myRef.child(objectfound.getKey()).removeValue();
Toast.makeText(FoundItem.this, "Item Updated", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FoundItem.this, MyPostsFoundRV.class);
intent.putExtra("username", username);
startActivity(intent);
finish();
}
else
{
StorageReference imageRef = mStorageRef.getReferenceFromUrl(objectfound.getImageUrl());
tempUri = objectfound.getImageUrl();
updatedata = true;
imageRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
myRef.child(objectfound.getKey()).removeValue();
Toast.makeText(FoundItem.this, "Item Updated", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FoundItem.this, MyPostsFoundRV.class);
intent.putExtra("username", username);
startActivity(intent);
finish();
}
});
}
}
if (mImageUri != null ) {
pd.show();
final StorageReference fileReference = mStorage.child(System.currentTimeMillis()
+ "." + getExtension(mImageUri));
......@@ -150,10 +204,17 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
@Override
public void onSuccess(Uri uri) {
uploadSessionUri = uri;
CreateFoundObject upload;
Date datef = new Date();
CreateFoundObject upload = new CreateFoundObject(username,Title ,uri.toString(),"location", Desc,
"category", datef,"found");
if(updatedata)
{
upload = new CreateFoundObject(username,Title ,tempUri,"location", Desc,
"category", datef,"found");
}
else {
upload = new CreateFoundObject(username, Title, uri.toString(), "location", Desc,
"category", datef, "found");
}
String uploadId = myRef.push().getKey();
Log.v("UploadID", uploadId);
myRef.child(uploadId).setValue(upload);
......@@ -185,6 +246,7 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
});
} else {
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,
......@@ -197,7 +259,10 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
desc.setText("");
date.setText("");
Toast.makeText(FoundItem.this,"SUBMIT SUCCESSFUL -NO IMAGE UPLOADED!",Toast.LENGTH_LONG).show();
Intent intent = new Intent(FoundItem.this, MyPostsFoundRV.class);
intent.putExtra("username", username);
startActivity(intent);
finish();
}
......@@ -251,10 +316,14 @@ public class FoundItem extends AppCompatActivity implements View.OnClickListener
try {
//getting image from gallery
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mImageUri);
//Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mImageUri);
//Setting image to ImageView
camera.setImageBitmap(bitmap);
//camera.setImageBitmap(bitmap);
Picasso.with(FoundItem.this).load(mImageUri)
.fit()
.centerCrop()
.into(camera);
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -27,7 +27,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class MyPostsFoundRV extends AppCompatActivity implements MyPostsAdaptor.OnItemClickListener {
public class MyPostsFoundRV extends AppCompatActivity implements MyPostsAdaptor.OnItemClickListener,Serializable {
private RecyclerView mrecyclerView;
private MyPostsAdaptor mAdaptor;
......@@ -91,8 +91,9 @@ public class MyPostsFoundRV extends AppCompatActivity implements MyPostsAdaptor.
final String selectedKey = selectedItem.getKey();
Intent intent = new Intent(MyPostsFoundRV.this, FoundItem.class);
intent.putExtra("FoundObject", selectedItem);
intent.putExtra("CallingClass","MyPosts");
intent.putExtra("username",username);
startActivity(intent);
Toast.makeText(this, "Whatever click at position: " + position, Toast.LENGTH_SHORT).show();
}
@Override
......
......@@ -59,6 +59,7 @@ public class Navigation extends AppCompatActivity implements NavigationView.OnNa
case R.id.post_found:
Intent intent = new Intent(Navigation.this, FoundItem.class);
intent.putExtra("username", username);
intent.putExtra("CallingClass","Navigation");
startActivity(intent);
break;
case R.id.post_lost:
......
......@@ -15,11 +15,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/camera"
android:src="@drawable/camera"
android:src="@drawable/cameraup"
android:minWidth="80dp"
android:minHeight="80dp"
android:layout_marginTop = "30dp"
android:layout_marginLeft="30dp"
android:minHeight="100dp"
/>
......
......@@ -24,7 +24,7 @@
android:id="@+id/found_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="140dp"
android:layout_marginHorizontal="150dp"
android:layout_marginBottom="24dp"
android:text="Found"
android:background="@color/colorPrimary"
......
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