old
Administrator 5 years ago
parent de70b8aa95
commit 365b261ee0
  1. 2
      README.md
  2. 2
      app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt
  3. 4
      app/src/main/java/com/novel/read/activity/NovelRankListActivity.kt
  4. 2
      app/src/main/java/com/novel/read/activity/NovelReadActivity.kt
  5. 6
      app/src/main/java/com/novel/read/event/DeleteBookSignEvent.kt
  6. 8
      app/src/main/java/com/novel/read/event/HotSearchEvent.kt
  7. 5
      app/src/main/java/com/novel/read/event/HumanEvent.kt
  8. 6
      app/src/main/java/com/novel/read/fragment/BookListFragment.kt
  9. 313
      app/src/main/java/com/novel/read/http/AccountManager.java
  10. 309
      app/src/main/java/com/novel/read/http/AccountManager.kt
  11. 94
      app/src/main/java/com/novel/read/http/service/AccountService.java
  12. 94
      app/src/main/java/com/novel/read/http/service/AccountService.kt
  13. 2
      app/src/main/java/com/novel/read/service/DownloadService.java

@ -28,7 +28,7 @@ Kt、AndroidX、Retrofit、Okhttp3、Glide、LitePal等
| --- | --- | --- |
| <img src="https://github.com/390057892/reader/blob/master/screenshot/%E8%AE%BE%E7%BD%AE.png?raw=true" width="280" alt="设置"/> | <img src="https://github.com/390057892/reader/blob/master/screenshot/%E6%90%9C%E7%B4%A2.png?raw=true" width="280" alt="搜索"/> | <img src="https://github.com/390057892/reader/blob/master/screenshot/%E9%98%85%E8%AF%BB%E9%A1%B5.png" width="280" alt="阅读页"/> |
| <img src="https://github.com/390057892/reader/blob/master/screenshot/%E9%98%85%E8%AF%BB%E9%A1%B5%E8%8F%9C%E5%8D%95.png" width="280" alt="菜单"/> | <img src="https://github.com/390057892/reader/blob/master/screenshot/%E4%B9%A6%E7%B1%8D%E7%9B%AE%E5%BD%95.png" width="280" alt="目录"/> | <img src="https://github.com/390057892/reader/blob/master/screenshot/%E6%8F%92%E9%A1%B51.jpg" width="280" alt="插页"/> |
| <img src="https://github.com/390057892/reader/blob/master/screenshot/%E6%8F%92%E9%A1%B52.jpg" width="280" alt="插页2"/> | | |
| <img src="https://github.com/390057892/reader/blob/master/screenshot/%E6%8F%92%E9%A1%B52.jpg" width="280" alt="插页2"/> | https://github.com/390057892/reader/blob/master/screenshot/night.jpg | https://github.com/390057892/reader/blob/master/screenshot/edit.jpg |

@ -63,7 +63,7 @@ class NovelBookTypeListActivity : NovelBaseActivity() {
}
private fun getData() {
AccountManager.getInstance().getSearchBookList(mCategoryId, "", page)
mCategoryId?.let { AccountManager.getInstance().getSearchBookList(it, "", page) }
}
@Subscribe

@ -24,8 +24,8 @@ class NovelRankListActivity : NovelBaseActivity() {
private var mList: MutableList<RankByUpadateResp.BookBean> = ArrayList()
private var page = 1
private var loadSize: Int = 0
private var type: String? = null
private var sex: String? = null
private var type: String = ""
private var sex: String = ""
override val layoutId: Int get() = R.layout.activity_rank_list

@ -74,7 +74,7 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
private val isRegistered = false
private var mCollBook: CollBookBean? = null
private var mBookId: String? = null
private var mBookId: String = ""
@SuppressLint("HandlerLeak")
private val mHandler = object : Handler() {

@ -3,4 +3,8 @@ package com.novel.read.event
import com.mango.mangolib.event.BaseEvent
import com.mango.mangolib.http.ErrorResponse
class DeleteBookSignEvent(result: ErrorResponse) : BaseEvent<ErrorResponse>(result)
class DeleteBookSignEvent : BaseEvent<ErrorResponse>{
constructor(result: ErrorResponse) : super(result) {}
constructor() {}
}

@ -2,9 +2,15 @@ package com.novel.read.event
import com.mango.mangolib.event.BaseEvent
import com.novel.read.model.protocol.HotSearchResp
import com.novel.read.model.protocol.SearchResp
/**
* create by zlj on 2019/6/18
* describe:
*/
class HotSearchEvent(result: HotSearchResp) : BaseEvent<HotSearchResp>(result)
class HotSearchEvent : BaseEvent<HotSearchResp>{
constructor(result: HotSearchResp) : super(result) {}
constructor() {}
}

@ -8,6 +8,9 @@ import com.novel.read.model.protocol.RecommendListResp
* create by 赵利君 on 2019/6/18
* describe:
*/
class HumanEvent(result: RecommendListResp) : BaseEvent<RecommendListResp>(result) {
class HumanEvent : BaseEvent<RecommendListResp> {
constructor(result: RecommendListResp) : super(result) {}
constructor() {}
}

@ -21,9 +21,9 @@ class BookListFragment : NovelBaseFragment() {
private var mAdapter: RankListAdapter? = null
private var mList: MutableList<RankByUpadateResp.BookBean> = ArrayList()
private var sex: String? = null
private var dateType: String? = null
private var type: String? = null
private var sex: String = ""
private var dateType: String = ""
private var type: String = ""
private var page = 1
private var loadSize: Int = 0

@ -1,313 +0,0 @@
package com.novel.read.http;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.mango.mangolib.event.EventManager;
import com.mango.mangolib.http.ErrorResponse;
import com.mango.mangolib.http.MyRequestType;
import com.mango.mangolib.http.ServiceCallback;
import com.novel.read.event.AddBookSignEvent;
import com.novel.read.event.BookArticleEvent;
import com.novel.read.event.DeleteBookSignEvent;
import com.novel.read.event.ErrorChapterEvent;
import com.novel.read.event.FinishChapterEvent;
import com.novel.read.event.GetBookDetailEvent;
import com.novel.read.event.GetBookSignEvent;
import com.novel.read.event.GetCategoryTypeEvent;
import com.novel.read.event.GetRecommendBookEvent;
import com.novel.read.event.HotSearchEvent;
import com.novel.read.event.LoginEvent;
import com.novel.read.event.SearchListEvent;
import com.novel.read.event.VersionEvent;
import com.novel.read.http.service.AccountService;
import com.novel.read.model.db.ChapterInfoBean;
import com.novel.read.model.db.dbManage.BookRepository;
import com.novel.read.model.protocol.BookArticleResp;
import com.novel.read.model.protocol.BookDetailResp;
import com.novel.read.model.protocol.CategoryTypeResp;
import com.novel.read.model.protocol.HotSearchResp;
import com.novel.read.model.protocol.MarkResp;
import com.novel.read.model.protocol.RankByUpadateResp;
import com.novel.read.model.protocol.RecommendBookResp;
import com.novel.read.model.protocol.RecommendListResp;
import com.novel.read.model.protocol.SearchResp;
import com.novel.read.model.protocol.UidResp;
import com.novel.read.model.protocol.VersionResp;
import com.novel.read.utlis.LogUtils;
import com.novel.read.utlis.PhoneUtils;
import com.novel.read.widget.page.TxtChapter;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Created by zlj on 2017/2/14.
*/
public class AccountManager {
private AccountService accountService;
private AccountManager() {
accountService = ServiceGenerator.createService(AccountService.class, MyRequestType.URL_TEXT);
}
private static AccountManager instance = null;
public static synchronized AccountManager getInstance() {
if (instance == null) {
instance = new AccountManager();
}
return instance;
}
public void getRecommendBook(String bookId, String limit) {
HashMap<String, String> map = new HashMap<>();
map.put("book_id", bookId);
Call<RecommendBookResp> call = accountService.getRecommendBook(getUrlString(Urls.getRecommend, map));
call.enqueue(new ServiceCallback<>(GetRecommendBookEvent.class));
}
public void getBookDetail(String bookId) {
HashMap<String, String> map = new HashMap<>();
map.put("book_id", bookId);
Call<BookDetailResp> call = accountService.getBookDetail(getUrlString(Urls.getBookDetail, map));
call.enqueue(new ServiceCallback<>(GetBookDetailEvent.class));
}
public Single<BookDetailResp> getBookDetails(String bookId) { //rxjava 获取多书籍详情 合并请求调用
HashMap<String, String> map = new HashMap<>();
map.put("book_id", bookId);
return accountService.getBookDetails(getUrlString(Urls.getBookDetail, map));
}
public void getCategoryType() {
HashMap<String, String> map = new HashMap<>();
Call<CategoryTypeResp> call = accountService.getCategoryType(getUrlString(Urls.getCategoryType, map));
call.enqueue(new ServiceCallback<>(GetCategoryTypeEvent.class));
}
public void getHotSearch() {
HashMap<String, String> map = new HashMap<>();
Call<HotSearchResp> call = accountService.getHotSearch(getUrlString(Urls.getHotSearch, map));
call.enqueue(new ServiceCallback<>(HotSearchEvent.class));
}
public void getBookArticle(String bookId, String hasContent, String page, String limit) {
HashMap<String, String> map = new HashMap<>();
map.put("book_id", bookId);
map.put("has_content", hasContent);
map.put("page", page);
map.put("limit", limit);
Call<BookArticleResp> call = accountService.getBookArticle(getUrlString(Urls.getBookArticle, map));
call.enqueue(new ServiceCallback<>(BookArticleEvent.class));
}
public void getSearchBookList(String category_id, String key, int page) {
HashMap<String, String> map = new HashMap<>();
if (!TextUtils.isEmpty(category_id)) {
map.put("category_id", category_id);
} else {
map.put("category_id", "0");
}
if (!TextUtils.isEmpty(key)) {
map.put("key", key);
}
map.put("page", String.valueOf(page));
Call<SearchResp> call = accountService.getSearchList(getUrlString(Urls.getBookList, map));
call.enqueue(new ServiceCallback<>(SearchListEvent.class));
}
public void getRecommendList(String listType, Callback<RecommendListResp> callback) {
HashMap<String, String> map = new HashMap<>();
map.put("type", listType);
Call<RecommendListResp> call = accountService.getRecommendList(getUrlString(Urls.getRecommendList, map));
call.enqueue(callback);
}
public void getRankByUpdate(int page, int limit, Callback<RankByUpadateResp> callback) {
HashMap<String, String> map = new HashMap<>();
if (!TextUtils.isEmpty(String.valueOf(page))) {
map.put("page", String.valueOf(page));
}
if (limit != 0) {
map.put("limit", String.valueOf(limit));
}
Call<RankByUpadateResp> call = accountService.getRankByUpdate(getUrlString(Urls.getRankByUpdate, map));
call.enqueue(callback);
}
public void getRankList(String type, String sex, String dateType, String page, Callback<RankByUpadateResp> callback) {
HashMap<String, String> map = new HashMap<>();
map.put("type", type);
map.put("gender", sex);
map.put("date_type", dateType);
map.put("page", page);
Call<RankByUpadateResp> call = accountService.getRankList(getUrlString(Urls.getRankList, map));
call.enqueue(callback);
}
public void checkVersion(int versionCode) {
HashMap<String, String> map = new HashMap<>();
map.put("version", String.valueOf(versionCode));
// map.put("shell", Constant.shell);
Call<VersionResp> call = accountService.checkVersion(getUrlString(Urls.checkVersion, map));
call.enqueue(new ServiceCallback<>(VersionEvent.class));
}
public void addSign(String bookId, String articleId, String content) {
HashMap<String, String> map = new HashMap<>();
map.put("book_id", bookId);
map.put("article_id", articleId);
map.put("content", content);
Call<ErrorResponse> call = accountService.addSign(Urls.addBookSign, mapToBody(map));
call.enqueue(new ServiceCallback<>(AddBookSignEvent.class));
}
public void deleteSign(String signIds) {
HashMap<String, String> map = new HashMap<>();
map.put("sign_ids", signIds);
Call<ErrorResponse> call = accountService.deleteSign(Urls.deleteSign, mapToBody(map));
call.enqueue(new ServiceCallback<>(DeleteBookSignEvent.class));
}
public void getSignList(String bookId) {
HashMap<String, String> map = new HashMap<>();
map.put("book_id", bookId);
Call<MarkResp> call = accountService.getSignList(getUrlString(Urls.getBookSign, map));
call.enqueue(new ServiceCallback<>(GetBookSignEvent.class));
}
public void login(Context mContext) {
HashMap<String, String> map = new HashMap<>();
Log.e("getUniquePsuedoID", "login: " + PhoneUtils.getUniquePsuedoID());
map.put("code", PhoneUtils.getUniquePsuedoID());
Call<UidResp> call = accountService.login(Urls.login, mapToBody(map));
call.enqueue(new ServiceCallback<>(LoginEvent.class));
}
private Subscription mChapterSub;
public void getBookArticleDetail(String bookId, List<TxtChapter> bookChapters) {
int size = bookChapters.size();
//取消上次的任务,防止多次加载
if (mChapterSub != null) {
mChapterSub.cancel();
}
List<Single<ChapterInfoBean>> chapterInfos = new ArrayList<>(bookChapters.size());
ArrayDeque<String> titles = new ArrayDeque<>(bookChapters.size());
// 将要下载章节,转换成网络请求。
for (int i = 0; i < size; ++i) {
TxtChapter bookChapter = bookChapters.get(i);
// 网络中获取数据
Single<ChapterInfoBean> chapterInfoSingle = getChapterInfo(bookChapter.getChapterId());
chapterInfos.add(chapterInfoSingle);
titles.add(bookChapter.getTitle());
}
Single.concat(chapterInfos)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ChapterInfoBean>() {
String title = titles.poll();
@Override
public void onSubscribe(Subscription s) {
s.request(Integer.MAX_VALUE);
mChapterSub = s;
}
@Override
public void onNext(ChapterInfoBean chapterInfoBean) {
//存储数据
BookRepository.getInstance().saveChapterInfo(
bookId, title, chapterInfoBean.getBody()
);
EventManager.Companion.getInstance().postEvent(new FinishChapterEvent());
//将获取到的数据进行存储
title = titles.poll();
}
@Override
public void onError(Throwable t) {
//只有第一个加载失败才会调用errorChapter
if (bookChapters.get(0).getTitle().equals(title)) {
EventManager.Companion.getInstance().postEvent(new ErrorChapterEvent());
}
LogUtils.e(t);
}
@Override
public void onComplete() {
}
}
);
}
/**
* 注意这里用的是同步请求
*/
public Single<ChapterInfoBean> getChapterInfo(String id) {
HashMap<String, String> map = new HashMap<>();
map.put("article_id", id);
return accountService.getBookArticleDetail(getUrlString(Urls.getDetail, map))
.map(bean -> bean.getArticle().get(0));
}
/**
* get方法拼接字符串
*/
private String getUrlString(String path, HashMap<String, String> query) {
String mypath = path;
if (query != null && query.size() > 0) {
StringBuilder pathWithQuery = new StringBuilder(path);
if (!path.contains("?")) {
pathWithQuery.append("?");
} else {
pathWithQuery.append("&");
}
for (Map.Entry<String, String> stringStringEntry : query.entrySet()) {
String key = (String) ((Map.Entry) stringStringEntry).getKey();
String val = (String) ((Map.Entry) stringStringEntry).getValue();
pathWithQuery.append(key);
pathWithQuery.append("=");
pathWithQuery.append(val);
pathWithQuery.append("&");
}
pathWithQuery.deleteCharAt(pathWithQuery.length() - 1);
mypath = pathWithQuery.toString();
}
return mypath;
}
/**
* 减少请求info类的数量,直接用map替代实体类返回body
*/
private RequestBody mapToBody(HashMap<String, String> map) {
return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), ServiceGenerator.formatResponse(map));
}
}

@ -0,0 +1,309 @@
package com.novel.read.http
import android.content.Context
import android.text.TextUtils
import android.util.Log
import com.mango.mangolib.event.EventManager
import com.mango.mangolib.http.MyRequestType
import com.mango.mangolib.http.ServiceCallback
import com.novel.read.event.AddBookSignEvent
import com.novel.read.event.BookArticleEvent
import com.novel.read.event.DeleteBookSignEvent
import com.novel.read.event.ErrorChapterEvent
import com.novel.read.event.FinishChapterEvent
import com.novel.read.event.GetBookDetailEvent
import com.novel.read.event.GetBookSignEvent
import com.novel.read.event.GetCategoryTypeEvent
import com.novel.read.event.GetRecommendBookEvent
import com.novel.read.event.HotSearchEvent
import com.novel.read.event.LoginEvent
import com.novel.read.event.SearchListEvent
import com.novel.read.event.VersionEvent
import com.novel.read.http.service.AccountService
import com.novel.read.model.db.ChapterInfoBean
import com.novel.read.model.db.dbManage.BookRepository
import com.novel.read.model.protocol.BookDetailResp
import com.novel.read.model.protocol.RankByUpadateResp
import com.novel.read.model.protocol.RecommendListResp
import com.novel.read.utlis.LogUtils
import com.novel.read.utlis.PhoneUtils
import com.novel.read.widget.page.TxtChapter
import org.reactivestreams.Subscriber
import org.reactivestreams.Subscription
import java.util.ArrayDeque
import java.util.ArrayList
import java.util.HashMap
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import okhttp3.MediaType
import okhttp3.RequestBody
import retrofit2.Callback
import java.util.Map
/**
* Created by zlj on 2017/2/14.
*/
class AccountManager private constructor() {
private val accountService: AccountService
private var mChapterSub: Subscription? = null
init {
accountService = ServiceGenerator.createService(AccountService::class.java, MyRequestType.URL_TEXT)
}
fun getRecommendBook(bookId: String, limit: String) {
val map = HashMap<String, String>()
map["book_id"] = bookId
val call = accountService.getRecommendBook(getUrlString(Urls.getRecommend, map))
call.enqueue(ServiceCallback(GetRecommendBookEvent::class.java))
}
fun getBookDetail(bookId: String) {
val map = HashMap<String, String>()
map["book_id"] = bookId
val call = accountService.getBookDetail(getUrlString(Urls.getBookDetail, map))
call.enqueue(ServiceCallback(GetBookDetailEvent::class.java))
}
fun getBookDetails(bookId: String): Single<BookDetailResp> { //rxjava 获取多书籍详情 合并请求调用
val map = HashMap<String, String>()
map["book_id"] = bookId
return accountService.getBookDetails(getUrlString(Urls.getBookDetail, map))
}
fun getCategoryType() {
val map = HashMap<String, String>()
val call = accountService.getCategoryType(getUrlString(Urls.getCategoryType, map))
call.enqueue(ServiceCallback(GetCategoryTypeEvent::class.java))
}
fun getHotSearch() {
val map = HashMap<String, String>()
val call = accountService.getHotSearch(getUrlString(Urls.getHotSearch, map))
call.enqueue(ServiceCallback(HotSearchEvent::class.java))
}
fun getBookArticle(bookId: String, hasContent: String, page: String, limit: String) {
val map = HashMap<String, String>()
map["book_id"] = bookId
map["has_content"] = hasContent
map["page"] = page
map["limit"] = limit
val call = accountService.getBookArticle(getUrlString(Urls.getBookArticle, map))
call.enqueue(ServiceCallback(BookArticleEvent::class.java))
}
fun getSearchBookList(category_id: String, key: String, page: Int) {
val map = HashMap<String, String>()
if (!TextUtils.isEmpty(category_id)) {
map["category_id"] = category_id
} else {
map["category_id"] = "0"
}
if (!TextUtils.isEmpty(key)) {
map["key"] = key
}
map["page"] = page.toString()
val call = accountService.getSearchList(getUrlString(Urls.getBookList, map))
call.enqueue(ServiceCallback(SearchListEvent::class.java))
}
fun getRecommendList(listType: String, callback: Callback<RecommendListResp>) {
val map = HashMap<String, String>()
map["type"] = listType
val call = accountService.getRecommendList(getUrlString(Urls.getRecommendList, map))
call.enqueue(callback)
}
fun getRankByUpdate(page: Int, limit: Int, callback: Callback<RankByUpadateResp>) {
val map = HashMap<String, String>()
if (!TextUtils.isEmpty(page.toString())) {
map["page"] = page.toString()
}
if (limit != 0) {
map["limit"] = limit.toString()
}
val call = accountService.getRankByUpdate(getUrlString(Urls.getRankByUpdate, map))
call.enqueue(callback)
}
fun getRankList(
type: String,
sex: String,
dateType: String,
page: String,
callback: Callback<RankByUpadateResp>
) {
val map = HashMap<String, String>()
map["type"] = type
map["gender"] = sex
map["date_type"] = dateType
map["page"] = page
val call = accountService.getRankList(getUrlString(Urls.getRankList, map))
call.enqueue(callback)
}
fun checkVersion(versionCode: Int) {
val map = HashMap<String, String>()
map["version"] = versionCode.toString()
// map.put("shell", Constant.shell);
val call = accountService.checkVersion(getUrlString(Urls.checkVersion, map))
call.enqueue(ServiceCallback(VersionEvent::class.java))
}
fun addSign(bookId: String, articleId: String, content: String) {
val map = HashMap<String, String>()
map["book_id"] = bookId
map["article_id"] = articleId
map["content"] = content
val call = accountService.addSign(Urls.addBookSign, mapToBody(map))
call.enqueue(ServiceCallback(AddBookSignEvent::class.java))
}
fun deleteSign(signIds: String) {
val map = HashMap<String, String>()
map["sign_ids"] = signIds
val call = accountService.deleteSign(Urls.deleteSign, mapToBody(map))
call.enqueue(ServiceCallback(DeleteBookSignEvent::class.java))
}
fun getSignList(bookId: String) {
val map = HashMap<String, String>()
map["book_id"] = bookId
val call = accountService.getSignList(getUrlString(Urls.getBookSign, map))
call.enqueue(ServiceCallback(GetBookSignEvent::class.java))
}
fun login(mContext: Context) {
val map = HashMap<String, String>()
Log.e("getUniquePsuedoID", "login: " + PhoneUtils.getUniquePsuedoID())
map["code"] = PhoneUtils.getUniquePsuedoID()
val call = accountService.login(Urls.login, mapToBody(map))
call.enqueue(ServiceCallback(LoginEvent::class.java))
}
fun getBookArticleDetail(bookId: String?, bookChapters: List<TxtChapter>) {
val size = bookChapters.size
//取消上次的任务,防止多次加载
if (mChapterSub != null) {
mChapterSub!!.cancel()
}
val chapterInfos = ArrayList<Single<ChapterInfoBean>>(bookChapters.size)
val titles = ArrayDeque<String>(bookChapters.size)
// 将要下载章节,转换成网络请求。
for (i in 0 until size) {
val bookChapter = bookChapters[i]
// 网络中获取数据
val chapterInfoSingle = getChapterInfo(bookChapter.chapterId)
chapterInfos.add(chapterInfoSingle)
titles.add(bookChapter.title)
}
Single.concat(chapterInfos)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Subscriber<ChapterInfoBean> {
internal var title = titles.poll()
override fun onSubscribe(s: Subscription) {
s.request(Integer.MAX_VALUE.toLong())
mChapterSub = s
}
override fun onNext(chapterInfoBean: ChapterInfoBean) {
//存储数据
BookRepository.getInstance().saveChapterInfo(
bookId, title, chapterInfoBean.body
)
EventManager.instance.postEvent(FinishChapterEvent())
//将获取到的数据进行存储
title = titles.poll()
}
override fun onError(t: Throwable) {
//只有第一个加载失败才会调用errorChapter
if (bookChapters[0].title == title) {
EventManager.instance.postEvent(ErrorChapterEvent())
}
LogUtils.e(t)
}
override fun onComplete() {}
}
)
}
/**
* 注意这里用的是同步请求
*/
fun getChapterInfo(id: String): Single<ChapterInfoBean> {
val map = HashMap<String, String>()
map["article_id"] = id
return accountService.getBookArticleDetail(getUrlString(Urls.getDetail, map))
.map { bean -> bean.article[0] }
}
/**
* get方法拼接字符串
*/
private fun getUrlString(path: String, query: HashMap<String, String>?): String {
var mypath = path
if (query != null && query.size > 0) {
val pathWithQuery = StringBuilder(path)
if (!path.contains("?")) {
pathWithQuery.append("?")
} else {
pathWithQuery.append("&")
}
for (stringStringEntry in query.entries) {
val key = (stringStringEntry as Map.Entry<*, *>).key as String
val `val` = (stringStringEntry as Map.Entry<*, *>).value as String
pathWithQuery.append(key)
pathWithQuery.append("=")
pathWithQuery.append(`val`)
pathWithQuery.append("&")
}
pathWithQuery.deleteCharAt(pathWithQuery.length - 1)
mypath = pathWithQuery.toString()
}
return mypath
}
/**
* 减少请求info类的数量,直接用map替代实体类返回body
*/
private fun mapToBody(map: HashMap<String, String>): RequestBody {
return RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
ServiceGenerator.formatResponse(map)
)
}
companion object {
private var instance: AccountManager? = null
@Synchronized
fun getInstance(): AccountManager {
if (instance == null) {
instance = AccountManager()
}
return instance as AccountManager
}
}
}

@ -1,94 +0,0 @@
package com.novel.read.http.service;
import com.mango.mangolib.http.ErrorResponse;
import com.novel.read.model.protocol.BookArticleResp;
import com.novel.read.model.protocol.BookDetailResp;
import com.novel.read.model.protocol.CategoryTypeResp;
import com.novel.read.model.protocol.ChapterInfoPackage;
import com.novel.read.model.protocol.HotSearchResp;
import com.novel.read.model.protocol.MarkResp;
import com.novel.read.model.protocol.RankByUpadateResp;
import com.novel.read.model.protocol.RecommendBookResp;
import com.novel.read.model.protocol.RecommendListResp;
import com.novel.read.model.protocol.SearchResp;
import com.novel.read.model.protocol.UidResp;
import com.novel.read.model.protocol.VersionResp;
import io.reactivex.Single;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Url;
/**
* Created by Administrator on 2017/2/14.
*/
public interface AccountService {
//获取推荐书籍
@GET
Call<RecommendBookResp> getRecommendBook(@Url String url);
//获取书籍详情
@GET
Call<BookDetailResp> getBookDetail(@Url String url);
//获取书籍详情
@GET
Single<BookDetailResp> getBookDetails(@Url String url);
//小说类型
@GET
Call<CategoryTypeResp> getCategoryType(@Url String url);
//热搜
@GET
Call<HotSearchResp> getHotSearch(@Url String url);
//书籍章节
@GET
Call<BookArticleResp> getBookArticle(@Url String url);
//搜索
@GET
Call<SearchResp> getSearchList(@Url String url);
//获取推荐
@GET
Call<RecommendListResp> getRecommendList(@Url String url);
//获取最新排行
@GET
Call<RankByUpadateResp> getRankByUpdate(@Url String url);
//获取排行
@GET
Call<RankByUpadateResp> getRankList(@Url String url);
//获取新版本
@GET
Call<VersionResp> checkVersion(@Url String url);
//添加标签
@POST
Call<ErrorResponse> addSign(@Url String url, @Body RequestBody body);
//删除标签
@POST
Call<ErrorResponse> deleteSign(@Url String url, @Body RequestBody body);
//获取标签
@GET
Call<MarkResp> getSignList(@Url String url);
//登录
@POST
Call<UidResp> login(@Url String url, @Body RequestBody body);
//获取书籍章节详情
@GET
Single<ChapterInfoPackage> getBookArticleDetail(@Url String url);
}

@ -0,0 +1,94 @@
package com.novel.read.http.service
import com.mango.mangolib.http.ErrorResponse
import com.novel.read.model.protocol.BookArticleResp
import com.novel.read.model.protocol.BookDetailResp
import com.novel.read.model.protocol.CategoryTypeResp
import com.novel.read.model.protocol.ChapterInfoPackage
import com.novel.read.model.protocol.HotSearchResp
import com.novel.read.model.protocol.MarkResp
import com.novel.read.model.protocol.RankByUpadateResp
import com.novel.read.model.protocol.RecommendBookResp
import com.novel.read.model.protocol.RecommendListResp
import com.novel.read.model.protocol.SearchResp
import com.novel.read.model.protocol.UidResp
import com.novel.read.model.protocol.VersionResp
import io.reactivex.Single
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Url
/**
* Created by Administrator on 2017/2/14.
*/
interface AccountService {
//获取推荐书籍
@GET
fun getRecommendBook(@Url url: String): Call<RecommendBookResp>
//获取书籍详情
@GET
fun getBookDetail(@Url url: String): Call<BookDetailResp>
//获取书籍详情
@GET
fun getBookDetails(@Url url: String): Single<BookDetailResp>
//小说类型
@GET
fun getCategoryType(@Url url: String): Call<CategoryTypeResp>
//热搜
@GET
fun getHotSearch(@Url url: String): Call<HotSearchResp>
//书籍章节
@GET
fun getBookArticle(@Url url: String): Call<BookArticleResp>
//搜索
@GET
fun getSearchList(@Url url: String): Call<SearchResp>
//获取推荐
@GET
fun getRecommendList(@Url url: String): Call<RecommendListResp>
//获取最新排行
@GET
fun getRankByUpdate(@Url url: String): Call<RankByUpadateResp>
//获取排行
@GET
fun getRankList(@Url url: String): Call<RankByUpadateResp>
//获取新版本
@GET
fun checkVersion(@Url url: String): Call<VersionResp>
//添加标签
@POST
fun addSign(@Url url: String, @Body body: RequestBody): Call<ErrorResponse>
//删除标签
@POST
fun deleteSign(@Url url: String, @Body body: RequestBody): Call<ErrorResponse>
//获取标签
@GET
fun getSignList(@Url url: String): Call<MarkResp>
//登录
@POST
fun login(@Url url: String, @Body body: RequestBody): Call<UidResp>
//获取书籍章节详情
@GET
fun getBookArticleDetail(@Url url: String): Single<ChapterInfoPackage>
}

@ -308,7 +308,7 @@ public class DownloadService extends BaseService {
final int[] result = {LOAD_NORMAL};
//问题:(这里有个问题,就是body其实比较大,如何获取数据流而不是对象,)是不是直接使用OkHttpClient交互会更好一点
Disposable disposable = AccountManager.getInstance()
Disposable disposable = AccountManager.Companion.getInstance()
.getChapterInfo(bean.getId())
//表示在当前环境下执行
.subscribe(

Loading…
Cancel
Save