parent
1fc37b253e
commit
d621430fab
|
@ -47,6 +47,18 @@ import java.util.*
|
|||
*/
|
||||
abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
||||
|
||||
override var refreshing: Boolean
|
||||
get() {
|
||||
if (context == null || isDetached) return false
|
||||
return loaderManager.hasRunningLoadersSafe()
|
||||
}
|
||||
set(value) {
|
||||
super.refreshing = value
|
||||
}
|
||||
|
||||
protected open val savedStatusesFileArgs: Array<String>?
|
||||
get() = null
|
||||
|
||||
private var lastId: String? = null
|
||||
private var page = 1
|
||||
private var pageDelta: Int = 0
|
||||
|
@ -58,22 +70,19 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteStatus(statusId: String) {
|
||||
val list = adapterData ?: return
|
||||
val dataToRemove = HashSet<ParcelableStatus>()
|
||||
for (i in 0 until list.size) {
|
||||
val status = list[i]
|
||||
if (status.id == statusId || status.retweet_id == statusId) {
|
||||
dataToRemove.add(status)
|
||||
} else if (status.my_retweet_id == statusId) {
|
||||
status.my_retweet_id = null
|
||||
status.retweet_count = status.retweet_count - 1
|
||||
}
|
||||
}
|
||||
if (list is MutableList) {
|
||||
list.removeAll(dataToRemove)
|
||||
}
|
||||
adapterData = list
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
bus.register(this)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
bus.unregister(this)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putInt(EXTRA_PAGE, page)
|
||||
}
|
||||
|
||||
override fun getStatuses(param: RefreshTaskParam): Boolean {
|
||||
|
@ -99,16 +108,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
return true
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
bus.register(this)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
bus.unregister(this)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun hasMoreData(data: List<ParcelableStatus>?): Boolean {
|
||||
if (data == null || data.isEmpty()) return false
|
||||
val tmpLastId = lastId
|
||||
|
@ -164,6 +163,43 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
getStatuses(param)
|
||||
}
|
||||
|
||||
override fun triggerRefresh(): Boolean {
|
||||
super.triggerRefresh()
|
||||
val accountKeys = accountKeys
|
||||
if (adapter.getStatusCount(true) > 0) {
|
||||
val firstStatus = adapter.getStatus(0, true)
|
||||
val sinceIds = Array(accountKeys.size) {
|
||||
return@Array if (firstStatus.account_key == accountKeys[it]) firstStatus.id else null
|
||||
}
|
||||
getStatuses(BaseRefreshTaskParam(accountKeys, null, sinceIds))
|
||||
} else {
|
||||
getStatuses(BaseRefreshTaskParam(accountKeys, null, null))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onHasMoreDataChanged(hasMoreData: Boolean) {
|
||||
pageDelta = if (hasMoreData) 1 else 0
|
||||
}
|
||||
|
||||
fun removeStatus(statusId: String) {
|
||||
val list = adapterData ?: return
|
||||
val dataToRemove = HashSet<ParcelableStatus>()
|
||||
for (i in 0 until list.size) {
|
||||
val status = list[i]
|
||||
if (status.id == statusId || status.retweet_id == statusId) {
|
||||
dataToRemove.add(status)
|
||||
} else if (status.my_retweet_id == statusId) {
|
||||
status.my_retweet_id = null
|
||||
status.retweet_count = status.retweet_count - 1
|
||||
}
|
||||
}
|
||||
if (list is MutableList) {
|
||||
list.removeAll(dataToRemove)
|
||||
}
|
||||
adapterData = list
|
||||
}
|
||||
|
||||
fun replaceStatusStates(status: ParcelableStatus?) {
|
||||
if (status == null) return
|
||||
val lm = layoutManager
|
||||
|
@ -182,41 +218,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
adapter.notifyItemRangeChanged(rangeStart, rangeEnd)
|
||||
}
|
||||
|
||||
override fun triggerRefresh(): Boolean {
|
||||
super.triggerRefresh()
|
||||
val accountKeys = accountKeys
|
||||
if (adapter.getStatusCount(true) > 0) {
|
||||
val firstStatus = adapter.getStatus(0, true)
|
||||
val sinceIds = Array(accountKeys.size) {
|
||||
return@Array if (firstStatus.account_key == accountKeys[it]) firstStatus.id else null
|
||||
}
|
||||
getStatuses(BaseRefreshTaskParam(accountKeys, null, sinceIds))
|
||||
} else {
|
||||
getStatuses(BaseRefreshTaskParam(accountKeys, null, null))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override var refreshing: Boolean
|
||||
get() {
|
||||
if (context == null || isDetached) return false
|
||||
return loaderManager.hasRunningLoadersSafe()
|
||||
}
|
||||
set(value) {
|
||||
super.refreshing = value
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle?) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState!!.putInt(EXTRA_PAGE, page)
|
||||
}
|
||||
|
||||
protected open val savedStatusesFileArgs: Array<String>?
|
||||
get() = null
|
||||
|
||||
override fun onHasMoreDataChanged(hasMoreData: Boolean) {
|
||||
pageDelta = if (hasMoreData) 1 else 0
|
||||
}
|
||||
|
||||
private fun updateFavoritedStatus(status: ParcelableStatus) {
|
||||
replaceStatusStates(status)
|
||||
|
@ -234,28 +235,44 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
adapterData = data
|
||||
}
|
||||
|
||||
protected open fun notifyFavoriteTask(event: FavoriteTaskEvent) {
|
||||
if (event.isSucceeded) {
|
||||
updateFavoritedStatus(event.status!!)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun notifyStatusDestroyed(event: StatusDestroyedEvent) {
|
||||
removeStatus(event.status.id)
|
||||
}
|
||||
|
||||
protected open fun notifyStatusListChanged(event: StatusListChangedEvent) {
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
protected open fun notifyStatusRetweeted(event: StatusRetweetedEvent) {
|
||||
updateRetweetedStatuses(event.status)
|
||||
}
|
||||
|
||||
protected inner class ParcelableStatusesBusCallback {
|
||||
|
||||
@Subscribe
|
||||
fun notifyFavoriteTask(event: FavoriteTaskEvent) {
|
||||
if (event.isSucceeded) {
|
||||
updateFavoritedStatus(event.status!!)
|
||||
}
|
||||
fun onFavoriteTaskEvent(event: FavoriteTaskEvent) {
|
||||
notifyFavoriteTask(event)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun notifyStatusDestroyed(event: StatusDestroyedEvent) {
|
||||
deleteStatus(event.status.id)
|
||||
fun onStatusDestroyedEvent(event: StatusDestroyedEvent) {
|
||||
notifyStatusDestroyed(event)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun notifyStatusListChanged(event: StatusListChangedEvent) {
|
||||
adapter.notifyDataSetChanged()
|
||||
fun onStatusListChangedEvent(event: StatusListChangedEvent) {
|
||||
notifyStatusListChanged(event)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun notifyStatusRetweeted(event: StatusRetweetedEvent) {
|
||||
updateRetweetedStatuses(event.status)
|
||||
fun onStatusRetweetedEvent(event: StatusRetweetedEvent) {
|
||||
notifyStatusRetweeted(event)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.mariotaku.twidere.TwidereConstants.*
|
|||
import org.mariotaku.twidere.loader.UserFavoritesLoader
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.event.FavoriteTaskEvent
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.util.*
|
||||
|
||||
|
@ -35,23 +36,6 @@ import java.util.*
|
|||
*/
|
||||
class UserFavoritesFragment : ParcelableStatusesFragment() {
|
||||
|
||||
override fun onCreateStatusesLoader(context: Context,
|
||||
args: Bundle,
|
||||
fromUser: Boolean): Loader<List<ParcelableStatus>?> {
|
||||
refreshing = true
|
||||
val accountKey = Utils.getAccountKey(context, args)
|
||||
val maxId = args.getString(EXTRA_MAX_ID)
|
||||
val sinceId = args.getString(EXTRA_SINCE_ID)
|
||||
val page = args.getInt(EXTRA_PAGE, -1)
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return UserFavoritesLoader(context, accountKey, userKey, screenName, sinceId, maxId,
|
||||
page, adapterData, savedStatusesFileArgs, tabPosition, fromUser,
|
||||
loadingMore)
|
||||
}
|
||||
|
||||
override val savedStatusesFileArgs: Array<String>?
|
||||
get() {
|
||||
val args = arguments!!
|
||||
|
@ -71,7 +55,6 @@ class UserFavoritesFragment : ParcelableStatusesFragment() {
|
|||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
|
||||
override val readPositionTagWithArguments: String?
|
||||
get() {
|
||||
val args = arguments!!
|
||||
|
@ -91,6 +74,39 @@ class UserFavoritesFragment : ParcelableStatusesFragment() {
|
|||
return sb.toString()
|
||||
}
|
||||
|
||||
|
||||
@TimelineType
|
||||
override val timelineType: String = TimelineType.OTHER
|
||||
|
||||
override fun onCreateStatusesLoader(context: Context, args: Bundle, fromUser: Boolean):
|
||||
Loader<List<ParcelableStatus>?> {
|
||||
refreshing = true
|
||||
val accountKey = Utils.getAccountKey(context, args)
|
||||
val maxId = args.getString(EXTRA_MAX_ID)
|
||||
val sinceId = args.getString(EXTRA_SINCE_ID)
|
||||
val page = args.getInt(EXTRA_PAGE, -1)
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return UserFavoritesLoader(context, accountKey, userKey, screenName, sinceId, maxId,
|
||||
page, adapterData, savedStatusesFileArgs, tabPosition, fromUser,
|
||||
loadingMore)
|
||||
}
|
||||
|
||||
override fun notifyFavoriteTask(event: FavoriteTaskEvent) {
|
||||
if (event.action == FavoriteTaskEvent.Action.DESTROY && event.isSucceeded) {
|
||||
event.status?.let { status ->
|
||||
val args = arguments!!
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
if (status.account_key == userKey) {
|
||||
removeStatus(event.statusId)
|
||||
triggerRefresh()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
super.notifyFavoriteTask(event)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,8 +96,7 @@ class DestroyFavoriteTask(
|
|||
|
||||
override fun afterExecute(callback: Any?, result: SingleResponse<ParcelableStatus>) {
|
||||
destroyingFavoriteIds.removeElement(AsyncTwitterWrapper.calculateHashCode(accountKey, statusId))
|
||||
val taskEvent = FavoriteTaskEvent(FavoriteTaskEvent.Action.DESTROY,
|
||||
accountKey, statusId)
|
||||
val taskEvent = FavoriteTaskEvent(FavoriteTaskEvent.Action.DESTROY, accountKey, statusId)
|
||||
taskEvent.isFinished = true
|
||||
if (result.hasData()) {
|
||||
val status = result.data
|
||||
|
|
|
@ -58,10 +58,6 @@
|
|||
android:icon="@drawable/ic_action_delete"
|
||||
android:title="@string/action_delete"
|
||||
android:visible="false"/>
|
||||
<item
|
||||
android:id="@id/open_in_browser"
|
||||
android:icon="@drawable/ic_action_web"
|
||||
android:title="@string/action_open_in_browser"/>
|
||||
<item
|
||||
android:id="@id/copy_url"
|
||||
android:icon="@drawable/ic_action_link"
|
||||
|
@ -70,5 +66,9 @@
|
|||
android:id="@id/open_with_account"
|
||||
android:icon="@drawable/ic_action_accounts"
|
||||
android:title="@string/open_with_account"/>
|
||||
<item
|
||||
android:id="@id/open_in_browser"
|
||||
android:icon="@drawable/ic_action_web"
|
||||
android:title="@string/action_open_in_browser"/>
|
||||
|
||||
</menu>
|
Loading…
Reference in New Issue