Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Comments

Homework9#9

Open
AndreiGrek wants to merge 2 commits intomasterfrom
Homework9
Open

Homework9#9
AndreiGrek wants to merge 2 commits intomasterfrom
Homework9

Conversation

@AndreiGrek
Copy link
Owner

No description provided.

import java.util.List;

public interface ListWeatherView {
void showData(List<ListWeather> listWeathers, MainWeather mainWeather);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы разделил этот метод на два. Это тебе даст больше контроля над View. Если тебе придется обновить что-то одно, то ты, собственно, вызовешь конкретный метод

public void glide(MainWeather mainWeather) {
Glide
.with(MainActivity.this)
.load(String.format(imageUri, mainWeather.getListWeathers().get(0).getWeather().get(0).getIcon()).toLowerCase())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Url для картинки должен быть уже подготовлен к тому моменту как MainWeather попадет в активити. То есть отформатировать и подготовить этот URL надо заранее

super.onDestroy();
}

public void glide(MainWeather mainWeather) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

метод имеет неинформативное имя. Надо дать более осмысленное. Также не думаю, что метод должен публичным, потому что он используется только внутри конкретной активити

@Override
public void showData(List<ListWeather> listWeathers, MainWeather mainWeather) {
if (!temperatureCheck) {
T = " C";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

подготовка контента должна просиходить на уровне презентера, а не в самой активити. Активити только показывает то, чт оей дают

if (!temperatureCheck) {
T = " C";
temperature = mainWeather.getListWeathers().get(0).getMain().getTemp();
temperatureTextView.setText(String.valueOf(temperature) + " C");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

подготовка контента должна просиходить на уровне презентера, а не в самой активити. Активити только показывает то, чт оей дают

adapter.setListWeathers(mainWeather.getListWeathers(), T);
glide(mainWeather);
} else {
T = " F";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

подготовка контента должна просиходить на уровне презентера, а не в самой активити. Активити только показывает то, чт оей дают

} else {
T = " F";
temperature = mainWeather.getListWeathers().get(0).getMain().getTemp();
temperatureTextView.setText(String.valueOf(temperature) + " F");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

подготовка контента должна просиходить на уровне презентера, а не в самой активити. Активити только показывает то, чт оей дают


@Override
public void showError() {
Toast.makeText(this, "Ошибка", Toast.LENGTH_SHORT).show();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше используй Snackbar. Тост уже довольно устаревший компонент


public class MainActivityPresenter {
private CompositeDisposable compositeDisposable;
ListWeatherView view;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет модификатора доступа

public void showInfoCelsium() {
ApiFactory apiFactory = ApiFactory.getInstance();
ApiService apiService = apiFactory.getApiService();
compositeDisposable = new CompositeDisposable();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompositeDisposable не нужно постоянно пересоздавать. Он создается только один раз. Инициализируй его при создании презентера

});
compositeDisposable.add(disposable);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя есть два метода: showInfoCelsium и showInfoFarenhate. В них есть одинаковые части кода. Их можно выделить в отдельные методы. Также ты можешь сделать конзюмеры для подписки и ошибки полями класса и просто передавать их в сабскрайб, чтобы постоянно не копипастить этот код

});
}

void saveBoolean(boolean temperatureCheck) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

дай более информативное имя методу

ed.apply();
}

public boolean loadBoolean() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

дай более информативное имя методу

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
temperatureCheck = true;
Toast.makeText(SettingsActivity.this, "Включен режим Фаренгейт", Toast.LENGTH_SHORT).show();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше Snackbar

saveBoolean(temperatureCheck);
} else {
temperatureCheck = false;
Toast.makeText(SettingsActivity.this, "Включен режим Цельсий", Toast.LENGTH_SHORT).show();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше Snackbar

public class WeatherAdapter extends RecyclerView.Adapter<WeatherAdapter.WeatherViewHolder> {

List<ListWeather> listWeathers;
MainActivity mainActivity;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ссфлки на активити в адаптере быть не должно. Контекст ты можешь получить из itemView твоего ViewHolder

weatherViewHolder.textViewTime.setText(listWeather.getDtTxt());
Glide
.with(mainActivity)
.load(String.format(imageUri, listWeather.getWeather().get(0).getIcon()).toLowerCase())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Url для картинки должен быть уже подготовлен к тому моменту как MainWeather попадет в активити. То есть отформатировать и подготовить этот URL надо заранее. Адаптер просто учавствутет в процессе отображения контента, по сути он тоже часть view. Поэтому он должен просто показывать данные


public class WeatherAdapter extends RecyclerView.Adapter<WeatherAdapter.WeatherViewHolder> {

List<ListWeather> listWeathers;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет модификатора доступа

Comment on lines +51 to +52
weatherViewHolder.temperatureTextView.setText(String.valueOf(listWeather.getMain().getTemp()) + T);
weatherViewHolder.textViewDescription.setText(String.valueOf(listWeather.getWeather().get(0).getDescription()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

подготовка контента должна просиходить на уровне презентера, а не в самой активити. Активити только показывает то, чт оей дают

public interface ApiService {

@GET("forecast?q=Minsk&units=metric&cnt=25&appid=60ac937a95b7355dbf856446fad8af84")
Observable<MainWeather> getMainWeatherCels();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы тут использовал Single. Он больше подходит. По сути ты каждый раз делаешь делаешь новый запрос и генеришь новый Observable, поэтому он тут бесполезен

Observable<MainWeather> getMainWeatherCels();

@GET("forecast?q=Minsk&units=imperial&cnt=25&appid=60ac937a95b7355dbf856446fad8af84")
Observable<MainWeather> getMainWeatherFarenhate();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы тут использовал Single. Он больше подходит. По сути ты каждый раз делаешь делаешь новый запрос и генеришь новый Observable, поэтому он тут бесполезен


public interface ApiService {

@GET("forecast?q=Minsk&units=metric&cnt=25&appid=60ac937a95b7355dbf856446fad8af84")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appid можно вынести в константу прямо в этом интерфейсе

@GET("forecast?q=Minsk&units=metric&cnt=25&appid=60ac937a95b7355dbf856446fad8af84")
Observable<MainWeather> getMainWeatherCels();

@GET("forecast?q=Minsk&units=imperial&cnt=25&appid=60ac937a95b7355dbf856446fad8af84")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appid можно вынести в константу прямо в этом интерфейсе

Comment on lines +9 to +10


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

убери пустые строчки

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Те же замечания, что и для mvp-реализации

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants