diff --git a/Sprint1/.gitignore b/Sprint1/.gitignore new file mode 100644 index 0000000..2b75303 --- /dev/null +++ b/Sprint1/.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/Sprint1/.idea/codeStyles/Project.xml b/Sprint1/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/Sprint1/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint1/.idea/gradle.xml b/Sprint1/.idea/gradle.xml new file mode 100644 index 0000000..2996d53 --- /dev/null +++ b/Sprint1/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/Sprint1/.idea/misc.xml b/Sprint1/.idea/misc.xml new file mode 100644 index 0000000..af0bbdd --- /dev/null +++ b/Sprint1/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint1/.idea/runConfigurations.xml b/Sprint1/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/Sprint1/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Sprint1/.idea/vcs.xml b/Sprint1/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Sprint1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sprint1/app/.gitignore b/Sprint1/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/Sprint1/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/Sprint1/app/build.gradle b/Sprint1/app/build.gradle new file mode 100644 index 0000000..38aff12 --- /dev/null +++ b/Sprint1/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.example.israel.sprint1" + minSdkVersion 21 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/Sprint1/app/proguard-rules.pro b/Sprint1/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/Sprint1/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/Sprint1/app/src/androidTest/java/com/example/israel/sprint1/ExampleInstrumentedTest.java b/Sprint1/app/src/androidTest/java/com/example/israel/sprint1/ExampleInstrumentedTest.java new file mode 100644 index 0000000..d97b48c --- /dev/null +++ b/Sprint1/app/src/androidTest/java/com/example/israel/sprint1/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.israel.sprint1; + +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.israel.sprint1", appContext.getPackageName()); + } +} diff --git a/Sprint1/app/src/main/AndroidManifest.xml b/Sprint1/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9660fe8 --- /dev/null +++ b/Sprint1/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint1/app/src/main/java/com/example/israel/sprint1/Movie.java b/Sprint1/app/src/main/java/com/example/israel/sprint1/Movie.java new file mode 100644 index 0000000..25cb54f --- /dev/null +++ b/Sprint1/app/src/main/java/com/example/israel/sprint1/Movie.java @@ -0,0 +1,29 @@ +package com.example.israel.sprint1; + +import java.io.Serializable; + +public class Movie implements Serializable { + private String name; + private boolean isWatched; + + public Movie(String name, boolean isWatched) { + this.name = name; + this.isWatched = isWatched; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isWatched() { + return isWatched; + } + + public void setWatched(boolean isWatched) { + this.isWatched = isWatched; + } +} diff --git a/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieDetailsActivity.java b/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieDetailsActivity.java new file mode 100644 index 0000000..d10ac06 --- /dev/null +++ b/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieDetailsActivity.java @@ -0,0 +1,90 @@ +package com.example.israel.sprint1; + +import android.content.Intent; +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.CompoundButton; +import android.widget.EditText; +import android.widget.Switch; + +public class MovieDetailsActivity extends AppCompatActivity { + + private Movie movie; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_movie_details); + + Intent intent = getIntent(); + + movie = (Movie)intent.getSerializableExtra(MovieListActivity.MOVIE_KEY); + + // adding a movie + if (movie == null) { + movie = new Movie("", false); + } + + // name + EditText movieNameEditText = findViewById(R.id.edit_text_movie_name); + movieNameEditText.setText(movie.getName()); + movieNameEditText.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) { + movie.setName(s.toString()); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + // isWatched + Switch isWatchedSwitch = findViewById(R.id.switch_is_watched); + isWatchedSwitch.setChecked(movie.isWatched()); + isWatchedSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + movie.setWatched(isChecked); + } + }); + + // delete + Button deleteButton = findViewById(R.id.button_delete); + deleteButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // no need to send back anything since we're just deleting + setResult(MovieListActivity.RESULT_CODE_MOVIE_EDIT_DELETE); + finishActivity(MovieListActivity.REQUEST_CODE_MOVIE_EDIT); + finish(); + + } + }); + + // save + Button saveButton = findViewById(R.id.button_save); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // return the edited/added movie + Intent resultIntent = new Intent(); + resultIntent.putExtra(MovieListActivity.MOVIE_KEY, movie); + setResult(MovieListActivity.RESULT_CODE_MOVIE_EDIT_SAVE, resultIntent); + finishActivity(MovieListActivity.REQUEST_CODE_MOVIE_EDIT); + finish(); + } + }); + + } +} diff --git a/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieListActivity.java b/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieListActivity.java new file mode 100644 index 0000000..166388f --- /dev/null +++ b/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieListActivity.java @@ -0,0 +1,108 @@ +package com.example.israel.sprint1; + +import android.content.Intent; +import android.graphics.Paint; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.TypedValue; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.ArrayList; + +public class MovieListActivity extends AppCompatActivity { + + public static final String MOVIE_KEY = "movie"; + public static final int REQUEST_CODE_MOVIE_EDIT = 0; + public static final int RESULT_CODE_MOVIE_EDIT_DELETE = 0; + public static final int RESULT_CODE_MOVIE_EDIT_SAVE = 1; + + private LinearLayout movieListLinearLayout; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + movieListLinearLayout = findViewById(R.id.linear_layout_movie_list); + + Button addMovieButton = findViewById(R.id.button_add_movie); + addMovieButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MovieListActivity.this, MovieDetailsActivity.class); + // adding a movie, no need to send data + startActivityForResult(intent, REQUEST_CODE_MOVIE_EDIT); + } + }); + +// // create dummy movies +// addMovie(new Movie("Dino", true)); +// addMovie(new Movie("Dragon", false)); + + // populate movie lists of movies from the repo + ArrayList movies = MovieRepository.getMovies(); + for (Movie movie : movies) { + addMovie(movie); + } + + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent intent) { + super.onActivityResult(requestCode, resultCode, intent); + + if (intent == null) { // this will actually delete the movie + return; + } + + switch (requestCode) { + case REQUEST_CODE_MOVIE_EDIT: { + if (resultCode == RESULT_CODE_MOVIE_EDIT_SAVE) { + Movie movie = (Movie)intent.getSerializableExtra(MOVIE_KEY); + if (movie != null) { + addMovie(movie); // add the movie that was returned + } + } // delete textView. the text view was already deleted when the details activity was opened + } break; + } + } + + private void addMovie(Movie movie) { + MovieRepository.addMovie(movie); + createTextView(movie); + } + + private void createTextView(final Movie movie) { + TextView newTextView = new TextView(this); + newTextView.setTag(movie); + newTextView.setText(movie.getName()); + newTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 25.f); + // draw a strike-through if this movie has been watched + if (movie.isWatched()) { + newTextView.setPaintFlags(newTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); + } + + movieListLinearLayout.addView(newTextView); + + newTextView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MovieListActivity.this, MovieDetailsActivity.class); + intent.putExtra(MOVIE_KEY, movie); + startActivityForResult(intent, REQUEST_CODE_MOVIE_EDIT); + + // remove movie. this will be added later if it is saved + MovieRepository.removeMovie((Movie)v.getTag()); + + // remove the textView + ViewGroup viewGroup = (ViewGroup)v.getParent(); + viewGroup.removeView(v); + } + }); + } +} diff --git a/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieRepository.java b/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieRepository.java new file mode 100644 index 0000000..126f5b9 --- /dev/null +++ b/Sprint1/app/src/main/java/com/example/israel/sprint1/MovieRepository.java @@ -0,0 +1,21 @@ +package com.example.israel.sprint1; + +import java.util.ArrayList; + +public class MovieRepository { + + static private ArrayList movies = new ArrayList<>(); + + static public ArrayList getMovies() { + return movies; + } + + static public void addMovie(Movie movie) { + movies.add(movie); + } + + static public void removeMovie(Movie movie) { + movies.remove(movie); + } + +} diff --git a/Sprint1/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Sprint1/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/Sprint1/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/Sprint1/app/src/main/res/drawable/ic_launcher_background.xml b/Sprint1/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/Sprint1/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sprint1/app/src/main/res/layout/activity_main.xml b/Sprint1/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..3c49476 --- /dev/null +++ b/Sprint1/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + +