Skip to content

Commit

Permalink
add useful site new ui
Browse files Browse the repository at this point in the history
  • Loading branch information
JsonChao committed Apr 2, 2018
1 parent 7b70189 commit dd19bd3
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,11 @@ interface View extends BaseView {
*/
void showTopSearchData(BaseResponse<List<TopSearchData>> topSearchDataResponse);

/**
* Show useful sites
*
* @param usefulSitesResponse BaseResponse<List<UsefulSiteData>>
*/
void showUsefulSites(BaseResponse<List<UsefulSiteData>> usefulSitesResponse);

/**
* Show top search data fail
*/
void showTopSearchDataFail();

/**
* Show useful sites data fail
*/
void showUsefulSitesDataFail();

/**
* Judge to the search list activity
*/
Expand All @@ -70,11 +58,6 @@ interface Presenter extends AbstractPresenter<View> {
*/
void getTopSearchData();

/**
* 常用网站
*/
void getUsefulSites();

/**
* Clear history data
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package json.chao.com.wanandroid.contract.main;

import java.util.List;

import json.chao.com.wanandroid.base.presenter.AbstractPresenter;
import json.chao.com.wanandroid.base.view.BaseView;
import json.chao.com.wanandroid.core.bean.BaseResponse;
import json.chao.com.wanandroid.core.bean.main.search.UsefulSiteData;


/**
* @author quchao
* @date 2018/4/2
*/

public interface UsageDialogContract {

interface View extends BaseView {

/**
* Show useful sites
*
* @param usefulSitesResponse BaseResponse<List<UsefulSiteData>>
*/
void showUsefulSites(BaseResponse<List<UsefulSiteData>> usefulSitesResponse);

/**
* Show useful sites data fail
*/
void showUsefulSitesDataFail();
}

interface Presenter extends AbstractPresenter<UsageDialogContract.View> {

/**
* 常用网站
*/
void getUsefulSites();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json.chao.com.wanandroid.di.scope.FragmentScope;
import json.chao.com.wanandroid.ui.hierarchy.fragment.KnowledgeHierarchyFragment;
import json.chao.com.wanandroid.ui.hierarchy.fragment.KnowledgeHierarchyListFragment;
import json.chao.com.wanandroid.ui.main.fragment.UsageDialogFragment;
import json.chao.com.wanandroid.ui.mainpager.fragment.MainPagerFragment;
import json.chao.com.wanandroid.ui.navigation.fragment.NavigationFragment;
import json.chao.com.wanandroid.ui.project.fragment.ProjectFragment;
Expand Down Expand Up @@ -79,5 +80,12 @@ public interface FragmentComponent {
*/
void inject(SearchDialogFragment searchDialogFragment);

/**
* 注入UsageDialogFragment所需的依赖
*
* @param usageDialogFragment UsageDialogFragment
*/
void inject(UsageDialogFragment usageDialogFragment);


}
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,4 @@ public void onNext(BaseResponse<List<TopSearchData>> topSearchDataResponse) {
}));
}

@Override
public void getUsefulSites() {
addSubscribe(mDataManager.getUsefulSites()
.compose(RxUtils.rxSchedulerHelper())
.subscribeWith(new BaseObserver<BaseResponse<List<UsefulSiteData>>>(mView) {
@Override
public void onNext(BaseResponse<List<UsefulSiteData>> usefulSitesResponse) {
if (usefulSitesResponse.getErrorCode() == BaseResponse.SUCCESS) {
mView.showUsefulSites(usefulSitesResponse);
} else {
mView.showUsefulSitesDataFail();
}
}
}));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package json.chao.com.wanandroid.presenter.main;

import java.util.List;

import javax.inject.Inject;

import json.chao.com.wanandroid.base.presenter.BasePresenter;
import json.chao.com.wanandroid.contract.main.UsageDialogContract;
import json.chao.com.wanandroid.core.DataManager;
import json.chao.com.wanandroid.core.bean.BaseResponse;
import json.chao.com.wanandroid.core.bean.main.search.UsefulSiteData;
import json.chao.com.wanandroid.utils.RxUtils;
import json.chao.com.wanandroid.widget.BaseObserver;

/**
* @author quchao
* @date 2018/4/2
*/

public class UsageDialogPresenter extends BasePresenter<UsageDialogContract.View> implements UsageDialogContract.Presenter {

DataManager mDataManager;

@Inject
UsageDialogPresenter(DataManager dataManager) {
mDataManager = dataManager;
}

@Override
public void getUsefulSites() {
addSubscribe(mDataManager.getUsefulSites()
.compose(RxUtils.rxSchedulerHelper())
.subscribeWith(new BaseObserver<BaseResponse<List<UsefulSiteData>>>(mView) {
@Override
public void onNext(BaseResponse<List<UsefulSiteData>> usefulSitesResponse) {
if (usefulSitesResponse.getErrorCode() == BaseResponse.SUCCESS) {
mView.showUsefulSites(usefulSitesResponse);
} else {
mView.showUsefulSitesDataFail();
}
}
}));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import json.chao.com.wanandroid.core.http.cookies.CookiesManager;
import json.chao.com.wanandroid.presenter.main.MainPresenter;
import json.chao.com.wanandroid.ui.hierarchy.fragment.KnowledgeHierarchyFragment;
import json.chao.com.wanandroid.ui.main.fragment.UsageDialogFragment;
import json.chao.com.wanandroid.ui.mainpager.fragment.MainPagerFragment;
import json.chao.com.wanandroid.ui.navigation.fragment.NavigationFragment;
import json.chao.com.wanandroid.ui.project.fragment.ProjectFragment;
Expand Down Expand Up @@ -179,9 +180,17 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_search) {
SearchDialogFragment searchDialogFragment = new SearchDialogFragment();
searchDialogFragment.show(getFragmentManager(), "SearchDialogFragment");
switch (item.getItemId()) {
case R.id.action_usage:
UsageDialogFragment usageDialogFragment = new UsageDialogFragment();
usageDialogFragment.show(getFragmentManager(), "UsageDialogFragment");
break;
case R.id.action_search:
SearchDialogFragment searchDialogFragment = new SearchDialogFragment();
searchDialogFragment.show(getFragmentManager(), "SearchDialogFragment");
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import json.chao.com.wanandroid.core.DataManager;
import json.chao.com.wanandroid.core.bean.BaseResponse;
import json.chao.com.wanandroid.core.bean.main.search.TopSearchData;
import json.chao.com.wanandroid.core.bean.main.search.UsefulSiteData;
import json.chao.com.wanandroid.core.dao.HistoryData;
import json.chao.com.wanandroid.presenter.main.SearchPresenter;
import json.chao.com.wanandroid.ui.main.adapter.HistorySearchAdapter;
Expand Down Expand Up @@ -82,13 +81,10 @@ public class SearchDialogFragment extends BaseDialogFragment<SearchPresenter> im
RecyclerView mRecyclerView;
@BindView(R.id.top_search_flow_layout)
TagFlowLayout mTopSearchFlowLayout;
@BindView(R.id.useful_sites_flow_layout)
TagFlowLayout mUsefulSitesFlowLayout;
@BindView(R.id.search_floating_action_btn)
FloatingActionButton mFloatingActionButton;

private List<TopSearchData> mTopSearchDataList;
private List<UsefulSiteData> mUsefulSiteDataList;

@Inject
DataManager mDataManager;
Expand Down Expand Up @@ -122,7 +118,6 @@ protected void initEventAndData() {
StatusBarUtil.immersive(getActivity().getWindow(), ContextCompat.getColor(getActivity(), R.color.transparent), 0.3f);
initCircleAnimation();
mTopSearchDataList = new ArrayList<>();
mUsefulSiteDataList = new ArrayList<>();
mSearchEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Expand Down Expand Up @@ -153,7 +148,6 @@ public void afterTextChanged(Editable s) {

showHistoryData(mDataManager.loadAllHistoryData());
mPresenter.getTopSearchData();
mPresenter.getUsefulSites();
}

@Override
Expand Down Expand Up @@ -185,38 +179,6 @@ public View getView(FlowLayout parent, int position, TopSearchData topSearchData
});
}

@Override
public void showUsefulSites(BaseResponse<List<UsefulSiteData>> usefulSitesResponse) {
if (usefulSitesResponse == null) {
showUsefulSitesDataFail();
return;
}
mUsefulSiteDataList = usefulSitesResponse.getData();
mUsefulSitesFlowLayout.setAdapter(new TagAdapter<UsefulSiteData>(mUsefulSiteDataList) {
@Override
public View getView(FlowLayout parent, int position, UsefulSiteData usefulSiteData) {
assert getActivity() != null;
TextView tv = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.flow_layout_tv,
parent, false);
assert usefulSiteData != null;
String name = usefulSiteData.getName();
tv.setText(name);
setItemBackground(tv);
mUsefulSitesFlowLayout.setOnTagClickListener((view, position1, parent1) -> {
JudgeUtils.startArticleDetailActivity(getActivity(),
mUsefulSiteDataList.get(position1).getId(),
mUsefulSiteDataList.get(position1).getName().trim(),
mUsefulSiteDataList.get(position1).getLink().trim(),
false,
false,
true);
return true;
});
return tv;
}
});
}

@Override
public void showHistoryData(List<HistoryData> historyDataList) {
if (historyDataList == null || historyDataList.size() <= 0) {
Expand All @@ -242,11 +204,6 @@ public void showTopSearchDataFail() {
CommonUtils.showSnackMessage(getActivity(), getString(R.string.failed_to_obtain_top_data));
}

@Override
public void showUsefulSitesDataFail() {
CommonUtils.showSnackMessage(getActivity(), getString(R.string.failed_to_obtain_useful_sites_data));
}

@Override
public void judgeToTheSearchListActivity() {
backEvent();
Expand Down
Loading

0 comments on commit dd19bd3

Please sign in to comment.