-
-
Save jemaf/cb31d8db62dd1bf79c043f60cedc3db8 to your computer and use it in GitHub Desktop.
Versão final da atividade de criação de novos vídeos.
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 edu.ifmg.eati.movieme; | |
import android.content.Intent; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.ListView; | |
import edu.ifmg.eati.movieme.model.Movie; | |
public class MainActivity extends AppCompatActivity { | |
private static final int NEW_MOVIE_CODE = 1; | |
MoviesAdapter adapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ListView moviesList = (ListView) findViewById(R.id.movies_list); | |
adapter = new MoviesAdapter(this); | |
moviesList.setAdapter(adapter); | |
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.btn_new_movie); | |
fab.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent intent = new Intent(MainActivity.this, NewMovieActivity.class); | |
startActivityForResult(intent, NEW_MOVIE_CODE); | |
} | |
}); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == NEW_MOVIE_CODE && resultCode == RESULT_OK) { | |
String name = data.getStringExtra("name"); | |
int rating = data.getIntExtra("rating", -1); | |
String comment = data.getStringExtra("comment"); | |
Movie newMovie = new Movie(name, rating, comment); | |
adapter.addNewMovie(newMovie); | |
} | |
} | |
} |
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 edu.ifmg.eati.movieme; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
import edu.ifmg.eati.movieme.model.Movie; | |
/** | |
* Created by edumontandon on 5/17/16. | |
*/ | |
public class MoviesAdapter extends BaseAdapter { | |
// Lista de filmes a serem exibidos | |
private ArrayList<Movie> movies; | |
private Context context; | |
public MoviesAdapter(Context context) { | |
this.context = context; | |
this.movies = new ArrayList<>(); | |
loadMovies(); | |
} | |
private void loadMovies() { | |
this.movies.add(new Movie("Star Wars", 7, "Filme clássico")); | |
this.movies.add(new Movie("Senhor dos Anéis", 10, "ÉPICO!!")); | |
this.movies.add(new Movie("A Origem", 9, "Mind Blowing")); | |
this.movies.add(new Movie("Pulp Fiction", 8, "Obra prima")); | |
this.movies.add(new Movie("Se eu fosse você", 3, "Se eu fosse você... não pederia seu tempo")); | |
} | |
@Override | |
public int getCount() { | |
return this.movies.size(); | |
} | |
@Override | |
public Object getItem(int position) { | |
return this.movies.get(position); | |
} | |
@Override | |
public long getItemId(int position) { | |
return position; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
// obtem o filme desejado | |
Movie movie = this.movies.get(position); | |
View view = LayoutInflater.from(this.context).inflate(R.layout.adapter_movies, parent, false); | |
TextView lblName = (TextView) view.findViewById(R.id.lbl_movie_name); | |
TextView lblGrade = (TextView) view.findViewById(R.id.lbl_movie_grade); | |
TextView lblComment = (TextView) view.findViewById(R.id.lbl_movie_comment); | |
lblName.setText(movie.getName()); | |
lblGrade.setText(String.valueOf(movie.getRating())); | |
lblComment.setText(movie.getComment()); | |
return view; | |
} | |
public void addNewMovie(Movie newMovie) { | |
this.movies.add(newMovie); | |
// atualiza o adapter com o novo filme | |
this.notifyDataSetChanged(); | |
} | |
} |
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 edu.ifmg.eati.movieme; | |
import android.content.Intent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.SeekBar; | |
import android.widget.Toast; | |
public class NewMovieActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_new_movie); | |
final EditText txtName = (EditText) findViewById(R.id.txt_movie_name); | |
final SeekBar skRating = (SeekBar) findViewById(R.id.sk_movie_rating); | |
final EditText txtComment = (EditText) findViewById(R.id.txt_comment); | |
Button okButton = (Button) findViewById(R.id.btn_new_movie); | |
okButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent returnIntent = new Intent(); | |
returnIntent.putExtra("name", txtName.getText().toString()); | |
returnIntent.putExtra("rating", skRating.getProgress()); | |
returnIntent.putExtra("comment", txtComment.getText().toString()); | |
setResult(RESULT_OK, returnIntent); | |
Toast.makeText(NewMovieActivity.this, "Filme cadastrado com sucesso", Toast.LENGTH_LONG).show(); | |
NewMovieActivity.this.finish(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment