Skip to content

Commit

Permalink
DI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Surya committed Feb 11, 2019
1 parent e9eee11 commit 59e08c5
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 90 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -18,10 +18,10 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".ui.login.LoginActivity"
android:name=".ui.main.MainActivity"
android:label="@string/title_activity_login" />
<activity
android:name=".ui.main.MainActivity"
android:name=".ui.login.LoginActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
Expand Down
@@ -1,10 +1,15 @@
package com.androidwave.cleancode.ui.login;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.androidwave.cleancode.R;
import com.androidwave.cleancode.data.network.pojo.LoginRequest;
import com.androidwave.cleancode.data.network.pojo.UserProfile;
import com.androidwave.cleancode.ui.base.BaseActivity;
import com.androidwave.cleancode.ui.main.MainActivity;

import javax.inject.Inject;

Expand All @@ -15,18 +20,28 @@ public class LoginActivity extends BaseActivity implements LoginMvpView {
@Inject
LoginMvpPresenter<LoginMvpView> mPresenter;

TextView mEmail, mPassword;
Button loginButton;


// UI references.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
getActivityComponent().inject(this);
mPresenter.onAttach(LoginActivity.this);
setUp();
}

@Override
protected void setUp() {

mEmail = findViewById(R.id.input_email);
mPassword = findViewById(R.id.input_password);
loginButton = findViewById(R.id.btn_login);
loginButton.setOnClickListener(v -> {
mPresenter.onLoginClick();
});
}

@Override
Expand All @@ -37,7 +52,34 @@ protected void onDestroy() {

@Override
public void onLoginSuccess(UserProfile mUser) {
startActivity(MainActivity.getStartIntent(this));
}

@Override
public String getEmail() {
return mEmail.getText().toString();
}

@Override
public String getPassword() {
return mPassword.getText().toString();
}

@Override
public void showInputError() {
showMessage(getString(R.string.input_invalid));
}

@Override
public void setPassword(String password) {
mEmail.setText(password);
}

@Override
public void setEmail(String email) {
mPassword.setText(email);
}


}

Expand Up @@ -4,5 +4,5 @@
import com.androidwave.cleancode.ui.base.MvpPresenter;

public interface LoginMvpPresenter<V extends LoginMvpView> extends MvpPresenter<V> {
void onLoginClick(LoginRequest request);
void onLoginClick();
}
Expand Up @@ -5,4 +5,14 @@

public interface LoginMvpView extends MvpView {
void onLoginSuccess(UserProfile mUser);

String getEmail();

String getPassword();

void showInputError();

void setPassword(String userId);

void setEmail(String password);
}
@@ -1,8 +1,10 @@
package com.androidwave.cleancode.ui.login;

import android.os.Handler;

import com.androidwave.cleancode.data.DataManager;
import com.androidwave.cleancode.data.network.pojo.LoginRequest;
import com.androidwave.cleancode.data.network.pojo.UserProfile;
import com.androidwave.cleancode.data.utils.LoggedInMode;
import com.androidwave.cleancode.ui.base.BasePresenter;
import com.androidwave.cleancode.utils.rx.SchedulerProvider;

Expand All @@ -18,12 +20,33 @@ public LoginPresenter(DataManager manager, SchedulerProvider schedulerProvider,
}

@Override
public void onLoginClick(LoginRequest request) {
// todo api call here
getMvpView().showLoading();
getMvpView().onLoginSuccess(new UserProfile());
if (!isViewAttached()) {
return;
public void onLoginClick() {
if (getMvpView() != null) {
if (getMvpView().getEmail().trim().equals("") || getMvpView().getPassword().trim().equals("")) {
getMvpView().showInputError();
} else {
getMvpView().showLoading();
new Handler().postDelayed(() -> {
if (!isViewAttached()) {
return;
}
// set demo user
UserProfile mProfile = new UserProfile();
mProfile.setFirstName("Dinesh");
mProfile.setLastName("Kumar");
mProfile.setEmail("dinesh@gmail.com");
mProfile.setUserId("1");
//update preferences
getDataManager().updateUserInfo("access toekn", 1l, LoggedInMode.LOGGED_IN_MODE_SERVER, "", mProfile.getEmail(), "");
getMvpView().onLoginSuccess(mProfile);

getMvpView().hideLoading();
}, 1000);

}

}


}
}
@@ -1,34 +1,36 @@
package com.androidwave.cleancode.ui.main;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.androidwave.cleancode.R;
import com.androidwave.cleancode.ui.base.BaseActivity;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends BaseActivity {

public static Intent getStartIntent(Context context) {
Intent intent = new Intent(context, MainActivity.class);
return intent;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

}

@Override
protected void setUp() {

}

@Override
Expand Down
Binary file added app/src/main/res/drawable/logo_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 63 additions & 63 deletions app/src/main/res/layout/activity_login.xml
@@ -1,78 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".ui.login.LoginActivity">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:background="@color/colorPrimary">

<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingTop="56dp"
android:paddingRight="24dp"
android:gravity="center">

<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"
android:src="@drawable/logo_icon" />

<LinearLayout
android:id="@+id/email_login_form"
<!-- Email Label -->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">

<com.google.android.material.textfield.TextInputLayout
<EditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
android:layout_height="wrap_content"
android:hint="Email"
android:textColor="@color/white"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>

</com.google.android.material.textfield.TextInputLayout>
<!-- Password Label -->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">

<com.google.android.material.textfield.TextInputLayout
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
android:layout_height="wrap_content"
android:hint="Password"
android:textColor="@color/white"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>

</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:padding="12dp"
android:textColor="@color/white"
android:text="Login" />

<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_sign_in"
android:textStyle="bold" />
<TextView
android:id="@+id/link_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:gravity="center"
android:textColor="@color/white"
android:text="No account yet? Create one"
android:textSize="16dip" />

</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</ScrollView>
16 changes: 13 additions & 3 deletions app/src/main/res/values/colors.xml
@@ -1,8 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorPrimary">#E43F3F</color>
<color name="colorPrimaryDark">#E12929</color>
<color name="colorAccent">#FF4081</color>
<color name="white">#FFFFFF</color>
<color name="black_effective">#2a2a2a</color>
<color name="colorPrimaryDarker">#CC1D1D</color>
<color name="accent">#FFFFFF</color>
<color name="black">#000000</color>
<color name="jet">#222222</color>
<color name="oil">#333333</color>
<color name="monsoon">#777777</color>
<color name="jumbo">#888888</color>
<color name="aluminum">#999999</color>
<color name="base">#AAAAAA</color>
<color name="iron">#CCCCCC</color>
<color name="white">#FFFFFF</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -15,4 +15,5 @@
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
<string name="input_invalid">Email or password cannot be empty</string>
</resources>

0 comments on commit 59e08c5

Please sign in to comment.