Skip to content
Permalink
cd491a4515
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
240 lines (153 sloc) 6.61 KB
package com.example.booksharing21;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
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 java.io.IOException;
import java.util.List;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class BProfileActivity extends AppCompatActivity implements View.OnClickListener, OnMapReadyCallback {
public String TAG = "BProfileActivity";
private ImageView bimage;
private TextView pbookname, plocation, pisbn, pcondition, pauthor , ubookname ;
public EditText s_email,s_message;
public Button addmess;
String id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bprofile);
bimage = findViewById(R.id.bimage);
ubookname = findViewById(R.id.bookname);
pauthor = findViewById(R.id.pauthor);
pisbn = findViewById(R.id.pisbn);
pcondition = findViewById(R.id.pcondition);
plocation = findViewById(R.id.plocation);
s_email = findViewById(R.id.s_email);
s_message = findViewById(R.id.s_message);
addmess = findViewById(R.id.addmess);
addmess.setOnClickListener(this);
geocoder = new Geocoder(this);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
getData();
}
// https://www.youtube.com/watch?v=GIDTH6Y0qds&list=PLhPyEFL5u-i1jAc79cJ2j8pDZFEyvpoH_&index=7 (item listener in recycler view)
public DatabaseReference myRef = FirebaseDatabase.getInstance().getReference("posts");
public void getData() {
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
Intent intent = getIntent();
id = intent.getStringExtra("id");
myRef.child(id).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
String bookname = snapshot.child("book name").getValue().toString();
String author = snapshot.child("author").getValue().toString();
String isbn = snapshot.child("isbn").getValue().toString();
String condition = snapshot.child("condition").getValue().toString();
String location = snapshot.child("location").getValue().toString();
String ImageUrl = snapshot.child("url").getValue().toString();
String email = snapshot.child("email").getValue().toString();
Glide.with(getApplicationContext()).load(ImageUrl).into(bimage);
ubookname.setText(bookname);
pauthor.setText(author);
pisbn.setText(isbn);
pcondition.setText(condition);
plocation.setText(location);
s_email.setText(email);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.addmess:
sendMail();
}
}
private void sendMail() {
String email = s_email.getText().toString();
String[] uemail = email.split(" ");
String message = s_message.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, uemail);
intent.putExtra(Intent.EXTRA_SUBJECT,ubookname.getText().toString());
intent.putExtra(Intent.EXTRA_TEXT,message);
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent,"Choose Email Client"));
}
GoogleMap map;
public Geocoder geocoder;
public LatLng LatLng(double latitude, double longitude) {
return new LatLng(latitude,longitude) ;
}
@Override
public void onMapReady(GoogleMap googleMap) {
Intent intent = getIntent();
id = intent.getStringExtra("id");
map = googleMap;
myRef.child(id).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
String location = snapshot.child("location").getValue().toString();
try {
List<Address> addresses = geocoder.getFromLocationName(location,1);
Address address = addresses.get(0);
Log.d(TAG, "onMapReady: " + address.toString());
LatLng loc = new LatLng(address.getLatitude(),address.getLongitude());
MarkerOptions markerOptions = new MarkerOptions()
.position(loc)
.title(address.getLocality());
map.addMarker(markerOptions);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc,10));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
}