Skip to content

Commit

Permalink
Add Attitude
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Dec 1, 2016
1 parent 2af4705 commit 5970817
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<del>允许拆分提及与评论</del>
<del>添加图片下载度条</del>
<del>解决大图无法显示问题</del>
<del>无图模式</del>
夜间模式
无图模式
多用户登陆
整理直接写代码中的String
搜索
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class MainActivity : BaseActivity() {
pageAdapter.add(Comment())
pageAdapter.add(CommentMention())
}
pageAdapter.add(Attitude())
pageAdapter.add(DirectMessage())
mPivot.adapter = pageAdapter
mPivot.setOffscreenPageLimit(pageAdapter.count)
Expand Down Expand Up @@ -120,7 +121,7 @@ class MainActivity : BaseActivity() {
}
})
kotlin.concurrent.timer(period = notifyInterval.toLong()){
Remind.getUnread(object : JsonCallback<UnreadModel>() {
Remind.getUnread(callback = object : JsonCallback<UnreadModel>() {
override fun onResponse(response: UnreadModel?, id: Int) {
if (PreferenceManager.getDefaultSharedPreferences(this@MainActivity).getBoolean(getString(R.string.is_merge_message_key), false)) {
var count = 0
Expand All @@ -131,7 +132,8 @@ class MainActivity : BaseActivity() {
if (PreferenceManager.getDefaultSharedPreferences(this@MainActivity).getBoolean(getString(R.string.is_comment_notify_name), true))
count += response?.cmt!!
if (PreferenceManager.getDefaultSharedPreferences(this@MainActivity).getBoolean(getString(R.string.is_message_notify_name), true))
count += response?.dm!!
mPivot.setTabBadge(mPivot.tabLayout.tabCount - 1, response?.dm!!)
mPivot.setTabBadge(mPivot.tabLayout.tabCount - 2, response?.attitude!!)
mPivot.setTabBadge(1, count)
} else {
if (PreferenceManager.getDefaultSharedPreferences(this@MainActivity).getBoolean(getString(R.string.is_mention_notify_name), true)) {
Expand All @@ -141,7 +143,8 @@ class MainActivity : BaseActivity() {
if (PreferenceManager.getDefaultSharedPreferences(this@MainActivity).getBoolean(getString(R.string.is_comment_notify_name), true))
mPivot.setTabBadge(2, response?.cmt!!)
if (PreferenceManager.getDefaultSharedPreferences(this@MainActivity).getBoolean(getString(R.string.is_message_notify_name), true))
mPivot.setTabBadge(4, response?.dm!!)
mPivot.setTabBadge(mPivot.tabLayout.tabCount - 1, response?.dm!!)
mPivot.setTabBadge(mPivot.tabLayout.tabCount - 2, response?.attitude!!)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import moe.tlaster.openween.common.controls.WeiboTextBlock
import moe.tlaster.openween.common.entities.PostWeiboType
import moe.tlaster.openween.common.helpers.WeiboCardHelper
import moe.tlaster.openween.core.model.BaseModel
import moe.tlaster.openween.core.model.attitude.AttitudeModel
import moe.tlaster.openween.core.model.comment.CommentModel
import moe.tlaster.openween.core.model.status.MessageModel
import moe.tlaster.openween.core.model.user.UserModel
Expand All @@ -49,7 +50,9 @@ class BaseModelAdapter<T : BaseModel> @JvmOverloads constructor(private val mIsE
if (p1.retweetedStatus != null)
baseView.findViewById(R.id.weibo_repost_container).findViewById(R.id.weibo_content).setOnClickListener { view -> goDetail(p1.retweetedStatus as MessageModel, baseView.findViewById(R.id.weibo_repost_container)) }
}
if (p1 is CommentModel && p1.status != null)
else if (p1 is CommentModel && p1.status != null)
baseView.findViewById(R.id.weibo_repost_container).findViewById(R.id.weibo_content).setOnClickListener { view -> goDetail(p1.status as MessageModel, baseView.findViewById(R.id.weibo_repost_container)) }
else if (p1 is AttitudeModel && p1.status != null)
baseView.findViewById(R.id.weibo_repost_container).findViewById(R.id.weibo_content).setOnClickListener { view -> goDetail(p1.status as MessageModel, baseView.findViewById(R.id.weibo_repost_container)) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import moe.tlaster.openween.adapter.WeiboImageAdapter
import moe.tlaster.openween.common.controls.WeiboTextBlock
import moe.tlaster.openween.common.entities.PostWeiboType
import moe.tlaster.openween.core.model.BaseModel
import moe.tlaster.openween.core.model.attitude.AttitudeModel
import moe.tlaster.openween.core.model.comment.CommentModel
import moe.tlaster.openween.core.model.status.MessageModel

Expand All @@ -37,6 +38,8 @@ internal object WeiboCardHelper {
val weiboRepostContainer = baseView.findViewById(R.id.weibo_repost_container)
val weiboRepostLinear = baseView.findViewById(R.id.weibo_repost_linear)
val enableImage = !((PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.is_auto_disable_image_key), false) && !DeviceHelper.checkWifiOnAndConnected(context)) || PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.is_disable_image_key), false))
if (baseModel is AttitudeModel)
baseModel.text = "赞了这条微博"
setWeiboContent(weiboContentContainer, baseModel, context = context, textColor = textColor, enableImage = enableImage)
if (baseModel is MessageModel) {
baseView.findViewById(R.id.comment).visibility = View.GONE
Expand Down Expand Up @@ -75,6 +78,15 @@ internal object WeiboCardHelper {
weiboRepostLinear.visibility = View.GONE
}
baseView.findViewById(R.id.comment).setOnClickListener(getReplyCommentListener(baseModel, context))
} else if (baseModel is AttitudeModel) {
baseView.findViewById(R.id.comment).visibility = View.GONE
baseView.findViewById(R.id.weibo_action).visibility = View.GONE
if (isEnableRepost) {
weiboRepostLinear.visibility = View.VISIBLE
setWeiboContent(baseView.findViewById(R.id.weibo_repost_container), baseModel.status as MessageModel, enableImage = false, context = context)
} else {
weiboRepostLinear.visibility = View.GONE
}
}
}

Expand Down Expand Up @@ -136,6 +148,8 @@ internal object WeiboCardHelper {
} else if (item is CommentModel) {
nineGridImageView.visibility = View.GONE
content.setOnClickListener(getReplyCommentListener(item, context))
} else if (item is AttitudeModel) {
nineGridImageView.visibility = View.GONE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import moe.tlaster.openween.core.api.Constants
import moe.tlaster.openween.common.helpers.HttpHelper
import moe.tlaster.openween.common.helpers.InvalidAccessTokenException
import moe.tlaster.openween.common.helpers.JsonCallback
import moe.tlaster.openween.core.model.attitude.AttitudeListModel
import moe.tlaster.openween.core.model.attitude.AttitudeModel

/**
* Created by Tlaster on 2016/9/2.
Expand All @@ -23,7 +25,7 @@ object Attitudes {
param.put("id", id.toString())
HttpHelper.postAsync(Constants.ATTITUDE_DESTROY, param, callback)
}
fun likeToMe(callback: JsonCallback<String>, with_common_attitude: Boolean = true, with_comment: Boolean = true, since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1) {
fun likeToMe(callback: JsonCallback<AttitudeListModel>, with_common_attitude: Boolean = true, with_comment: Boolean = true, since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1) {
val param = HashMap<String, String>()
param.put("with_common_attitude", if (with_common_attitude) "1" else "0")
param.put("with_comment", if (with_comment) "1" else "0")
Expand All @@ -33,6 +35,6 @@ object Attitudes {
param.put("page", page.toString())
param.put("source", "211160679")
param.put("from", "1055095010")

HttpHelper.getAsync("https://api.weibo.cn/2/like/to_me", param, callback)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ import moe.tlaster.openween.common.helpers.JsonCallback
* Created by Tlaster on 2016/9/7.
*/
object Remind {
fun getUnread(uid: String, callback: JsonCallback<UnreadModel>) {
fun getUnread(unread_message: Boolean = true, callback: JsonCallback<UnreadModel>) {
val param = HashMap<String, String>()
param.put("uid", uid.toString())
param.put("unread_message", "0")
param.put("unread_message", if (unread_message) "1" else "0")
HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, param, callback)
}

fun getUnread(callback: JsonCallback<UnreadModel>) {
HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, null, callback)
}

fun clearUnread(type: RemindType) {
val param = HashMap<String, String>()
param.put("type", type.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.google.gson.annotations.SerializedName
* Created by Tlaster on 2016/8/26.
*/
class UnreadModel {
@SerializedName("attitude")
var attitude = 0
@SerializedName("status")
var status = 0
@SerializedName("follower")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package moe.tlaster.openween.core.model.attitude

import com.google.gson.annotations.SerializedName
import moe.tlaster.openween.core.model.BaseListModel
import moe.tlaster.openween.core.model.status.MessageModel

/**
* Created by Asahi on 16/12/01.
*/
class AttitudeListModel : BaseListModel() {
@SerializedName("attitudes")
var attitudes: List<AttitudeModel>? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package moe.tlaster.openween.core.model.attitude

import com.google.gson.annotations.SerializedName
import moe.tlaster.openween.core.model.BaseModel
import moe.tlaster.openween.core.model.status.MessageModel

/**
* Created by Asahi on 16/12/01.
*/
class AttitudeModel : BaseModel() {
@SerializedName("attitude")
var attitude: String = ""
@SerializedName("attitude_type")
var attitudeType: Int = -1
@SerializedName("last_attitude")
var lastAttitude: String = ""
@SerializedName("status")
var status: MessageModel? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract class WeiboListBase<T> : Pivot.PivotItemFragment() {
mRecyclerView?.layoutManager = layoutManager
mAdapter = initAdapter()
mAdapter?.openLoadAnimation()
mAdapter?.openLoadMore(20)
mAdapter?.openLoadMore(mLoadCount)
mRecyclerView?.adapter = mAdapter
mAdapter?.setOnLoadMoreListener { mRecyclerView?.post { this.loadMore() } }
mRecyclerView?.addItemDecoration(SimpleDividerItemDecoration(context))
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/kotlin/moe/tlaster/openween/fragment/main/Attitude.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package moe.tlaster.openween.fragment.main

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
import moe.tlaster.openween.adapter.BaseModelAdapter
import moe.tlaster.openween.core.api.attitudes.Attitudes
import moe.tlaster.openween.core.model.attitude.AttitudeListModel
import moe.tlaster.openween.core.model.attitude.AttitudeModel
import moe.tlaster.openween.fragment.WeiboListBase

/**
* Created by Asahi on 16/12/01.
*/
class Attitude(override val icon: IIcon = GoogleMaterial.Icon.gmd_thumb_up) : WeiboListBase<AttitudeModel>() {

override fun initAdapter(): BaseQuickAdapter<AttitudeModel, BaseViewHolder> {
return BaseModelAdapter()
}

override fun loadMoreOverride(callback: Callback<List<AttitudeModel>>) {
Attitudes.likeToMe(count = mLoadCount, max_id = mAdapter?.data?.last()?.id!!, callback = object : WeiboListCallback<AttitudeListModel>() {
override fun onResponse(response: AttitudeListModel, id: Int) {
response.attitudes = response.attitudes?.subList(1, response.attitudes?.lastIndex!!)
callback.onResponse(response.attitudes!!, response.totalNumber)
}
})
}

override fun refreshOverride(callback: Callback<List<AttitudeModel>>) {
Attitudes.likeToMe(count = mLoadCount, callback = object : WeiboListCallback<AttitudeListModel>() {
override fun onResponse(response: AttitudeListModel, id: Int) {
callback.onResponse(response.attitudes!!, response.totalNumber)
}
})
}
}

0 comments on commit 5970817

Please sign in to comment.