diff --git a/app/src/main/java/soko/ekibun/bangumi/api/bangumi/Bangumi.kt b/app/src/main/java/soko/ekibun/bangumi/api/bangumi/Bangumi.kt index 0ca0050..c7178a5 100644 --- a/app/src/main/java/soko/ekibun/bangumi/api/bangumi/Bangumi.kt +++ b/app/src/main/java/soko/ekibun/bangumi/api/bangumi/Bangumi.kt @@ -202,7 +202,7 @@ interface Bangumi { Pair(tip.trim(':',' '), it.text().substring(tip.length).trim()) } - val eps_count = infobox?.firstOrNull { it.first == "话数" }?.second?.toIntOrNull()?:subject.eps_count + var eps_count = infobox?.firstOrNull { it.first == "话数" }?.second?.toIntOrNull()?:subject.eps_count //air-date val air_date = infobox?.firstOrNull { it.first in arrayOf("放送开始", "上映年度", "开始") }?.second?.replace("/", "-")?. replace("年", "-")?.replace("月", "-")?.replace("日", "")?:"" @@ -230,7 +230,20 @@ interface Bangumi { img.replace("/c/", "/s/"), img.replace("/c/", "/g/")) //TODO Collection - //no eps + //prg + val ep_status = doc.selectFirst("input[name=watchedeps]")?.attr("value")?.toIntOrNull()?:0 + val vol_status = doc.selectFirst("input[name=watched_vols]")?.attr("value")?.toIntOrNull()?:0 + var vol_count = 0 + var has_vol = false + doc.select(".prgText")?.forEach { + when(it.selectFirst(".type")?.text()){ + "Vol." -> { + has_vol = true + vol_count = it.ownText()?.trim(' ', '/')?.toIntOrNull()?:0 + } + else -> eps_count = it.ownText()?.trim(' ', '/')?.toIntOrNull()?:0 + } + } //crt val crt = doc.select(".subject_section").filter { it.select(".subtitle")?.text() == "角色介绍" }.getOrNull(0)?.select("li")?.map { val a = it.selectFirst("a.avatar") @@ -358,6 +371,7 @@ interface Bangumi { //formhash val formhash = if(doc.selectFirst(".guest") != null) "" else doc.selectFirst("input[name=formhash]")?.attr("value") Subject(subject.id, subject.url, type, name, name_cn, summary, eps_count, air_date, air_weekday, rating, rank, images, infobox = infobox, + ep_status = ep_status, vol_count = vol_count, vol_status = vol_status, has_vol = has_vol, crt=crt, topic = topic, blog = blog, linked = linked, commend = commend, tags = tags, typeString = typeString, formhash = formhash, interest = interest) } } @@ -653,7 +667,20 @@ interface Bangumi { val name = data.attr("data-subject-name") val name_cn = data.attr("data-subject-name-cn") val img = getImageUrl(it.selectFirst("img")) - val eps_count = it.selectFirst(".prgBatchManagerForm .grey")?.text()?.trim(' ', '/')?.toIntOrNull()?:0 + val ep_status = it.selectFirst("input[name=watchedeps]")?.attr("value")?.toIntOrNull()?:0 + var eps_count = it.selectFirst(".prgBatchManagerForm .grey")?.text()?.trim(' ', '/')?.toIntOrNull()?:0 + val vol_status = it.selectFirst("input[name=watched_vols]")?.attr("value")?.toIntOrNull()?:0 + var vol_count = 0 + var has_vol = false + it.select(".prgText")?.forEach { + when(it.selectFirst(".type")?.text()){ + "Chap." -> eps_count = it.ownText()?.trim(' ', '/')?.toIntOrNull()?:0 + "Vol." -> { + has_vol = true + vol_count = it.ownText()?.trim(' ', '/')?.toIntOrNull()?:0 + } + } + } val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) val now = Date().time var cat = "MAIN" @@ -686,11 +713,12 @@ interface Bangumi { val watched_eps = it.selectFirst("input[name=watchedeps]")?.attr("value")?.toIntOrNull()?:0 val watched_vols = it.selectFirst("input[name=watched_vols]")?.attr("value")?.toIntOrNull()?:0 ret += SubjectCollection(name, id, watched_eps, watched_vols, 0, Subject( - id, "$SERVER/subject/$id", type, name, name_cn, eps = eps, eps_count = eps_count, - images = Images(img.replace("/g/", "/l/"), - img.replace("/g/", "/m/"), - img.replace("/g/", "/c/"), - img.replace("/g/", "/s/"), img))) + id, "$SERVER/subject/$id", type, name, name_cn, eps = eps, + eps_count = eps_count, ep_status = ep_status, vol_count = vol_count, vol_status = vol_status, has_vol = has_vol, + images = Images(img.replace("/s/", "/l/"), + img.replace("/s/", "/m/"), + img.replace("/s/", "/c/"), img, + img.replace("/s/", "/s/")))) } return@buildHttpCall ret } diff --git a/app/src/main/java/soko/ekibun/bangumi/api/bangumi/bean/Subject.kt b/app/src/main/java/soko/ekibun/bangumi/api/bangumi/bean/Subject.kt index 1d2748c..27db929 100644 --- a/app/src/main/java/soko/ekibun/bangumi/api/bangumi/bean/Subject.kt +++ b/app/src/main/java/soko/ekibun/bangumi/api/bangumi/bean/Subject.kt @@ -30,7 +30,11 @@ data class Subject( var tags: List>? = null, var typeString: String? = null, var formhash: String? = null, - var interest: Collection? = null + var interest: Collection? = null, + var ep_status: Int = 0, + var vol_status: Int = 0, + var vol_count: Int = 0, + var has_vol: Boolean = false ){ fun getPrettyName(): String{ return ((if(name_cn.isNullOrEmpty()) name else name_cn)?:"").replace("&", "&") diff --git a/app/src/main/java/soko/ekibun/bangumi/ui/subject/EditProgressDialog.kt b/app/src/main/java/soko/ekibun/bangumi/ui/subject/EditProgressDialog.kt new file mode 100644 index 0000000..5921d92 --- /dev/null +++ b/app/src/main/java/soko/ekibun/bangumi/ui/subject/EditProgressDialog.kt @@ -0,0 +1,97 @@ +package soko.ekibun.bangumi.ui.subject + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.Rect +import android.os.Bundle +import android.support.v4.app.DialogFragment +import android.support.v7.app.AppCompatActivity +import android.util.DisplayMetrics +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.WindowManager +import kotlinx.android.synthetic.main.dialog_edit_progress.view.* +import okhttp3.FormBody +import soko.ekibun.bangumi.R +import soko.ekibun.bangumi.api.ApiHelper +import soko.ekibun.bangumi.api.bangumi.Bangumi +import soko.ekibun.bangumi.api.bangumi.bean.Subject + +class EditProgressDialog: DialogFragment() { + companion object { + fun showDialog(context: AppCompatActivity, subject: Subject, formhash: String, ua: String, callback: ()->Unit){ + val dialog = EditProgressDialog() + dialog.subject = subject + dialog.formhash = formhash + dialog.callback = callback + dialog.ua = ua + dialog.show(context.supportFragmentManager, "edit_progress") + } + } + + private fun getKeyBoardHeight(): Int{ + val rect = Rect() + activity?.window?.decorView?.getWindowVisibleDisplayFrame(rect) + val metrics = DisplayMetrics() + (activity?.getSystemService(Context.WINDOW_SERVICE) as? WindowManager)?.defaultDisplay?.getMetrics(metrics) + return metrics.heightPixels - rect.bottom + } + + lateinit var subject: Subject + lateinit var formhash: String + lateinit var ua: String + lateinit var callback: ()->Unit + @SuppressLint("SetTextI18n") + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val view = inflater.inflate(R.layout.dialog_edit_progress, container) + + view.item_eps.setText(subject.ep_status.toString()) + view.item_eps_info.text = "${ if(subject.eps_count == 0) "" else "/${subject.eps_count}" } 话" + view.item_vol.setText(subject.vol_status.toString()) + view.item_vol_info.text = "${ if(subject.vol_count == 0) "" else "/${subject.vol_count}" } 章" + view.item_vol_panel.visibility = if(subject.has_vol) View.VISIBLE else View.GONE + + view.item_outside.setOnClickListener { + dialog.dismiss() + } + view.item_submit.setOnClickListener { + dialog.dismiss() + val body = FormBody.Builder() + .add("referer", "subject") + .add("submit", "更新") + .add("watchedeps", view.item_eps.text.toString()) + if(subject.has_vol) body.add("watched_vols", view.item_vol.text.toString()) + + ApiHelper.buildHttpCall("${Bangumi.SERVER}/subject/set/watched/${subject.id}", mapOf("User-Agent" to ua), body.build()){ + it.code() == 200 + }.enqueue(ApiHelper.buildCallback(context,{ + if(!it) return@buildCallback + subject.ep_status = view.item_eps.text.toString().toIntOrNull()?:0 + subject.vol_status = view.item_vol.text.toString().toIntOrNull()?:0 + callback() + },{})) + } + + activity?.window?.decorView?.viewTreeObserver?.addOnGlobalLayoutListener{ + view.item_keyboard.layoutParams?.let{ + it.height = getKeyBoardHeight() + view.item_keyboard.layoutParams = it + } + } + + dialog.window?.attributes?.let{ + it.dimAmount = 0.6f + dialog.window?.attributes = it + } + dialog.window?.setWindowAnimations(R.style.AnimDialog) + dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) + return view + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_Dialog) + } +} \ No newline at end of file diff --git a/app/src/main/java/soko/ekibun/bangumi/ui/subject/EditSubjectDialog.kt b/app/src/main/java/soko/ekibun/bangumi/ui/subject/EditSubjectDialog.kt index 537c2b7..e16fe0a 100644 --- a/app/src/main/java/soko/ekibun/bangumi/ui/subject/EditSubjectDialog.kt +++ b/app/src/main/java/soko/ekibun/bangumi/ui/subject/EditSubjectDialog.kt @@ -24,7 +24,6 @@ class EditSubjectDialog: DialogFragment() { val dialog = EditSubjectDialog() dialog.subject = subject dialog.status = status - dialog.status = status dialog.formhash = formhash dialog.callback = callback dialog.ua = ua diff --git a/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectPresenter.kt b/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectPresenter.kt index e556a44..ffa14da 100644 --- a/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectPresenter.kt +++ b/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectPresenter.kt @@ -47,6 +47,12 @@ class SubjectPresenter(private val context: SubjectActivity){ WebActivity.launchUrl(context, "${subject.url}/characters") } + subjectView.detail.item_progress_edit.setOnClickListener { + EditProgressDialog.showDialog(context, this.subject, context.formhash, context.ua){ + refresh() + } + } + context.title_expand.setOnClickListener { WebActivity.launchUrl(context, subject.url) } @@ -295,9 +301,9 @@ class SubjectPresenter(private val context: SubjectActivity){ } private fun loadComment(subject: Subject, page: Int){ - if(page == 1) - subjectView.commentAdapter.setNewData(null) Bangumi.getComments(subject, page, context.ua).enqueue(ApiHelper.buildCallback(context, { + if(page == 1) + subjectView.commentAdapter.setNewData(null) if(it?.isEmpty() == true) subjectView.commentAdapter.loadMoreEnd() else{ diff --git a/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectView.kt b/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectView.kt index 7f442be..e28df20 100644 --- a/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectView.kt +++ b/app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectView.kt @@ -30,9 +30,7 @@ import kotlinx.android.synthetic.main.subject_episode.view.* import kotlinx.android.synthetic.main.subject_topic.* import soko.ekibun.bangumi.R import soko.ekibun.bangumi.api.bangumi.Bangumi -import soko.ekibun.bangumi.api.bangumi.bean.Episode -import soko.ekibun.bangumi.api.bangumi.bean.Subject -import soko.ekibun.bangumi.api.bangumi.bean.SubjectType +import soko.ekibun.bangumi.api.bangumi.bean.* import soko.ekibun.bangumi.ui.main.fragment.calendar.CalendarAdapter import soko.ekibun.bangumi.ui.view.DragPhotoView import soko.ekibun.bangumi.ui.web.WebActivity @@ -263,6 +261,9 @@ class SubjectView(private val context: SubjectActivity){ .show() else WebActivity.launchUrl(context, subject.url) } + + detail.item_progress.visibility = if(subject.formhash?.isNotEmpty() == true && subject.interest?.status?.type == CollectionStatusType.DO && subject.type in listOf(SubjectType.ANIME, SubjectType.REAL, SubjectType.BOOK)) View.VISIBLE else View.GONE + detail.item_progress_info.text = "看到 ${ if(subject.has_vol) "第 ${subject.vol_status}${ if(subject.vol_count == 0) "" else "/${subject.vol_count}" } 章 " else ""}第 ${subject.ep_status}${ if(subject.eps_count == 0) "" else "/${subject.eps_count}" } 话" } fun updateEpisode(episodes: List){ diff --git a/app/src/main/res/layout/activity_subject.xml b/app/src/main/res/layout/activity_subject.xml index 6d19c94..65c997e 100644 --- a/app/src/main/res/layout/activity_subject.xml +++ b/app/src/main/res/layout/activity_subject.xml @@ -148,6 +148,29 @@ android:layout_width="match_parent" android:layout_height="wrap_content"/> + + + + diff --git a/app/src/main/res/layout/dialog_edit_progress.xml b/app/src/main/res/layout/dialog_edit_progress.xml new file mode 100644 index 0000000..108a858 --- /dev/null +++ b/app/src/main/res/layout/dialog_edit_progress.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + +