diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/.gitignore b/Android Projects/CatalogueMovieSqLiteFavorite/.gitignore new file mode 100644 index 00000000..39fb081a --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/.idea/caches/build_file_checksums.ser b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/caches/build_file_checksums.ser new file mode 100644 index 00000000..ea6617a0 Binary files /dev/null and b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/caches/build_file_checksums.ser differ diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/.idea/codeStyles/Project.xml b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..30aa626c --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/.idea/gradle.xml b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/gradle.xml new file mode 100644 index 00000000..2bf9ae92 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/.idea/misc.xml b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/misc.xml new file mode 100644 index 00000000..9e762bbd --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/misc.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/.idea/modules.xml b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/modules.xml new file mode 100644 index 00000000..2a5ac026 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/.idea/runConfigurations.xml b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/.gitignore b/Android Projects/CatalogueMovieSqLiteFavorite/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/build.gradle b/Android Projects/CatalogueMovieSqLiteFavorite/app/build.gradle new file mode 100644 index 00000000..4cfe34ae --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/build.gradle @@ -0,0 +1,54 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "com.fajarnandagusti.cataloguemoviefinal" + minSdkVersion 19 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + buildTypes.each { + it.buildConfigField 'String', 'API_KEY', ApiKey + } +} +ext { + butterknifeVersion = "8.8.1" +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support:design:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'com.android.support:support-v4:26.1.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 'com.android.support:support-annotations:27.1.1' + + implementation 'com.android.support:recyclerview-v7:26.1.0' + implementation 'com.android.support:cardview-v7:26.1.0' + + implementation 'com.github.bumptech.glide:glide:3.7.0' + + implementation 'com.squareup.retrofit2:retrofit:2.1.0' + implementation 'com.squareup.retrofit2:converter-gson:2.1.0' + implementation 'com.google.code.gson:gson:2.8.0' + implementation 'com.google.code.gson:gson:2.6.2' + + implementation 'com.squareup.retrofit2:retrofit:2.0.2' + implementation 'com.squareup.retrofit2:converter-gson:2.0.2' + implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1' + implementation "com.jakewharton:butterknife:$butterknifeVersion" + annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion" + +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/proguard-rules.pro b/Android Projects/CatalogueMovieSqLiteFavorite/app/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/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/Android Projects/CatalogueMovieSqLiteFavorite/app/src/androidTest/java/com/fajarnandagusti/cataloguemoviefinal/ExampleInstrumentedTest.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/androidTest/java/com/fajarnandagusti/cataloguemoviefinal/ExampleInstrumentedTest.java new file mode 100644 index 00000000..bcc27ac9 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/androidTest/java/com/fajarnandagusti/cataloguemoviefinal/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.fajarnandagusti.cataloguemoviefinal; + +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() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.fajarnandagusti.cataloguemoviefinal", appContext.getPackageName()); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/AndroidManifest.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..d76ad502 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/AndroidManifest.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/DetailMovieActivity.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/DetailMovieActivity.java new file mode 100644 index 00000000..561d8d12 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/DetailMovieActivity.java @@ -0,0 +1,151 @@ +package com.fajarnandagusti.cataloguemoviefinal.activity; + +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract; +import com.fajarnandagusti.cataloguemoviefinal.utils.Utility; + +import java.util.Objects; + +import butterknife.BindView; +import butterknife.ButterKnife; + +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.CONTENT_URI; + +public class DetailMovieActivity extends AppCompatActivity { + @BindView(R.id.detPoster) + ImageView detPoster; + @BindView(R.id.detJudul) + TextView detJudul; + @BindView(R.id.detTgl) + TextView detTgl; + @BindView(R.id.detPopular) + TextView detPopular; + @BindView(R.id.detDesc) + TextView detDesc; + @BindView(R.id.fav) + ImageView btnFav; + @BindView(R.id.linear) + LinearLayout linearLayout; + + String image, judul, tgl, popular, desc; + private long id; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_detail_movie); + + ButterKnife.bind(this); + + getParcel(); + bindMovie(); + setFavorite(); + + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } + + private void getParcel() { + image = getIntent().getStringExtra("poster_path"); + judul = getIntent().getStringExtra("title"); + tgl = getIntent().getStringExtra("release_date"); + popular = getIntent().getStringExtra("popularity"); + desc = getIntent().getStringExtra("overview"); + } + + private void bindMovie() { + Glide.with(getApplicationContext()) + .load(Utility.URL+image) + .placeholder(R.drawable.ph) + .error(R.drawable.bg) + .into(detPoster); + + detJudul.setText(judul); + detTgl.setText(tgl); + detPopular.setText(popular); + detDesc.setText(desc); + btnFav.setImageResource(R.drawable.ic_star_unchecked); + } + + public void clickFav(View view){ + if (setFavorite()){ + Uri uri = Uri.parse(CONTENT_URI+"/"+id); + getContentResolver().delete(uri, null, null); + btnFav.setImageResource(R.drawable.ic_star_unchecked); + }else { + + ContentValues contentValues = new ContentValues(); + + contentValues.put(DatabaseContract.FavoriteColumn.POSTER, image); + contentValues.put(DatabaseContract.FavoriteColumn.TITLE, judul); + contentValues.put(DatabaseContract.FavoriteColumn.RELEASE, tgl); + contentValues.put(DatabaseContract.FavoriteColumn.POPULARITY, popular); + contentValues.put(DatabaseContract.FavoriteColumn.OVERVIEW, desc); + + getContentResolver().insert(CONTENT_URI, contentValues); + setResult(101); + + btnFav.setImageResource(R.drawable.ic_star_checked); + + showSnackbarMessage(R.string.addto); + } + } + + private void showSnackbarMessage(int message) { + Snackbar.make(linearLayout, message, Snackbar.LENGTH_SHORT).show(); + } + + + private boolean setFavorite() { + Uri uri = Uri.parse(CONTENT_URI + ""); + boolean favorite = false; + Cursor cursor = getContentResolver().query(uri, null, null, null, null); + + String getTitle; + + assert cursor != null; + if (cursor.moveToFirst()) { + do { + id = cursor.getLong(0); + getTitle = cursor.getString(1); + if (getTitle.equals(getIntent().getStringExtra("title"))) { + btnFav.setImageResource(R.drawable.ic_star_checked); + favorite = true; + } + } while (cursor.moveToNext()); + + } + return favorite; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()){ + case android.R.id.home : { + finish(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + break; + } + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/FavoriteActivity.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/FavoriteActivity.java new file mode 100644 index 00000000..c64c3521 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/FavoriteActivity.java @@ -0,0 +1,98 @@ +package com.fajarnandagusti.cataloguemoviefinal.activity; + +import android.database.Cursor; +import android.os.AsyncTask; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.MenuItem; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.adapter.FavoriteAdapter; + +import java.util.Objects; + +import butterknife.BindView; +import butterknife.ButterKnife; + +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.CONTENT_URI; + +public class FavoriteActivity extends AppCompatActivity { + @BindView(R.id.recycler_movie) + RecyclerView recyclerView; + + @BindView(R.id.Favorite) + CoordinatorLayout favoriteLayout; + + private FavoriteAdapter favoriteAdapter; + private Cursor cursor; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_favorite); + ButterKnife.bind(this); + + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.setHasFixedSize(true); + favoriteAdapter = new FavoriteAdapter(this); + favoriteAdapter.setFavoriteList(cursor); + recyclerView.setAdapter(favoriteAdapter); + + new LoadFavoriteMovie().execute(); + + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + } + + private class LoadFavoriteMovie extends AsyncTask { + @Override + protected Cursor doInBackground(Void... voids) { + return getContentResolver().query(CONTENT_URI, null, null, null, null); + } + + @Override + protected void onPreExecute(){ + + } + + @Override + protected void onPostExecute(Cursor favorite){ + super.onPostExecute(favorite); + + cursor = favorite; + favoriteAdapter.setFavoriteList(cursor); + favoriteAdapter.notifyDataSetChanged(); + + if (cursor.getCount() == 0){ + showSnackbarMessage(R.string.Empty); + } + } + } + + private void showSnackbarMessage(int message) { + Snackbar.make(favoriteLayout, message, Snackbar.LENGTH_SHORT).show(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()){ + case android.R.id.home : { + finish(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + break; + } + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/MainActivity.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/MainActivity.java new file mode 100644 index 00000000..9617cd2b --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/MainActivity.java @@ -0,0 +1,224 @@ +package com.fajarnandagusti.cataloguemoviefinal.activity; + +import android.app.ProgressDialog; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.design.widget.NavigationView; +import android.support.v4.view.GravityCompat; + +import android.support.v4.view.MenuItemCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.SearchView; +import android.widget.Toast; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.adapter.MovieAdapter; +import com.fajarnandagusti.cataloguemoviefinal.api.ApiService; +import com.fajarnandagusti.cataloguemoviefinal.api.Server; +import com.fajarnandagusti.cataloguemoviefinal.model.Movies; +import com.fajarnandagusti.cataloguemoviefinal.model.ResponseMovie; +import com.fajarnandagusti.cataloguemoviefinal.utils.Utility; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class MainActivity extends AppCompatActivity + implements NavigationView.OnNavigationItemSelectedListener { + + @BindView(R.id.recycler_movie) + RecyclerView recyclerView; + + ApiService API; + ProgressDialog loading; + List listMovies; + private MovieAdapter movieAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + ButterKnife.bind(this); + API = Server.getAPIService(); + + preload(); + + if (savedInstanceState == null) { + load(); + }else{ + listMovies = savedInstanceState.getParcelableArrayList(Utility.KEY_PARCELABLE); + movieAdapter = new MovieAdapter(getApplicationContext(), listMovies); + recyclerView.setAdapter(movieAdapter); + } + + DrawerLayout drawer = findViewById(R.id.drawer_layout); + ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( + this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + drawer.addDrawerListener(toggle); + toggle.syncState(); + + NavigationView navigationView = findViewById(R.id.nav_view); + navigationView.setNavigationItemSelectedListener(this); + } + + protected void onSaveInstanceState(Bundle outState) { + outState.putParcelableArrayList(Utility.KEY_PARCELABLE, new ArrayList<>(listMovies)); + super.onSaveInstanceState(outState); + } + + private void preload() { + movieAdapter = new MovieAdapter(getApplicationContext(), listMovies); + recyclerView.setHasFixedSize(true); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + recyclerView.setAdapter(movieAdapter); + } + + private void load() { + loading = ProgressDialog.show(this, null, "Loading...", true, false); + + API.getAllMovies(Utility.API_KEY).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + loading.dismiss(); + listMovies = response.body().getMovies(); + recyclerView.setAdapter(new MovieAdapter(getApplicationContext(), listMovies)); + + movieAdapter.notifyDataSetChanged(); //ini penting, kalau gak ada, data gak tampil + + }else { + loading.dismiss(); + Toast.makeText(getApplicationContext(), getString(R.string.error), Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + loading.dismiss(); + Toast.makeText(getApplicationContext(), getString(R.string.error), Toast.LENGTH_SHORT).show(); + } + }); + } + + + @Override + public void onBackPressed() { + DrawerLayout drawer = findViewById(R.id.drawer_layout); + if (drawer.isDrawerOpen(GravityCompat.START)) { + drawer.closeDrawer(GravityCompat.START); + } else { + super.onBackPressed(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + + SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search)); + searchView.setQueryHint(getResources().getString(R.string.search)); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + + @Override + public boolean onQueryTextSubmit(String query) { + cariFilm(query); + return true; + } + + @Override + public boolean onQueryTextChange(String newText) { + if (TextUtils.isEmpty(newText)){ + load(); + } + return false; + } + }); + + return true; + } + + private void cariFilm(String query) { + API.getSearchMovie(Utility.API_KEY, Utility.LANGUAGE, query, Utility.page, Utility.include_adult) + .enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + listMovies = response.body().getMovies(); + recyclerView.setAdapter(new MovieAdapter(getApplicationContext(), listMovies)); + movieAdapter.notifyDataSetChanged(); + } + else { + Toast.makeText(getApplicationContext(), getString(R.string.error), Toast.LENGTH_LONG).show(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Toast.makeText(getApplicationContext(), getString(R.string.internet), Toast.LENGTH_SHORT).show(); + } + }); + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + Intent setting = new Intent(getApplicationContext(), SettingActivity.class); + startActivity(setting); + return true; + } + + return super.onOptionsItemSelected(item); + } + + @SuppressWarnings("StatementWithEmptyBody") + @Override + public boolean onNavigationItemSelected(MenuItem item) { + // Handle navigation view item clicks here. + int id = item.getItemId(); + + if (id == R.id.now_playing) { + Intent now = new Intent(getApplicationContext(), NowPlayingActivity.class); + startActivity(now); + Toast.makeText(getApplicationContext(), "Show Now Playing Movies", Toast.LENGTH_SHORT).show(); + + } else if (id == R.id.upcoming) { + Intent up = new Intent(getApplicationContext(), UpcomingActivity.class); + startActivity(up); + Toast.makeText(getApplicationContext(), "Show Upcoming Movies", Toast.LENGTH_SHORT).show(); + + } else if (id == R.id.favorite) { + Intent fav = new Intent(getApplicationContext(), FavoriteActivity.class); + startActivity(fav); + Toast.makeText(getApplicationContext(), "Show Favorite Movies", Toast.LENGTH_SHORT).show(); + } + + DrawerLayout drawer = findViewById(R.id.drawer_layout); + drawer.closeDrawer(GravityCompat.START); + return true; + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/NowPlayingActivity.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/NowPlayingActivity.java new file mode 100644 index 00000000..bd95cc9d --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/NowPlayingActivity.java @@ -0,0 +1,119 @@ +package com.fajarnandagusti.cataloguemoviefinal.activity; + +import android.app.ProgressDialog; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.MenuItem; +import android.widget.Toast; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.adapter.MovieAdapter; +import com.fajarnandagusti.cataloguemoviefinal.api.ApiService; +import com.fajarnandagusti.cataloguemoviefinal.api.Server; +import com.fajarnandagusti.cataloguemoviefinal.model.Movies; +import com.fajarnandagusti.cataloguemoviefinal.model.ResponseMovie; +import com.fajarnandagusti.cataloguemoviefinal.utils.Utility; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import butterknife.BindView; +import butterknife.ButterKnife; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class NowPlayingActivity extends AppCompatActivity { + @BindView(R.id.recycler_movie) + RecyclerView recyclerView; + + ApiService API; + ProgressDialog loading; + List listMovies; + private MovieAdapter movieAdapter; + + public final String KEY_PARCELABLE ="key_parcelable"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_now_playing); + + ButterKnife.bind(this); + API = Server.getAPIService(); + + preload(); + + if (savedInstanceState == null) { + load(); + }else{ + listMovies = savedInstanceState.getParcelableArrayList(Utility.KEY_PARCELABLE); + movieAdapter = new MovieAdapter(getApplicationContext(), listMovies); + recyclerView.setAdapter(movieAdapter); + } + + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } + + protected void onSaveInstanceState(Bundle outState) { + outState.putParcelableArrayList(Utility.KEY_PARCELABLE, new ArrayList<>(listMovies)); + super.onSaveInstanceState(outState); + + } + + private void preload() { + movieAdapter = new MovieAdapter(getApplicationContext(), listMovies); + recyclerView.setHasFixedSize(true); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + recyclerView.setAdapter(movieAdapter); + } + + private void load() { + + loading = ProgressDialog.show(this, null, "Loading...", true, false); + + API.getNowPlayingMovie(Utility.API_KEY).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + loading.dismiss(); + listMovies = response.body().getMovies(); + recyclerView.setAdapter(new MovieAdapter(getApplicationContext(), listMovies)); + movieAdapter.notifyDataSetChanged(); + + }else { + loading.dismiss(); + Toast.makeText(getApplicationContext(), getString(R.string.error), Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + loading.dismiss(); + Toast.makeText(getApplicationContext(), getString(R.string.error), Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()){ + case android.R.id.home : { + finish(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + break; + } + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/SettingActivity.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/SettingActivity.java new file mode 100644 index 00000000..24378864 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/SettingActivity.java @@ -0,0 +1,143 @@ +package com.fajarnandagusti.cataloguemoviefinal.activity; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.provider.Settings; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Switch; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.scheduler.DailyReminderReceiver; +import com.fajarnandagusti.cataloguemoviefinal.scheduler.ReleaseReminderReceiver; +import com.fajarnandagusti.cataloguemoviefinal.scheduler.ReminderPreference; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnCheckedChanged; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.KEY_FIELD_DAILY_REMINDER; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.KEY_FIELD_UPCOMING_REMINDER; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.KEY_HEADER_DAILY_REMINDER; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.KEY_HEADER_UPCOMING_REMINDER; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.TYPE_REMINDER_PREF; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.TYPE_REMINDER_RECIEVE; + +public class SettingActivity extends AppCompatActivity { + @BindView(R.id.dailyReminder) + Switch dailyReminder; + @BindView(R.id.releaseReminder) + Switch releaseReminder; + + public DailyReminderReceiver dailyReminderReceiver; + public ReleaseReminderReceiver releaseReminderReceiver; + public ReminderPreference reminderPreference; + public SharedPreferences sReleaseReminder, sDailyReminder; + public SharedPreferences.Editor editorReleaseReminder, editorDailyReminder; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_setting); + + ButterKnife.bind(this); + + dailyReminderReceiver = new DailyReminderReceiver(); + releaseReminderReceiver = new ReleaseReminderReceiver(); + reminderPreference = new ReminderPreference(this); + setPreference(); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setTitle("Settings"); + } + + private void setPreference() { + sReleaseReminder = getSharedPreferences(KEY_HEADER_UPCOMING_REMINDER, MODE_PRIVATE); + sDailyReminder = getSharedPreferences(KEY_HEADER_DAILY_REMINDER, MODE_PRIVATE); + boolean checkSwUpcomingReminder = sReleaseReminder.getBoolean(KEY_FIELD_UPCOMING_REMINDER, false); + releaseReminder.setChecked(checkSwUpcomingReminder); + boolean checkSwDailyReminder = sDailyReminder.getBoolean(KEY_FIELD_DAILY_REMINDER, false); + dailyReminder.setChecked(checkSwDailyReminder); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } + + @OnCheckedChanged(R.id.dailyReminder) + public void setDailyRemind(boolean isChecked){ + editorDailyReminder = sDailyReminder.edit(); + if (isChecked) { + editorDailyReminder.putBoolean(KEY_FIELD_DAILY_REMINDER, true); + editorDailyReminder.commit(); + dailyReminderOn(); + } else { + editorDailyReminder.putBoolean(KEY_FIELD_DAILY_REMINDER, false); + editorDailyReminder.commit(); + dailyReminderOff(); + } + } + + private void dailyReminderOff() { + dailyReminderReceiver.cancelReminder(SettingActivity.this); + } + + private void dailyReminderOn() { + String time = "07:00"; + String message = getResources().getString(R.string.daily_reminder_message); + reminderPreference.setReminderDailyTime(time); + reminderPreference.setReminderDailyMessage(message); + dailyReminderReceiver.setReminder(SettingActivity.this, TYPE_REMINDER_RECIEVE, time, message); + } + + @OnCheckedChanged(R.id.releaseReminder) + public void setReleaseRemind(boolean isChecked){ + editorReleaseReminder = sReleaseReminder.edit(); + if (isChecked) { + editorReleaseReminder.putBoolean(KEY_FIELD_UPCOMING_REMINDER, true); + editorReleaseReminder.commit(); + releaseReminderOn(); + } else { + editorReleaseReminder.putBoolean(KEY_FIELD_UPCOMING_REMINDER, false); + editorReleaseReminder.commit(); + releaseReminderOff(); + } + } + + private void releaseReminderOff() { + releaseReminderReceiver.cancelReminder(SettingActivity.this); + } + + private void releaseReminderOn() { + String time = "08:00"; + String message = getResources().getString(R.string.release_movie_message); + reminderPreference.setReminderReleaseTime(time); + reminderPreference.setReminderReleaseMessage(message); + releaseReminderReceiver.setReminder(SettingActivity.this, TYPE_REMINDER_PREF, time, message); + + } + + public void setBahasa(View view){ + Intent mIntent = new Intent(Settings.ACTION_LOCALE_SETTINGS); + startActivity(mIntent); + } + + @Override + public boolean onSupportNavigateUp() { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + return true; + } + + @Override + public void onBackPressed() { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + } + + +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/UpcomingActivity.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/UpcomingActivity.java new file mode 100644 index 00000000..bc9529f6 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/activity/UpcomingActivity.java @@ -0,0 +1,129 @@ +package com.fajarnandagusti.cataloguemoviefinal.activity; + +import android.app.ProgressDialog; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.MenuItem; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.Toast; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.adapter.MovieAdapter; +import com.fajarnandagusti.cataloguemoviefinal.api.ApiService; +import com.fajarnandagusti.cataloguemoviefinal.api.Server; +import com.fajarnandagusti.cataloguemoviefinal.model.Movies; +import com.fajarnandagusti.cataloguemoviefinal.model.ResponseMovie; +import com.fajarnandagusti.cataloguemoviefinal.utils.Utility; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import butterknife.BindView; +import butterknife.ButterKnife; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class UpcomingActivity extends AppCompatActivity { + + @BindView(R.id.recycler_movie) + RecyclerView recyclerView; + + @BindView(R.id.progress_bar) + ProgressBar progressBar; + + ApiService API; + List listMovies; + private MovieAdapter movieAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_upcoming); + + ButterKnife.bind(this); + API = Server.getAPIService(); + + preload(); + + if (savedInstanceState == null) { + load(); + }else{ + listMovies = savedInstanceState.getParcelableArrayList(Utility.KEY_PARCELABLE); + movieAdapter = new MovieAdapter(getApplicationContext(), listMovies); + recyclerView.setAdapter(movieAdapter); + } + + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } + + protected void onSaveInstanceState(Bundle outState) { + outState.putParcelableArrayList(Utility.KEY_PARCELABLE, new ArrayList<>(listMovies)); + super.onSaveInstanceState(outState); + + } + + private void preload() { + movieAdapter = new MovieAdapter(getApplicationContext(), listMovies); + recyclerView.setHasFixedSize(true); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + recyclerView.setAdapter(movieAdapter); + } + + private void load() { + showProgressBar(); + + API.getUpComingMovie(Utility.API_KEY).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + hideProgressBar(); + listMovies = response.body().getMovies(); + recyclerView.setAdapter(new MovieAdapter(getApplicationContext(), listMovies)); + movieAdapter.notifyDataSetChanged(); + + }else { + hideProgressBar(); + Toast.makeText(getApplicationContext(), getString(R.string.error), Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + hideProgressBar(); + Toast.makeText(getApplicationContext(), getString(R.string.error), Toast.LENGTH_SHORT).show(); + } + }); + } + + void showProgressBar() { + progressBar.setVisibility(View.VISIBLE); + } + + void hideProgressBar() { + progressBar.setVisibility(View.GONE); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()){ + case android.R.id.home : { + finish(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + break; + } + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/adapter/FavoriteAdapter.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/adapter/FavoriteAdapter.java new file mode 100644 index 00000000..432dd204 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/adapter/FavoriteAdapter.java @@ -0,0 +1,129 @@ +package com.fajarnandagusti.cataloguemoviefinal.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.activity.DetailMovieActivity; +import com.fajarnandagusti.cataloguemoviefinal.model.Favorite; +import com.fajarnandagusti.cataloguemoviefinal.utils.DateFormat; +import com.fajarnandagusti.cataloguemoviefinal.utils.Utility; + +import butterknife.BindView; +import butterknife.ButterKnife; + +/** + * Created by Gustiawan on 11/17/2018. + */ + +public class FavoriteAdapter extends RecyclerView.Adapter{ + private Context context; + private Cursor listFavorite; + + public FavoriteAdapter(Context context){ + this.context = context; + } + + public void setFavoriteList(Cursor listFavorite){ + this.listFavorite = listFavorite; + } + + public class ViewHolder extends RecyclerView.ViewHolder { + @BindView(R.id.img_cv) + ImageView poster; + @BindView(R.id.movie_title) + TextView judul; + @BindView(R.id.movie_date) + TextView tanggal; + @BindView(R.id.movie_desc) + TextView sinopsis; + @BindView(R.id.popularity) + TextView popular; + @BindView(R.id.btn_detail) + Button btnDetail; + @BindView(R.id.btn_share) + Button btnShare; + + public ViewHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + + } + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_movies, null, false); + RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + view.setLayoutParams(layoutParams); + + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + final Favorite favorite = getItem(position); + + Glide.with(context) + .load(Utility.URL+favorite.getPosterPath()) + .placeholder(R.drawable.ph) + .error(R.drawable.bg) + .into(holder.poster); + holder.judul.setText(favorite.getTitle()); + holder.tanggal.setText(DateFormat.dateConverter(favorite.getReleaseDate())); + holder.popular.setText(favorite.getPopularity()); + holder.sinopsis.setText(favorite.getOverview()); + + holder.btnDetail.setOnClickListener(new View.OnClickListener(){ + + @Override + public void onClick(View v) { + Intent intent = new Intent(context, DetailMovieActivity.class); + intent.putExtra("title", favorite.getTitle()); + intent.putExtra("overview", favorite.getOverview()); + intent.putExtra("poster_path", favorite.getPosterPath()); + intent.putExtra("release_date", favorite.getReleaseDate()); + intent.putExtra("popularity", favorite.getPopularity()); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + + } + }); + + holder.btnShare.setOnClickListener(new View.OnClickListener() { + @SuppressLint({"StringFormatInvalid", "ResourceType"}) + @Override + public void onClick(View v) { + Intent i = new Intent(); + i.setAction(Intent.ACTION_SEND); + i.putExtra(Intent.EXTRA_TEXT, + context.getString(R.string.share, favorite.getTitle())); + i.setType("text/plain"); + context.startActivity(i); + } + }); + } + + @Override + public int getItemCount() { + if (listFavorite == null) return 0; + return listFavorite.getCount(); + } + + private Favorite getItem(int position){ + if (!listFavorite.moveToPosition(position)) { + throw new IllegalStateException("Position invalid"); + } + return new Favorite(listFavorite); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/adapter/MovieAdapter.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/adapter/MovieAdapter.java new file mode 100644 index 00000000..d9f8e6c6 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/adapter/MovieAdapter.java @@ -0,0 +1,118 @@ +package com.fajarnandagusti.cataloguemoviefinal.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.activity.DetailMovieActivity; +import com.fajarnandagusti.cataloguemoviefinal.model.Movies; +import com.fajarnandagusti.cataloguemoviefinal.utils.DateFormat; + +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.URL; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class MovieAdapter extends RecyclerView.Adapter{ + public final static String EXTRA_MOVIE = "movie"; + private Context context; + private List listMovies; + + public MovieAdapter(Context context, List listMovies){ + this.context = context; + this.listMovies = listMovies; + } + + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_movies, null, false); + RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + v.setLayoutParams(layoutParams); + return new ViewHolder(v); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + final Movies movies = listMovies.get(position); + Glide.with(context) + .load(URL+movies.getPosterPath()) + .placeholder(R.drawable.ph) + .error(R.drawable.bg) + .into(holder.poster); + holder.judul.setText(movies.getTitle()); + holder.sinopsis.setText(movies.getOverview()); + holder.tanggal.setText(DateFormat.dateConverter(movies.getReleaseDate())); + holder.popular.setText(movies.getPopularity()); + + holder.btnDetail.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, DetailMovieActivity.class); + intent.putExtra("title", movies.getTitle()); + intent.putExtra("overview", movies.getOverview()); + intent.putExtra("poster_path", movies.getPosterPath()); + intent.putExtra("release_date", DateFormat.dateConverter(movies.getReleaseDate())); + intent.putExtra("popularity", movies.getPopularity()); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + }); + + holder.btnShare.setOnClickListener(new View.OnClickListener() { + @SuppressLint("StringFormatInvalid") + @Override + public void onClick(View v) { + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, + context.getString(R.string.share, movies.getTitle())); + sendIntent.setType("text/plain"); + } + }); + + } + @Override + public int getItemCount() { + if (listMovies == null) return 0; + return listMovies.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + @BindView(R.id.img_cv) + ImageView poster; + @BindView(R.id.movie_title) + TextView judul; + @BindView(R.id.movie_date) + TextView tanggal; + @BindView(R.id.movie_desc) + TextView sinopsis; + @BindView(R.id.popularity) + TextView popular; + @BindView(R.id.btn_detail) + Button btnDetail; + @BindView(R.id.btn_share) + Button btnShare; + + public ViewHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + } + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/ApiService.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/ApiService.java new file mode 100644 index 00000000..98ff4ec7 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/ApiService.java @@ -0,0 +1,29 @@ +package com.fajarnandagusti.cataloguemoviefinal.api; + +import com.fajarnandagusti.cataloguemoviefinal.model.ResponseMovie; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public interface ApiService { + @GET("3/discover/movie") + Call getAllMovies(@Query("api_key") String api_key); + + @GET("/3/search/movie") + Call getSearchMovie(@Query("api_key") String api_key, + @Query("language") String language, + @Query("query") String query, + @Query("page") String page, + @Query("include_adult") String include_adult); + + @GET("/3/movie/now_playing") + Call getNowPlayingMovie(@Query("api_key") String api_key); + + @GET("/3/movie/upcoming") + Call getUpComingMovie(@Query("api_key") String api_key); +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/Client.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/Client.java new file mode 100644 index 00000000..b48b7724 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/Client.java @@ -0,0 +1,29 @@ +package com.fajarnandagusti.cataloguemoviefinal.api; + +import okhttp3.OkHttpClient; +import okhttp3.logging.HttpLoggingInterceptor; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class Client { + private static Retrofit retrofit = null; + + public static Retrofit getClient(String baseUrl){ + HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); + interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); + OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); + + if (retrofit == null){ + retrofit = new Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(GsonConverterFactory.create()) + .client(client) + .build(); + } + return retrofit; + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/Server.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/Server.java new file mode 100644 index 00000000..04165324 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/api/Server.java @@ -0,0 +1,13 @@ +package com.fajarnandagusti.cataloguemoviefinal.api; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.BASE_URL_API; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class Server { + public static ApiService getAPIService(){ + return Client.getClient(BASE_URL_API).create(ApiService.class); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/DatabaseContract.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/DatabaseContract.java new file mode 100644 index 00000000..c24e0bd1 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/DatabaseContract.java @@ -0,0 +1,37 @@ +package com.fajarnandagusti.cataloguemoviefinal.database; + +import android.database.Cursor; +import android.net.Uri; +import android.provider.BaseColumns; + +import com.fajarnandagusti.cataloguemoviefinal.utils.Utility; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class DatabaseContract { + public static String TABLE_FAVORITE = "favorite"; + + public static final class FavoriteColumn implements BaseColumns { + public static String POSTER = "posterPath"; + public static String TITLE = "title"; + public static String RELEASE = "releaseDate"; + public static String POPULARITY = "popularity"; + public static String OVERVIEW = "overview"; + + public static final Uri CONTENT_URI = new Uri.Builder() + .scheme(Utility.SCHEME) + .authority(Utility.AUTHORITY) + .appendPath(TABLE_FAVORITE) + .build(); + } + + public static String getColumnString(Cursor cursor, String columnName) { + return cursor.getString( cursor.getColumnIndex(columnName) ); + } + + public static int getColumnInt(Cursor cursor, String columnName) { + return cursor.getInt( cursor.getColumnIndex(columnName) ); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/DatabaseHelper.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/DatabaseHelper.java new file mode 100644 index 00000000..40e2f21e --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/DatabaseHelper.java @@ -0,0 +1,55 @@ +package com.fajarnandagusti.cataloguemoviefinal.database; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +import static android.provider.BaseColumns._ID; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.OVERVIEW; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.POPULARITY; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.POSTER; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.RELEASE; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.TITLE; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.TABLE_FAVORITE; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class DatabaseHelper extends SQLiteOpenHelper { + private static String DATABASE_NAME = "dbmoviefav"; + private static final int DATABASE_VERSION = 1; + + public static final String CREATE_TABLE_FAV = String.format("CREATE TABLE %s" + + " (%s INTEGER PRIMARY KEY AUTOINCREMENT," + + " %s TEXT NOT NULL," + + " %s TEXT NOT NULL," + + " %s TEXT NOT NULL," + + " %s TEXT NOT NULL," + + " %s TEXT NOT NULL)", + TABLE_FAVORITE, + _ID, + TITLE, + POSTER, + RELEASE, + POPULARITY, + OVERVIEW + + ); + + public DatabaseHelper(Context context){ + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(CREATE_TABLE_FAV); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("DROP TABLE IF EXISTS "+ TABLE_FAVORITE); + onCreate(db); + } + +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/FavoriteHelper.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/FavoriteHelper.java new file mode 100644 index 00000000..79c696f3 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/database/FavoriteHelper.java @@ -0,0 +1,137 @@ +package com.fajarnandagusti.cataloguemoviefinal.database; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; + +import com.fajarnandagusti.cataloguemoviefinal.model.Favorite; + +import java.util.ArrayList; + +import static android.provider.BaseColumns._ID; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.OVERVIEW; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.POPULARITY; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.POSTER; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.RELEASE; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.TITLE; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.TABLE_FAVORITE; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class FavoriteHelper { + private static String DATABASE_TABLE = TABLE_FAVORITE; + private Context context; + private DatabaseHelper databaseHelper; + private SQLiteDatabase database; + + + public FavoriteHelper(Context context){ + this.context = context; + } + + public FavoriteHelper open() throws SQLException { + databaseHelper = new DatabaseHelper(context); + database = databaseHelper.getWritableDatabase(); + return this; + } + public void close(){ + databaseHelper.close(); + } + + public ArrayList getAllData(){ + ArrayList arrayList = new ArrayList<>(); + Cursor cursor = database.query(DATABASE_TABLE, + null, + null, + null, + null, + null, + _ID +" ASC", + null); + cursor.moveToFirst(); + Favorite favorite; + + if (cursor.getCount()>0) { + do{ + favorite = new Favorite(); + favorite.setId(cursor.getInt(cursor.getColumnIndexOrThrow(_ID))); + favorite.setTitle(cursor.getString(cursor.getColumnIndexOrThrow(TITLE))); + favorite.setPosterPath(cursor.getString(cursor.getColumnIndexOrThrow(POSTER))); + favorite.setOverview(cursor.getString(cursor.getColumnIndexOrThrow(OVERVIEW))); + favorite.setReleaseDate(cursor.getString(cursor.getColumnIndexOrThrow(RELEASE))); + favorite.setPopularity(cursor.getString(cursor.getColumnIndexOrThrow(POPULARITY))); + + arrayList.add(favorite); + cursor.moveToNext(); + + }while (!cursor.isAfterLast()); + } + cursor.close(); + return arrayList; + } + + public long insert(Favorite favorite){ + ContentValues initialValues = new ContentValues(); + initialValues.put(POSTER, favorite.getPosterPath()); + initialValues.put(TITLE, favorite.getTitle()); + initialValues.put(OVERVIEW, favorite.getOverview()); + initialValues.put(RELEASE, favorite.getReleaseDate()); + initialValues.put(POPULARITY, favorite.getPopularity()); + return database.insert(DATABASE_TABLE, null, initialValues); + } + + public int update(Favorite favorite){ + ContentValues args = new ContentValues(); + args.put(POSTER, favorite.getPosterPath()); + args.put(TITLE, favorite.getTitle()); + args.put(OVERVIEW, favorite.getOverview()); + args.put(RELEASE, favorite.getReleaseDate()); + args.put(POPULARITY, favorite.getPopularity()); + return database.update(DATABASE_TABLE, args, _ID + "= '"+ favorite.getId() + "'", null); + } + + public int delete(int id){ + return database.delete(DATABASE_TABLE, _ID + " = '" +id+ "'", null); + } + + + + public Cursor queryProvider(){ + return database.query( + DATABASE_TABLE, + null, + null, + null, + null, + null, + _ID + " DESC" + ); + } + + public Cursor queryByIdProvider(String id){ + return database.query(DATABASE_TABLE + ,null + , _ID + " = ?" + ,new String[]{id} + ,null + ,null + ,null + ,null); + } + + public long insertProvider (ContentValues values){ + return database.insert(DATABASE_TABLE, null, values); + } + + public int updateProvider (String id, ContentValues values){ + return database.update(DATABASE_TABLE, values, _ID +" = ?", new String[]{id}); + } + + public int deleteProvider (String id){ + return database.delete(DATABASE_TABLE, _ID + " = ?", new String[]{id}); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/Favorite.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/Favorite.java new file mode 100644 index 00000000..f41e785d --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/Favorite.java @@ -0,0 +1,127 @@ +package com.fajarnandagusti.cataloguemoviefinal.model; + +import android.database.Cursor; +import android.os.Parcel; +import android.os.Parcelable; + +import static android.provider.BaseColumns._ID; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.OVERVIEW; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.POPULARITY; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.POSTER; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.RELEASE; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.TITLE; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.getColumnInt; +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.getColumnString; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class Favorite implements Parcelable { + private int id; + private String posterPath; + private String title; + private String releaseDate; + private String popularity; + private String overview; + + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getReleaseDate() { + return releaseDate; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public String getPopularity() { + return popularity; + } + + public void setPopularity(String popularity) { + this.popularity = popularity; + } + + public String getOverview() { + return overview; + } + + public void setOverview(String overview) { + this.overview = overview; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeString(posterPath); + dest.writeString(title); + dest.writeString(releaseDate); + dest.writeString(popularity); + dest.writeString(overview); + } + + protected Favorite(Parcel in) { + id = in.readInt(); + posterPath = in.readString(); + title = in.readString(); + releaseDate = in.readString(); + popularity = in.readString(); + overview = in.readString(); + } + + public Favorite(Cursor cursor){ + this.id = getColumnInt(cursor, _ID); + this.posterPath = getColumnString(cursor, POSTER); + this.title = getColumnString(cursor, TITLE); + this.overview = getColumnString(cursor, OVERVIEW); + this.releaseDate = getColumnString(cursor, RELEASE); + this.popularity = getColumnString(cursor, POPULARITY); + } + + public Favorite() { + + } + + public static final Creator CREATOR = new Creator() { + @Override + public Favorite createFromParcel(Parcel in) { + return new Favorite(in); + } + + @Override + public Favorite[] newArray(int size) { + return new Favorite[size]; + } + }; + +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/Movies.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/Movies.java new file mode 100644 index 00000000..098d02b5 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/Movies.java @@ -0,0 +1,113 @@ +package com.fajarnandagusti.cataloguemoviefinal.model; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class Movies implements Parcelable { + @SerializedName("id") + @Expose + private int id; + + @SerializedName("title") + @Expose + private String title; + + @SerializedName("poster_path") + @Expose + private String posterPath; + + @SerializedName("overview") + @Expose + private String overview; + + @SerializedName("release_date") + @Expose + private String releaseDate; + + @SerializedName("popularity") + @Expose + private String popularity; + + public Movies( int id, String title, String posterPath, String overview, String releaseDate, String popularity) { + this.id = id; + this.title = title; + this.posterPath = posterPath; + this.overview = overview; + this.releaseDate = releaseDate; + this.popularity = popularity; + } + + protected Movies(Parcel in) { + + id = in.readInt(); + title = in.readString(); + posterPath = in.readString(); + overview = in.readString(); + releaseDate = in.readString(); + popularity = in.readString(); + + } + + public Movies(){ + + } + + public int getId() { + return id; + } + + public String getTitle() { + return title; + } + + public String getPosterPath() { + return posterPath; + } + + public String getOverview() { + return overview; + } + + public String getReleaseDate() { + return releaseDate; + } + + public String getPopularity(){ + return popularity; + } + + + public static final Creator CREATOR = new Creator() { + @Override + public Movies createFromParcel(Parcel in) { + return new Movies(in); + } + + @Override + public Movies[] newArray(int size) { + return new Movies[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeString(title); + dest.writeString(posterPath); + dest.writeString(overview); + dest.writeString(releaseDate); + dest.writeString(popularity); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/ResponseMovie.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/ResponseMovie.java new file mode 100644 index 00000000..81c963a2 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/model/ResponseMovie.java @@ -0,0 +1,48 @@ +package com.fajarnandagusti.cataloguemoviefinal.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class ResponseMovie { + @SerializedName("page") + @Expose + private int page; + @SerializedName("total_results") + @Expose + private int totalResults; + @SerializedName("total_pages") + @Expose + private int totalPages; + @SerializedName("results") + @Expose + private List movies = null; + + public ResponseMovie(int page, int totalResults, int totalPages, List movies) { + this.page = page; + this.totalResults = totalResults; + this.totalPages = totalPages; + this.movies = movies; + } + + public int getPage() { + return page; + } + + public int getTotalResults() { + return totalResults; + } + + public int getTotalPages() { + return totalPages; + } + + public List getMovies() { + return movies; + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/provider/MovieProvider.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/provider/MovieProvider.java new file mode 100644 index 00000000..e936d54e --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/provider/MovieProvider.java @@ -0,0 +1,127 @@ +package com.fajarnandagusti.cataloguemoviefinal.provider; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract; +import com.fajarnandagusti.cataloguemoviefinal.database.FavoriteHelper; + +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.CONTENT_URI; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.AUTHORITY; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class MovieProvider extends ContentProvider { + private static final int MOVIE = 1; + private static final int MOVIE_ID = 2; + + private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + + static { + sUriMatcher.addURI(AUTHORITY, DatabaseContract.TABLE_FAVORITE, MOVIE); + + sUriMatcher.addURI(AUTHORITY, DatabaseContract.TABLE_FAVORITE+ "/#", + MOVIE_ID); + } + + private FavoriteHelper favoriteHelper; + + + @Override + public boolean onCreate() { + favoriteHelper = new FavoriteHelper(getContext()); + favoriteHelper.open(); + return true; + } + + @Nullable + @Override + public Cursor query(@NonNull Uri uri, String[] strings, String s, String[] strings1, String s1) { + Cursor cursor; + switch (sUriMatcher.match(uri)){ + case MOVIE: + cursor = favoriteHelper.queryProvider(); + break; + case MOVIE_ID: + cursor = favoriteHelper.queryByIdProvider(uri.getLastPathSegment()); + break; + default: + cursor=null; + break; + } + + if (cursor != null){ + cursor.setNotificationUri(getContext().getContentResolver(), uri); + } + return cursor; + } + + + @Override + public String getType(@NonNull Uri uri) { + return null; + } + + @Nullable + @Override + public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) { + long added; + switch (sUriMatcher.match(uri)){ + case MOVIE: + added = favoriteHelper.insertProvider(contentValues); + break; + default: + added = 0 ; + break; + } + + if (added > 0 ){ + getContext().getContentResolver().notifyChange(uri, null); + } + return Uri.parse(CONTENT_URI + "/" + added); + } + + @Override + public int delete(@NonNull Uri uri, String s, String[] strings) { + int deleted; + switch (sUriMatcher.match(uri)){ + case MOVIE_ID: + deleted = favoriteHelper.deleteProvider(uri.getLastPathSegment()); + break; + default: + deleted = 0; + break; + } + + if (deleted > 0){ + getContext().getContentResolver().notifyChange(uri, null); + } + return deleted; + } + + @Override + public int update(@NonNull Uri uri, ContentValues contentValues, String s, String[] strings) { + int update; + switch (sUriMatcher.match(uri)){ + case MOVIE_ID: + update = favoriteHelper.updateProvider(uri.getLastPathSegment(), contentValues); + break; + default: + update = 0 ; + break; + } + + if (update > 0){ + getContext().getContentResolver().notifyChange(uri, null); + + } + return update; + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/DailyReminderReceiver.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/DailyReminderReceiver.java new file mode 100644 index 00000000..af982d27 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/DailyReminderReceiver.java @@ -0,0 +1,72 @@ +package com.fajarnandagusti.cataloguemoviefinal.scheduler; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.TaskStackBuilder; +import android.widget.Toast; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.activity.MainActivity; + +import java.util.Calendar; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.EXTRA_MESSAGE_PREF; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.EXTRA_TYPE_PREF; + +/** + * Created by Gustiawan on 11/17/2018. + */ + +public class DailyReminderReceiver extends BroadcastReceiver { + private final int NOTIF_ID_REMINDER = 1; + + public DailyReminderReceiver(){ + + } + + @Override + public void onReceive(Context context, Intent intent) { + String message = intent.getStringExtra(EXTRA_MESSAGE_PREF); + String title = "Daily Reminder"; + int notifId = NOTIF_ID_REMINDER; + + showReminderNotification(context,title,message,notifId); + } + + private void showReminderNotification(Context context, String title, String message, int notifId) { + Intent intent = new Intent(context, MainActivity.class); + PendingIntent pendingIntent = TaskStackBuilder.create(context) + .addNextIntent(intent) + .getPendingIntent(NOTIF_ID_REMINDER, PendingIntent.FLAG_UPDATE_CURRENT); + + NotificationHelper notificationHelper = new NotificationHelper(context); + notificationHelper.createNotification(title, message); + } + + public void setReminder(Context context, String type, String time, String message){ + AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(context, DailyReminderReceiver.class); + intent.putExtra(EXTRA_MESSAGE_PREF,message); + intent.putExtra(EXTRA_TYPE_PREF,type); + String timeArray[] = time.split(":"); + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeArray[0])); + calendar.set(Calendar.MINUTE, Integer.parseInt(timeArray[1])); + calendar.set(Calendar.SECOND,0); + + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, NOTIF_ID_REMINDER,intent,0); + alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); + + Toast.makeText(context, R.string.dailyReminderSaved, Toast.LENGTH_SHORT).show(); + } + public void cancelReminder(Context context){ + AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(context, DailyReminderReceiver.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, NOTIF_ID_REMINDER,intent,0); + alarmManager.cancel(pendingIntent); + Toast.makeText(context, R.string.dailyReminderCanceled, Toast.LENGTH_SHORT).show(); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/NotificationHelper.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/NotificationHelper.java new file mode 100644 index 00000000..df2dfbaf --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/NotificationHelper.java @@ -0,0 +1,59 @@ +package com.fajarnandagusti.cataloguemoviefinal.scheduler; + +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.provider.Settings; +import android.support.v4.app.NotificationCompat; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.activity.MainActivity; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.NOTIFICATION_CHANNEL_ID; + +/** + * Created by Gustiawan on 11/17/2018. + */ + +public class NotificationHelper { + private Context mContext; + + public NotificationHelper(Context context) { + mContext = context; + } + + public void createNotification(String title, String message){ + Intent resultIntent = new Intent(mContext, MainActivity.class); + resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, + 0 , resultIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); + mBuilder.setSmallIcon(R.mipmap.ic_launcher); + mBuilder.setContentTitle(title) + .setContentText(message) + .setAutoCancel(false) + .setSound(Settings.System.DEFAULT_NOTIFICATION_URI) + .setContentIntent(resultPendingIntent); + + NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + int importance = NotificationManager.IMPORTANCE_HIGH; + NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance); + notificationChannel.enableLights(true); + notificationChannel.setLightColor(Color.RED); + notificationChannel.enableVibration(true); + notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); + assert mNotificationManager != null; + mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID); + mNotificationManager.createNotificationChannel(notificationChannel); + } + assert mNotificationManager != null; + mNotificationManager.notify(0, mBuilder.build()); + + } + +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/ReleaseReminderReceiver.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/ReleaseReminderReceiver.java new file mode 100644 index 00000000..56e7ae69 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/ReleaseReminderReceiver.java @@ -0,0 +1,113 @@ +package com.fajarnandagusti.cataloguemoviefinal.scheduler; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import android.widget.Toast; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.activity.DetailMovieActivity; +import com.fajarnandagusti.cataloguemoviefinal.api.ApiService; +import com.fajarnandagusti.cataloguemoviefinal.api.Client; +import com.fajarnandagusti.cataloguemoviefinal.model.Movies; +import com.fajarnandagusti.cataloguemoviefinal.model.ResponseMovie; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Random; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.API_KEY; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.BASE_URL_API; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.EXTRA_MESSAGE_RECIEVE; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.EXTRA_TYPE_RECIEVE; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.LANGUAGE; + +/** + * Created by Gustiawan on 11/17/2018. + */ + +public class ReleaseReminderReceiver extends BroadcastReceiver { + + public List listMovie = new ArrayList<>(); + private final int NOTIF_ID_RELEASE = 21; + + public ReleaseReminderReceiver() { + + } + + public void setReminder(Context context, String type, String time, String message){ + AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(context, ReleaseReminderReceiver.class); + intent.putExtra(EXTRA_MESSAGE_RECIEVE,message); + intent.putExtra(EXTRA_TYPE_RECIEVE,type); + String timeArray[] = time.split(":"); + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeArray[0])); + calendar.set(Calendar.MINUTE, Integer.parseInt(timeArray[1])); + calendar.set(Calendar.SECOND,0); + + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, NOTIF_ID_RELEASE,intent,0); + alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); + + Toast.makeText(context, R.string.reminderSave, Toast.LENGTH_SHORT).show(); + } + + public void cancelReminder(Context context){ + AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(context,ReleaseReminderReceiver.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, NOTIF_ID_RELEASE,intent,0); + alarmManager.cancel(pendingIntent); + Toast.makeText(context,R.string.reminderCancel, Toast.LENGTH_SHORT).show(); + } + + @Override + public void onReceive(Context context, Intent intent) { + getUpcomingMovie(context); + } + + private void getUpcomingMovie(final Context context) { + ApiService service = Client.getClient(BASE_URL_API).create(ApiService.class); + Call call = service.getUpComingMovie(API_KEY); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + listMovie = response.body().getMovies(); + List items = response.body().getMovies(); + int index = new Random().nextInt(items.size()); + Movies item = items.get(index); + int notifId = 200; + String title = items.get(index).getTitle(); + String message = items.get(index).getOverview(); + showNotification(context, title, message, notifId, item); + } + + @Override + public void onFailure(Call call, Throwable t) { + Log.d("getUpCommingMovie", "onFailure: " + t.toString()); + } + }); + } + + private void showNotification(Context context, String title, String message, int notifId, Movies item) { + + Intent i = new Intent(context, DetailMovieActivity.class); + i.putExtra("title", item.getTitle()); + i.putExtra("poster_path", item.getPosterPath()); + i.putExtra("overview", item.getOverview()); + i.putExtra("release_date", item.getReleaseDate()); + PendingIntent pendingIntent = PendingIntent.getActivity(context, notifId, i, PendingIntent.FLAG_UPDATE_CURRENT); + + + NotificationHelper notificationHelper = new NotificationHelper(context); + + notificationHelper.createNotification(title, message); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/ReminderPreference.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/ReminderPreference.java new file mode 100644 index 00000000..281cd5bc --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/scheduler/ReminderPreference.java @@ -0,0 +1,38 @@ +package com.fajarnandagusti.cataloguemoviefinal.scheduler; + +import android.content.Context; +import android.content.SharedPreferences; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.KEY_REMINDER_DAILY; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.KEY_REMINDER_MESSAGE_DAILY; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.KEY_REMINDER_MESSAGE_RELEASE; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.PREF_NAME; + +/** + * Created by Gustiawan on 11/17/2018. + */ + +public class ReminderPreference { + public SharedPreferences sharedPreferences; + public SharedPreferences.Editor editor; + + public ReminderPreference(Context context) { + sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); + editor = sharedPreferences.edit(); + } + + public void setReminderReleaseTime(String time){ + editor.putString(KEY_REMINDER_DAILY,time); + editor.commit(); + } + public void setReminderReleaseMessage (String message){ + editor.putString(KEY_REMINDER_MESSAGE_RELEASE,message); + } + public void setReminderDailyTime(String time){ + editor.putString(KEY_REMINDER_DAILY,time); + editor.commit(); + } + public void setReminderDailyMessage(String message){ + editor.putString(KEY_REMINDER_MESSAGE_DAILY,message); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/utils/DateFormat.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/utils/DateFormat.java new file mode 100644 index 00000000..5bca1d61 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/utils/DateFormat.java @@ -0,0 +1,27 @@ +package com.fajarnandagusti.cataloguemoviefinal.utils; + +import android.util.Log; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class DateFormat { + public static String dateConverter(String dateString){ + java.text.DateFormat currentDate = new SimpleDateFormat("yyyy-MM-dd"); + java.text.DateFormat newDate = new SimpleDateFormat("EEEE, dd MMMM yyyy"); + + try { + Date date = currentDate.parse(dateString); + return newDate.format(date); + }catch (ParseException e){ + Log.e("Date Format", e.toString()); + } + + return ""; + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/utils/Utility.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/utils/Utility.java new file mode 100644 index 00000000..b70a0170 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/utils/Utility.java @@ -0,0 +1,52 @@ +package com.fajarnandagusti.cataloguemoviefinal.utils; + +import com.fajarnandagusti.cataloguemoviefinal.BuildConfig; + +/** + * Created by Gustiawan on 11/16/2018. + */ + +public class Utility { + public final static String EXTRA_MOVIE = "movie"; + public final static String URL = "http://image.tmdb.org/t/p/w500"; + public final static String API_KEY = BuildConfig.API_KEY; + + public static final String BASE_URL_API = "https://api.themoviedb.org/"; + + public final static String KEY_PARCELABLE ="key_parcelable"; + + public final static String include_adult = "false"; + public final static String page = "1"; + + public static final String AUTHORITY = "com.fajarnandagusti.cataloguemoviefinal"; + public static final String SCHEME = "content"; + + + public static final String KEY_HEADER_UPCOMING_REMINDER = "upcomingReminder"; + public static final String KEY_HEADER_DAILY_REMINDER = "dailyReminder"; + + public static final String KEY_FIELD_UPCOMING_REMINDER = "checkedUpcoming"; + public static final String KEY_FIELD_DAILY_REMINDER = "checkedDaily"; + + public final static String PREF_NAME = "reminderPreferences"; + public static final String LANGUAGE = "en-US"; + + public final static String KEY_REMINDER_DAILY = "DailyTime"; + public final static String KEY_REMINDER_MESSAGE_RELEASE = "reminderMessageRelease"; + public final static String KEY_REMINDER_MESSAGE_DAILY = "reminderMessageDaily"; + public static final String EXTRA_MESSAGE_PREF = "message"; + public static final String EXTRA_TYPE_PREF = "type"; + public static final String TYPE_REMINDER_PREF = "reminderAlarm"; + public static final String EXTRA_MESSAGE_RECIEVE = "messageRelease"; + public static final String EXTRA_TYPE_RECIEVE = "typeRelease"; + public static final String TYPE_REMINDER_RECIEVE = "reminderAlarmRelease"; + + public static final String NOTIFICATION_CHANNEL_ID = "10001"; + + public final static int NOTIFICATION_ID = 501; + public final static int NOTIFICATION_ID_ = 21; + + public static final String TOAST_ACTION = "com.fajarnandagusti.cataloguemoviefinal.TOAST_ACTION"; + public static final String EXTRA_ITEM = "com.fajarnandagusti.cataloguemoviefinal.EXTRA_ITEM"; + public static final String ON_CLICK_FAVORITE_ACTION = "com.fajarnandagusti.cataloguemoviefinal.ON_CLICK_FAVORITE_ACTION"; +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/ImageBannerWidget.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/ImageBannerWidget.java new file mode 100644 index 00000000..dcf155ba --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/ImageBannerWidget.java @@ -0,0 +1,99 @@ +package com.fajarnandagusti.cataloguemoviefinal.widget; + +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.util.Log; +import android.widget.RemoteViews; +import android.widget.Toast; + +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.adapter.MovieAdapter; + +import java.util.Objects; + +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.EXTRA_ITEM; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.ON_CLICK_FAVORITE_ACTION; +import static com.fajarnandagusti.cataloguemoviefinal.utils.Utility.TOAST_ACTION; + +/** + * Implementation of App Widget functionality. + */ +public class ImageBannerWidget extends AppWidgetProvider { + + int appWidgetId, viewIndex; + + static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, + int appWidgetId) { + + Intent intent = new Intent(context, StackWidgetService.class); + intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); + + // Construct the RemoteViews object + RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.image_banner_widget); + views.setRemoteAdapter(R.id.stack_view, intent); + views.setEmptyView(R.id.stack_view, R.id.empty_view); + + Intent toastIntent = new Intent(context, ImageBannerWidget.class); + toastIntent.setAction(TOAST_ACTION); + toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); + + PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + views.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent); + + // Instruct the widget manager to update the widget + appWidgetManager.updateAppWidget(appWidgetId, views); + } + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + // There may be multiple widgets active, so update all of them + for (int appWidgetId : appWidgetIds) { + updateAppWidget(context, appWidgetManager, appWidgetId); + } + } + + @Override + public void onEnabled(Context context) { + // Enter relevant functionality for when the first widget is created + } + + @Override + public void onDisabled(Context context) { + // Enter relevant functionality for when the last widget is disabled + } + + @Override + public void onReceive(Context context, Intent intent) { + AppWidgetManager mgr = AppWidgetManager.getInstance(context); + + switch (Objects.requireNonNull(intent.getAction())) { + case TOAST_ACTION: + appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + viewIndex = intent.getIntExtra(EXTRA_ITEM, 0); + String title = intent.getStringExtra(MovieAdapter.EXTRA_MOVIE); + + Toast.makeText(context, title, Toast.LENGTH_SHORT).show(); + break; + case ON_CLICK_FAVORITE_ACTION: { + Log.d("TAG", "onReceive: " + "RECEIVED"); + int widgetIDs[] = mgr.getAppWidgetIds(new ComponentName(context, ImageBannerWidget.class)); + onUpdate(context, mgr, widgetIDs); + mgr.notifyAppWidgetViewDataChanged(widgetIDs, R.id.stack_view); + break; + + } + } + + super.onReceive(context, intent); + } +} + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/StackRemoteViewFactory.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/StackRemoteViewFactory.java new file mode 100644 index 00000000..863acaf6 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/StackRemoteViewFactory.java @@ -0,0 +1,126 @@ +package com.fajarnandagusti.cataloguemoviefinal.widget; + +import android.appwidget.AppWidgetManager; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.drawable.ColorDrawable; +import android.os.Binder; +import android.os.Bundle; +import android.util.Log; +import android.widget.RemoteViews; +import android.widget.RemoteViewsService; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.target.Target; +import com.fajarnandagusti.cataloguemoviefinal.R; +import com.fajarnandagusti.cataloguemoviefinal.adapter.MovieAdapter; +import com.fajarnandagusti.cataloguemoviefinal.model.Favorite; +import com.fajarnandagusti.cataloguemoviefinal.utils.Utility; + +import java.util.ArrayList; +import java.util.concurrent.ExecutionException; + +import static com.fajarnandagusti.cataloguemoviefinal.database.DatabaseContract.FavoriteColumn.CONTENT_URI; + +/** + * Created by Gustiawan on 11/17/2018. + */ + +public class StackRemoteViewFactory implements RemoteViewsService.RemoteViewsFactory { + private ArrayList mWidgetItems = new ArrayList<>(); + private Context mContext; + + public StackRemoteViewFactory(Context applicationContext, Intent intent) { + mContext = applicationContext; + int mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + } + + @Override + public void onCreate() { + + } + + @Override + public void onDataSetChanged() { + mWidgetItems.clear(); + final long identityToken = Binder.clearCallingIdentity(); + Cursor cursor = mContext.getContentResolver().query(CONTENT_URI, null, null, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + do { + Favorite favorite = new Favorite(cursor); + mWidgetItems.add(favorite); + cursor.moveToNext(); + } + while (!cursor.isAfterLast()); + } + + if (cursor != null) { + cursor.close(); + } + Binder.restoreCallingIdentity(identityToken); + + } + + @Override + public void onDestroy() { + + } + + @Override + public int getCount() { + return mWidgetItems.size(); + } + + @Override + public RemoteViews getViewAt(int position) { + Favorite currentMovieFavorite ; + Bundle extras = new Bundle(); + Bitmap bmp = null; + String releaseDate = null; + try { + currentMovieFavorite = mWidgetItems.get(position); + bmp = Glide.with(mContext) + .load(Utility.URL + currentMovieFavorite.getPosterPath()).asBitmap() + .error(new ColorDrawable(mContext.getResources().getColor(R.color.colorPrimaryDark))) + .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get(); + + releaseDate = currentMovieFavorite.getReleaseDate(); + extras.putString(MovieAdapter.EXTRA_MOVIE,currentMovieFavorite.getTitle()); + + } catch (InterruptedException | ExecutionException | IndexOutOfBoundsException e) { + Log.d("Error loading", "error"); + } + + RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_items); + rv.setImageViewBitmap(R.id.imgWidget, bmp); + rv.setTextViewText(R.id.txtDate, releaseDate); + Intent fillInIntent = new Intent(); + fillInIntent.putExtras(extras); + + rv.setOnClickFillInIntent(R.id.imgWidget, fillInIntent); + return rv; + } + + @Override + public RemoteViews getLoadingView() { + return null; + } + + @Override + public int getViewTypeCount() { + return 1; + } + + @Override + public long getItemId(int position) { + return 0; + } + + @Override + public boolean hasStableIds() { + return false; + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/StackWidgetService.java b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/StackWidgetService.java new file mode 100644 index 00000000..c4a16da2 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/java/com/fajarnandagusti/cataloguemoviefinal/widget/StackWidgetService.java @@ -0,0 +1,15 @@ +package com.fajarnandagusti.cataloguemoviefinal.widget; + +import android.content.Intent; +import android.widget.RemoteViewsService; + +/** + * Created by Gustiawan on 11/17/2018. + */ + +public class StackWidgetService extends RemoteViewsService { + @Override + public RemoteViewsFactory onGetViewFactory(Intent intent) { + return new StackRemoteViewFactory(this.getApplicationContext(), intent); + } +} diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-nodpi/example_appwidget_preview.png b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-nodpi/example_appwidget_preview.png new file mode 100644 index 00000000..894b069a Binary files /dev/null and b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-nodpi/example_appwidget_preview.png differ diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_camera.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_camera.xml new file mode 100644 index 00000000..0d9ea104 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_camera.xml @@ -0,0 +1,12 @@ + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_gallery.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_gallery.xml new file mode 100644 index 00000000..f6872c40 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_gallery.xml @@ -0,0 +1,9 @@ + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_manage.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_manage.xml new file mode 100644 index 00000000..c1be60b3 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_manage.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_send.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_send.xml new file mode 100644 index 00000000..00c668c6 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_send.xml @@ -0,0 +1,9 @@ + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_share.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_share.xml new file mode 100644 index 00000000..a28fb9e2 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_share.xml @@ -0,0 +1,9 @@ + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_slideshow.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_slideshow.xml new file mode 100644 index 00000000..209aa643 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v21/ic_menu_slideshow.xml @@ -0,0 +1,9 @@ + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..c7bd21db --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/baseline_av_timer_black_24dp.png b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/baseline_av_timer_black_24dp.png new file mode 100644 index 00000000..f646df0e Binary files /dev/null and b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/baseline_av_timer_black_24dp.png differ diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/baseline_play_circle_outline_black_24dp.png b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/baseline_play_circle_outline_black_24dp.png new file mode 100644 index 00000000..216dc913 Binary files /dev/null and b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/baseline_play_circle_outline_black_24dp.png differ diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/bg.jpeg b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/bg.jpeg new file mode 100644 index 00000000..b1384e8f Binary files /dev/null and b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/bg.jpeg differ diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_launcher_background.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..d5fccc53 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_search_white_24px.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_search_white_24px.xml new file mode 100644 index 00000000..be5ad99c --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_search_white_24px.xml @@ -0,0 +1,5 @@ + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_star_checked.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_star_checked.xml new file mode 100644 index 00000000..4e69e5a2 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_star_checked.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_star_unchecked.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_star_unchecked.xml new file mode 100644 index 00000000..e021e3d6 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_star_unchecked.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_stars_black_24dp.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_stars_black_24dp.xml new file mode 100644 index 00000000..61c5d7ac --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ic_stars_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ph.png b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ph.png new file mode 100644 index 00000000..f2535763 Binary files /dev/null and b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/ph.png differ diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/side_nav_bar.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/side_nav_bar.xml new file mode 100644 index 00000000..6d81870b --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/side_nav_bar.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/tmdb.png b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/tmdb.png new file mode 100644 index 00000000..799d0b80 Binary files /dev/null and b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/drawable/tmdb.png differ diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_detail_movie.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_detail_movie.xml new file mode 100644 index 00000000..59fb953f --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_detail_movie.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_favorite.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_favorite.xml new file mode 100644 index 00000000..d9cfdf5d --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_favorite.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_main.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..a61d8a63 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_now_playing.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_now_playing.xml new file mode 100644 index 00000000..552a962c --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_now_playing.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_setting.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_setting.xml new file mode 100644 index 00000000..7501c491 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_setting.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_upcoming.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_upcoming.xml new file mode 100644 index 00000000..11a8b158 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/activity_upcoming.xml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/app_bar_main.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/app_bar_main.xml new file mode 100644 index 00000000..381854e9 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/app_bar_main.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/content_main.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/content_main.xml new file mode 100644 index 00000000..aa7d53ef --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/content_main.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/image_banner_widget.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/image_banner_widget.xml new file mode 100644 index 00000000..a8f06829 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/image_banner_widget.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/list_movies.xml b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/list_movies.xml new file mode 100644 index 00000000..5ddb4e79 --- /dev/null +++ b/Android Projects/CatalogueMovieSqLiteFavorite/app/src/main/res/layout/list_movies.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + +