1 Теориялық бөлім



бет2/3
Дата11.05.2022
өлшемі2,23 Mb.
#142640
1   2   3
Байланысты:
Реферат

package com.sumin.mymovies;


import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;


import com.sumin.mymovies.adapters.MovieAdapter;
import com.sumin.mymovies.data.MainViewModel;
import com.sumin.mymovies.data.Movie;
import com.sumin.mymovies.utils.JSONUtils;
import com.sumin.mymovies.utils.NetworkUtils;


import org.json.JSONObject;


import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;


public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks {


private Switch switchSort;
private RecyclerView recyclerViewPosters;
private MovieAdapter movieAdapter;
private TextView textViewTopRated;
private TextView textViewPopularity;
private ProgressBar progressBarLoading;


private MainViewModel viewModel;
private int getColumnCount() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = (int) (displayMetrics.widthPixels / displayMetrics.density);
return width / 185 > 2 ? width / 185 : 2;
}


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lang = Locale.getDefault().getLanguage();
loaderManager = LoaderManager.getInstance(this);
viewModel = ViewModelProviders.of(this).get(MainViewModel.class);
switchSort = findViewById(R.id.switchSort);
textViewPopularity = findViewById(R.id.textViewPopularity);
textViewTopRated = findViewById(R.id.textViewTopRated);
progressBarLoading = findViewById(R.id.progressBarLoading);
recyclerViewPosters = findViewById(R.id.recyclerViewPosters);
recyclerViewPosters.setLayoutManager(new GridLayoutManager(this, getColumnCount()));
movieAdapter = new MovieAdapter();
recyclerViewPosters.setAdapter(movieAdapter);
switchSort.setChecked(true);
switchSort.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
page = 1;
setMethodOfSort(isChecked);
}
});
switchSort.setChecked(false);
movieAdapter.setOnPosterClickListener(new MovieAdapter.OnPosterClickListener() {
@Override
public void onPosterClick(int position) {


Достарыңызбен бөлісу:
1   2   3




©engime.org 2024
әкімшілігінің қараңыз

    Басты бет