Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signup and Login Error Resolved #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -25,13 +25,13 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-database:19.6.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
@@ -44,6 +44,7 @@ dependencies {
//Slide to act
implementation "com.ncorti:slidetoact:0.9.0"
//circular image
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'

}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
<activity android:name=".homeActivity" />
<activity android:name=".LoginScreen" >
</activity>

<activity android:name=".LoginWithOtp" />
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.dscnitp.touristshelperapp.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
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.bumptech.glide.Glide;
import com.dscnitp.touristshelperapp.R;

import java.util.ArrayList;


public class CityRecyclerViewAdapter extends RecyclerView.Adapter<CityRecyclerViewAdapter.ViewHolder> {
Context mContext;
private OnItemClickListener mListener;
private final ArrayList<String> CityList,DistrictList,StateList,PinCodeList,ImageList;
public interface OnItemClickListener
{
void onItemClick(int position);
}
public void setOnItemClickListener(OnItemClickListener listener)
{
mListener=listener;
}

public CityRecyclerViewAdapter(Context mContext, ArrayList<String> cityList, ArrayList<String> districtList, ArrayList<String> stateList, ArrayList<String> pinCodeList, ArrayList<String> ImageList) {
this.mContext = mContext;
this.CityList = cityList;
this.DistrictList = districtList;
this.StateList = stateList;
this.PinCodeList = pinCodeList;
this.ImageList=ImageList;
}

@NonNull
@Override
public CityRecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.city_list_layout, parent, false);
return new CityRecyclerViewAdapter.ViewHolder(view,mListener);
}


@Override
public void onBindViewHolder(@NonNull CityRecyclerViewAdapter.ViewHolder holder, int position) {
holder.City.setText(CityList.get(position));
holder.State.setText(StateList.get(position));
holder.PinCode.setText(PinCodeList.get(position));
holder.District.setText(DistrictList.get(position));
Glide.with(mContext).load(ImageList.get(position)).into(holder.City_Image);
}

@Override
public int getItemCount() {
return CityList.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView City,District,State,PinCode;
public ImageView City_Image;
public ViewHolder(@NonNull View itemView, final OnItemClickListener listener) {
super(itemView);
City=itemView.findViewById(R.id.City);
District=itemView.findViewById(R.id.District);
State=itemView.findViewById(R.id.State);
PinCode=itemView.findViewById(R.id.Pin);
City_Image=itemView.findViewById(R.id.city_image);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(listener!=null)
{
int position=getAdapterPosition();
if(position!=RecyclerView.NO_POSITION)
{
listener.onItemClick(position);
}
}
}
});
}
}

@Override
public int getItemViewType(int position) {
return 1;
}
}
66 changes: 65 additions & 1 deletion app/src/main/java/com/dscnitp/touristshelperapp/LoginScreen.java
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
import android.widget.Button;
import android.widget.Toast;

import com.dscnitp.touristshelperapp.Model.UserProfile;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
@@ -23,12 +24,20 @@
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
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.util.HashMap;

public class LoginScreen extends AppCompatActivity implements View.OnClickListener {
private static final int RC_SIGN_IN =1000 ;
Button google_btn;
GoogleSignInClient mGoogleSigninClient;
FirebaseAuth mAuth;
public String email,Id;
private Button sign_otp;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -80,7 +89,10 @@ private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);

// Signed in successfully, show authenticated UI.
Toast.makeText(this,account.getDisplayName()+" is in!",Toast.LENGTH_SHORT).show();
if(account!=null)
{
email=account.getEmail();
}
firebaseAuth(account);
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
@@ -97,6 +109,58 @@ private void firebaseAuth(GoogleSignInAccount account) {
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
FirebaseDatabase firebaseDatabase1=FirebaseDatabase.getInstance();
DatabaseReference databaseReference1=firebaseDatabase1.getReference("UserProfile");
databaseReference1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists())
{
HashMap<String,Object> hashMap= (HashMap<String, Object>) snapshot.getValue();
for(String key:hashMap.keySet())
{
Object data=hashMap.get(key);
HashMap<String,Object> hashMap1= (HashMap<String, Object>) data;
String email=hashMap1.get("email").toString();
if(email.equals(email))
{
FirebaseAuth auth= FirebaseAuth.getInstance();
if(auth.getCurrentUser()!=null) {
Id = auth.getCurrentUser().getUid();
Intent intent = new Intent(LoginScreen.this, homeActivity.class);
intent.putExtra("Id",Id);
startActivity(intent);
}
}
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
UserProfile userProfile=new UserProfile(
"",
email,
"",
"",
"",
"","","",""
);
Id=mAuth.getCurrentUser().getUid();
FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance();
DatabaseReference databaseReference=firebaseDatabase.getReference("UserProfile").child(Id);
databaseReference.setValue(userProfile).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(getApplicationContext(), "You logged in Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginScreen.this, homeActivity.class);
intent.putExtra("Id",Id);
startActivity(intent);
}
});
Toast.makeText(LoginScreen.this,"Firebase Auth successful",Toast.LENGTH_SHORT).show();
FirebaseUser user=mAuth.getCurrentUser();
}
65 changes: 60 additions & 5 deletions app/src/main/java/com/dscnitp/touristshelperapp/LoginWithOtp.java
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
import android.widget.EditText;
import android.widget.Toast;

import com.dscnitp.touristshelperapp.Model.UserProfile;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
@@ -18,14 +19,20 @@
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
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.util.HashMap;
import java.util.concurrent.TimeUnit;

public class LoginWithOtp extends AppCompatActivity {

private Button request, verify;
private EditText mobile_edit, otp_edit;
private String phone, mVerificationId;
private String phone, mVerificationId,Id;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private FirebaseAuth mAuth;

@@ -113,10 +120,58 @@ private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "You logged in Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginWithOtp.this, homeActivity.class);
startActivity(intent);

FirebaseDatabase firebaseDatabase1=FirebaseDatabase.getInstance();
DatabaseReference databaseReference1=firebaseDatabase1.getReference("UserProfile");
databaseReference1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists())
{
HashMap<String,Object> hashMap= (HashMap<String, Object>) snapshot.getValue();
for(String key:hashMap.keySet())
{
Object data=hashMap.get(key);
HashMap<String,Object> hashMap1= (HashMap<String, Object>) data;
String contact=hashMap1.get("contact").toString();
if(contact.equals(phone))
{
FirebaseAuth auth= FirebaseAuth.getInstance();
if(auth.getCurrentUser()!=null) {
Id = auth.getCurrentUser().getUid();
Intent intent = new Intent(LoginWithOtp.this, homeActivity.class);
intent.putExtra("Id",Id);
startActivity(intent);
}
}
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
UserProfile userProfile=new UserProfile(
"",
"",
"",
phone,
"",
"","","",""
);
Id=mAuth.getCurrentUser().getUid();
FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance();
DatabaseReference databaseReference=firebaseDatabase.getReference("UserProfile").child(Id);
databaseReference.setValue(userProfile).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(getApplicationContext(), "You logged in Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginWithOtp.this, homeActivity.class);
intent.putExtra("Id",Id);
startActivity(intent);
}
});
} else {

String message = "Somthing is wrong, we will fix it soon...";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.dscnitp.touristshelperapp.Model;

public class UserProfile {
public String username,email,password,contact,description,gender,location,liked_cities,visited_cities;

public UserProfile(String username, String email, String password, String contact, String description, String gender, String location, String liked_cities, String visited_cities) {
this.username = username;
this.email = email;
this.password = password;
this.contact = contact;
this.description = description;
this.gender = gender;
this.location = location;
this.liked_cities = liked_cities;
this.visited_cities = visited_cities;
}
}
19 changes: 16 additions & 3 deletions app/src/main/java/com/dscnitp/touristshelperapp/SplashScreen.java
Original file line number Diff line number Diff line change
@@ -5,12 +5,14 @@
import android.content.Intent;
import android.os.Bundle;

import com.google.firebase.auth.FirebaseAuth;
import com.ncorti.slidetoact.SlideToActView;

public class SplashScreen extends AppCompatActivity {

SlideToActView slideToActView;

FirebaseAuth auth;
public String Id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -20,8 +22,19 @@ protected void onCreate(Bundle savedInstanceState) {
slideToActView.setOnSlideCompleteListener(new SlideToActView.OnSlideCompleteListener() {
@Override
public void onSlideComplete(SlideToActView slideToActView) {
startActivity(new Intent(getApplicationContext(), LoginScreen.class));
finish();
auth= FirebaseAuth.getInstance();
if(auth.getCurrentUser()!=null) {
Id = auth.getCurrentUser().getUid();
Intent intent = new Intent(SplashScreen.this, homeActivity.class);
intent.putExtra("Id",Id);
startActivity(intent);
}
else
{
startActivity(new Intent(getApplicationContext(), LoginScreen.class));
finish();
}
SplashScreen.this.finish();
}
});
}
Loading