implemented user list selector
This commit is contained in:
parent
85ae456b4a
commit
0f74a8c8ec
|
@ -348,7 +348,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
|
|||
return createViewFromResource(position, convertView, parent, mResource);
|
||||
}
|
||||
|
||||
private View createViewFromResource(int position, View convertView, ViewGroup parent,
|
||||
protected View createViewFromResource(int position, View convertView, ViewGroup parent,
|
||||
int resource) {
|
||||
View view;
|
||||
TextView text;
|
||||
|
|
|
@ -34,8 +34,11 @@ import org.mariotaku.ktextension.set
|
|||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.REQUEST_SELECT_USER
|
||||
import org.mariotaku.twidere.adapter.SimpleParcelableUserListsAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition
|
||||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.loader.UserListOwnershipsLoader
|
||||
import org.mariotaku.twidere.loader.iface.ICursorSupportLoader
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.ParcelableUserList
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
|
@ -54,6 +57,7 @@ class UserListSelectorActivity : BaseActivity(),
|
|||
get() = intent.getBooleanExtra(EXTRA_SHOW_MY_LISTS, false)
|
||||
|
||||
private var userKey: UserKey? = null
|
||||
private var nextCursor: Long = -1
|
||||
|
||||
private var loaderInitialized: Boolean = false
|
||||
|
||||
|
@ -66,12 +70,15 @@ class UserListSelectorActivity : BaseActivity(),
|
|||
setContentView(R.layout.activity_user_list_selector)
|
||||
|
||||
adapter = SimpleParcelableUserListsAdapter(this)
|
||||
adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.END
|
||||
listView.addFooterView(layoutInflater.inflate(R.layout.simple_list_item_activated_1,
|
||||
listView, false).apply {
|
||||
(findViewById(android.R.id.text1) as TextView).setText(R.string.action_select_user)
|
||||
}, SelectUserAction, true)
|
||||
listView.adapter = adapter
|
||||
listView.setOnScrollListener(ListViewScrollHandler(this, listView))
|
||||
val handler = ListViewScrollHandler(this, listView)
|
||||
listView.setOnScrollListener(handler)
|
||||
listView.setOnTouchListener(handler.touchListener)
|
||||
listView.onItemClickListener = OnItemClickListener { view, child, position, id ->
|
||||
val item = view.getItemAtPosition(position)
|
||||
when (item) {
|
||||
|
@ -124,15 +131,27 @@ class UserListSelectorActivity : BaseActivity(),
|
|||
override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableUserList>> {
|
||||
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
return UserListOwnershipsLoader(this, accountKey, userKey, null, adapter.all)
|
||||
val nextCursor = args.getLong(EXTRA_NEXT_CURSOR)
|
||||
return UserListOwnershipsLoader(this, accountKey, userKey, null, nextCursor, adapter.all)
|
||||
}
|
||||
|
||||
override fun onLoaderReset(loader: Loader<List<ParcelableUserList>>?) {
|
||||
adapter.setData(null)
|
||||
}
|
||||
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableUserList>>?, data: List<ParcelableUserList>?) {
|
||||
adapter.loadMoreIndicatorPosition = ILoadMoreSupportAdapter.NONE
|
||||
adapter.loadMoreSupportedPosition = if (adapter.all != data) {
|
||||
ILoadMoreSupportAdapter.END
|
||||
} else {
|
||||
ILoadMoreSupportAdapter.NONE
|
||||
}
|
||||
adapter.setData(data)
|
||||
refreshing = false
|
||||
if (loader is ICursorSupportLoader) {
|
||||
nextCursor = loader.nextCursor
|
||||
}
|
||||
showList()
|
||||
}
|
||||
|
||||
|
@ -144,19 +163,25 @@ class UserListSelectorActivity : BaseActivity(),
|
|||
return supportLoaderManager.hasRunningLoadersSafe()
|
||||
}
|
||||
set(value) {
|
||||
|
||||
}
|
||||
|
||||
override val reachingStart: Boolean
|
||||
get() = listView.firstVisiblePosition < 0
|
||||
override val reachingEnd: Boolean
|
||||
get() = listView.lastVisiblePosition > (listView.count + listView.headerViewsCount
|
||||
+ listView.footerViewsCount)
|
||||
get() = listView.firstVisiblePosition <= 0
|
||||
|
||||
override fun onLoadMoreContents(position: Long) {
|
||||
override val reachingEnd: Boolean
|
||||
get() = listView.lastVisiblePosition >= listView.count - 1
|
||||
|
||||
override fun onLoadMoreContents(@IndicatorPosition position: Long) {
|
||||
val accountKey = this.accountKey ?: return
|
||||
val userKey = this.userKey ?: return
|
||||
if (refreshing || position and adapter.loadMoreSupportedPosition == 0L) {
|
||||
return
|
||||
}
|
||||
adapter.loadMoreIndicatorPosition = position
|
||||
loadUserLists(accountKey, userKey, nextCursor)
|
||||
}
|
||||
|
||||
private fun loadUserLists(accountKey: UserKey, userKey: UserKey) {
|
||||
private fun loadUserLists(accountKey: UserKey, userKey: UserKey, nextCursor: Long = -1) {
|
||||
if (userKey != this.userKey) {
|
||||
adapter.clear()
|
||||
showProgress()
|
||||
|
@ -165,6 +190,7 @@ class UserListSelectorActivity : BaseActivity(),
|
|||
val args = Bundle {
|
||||
this[EXTRA_ACCOUNT_KEY] = accountKey
|
||||
this[EXTRA_USER_KEY] = userKey
|
||||
this[EXTRA_NEXT_CURSOR] = nextCursor
|
||||
}
|
||||
if (!loaderInitialized) {
|
||||
loaderInitialized = true
|
||||
|
|
|
@ -23,7 +23,10 @@ import android.content.Context
|
|||
import android.support.v4.text.BidiFormatter
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.twidere.adapter.iface.IContentAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.model.ItemCounts
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
import javax.inject.Inject
|
||||
|
@ -32,7 +35,8 @@ open class BaseArrayAdapter<T>(
|
|||
context: Context,
|
||||
layoutRes: Int,
|
||||
collection: Collection<T>? = null
|
||||
) : ArrayAdapter<T>(context, layoutRes, collection), IContentAdapter {
|
||||
) : ArrayAdapter<T>(context, layoutRes, collection), IContentAdapter, ILoadMoreSupportAdapter,
|
||||
IItemCountsAdapter {
|
||||
val linkify: TwidereLinkify
|
||||
|
||||
@Inject
|
||||
|
@ -54,6 +58,24 @@ open class BaseArrayAdapter<T>(
|
|||
final override val showAbsoluteTime: Boolean
|
||||
val nameFirst: Boolean
|
||||
|
||||
override val itemCounts: ItemCounts = ItemCounts(1)
|
||||
|
||||
@ILoadMoreSupportAdapter.IndicatorPosition
|
||||
override var loadMoreSupportedPosition: Long = 0
|
||||
set(value) {
|
||||
field = value
|
||||
loadMoreIndicatorPosition = ILoadMoreSupportAdapter.apply(loadMoreIndicatorPosition, value)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
@ILoadMoreSupportAdapter.IndicatorPosition
|
||||
override var loadMoreIndicatorPosition: Long = 0
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
field = ILoadMoreSupportAdapter.apply(value, loadMoreSupportedPosition)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
init {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
GeneralComponentHelper.build(context).inject(this as BaseArrayAdapter<Any>)
|
||||
|
@ -67,5 +89,4 @@ open class BaseArrayAdapter<T>(
|
|||
|
||||
override fun getItemCount(): Int = count
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class MessageEntriesAdapter(context: Context) : LoadMoreSupportAdapter<ViewHolde
|
|||
return MessageEntryViewHolder(this, view)
|
||||
}
|
||||
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent, false)
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ class ParcelableActivitiesAdapter(
|
|||
return GapViewHolder(this, view)
|
||||
}
|
||||
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent, false)
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
ITEM_VIEW_TYPE_STUB -> {
|
||||
|
|
|
@ -102,7 +102,7 @@ class ParcelableGroupsAdapter(context: Context) : LoadMoreSupportAdapter<Recycle
|
|||
return holder
|
||||
}
|
||||
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent, false)
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,7 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.Companion.ITE
|
|||
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
|
||||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_DISPLAY_SENSITIVE_CONTENTS
|
||||
import org.mariotaku.twidere.model.ObjectId
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.ParcelableStatusCursorIndices
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.util.MediaLoadingHandler
|
||||
import org.mariotaku.twidere.util.StatusAdapterLinkClickHandler
|
||||
import org.mariotaku.twidere.util.TwidereLinkify
|
||||
|
@ -112,7 +109,7 @@ abstract class ParcelableStatusesAdapter(
|
|||
private var showingActionCardId = RecyclerView.NO_ID
|
||||
private var lastItemFiltered: Boolean = false
|
||||
|
||||
override val itemCounts: IntArray = IntArray(4)
|
||||
override val itemCounts = ItemCounts(4)
|
||||
|
||||
protected abstract val progressViewIds: IntArray
|
||||
|
||||
|
@ -263,7 +260,7 @@ abstract class ParcelableStatusesAdapter(
|
|||
return GapViewHolder(this, view)
|
||||
}
|
||||
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent, false)
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
ITEM_VIEW_TYPE_EMPTY -> {
|
||||
|
@ -344,7 +341,7 @@ abstract class ParcelableStatusesAdapter(
|
|||
itemCounts[1] = pinnedStatuses?.size ?: 0
|
||||
itemCounts[2] = statusCount
|
||||
itemCounts[3] = if (position and ILoadMoreSupportAdapter.END != 0L) 1 else 0
|
||||
return itemCounts.sum()
|
||||
return itemCounts.itemCount
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ class ParcelableUserListsAdapter(
|
|||
return createUserListViewHolder(this, inflater, parent)
|
||||
}
|
||||
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent, false)
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ class ParcelableUsersAdapter(context: Context) : LoadMoreSupportAdapter<Recycler
|
|||
return createUserViewHolder(this, inflater, parent)
|
||||
}
|
||||
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent, false)
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.content.Context
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.model.ItemCounts
|
||||
import org.mariotaku.twidere.model.ParcelableUserList
|
||||
import org.mariotaku.twidere.util.view.display
|
||||
import org.mariotaku.twidere.view.holder.SimpleUserListViewHolder
|
||||
|
@ -31,21 +33,53 @@ class SimpleParcelableUserListsAdapter(
|
|||
context: Context
|
||||
) : BaseArrayAdapter<ParcelableUserList>(context, R.layout.list_item_simple_user_list) {
|
||||
|
||||
override val itemCounts: ItemCounts = ItemCounts(2)
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return (if (getItem(position) != null) getItem(position).hashCode() else -1).toLong()
|
||||
when (itemCounts.getItemCountIndex(position)) {
|
||||
0 -> {
|
||||
return getItem(position - itemCounts.getItemStartPosition(0)).hashCode().toLong()
|
||||
}
|
||||
1 -> {
|
||||
return Integer.MAX_VALUE + 1L
|
||||
}
|
||||
}
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val view = super.getView(position, convertView, parent)
|
||||
val tag = view.tag
|
||||
val holder = tag as? SimpleUserListViewHolder ?: run {
|
||||
val h = SimpleUserListViewHolder(view)
|
||||
view.tag = h
|
||||
return@run h
|
||||
when (getItemViewType(position)) {
|
||||
0 -> {
|
||||
val view = super.getView(position, convertView, parent)
|
||||
val holder = view.tag as? SimpleUserListViewHolder ?: run {
|
||||
val h = SimpleUserListViewHolder(view)
|
||||
view.tag = h
|
||||
return@run h
|
||||
}
|
||||
val userList = getItem(position)
|
||||
holder.display(userList, mediaLoader, userColorNameManager, profileImageEnabled)
|
||||
return view
|
||||
}
|
||||
1 -> {
|
||||
val view = createViewFromResource(position, convertView, parent, R.layout.list_item_load_indicator)
|
||||
return view
|
||||
}
|
||||
}
|
||||
val userList = getItem(position)
|
||||
holder.display(userList, mediaLoader, userColorNameManager, profileImageEnabled)
|
||||
return view
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return itemCounts.getItemCountIndex(position)
|
||||
}
|
||||
|
||||
override fun getViewTypeCount(): Int {
|
||||
return itemCounts.size
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
itemCounts[0] = super.getCount()
|
||||
itemCounts[1] = if (loadMoreIndicatorPosition and ILoadMoreSupportAdapter.END != 0L) 1 else 0
|
||||
return itemCounts.itemCount
|
||||
}
|
||||
|
||||
fun setData(data: List<ParcelableUserList>?) {
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
package org.mariotaku.twidere.adapter.iface;
|
||||
|
||||
import org.mariotaku.twidere.model.ItemCounts
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/8/19.
|
||||
*/
|
||||
interface IItemCountsAdapter {
|
||||
|
||||
val itemCounts: IntArray
|
||||
val itemCounts: ItemCounts
|
||||
|
||||
fun getItemCountIndex(position: Int): Int {
|
||||
var sum: Int = 0
|
||||
itemCounts.forEachIndexed { idx, count ->
|
||||
sum += count
|
||||
if (position < sum) {
|
||||
return idx
|
||||
}
|
||||
}
|
||||
return -1
|
||||
return itemCounts.getItemCountIndex(position)
|
||||
}
|
||||
|
||||
fun getItemStartPosition(index: Int): Int {
|
||||
return itemCounts.slice(0 until index).sum()
|
||||
return itemCounts.getItemStartPosition(index)
|
||||
}
|
||||
|
||||
}
|
|
@ -26,8 +26,10 @@ import android.support.annotation.IntDef
|
|||
*/
|
||||
interface ILoadMoreSupportAdapter {
|
||||
|
||||
@IndicatorPosition
|
||||
var loadMoreIndicatorPosition: Long
|
||||
|
||||
@IndicatorPosition
|
||||
var loadMoreSupportedPosition: Long
|
||||
|
||||
@IntDef(flag = true, value = *longArrayOf(NONE, START, END, BOTH))
|
||||
|
|
|
@ -5,15 +5,11 @@ import android.widget.ListView
|
|||
import org.mariotaku.ktextension.setItemAvailability
|
||||
import org.mariotaku.twidere.R
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/1/1.
|
||||
*/
|
||||
|
||||
|
||||
fun ListView.selectAll() {
|
||||
for (i in 0 until count) {
|
||||
setItemChecked(i, true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun ListView.selectNone() {
|
||||
|
@ -35,4 +31,4 @@ fun ListView.updateSelectionItems(menu: Menu) {
|
|||
menu.setItemAvailability(R.id.select_none, checkedCount > 0)
|
||||
menu.setItemAvailability(R.id.select_all, checkedCount < listCount)
|
||||
menu.setItemAvailability(R.id.invert_selection, checkedCount > 0 && checkedCount < listCount)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1687,7 +1687,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||
return ListParcelableStatusesAdapter.createStatusViewHolder(this, inflater, parent)
|
||||
}
|
||||
VIEW_TYPE_CONVERSATION_LOAD_INDICATOR, VIEW_TYPE_REPLIES_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent,
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent,
|
||||
false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
|
|
|
@ -37,12 +37,17 @@ import org.mariotaku.twidere.util.Utils
|
|||
|
||||
class UserListsOwnershipsFragment : ParcelableUserListsFragment() {
|
||||
|
||||
override fun onCreateUserListsLoader(context: Context,
|
||||
args: Bundle, fromUser: Boolean): Loader<List<ParcelableUserList>> {
|
||||
private val screenName: String?
|
||||
get() = arguments.getString(EXTRA_SCREEN_NAME)
|
||||
|
||||
private val userId: UserKey?
|
||||
get() = arguments.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
|
||||
override fun onCreateUserListsLoader(context: Context, args: Bundle, fromUser: Boolean): Loader<List<ParcelableUserList>> {
|
||||
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
return UserListOwnershipsLoader(activity, accountKey, userKey, screenName, data)
|
||||
return UserListOwnershipsLoader(activity, accountKey, userKey, screenName, nextCursor, data)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
|
@ -50,12 +55,12 @@ class UserListsOwnershipsFragment : ParcelableUserListsFragment() {
|
|||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||
inflater!!.inflate(R.menu.menu_user_lists_owned, menu)
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_user_lists_owned, menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
when (item!!.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.new_user_list -> {
|
||||
val f = CreateUserListDialogFragment()
|
||||
val args = Bundle()
|
||||
|
@ -68,22 +73,19 @@ class UserListsOwnershipsFragment : ParcelableUserListsFragment() {
|
|||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu?) {
|
||||
val item = menu!!.findItem(R.id.new_user_list)
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
val item = menu.findItem(R.id.new_user_list)
|
||||
val accountId = accountKey
|
||||
if (accountId == null || item == null) return
|
||||
if (accountId == userId) {
|
||||
MenuUtils.setItemAvailability(menu, R.id.new_user_list, true)
|
||||
} else {
|
||||
MenuUtils.setItemAvailability(menu, R.id.new_user_list, Utils.isMyAccount(activity, screenName))
|
||||
val screenName = this.screenName
|
||||
MenuUtils.setItemAvailability(menu, R.id.new_user_list, screenName != null &&
|
||||
Utils.isMyAccount(activity, screenName))
|
||||
}
|
||||
}
|
||||
|
||||
private val screenName: String
|
||||
get() = arguments.getString(EXTRA_SCREEN_NAME)
|
||||
|
||||
private val userId: UserKey
|
||||
get() = arguments.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
|
|
@ -336,7 +336,7 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment<Ba
|
|||
return holder
|
||||
}
|
||||
ILoadMoreSupportAdapter.ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.card_item_load_indicator, parent, false)
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import android.view.View
|
|||
import android.widget.TextView
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.ktextension.setItemAvailability
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.activity.AccountSelectorActivity
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.mariotaku.twidere.loader
|
|||
import android.content.Context
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.util.Log
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.CursorSupport
|
||||
|
@ -29,13 +30,17 @@ import org.mariotaku.microblog.library.twitter.model.PageableResponseList
|
|||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.UserList
|
||||
import org.mariotaku.twidere.TwidereConstants.LOGTAG
|
||||
import org.mariotaku.twidere.constant.loadItemLimitKey
|
||||
import org.mariotaku.twidere.loader.iface.ICursorSupportLoader
|
||||
import org.mariotaku.twidere.model.ParcelableUserList
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserListUtils
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper
|
||||
import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
abstract class BaseUserListsLoader(
|
||||
|
@ -44,6 +49,8 @@ abstract class BaseUserListsLoader(
|
|||
override val cursor: Long,
|
||||
data: List<ParcelableUserList>?
|
||||
) : AsyncTaskLoader<List<ParcelableUserList>>(context), ICursorSupportLoader {
|
||||
@Inject
|
||||
lateinit var preferences: SharedPreferencesWrapper
|
||||
|
||||
protected val data = NoDuplicatesArrayList<ParcelableUserList>()
|
||||
|
||||
|
@ -51,6 +58,7 @@ abstract class BaseUserListsLoader(
|
|||
override var prevCursor: Long = 0
|
||||
|
||||
init {
|
||||
GeneralComponentHelper.build(context).inject(this)
|
||||
if (data != null) {
|
||||
this.data.addAll(data)
|
||||
}
|
||||
|
@ -64,6 +72,7 @@ abstract class BaseUserListsLoader(
|
|||
var listLoaded: List<UserList>? = null
|
||||
try {
|
||||
val paging = Paging()
|
||||
paging.count(preferences[loadItemLimitKey].coerceIn(0, 100))
|
||||
if (cursor > 0) {
|
||||
paging.cursor(cursor)
|
||||
}
|
||||
|
|
|
@ -32,8 +32,9 @@ class UserListOwnershipsLoader(
|
|||
accountKey: UserKey,
|
||||
private val userKey: UserKey?,
|
||||
private val screenName: String?,
|
||||
nextCursor: Long,
|
||||
data: List<ParcelableUserList>?
|
||||
) : BaseUserListsLoader(context, accountKey, 0, data) {
|
||||
) : BaseUserListsLoader(context, accountKey, nextCursor, data) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getUserLists(twitter: MicroBlog, paging: Paging): List<UserList> {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package org.mariotaku.twidere.model
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 11/22/16.
|
||||
*/
|
||||
|
||||
class ItemCounts(counts: Int) {
|
||||
private val data: IntArray = IntArray(counts)
|
||||
|
||||
fun getItemCountIndex(itemPosition: Int): Int {
|
||||
var sum = 0
|
||||
for (i in data.indices) {
|
||||
sum += data[i]
|
||||
if (itemPosition < sum) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
fun getItemStartPosition(countIndex: Int): Int {
|
||||
var sum = 0
|
||||
for (i in 0..countIndex - 1) {
|
||||
sum += data[i]
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
val itemCount: Int get() = data.sum()
|
||||
|
||||
val size: Int get() = data.size
|
||||
|
||||
operator fun set(countIndex: Int, value: Int) {
|
||||
data[countIndex] = value
|
||||
}
|
||||
|
||||
}
|
|
@ -74,10 +74,10 @@ open class ContentScrollHandler<A>(
|
|||
if (!contentListSupport.refreshing && adapter.loadMoreSupportedPosition != ILoadMoreSupportAdapter.NONE
|
||||
&& adapter.loadMoreIndicatorPosition == ILoadMoreSupportAdapter.NONE) {
|
||||
var position: Long = 0
|
||||
if (contentListSupport.reachingEnd && scrollDirection >= 0) {
|
||||
if (contentListSupport.reachingEnd && scrollDirection > 0) {
|
||||
position = position or ILoadMoreSupportAdapter.END
|
||||
}
|
||||
if (contentListSupport.reachingStart && scrollDirection <= 0) {
|
||||
if (contentListSupport.reachingStart && scrollDirection < 0) {
|
||||
position = position or ILoadMoreSupportAdapter.START
|
||||
}
|
||||
resetScrollDirection()
|
||||
|
|
|
@ -28,10 +28,7 @@ import org.mariotaku.twidere.adapter.*
|
|||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
import org.mariotaku.twidere.fragment.*
|
||||
import org.mariotaku.twidere.fragment.filter.FilteredUsersFragment
|
||||
import org.mariotaku.twidere.loader.CacheUserSearchLoader
|
||||
import org.mariotaku.twidere.loader.MicroBlogAPIStatusesLoader
|
||||
import org.mariotaku.twidere.loader.ParcelableStatusLoader
|
||||
import org.mariotaku.twidere.loader.ParcelableUserLoader
|
||||
import org.mariotaku.twidere.loader.*
|
||||
import org.mariotaku.twidere.preference.AccountsListPreference
|
||||
import org.mariotaku.twidere.preference.KeyboardShortcutPreference
|
||||
import org.mariotaku.twidere.preference.PremiumEntryPreference
|
||||
|
@ -153,4 +150,6 @@ interface GeneralComponent {
|
|||
fun inject(preference: PremiumEntryPreference)
|
||||
|
||||
fun inject(loader: CacheUserSearchLoader)
|
||||
|
||||
fun inject(loader: BaseUserListsLoader)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue