diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b75303 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2996d53 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/android_sprint1_challenge/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/android_sprint1_challenge/ExampleInstrumentedTest.java new file mode 100644 index 0000000..48457a9 --- /dev/null +++ b/app/src/androidTest/java/com/example/android_sprint1_challenge/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.android_sprint1_challenge; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.android_sprint1_challenge", appContext.getPackageName()); + } +} diff --git a/app/src/main/java/com/example/android_sprint1_challenge/AddNewMovie.java b/app/src/main/java/com/example/android_sprint1_challenge/AddNewMovie.java new file mode 100644 index 0000000..9698512 --- /dev/null +++ b/app/src/main/java/com/example/android_sprint1_challenge/AddNewMovie.java @@ -0,0 +1,100 @@ +package com.example.android_sprint1_challenge; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.graphics.Movie; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Switch; +import android.widget.TextView; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class AddNewMovie extends AppCompatActivity implements Serializable { + private MovieEntry movie; + private EditText movieTitleEntry; + private Switch watchedSwitch; + private Button saveButton; + private Button deleteButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_movie_deltails); + + movieTitleEntry = findViewById(R.id.movie_edit_text); + watchedSwitch = findViewById(R.id.watched_switch); + saveButton = findViewById(R.id.button_save); + deleteButton = findViewById(R.id.button_delete); + + } + + @Override + protected void onResume() { + super.onResume(); + + Intent intent = getIntent(); + if (intent.hasExtra(MovieEntry.MOVIE_TAG)) { + movie = (MovieEntry) intent.getSerializableExtra(MovieEntry.MOVIE_TAG); + movieTitleEntry.setText(movie.getMovieName()); + watchedSwitch.setChecked(movie.isWatched()); + } else { + movie = new MovieEntry(); + } + + movieTitleEntry.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + String name = s.toString(); + movie.setMovieName(name); + } + }); + + + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onSavePressed(movie); + } + }); + + deleteButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent saveIntent = new Intent(); + saveIntent.putExtra(MovieEntry.MOVIE_TAG, movie); + setResult(Activity.RESULT_CANCELED, saveIntent); + finish(); + } + }); + } + + protected void onSavePressed(MovieEntry movie) { + if (movie != null) { + movie.setWatched(watchedSwitch.isChecked()); + Intent saveIntent = new Intent(); + saveIntent.putExtra(MovieEntry.MOVIE_TAG, movie); + setResult(Activity.RESULT_OK, saveIntent); + finish(); + } else { onBackPressed(); } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/android_sprint1_challenge/MovieEntry.java b/app/src/main/java/com/example/android_sprint1_challenge/MovieEntry.java new file mode 100644 index 0000000..81ce597 --- /dev/null +++ b/app/src/main/java/com/example/android_sprint1_challenge/MovieEntry.java @@ -0,0 +1,51 @@ +package com.example.android_sprint1_challenge; + +import java.io.Serializable; + +public class MovieEntry implements Serializable { + public static final String MOVIE_TAG = "tagThis"; + + private String movieName; + private int movieId; + private boolean isWatched; + + + public MovieEntry(String movieName, int movieId, boolean isWatched) { + this.movieName = movieName; + this.movieId = movieId; + this.isWatched = isWatched; + } + + + public String getMovieName() { + return movieName; + } + + public int getMovieId() { + return movieId; + } + + + + public void setMovieName(String movieName) { + this.movieName = movieName; + } + + + public void setMovieId(int movieId) { + this.movieId = movieId; + } + + public boolean isWatched() { + return isWatched; + } + + public void setWatched(boolean watched) { + isWatched = watched; + } + + public MovieEntry() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/android_sprint1_challenge/MovieListActivity.java b/app/src/main/java/com/example/android_sprint1_challenge/MovieListActivity.java new file mode 100644 index 0000000..4ef2816 --- /dev/null +++ b/app/src/main/java/com/example/android_sprint1_challenge/MovieListActivity.java @@ -0,0 +1,132 @@ +package com.example.android_sprint1_challenge; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.graphics.Typeface; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.w3c.dom.Text; + +import java.io.Serializable; +import java.util.ArrayList; + +public class MovieListActivity extends AppCompatActivity implements Serializable { + Context context; + LinearLayout movieListView; + + public static final int ADD_IMAGE_REQUEST = 2; + public static final int EDIT_IMAGE_REQUEST =3; + + private int movieIndex; + private ArrayList movies; + private ArrayList movieViews; + + + + +// @Override +// protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { +// if(resultCode == RESULT_OK && requestCode == ACTIVITY_REQUEST_CODE) { +// if (data != null) { + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_movie_list); + context = this; + movies = new ArrayList<>(); + movieViews = new ArrayList<>(); + movieListView = findViewById(R.id.list_view); + + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + FloatingActionButton fab = findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent addMovieIntent = new Intent(context, AddNewMovie.class); + startActivityForResult(addMovieIntent, ADD_IMAGE_REQUEST); + } + }); + + + + } + + @Override + protected void onResume() { + super.onResume(); + if(movieListView!= null) {movieListView.removeAllViews();} + for (TextView movieView : movieViews){ + movieListView.addView(movieView); + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + if (resultCode == Activity.RESULT_OK && requestCode == ADD_IMAGE_REQUEST) { + if (data != null) { + MovieEntry newMovie = (MovieEntry) data.getSerializableExtra(MovieEntry.MOVIE_TAG); + if (newMovie.getMovieName() != null) { + newMovie.setMovieId(movieIndex++); + movies.add(newMovie); + TextView newMovieView = createTextView(newMovie); + movieViews.add(newMovieView); + } + } + } + + if(resultCode ==Activity.RESULT_OK && requestCode == EDIT_IMAGE_REQUEST){ + if (data != null) { + MovieEntry editedMovie = (MovieEntry) data.getSerializableExtra(MovieEntry.MOVIE_TAG); + movies.set(editedMovie.getMovieId(), editedMovie); + TextView editedMovieView = createTextView(editedMovie); + movieViews.set(editedMovie.getMovieId(), editedMovieView); + } + } + if (resultCode == Activity.RESULT_CANCELED && requestCode == EDIT_IMAGE_REQUEST){ + if(data !=null){ + MovieEntry deletedMovie = (MovieEntry) data.getSerializableExtra(MovieEntry.MOVIE_TAG); + movies.remove(deletedMovie.getMovieId()); + movieViews.remove(deletedMovie.getMovieId()); + for (int i = deletedMovie.getMovieId(); i < movies.size(); i++) { + movies.get(i).setMovieId(i); + }} + + } + } + + + + + + private TextView createTextView(final MovieEntry movie) { + TextView movieView = new TextView(context); + movieView.setText(movie.getMovieName()); + if (movie.isWatched()) { + movieView.setTextColor(getResources().getColor(android.R.color.holo_green_light)); + } else { movieView.setTextColor(getResources().getColor(android.R.color.holo_red_dark)); } + movieView.setTextSize(30); + movieView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent editIntent = new Intent(context, AddNewMovie.class); + editIntent.putExtra(MovieEntry.MOVIE_TAG, movie); + startActivityForResult(editIntent, EDIT_IMAGE_REQUEST); + } + }); + return movieView; + } +} diff --git a/app/src/main/java/com/example/android_sprint1_challenge/MovieRepo.java b/app/src/main/java/com/example/android_sprint1_challenge/MovieRepo.java new file mode 100644 index 0000000..6590a07 --- /dev/null +++ b/app/src/main/java/com/example/android_sprint1_challenge/MovieRepo.java @@ -0,0 +1,14 @@ +package com.example.android_sprint1_challenge; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +public class MovieRepo { + public static List allMovies = new ArrayList<>(); + + public List getAllMovies(){ + return allMovies; + } + +} diff --git a/app/src/main/res/layout/activity_movie_deltails.xml b/app/src/main/res/layout/activity_movie_deltails.xml new file mode 100644 index 0000000..2ced293 --- /dev/null +++ b/app/src/main/res/layout/activity_movie_deltails.xml @@ -0,0 +1,69 @@ + + + + + + + +