code cleanup
This commit is contained in:
parent
deb93d5049
commit
1879d2d9be
|
@ -103,6 +103,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.*
|
|||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.ContentScrollHandler.ContentListSupport
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback
|
||||
import org.mariotaku.twidere.util.RecyclerViewScrollHandler.RecyclerViewCallback
|
||||
import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener
|
||||
import org.mariotaku.twidere.view.ExtendedRecyclerView
|
||||
import org.mariotaku.twidere.view.holder.GapViewHolder
|
||||
|
@ -121,19 +122,18 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
private var mItemDecoration: DividerItemDecoration? = null
|
||||
|
||||
override lateinit var adapter: StatusAdapter
|
||||
private set
|
||||
|
||||
private var layoutManager: LinearLayoutManager? = null
|
||||
private lateinit var layoutManager: LinearLayoutManager
|
||||
private lateinit var navigationHelper: RecyclerViewNavigationHelper
|
||||
private lateinit var scrollListener: RecyclerViewScrollHandler
|
||||
|
||||
private var loadTranslationTask: LoadTranslationTask? = null
|
||||
|
||||
private var navigationHelper: RecyclerViewNavigationHelper? = null
|
||||
private var scrollListener: RecyclerViewScrollHandler? = null
|
||||
// Data fields
|
||||
private var conversationLoaderInitialized: Boolean = false
|
||||
|
||||
private var mActivityLoaderInitialized: Boolean = false
|
||||
private var hasMoreConversation = true
|
||||
private var mStatusEvent: TweetEvent? = null
|
||||
private var statusEvent: TweetEvent? = null
|
||||
// Listeners
|
||||
private val conversationsLoaderCallback = object : LoaderCallbacks<List<ParcelableStatus>> {
|
||||
override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableStatus>> {
|
||||
|
@ -256,36 +256,32 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater!!.inflate(R.layout.fragment_status, container, false)
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_status, container, false)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
val view = view!!
|
||||
val context = view.context
|
||||
Utils.setNdefPushMessageCallback(activity, CreateNdefMessageCallback {
|
||||
val status = status ?: return@CreateNdefMessageCallback null
|
||||
NdefMessage(arrayOf(NdefRecord.createUri(LinkCreator.getStatusWebLink(status))))
|
||||
})
|
||||
adapter = StatusAdapter(this)
|
||||
layoutManager = StatusListLinearLayoutManager(context, recyclerView)
|
||||
mItemDecoration = StatusDividerItemDecoration(context, adapter, layoutManager!!.orientation)
|
||||
mItemDecoration = StatusDividerItemDecoration(context, adapter, layoutManager.orientation)
|
||||
recyclerView.addItemDecoration(mItemDecoration)
|
||||
layoutManager!!.recycleChildrenOnDetach = true
|
||||
layoutManager.recycleChildrenOnDetach = true
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.clipToPadding = false
|
||||
adapter.statusClickListener = this
|
||||
recyclerView.adapter = adapter
|
||||
registerForContextMenu(recyclerView!!)
|
||||
registerForContextMenu(recyclerView)
|
||||
|
||||
scrollListener = RecyclerViewScrollHandler(this,
|
||||
RecyclerViewScrollHandler.RecyclerViewCallback(recyclerView))
|
||||
scrollListener!!.touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
scrollListener = RecyclerViewScrollHandler(this, RecyclerViewCallback(recyclerView))
|
||||
scrollListener.touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
|
||||
navigationHelper = RecyclerViewNavigationHelper(recyclerView!!, layoutManager!!,
|
||||
navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager,
|
||||
adapter, null)
|
||||
|
||||
setState(STATE_LOADING)
|
||||
|
@ -324,14 +320,13 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
|
||||
override fun onItemMenuClick(holder: ViewHolder, menuView: View, position: Int) {
|
||||
if (activity == null) return
|
||||
val view = layoutManager!!.findViewByPosition(position) ?: return
|
||||
val view = layoutManager.findViewByPosition(position) ?: return
|
||||
recyclerView.showContextMenuForChild(view)
|
||||
}
|
||||
|
||||
override fun onUserProfileClick(holder: IStatusViewHolder, position: Int) {
|
||||
val activity = activity
|
||||
val status = adapter.getStatus(position)
|
||||
IntentUtils.openUserProfile(activity, status!!.account_key, status.user_key,
|
||||
val status = adapter.getStatus(position)!!
|
||||
IntentUtils.openUserProfile(activity, status.account_key, status.user_key,
|
||||
status.user_screen_name, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API),
|
||||
Referral.TIMELINE_STATUS)
|
||||
}
|
||||
|
@ -352,10 +347,10 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
keyCode: Int, event: KeyEvent,
|
||||
metaState: Int): Boolean {
|
||||
if (!KeyboardShortcutsHandler.isValidForHotkey(keyCode, event)) return false
|
||||
val focusedChild = RecyclerViewUtils.findRecyclerViewChild(recyclerView, layoutManager!!.focusedChild)
|
||||
val focusedChild = RecyclerViewUtils.findRecyclerViewChild(recyclerView, layoutManager.focusedChild)
|
||||
val position: Int
|
||||
if (focusedChild != null && focusedChild.parent === recyclerView) {
|
||||
position = recyclerView!!.getChildLayoutPosition(focusedChild)
|
||||
position = recyclerView.getChildLayoutPosition(focusedChild)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
@ -391,13 +386,13 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
when (action) {
|
||||
ACTION_STATUS_REPLY, ACTION_STATUS_RETWEET, ACTION_STATUS_FAVORITE -> return true
|
||||
}
|
||||
return navigationHelper!!.isKeyboardShortcutHandled(handler, keyCode, event, metaState)
|
||||
return navigationHelper.isKeyboardShortcutHandled(handler, keyCode, event, metaState)
|
||||
}
|
||||
|
||||
override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler,
|
||||
keyCode: Int, repeatCount: Int,
|
||||
event: KeyEvent, metaState: Int): Boolean {
|
||||
return navigationHelper!!.handleKeyboardShortcutRepeat(handler, keyCode,
|
||||
return navigationHelper.handleKeyboardShortcutRepeat(handler, keyCode,
|
||||
repeatCount, event, metaState)
|
||||
}
|
||||
|
||||
|
@ -429,13 +424,13 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
|
||||
val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
layoutManager!!.scrollToPositionWithOffset(position, 0)
|
||||
layoutManager.scrollToPositionWithOffset(position, 0)
|
||||
}
|
||||
|
||||
val event = TweetEvent.create(activity, status, TimelineType.OTHER)
|
||||
event.action = TweetEvent.Action.OPEN
|
||||
event.isHasTranslateFeature = Utils.isOfficialCredentials(context, details)
|
||||
mStatusEvent = event
|
||||
statusEvent = event
|
||||
} else if (readPosition != null) {
|
||||
restoreReadPosition(readPosition)
|
||||
}
|
||||
|
@ -449,27 +444,27 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
override fun onLoaderReset(loader: Loader<SingleResponse<ParcelableStatus>>) {
|
||||
val event = mStatusEvent ?: return
|
||||
val event = statusEvent ?: return
|
||||
event.markEnd()
|
||||
val accountKey = UserKey(event.accountId, event.accountHost)
|
||||
HotMobiLogger.getInstance(activity).log(accountKey, event)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||
inflater!!.inflate(R.menu.menu_status, menu)
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_status, menu)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu?) {
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
MenuUtils.setItemAvailability(menu, R.id.current_status, adapter.status != null)
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
when (item!!.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.current_status -> {
|
||||
if (adapter.status != null) {
|
||||
val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
|
||||
recyclerView!!.smoothScrollToPosition(position)
|
||||
recyclerView.smoothScrollToPosition(position)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -507,10 +502,10 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
override val reachingEnd: Boolean
|
||||
get() = layoutManager!!.findLastCompletelyVisibleItemPosition() >= adapter.itemCount - 1
|
||||
get() = layoutManager.findLastCompletelyVisibleItemPosition() >= adapter.itemCount - 1
|
||||
|
||||
override val reachingStart: Boolean
|
||||
get() = layoutManager!!.findFirstCompletelyVisibleItemPosition() <= 1
|
||||
get() = layoutManager.findFirstCompletelyVisibleItemPosition() <= 1
|
||||
|
||||
private val status: ParcelableStatus?
|
||||
get() = adapter.status
|
||||
|
@ -566,7 +561,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
private fun saveReadPosition(): ReadPosition? {
|
||||
val lm = layoutManager ?: return null
|
||||
val lm = layoutManager
|
||||
val adapter = this.adapter
|
||||
val position = lm.findFirstVisibleItemPosition()
|
||||
if (position == RecyclerView.NO_POSITION) return null
|
||||
|
@ -589,7 +584,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
val adapterPosition = adapter.findPositionByItemId(position.statusId)
|
||||
if (adapterPosition < 0) return
|
||||
//TODO maintain read position
|
||||
layoutManager!!.scrollToPositionWithOffset(adapterPosition, position.offsetTop)
|
||||
layoutManager.scrollToPositionWithOffset(adapterPosition, position.offsetTop)
|
||||
}
|
||||
|
||||
private fun setState(state: Int) {
|
||||
|
@ -605,30 +600,29 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
override fun onStart() {
|
||||
super.onStart()
|
||||
bus.register(this)
|
||||
recyclerView!!.addOnScrollListener(scrollListener)
|
||||
recyclerView!!.setOnTouchListener(scrollListener!!.touchListener)
|
||||
recyclerView.addOnScrollListener(scrollListener)
|
||||
recyclerView.setOnTouchListener(scrollListener.touchListener)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
recyclerView.setOnTouchListener(null)
|
||||
recyclerView!!.removeOnScrollListener(scrollListener)
|
||||
recyclerView.removeOnScrollListener(scrollListener)
|
||||
bus.unregister(this)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
|
||||
if (!userVisibleHint || menuInfo == null) return
|
||||
if (!userVisibleHint) return
|
||||
val contextMenuInfo = menuInfo as? ExtendedRecyclerView.ContextMenuInfo ?: return
|
||||
val status = adapter.getStatus(contextMenuInfo.position) ?: return
|
||||
val inflater = MenuInflater(context)
|
||||
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
|
||||
val status = adapter.getStatus(contextMenuInfo!!.position)
|
||||
inflater.inflate(R.menu.action_status, menu)
|
||||
MenuUtils.setupForStatus(context, preferences, menu, status!!,
|
||||
twitterWrapper)
|
||||
MenuUtils.setupForStatus(context, preferences, menu, status, twitterWrapper)
|
||||
}
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem?): Boolean {
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
if (!userVisibleHint) return false
|
||||
val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo
|
||||
val contextMenuInfo = item.menuInfo as? ExtendedRecyclerView.ContextMenuInfo ?: return false
|
||||
val status = adapter.getStatus(contextMenuInfo.position) ?: return false
|
||||
if (item.itemId == R.id.share) {
|
||||
val shareIntent = Utils.createStatusShareIntent(activity, status)
|
||||
|
|
Loading…
Reference in New Issue