diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml deleted file mode 100644 index 719bb8b..0000000 --- a/.idea/codeStyleSettings.xml +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 7ac24c7..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 5d19981..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 54b7b3f..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index e3f632e..8ec3711 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,9 @@ dependencies { }) compile 'com.android.support:appcompat-v7:26.0.2' compile 'com.android.support.constraint:constraint-layout:1.0.2' + compile 'com.android.support:design:26.+' testCompile 'junit:junit:4.12' + compile "com.android.support:support-core-utils:26.1.0" } allprojects { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0199761..c792dce 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="cz.muni.fi.pv256.movio2"> - + android:theme="@style/SecondTheme" + android:name=".App"> + + - + - + + + + \ No newline at end of file diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/App.java b/app/src/main/java/cz/muni/fi/pv256/movio2/App.java index 0c93b1c..a34aa74 100644 --- a/app/src/main/java/cz/muni/fi/pv256/movio2/App.java +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/App.java @@ -17,6 +17,7 @@ public void onCreate() { } } + private void initStrictMode() { StrictMode.ThreadPolicy.Builder tpb = new StrictMode.ThreadPolicy.Builder() .detectAll() diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/DetailFragment.java b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/DetailFragment.java new file mode 100644 index 0000000..1bb8f1d --- /dev/null +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/DetailFragment.java @@ -0,0 +1,55 @@ +package cz.muni.fi.pv256.movio2.uco_422678; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.content.Context; +import cz.muni.fi.pv256.movio2.R; + +/** + * Created by BranislavSmik on 10/19/2017. + */ + +public class DetailFragment extends Fragment { + public static final String TAG = DetailFragment.class.getSimpleName(); + private static final String ARGS_MOVIE = "args_movie"; + + private Context mContext; + private Movie mMovie; + + public static DetailFragment newInstance(Movie movie) { + DetailFragment fragment = new DetailFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARGS_MOVIE, movie); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mContext = getActivity(); + Bundle args = getArguments(); + if (args != null) { + mMovie = args.getParcelable(ARGS_MOVIE); + } + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_detail, container, false); + + TextView titleTextView = (TextView) view.findViewById(R.id.detail_movie); + + if (mMovie != null) { + titleTextView.setText(mMovie.getTitle()); + } + + return view; + } +} diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MainActivity.java b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MainActivity.java new file mode 100644 index 0000000..bdf1289 --- /dev/null +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MainActivity.java @@ -0,0 +1,114 @@ +package cz.muni.fi.pv256.movio2.uco_422678; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v4.app.FragmentManager; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.Button; +import android.widget.Switch; +import android.support.v4.app.FragmentActivity; + + +import cz.muni.fi.pv256.movio2.R; + +public class MainActivity extends AppCompatActivity implements MovieListFragment.OnMovieSelectListener { + private RecyclerView mRecyclerView; + private RecyclerView.Adapter mAdapter; + private RecyclerView.LayoutManager mLayoutManager; + private static final String PREFSTRING = "currentTheme"; + private boolean mTwoPane; + + //private Button mSwitchThemeButton; + //private SharedPreferences myPreferences; + //private SharedPreferences.Editor myPreferencesEditor; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + //Ukol2 + /* + myPreferences = getSharedPreferences("movio2preferences", MODE_PRIVATE); + final boolean isCurrentThemeAppTheme = myPreferences.getBoolean(PREFSTRING, false); + if(isCurrentThemeAppTheme){ + setTheme(R.style.AppTheme); + } else { + setTheme(R.style.SecondTheme); + } + myPreferencesEditor = myPreferences.edit(); + + + setContentView(R.layout.activity_main); + + mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); + + + mSwitchThemeButton = (Button) findViewById(R.id.switchtheme_button); + + mSwitchThemeButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + myPreferencesEditor.putBoolean(PREFSTRING, !isCurrentThemeAppTheme); + myPreferencesEditor.apply(); + + Intent intent = new Intent(getApplicationContext() ,MainActivity.class); + startActivity(intent); + finish(); + } + }); + + //improving performance if changes + //in content do not change the layout size of the RecyclerView + mRecyclerView.setHasFixedSize(true); + + // use a linear layout manager + //mLayoutManager = new LinearLayoutManager(this); + mRecyclerView.setLayoutManager(mLayoutManager); + */ + + //TODO: specify an adapter + + setContentView(R.layout.activity_main); + if (findViewById(R.id.movie_detail_container) != null) { + // The detail container view will be present only in the large-screen layouts + // (res/layout-sw600dp). If this view is present, then the activity should be + // in two-pane mode. + mTwoPane = true; + // In two-pane mode, show the detail view in this activity by + // adding or replacing the detail fragment using a + // fragment transaction. + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.movie_detail_container, new DetailFragment(), DetailFragment.TAG) + .commit(); + } + } else { + mTwoPane = false; + getSupportActionBar().setElevation(0f); + } + } + + @Override + public void onMovieSelect(Movie movie) { + if (mTwoPane) { + FragmentManager myManager = getSupportFragmentManager(); + + DetailFragment fragment = DetailFragment.newInstance(movie); + myManager.beginTransaction() + .replace(R.id.movie_detail_container, fragment, DetailFragment.TAG) + .commit(); + + } else { + Intent intent = new Intent(this, MovieDetailActivity.class); + intent.putExtra(MovieDetailActivity.EXTRA_MOVIE, movie); + startActivity(intent); + } + } + +} diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/Movie.java b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/Movie.java new file mode 100644 index 0000000..0b9ebaa --- /dev/null +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/Movie.java @@ -0,0 +1,98 @@ +package cz.muni.fi.pv256.movio2.uco_422678; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Created by BranislavSmik on 10/19/2017. + */ + +public class Movie implements Parcelable{ + private long mRealeaseDate; + private String mCoverPath; + private String mTitle; + private String mBackdrop; + private float mPopularity; + + public Movie(long realeaseDate, String coverPath, String title, String backdrop, float popularity) { + mRealeaseDate = realeaseDate; + mCoverPath = coverPath; + mTitle = title; + mBackdrop = backdrop; + mPopularity = popularity; + } + + public long getRealeaseDate() { + return mRealeaseDate; + } + + public void setRealeaseDate(long realeaseDate) { + mRealeaseDate = realeaseDate; + } + + public String getCoverPath() { + return mCoverPath; + } + + public void setCoverPath(String coverPath) { + mCoverPath = coverPath; + } + + public String getTitle() { + return mTitle; + } + + public void setTitle(String title) { + mTitle = title; + } + + public String getBackdrop() { + return mBackdrop; + } + + public void setBackdrop(String backdrop) { + mBackdrop = backdrop; + } + + public float getPopularity() { + return mPopularity; + } + + public void setPopularity(float popularity) { + mPopularity = popularity; + } + + @Override + public int describeContents() { + return 0; + } + + public Movie(Parcel in) { + mRealeaseDate = in.readLong(); + mCoverPath = in.readString(); + mTitle = in.readString(); + mBackdrop = in.readString(); + mPopularity = in.readFloat(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeLong(mRealeaseDate); + dest.writeString(mCoverPath); + dest.writeString(mTitle); + dest.writeString(mBackdrop); + dest.writeFloat(mPopularity); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public Movie createFromParcel(Parcel sourceParcel) { + return new Movie(sourceParcel); + } + + @Override + public Movie[] newArray(int size) { + return new Movie[size]; + } + }; +} diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MovieDetailActivity.java b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MovieDetailActivity.java new file mode 100644 index 0000000..7469089 --- /dev/null +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MovieDetailActivity.java @@ -0,0 +1,36 @@ +package cz.muni.fi.pv256.movio2.uco_422678; + +import android.os.Bundle; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.AppCompatActivity; + +import cz.muni.fi.pv256.movio2.R; + +/** + * Created by BranislavSmik on 10/19/2017. + */ + +public class MovieDetailActivity extends AppCompatActivity{ + public static final String EXTRA_MOVIE = "extra_movie"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_detail); + + if(savedInstanceState == null){ + Movie movie = getIntent().getParcelableExtra(EXTRA_MOVIE); + FragmentManager fm = getSupportFragmentManager(); + DetailFragment fragment = (DetailFragment) fm.findFragmentById(R.id.movie_detail_container); + + if (fragment == null) { + fragment = DetailFragment.newInstance(movie); + fm.beginTransaction() + .add(R.id.movie_detail_container, fragment) + .commit(); + } + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MovieListFragment.java b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MovieListFragment.java new file mode 100644 index 0000000..fda5749 --- /dev/null +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MovieListFragment.java @@ -0,0 +1,111 @@ +package cz.muni.fi.pv256.movio2.uco_422678; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; +import android.widget.Button; +import android.content.Context; +import java.util.ArrayList; + +import cz.muni.fi.pv256.movio2.R; + +/** + * Created by BranislavSmik on 10/19/2017. + */ + +public class MovieListFragment extends Fragment { + private static final String TAG = MovieListFragment.class.getSimpleName(); + private static final String SELECTED_KEY = "selected_position"; + + private int mPosition = ListView.INVALID_POSITION; + private OnMovieSelectListener mListener; + private Context mContext; + private ArrayList mMovieList = new ArrayList<>(); + private Button mButton1; + private Button mButton2; + private Button mButton3; + + @Override + public void onAttach(Context activity) { + super.onAttach(activity); + + mListener = (OnMovieSelectListener) activity; + } + + @Override + public void onDetach() { + super.onDetach(); + + //Avoid Activity leaking + mListener = null; + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mContext = getActivity().getApplicationContext(); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_movie_list , container, false); + + mMovieList.add(new Movie(1234, "", "movie1", "This is a movie 1", 0.1f)); + mMovieList.add(new Movie(5678, "", "movie2", "This is a movie 2", 0.2f)); + mMovieList.add(new Movie(91011, "", "movie3", "This is a movie 3", 0.3f)); + + mButton1 = (Button) view.findViewById(R.id.movie1); + mButton2 = (Button) view.findViewById(R.id.movie2); + mButton3 = (Button) view.findViewById(R.id.movie3); + + View.OnClickListener clickListener = new View.OnClickListener(){ + + @Override + public void onClick(View myView) { + switch(myView.getId()) { + case R.id.movie1: + mListener.onMovieSelect(mMovieList.get(0)); + break; + case R.id.movie2: + mListener.onMovieSelect(mMovieList.get(1)); + break; + case R.id.movie3: + mListener.onMovieSelect(mMovieList.get(2)); + break; + } + } + }; + mButton1.setOnClickListener(clickListener); + mButton2.setOnClickListener(clickListener); + mButton3.setOnClickListener(clickListener); + + if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) { + mPosition = savedInstanceState.getInt(SELECTED_KEY); + } + + return view; + } + + + @Override + public void onSaveInstanceState(Bundle outState) { + // When tablets rotate, the currently selected list item needs to be saved. + // When no item is selected, mPosition will be set to Listview.INVALID_POSITION, + // so check for that before storing. + if (mPosition != ListView.INVALID_POSITION) { + outState.putInt(SELECTED_KEY, mPosition); + } + super.onSaveInstanceState(outState); + } + + public interface OnMovieSelectListener { + void onMovieSelect(Movie movie); + } + +} diff --git a/app/src/main/res/layout-w600dp/activity_main.xml b/app/src/main/res/layout-w600dp/activity_main.xml new file mode 100644 index 0000000..d6e9bbb --- /dev/null +++ b/app/src/main/res/layout-w600dp/activity_main.xml @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/activity_app.xml b/app/src/main/res/layout/activity_app.xml index 7cd2a6c..56cb75c 100644 --- a/app/src/main/res/layout/activity_app.xml +++ b/app/src/main/res/layout/activity_app.xml @@ -6,13 +6,4 @@ android:layout_height="match_parent" tools:context="cz.muni.fi.pv256.movio2.App"> - - diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml new file mode 100644 index 0000000..39c40eb --- /dev/null +++ b/app/src/main/res/layout/activity_detail.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..f521cd6 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 0000000..94246c1 --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/fragment_detail.xml b/app/src/main/res/layout/fragment_detail.xml new file mode 100644 index 0000000..0a9ee4f --- /dev/null +++ b/app/src/main/res/layout/fragment_detail.xml @@ -0,0 +1,24 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_movie_list.xml b/app/src/main/res/layout/fragment_movie_list.xml new file mode 100644 index 0000000..c0eb5a0 --- /dev/null +++ b/app/src/main/res/layout/fragment_movie_list.xml @@ -0,0 +1,31 @@ + + + + + +