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

redirection phone or email #225

Merged
merged 19 commits into from
May 28, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void init() {
// clear shared preferences to avoid auto-login
mActivityTestRule.getScenario().onActivity(SharedPreferencesHelper::clearSavedUserForAutoLogin);
}

/**
* taken from :
* https://stackoverflow.com/questions/29378552/in-espresso-how-to-avoid-ambiguousviewmatcherexception-when-multiple-views-matc
Expand Down Expand Up @@ -170,10 +170,7 @@ public void favoriteUITest() {
ViewInteraction appCompatImageView = onView(withIndex(withId(R.id.image_CardLayout_imageView), 0));
appCompatImageView.perform(forceClick());

ViewInteraction actionMenuItemView = onView(
allOf(withId(R.id.action_add_favorite), withContentDescription("Add to Favorites"),
isDisplayed()));
actionMenuItemView.perform(click());
onView(withId(R.id.action_add_favorite)).perform(click());

ViewInteraction overflowMenuButton3 = onView(
allOf(withContentDescription("More options"),
Expand Down Expand Up @@ -307,5 +304,5 @@ public void release() {
mActivityTestRule.getScenario().onActivity(SharedPreferencesHelper::clearSavedUserForAutoLogin);
login.signOut();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.view.ViewGroup;
import android.view.ViewParent;

import android.widget.Button;
import androidx.appcompat.app.AlertDialog;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import org.hamcrest.Description;
Expand Down Expand Up @@ -35,9 +37,11 @@
import dagger.hilt.android.testing.UninstallModules;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.pressBack;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isClickable;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
Expand Down Expand Up @@ -68,6 +72,7 @@ public void init() {
hiltRule.inject();
}


public static ViewAction forceClick() {
return new ViewAction() {
@Override public Matcher<View> getConstraints() {
Expand Down Expand Up @@ -295,6 +300,24 @@ public void simpleUserProfileActivityTest() {
withParent(withParent(IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class))),
isDisplayed()));
imageView2.check(matches(isDisplayed()));

ViewInteraction appCompatButton2 = onView(
allOf(withId(R.id.contact_SimpleUserProfile_button), withText("Contact")));
appCompatButton2.perform(click());


onView(withText("How did you prefer contact the announcer ?"))
.inRoot(isDialog())
.check(matches(isDisplayed()));

onView(withText("Contact via Email"))
.inRoot(isDialog())
.check(matches(isDisplayed()));

onView(withText("Contact via phone number"))
.inRoot(isDialog())
.check(matches(isDisplayed()));

}

private static Matcher<View> childAtPosition(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>


</manifest>
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
package ch.epfl.sdp.appart;

import static android.widget.Toast.makeText;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import ch.epfl.sdp.appart.utils.PermissionRequest;
import javax.inject.Inject;

import androidx.lifecycle.ViewModelProvider;

import java.util.concurrent.CompletableFuture;

import ch.epfl.sdp.appart.database.DatabaseService;
import ch.epfl.sdp.appart.database.local.LocalDatabase;
import ch.epfl.sdp.appart.database.local.LocalDatabaseService;
import ch.epfl.sdp.appart.glide.visitor.GlideImageViewLoader;
import ch.epfl.sdp.appart.user.User;
import ch.epfl.sdp.appart.user.UserViewModel;
import ch.epfl.sdp.appart.utils.ActivityCommunicationLayout;
import ch.epfl.sdp.appart.utils.DatabaseSync;
import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
Expand All @@ -49,6 +57,8 @@ public class SimpleUserProfileActivity extends AppCompatActivity {
private TextView emailTextView;
private ImageView imageView;

private final static int PHONE_CALL_PERMISSION_CODE = 123;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -80,11 +90,61 @@ protected void onCreate(Bundle savedInstanceState) {
}

/**
* closes activity when back button pressed on UI
* Contact announcer.
*/
public void contactAdUser(View view) {
// TODO: send message to user
public void openEmailOrPhone(View view){
if(!advertiserUser.getPhoneNumber().isEmpty()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("How did you prefer contact the announcer ?");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In refactor PR next week this sentence should be changed to present. And maybe something shorter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes absolutely!

builder.setPositiveButton("Contact via Email", (dialog, which) -> onEmail());
builder.setNeutralButton("Contact via phone number", (dialog, which) -> onCall());
AlertDialog dialog = builder.create();
dialog.show();
} else {
onEmail();
}
}

private void onEmail() {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{advertiserUser.getUserEmail()});
intent.putExtra(Intent.EXTRA_SUBJECT, "Rent apartment");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
makeText(this, "Error open email, try again",Toast.LENGTH_SHORT).show();

}
}
private void onCall() {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.CALL_PHONE},
PHONE_CALL_PERMISSION_CODE);
} else {
startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:"+advertiserUser.getPhoneNumber())));
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PHONE_CALL_PERMISSION_CODE:
if(PermissionRequest.checkPermission(grantResults)){
onCall();
}else{
makeText(this, "Permission Not Granted",Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}


/**
* @param user sets the value of the current user to the session user object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ public static void askForStoragePermission(Activity activity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE});
}

public static boolean checkPermission(int[] grantResults){
return ((grantResults.length > 0) && (grantResults[0]
== PackageManager.PERMISSION_GRANTED));
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/filterPrice"
android:textSize="16dp"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/guideline30"
app:layout_constraintStart_toStartOf="@+id/guideline29"
app:layout_constraintTop_toBottomOf="@+id/title_Filter_TextView" />
Expand Down Expand Up @@ -117,7 +117,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/filterLocation"
android:textSize="16dp"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/guideline30"
app:layout_constraintStart_toStartOf="@+id/guideline29"
app:layout_constraintTop_toBottomOf="@+id/price_Filter_linearLayout" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_simple_user_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
android:drawableEnd="@drawable/ic_call"
android:textColor="@color/primaryStart"
android:textSize="16sp"
android:onClick="openEmailOrPhone"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down