Skip to content

Commit

Permalink
Complete App
Browse files Browse the repository at this point in the history
User and Guide authoru=ization done.
  • Loading branch information
PreetPRG committed May 13, 2019
1 parent d540fa5 commit 4b94990
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.travelbuddy.travelguideapp.Activities;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
Expand All @@ -20,6 +22,8 @@
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.functions.FirebaseFunctions;
import com.google.firebase.functions.HttpsCallableResult;
import com.travelbuddy.travelguideapp.R;
Expand All @@ -30,7 +34,11 @@
public class ConfirmActivity extends BaseActivity {
private FirebaseFunctions mFunctions;
ConstraintLayout dynamicContent,bottonNavBar;
SharedPreferences sharedPreferences;
private Button home;
String emailGuide,guideName,guideId;
String emailUser,user_name,no_persons,contact;
FirebaseFirestore db;
// private boolean doubleBackToExitPressedOnce = false;

@Override
Expand All @@ -53,17 +61,58 @@ protected void onCreate(Bundle savedInstanceState) {
bottonNavBar= (ConstraintLayout) findViewById(R.id.bottonNavBar);
View wizard = getLayoutInflater().inflate(R.layout.activity_confirm, dynamicContent);

sharedPreferences = getSharedPreferences("Travel_Data",Context.MODE_PRIVATE);

RadioGroup rg=(RadioGroup)findViewById(R.id.radioGroup1);
RadioButton rb=(RadioButton)findViewById(R.id.hire_nav);
rb.setBackgroundColor(getResources().getColor(R.color.colorAccent));
rb.setTextColor(getResources().getColor(R.color.white));
home = findViewById(R.id.homeBtn);

Intent intent = getIntent();
String emailUser = intent.getStringExtra("emailUser");
String user_name= intent.getStringExtra("username");
String no_persons = intent.getStringExtra("persons");
String contact = intent.getStringExtra("contact");
db = FirebaseFirestore.getInstance();
emailUser = intent.getStringExtra("emailUser");
user_name= intent.getStringExtra("username");
no_persons = intent.getStringExtra("persons");
contact = intent.getStringExtra("contact");
guideId = sharedPreferences.getString("guide_id","");

db.collection("Guides").document(guideId).update("Available",false);
db.collection("Guides").document(guideId).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
// Log.d("TEST", "DocumentSnapshot data: " + document.getData());
emailGuide = document.get("Guide_email").toString();
guideName = document.get("Guide_name").toString();
//EMAIL TO GUIDE--
addMessageToGuide(emailGuide, guideName, user_name, no_persons, contact)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("DD","FAILED to Send EMAIL TO GUIDE!");
}
}).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
Toast.makeText(getApplicationContext(),"Notification Send To Guide",Toast
.LENGTH_SHORT)
.show();
}
});


} else {
Log.d("TEST", "No such document");
}
} else {
Log.d("TEST", "get failed with ", task.getException());
}
}
});


mFunctions = FirebaseFunctions.getInstance();
// mFunctions.getHttpsCallable("")
Expand All @@ -79,6 +128,8 @@ public void onComplete(@NonNull Task task) {
}
});



home.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -102,5 +153,21 @@ private Task addMessage(String emailUser,String user_name,String no_persons,Stri
.getHttpsCallable("sendEmailToUser")
.call(data);
}
private Task addMessageToGuide(String emailUser,String guidename,String user_name,String
no_persons,String
contact) {
// Create the arguments to the callable function.
Map<String, Object> data = new HashMap<>();
data.put("emailUser", emailUser);
data.put("guidename", guidename);
data.put("username", user_name);
data.put("persons", no_persons);
data.put("contact", contact);
data.put("push", true);

return mFunctions
.getHttpsCallable("sendEmailToGuide")
.call(data);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,43 @@ public void onComplete(@NonNull Task<AuthResult> task) {
SharedPreferences.Editor editor = shared.edit();
editor.putString("user_id",uid);
editor.commit();

// TravelBuddyUser user = documentSnapshot.toObject(TravelBuddyUser.class);
// SharedPreferences.Editor editor = shared.edit();
// Log.d("USER",user.toString());
// editor.putString("user_name",user.getUser_name());
// editor.commit();

DocumentReference docRef = db.collection("Users").document(uid);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
TravelBuddyUser user = documentSnapshot.toObject(TravelBuddyUser.class);
SharedPreferences.Editor editor = shared.edit();
Log.d("USER",user.toString());
editor.putString("user_name",user.getUser_name());
editor.commit();
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
// Log.d("TEST", "DocumentSnapshot data: " + document.getData());
TravelBuddyUser user = document.toObject(TravelBuddyUser.class);
SharedPreferences.Editor editor = shared.edit();
Log.d("USER",user.toString());
editor.putString("user_name",user.getUser_name());
editor.commit();
changeActivity();

} else {
Log.d("TEST", "No such document");
showMessage("You are not registered as User!");
mAuth.signOut();
Intent r = new Intent(getApplicationContext(),RegisterActivity.class);
startActivity(r);
finish();
return;
}
} else {
Log.d("TEST", "get failed with ", task.getException());
}
}
});

changeActivity();

}else {
showMessage("Login Error Occured : " + task.getException().getMessage());
progressBar.setVisibility(View.INVISIBLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.travelbuddy.travelguideapp.Activities;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.constraint.ConstraintLayout;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
Expand All @@ -27,7 +29,8 @@ public class PlacesActivity extends BaseActivity {
ConstraintLayout dynamicContent,bottonNavBar;
RecyclerView recyclerView;
FirebaseFirestore db;
TextView emptyView;
TextView emptyView,cityName;
SharedPreferences sharedPreferences;
public CollectionReference cityref ;
private CityAdapter adapter;

Expand Down Expand Up @@ -57,14 +60,17 @@ protected void onCreate(Bundle savedInstanceState) {
cityref = db.collection("Cities");
emptyView = findViewById(R.id.empty_view);
//get the reference of RadioGroup.
cityName = findViewById(R.id.cityName);

RadioGroup rg=(RadioGroup)findViewById(R.id.radioGroup1);
RadioButton rb=(RadioButton)findViewById(R.id.search_nav);
rb.setBackgroundColor(getResources().getColor(R.color.colorAccent));
rb.setTextColor(getResources().getColor(R.color.white));




sharedPreferences = getSharedPreferences("Travel_Data", Context.MODE_PRIVATE);
String c_name = sharedPreferences.getString("cityName","");
cityName.setText("Places of "+c_name+" city:");
final String item = getIntent().getStringExtra("cityID");
Log.i("EEEE",item);
recyclerView = (RecyclerView) findViewById(R.id.rv_view);
Expand All @@ -88,7 +94,6 @@ public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
Place place=documentSnapshot.toObject(Place.class);
String id = documentSnapshot.getId();
String path = documentSnapshot.getReference().getPath();

Intent i = new Intent(getApplicationContext(),SeparatePlaceDetailsActivity.class);
i.putExtra("placeID",id);
i.putExtra("cityID",item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
Plan plan=documentSnapshot.toObject(Plan.class);
String id = documentSnapshot.getId();
String path = documentSnapshot.getReference().getPath();
Toast.makeText(PlanActivity.this,
"Position: " + position + " ID: " + id + " \nPath " + path, Toast.LENGTH_SHORT).show();
// Toast.makeText(PlanActivity.this,
// "Position: " + position + " ID: " + id + " \nPath " + path, Toast.LENGTH_SHORT).show();
Intent i = new Intent(PlanActivity.this,FillUserDetailsActivity.class);
i.putExtra("plan_id",id);
//i.putExtra("city",value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ protected void onStart() {
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d("Document",document.getReference().toString());
Log.d("EEEE", document.getId() + " => " + document.get("CityName"));
ls.add((String) document.get("CityName"));
map.put(document.getString("CityName"),document.getId());
Expand Down
28 changes: 26 additions & 2 deletions TravelGuide/app/src/main/res/layout/activity_places.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,42 @@
tools:context=".Activities.PlacesActivity"
android:background="@color/colorBackground">

<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/cityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/constraintLayout2" />

<TextView
android:id="@+id/empty_view"
Expand Down

0 comments on commit 4b94990

Please sign in to comment.