Skip to content

Commit

Permalink
search
Browse files Browse the repository at this point in the history
  • Loading branch information
iamwent committed Mar 12, 2017
1 parent f744f11 commit 5b45437
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 112 deletions.
137 changes: 41 additions & 96 deletions app/src/main/java/com/iamwent/gank/data/bean/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,106 +13,51 @@ public class Search {
* ganhuo_id : 56cc6d1d421aa95caa7076fa
* publishedAt : 2015-07-17T03:43:22.395000
* readability : <div><article class="markdown-body entry-content">
<p>ListView&#x6298;&#x53E0;&#x6548;&#x679C;</p>
<h2><a id="user-content-screenshots" class="anchor" href="https://github.com/dodola/ListItemFold#screenshots"><svg class="octicon octicon-link" height="16" width="16"><path></path></svg></a>Screenshots</h2>
<p><a href="https://raw.githubusercontent.com/dodola/ListItemFold/master/screenshot/fold.gif" target="_blank"><img src="https://raw.githubusercontent.com/dodola/ListItemFold/master/screenshot/fold.gif" alt="image"></a></p>
<p><a href="http://www.youtube.com/watch?v=Tjt37wINiF4"><img src="http://img.youtube.com/vi/Tjt37wINiF4/0.jpg" alt="List"></a></p>
<h2><a id="user-content-license" class="anchor" href="https://github.com/dodola/ListItemFold#license"><svg class="octicon octicon-link" height="16" width="16"><path></path></svg></a>License</h2>
<p>The MIT License (MIT)</p>
<p>Copyright (c) 2015 dodola</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</p>
</article>
</div>
* <p>
* <p>ListView&#x6298;&#x53E0;&#x6548;&#x679C;</p>
* <p>
* <h2><a id="user-content-screenshots" class="anchor" href="https://github.com/dodola/ListItemFold#screenshots"><svg class="octicon octicon-link" height="16" width="16"><path></path></svg></a>Screenshots</h2>
* <p>
* <p><a href="https://raw.githubusercontent.com/dodola/ListItemFold/master/screenshot/fold.gif" target="_blank"><img src="https://raw.githubusercontent.com/dodola/ListItemFold/master/screenshot/fold.gif" alt="image"></a></p>
* <p>
* <p><a href="http://www.youtube.com/watch?v=Tjt37wINiF4"><img src="http://img.youtube.com/vi/Tjt37wINiF4/0.jpg" alt="List"></a></p>
* <p>
* <h2><a id="user-content-license" class="anchor" href="https://github.com/dodola/ListItemFold#license"><svg class="octicon octicon-link" height="16" width="16"><path></path></svg></a>License</h2>
* <p>
* <p>The MIT License (MIT)</p>
* <p>
* <p>Copyright (c) 2015 dodola</p>
* <p>
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
* <p>
* <p>The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.</p>
* <p>
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.</p>
* </article>
* </div>
* type : Android
* url : https://github.com/dodola/ListItemFold
* who : Jason
*/

private String desc;
private String ganhuo_id;
private String publishedAt;
private String readability;
private String type;
private String url;
private String who;

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}

public String getGanhuo_id() {
return ganhuo_id;
}

public void setGanhuo_id(String ganhuo_id) {
this.ganhuo_id = ganhuo_id;
}

public String getPublishedAt() {
return publishedAt;
}

public void setPublishedAt(String publishedAt) {
this.publishedAt = publishedAt;
}

public String getReadability() {
return readability;
}

public void setReadability(String readability) {
this.readability = readability;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getWho() {
return who;
}
public String desc;
public String ganhuo_id;
public String publishedAt;
public String readability;
public String type;
public String url;
public String who;

public void setWho(String who) {
this.who = who;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ public Observable saveRecords(List<Record> records) {
}

public Observable<Record> getGankByDate(int year, int month, int day) {
return Observable.create(new ObservableOnSubscribe<Record>() {
@Override
public void subscribe(ObservableEmitter<Record> emitter) throws Exception {
String date = String.format(Locale.getDefault(), "%d-%d-%d", year, month, day);
Record record = orm.queryById(date, Record.class);
if (record != null && record.ganks != null) {
emitter.onNext(record);
}
return Observable.create(emitter -> {
String date = String.format(Locale.getDefault(), "%d-%d-%d", year, month, day);
Record record = orm.queryById(date, Record.class);
if (record != null && record.ganks != null) {
emitter.onNext(record);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/iamwent/gank/data/remote/GankApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Observable<BaseResponse<List<Gank>>> getCategory(@Path("type") String type,
@Path("page") int page);

// 搜索 API
@GET("search/query/{searchKey}/category/{searchCategory}/count/{searchCount}/page/{searchPage}")
Observable<BaseResponse<List<Search>>> search(@Path("searchKey") String key,
// hsearch/query/listview/category/Android/count/10/page/1
@GET("search/query/{key}/category/{type}/count/{count}/page/{page}")
Observable<BaseResponse<List<Search>>> search(@Path("key") String key,
@Path("type") String type,
@Path("count") int count,
@Path("page") int page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setDisplayHomeAsUpEnabled(false);

List<Gank> ganks = Collections.emptyList();
adapter = new DailyGankAdapter(this, ganks);
adapter = new DailyGankAdapter(this, Collections.emptyList());

recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void bind(Gank newGank) {

static class FooterViewHolder extends RecyclerView.ViewHolder {

public FooterViewHolder(View itemView) {
FooterViewHolder(View itemView) {
super(itemView);
}
}
Expand Down
81 changes: 80 additions & 1 deletion app/src/main/java/com/iamwent/gank/ui/search/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,65 @@
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.iamwent.gank.R;
import com.iamwent.gank.data.GankRepository;
import com.iamwent.gank.data.bean.Search;
import com.iamwent.gank.provider.GankRecentSearchProvider;
import com.iamwent.gank.ui.base.BaseActivity;

import java.lang.annotation.Retention;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;

import static java.lang.annotation.RetentionPolicy.SOURCE;

/**
* Created by iamwent on 24/02/2017.
*
* @author iamwent
* @since 24/02/2017
*/

public class SearchActivity extends BaseActivity {
public class SearchActivity extends BaseActivity implements SearchContract.View {

@Retention(SOURCE)
@StringDef({
ALL,
ANDROID,
IOS,
VIDEO,
GIRL,
EXPANSION,
FRONT_END,
FUNNY,
APP
})
public @interface Type {
}

public static final String ALL = "all";
public static final String ANDROID = "Android";
public static final String IOS = "iOS";
public static final String VIDEO = "休息视频";
public static final String GIRL = "福利";
public static final String EXPANSION = "拓展资源";
public static final String FRONT_END = "前端";
public static final String FUNNY = "瞎推荐";
public static final String APP = "App";


@BindView(R.id.rv_search_result)
RecyclerView recyclerView;

private SearchResultAdapter adapter;
private SearchContract.Presenter presenter;

@Override
protected int provideContentViewLayoutResId() {
Expand All @@ -38,10 +83,44 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
GankRecentSearchProvider.AUTHORITY, GankRecentSearchProvider.MODE);
suggestions.saveRecentQuery(query, null);
}

initView();

presenter = new SearchPresenter(this, GankRepository.getInstance(this));
presenter.subscribe();
}

private void initView() {
adapter = new SearchResultAdapter(this, Collections.emptyList());

recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
}

@Override
protected void onDestroy() {
presenter.unsubscribe();

super.onDestroy();
}

@Override
public boolean onSearchRequested() {
return super.onSearchRequested();
}

@Override
public void changeProgress(boolean isShow) {

}

@Override
public void error() {

}

@Override
public void showSearchResults(List<Search> results) {

}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/iamwent/gank/ui/search/SearchContract.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.iamwent.gank.ui.search;

import android.support.annotation.NonNull;

import com.iamwent.gank.data.bean.Gank;
import com.iamwent.gank.data.bean.Search;
import com.iamwent.gank.ui.base.BasePresenter;
import com.iamwent.gank.ui.base.BaseView;

import java.util.List;

/**
* Created by iamwent on 24/02/2017.
*
* @author iamwent
* @since 24/02/2017
*/

interface SearchContract {

interface View extends BaseView {
void changeProgress(boolean isShow);

void error();

void showSearchResults(List<Search> results);
}

interface Presenter extends BasePresenter {
void search(@NonNull String key, @NonNull String type);

void loadMore();
}
}
Loading

0 comments on commit 5b45437

Please sign in to comment.