Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ public class MovieMapper {
public static final String QUERY_STRING_SEARCH_KEY = "query";
public static final String QUERY_STRING_PAGE_UNIT = "display";
public static final String QUERY_STRING_START = "start";
public static final String QUERY_STRING_YEAR_FROM="yearFrom";
public static final String QUERY_STRING_YEAR_TO="yearTo";

public static Map<String, String> toRequest(String searchKey, int pageUnit, int start){
public static Map<String, String> toRequest(String searchKey, int pageUnit, int start,int yearFrom, int yearTo){

Map<String, String> queryMap = new HashMap<>();
queryMap.put(QUERY_STRING_SEARCH_KEY, searchKey);
queryMap.put(QUERY_STRING_PAGE_UNIT, ""+pageUnit);
queryMap.put(QUERY_STRING_START, ""+start);

if(yearFrom!=0&&yearTo!=0) {
queryMap.put(QUERY_STRING_YEAR_FROM,""+yearFrom);
queryMap.put(QUERY_STRING_YEAR_TO,""+yearTo);
}
return queryMap;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.yeseul.movieapp.view.main;

import android.app.AlertDialog;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -10,14 +11,15 @@
import android.text.Html;
import android.text.TextUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.NumberPicker;

import com.example.yeseul.movieapp.R;
import com.example.yeseul.movieapp.data.source.movie.MovieRepository;
import com.example.yeseul.movieapp.databinding.ActivityMovieBinding;
import com.example.yeseul.movieapp.utils.KeyboardUtil;
import com.example.yeseul.movieapp.view.BaseActivity;

public class MainActivity extends BaseActivity<ActivityMovieBinding, MainPresenter> implements MainContract.View {
public class MainActivity extends BaseActivity<ActivityMovieBinding, MainPresenter> implements MainContract.View{

private MovieListAdapter adapter;

Expand Down Expand Up @@ -77,6 +79,16 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat

// 검색 버튼 리스너 등록
binding.searchBox.btnSubmit.setOnClickListener(v -> onSearchButtonClicked());

//년도 버튼 리스너 등록
binding.searchBox.yearBtn.setOnClickListener(v->onYearButtonClicked());
}

// 년도 버튼 눌렀을 때 호출
private void onYearButtonClicked(){
NumberPickerDialog dialog=new NumberPickerDialog();
dialog.setListener(presenter);
dialog.show(getSupportFragmentManager(),"Year Select");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface View extends BaseView {
}

interface Presenter extends BasePresenter {
void onYearButtonClicked(int from,int to);

void onSearchButtonClicked(String searchKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.annotation.SuppressLint;
import android.databinding.ObservableBoolean;
import android.databinding.ObservableField;

import com.example.yeseul.movieapp.data.source.movie.MovieRepository;
import com.example.yeseul.movieapp.mapper.MovieMapper;
Expand All @@ -26,6 +25,8 @@ public class MainPresenter implements MainContract.Presenter {
private final int PAGE_UNIT = 20; // 한번에 가져올 데이터 개수
private int currentPage = 0; // 현재 페이지 index
private boolean isEndOfPage = false; // 페이지 끝 flag
private int yearFrom=0; //시작 년도
private int yearTo=0; //끝 년도

public MainPresenter(MainContract.View view, MovieRepository repository) {
this.view = view;
Expand Down Expand Up @@ -76,7 +77,7 @@ private void getMovieList(){

isLoading.set(true);

repository.searchMovies(MovieMapper.toRequest(searchKey, PAGE_UNIT, (PAGE_UNIT * currentPage++) + 1))
repository.searchMovies(MovieMapper.toRequest(searchKey, PAGE_UNIT, (PAGE_UNIT * currentPage++) + 1,yearFrom,yearTo))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> {

Expand Down Expand Up @@ -111,4 +112,11 @@ private void getMovieList(){
view.onSearchResultEmpty(searchKey);
});
}

@Override
public void onYearButtonClicked(int from,int to){
yearFrom=from;
yearTo=to;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.example.yeseul.movieapp.view.main;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.widget.NumberPicker;

import com.example.yeseul.movieapp.R;
import com.example.yeseul.movieapp.databinding.YearDialogBinding;
import com.example.yeseul.movieapp.utils.BindingUtil;

public class NumberPickerDialog extends DialogFragment {
private MainContract.Presenter listener;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

그냥 Dialog 대신 DialogFragment 를 이용할 때 얻을 수 있는 장점은 무엇인가요 ?

private YearDialogBinding binding;
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
binding= DataBindingUtil.inflate(LayoutInflater.from(getContext()),R.layout.year_dialog,null,false);
binding.setDialog(this);
LayoutInflater inflater =getActivity().getLayoutInflater();
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
builder.setTitle("제작년도 설정");
builder.setView(binding.getRoot())
.setPositiveButton("OK",((dialog, which) -> listener.onYearButtonClicked(binding.yearFrom.getValue(),binding.yearTo.getValue())))
.setNegativeButton("Cancel", ((dialog, which) ->listener.onYearButtonClicked(0,0)));
binding.yearFrom.setMinValue(1990);
binding.yearFrom.setMaxValue(2019);
binding.yearFrom.setValue(2019);
binding.yearTo.setMinValue(1990);
binding.yearTo.setMaxValue(2019);
binding.yearTo.setValue(2019);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

    binding.yearFrom.setMinValue(1990);
    binding.yearFrom.setMaxValue(2019);
    binding.yearFrom.setValue(2019);
    binding.yearTo.setMinValue(1990);
    binding.yearTo.setMaxValue(2019);
    binding.yearTo.setValue(2019);

최소값이 1990이 최대인가요??
나중에 수정이 용이하게 다른 파일에 값들을 지정하는것도 좋을 것같습니다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

네 조언 감사합니다

binding.yearFrom.setWrapSelectorWheel(false);
binding.yearTo.setWrapSelectorWheel(false);
return builder.create();
}

public MainContract.Presenter getListener(){
return listener;
}
public void setListener(MainContract.Presenter listener){
this.listener=listener;
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/layout_search_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
android:textColor="@android:color/black"
android:textSize="@dimen/text_size_main"
android:gravity="center_vertical"/>
<Button
android:id="@+id/year_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="16sp"
android:text="년도"/>

<Button
android:id="@+id/btn_submit"
Expand Down
57 changes: 57 additions & 0 deletions app/src/main/res/layout/year_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="dialog"
type="com.example.yeseul.movieapp.view.main.NumberPickerDialog"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/year_from_text"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="시작년도" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

시작년도종료년도 문자열을 strings.xml 에서 관리해도 좋을 것 같습니다


<TextView
android:id="@+id/year_to_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="0.5"
android:text="종료년도" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<NumberPicker
android:id="@+id/year_From"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5">

</NumberPicker>

<NumberPicker
android:id="@+id/year_To"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5">

</NumberPicker>
</LinearLayout>
</LinearLayout>
</layout>