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..af0bbdd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ 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/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..9632260 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.vivekvishwanath.movie_list" + 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/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/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/app/src/androidTest/java/com/vivekvishwanath/movie_list/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/vivekvishwanath/movie_list/ExampleInstrumentedTest.java new file mode 100644 index 0000000..9f79752 --- /dev/null +++ b/app/src/androidTest/java/com/vivekvishwanath/movie_list/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.vivekvishwanath.movie_list; + +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.vivekvishwanath.movie_list", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..af55e5a --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/vivekvishwanath/movie_list/EditActivity.java b/app/src/main/java/com/vivekvishwanath/movie_list/EditActivity.java new file mode 100644 index 0000000..8ef6504 --- /dev/null +++ b/app/src/main/java/com/vivekvishwanath/movie_list/EditActivity.java @@ -0,0 +1,92 @@ +package com.vivekvishwanath.movie_list; + +import android.app.Activity; +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.EditText; +import android.widget.Switch; + +public class EditActivity extends AppCompatActivity { + + private Movie 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_edit); + + movieTitleEntry = findViewById(R.id.movie_title_entry); + watchedSwitch = findViewById(R.id.watched_switch); + saveButton = findViewById(R.id.save_button); + deleteButton = findViewById(R.id.delete_button); + + } + + @Override + protected void onResume() { + super.onResume(); + + Intent intent = getIntent(); + if (intent.hasExtra(Movie.MOVIE_TAG)) { + movie = (Movie) intent.getSerializableExtra(Movie.MOVIE_TAG); + movieTitleEntry.setText(movie.getMovieTitle()); + watchedSwitch.setChecked(movie.isWatched()); + } else { + movie = new Movie(); + } + + 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) { + movie.setMovieTitle(s.toString()); + } + }); + + + 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(Movie.MOVIE_TAG, movie); + setResult(Activity.RESULT_CANCELED, saveIntent); + finish(); + } + }); + } + + protected void onSavePressed(Movie movie) { + if (movie != null) { + movie.setWatched(watchedSwitch.isChecked()); + Intent saveIntent = new Intent(); + saveIntent.putExtra(Movie.MOVIE_TAG, movie); + setResult(Activity.RESULT_OK, saveIntent); + finish(); + } else { onBackPressed(); } + } +} diff --git a/app/src/main/java/com/vivekvishwanath/movie_list/ListActivity.java b/app/src/main/java/com/vivekvishwanath/movie_list/ListActivity.java new file mode 100644 index 0000000..dd423b7 --- /dev/null +++ b/app/src/main/java/com/vivekvishwanath/movie_list/ListActivity.java @@ -0,0 +1,119 @@ +package com.vivekvishwanath.movie_list; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.w3c.dom.Text; + +import java.util.ArrayList; + +public class ListActivity extends AppCompatActivity { + Context context; + LinearLayout movieListView; + Button addMovieButton; + private int watchedColor = android.R.color.holo_green_dark; + private int unwatchedColor = android.R.color.holo_red_dark; + + public static final int ADD_IMAGE_REQUEST = 2; + public static final int EDIT_IMAGE_REQUEST =3; + + private ArrayList movies; + private ArrayList movieViews; + + private int currentIndex; + + private int movieIndex; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_list); + context = this; + + movies = new ArrayList<>(); + movieViews = new ArrayList<>(); + + addMovieButton = findViewById(R.id.add_movie_button); + movieListView = findViewById(R.id.movie_list_view); + + addMovieButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent addMovieIntent = new Intent(context, EditActivity.class); + startActivityForResult(addMovieIntent, ADD_IMAGE_REQUEST); + } + }); + } + + @Override + protected void onResume() { + super.onResume(); + + 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) { + Movie newMovie = (Movie) data.getSerializableExtra(Movie.MOVIE_TAG); + if (newMovie.getMovieTitle() != null) { + newMovie.setMovieId(movieIndex++); + movies.add(newMovie); + TextView newMovieView = createMovieView(newMovie); + movieViews.add(newMovieView); + } + } + } + + if (resultCode == Activity.RESULT_OK && requestCode == EDIT_IMAGE_REQUEST) { + if (data != null) { + Movie editedMovie = (Movie) data.getSerializableExtra(Movie.MOVIE_TAG); + movies.set(editedMovie.getMovieId(), editedMovie); + TextView editedMovieView = createMovieView(editedMovie); + movieViews.set(editedMovie.getMovieId(), editedMovieView); + } + } + + if (resultCode == Activity.RESULT_CANCELED && requestCode == EDIT_IMAGE_REQUEST){ + Movie deletedMovie = (Movie) data.getSerializableExtra(Movie.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 createMovieView(final Movie movie) { + TextView movieView = new TextView(context); + movieView.setText(movie.getMovieTitle()); + if (movie.isWatched()) { + movieView.setTextColor(getResources().getColor(watchedColor)); + } else { movieView.setTextColor(getResources().getColor(unwatchedColor)); } + movieView.setTextSize(20); + movieView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent editIntent = new Intent(context, EditActivity.class); + editIntent.putExtra(Movie.MOVIE_TAG, movie); + startActivityForResult(editIntent, EDIT_IMAGE_REQUEST); + } + }); + return movieView; + } +} + diff --git a/app/src/main/java/com/vivekvishwanath/movie_list/Movie.java b/app/src/main/java/com/vivekvishwanath/movie_list/Movie.java new file mode 100644 index 0000000..8c28a53 --- /dev/null +++ b/app/src/main/java/com/vivekvishwanath/movie_list/Movie.java @@ -0,0 +1,45 @@ +package com.vivekvishwanath.movie_list; + +import java.io.Serializable; + +public class Movie implements Serializable { + + private String movieTitle; + private int movieId; + private boolean isWatched; + public static final String MOVIE_TAG = "Movie"; + + public Movie(String movieTitle, int movieId, boolean isWatched) { + this.movieTitle = movieTitle; + this.movieId = movieId; + this.isWatched = isWatched; + } + + public Movie() { + + } + + public String getMovieTitle() { + return movieTitle; + } + + public void setMovieTitle(String movieTitle) { + this.movieTitle = movieTitle; + } + + public int getMovieId() { + return movieId; + } + + public void setMovieId(int movieId) { + this.movieId = movieId; + } + + public boolean isWatched() { + return isWatched; + } + + public void setWatched(boolean watched) { + isWatched = watched; + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml new file mode 100644 index 0000000..1ca9304 --- /dev/null +++ b/app/src/main/res/layout/activity_edit.xml @@ -0,0 +1,55 @@ + + + + + + + + + +