Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -9,13 +9,24 @@ public class MovieMapper {
public static final String QUERY_STRING_PAGE_UNIT = "display";
public static final String QUERY_STRING_START = "start";

public static Map<String, String> toRequest(String searchKey, int pageUnit, int start){
public static final String QUERY_STRING_GENRE = "genre";
public static final String QUERY_STRING_COUNTRY = "country";

public static Map<String, String> toRequest(String searchKey, int pageUnit, int start, String genre, String country){

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( genre != null && !genre.equals("0")){
queryMap.put(QUERY_STRING_GENRE, genre);
}

if( country != null && !country.equals("") ){
queryMap.put(QUERY_STRING_COUNTRY, country);
}

return queryMap;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.example.yeseul.movieapp.view.custom;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

com.example.yeseul.movieapp.view.custom 패키지는 커스텀 뷰를 보관하는 것으로 이해하고 있습니다.
FilterView 는 뷰의 목적이 아닌 값을 보관하기 위한 것 같은데 해당 패키지에 있는 이유가 있나요?

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.

mvp 패턴에 대해 잘 숙지하지 못해서 패키지를 어디에 분류할까 생각하다 넣었네요 .. 만약에 넣는다면 어디가 좋을까요 ??


import java.util.HashMap;

public class FilterView {

static HashMap<String,String> genreMap = null;
static HashMap<String,String> countryMap = null;

public synchronized static HashMap<String,String> getGenreMap() {

if( genreMap == null) {

genreMap = new HashMap<>();

genreMap.put("전체", "0");
genreMap.put("드라마", "1");
genreMap.put("판타지", "2");
genreMap.put("서부", "3");
genreMap.put("공포", "4");
genreMap.put("로맨스", "5");
genreMap.put("모험", "6");
genreMap.put("스릴러", "7");
genreMap.put("느와르", "8");
genreMap.put("컬트", "9");
genreMap.put("다큐멘터리", "10");
genreMap.put("코미디", "11");
genreMap.put("가족", "12");
genreMap.put("미스터리", "13");
genreMap.put("전쟁", "14");
genreMap.put("애니메이션", "15");
genreMap.put("범죄", "16");
genreMap.put("뮤지컬", "17");
genreMap.put("SF", "18");
genreMap.put("액션", "19");
genreMap.put("무협", "20");
genreMap.put("에로", "21");
genreMap.put("서스펜스", "22");
genreMap.put("서사", "23");
genreMap.put("블랙코미디", "24");
genreMap.put("실험", "25");
genreMap.put("영화카툰", "26");
genreMap.put("영화음악", "27");
genreMap.put("영화패러디포스터", "28");

}

return genreMap;
}


public synchronized static HashMap<String,String> getCountryMap() {

if( countryMap == null) {

countryMap = new HashMap<>();

countryMap.put("전체", "");
countryMap.put("한국", "KR");
countryMap.put("일본", "JP");
countryMap.put("미국", "US");
countryMap.put("홍콩", "HK");
countryMap.put("영국", "GB");
countryMap.put("프랑스", "FR");
countryMap.put("기타", "ETC");

}

return countryMap;
}

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

import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.Toast;

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;

import java.util.HashMap;

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

private MovieListAdapter adapter;
private String genre;
private String country;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  genrecountryMainPresenter에서 처리되기 때문에 Activity는 해당 정보를 가지고 있지 않는게 좋아 보입니다. 이 값은 Setter를 이용하여 Presenter로 넘겨주면 좋을 것 같습니다.

@Override
protected int getLayoutId() {
Expand All @@ -44,6 +51,9 @@ protected void onCreate(Bundle savedInstanceState) {
initView();

presenter.onViewCreated();

country = "";

}

private void initView() {
Expand All @@ -66,6 +76,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
}
});


// 키보드 검색 버튼 리스너 등록
binding.searchBox.etSearch.setOnEditorActionListener((v, actionId, event) -> {
if(actionId == EditorInfo.IME_ACTION_SEARCH){
Expand All @@ -77,6 +88,63 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat

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

// 필터 버튼 리스터 등록
binding.searchBox.btnFilter.setOnClickListener(v -> onFilterButtonClicked());

}

//필터 설정
private void onFilterButtonClicked() {


/* HashMap <String,String> countryMap = new HashMap<>();
countryMap.put("전체","");
countryMap.put("한국","KR");
countryMap.put("일본","JP");
countryMap.put("미국","US");
countryMap.put("홍콩","HK");
countryMap.put("영국","GB");
countryMap.put("프랑스","FR");
countryMap.put("기타","ETC");*/

Comment thread
wjddnwls918 marked this conversation as resolved.
Outdated
//국가 선택
AlertDialog.Builder cDialog = new AlertDialog.Builder(this);
cDialog.setTitle(R.string.country)
.setItems(R.array.country, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//country = countryMap.get(getResources().getStringArray(R.array.country)[which]);
country = getResources().getStringArray(R.array.country)[which];
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

인터페이스를 람다 표현식으로 사용하는건 어떨까요?
Android Java 8 언어 기능 사용

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.

넵 참고하겠습니다

@Override
public void onDismiss(DialogInterface dialog) {
presenter.setFilter(genre, country);
}
});


//장르 선택
AlertDialog.Builder gDialog = new AlertDialog.Builder(this);
gDialog.setTitle(R.string.genre)
.setItems(R.array.genre, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//genre = Integer.toString(which);
genre = getResources().getStringArray(R.array.genre)[which];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

which는 다이얼로그 인덱스입니다.
이를 이용하여 장르는 MainPresenterHashMap이 아닌 int값으로 가지고 있어도 괜찮아 보입니다.

}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
//orderFlag = true;
cDialog.show();
}
});

gDialog.show();


}

/**
Expand All @@ -87,7 +155,7 @@ private void onSearchButtonClicked(){
String searchKey = binding.searchBox.etSearch.getText().toString();

if(!TextUtils.isEmpty(searchKey)) {
presenter.onSearchButtonClicked(searchKey);
presenter.onSearchButtonClicked(searchKey,genre,country);
binding.recyclerMovie.scrollToPosition(0);
binding.emptyView.setText("");
KeyboardUtil.closeKeyboard(this, binding.searchBox.etSearch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface View extends BaseView {

interface Presenter extends BasePresenter {

void onSearchButtonClicked(String searchKey);
void onSearchButtonClicked(String searchKey, String genre, String coutnry);

void setAdapterView(AdapterContract.View adapterView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.example.yeseul.movieapp.mapper.MovieMapper;
import com.example.yeseul.movieapp.pojo.Movie;
import com.example.yeseul.movieapp.view.adapter.AdapterContract;
import com.example.yeseul.movieapp.view.custom.FilterView;

import java.util.HashMap;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
Expand All @@ -23,15 +25,27 @@ public class MainPresenter implements MainContract.Presenter {
private AdapterContract.Model<Movie> adapterModel;

private String searchKey = ""; // 검색 키워드
private String genre = "";
private String country = "";
private final int PAGE_UNIT = 20; // 한번에 가져올 데이터 개수
private int currentPage = 0; // 현재 페이지 index
private boolean isEndOfPage = false; // 페이지 끝 flag

private ObservableField<String> filter = new ObservableField<>("필터");

public MainPresenter(MainContract.View view, MovieRepository repository) {
this.view = view;
this.repository = repository;
}

public ObservableField<String> getFilter() {
return filter;
}

public void setFilter(String genre, String country) {
filter.set("장르 : " + genre +"\n"+"국가 : "+country);
}

@Override
public void onViewCreated() {
// do nothing
Expand All @@ -54,8 +68,10 @@ public void loadItems(boolean isRefresh) {
}

@Override
public void onSearchButtonClicked(String searchKey) {
public void onSearchButtonClicked(String searchKey, String genre, String country) {
this.searchKey = searchKey;
this.genre = genre;
this.country = country;
loadItems(true);
}

Expand All @@ -76,7 +92,10 @@ private void getMovieList(){

isLoading.set(true);

repository.searchMovies(MovieMapper.toRequest(searchKey, PAGE_UNIT, (PAGE_UNIT * currentPage++) + 1))
HashMap<String,String> genreMap = FilterView.getGenreMap();
HashMap<String,String> countryMap = FilterView.getCountryMap();

repository.searchMovies(MovieMapper.toRequest(searchKey, PAGE_UNIT, (PAGE_UNIT * currentPage++) + 1, genreMap.get(genre), countryMap.get(country)))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> {

Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout/layout_search_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<EditText
android:id="@+id/et_search"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_weight="4"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/padding_main"
android:layout_marginStart="@dimen/padding_main"
Expand All @@ -30,6 +30,17 @@
android:textSize="@dimen/text_size_main"
android:gravity="center_vertical"/>

<Button
android:id="@+id/btn_filter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:background="@null"
android:textSize="16sp"
android:text="@{presenter.filter}"
/>

<Button
android:id="@+id/btn_submit"
android:layout_width="wrap_content"
Expand Down
50 changes: 50 additions & 0 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="genre">

<item> 전체 </item>
<item> 드라마 </item>
<item> 판타지 </item>
<item> 서부 </item>
<item> 공포 </item>
<item> 로맨스 </item>
<item> 모험 </item>
<item> 스릴러 </item>
<item> 느와르 </item>
<item> 컬트 </item>
<item> 다큐멘터리 </item>
<item> 코미디 </item>
<item> 가족 </item>
<item> 미스터리 </item>
<item> 전쟁 </item>
<item> 애니메이션 </item>
<item> 범죄 </item>
<item> 뮤지컬 </item>
<item> SF </item>
<item> 액션 </item>
<item> 무협 </item>
<item> 에로 </item>
<item> 서스펜스 </item>
<item> 서사 </item>
<item> 블랙코미디 </item>
<item> 실험 </item>
<item> 영화카툰 </item>
<item> 영화음악 </item>
<item> 영화패러디포스터 </item>

</string-array>

<string-array name="country">

<item> 전체 </item>
<item> 한국 </item>
<item> 일본 </item>
<item> 미국 </item>
<item> 홍콩 </item>
<item> 영국 </item>
<item> 프랑스 </item>
<item> 기타 </item>

</string-array>

</resources>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

고생하셨습니다. 확실히 영화를 검색하는 것에 있어 필터를 검색하는 것은 좋은 아이디어라고 생각합니다.
저는 기능적으로 모든 필터를 검사하는 것이 아닌, 검색한 결과에 대한 장르만 부분적으로 판별했으면 더 좋았을 것이라고 생각했습니다.
또한 resource에 값을 추가하고, HashMap으로도 관리했던 것 같은데,
두 가지를 더 간단하게 할 수 있는 방법은 없었을까? 생각했습니다.

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.

위에서 조언해주신대로 presenter에서 처리하는 방법을 생각해봐야겠네요

9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
<string name="search_hint">검색어를 입력하세요.</string>
<string name="search_submit">검색</string>
<string name="search_result_empty">에 대한 검색결과가 없습니다.</string>

//사전 미션
<string name="search_filter">조건 검색</string>
<string name="genre">장르</string>
<string name="country">국가</string>
<string name="ok"> 확인 </string>
<string name="next"> 다음 </string>
<string name="cancel"> 취소 </string>

</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.3.0'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
Loading