Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tgs.app.submission4aplikasilocalstorage.main;
- import android.content.Intent;
- import android.os.Bundle;
- import android.provider.Settings;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.appcompat.widget.Toolbar;
- import androidx.viewpager.widget.ViewPager;
- import com.google.android.material.tabs.TabLayout;
- import java.util.ArrayList;
- import java.util.List;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- import tgs.app.submission4aplikasilocalstorage.entity.Movie;
- import tgs.app.submission4aplikasilocalstorage.favorite.FavoriteActivity;
- import tgs.app.submission4aplikasilocalstorage.R;
- import tgs.app.submission4aplikasilocalstorage.model.ListMovie;
- import tgs.app.submission4aplikasilocalstorage.notification.MovieDailyReminder;
- import tgs.app.submission4aplikasilocalstorage.notification.MovieReleaseTodayReminder;
- import tgs.app.submission4aplikasilocalstorage.retrofit.Api;
- import tgs.app.submission4aplikasilocalstorage.retrofit.ApiInterface;
- import tgs.app.submission4aplikasilocalstorage.search.SearchMovie;
- public class MainActivity extends AppCompatActivity {
- List<ListMovie.DataMovie> listRelease;
- Movie movie;
- ArrayList<Movie> arrayMovie = new ArrayList<>();
- MovieReleaseTodayReminder movieReleaseTodayReminder;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- MovieDailyReminder.setAlarm(this);
- movie = new Movie();
- movieReleaseTodayReminder = new MovieReleaseTodayReminder();
- TabLayout tabLayout = findViewById(R.id.tabLayout);
- ViewPager viewPager = findViewById(R.id.viewPager);
- Toolbar toolBar = findViewById(R.id.toolBar);
- toolBar.setTitle("Movie Catalogue");
- MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager(), this);
- viewPager.setAdapter(myPagerAdapter);
- tabLayout.setupWithViewPager(viewPager);
- setSupportActionBar(toolBar);
- releaseTodayAlarm();
- }
- private void releaseTodayAlarm() {
- ApiInterface apiInterface = Api.getUrl().create(ApiInterface.class);
- Call<ListMovie> call = apiInterface.getMovieRelease();
- call.enqueue(new Callback<ListMovie>() {
- @Override
- public void onResponse(Call<ListMovie> call, Response<ListMovie> response) {
- if (response.body() != null) {
- listRelease = response.body().getReadListMovie();
- }
- for (int i=0; i < listRelease.size(); i++) {
- Log.e("Release", listRelease.get(i).getTitle());
- movie.setId(i);
- movie.setMovie_id(listRelease.get(i).getId());
- movie.setMovie_title(listRelease.get(i).getTitle());
- Log.e("Relloop", listRelease.get(i).getTitle());
- arrayMovie.add(movie);
- // movie.setMovie_release(listRelease.get(i).getRelease_date());
- // movie.setMovie_score(listRelease.get(i).getVote_average());
- // movie.setMovie_overview(listRelease.get(i).getOverview());
- // movie.setMovie_image(listRelease.get(i).getPoster_path());
- }
- movieReleaseTodayReminder.setAlarm(getApplicationContext(), arrayMovie);
- }
- @Override
- public void onFailure(Call<ListMovie> call, Throwable t) {
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu, menu);
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.setting){
- Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
- startActivity(intent);
- }
- if (item.getItemId() == R.id.list_favorite){
- Intent intent = new Intent(this, FavoriteActivity.class);
- startActivity(intent);
- }
- if (item.getItemId() == R.id.search_button){
- startActivity(new Intent(this, SearchMovie.class));
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement