Skip to content

Commit

Permalink
非会员支持查看有限的热度排序
Browse files Browse the repository at this point in the history
  • Loading branch information
CeuiLiSA committed Aug 26, 2020
1 parent 904f971 commit a108041
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 30 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "ceui.lisa.pixiv"
minSdkVersion 21
targetSdkVersion 28
versionCode 114
versionName "2.2.6"
versionCode 113
versionName "2.2.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/ceui/lisa/activities/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

public class SearchActivity extends BaseActivity<FragmentNewSearchBinding> {

private static final String[] TITLES = new String[]{"插画/漫画", "小说"};
private BaseFragment<?>[] allPages = new BaseFragment[]{null, null};
private static final String[] TITLES = new String[]{"插画/漫画", "热度(有限)", "小说"};
private BaseFragment<?>[] allPages = new BaseFragment[]{null, null, null};
private String keyWord = "";
private SearchModel searchModel;
private int index = 0;
Expand Down Expand Up @@ -67,7 +67,9 @@ protected void initView() {
public Fragment getItem(int position) {
if (allPages[position] == null) {
if (position == 0) {
allPages[position] = FragmentSearchIllust.newInstance();
allPages[position] = FragmentSearchIllust.newInstance(false);
} else if(position == 1) {
allPages[position] = FragmentSearchIllust.newInstance(true);
} else {
allPages[position] = FragmentSearchNovel.newInstance();
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/ceui/lisa/core/BaseRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;

import ceui.lisa.activities.Shaft;
import ceui.lisa.utils.Common;

public class BaseRepo implements DataView{

public BaseRepo() {
Common.showLog("BaseRepo " + getClass().getSimpleName() + " newInstance");
}

@Override
public boolean hasNext() {
return true;
Expand Down
36 changes: 26 additions & 10 deletions app/src/main/java/ceui/lisa/fragments/FragmentSearchIllust.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ceui.lisa.http.Retro;
import ceui.lisa.model.ListIllust;
import ceui.lisa.models.IllustsBean;
import ceui.lisa.utils.Params;
import ceui.lisa.utils.PixivOperate;
import ceui.lisa.viewmodel.SearchModel;
import io.reactivex.Observable;
Expand All @@ -26,6 +27,15 @@ public class FragmentSearchIllust extends NetListFragment<FragmentBaseListBindin
IllustsBean> {

private SearchModel searchModel;
private boolean isPopular = false;

public static FragmentSearchIllust newInstance(boolean popular) {
Bundle args = new Bundle();
args.putBoolean(Params.IS_POPULAR, popular);
FragmentSearchIllust fragment = new FragmentSearchIllust();
fragment.setArguments(args);
return fragment;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
Expand All @@ -39,8 +49,9 @@ public void onChanged(String s) {
super.onActivityCreated(savedInstanceState);
}

public static FragmentSearchIllust newInstance() {
return new FragmentSearchIllust();
@Override
protected void initBundle(Bundle bundle) {
isPopular = bundle.getBoolean(Params.IS_POPULAR);
}

@Override
Expand All @@ -53,14 +64,19 @@ public BaseRepo repository() {
return new RemoteRepo<ListIllust>() {
@Override
public Observable<ListIllust> initApi() {
PixivOperate.insertSearchHistory(searchModel.getKeyword().getValue(), 0);
return Retro.getAppApi().searchIllust(
token(),
searchModel.getKeyword().getValue() +
(Shaft.sSettings.getSearchFilter().contains("无限制") ?
"" : " " + (Shaft.sSettings.getSearchFilter())),
searchModel.getSortType().getValue(),
searchModel.getSearchType().getValue());
if (isPopular) {
return Retro.getAppApi().popularPreview(token(),
searchModel.getKeyword().getValue());
} else {
PixivOperate.insertSearchHistory(searchModel.getKeyword().getValue(), 0);
return Retro.getAppApi().searchIllust(
token(),
searchModel.getKeyword().getValue() +
(Shaft.sSettings.getSearchFilter().contains("无限制") ?
"" : " " + (Shaft.sSettings.getSearchFilter())),
searchModel.getSortType().getValue(),
searchModel.getSearchType().getValue());
}
}

@Override
Expand Down
18 changes: 4 additions & 14 deletions app/src/main/java/ceui/lisa/fragments/ListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public void onAdapterPrepared() {
public void initModel() {
mModel = (BaseModel<Item>) new ViewModelProvider(this).get(modelClass());
allItems = mModel.getContent().getValue();
mModel.setBaseRepo(repository());
if (mModel.getBaseRepo() == null) {
mModel.setBaseRepo(repository());
}
}

public Class<? extends BaseModel> modelClass() {
Expand Down Expand Up @@ -189,12 +191,7 @@ public void initToolbar(Toolbar toolbar) {
toolbar.setVisibility(View.GONE);
}
toolbar.setTitle(getToolbarTitle());
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mActivity.finish();
}
});
toolbar.setNavigationOnClickListener(v -> finish());
}

public void beforeFirstLoad(List<Item> items) {
Expand Down Expand Up @@ -245,13 +242,6 @@ public void nowRefresh() {
mRefreshLayout.autoRefresh();
}

public List<Item> getContent() {
if (mModel == null) {
return new ArrayList<>();
}
return mModel.getContent().getValue();
}

public int getCount() {
return allItems == null ? 0 : allItems.size();
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/ceui/lisa/http/AppApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ Observable<ListUser> searchUser(@Header("Authorization") String token,
@Query("word") String word);


@GET("v1/search/popular-preview/illust?filter=for_android&include_translated_tag_results=true&merge_plain_keyword_results=true&search_target=exact_match_for_tags")
Observable<ListIllust> popularPreview(@Header("Authorization") String token,
@Query("word") String word);


// v2/search/autocomplete?merge_plain_keyword_results=true&word=%E5%A5%B3%E4%BD%93 HTTP/1.1
@GET("v2/search/autocomplete?merge_plain_keyword_results=true")
Observable<ListTrendingtag> searchCompleteWord(@Header("Authorization") String token,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/ceui/lisa/utils/Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Params {
public static final String PAGE_UUID = "page_uuid";
public static final String POSITION = "position";
public static final String IS_LIKED = "is liked";
public static final String IS_POPULAR = "is popular";
public static final String LAST_CLASS = "last class";

public static final String FILTER_ILLUST = "ceui.lisa.fragments.NetListFragment FILTER_ILLUST";
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/toast_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="36dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardBackgroundColor="@color/new_color_primary"
app:cardElevation="@dimen/four_dp"
android:layout_height="wrap_content">

Expand Down

0 comments on commit a108041

Please sign in to comment.