Skip to content

Commit

Permalink
v1.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
iMeiji committed Jun 16, 2017
1 parent 42067aa commit f83d43e
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 112 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@

## Changelog
```
2017-6-16
重写搜索模块(beta)
重构代码
2017-6-4
添加导航栏着色设置选项
添加视频横屏设置选项
Expand Down
7 changes: 2 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId "com.meiji.toutiao"
minSdkVersion 16
targetSdkVersion 25
versionCode 3
versionName "1.2.5.2"
versionCode 4
versionName "1.2.6"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -109,7 +109,4 @@ dependencies {
debugCompile 'com.facebook.stetho:stetho:1.5.0'
testCompile 'junit:junit:4.12'
compile 'me.drakeet.multitype:multitype:3.0.0'
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
compile 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.0.0'

}
48 changes: 24 additions & 24 deletions app/src/main/java/com/meiji/toutiao/bean/search/SearchBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ public static class DataBeanX {
private int cell_type;
private String id_str;
private String ala_src;
private DataBean data;
// private DataBean data;
private long id;
private DisplayBean display;
// private DisplayBean display;
private String media_name;
private int repin_count;
private int ban_comment;
Expand Down Expand Up @@ -332,7 +332,7 @@ public static class DataBeanX {
private String video_duration_str;
private int group_flags;
private int gallery_pic_count;
private List<String> tokens;
// private List<String> tokens;
private List<ImageListBean> image_list;
private List<QueriesBean> queries;

Expand Down Expand Up @@ -360,13 +360,13 @@ public void setAla_src(String ala_src) {
this.ala_src = ala_src;
}

public DataBean getData() {
return data;
}

public void setData(DataBean data) {
this.data = data;
}
// public DataBean getData() {
// return data;
// }
//
// public void setData(DataBean data) {
// this.data = data;
// }

public long getId() {
return id;
Expand All @@ -376,13 +376,13 @@ public void setId(long id) {
this.id = id;
}

public DisplayBean getDisplay() {
return display;
}

public void setDisplay(DisplayBean display) {
this.display = display;
}
// public DisplayBean getDisplay() {
// return display;
// }
//
// public void setDisplay(DisplayBean display) {
// this.display = display;
// }

public String getMedia_name() {
return media_name;
Expand Down Expand Up @@ -808,13 +808,13 @@ public void setGallery_pic_count(int gallery_pic_count) {
this.gallery_pic_count = gallery_pic_count;
}

public List<String> getTokens() {
return tokens;
}

public void setTokens(List<String> tokens) {
this.tokens = tokens;
}
// public List<String> getTokens() {
// return tokens;
// }
//
// public void setTokens(List<String> tokens) {
// this.tokens = tokens;
// }

public List<ImageListBean> getImage_list() {
return image_list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected SearchViewBinder.ViewHolder onCreateViewHolder(@NonNull LayoutInflater
protected void onBindViewHolder(@NonNull SearchViewBinder.ViewHolder holder, @NonNull final SearchBean.DataBeanX item) {
try {

if (item.getImage_list().size() > 0) {
if (item.getImage_list() != null && item.getImage_list().size() > 0) {
String url = item.getImage_list().get(0).getUrl();
ImageLoader.loadCenterCrop(holder.itemView.getContext(), url, holder.iv_image, R.color.viewBackground);
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public void onClick(View v) {
}
});
} catch (Exception e) {

e.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Created by Meiji on 2017/2/7.
*/

@Deprecated
interface ISearch {

interface View extends IBaseView<Presenter> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.meiji.toutiao.R;
import com.meiji.toutiao.module.base.BaseActivity;

@Deprecated
public class SearchActivity extends BaseActivity {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* Created by Meiji on 2017/5/9.
*/

@Deprecated
public class SearchFragment extends BaseFragment<ISearch.Presenter> implements ISearch.View, SwipeRefreshLayout.OnRefreshListener {

private RecyclerView recycler_view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Created by Meiji on 2017/2/7.
*/

@Deprecated
class SearchPresenter implements ISearch.Presenter {

private static final String TAG = "SearchPresenter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.support.v7.widget.SearchViewQueryTextEvent;
import com.meiji.toutiao.R;
import com.meiji.toutiao.RetrofitFactory;
import com.meiji.toutiao.adapter.base.BasePagerAdapter;
Expand All @@ -36,9 +35,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
Expand All @@ -52,15 +49,15 @@
public class SearchActivity2 extends BaseActivity {

private static final String TAG = "SearchActivity2";
private TabLayout tab_layout;
private ViewPager view_pager;
private BasePagerAdapter adapter;
private TabLayout tabLayout;
private ViewPager viewPager;
private BasePagerAdapter pagerAdapter;
private List<Fragment> fragmentList = new ArrayList<>();
private String[] titles = new String[]{"综合", "视频", "图集", "用户", "问答"};
private SearchView searchView;
private LinearLayout search_layout;
private ListView listview;
private MyAdapter myAdapter;
private LinearLayout searchLayout;
private ListView listView;
private SearchAdapter searchAdapter;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -72,32 +69,43 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
initToolBar(toolbar, true, "");
tab_layout = (TabLayout) findViewById(R.id.tab_layout);
view_pager = (ViewPager) findViewById(R.id.view_pager);

tab_layout.setBackgroundColor(SettingsUtil.getInstance().getColor());
tab_layout.setupWithViewPager(view_pager);
tab_layout.setTabMode(TabLayout.MODE_SCROLLABLE);
search_layout = (LinearLayout) findViewById(R.id.search_layout);
listview = (ListView) findViewById(R.id.listview);

myAdapter = new MyAdapter(this, -1);
listview.setAdapter(myAdapter);
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
viewPager = (ViewPager) findViewById(R.id.view_pager);

tabLayout.setBackgroundColor(SettingsUtil.getInstance().getColor());
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
searchLayout = (LinearLayout) findViewById(R.id.search_layout);
listView = (ListView) findViewById(R.id.listview);

searchAdapter = new SearchAdapter(this, -1);
listView.setAdapter(searchAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String keyWord = searchAdapter.getItem(position).getKeyword();
Log.d(TAG, "onItemClick: " + keyWord);
initData(keyWord);
pagerAdapter.notifyDataSetChanged();
searchView.clearFocus();
searchView.setQuery(keyWord, true);
}
});
}

private void initData(String query) {
search_layout.setVisibility(View.VISIBLE);
listview.setVisibility(View.GONE);
searchLayout.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
if (fragmentList.size() > 0) {
fragmentList.clear();
}
for (int i = 1; i < titles.length + 1; i++) {
fragmentList.add(SearchFragment2.newInstance(query, i + ""));
}
Log.d(TAG, "initData: " + query);
adapter = new BasePagerAdapter(getSupportFragmentManager(), fragmentList, titles);
view_pager.setAdapter(adapter);
view_pager.setOffscreenPageLimit(5);
pagerAdapter = new BasePagerAdapter(getSupportFragmentManager(), fragmentList, titles);
viewPager.setAdapter(pagerAdapter);
viewPager.setOffscreenPageLimit(5);
}

@Override
Expand All @@ -112,27 +120,25 @@ public boolean onCreateOptionsMenu(Menu menu) {
searchView.setSearchableInfo(searchableInfo);
searchView.onActionViewExpanded();


searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Log.d(TAG, "onQueryTextSubmit: " + query);
initData(query);
adapter.notifyDataSetChanged();
public boolean onQueryTextSubmit(String keyWord) {
Log.d(TAG, "onQueryTextSubmit: " + keyWord);
initData(keyWord);
pagerAdapter.notifyDataSetChanged();
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
// getSearchSuggest();
if (!TextUtils.isEmpty(newText)) {
getSearchSuggest2(newText);
public boolean onQueryTextChange(String keyWord) {
if (!TextUtils.isEmpty(keyWord)) {
getSearchSuggest(keyWord);
} else {
if (search_layout.getVisibility() != View.GONE) {
search_layout.setVisibility(View.GONE);
if (searchLayout.getVisibility() != View.GONE) {
searchLayout.setVisibility(View.GONE);
}
if (listview.getVisibility() != View.VISIBLE) {
listview.setVisibility(View.VISIBLE);
if (listView.getVisibility() != View.VISIBLE) {
listView.setVisibility(View.VISIBLE);
}
}
return false;
Expand All @@ -142,9 +148,9 @@ public boolean onQueryTextChange(String newText) {
return super.onCreateOptionsMenu(menu);
}

private void getSearchSuggest2(String text) {
private void getSearchSuggest(String keyWord) {
RetrofitFactory.getRetrofit().create(IMobileSearchApi.class)
.getSearchSuggestion(text.trim())
.getSearchSuggestion(keyWord.trim())
.subscribeOn(Schedulers.io())
.map(new Function<SearchSuggestionBean, List<SearchSuggestionBean.DataBean>>() {
@Override
Expand All @@ -157,7 +163,7 @@ public List<SearchSuggestionBean.DataBean> apply(@NonNull SearchSuggestionBean s
.subscribe(new Consumer<List<SearchSuggestionBean.DataBean>>() {
@Override
public void accept(@NonNull List<SearchSuggestionBean.DataBean> dataBeen) throws Exception {
myAdapter.updateDataSource(dataBeen);
searchAdapter.updateDataSource(dataBeen);
}
}, new Consumer<Throwable>() {
@Override
Expand All @@ -167,45 +173,18 @@ public void accept(@NonNull Throwable throwable) throws Exception {
});
}

private void getSearchSuggest() {
RxSearchView.queryTextChangeEvents(searchView)
.subscribeOn(AndroidSchedulers.mainThread())
.debounce(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
.observeOn(Schedulers.io())
.switchMap(new Function<SearchViewQueryTextEvent, ObservableSource<SearchSuggestionBean>>() {
@Override
public ObservableSource<SearchSuggestionBean> apply(@NonNull SearchViewQueryTextEvent searchViewQueryTextEvent) throws Exception {
return RetrofitFactory.getRetrofit().create(IMobileSearchApi.class)
.getSearchSuggestion(searchViewQueryTextEvent.queryText().toString().trim());
}
})
.map(new Function<SearchSuggestionBean, List<SearchSuggestionBean.DataBean>>() {
@Override
public List<SearchSuggestionBean.DataBean> apply(@NonNull SearchSuggestionBean searchSuggestionBean) throws Exception {
return searchSuggestionBean.getData();
}
})
.observeOn(AndroidSchedulers.mainThread())
.compose(this.<List<SearchSuggestionBean.DataBean>>bindToLifecycle())
.subscribe(new Consumer<List<SearchSuggestionBean.DataBean>>() {
@Override
public void accept(@NonNull List<SearchSuggestionBean.DataBean> dataBeen) throws Exception {
myAdapter.updateDataSource(dataBeen);
}
}, new Consumer<Throwable>() {
@Override
public void accept(@NonNull Throwable throwable) throws Exception {
throwable.printStackTrace();
}
});
@Override
protected void onRestart() {
super.onRestart();
searchView.clearFocus();
}

private class MyAdapter extends ArrayAdapter<SearchSuggestionBean.DataBean> {
private class SearchAdapter extends ArrayAdapter<SearchSuggestionBean.DataBean> {

private LayoutInflater inflater;
private List<SearchSuggestionBean.DataBean> data;

public MyAdapter(Context context, int resource) {
public SearchAdapter(Context context, int resource) {
super(context, resource);
inflater = LayoutInflater.from(context);
data = new ArrayList<>();
Expand Down
Loading

0 comments on commit f83d43e

Please sign in to comment.