Skip to content

Commit

Permalink
updated app
Browse files Browse the repository at this point in the history
  • Loading branch information
tirtharajsinha committed Nov 23, 2021
1 parent 2f58bbf commit 60ea15e
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 59 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-auth:19.2.0'
testImplementation 'junit:junit:4.+'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.mikhaellopez:circularimageview:4.3.0'
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.todo_app">

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Todo_app">
<activity
android:name=".LoginActivity"
android:exported="false" />
<activity
android:name=".SplashActivity"
android:exported="true">
Expand All @@ -20,9 +24,7 @@
</activity>
<activity
android:name=".MainActivity"
android:exported="true">

</activity>
android:exported="true"></activity>
</application>

</manifest>
102 changes: 102 additions & 0 deletions app/src/main/java/com/example/todo_app/LoginActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.example.todo_app;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

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;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;

public class LoginActivity extends AppCompatActivity {
GoogleSignInClient mGoogleSignInClient;
Button signInButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginactivity);

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();

mGoogleSignInClient = GoogleSignIn.getClient(this,gso);

GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);

signInButton = findViewById(R.id.Loginbutton);


signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startactivityresult.launch(signInIntent);
}
});
}

public void updateUI(GoogleSignInAccount account){

Button signoutButton=findViewById(R.id.sign_out_button);
if(account!=null){
String personName = account.getDisplayName();
String personGivenName = account.getGivenName();
String personFamilyName = account.getFamilyName();
String personEmail = account.getEmail();
String personId = account.getId();
Uri personPhoto = account.getPhotoUrl();
final Intent i=new Intent(LoginActivity.this,MainActivity.class);
startActivity(i);


}
else{
Toast.makeText(this, "log in failed! try again", Toast.LENGTH_SHORT).show();
}
}


ActivityResultLauncher<Intent> startactivityresult=registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if(result.getResultCode()== Activity.RESULT_OK){
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(result.getData());
handleSignInResult(task);
}
}
}
);

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
updateUI(account);
// Signed in successfully, show authenticated UI.
Toast.makeText(this, "Congratulations ! successfully signed in.", Toast.LENGTH_SHORT).show();

} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.d("GOOGLE ERROR",e.getMessage());
}
}
}
67 changes: 58 additions & 9 deletions app/src/main/java/com/example/todo_app/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,74 @@
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

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;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;

import java.util.Objects;

public class SplashActivity extends AppCompatActivity {

GoogleSignInClient mGoogleSignInClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

final Intent i=new Intent(SplashActivity.this,MainActivity.class);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(i);
finish();
}
},1000);

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();

mGoogleSignInClient = GoogleSignIn.getClient(this,gso);

GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
updateUI(account);


}


public void updateUI(GoogleSignInAccount account){

if(account!=null){
String personName = account.getDisplayName();
String personGivenName = account.getGivenName();
String personFamilyName = account.getFamilyName();
String personEmail = account.getEmail();
String personId = account.getId();
Uri personPhoto = account.getPhotoUrl();
Toast.makeText(this, "hi, "+personName, Toast.LENGTH_SHORT).show();
final Intent i=new Intent(SplashActivity.this,MainActivity.class);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(i);
finish();
}
},1000);


}
else{
final Intent i=new Intent(SplashActivity.this,LoginActivity.class);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(i);
finish();
}
},800);

}
}
}
47 changes: 19 additions & 28 deletions app/src/main/java/com/example/todo_app/fourthFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.*;
import java.util.Objects;
import java.util.concurrent.Executor;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.example.todo_app.*;
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;
Expand All @@ -33,6 +29,8 @@
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.mikhaellopez.circularimageview.CircularImageView;
import com.squareup.picasso.Picasso;

public class fourthFragment extends Fragment {

Expand All @@ -42,6 +40,7 @@ public class fourthFragment extends Fragment {
Context thiscontext;
View view;
TextView textView3;
CircularImageView usrdp;

public fourthFragment(){
// require a empty public constructor
Expand All @@ -63,17 +62,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(view.getContext());
updateUI(account);

signInButton = view.findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);


signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startactivityresult.launch(signInIntent);
}
});


// sign out button setup
Expand All @@ -90,8 +78,7 @@ public void onClick(View v) {
}

public void updateUI(GoogleSignInAccount account){
SignInButton signInButton = view.findViewById(R.id.sign_in_button);
Button signoutButton=view.findViewById(R.id.sign_out_button);

if(account!=null){
String personName = account.getDisplayName();
String personGivenName = account.getGivenName();
Expand All @@ -100,24 +87,29 @@ public void updateUI(GoogleSignInAccount account){
String personId = account.getId();
Uri personPhoto = account.getPhotoUrl();
textView3=view.findViewById(R.id.textView3);
textView3.setText("Hi,"+personName);
usrdp =view.findViewById(R.id.UserImage);
textView3.setText("hi, "+personGivenName);
textView3.setTextSize(20);
signInButton.setVisibility(View.GONE);
signoutButton.setVisibility(View.VISIBLE);
Picasso.get().load(personPhoto).into(usrdp);
System.out.println(personPhoto);



}
else{
textView3=view.findViewById(R.id.textView3);
textView3.setText("Profile");
textView3.setTextSize(30);
signInButton.setVisibility(View.VISIBLE);
signoutButton.setVisibility(View.GONE);
redirectAuthPage();

}
}



public void redirectAuthPage(){
final Intent i=new Intent(thiscontext,LoginActivity.class);
startActivity(i);
}


ActivityResultLauncher<Intent> startactivityresult=registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
Expand All @@ -134,7 +126,6 @@ public void onActivityResult(ActivityResult result) {
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
updateUI(account);
// Signed in successfully, show authenticated UI.
Toast.makeText(thiscontext, "Congratulations ! successfully signed in.", Toast.LENGTH_SHORT).show();

Expand All @@ -151,7 +142,7 @@ private void signOut() {
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
updateUI(null);
redirectAuthPage();
Toast.makeText(thiscontext, "See you later! successfully signed out.", Toast.LENGTH_SHORT).show();
}
});
Expand Down
Loading

0 comments on commit 60ea15e

Please sign in to comment.