Last active
November 3, 2017 13:30
-
-
Save brunoazevedomendonca/602db35d4501e9e44f95cc70b3bc75a0 to your computer and use it in GitHub Desktop.
Projeto Movies Road 03-11-2017
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
//Parâmetros do seu projeto .... | |
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation 'com.android.support:appcompat-v7:26.1.0' | |
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | |
testImplementation 'junit:junit:4.12' | |
androidTestImplementation 'com.android.support.test:runner:1.0.1' | |
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' | |
compile 'com.android.support:design:26.1.0' | |
compile 'com.jakewharton:butterknife:8.8.1' | |
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' | |
compile 'com.android.support:recyclerview-v7:26.1.0' | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.android.moviesroadaula1"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity android:name=".login.LoginActivity" | |
android:theme="@style/AppThemeNoActionBar"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<activity android:name=".add_movie.AddMovieActivity" | |
android:label="Adicionar Filme"/> | |
<activity android:name=".movies.MoviesActivity" | |
android:label="Filmes"/> | |
</application> | |
</manifest> |
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
package com.example.android.moviesroadaula1.add_movie; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.widget.EditText; | |
import com.example.android.moviesroadaula1.R; | |
import butterknife.BindView; | |
import butterknife.ButterKnife; | |
import butterknife.OnClick; | |
public class AddMovieActivity extends AppCompatActivity { | |
@BindView(R.id.edt_movie_name) | |
EditText movieName; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_add_movie); | |
ButterKnife.bind(this); | |
} | |
@OnClick(R.id.btn_movie_added) | |
public void movieAdded(){ | |
Intent resultIntent = new Intent(); | |
resultIntent.putExtra("movie_name", movieName.getText().toString()); | |
setResult(Activity.RESULT_OK, resultIntent); | |
finish(); | |
} | |
} |
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
package com.example.android.moviesroadaula1.login; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.design.widget.TextInputEditText; | |
import android.support.design.widget.TextInputLayout; | |
import android.support.v7.app.AppCompatActivity; | |
import com.example.android.moviesroadaula1.R; | |
import com.example.android.moviesroadaula1.movies.MoviesActivity; | |
import butterknife.BindView; | |
import butterknife.ButterKnife; | |
import butterknife.OnClick; | |
import butterknife.OnTextChanged; | |
public class LoginActivity extends AppCompatActivity implements LoginView { | |
@BindView(R.id.text_input_layout_username) TextInputLayout usernameTextInputLayout; | |
@BindView(R.id.edit_text_username) TextInputEditText usernameEditText; | |
@BindView(R.id.text_input_layout_password) TextInputLayout passwordTextInputLayout; | |
@BindView(R.id.edit_text_password) TextInputEditText passwordEditText; | |
LoginPresenter loginPresenter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_login); | |
ButterKnife.bind(this); | |
loginPresenter = new LoginPresenter(LoginActivity.this); | |
} | |
@OnTextChanged(R.id.edit_text_username) | |
public void validaUsuario(){ | |
usernameTextInputLayout.setErrorEnabled(false); | |
usernameTextInputLayout.setError(""); | |
} | |
@OnTextChanged(R.id.edit_text_password) | |
public void validaSenha(){ | |
passwordTextInputLayout.setErrorEnabled(false); | |
passwordTextInputLayout.setError(""); | |
} | |
@OnClick(R.id.button_login) | |
public void fazLogin(){ | |
loginPresenter.login( | |
usernameEditText.getText().toString(), | |
passwordEditText.getText().toString()); | |
} | |
public void setErroUsuario() { | |
usernameTextInputLayout.setErrorEnabled(true); | |
usernameTextInputLayout.setError(getString(R.string.invalid_username)); | |
} | |
public void setErroSenha() { | |
passwordTextInputLayout.setErrorEnabled(true); | |
passwordTextInputLayout.setError(getString(R.string.invalid_password)); | |
} | |
public void loginComSuccesso() { | |
Intent abirMoviesActivity = new Intent(LoginActivity.this, MoviesActivity.class); | |
startActivity(abirMoviesActivity); | |
} | |
} |
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
package com.example.android.moviesroadaula1.login; | |
import android.text.TextUtils; | |
public class LoginPresenter { | |
LoginView loginView; | |
public LoginPresenter(LoginView loginView){ | |
this.loginView = loginView; | |
} | |
public void login(String username, String password){ | |
if(TextUtils.isEmpty(username)){ | |
loginView.setErroUsuario(); | |
} else if(TextUtils.isEmpty(password)){ | |
loginView.setErroSenha(); | |
} else { | |
loginView.loginComSuccesso(); | |
} | |
} | |
} |
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
package com.example.android.moviesroadaula1.login; | |
public interface LoginView { | |
void setErroUsuario(); | |
void setErroSenha(); | |
void loginComSuccesso(); | |
} |
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
package com.example.android.moviesroadaula1.movies; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.View; | |
import android.widget.Toast; | |
import com.example.android.moviesroadaula1.R; | |
import com.example.android.moviesroadaula1.add_movie.AddMovieActivity; | |
import java.util.List; | |
import butterknife.BindView; | |
import butterknife.ButterKnife; | |
import butterknife.OnClick; | |
public class MoviesActivity extends AppCompatActivity implements MoviesView { | |
@BindView(R.id.rv_movies) | |
RecyclerView rvMovies; | |
MoviesPresenter moviesPresenter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_movies); | |
ButterKnife.bind(this); | |
moviesPresenter = new MoviesPresenter(this); | |
} | |
@OnClick(R.id.btn_add_movie) | |
public void addMovie(){ | |
Intent openAddMovieAcitivity = new Intent(this, AddMovieActivity.class); | |
startActivityForResult(openAddMovieAcitivity, 123); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
moviesPresenter.addMovieInList(requestCode, resultCode, data); | |
} | |
@Override | |
public void updateList(List<String> moviesList) { | |
//seta o adapter | |
MoviesAdapter moviesAdapter = new MoviesAdapter(moviesList); | |
moviesAdapter.setOnRecyclerViewSelected(new OnRecyclerViewSelected() { | |
@Override | |
public void onClick(View view, int position) { | |
Toast.makeText(MoviesActivity.this, "Clique Rápido", Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
public void onLongClick(View view, int position) { | |
Toast.makeText(MoviesActivity.this, "Clique Longo", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
rvMovies.setAdapter(moviesAdapter); | |
// criação do gerenciador de layouts | |
LinearLayoutManager layoutManager = new LinearLayoutManager(this); | |
rvMovies.setLayoutManager(layoutManager); | |
} | |
} |
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
package com.example.android.moviesroadaula1.movies; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import com.example.android.moviesroadaula1.R; | |
import java.util.List; | |
import butterknife.BindView; | |
import butterknife.ButterKnife; | |
import butterknife.OnClick; | |
import butterknife.OnLongClick; | |
public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.ViewHolder> { | |
private List<String> moviesList; | |
OnRecyclerViewSelected onRecyclerViewSelected; | |
//Construtor que recebe a lista | |
MoviesAdapter(List<String> moviesList) { | |
this.moviesList = moviesList; | |
} | |
//infla o componente view | |
@Override | |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.movie_item_list, parent, false); | |
return new ViewHolder(v); | |
} | |
//seta os dados nas views | |
@Override | |
public void onBindViewHolder(ViewHolder holder, int position) { | |
holder.txMovieName.setText(moviesList.get(position)); | |
//holder.imgBackgroud.setImageBitmap(); | |
} | |
//retorna o tamanho da lista | |
@Override | |
public int getItemCount() { | |
return moviesList.size(); | |
} | |
//mapeamento dos componentes da view | |
public class ViewHolder extends RecyclerView.ViewHolder { | |
@BindView(R.id.tx_movie_name) | |
TextView txMovieName; | |
@BindView(R.id.image_view_background) | |
ImageView imgBackgroud; | |
public ViewHolder(View itemView) { | |
super(itemView); | |
ButterKnife.bind(this, itemView); | |
} | |
//seta o clique rápido | |
@OnClick(R.id.container) | |
void onItemClick(View view){ | |
if(onRecyclerViewSelected != null) | |
onRecyclerViewSelected.onClick(view, getAdapterPosition()); | |
} | |
//seta o clique longo | |
@OnLongClick(R.id.container) | |
boolean onLongItemClick(View view){ | |
if(onRecyclerViewSelected != null) | |
onRecyclerViewSelected.onLongClick(view, getAdapterPosition()); | |
return true; | |
} | |
} | |
public void setOnRecyclerViewSelected(OnRecyclerViewSelected onRecyclerViewSelected){ | |
this.onRecyclerViewSelected = onRecyclerViewSelected; | |
} | |
} |
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
package com.example.android.moviesroadaula1.movies; | |
import android.app.Activity; | |
import android.content.Intent; | |
import java.util.ArrayList; | |
import java.util.List; | |
class MoviesPresenter { | |
private MoviesView moviesView; | |
private List<String> moviesList = new ArrayList<>(); | |
MoviesPresenter(MoviesView moviesView){ | |
this.moviesView = moviesView; | |
} | |
void addMovieInList(int requestCode, int resultCode, Intent data){ | |
if(requestCode == 123 && resultCode == Activity.RESULT_OK){ | |
String movieName = data.getStringExtra("movie_name"); | |
moviesList.add(movieName); | |
moviesView.updateList(moviesList); | |
} | |
} | |
} |
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
package com.example.android.moviesroadaula1.movies; | |
import java.util.List; | |
interface MoviesView { | |
void updateList(List<String> movieList); | |
} |
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
package com.example.android.moviesroadaula1.movies; | |
import android.view.View; | |
public interface OnRecyclerViewSelected { | |
void onClick(View view, int position); | |
void onLongClick(View view, int position); | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle"> | |
<corners android:radius="4dp" /> | |
<solid android:color="@color/havelock_blue" /> | |
</shape> |
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
<?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:orientation="vertical"> | |
<EditText | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/edt_movie_name" | |
android:hint="Filme"/> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/btn_movie_added" | |
android:text="OK"/> | |
</LinearLayout> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ScrollView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/oxford_blue"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:descendantFocusability="beforeDescendants" | |
android:focusableInTouchMode="true" | |
android:orientation="vertical" | |
android:paddingLeft="16dp" | |
android:paddingRight="16dp"> | |
<ImageView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_horizontal" | |
android:layout_marginTop="55dp" | |
android:contentDescription="@null" | |
android:src="@drawable/logo" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginTop="25dp" | |
android:fontFamily="sans-serif-light" | |
android:text="@string/series_movies_and_news" | |
android:textAllCaps="true" | |
android:textColor="@color/blue_chalk" | |
android:textSize="18sp" /> | |
<android.support.design.widget.TextInputLayout | |
android:id="@+id/text_input_layout_username" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="41dp" | |
android:textColorHint="@color/white"> | |
<android.support.design.widget.TextInputEditText | |
android:id="@+id/edit_text_username" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:inputType="text" | |
android:hint="@string/username" | |
android:maxLines="1" | |
android:lines="1" | |
android:textColor="@color/white" | |
android:textSize="16sp" | |
android:imeOptions="actionNext" /> | |
</android.support.design.widget.TextInputLayout> | |
<android.support.design.widget.TextInputLayout | |
android:id="@+id/text_input_layout_password" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="20dp" | |
android:textColorHint="@color/white"> | |
<android.support.design.widget.TextInputEditText | |
android:id="@+id/edit_text_password" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/password" | |
android:inputType="textPassword" | |
android:maxLines="1" | |
android:lines="1" | |
android:textColor="@color/white" | |
android:textSize="16sp" /> | |
</android.support.design.widget.TextInputLayout> | |
<Button | |
android:id="@+id/button_login" | |
android:layout_width="match_parent" | |
android:layout_height="50dp" | |
android:layout_marginBottom="33dp" | |
android:layout_marginLeft="29dp" | |
android:layout_marginRight="29dp" | |
android:layout_marginTop="48dp" | |
android:background="@drawable/havelock_blue_rounded_corners" | |
android:fontFamily="sans-serif-bold" | |
android:text="@string/sign_in" | |
android:textAllCaps="false" | |
android:textColor="@color/white" | |
android:textSize="17sp" /> | |
</LinearLayout> | |
</ScrollView> | |
</RelativeLayout> |
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
<?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:orientation="vertical"> | |
<android.support.v7.widget.RecyclerView | |
android:id="@+id/rv_movies" | |
android:scrollbars="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:layout_weight="9"/> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:layout_weight="1" | |
android:id="@+id/btn_add_movie" | |
android:text="Adicionar Filme"/> | |
</LinearLayout> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="155dp" | |
android:id="@+id/container" > | |
<View | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/alpha_black_50" /> | |
<ImageView | |
android:id="@+id/image_view_background" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:contentDescription="@null" /> | |
<TextView | |
android:id="@+id/tx_movie_name" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerInParent="true" | |
android:layout_marginLeft="5dp" | |
android:layout_marginRight="5dp" | |
android:ellipsize="end" | |
android:fontFamily="sans-serif-light" | |
android:maxLines="1" | |
android:textAllCaps="true" | |
android:textColor="@color/white" | |
android:textSize="27sp" /> | |
</RelativeLayout> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<color name="colorPrimary">@color/havelock_blue</color> | |
<color name="colorPrimaryDark">@color/steel_blue</color> | |
<color name="colorAccent">@color/white</color> | |
<color name="white">#FFFFFF</color> | |
<color name="blue_chalk">#ECD7FF</color> | |
<color name="havelock_blue">#4A90E2</color> | |
<color name="steel_blue">#3b73b4</color> | |
<color name="saphire">#303F9F</color> | |
<color name="cloud_burst">#213449</color> | |
<color name="oxford_blue">#32404f</color> | |
<color name="oxford_blue_dark">#2c3946</color> | |
<color name="alpha_black_50">#80000000</color> | |
<color name="alpha_white_12">#1effffff</color> | |
</resources> |
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
<resources> | |
<string name="app_name">@string/movies_road</string> | |
<string name="series_movies_and_news">Séries, filmes e novidades</string> | |
<string name="username">Nome de usuário</string> | |
<string name="password">Senha</string> | |
<string name="sign_in">Entrar</string> | |
<string name="invalid_username">Usuário inválido</string> | |
<string name="invalid_password">Senha inválida</string> | |
<string name="movies_road">Movies Road</string> | |
<string name="sinopse">Sinopse</string> | |
</resources> |
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
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<!-- Customize your theme here. --> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="colorControlActivated">@color/colorAccent</item> | |
<item name="colorControlHighlight">@color/colorAccent</item> | |
</style> | |
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar"> | |
<!-- Customize your theme here. --> | |
<item name="colorPrimary">@color/oxford_blue</item> | |
<item name="colorPrimaryDark">@color/oxford_blue_dark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="colorControlNormal">@color/alpha_white_12</item> | |
<item name="colorControlActivated">@color/colorAccent</item> | |
<item name="colorControlHighlight">@color/colorAccent</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment