This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
Developed Login for DevAuthBackEnd #48 #65
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
654fed0
Add Dev server login link in LoginActivity
kunall17 12575fd
Added click listener for devAuth link
kunall17 4fd1be0
Fetch the admin and user E-mail's
kunall17 b1c4bc3
Added new Activity for displaying the fetched Email-s
kunall17 1afdbbe
Implemented RecyclerView for holding the list of E-Mail's
kunall17 53d192a
Hide devAuth textView button if this is non-debug builds
kunall17 ad1c4d3
Implemented Tests for DevAuthLogin
kunall17 70ac863
Removed iago Server URL Hack
kunall17 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
app/src/androidTest/java/com/zulip/android/activities/LoginDevAuthTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package com.zulip.android.activities; | ||
|
||
|
||
import android.support.test.espresso.NoMatchingViewException; | ||
import android.support.test.espresso.ViewAssertion; | ||
import android.support.test.espresso.ViewInteraction; | ||
import android.support.test.espresso.matcher.BoundedMatcher; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.test.suitebuilder.annotation.LargeTest; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
import com.zulip.android.R; | ||
import com.zulip.android.ZulipApp; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; | ||
import static android.support.test.espresso.action.ViewActions.replaceText; | ||
import static android.support.test.espresso.matcher.ViewMatchers.assertThat; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withHint; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withParent; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.core.AllOf.allOf; | ||
|
||
@LargeTest | ||
@RunWith(AndroidJUnit4.class) | ||
public class LoginDevAuthTest { | ||
|
||
@Rule | ||
public ActivityTestRule<ZulipActivity> mActivityTestRule = new ActivityTestRule<>(ZulipActivity.class); | ||
|
||
private static String EMAIL_TEST = ""; | ||
private static String SERVER_URL = "http://10.0.3.2:9991/api/"; | ||
|
||
// Convenience helper | ||
@Test | ||
public void TestSerially() { | ||
getDevEmails(); | ||
loginThroughDevMail(); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
closeSoftKeyboard(); | ||
} | ||
|
||
public void getDevEmails() { | ||
|
||
closeSoftKeyboard(); | ||
//Uncheck Checkbox | ||
ViewInteraction checkBox = onView( | ||
allOf(withId(R.id.checkbox_usezulip), withText("Use Zulip.com"), | ||
withParent(withId(R.id.server)), | ||
isDisplayed())); | ||
checkBox.perform(click()); | ||
|
||
//Give a Server URL | ||
ViewInteraction editText = onView(allOf(withId(R.id.server_url), withHint(R.string.server_domain), withParent(withId(R.id.server)), isDisplayed())); | ||
editText.perform(replaceText(SERVER_URL)); | ||
|
||
closeSoftKeyboard(); | ||
|
||
//Click DevAuth TextView Button | ||
ViewInteraction textView = onView(allOf(withId(R.id.local_server_button), withText("Dev Backend testing server"), isDisplayed())); | ||
textView.perform(click()); | ||
|
||
//Check if there are Emails | ||
onView(withId(R.id.devAuthRecyclerView)).check(hasItemsCount()); | ||
} | ||
|
||
private static boolean matchedBefore = false; | ||
|
||
//This filter returns only one View! | ||
private Matcher<View> emailFilter() { | ||
|
||
return new BoundedMatcher<View, Button>(Button.class) { | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("ERROR"); | ||
} | ||
|
||
@Override | ||
protected boolean matchesSafely(Button item) { | ||
if (!matchedBefore && item.getText().toString().contains("@")) { | ||
EMAIL_TEST = item.getText().toString(); | ||
matchedBefore = true; | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
|
||
public void loginThroughDevMail() { | ||
|
||
//If EMAIL not specified click on first EMAIL. | ||
if (EMAIL_TEST.equals("")) { | ||
onView(allOf(withId(android.R.id.text1), emailFilter())).perform(click()); | ||
} else { | ||
//Find and click the E-Mail Button. | ||
ViewInteraction button = onView(Matchers.allOf(withId(android.R.id.text1), withText(EMAIL_TEST), isDisplayed())); | ||
button.perform(click()); | ||
} | ||
|
||
//Verify Correct E-Mail is Stored | ||
assertThat(ZulipApp.get().getEmail(), is(EMAIL_TEST)); | ||
} | ||
|
||
public static ViewAssertion hasItemsCount() { | ||
return new ViewAssertion() { | ||
@Override | ||
public void check(View view, NoMatchingViewException e) { | ||
if (!(view instanceof RecyclerView)) { | ||
throw e; | ||
} | ||
RecyclerView rv = (RecyclerView) view; | ||
assertThat("Items less than 2, which means no E-Mails!", rv.getAdapter().getItemCount(), Matchers.greaterThan(2)); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/src/main/java/com/zulip/android/activities/AuthEmailAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.zulip.android.activities; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.ColorInt; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
|
||
import com.zulip.android.R; | ||
import com.zulip.android.util.AuthClickListener; | ||
|
||
import java.util.List; | ||
|
||
class AuthEmailAdapter extends RecyclerView.Adapter<AuthEmailAdapter.AuthEmailViewHolder> { | ||
|
||
private static final int VIEW_TYPE_HEADER = 0; | ||
private static final int VIEW_TYPE_ADMIN = 1; | ||
private static final int VIEW_TYPE_USER = 2; | ||
private List<String> emails; | ||
private int userStringPosition; //Position of the User String header | ||
private static AuthClickListener authClickListener; | ||
|
||
private | ||
@ColorInt | ||
int devAuthUserColor; | ||
private | ||
@ColorInt | ||
int devAuthAdminColor; | ||
|
||
AuthEmailAdapter(List<String> emails, int directAdminSize, Context context) { | ||
this.userStringPosition = directAdminSize + 1; //+1 due to the Administrator String | ||
this.emails = emails; | ||
devAuthUserColor = ContextCompat.getColor(context, R.color.dev_auth_user); | ||
devAuthAdminColor = ContextCompat.getColor(context, R.color.dev_auth_admin); | ||
} | ||
|
||
@Override | ||
public AuthEmailViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View v = null; | ||
if (viewType == VIEW_TYPE_HEADER) | ||
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.dev_auth_header, parent, false); | ||
else | ||
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.dev_auth_row, parent, false); | ||
return new AuthEmailViewHolder(v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(AuthEmailViewHolder holder, int position) { | ||
if (position == 0) { | ||
if (userStringPosition == 1) | ||
((TextView) holder.view).setText(R.string.admin_none); //Show none if no admins | ||
else ((TextView) holder.view).setText(R.string.admin); | ||
} else if (position == userStringPosition) | ||
((TextView) holder.view).setText(R.string.normal_user); | ||
else if (position > userStringPosition) { | ||
((Button) holder.view).setText(emails.get(position - 2)); | ||
holder.view.setBackgroundColor(devAuthUserColor); | ||
} else { | ||
((Button) holder.view).setText(emails.get(position - 1)); | ||
holder.view.setBackgroundColor(devAuthAdminColor); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return emails.size() + 2; | ||
//+2 due to the two headers {"Admin and user"} | ||
} | ||
|
||
@Override | ||
public int getItemViewType(int position) { | ||
if (position == 0 || position == userStringPosition) return VIEW_TYPE_HEADER; | ||
if (position > userStringPosition) return VIEW_TYPE_USER; | ||
else return VIEW_TYPE_ADMIN; | ||
} | ||
|
||
void setOnItemClickListener(AuthClickListener authClickListener) { | ||
AuthEmailAdapter.authClickListener = authClickListener; | ||
} | ||
|
||
class AuthEmailViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
View view; | ||
|
||
AuthEmailViewHolder(View itemView) { | ||
super(itemView); | ||
view = itemView.findViewById(android.R.id.text1); | ||
if (view instanceof Button) { | ||
view.setOnClickListener(this); | ||
} | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
authClickListener.onItemClick(((Button) v).getText().toString()); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/zulip/android/activities/DevAuthActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.zulip.android.activities; | ||
|
||
import android.app.Activity; | ||
import android.app.ProgressDialog; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import com.zulip.android.R; | ||
import com.zulip.android.networking.AsyncDevGetEmails; | ||
import com.zulip.android.networking.AsyncLogin; | ||
import com.zulip.android.util.AuthClickListener; | ||
import com.zulip.android.util.ZLog; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DevAuthActivity extends Activity { | ||
private RecyclerView recyclerView; | ||
private ProgressDialog connectionProgressDialog; | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_dev_auth); | ||
String json = getIntent().getStringExtra(AsyncDevGetEmails.EMAIL_JSON); | ||
recyclerView = (RecyclerView) findViewById(R.id.devAuthRecyclerView); | ||
List<String> emails = new ArrayList<>(); | ||
int directAdminSize = 1; | ||
connectionProgressDialog = new ProgressDialog(this); | ||
connectionProgressDialog.setMessage(getString(R.string.signing_in)); | ||
|
||
try { | ||
JSONObject jsonObject = new JSONObject(json); | ||
JSONArray jsonArray = jsonObject.getJSONArray("direct_admins"); | ||
for (int i = 0; i < jsonArray.length(); i++) { | ||
emails.add(jsonArray.get(i).toString()); | ||
} | ||
directAdminSize = jsonArray.length(); | ||
jsonArray = jsonObject.getJSONArray("direct_users"); | ||
for (int i = 0; i < jsonArray.length(); i++) { | ||
emails.add(jsonArray.get(i).toString()); | ||
} | ||
} catch (JSONException e) { | ||
ZLog.logException(e); | ||
} | ||
AuthEmailAdapter authEmailAdapter = new AuthEmailAdapter(emails, directAdminSize, DevAuthActivity.this); | ||
recyclerView.setAdapter(authEmailAdapter); | ||
authEmailAdapter.setOnItemClickListener(new AuthClickListener() { | ||
@Override | ||
public void onItemClick(String email) { | ||
AsyncLogin asyncLogin = new AsyncLogin(DevAuthActivity.this, email, null, true); | ||
asyncLogin.execute(); | ||
connectionProgressDialog.show(); | ||
} | ||
}); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(DevAuthActivity.this) { | ||
}); | ||
} | ||
|
||
public void openHome() { | ||
// Cancel before leaving activity to avoid leaking windows | ||
connectionProgressDialog.dismiss(); | ||
Intent i = new Intent(this, ZulipActivity.class); | ||
startActivity(i); | ||
finish(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a small thing, but can you remove the period from this commit message?