diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39b6783 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md 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..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0d5b93 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ 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..a6302fc --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.lambdaschool.movieslist" + minSdkVersion 21 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.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' + implementation 'com.android.support:design:28.0.0' + 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' + implementation 'android.arch.lifecycle:extensions:1.1.1' + implementation 'android.arch.lifecycle:viewmodel:1.1.1' +} 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/example/patrickjmartin/android_sprint1_challenge/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/patrickjmartin/android_sprint1_challenge/ExampleInstrumentedTest.java new file mode 100644 index 0000000..8ca6d7a --- /dev/null +++ b/app/src/androidTest/java/com/example/patrickjmartin/android_sprint1_challenge/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.patrickjmartin.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.patrickjmartin.android_sprint1_challenge", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..eb4ecb7 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/AddDetails.java b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/AddDetails.java new file mode 100644 index 0000000..abdcd88 --- /dev/null +++ b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/AddDetails.java @@ -0,0 +1,72 @@ +package com.example.patrickjmartin.android_sprint1_challenge; + +import android.app.Activity; +import android.content.Context; +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.Switch; + +import com.lambdaschool.movieslist.R; + +public class AddDetails extends AppCompatActivity { + + + public static final String EDIT_MOVIE_KEY = "edit_movie"; + + private Movie movie; + private Switch watchSwitch; + private EditText movieTitle; + private Button deleteMovie, saveMovie; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_details); + + movieTitle = findViewById(R.id.editText); + deleteMovie = findViewById(R.id.button_delete); + saveMovie = findViewById(R.id.button_save); + watchSwitch = findViewById(R.id.switch1); + + + movie = (Movie) getIntent().getSerializableExtra(EDIT_MOVIE_KEY); + if(movie == null){ + movie = new Movie(Movie.NO_ID); + } + movieTitle.setText(movie.getTitle()); + watchSwitch.setChecked(movie.isWatched()); + } + + + + @Override + protected void onResume() { + super.onResume(); + + saveMovie.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + movie.setTitle(movieTitle.getText().toString()); + movie.setWatched(watchSwitch.isChecked()); + Intent editIntent = new Intent(); + editIntent.putExtra(EDIT_MOVIE_KEY, movie); + setResult(Activity.RESULT_OK, editIntent); + finish(); + } + }); + + deleteMovie.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + movie.setId(Movie.NO_ID); + finish(); + } + }); + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MainActivity.java b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MainActivity.java new file mode 100644 index 0000000..a9d8795 --- /dev/null +++ b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MainActivity.java @@ -0,0 +1,102 @@ +package com.example.patrickjmartin.android_sprint1_challenge; + +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; +import android.content.Context; +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.Log; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.lambdaschool.movieslist.R; +import com.lambdaschool.movieslist.apiaccess.MovieOverview; + +import java.util.ArrayList; + +public class MainActivity extends AppCompatActivity { + + LinearLayout layoutList; + MovieViewModel viewModel; + Context context; + public static final int EDIT_MOVIE_REQUEST_CODE = 5; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + layoutList = findViewById(R.id.layout_list); + context = this; + + viewModel = ViewModelProviders.of(this).get(MovieViewModel.class); + final Observer> observer = new Observer>() { + @Override + public void onChanged(@Nullable ArrayList movies) { + if (movies != null) { + refreshListView(movies); + } + } + }; + + viewModel.getOverViewList().observe(this, observer); + + findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent addMovieIntent = new Intent(context, AddDetails.class); + Movie movie = new Movie(Movie.NO_ID); + addMovieIntent.putExtra(AddDetails.EDIT_MOVIE_KEY, movie); + startActivityForResult(addMovieIntent, EDIT_MOVIE_REQUEST_CODE); + } + }); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK){ + if(requestCode == EDIT_MOVIE_REQUEST_CODE ) { + if(data != null) { + Movie retMovie = (Movie) data.getSerializableExtra(AddDetails.EDIT_MOVIE_KEY); + viewModel.addMovie(retMovie); + } + } + } + } + + private TextView getDefaultTextView(final Movie movie) { + TextView textView = new TextView(context); + textView.setText(movie.getTitle()); + boolean watched = movie.isWatched(); + + if (watched) { + textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); + } + + textView.setTextSize(24); + textView.setPadding(10, 10, 10, 10); + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + viewModel.removeMovie(movie); + Intent editMovieIntent = new Intent(context, AddDetails.class); + editMovieIntent.putExtra(AddDetails.EDIT_MOVIE_KEY, movie); + startActivityForResult(editMovieIntent, EDIT_MOVIE_REQUEST_CODE); + + } + }); + return textView; + } + + private void refreshListView(ArrayList movies) { + layoutList.removeAllViews(); + for (Movie movie : movies) { + layoutList.addView(getDefaultTextView(movie)); + } + } +} diff --git a/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/Movie.java b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/Movie.java new file mode 100644 index 0000000..4660151 --- /dev/null +++ b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/Movie.java @@ -0,0 +1,52 @@ +package com.example.patrickjmartin.android_sprint1_challenge; + +import java.io.Serializable; + +public class Movie implements Serializable { + + public static final int NO_ID = -1; + + private String title; + private boolean watched; + private int id; + + public Movie(int id, String title, boolean watched){ + this.id = id; + this.title = title; + this.watched = watched; + } + + public Movie(int id){ + this.id = id; + } + + public static int getNoId() { + return NO_ID; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public boolean isWatched() { + return watched; + } + + public void setWatched(boolean watched) { + this.watched = watched; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + +} diff --git a/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MovieRepo.java b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MovieRepo.java new file mode 100644 index 0000000..9740fc9 --- /dev/null +++ b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MovieRepo.java @@ -0,0 +1,41 @@ +package com.example.patrickjmartin.android_sprint1_challenge; + +import android.arch.lifecycle.MutableLiveData; + +import java.util.ArrayList; + +public class MovieRepo { + + + private ArrayList movies; + + public MovieRepo(){ + this.movies = new ArrayList<>(); + } + + public MutableLiveData> getOverviewList() { + MutableLiveData> liveDataList = new MutableLiveData<>(); + liveDataList.setValue(movies); + return liveDataList; + } + + public ArrayList addMovie(Movie movie){ + if(movie.getId() == Movie.NO_ID) { + int movieIndex = movies.size(); + movie.setId((movieIndex)); + } + movies.add(movie); + return movies; + } + + + public ArrayList removeMovie(Movie movie) { + for (int i = 0; i < movies.size(); i++) { + if (movies.get(i).getId() == movie.getId()) { + movies.remove(i); + } + } + return movies; + } + +} diff --git a/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MovieViewModel.java b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MovieViewModel.java new file mode 100644 index 0000000..c695d21 --- /dev/null +++ b/app/src/main/java/com/example/patrickjmartin/android_sprint1_challenge/MovieViewModel.java @@ -0,0 +1,41 @@ +package com.example.patrickjmartin.android_sprint1_challenge; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.MutableLiveData; +import android.arch.lifecycle.ViewModel; + +import java.util.ArrayList; + +public class MovieViewModel extends ViewModel { + + private MovieRepo repo; + private MutableLiveData> movieList; + + public LiveData> getOverViewList(){ + if(movieList == null) { + loadList(); + } + + return movieList; + } + + private void loadList() { + + repo = new MovieRepo(); + movieList = repo.getOverviewList(); + + } + + public void addMovie(Movie movie) { + if(movieList != null){ + movieList.setValue(repo.addMovie(movie)); + } + } + + public void removeMovie(Movie movie){ + if (movieList != null){ + movieList.setValue(repo.removeMovie(movie)); + } + } + +} 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_add_details.xml b/app/src/main/res/layout/activity_add_details.xml new file mode 100644 index 0000000..834b3c6 --- /dev/null +++ b/app/src/main/res/layout/activity_add_details.xml @@ -0,0 +1,57 @@ + + + +