Skip to content

Commit

Permalink
now authentication is done with parse server
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthMudgil committed Jun 5, 2022
1 parent 1871986 commit bec00ed
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Reco/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation 'com.tbuonomo:dotsindicator:4.3'

// for authentication
implementation 'com.google.firebase:firebase-auth:21.0.5'
implementation 'com.github.parse-community.Parse-SDK-Android:parse:3.0.0'

// for spotify url
implementation 'com.android.volley:volley:1.2.1'
Expand Down
Binary file modified Reco/app/release/app-release.apk
Binary file not shown.
19 changes: 16 additions & 3 deletions Reco/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.sidharth.reco">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -22,24 +24,35 @@
android:exported="false"
android:noHistory="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"/>
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".onboarding.OnBoardingActivity"
android:exported="false"
android:noHistory="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"/>
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".MainActivity"
android:theme="@style/SplashTheme"
android:exported="true"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
android:name="com.parse.SERVER_URL"
android:value="@string/back4app_server_url" />
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="@string/back4app_app_id" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="@string/back4app_client_key" />

</activity>
</application>
</manifest>
18 changes: 18 additions & 0 deletions Reco/app/src/main/java/com/sidharth/reco/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sidharth.reco;

import android.app.Application;

import com.parse.Parse;

public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId(getString(R.string.back4app_app_id))
.clientKey(getString(R.string.back4app_client_key))
.server(getString(R.string.back4app_server_url))
.build()
);
}
}
14 changes: 13 additions & 1 deletion Reco/app/src/main/java/com/sidharth/reco/chat/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.parse.ParseObject;
import com.sidharth.reco.R;
import com.sidharth.reco.chat.controller.ChatAdapter;
import com.sidharth.reco.chat.model.ChatModel;
Expand Down Expand Up @@ -170,6 +170,7 @@ private void recommendSong(int type, int position) {
case TYPE_FEEDBACK: {
if (position == 0) {
wantSimilarSong();
addSongToDatabase();
} else {
tryNewSong();
}
Expand Down Expand Up @@ -217,6 +218,17 @@ private void recommendSong(int type, int position) {
}
}

private void addSongToDatabase() {
ParseObject song = new ParseObject("Favourites");
SongFeatureModel model = songModel.getFeatureModel();
song.put("id", model.getId());
song.put("name", model.getName());
song.put("valence", model.getValence());
song.put("energy", model.getEnergy());
song.put("tempo", model.getTempo());
song.saveInBackground();
}

private void likedTheSong() {
ChatOptionModel optionModel = new ChatOptionModel(TYPE_FEEDBACK, FEEDBACK);
ChatModel chatModel = new ChatModel(SENDER_BOT, getString(R.string.msg_liked_the_song), optionModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,13 @@

import com.google.android.material.button.MaterialButton;
import com.google.android.material.textview.MaterialTextView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.parse.ParseUser;
import com.sidharth.reco.MainActivity;
import com.sidharth.reco.R;
import com.sidharth.reco.chat.ChatActivity;

public class LoginFragment extends Fragment {
private ProgressDialog progressDialog;
private FirebaseAuth auth;

public LoginFragment() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
auth = FirebaseAuth.getInstance();
}

@Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = auth.getCurrentUser();
if (currentUser != null) {
currentUser.reload();
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand Down Expand Up @@ -83,14 +63,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}

private void loginUser(String email, String password) {
auth.signInWithEmailAndPassword(email, password).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
ParseUser.logInInBackground(email, password, (user, e) -> {
if (user == null) {
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
startChatActivity();
} else {
progressDialog.dismiss();
assert task.getException() != null;
Toast.makeText(getActivity(), "Signing failed", Toast.LENGTH_SHORT).show();
startChatActivity();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.google.android.material.button.MaterialButton;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.parse.ParseObject;
import com.parse.ParseUser;
import com.sidharth.reco.MainActivity;
import com.sidharth.reco.R;
import com.sidharth.reco.chat.ChatActivity;
Expand All @@ -26,25 +27,6 @@

public class SignUpFragment extends Fragment {
private ProgressDialog progressDialog;
private FirebaseAuth auth;

public SignUpFragment() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
auth = FirebaseAuth.getInstance();
}

@Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = auth.getCurrentUser();
if (currentUser != null) {
currentUser.reload();
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand Down Expand Up @@ -121,13 +103,22 @@ private boolean arePasswordsSame(String password, String confirmPassword) {
}

private void signUpAndLoginUser(String email, String password) {
auth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
ParseObject person = new ParseObject("Person");
person.put("email", email);
person.put("password", password);
person.saveInBackground();

ParseUser user = new ParseUser();
user.setUsername(email);
user.setEmail(email);
user.setPassword(password);
user.signUpInBackground(e -> {
if (e != null) {
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
startChatActivity();
} else {
progressDialog.dismiss();
assert task.getException() != null;
startChatActivity();
}
});
}
Expand Down
10 changes: 4 additions & 6 deletions Reco/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<resources>
<string name="app_name">Reco</string>

<!-- onBoarding screen -->
<!-- titles -->
<string name="back4app_server_url">https://parseapi.back4app.com/</string>
<string name="back4app_app_id">QGmTRZMYhRvC4AxXly0EzjRr5soJSVkAYOd76BXQ</string>
<string name="back4app_client_key">3opM0HdmVhWJzDgy4v0dEFIA2p52m73x0koNHiJG</string>

<string name="tv_title1">Ask the Reco</string>
<string name="tv_title2">Enjoy the music</string>
<string name="tv_title3">Save the time</string>

<!-- description -->
<string name="tv_description1">Start a chat and get free song recommendations</string>
<string name="tv_description2">enjoy the songs depending on your mood</string>
<string name="tv_description3">get freedom from daily song hunting</string>

<!-- image description -->
<string name="imgDesc_slideImage">onBoarding image</string>

<!-- Buttons text-->
<string name="btn_next">Next</string>

<!-- login screen -->
<string name="imgDesc_appLogo">app logo</string>

<string name="sign_in">Sign in</string>
Expand Down
1 change: 1 addition & 0 deletions Reco/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://jitpack.io" }
}
}
Expand Down

0 comments on commit bec00ed

Please sign in to comment.