Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/mysweethome/AddHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class AddHome extends AppCompatActivity {
EditText info;
String rentOrSellST="";
EditText emailContacting;
String currentUserId;
String currentUserId;

Boolean isImages;

Expand All @@ -80,7 +80,7 @@ protected void onCreate(Bundle savedInstanceState) {

result -> {
if (result.isSignedIn()){
currentUserId= Amplify.Auth.getCurrentUser().getUserId();
currentUserId= Amplify.Auth.getCurrentUser().getUserId();
}
Log.i("AmplifyQuickstart", result.toString());

Expand Down
119 changes: 48 additions & 71 deletions app/src/main/java/com/example/mysweethome/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,35 @@
package com.example.mysweethome;

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

import android.content.ClipData;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import android.widget.ImageView;
import android.widget.TextView;


import com.amplifyframework.AmplifyException;
import com.amplifyframework.api.graphql.model.ModelQuery;
import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin;
import com.amplifyframework.auth.cognito.AWSCognitoAuthSession;
import com.amplifyframework.auth.options.AuthSignOutOptions;
import com.amplifyframework.core.Amplify;
import com.amplifyframework.datastore.generated.model.sweetHouse;
import com.google.android.material.bottomnavigation.BottomNavigationItemView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

String extras;


BottomNavigationItemView logout;


ImageView imageView ;
BottomNavigationItemView bottom;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
extras = getIntent().getStringExtra("userName");

Amplify.Auth.fetchAuthSession(

result -> {
if (result.isSignedIn()){
extras= Amplify.Auth.getCurrentUser().getUsername();

TextView userName = findViewById(R.id.textView2);
userName.setText(extras);
}
Log.i("AmplifyQuickstart", result.toString());

},
error -> Log.e("AmplifyQuickstart", error.toString())
);
FloatingActionButton addHome = findViewById(R.id.addHome);
addHome.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -71,30 +39,59 @@ public void onClick(View v) {
}
});

BottomNavigationView navView=findViewById(R.id.bottomNavView);
BottomNavigationView navView = findViewById(R.id.bottomNavView);
navView.setBackground(null);

bottom = findViewById(R.id.Account);
imageView=findViewById(R.id.logButton);
imageView.setClickable(true);
imageView.setOnClickListener(new View.OnClickListener() {

bottom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, profilePage.class);
startActivity(intent);
}
});


BottomNavigationItemView myHome = findViewById(R.id.Home);
myHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
}
});

BottomNavigationItemView search = findViewById(R.id.Search);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent goToSearch = new Intent(getApplicationContext(),SpinnerClass.class);
startActivity(goToSearch);
}
});



logout = findViewById(R.id.logButton);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Amplify.Auth.signOut(
AuthSignOutOptions.builder().globalSignOut(true).build(),
() -> {
Amplify.Auth.fetchAuthSession(

result -> {
if (!result.isSignedIn()){
Intent goToLogin = new Intent(MainActivity.this, Login.class);
startActivity(goToLogin);
}
Log.i("AmplifyQuickstart", result.toString());
result -> {
if (!result.isSignedIn()) {
Intent goToLogin = new Intent(MainActivity.this, Login.class);
startActivity(goToLogin);
}
Log.i("AmplifyQuickstart", result.toString());

},
error -> Log.e("AmplifyQuickstart", error.toString())
);
},
error -> Log.e("AmplifyQuickstart", error.toString())
);


Log.i("AuthQuickstart", "Signed out globally");
Expand All @@ -107,8 +104,8 @@ public void onClick(View v) {
Amplify.Auth.fetchAuthSession(

result -> {
if (result.isSignedIn()){
extras= Amplify.Auth.getCurrentUser().getUsername();
if (result.isSignedIn()) {
extras = Amplify.Auth.getCurrentUser().getUsername();
}
Log.i("AmplifyQuickstart", result.toString());

Expand All @@ -117,25 +114,5 @@ public void onClick(View v) {
);


TextView userName = findViewById(R.id.textView2);
if (extras != null){
userName.setText(extras);
}

bottom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, profilePage.class);
intent.putExtra("userName",extras.toString());
startActivity(intent);
}
});
}

@Override
protected void onStart(){
super.onStart();


}
}
99 changes: 89 additions & 10 deletions app/src/main/java/com/example/mysweethome/SpinnerClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import com.amplifyframework.api.graphql.model.ModelQuery;
Expand All @@ -22,13 +27,16 @@

public class SpinnerClass extends AppCompatActivity {
private Spinner spinner;
EditText fromPrice;
EditText toPrice;
String selected;
List<sweetHouse> arr1;

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

spinner = findViewById(R.id.spinner);

}
@Override
Expand All @@ -45,28 +53,99 @@ public boolean handleMessage(@NonNull Message msg) {
}
});


List<sweetHouse> allData = new ArrayList<>();
allDataFromAWS.setLayoutManager(new LinearLayoutManager(this));
allDataFromAWS.setAdapter(new ViewAdapter((ArrayList<sweetHouse>) allData));


Intent intent= getIntent();
int price = intent.getExtras().getInt("Price");
String type = intent.getExtras().getString("Type");

Amplify.API.query(
ModelQuery.list(sweetHouse.class),
response -> {
System.out.println(response.toString());

for (sweetHouse house : response.getData().getItems()) {
allData.add(house);
System.out.println("based on id ----------------: "+house);
}

for (sweetHouse house : response.getData().getItems()) {
allData.add(house);
}
handler.sendEmptyMessage(1);
Log.i("MyAmplifyApp", "Out of Loop!");

},
error -> Log.e("MyAmplifyApp", "Query failure", error)
);

}

//Ali -- Filtered
spinner = findViewById(R.id.spinner);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("Selected House Type");
arrayList.add("Apartment");
String str1 = "Apartment";
arrayList.add("Villa");
String str2 = "Villa";
arrayList.add("Flat");
String str3 = "Flat";
fromPrice = findViewById(R.id.fromPrice);
int fromPriceValue = 0;
toPrice = findViewById(R.id.toPrice);
int toPriceValue = 1000000000;

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, arrayList);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(arrayAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String tutorialsName = parent.getItemAtPosition(position).toString();
selected=tutorialsName;
}
@Override
public void onNothingSelected(AdapterView <?> parent) {
}
});

Button filter = findViewById(R.id.fitered);
filter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*Apartment,Villa,Flat*/
arr1 = new ArrayList<>();
if (selected.equals("Selected House Type") && toPrice.getText().toString().equals("") && fromPrice.getText().toString().equals("")){
for (sweetHouse allDatum : allData) {
arr1.add(allDatum);
}
allDataFromAWS.setAdapter(new ViewAdapter((ArrayList<sweetHouse>) allData));
}
List<sweetHouse> arr2= new ArrayList<>();
if(selected.equals(str1) && toPrice != null && fromPrice != null){
for (sweetHouse allDatum : allData) {
if (allDatum.getPrice() <= Integer.parseInt(toPrice.getText().toString()) && allDatum.getPrice() >= Integer.parseInt(fromPrice.getText().toString())){
arr2.add(allDatum);
}
allDataFromAWS.setAdapter(new ViewAdapter((ArrayList<sweetHouse>) arr2));
}
}
List<sweetHouse> arr3 = new ArrayList<>();
if(selected.equals(str2) && toPrice != null && fromPrice != null){
for (sweetHouse allDatum : allData) {
if (allDatum.getPrice() <= Integer.parseInt(toPrice.getText().toString()) && allDatum.getPrice() >= Integer.parseInt(fromPrice.getText().toString())){
arr3.add(allDatum);
}
allDataFromAWS.setAdapter(new ViewAdapter((ArrayList<sweetHouse>) arr3));
}
}
List<sweetHouse> arr4 = new ArrayList<>();
if(selected.equals(str3) && toPrice != null && fromPrice != null){
for (sweetHouse allDatum : allData) {
if (allDatum.getPrice() <= Integer.parseInt(toPrice.getText().toString()) && allDatum.getPrice() >= Integer.parseInt(fromPrice.getText().toString())){
arr1.add(allDatum);
}
allDataFromAWS.setAdapter(new ViewAdapter((ArrayList<sweetHouse>) arr4));
}
}
}
});

}
}
Loading