cleaned up code

This commit is contained in:
Mariotaku Lee 2016-12-08 22:56:21 +08:00
parent 963ff1c3ca
commit b6a0abe5dc
20 changed files with 82 additions and 140 deletions

View File

@ -42,7 +42,7 @@ import org.mariotaku.twidere.model.util.AccountUtils
class AccountSelectorActivity : BaseActivity(), OnClickListener, OnItemClickListener { class AccountSelectorActivity : BaseActivity(), OnClickListener, OnItemClickListener {
private var adapter: AccountDetailsAdapter? = null private lateinit var adapter: AccountDetailsAdapter
private var firstCreated: Boolean = false private var firstCreated: Boolean = false
@ -136,7 +136,6 @@ class AccountSelectorActivity : BaseActivity(), OnClickListener, OnItemClickList
} }
fun selectSingleAccount(position: Int) { fun selectSingleAccount(position: Int) {
val adapter = adapter!!
val account = adapter.getItem(position) val account = adapter.getItem(position)
val data = Intent() val data = Intent()
data.putExtra(EXTRA_ID, account.key.id) data.putExtra(EXTRA_ID, account.key.id)

View File

@ -217,14 +217,10 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
} }
protected fun saveReadPosition() { protected fun saveReadPosition() {
val layoutManager = layoutManager
if (layoutManager != null) {
saveReadPosition(layoutManager.findFirstVisibleItemPosition()) saveReadPosition(layoutManager.findFirstVisibleItemPosition())
} }
}
override fun onLoadFinished(loader: Loader<List<ParcelableActivity>>, data: List<ParcelableActivity>) { override fun onLoadFinished(loader: Loader<List<ParcelableActivity>>, data: List<ParcelableActivity>) {
val adapter = adapter
val rememberPosition = preferences.getBoolean(KEY_REMEMBER_POSITION, false) val rememberPosition = preferences.getBoolean(KEY_REMEMBER_POSITION, false)
val readFromBottom = preferences.getBoolean(KEY_READ_FROM_BOTTOM, false) val readFromBottom = preferences.getBoolean(KEY_READ_FROM_BOTTOM, false)
var lastReadId: Long var lastReadId: Long
@ -315,7 +311,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
} }
override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, position: Int) { override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, position: Int) {
val adapter = adapter
val status = adapter.getActivity(position)?.getActivityStatus() ?: return val status = adapter.getActivity(position)?.getActivityStatus() ?: return
IntentUtils.openMedia(activity, status, media, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API)) IntentUtils.openMedia(activity, status, media, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API))
// BEGIN HotMobi // BEGIN HotMobi
@ -435,7 +430,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
scrollListener!!.reversed = preferences.getBoolean(KEY_READ_FROM_BOTTOM) scrollListener!!.reversed = preferences.getBoolean(KEY_READ_FROM_BOTTOM)
val adapter = adapter
val layoutManager = layoutManager val layoutManager = layoutManager
adapter.setListener(this) adapter.setListener(this)
registerForContextMenu(recyclerView) registerForContextMenu(recyclerView)
@ -452,7 +446,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
override val reachingEnd: Boolean override val reachingEnd: Boolean
get() { get() {
val lm = layoutManager val lm = layoutManager
val adapter = adapter
val lastPosition = lm.findLastCompletelyVisibleItemPosition() val lastPosition = lm.findLastCompletelyVisibleItemPosition()
val itemCount = adapter.itemCount val itemCount = adapter.itemCount
var finalPos = itemCount - 1 var finalPos = itemCount - 1
@ -520,7 +513,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
if (!userVisibleHint || menuInfo == null) return if (!userVisibleHint || menuInfo == null) return
val adapter = adapter
val inflater = MenuInflater(context) val inflater = MenuInflater(context)
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo? val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
val position = contextMenuInfo!!.position val position = contextMenuInfo!!.position
@ -534,10 +526,9 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
} }
} }
override fun onContextItemSelected(item: MenuItem?): Boolean { override fun onContextItemSelected(item: MenuItem): Boolean {
if (!userVisibleHint) return false if (!userVisibleHint) return false
val adapter = adapter val contextMenuInfo = item.menuInfo as ExtendedRecyclerView.ContextMenuInfo
val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo
val position = contextMenuInfo.position val position = contextMenuInfo.position
when (adapter.getItemViewType(position)) { when (adapter.getItemViewType(position)) {
@ -559,7 +550,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
override fun createItemDecoration(context: Context, recyclerView: RecyclerView, override fun createItemDecoration(context: Context, recyclerView: RecyclerView,
layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? { layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? {
val adapter = adapter
val itemDecoration = object : DividerItemDecoration(context, val itemDecoration = object : DividerItemDecoration(context,
(recyclerView.layoutManager as LinearLayoutManager).orientation) { (recyclerView.layoutManager as LinearLayoutManager).orientation) {
override fun isDividerEnabled(childPos: Int): Boolean { override fun isDividerEnabled(childPos: Int): Boolean {

View File

@ -42,12 +42,12 @@ import org.mariotaku.twidere.util.TwidereColorUtils
* Created by mariotaku on 15/4/16. * Created by mariotaku on 15/4/16.
*/ */
abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment(), OnRefreshListener, RefreshScrollTopInterface, ControlBarOffsetListener, ContentListSupport, AbsListView.OnScrollListener { abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment(), OnRefreshListener, RefreshScrollTopInterface, ControlBarOffsetListener, ContentListSupport, AbsListView.OnScrollListener {
private var scrollHandler: ListViewScrollHandler? = null private lateinit var scrollHandler: ListViewScrollHandler
override var adapter: A? = null override lateinit var adapter: A
// Data fields // Data fields
private val mSystemWindowsInsets = Rect() private val systemWindowsInsets = Rect()
override fun onControlBarOffsetChanged(activity: IControlBarActivity, offset: Float) { override fun onControlBarOffsetChanged(activity: IControlBarActivity, offset: Float) {
updateRefreshProgressOffset() updateRefreshProgressOffset()
@ -128,9 +128,10 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment
} }
listView.adapter = adapter listView.adapter = adapter
listView.clipToPadding = false listView.clipToPadding = false
scrollHandler = ListViewScrollHandler(this, ListViewScrollHandler.ListViewCallback(listView)) scrollHandler = ListViewScrollHandler(this, ListViewScrollHandler.ListViewCallback(listView)).apply {
scrollHandler!!.touchSlop = ViewConfiguration.get(context).scaledTouchSlop this.touchSlop = ViewConfiguration.get(context).scaledTouchSlop
scrollHandler!!.onScrollListener = this this.onScrollListener = this@AbsContentListViewFragment
}
} }
@ -148,7 +149,7 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment
listView.setPadding(insets.left, insets.top, insets.right, insets.bottom) listView.setPadding(insets.left, insets.top, insets.right, insets.bottom)
errorContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom) errorContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom)
progressContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom) progressContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom)
mSystemWindowsInsets.set(insets) systemWindowsInsets.set(insets)
updateRefreshProgressOffset() updateRefreshProgressOffset()
} }
@ -192,14 +193,14 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment
protected fun updateRefreshProgressOffset() { protected fun updateRefreshProgressOffset() {
val activity = activity val activity = activity
if (activity !is IControlBarActivity || mSystemWindowsInsets.top == 0 || swipeLayout == null if (activity !is IControlBarActivity || systemWindowsInsets.top == 0 || swipeLayout == null
|| refreshing) { || refreshing) {
return return
} }
val density = resources.displayMetrics.density val density = resources.displayMetrics.density
val progressCircleDiameter = swipeLayout.progressCircleDiameter val progressCircleDiameter = swipeLayout.progressCircleDiameter
val controlBarOffsetPixels = Math.round(activity.controlBarHeight * (1 - activity.controlBarOffset)) val controlBarOffsetPixels = Math.round(activity.controlBarHeight * (1 - activity.controlBarOffset))
val swipeStart = mSystemWindowsInsets.top - controlBarOffsetPixels - progressCircleDiameter val swipeStart = systemWindowsInsets.top - controlBarOffsetPixels - progressCircleDiameter
// 64: SwipeRefreshLayout.DEFAULT_CIRCLE_TARGET // 64: SwipeRefreshLayout.DEFAULT_CIRCLE_TARGET
val swipeDistance = Math.round(64 * density) val swipeDistance = Math.round(64 * density)
swipeLayout.setProgressViewOffset(false, swipeStart, swipeStart + swipeDistance) swipeLayout.setProgressViewOffset(false, swipeStart, swipeStart + swipeDistance)

View File

@ -170,7 +170,6 @@ abstract class AbsStatusesFragment protected constructor() :
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
scrollListener?.reversed = preferences.getBoolean(SharedPreferenceConstants.KEY_READ_FROM_BOTTOM) scrollListener?.reversed = preferences.getBoolean(SharedPreferenceConstants.KEY_READ_FROM_BOTTOM)
val adapter = adapter
adapter.statusClickListener = this adapter.statusClickListener = this
registerForContextMenu(recyclerView) registerForContextMenu(recyclerView)
navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter, this) navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter, this)
@ -223,7 +222,6 @@ abstract class AbsStatusesFragment protected constructor() :
} }
override fun onDestroy() { override fun onDestroy() {
val adapter = adapter
adapter.statusClickListener = null adapter.statusClickListener = null
super.onDestroy() super.onDestroy()
} }
@ -316,7 +314,6 @@ abstract class AbsStatusesFragment protected constructor() :
} }
override fun onLoadFinished(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) { override fun onLoadFinished(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) {
val adapter = adapter
val rememberPosition = preferences.getBoolean(SharedPreferenceConstants.KEY_REMEMBER_POSITION, false) val rememberPosition = preferences.getBoolean(SharedPreferenceConstants.KEY_REMEMBER_POSITION, false)
val readFromBottom = preferences.getBoolean(SharedPreferenceConstants.KEY_READ_FROM_BOTTOM, false) val readFromBottom = preferences.getBoolean(SharedPreferenceConstants.KEY_READ_FROM_BOTTOM, false)
var lastReadPositionKey: Long var lastReadPositionKey: Long
@ -410,7 +407,6 @@ abstract class AbsStatusesFragment protected constructor() :
} }
override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, statusPosition: Int) { override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, statusPosition: Int) {
val adapter = adapter
val status = adapter.getStatus(statusPosition) ?: return val status = adapter.getStatus(statusPosition) ?: return
IntentUtils.openMedia(activity, status, media, null, IntentUtils.openMedia(activity, status, media, null,
preferences.getBoolean(SharedPreferenceConstants.KEY_NEW_DOCUMENT_API)) preferences.getBoolean(SharedPreferenceConstants.KEY_NEW_DOCUMENT_API))
@ -422,16 +418,12 @@ abstract class AbsStatusesFragment protected constructor() :
} }
override fun onItemActionClick(holder: RecyclerView.ViewHolder, id: Int, position: Int) { override fun onItemActionClick(holder: RecyclerView.ViewHolder, id: Int, position: Int) {
val context = context ?: return
val adapter = adapter
val status = adapter.getStatus(position) ?: return val status = adapter.getStatus(position) ?: return
handleStatusActionClick(context, fragmentManager, twitterWrapper, holder as StatusViewHolder, status, id) handleStatusActionClick(context, fragmentManager, twitterWrapper, holder as StatusViewHolder, status, id)
} }
override fun createItemDecoration(context: Context, recyclerView: RecyclerView, layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? { override fun createItemDecoration(context: Context, recyclerView: RecyclerView, layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? {
val adapter = adapter val itemDecoration = DividerItemDecoration(context, (recyclerView.layoutManager as LinearLayoutManager).orientation)
val itemDecoration = DividerItemDecoration(context,
(recyclerView.layoutManager as LinearLayoutManager).orientation)
val res = context.resources val res = context.resources
if (adapter.profileImageEnabled) { if (adapter.profileImageEnabled) {
val decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 2 + res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image) val decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 2 + res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image)
@ -511,7 +503,6 @@ abstract class AbsStatusesFragment protected constructor() :
protected fun saveReadPosition(position: Int) { protected fun saveReadPosition(position: Int) {
if (host == null) return if (host == null) return
if (position == RecyclerView.NO_POSITION) return if (position == RecyclerView.NO_POSITION) return
val adapter = adapter
val status = adapter.getStatus(position) ?: return val status = adapter.getStatus(position) ?: return
val positionKey = if (status.position_key > 0) status.position_key else status.timestamp val positionKey = if (status.position_key > 0) status.position_key else status.timestamp
readPositionTagWithArguments?.let { readPositionTagWithArguments?.let {
@ -534,7 +525,6 @@ abstract class AbsStatusesFragment protected constructor() :
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
if (!userVisibleHint || menuInfo == null) return if (!userVisibleHint || menuInfo == null) return
val adapter = adapter
val inflater = MenuInflater(context) val inflater = MenuInflater(context)
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo? val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
val status = adapter.getStatus(contextMenuInfo!!.position) val status = adapter.getStatus(contextMenuInfo!!.position)
@ -542,9 +532,9 @@ abstract class AbsStatusesFragment protected constructor() :
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 if (!userVisibleHint) return false
val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo val contextMenuInfo = item.menuInfo as ExtendedRecyclerView.ContextMenuInfo
val status = adapter.getStatus(contextMenuInfo.position) ?: return false val status = adapter.getStatus(contextMenuInfo.position) ?: return false
if (item.itemId == R.id.share) { if (item.itemId == R.id.share) {
val shareIntent = Utils.createStatusShareIntent(activity, status) val shareIntent = Utils.createStatusShareIntent(activity, status)

View File

@ -169,7 +169,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
} }
override fun onLoadFinished(loader: Loader<Cursor?>, data: Cursor?) { override fun onLoadFinished(loader: Loader<Cursor?>, data: Cursor?) {
val adapter = adapter
adapter!!.swapCursor(data) adapter!!.swapCursor(data)
if (data != null && data.count > 0) { if (data != null && data.count > 0) {
showContent() showContent()
@ -179,7 +178,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
} }
override fun onLoaderReset(loader: Loader<Cursor?>) { override fun onLoaderReset(loader: Loader<Cursor?>) {
val adapter = adapter
adapter!!.swapCursor(null) adapter!!.swapCursor(null)
} }
@ -254,15 +252,15 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
val autoCompleteType: Int val autoCompleteType: Int
autoCompleteType = args.getInt(EXTRA_AUTO_COMPLETE_TYPE, 0) autoCompleteType = args.getInt(EXTRA_AUTO_COMPLETE_TYPE, 0)
if (autoCompleteType != 0) { if (autoCompleteType != 0) {
val mUserAutoCompleteAdapter: SimpleCursorAdapter val userAutoCompleteAdapter: SimpleCursorAdapter
if (autoCompleteType == AUTO_COMPLETE_TYPE_SOURCES) { if (autoCompleteType == AUTO_COMPLETE_TYPE_SOURCES) {
mUserAutoCompleteAdapter = SourceAutoCompleteAdapter(activity) userAutoCompleteAdapter = SourceAutoCompleteAdapter(activity)
} else { } else {
val adapter = ComposeAutoCompleteAdapter(activity) val adapter = ComposeAutoCompleteAdapter(activity)
adapter.accountKey = Utils.getDefaultAccountKey(activity) adapter.accountKey = Utils.getDefaultAccountKey(activity)
mUserAutoCompleteAdapter = adapter userAutoCompleteAdapter = adapter
} }
editText.setAdapter(mUserAutoCompleteAdapter) editText.setAdapter(userAutoCompleteAdapter)
editText.threshold = 1 editText.threshold = 1
} }
} }

View File

@ -55,7 +55,6 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
override fun onLoadingFinished() { override fun onLoadingFinished() {
val accountKeys = accountKeys val accountKeys = accountKeys
val adapter = adapter
if (adapter.itemCount > 0) { if (adapter.itemCount > 0) {
showContent() showContent()
} else if (accountKeys.isNotEmpty()) { } else if (accountKeys.isNotEmpty()) {
@ -100,7 +99,6 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
} }
val expression = processWhere(where, accountSelectionArgs) val expression = processWhere(where, accountSelectionArgs)
val selection = expression.sql val selection = expression.sql
val adapter = adapter
adapter.showAccountsColor = accountKeys.size > 1 adapter.showAccountsColor = accountKeys.size > 1
val projection = Activities.COLUMNS val projection = Activities.COLUMNS
return CursorActivitiesLoader(context, uri, projection, selection, expression.parameters, return CursorActivitiesLoader(context, uri, projection, selection, expression.parameters,
@ -258,7 +256,6 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
fun replaceStatusStates(result: ParcelableStatus?) { fun replaceStatusStates(result: ParcelableStatus?) {
if (result == null) return if (result == null) return
val lm = layoutManager val lm = layoutManager
val adapter = adapter
val rangeStart = Math.max(adapter.activityStartIndex, lm.findFirstVisibleItemPosition()) val rangeStart = Math.max(adapter.activityStartIndex, lm.findFirstVisibleItemPosition())
val rangeEnd = Math.min(lm.findLastVisibleItemPosition(), adapter.activityStartIndex + adapter.activityCount - 1) val rangeEnd = Math.min(lm.findLastVisibleItemPosition(), adapter.activityStartIndex + adapter.activityCount - 1)
loop@ for (i in rangeStart..rangeEnd) { loop@ for (i in rangeStart..rangeEnd) {

View File

@ -27,14 +27,12 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.support.v4.content.Loader import android.support.v4.content.Loader
import android.util.Log
import com.squareup.otto.Subscribe import com.squareup.otto.Subscribe
import kotlinx.android.synthetic.main.fragment_content_recyclerview.* import kotlinx.android.synthetic.main.fragment_content_recyclerview.*
import org.mariotaku.sqliteqb.library.ArgsArray import org.mariotaku.sqliteqb.library.ArgsArray
import org.mariotaku.sqliteqb.library.Columns.Column import org.mariotaku.sqliteqb.library.Columns.Column
import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.LOGTAG
import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition
@ -86,7 +84,6 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
} else { } else {
where = accountWhere where = accountWhere
} }
val adapter = adapter
adapter.showAccountsColor = accountKeys.size > 1 adapter.showAccountsColor = accountKeys.size > 1
val projection = Statuses.COLUMNS val projection = Statuses.COLUMNS
val selectionArgs = Array(accountKeys.size) { val selectionArgs = Array(accountKeys.size) {
@ -103,8 +100,7 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
private fun showContentOrError() { private fun showContentOrError() {
val accountKeys = accountKeys val accountKeys = this.accountKeys
val adapter = adapter
if (adapter.itemCount > 0) { if (adapter.itemCount > 0) {
showContent() showContent()
} else if (accountKeys.isNotEmpty()) { } else if (accountKeys.isNotEmpty()) {
@ -270,7 +266,6 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
val status = event.status val status = event.status
val data = adapterData val data = adapterData
if (status == null || data == null || data.isEmpty()) return if (status == null || data == null || data.isEmpty()) return
val adapter = adapter
val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition() val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition()
val lastVisiblePosition = layoutManager.findLastVisibleItemPosition() val lastVisiblePosition = layoutManager.findLastVisibleItemPosition()
val startIndex = adapter.statusStartIndex val startIndex = adapter.statusStartIndex

View File

@ -73,7 +73,7 @@ import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder
class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, MultiChoiceModeListener { class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, MultiChoiceModeListener {
private var adapter: CustomTabsAdapter? = null private lateinit var adapter: CustomTabsAdapter
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
@ -95,7 +95,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL
listView.setMultiChoiceModeListener(this) listView.setMultiChoiceModeListener(this)
listView.onItemClickListener = OnItemClickListener { parent, view, position, id -> listView.onItemClickListener = OnItemClickListener { parent, view, position, id ->
val tab = adapter!!.getTab(position) val tab = adapter.getTab(position)
val df = TabEditorDialogFragment() val df = TabEditorDialogFragment()
df.arguments = Bundle { df.arguments = Bundle {
this[EXTRA_OBJECT] = tab this[EXTRA_OBJECT] = tab
@ -105,7 +105,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
listView.adapter = adapter listView.adapter = adapter
listView.emptyView = emptyView listView.emptyView = emptyView
listView.setDropListener { from, to -> listView.setDropListener { from, to ->
adapter!!.drop(from, to) adapter.drop(from, to)
if (listView.choiceMode != AbsListView.CHOICE_MODE_NONE) { if (listView.choiceMode != AbsListView.CHOICE_MODE_NONE) {
listView.moveCheckState(from, to) listView.moveCheckState(from, to)
} }
@ -132,7 +132,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
values.put(Tabs.TYPE, data.getStringExtra(EXTRA_TYPE)) values.put(Tabs.TYPE, data.getStringExtra(EXTRA_TYPE))
values.put(Tabs.ARGUMENTS, data.getStringExtra(EXTRA_ARGUMENTS)) values.put(Tabs.ARGUMENTS, data.getStringExtra(EXTRA_ARGUMENTS))
values.put(Tabs.EXTRAS, data.getStringExtra(EXTRA_EXTRAS)) values.put(Tabs.EXTRAS, data.getStringExtra(EXTRA_EXTRAS))
values.put(Tabs.POSITION, adapter!!.count) values.put(Tabs.POSITION, adapter.count)
contentResolver.insert(Tabs.CONTENT_URI, values) contentResolver.insert(Tabs.CONTENT_URI, values)
SettingsActivity.setShouldRestart(activity) SettingsActivity.setShouldRestart(activity)
} }
@ -187,7 +187,6 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
val df = TabEditorDialogFragment() val df = TabEditorDialogFragment()
df.arguments = Bundle { df.arguments = Bundle {
this[EXTRA_TAB_TYPE] = type this[EXTRA_TAB_TYPE] = type
val adapter = adapter!!
if (!adapter.isEmpty) { if (!adapter.isEmpty) {
this[EXTRA_TAB_POSITION] = adapter.getTab(adapter.count - 1).position + 1 this[EXTRA_TAB_POSITION] = adapter.getTab(adapter.count - 1).position + 1
} }
@ -214,11 +213,11 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
override fun onLoaderReset(loader: Loader<Cursor?>) { override fun onLoaderReset(loader: Loader<Cursor?>) {
adapter!!.changeCursor(null) adapter.changeCursor(null)
} }
override fun onLoadFinished(loader: Loader<Cursor?>, cursor: Cursor?) { override fun onLoadFinished(loader: Loader<Cursor?>, cursor: Cursor?) {
adapter!!.changeCursor(cursor) adapter.changeCursor(cursor)
setListShown(true) setListShown(true)
} }
@ -242,8 +241,8 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
} }
private fun saveTabPositions() { private fun saveTabPositions() {
val positions = adapter!!.cursorPositions val positions = adapter.cursorPositions
val c = adapter!!.cursor val c = adapter.cursor
if (positions != null && c != null && !c.isClosed) { if (positions != null && c != null && !c.isClosed) {
val idIdx = c.getColumnIndex(Tabs._ID) val idIdx = c.getColumnIndex(Tabs._ID)
for (i in 0 until positions.size) { for (i in 0 until positions.size) {

View File

@ -44,7 +44,6 @@ import org.mariotaku.twidere.util.PermissionsManager
class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<ExtensionInfo>> { class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<ExtensionInfo>> {
private var adapter: ExtensionsAdapter? = null
private var packageManager: PackageManager? = null private var packageManager: PackageManager? = null
private var permissionsManager: PermissionsManager? = null private var permissionsManager: PermissionsManager? = null
@ -52,8 +51,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
packageManager = activity.packageManager packageManager = activity.packageManager
permissionsManager = PermissionsManager(activity) permissionsManager = PermissionsManager(activity)
adapter = ExtensionsAdapter(activity) listAdapter = ExtensionsAdapter(activity)
listAdapter = adapter
listView.setOnCreateContextMenuListener(this) listView.setOnCreateContextMenuListener(this)
loaderManager.initLoader(0, null, this) loaderManager.initLoader(0, null, this)
setEmptyText(getString(R.string.no_extension_installed)) setEmptyText(getString(R.string.no_extension_installed))
@ -69,28 +67,28 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
} }
override fun onLoadFinished(loader: Loader<List<ExtensionInfo>>, data: List<ExtensionInfo>) { override fun onLoadFinished(loader: Loader<List<ExtensionInfo>>, data: List<ExtensionInfo>) {
adapter!!.setData(data) (listAdapter as ExtensionsAdapter).setData(data)
setListShown(true) setListShown(true)
} }
override fun onLoaderReset(loader: Loader<List<ExtensionInfo>>) { override fun onLoaderReset(loader: Loader<List<ExtensionInfo>>) {
adapter!!.setData(null) (listAdapter as ExtensionsAdapter).setData(null)
} }
override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) { override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) {
openSettings(adapter!!.getItem(position)) openSettings((listAdapter as ExtensionsAdapter).getItem(position))
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
adapter!!.notifyDataSetChanged() (listAdapter as ExtensionsAdapter).notifyDataSetChanged()
} }
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo) { override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo) {
val inflater = MenuInflater(v.context) val inflater = MenuInflater(v.context)
inflater.inflate(R.menu.action_extension, menu) inflater.inflate(R.menu.action_extension, menu)
val adapterMenuInfo = menuInfo as AdapterContextMenuInfo val adapterMenuInfo = menuInfo as AdapterContextMenuInfo
val extensionInfo = adapter!!.getItem(adapterMenuInfo.position) val extensionInfo = (listAdapter as ExtensionsAdapter).getItem(adapterMenuInfo.position)
if (extensionInfo.pname != null && extensionInfo.settings != null) { if (extensionInfo.pname != null && extensionInfo.settings != null) {
val intent = Intent(IntentConstants.INTENT_ACTION_EXTENSION_SETTINGS) val intent = Intent(IntentConstants.INTENT_ACTION_EXTENSION_SETTINGS)
intent.setClassName(extensionInfo.pname, extensionInfo.settings) intent.setClassName(extensionInfo.pname, extensionInfo.settings)
@ -103,7 +101,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
override fun onContextItemSelected(item: MenuItem?): Boolean { override fun onContextItemSelected(item: MenuItem?): Boolean {
val adapterMenuInfo = item!!.menuInfo as AdapterContextMenuInfo val adapterMenuInfo = item!!.menuInfo as AdapterContextMenuInfo
val extensionInfo = adapter!!.getItem(adapterMenuInfo.position) val extensionInfo = (listAdapter as ExtensionsAdapter).getItem(adapterMenuInfo.position)
when (item.itemId) { when (item.itemId) {
R.id.settings -> { R.id.settings -> {
openSettings(extensionInfo) openSettings(extensionInfo)
@ -113,7 +111,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
} }
R.id.revoke -> { R.id.revoke -> {
permissionsManager!!.revoke(extensionInfo.pname) permissionsManager!!.revoke(extensionInfo.pname)
adapter!!.notifyDataSetChanged() (listAdapter as ExtensionsAdapter).notifyDataSetChanged()
} }
else -> { else -> {
return false return false

View File

@ -59,13 +59,11 @@ class IncomingFriendshipsFragment : CursorSupportUsersListFragment(), IUsersAdap
} }
override fun onAcceptClicked(holder: UserViewHolder, position: Int) { override fun onAcceptClicked(holder: UserViewHolder, position: Int) {
val adapter = adapter
val user = adapter.getUser(position) ?: return val user = adapter.getUser(position) ?: return
twitterWrapper.acceptFriendshipAsync(user.account_key, user.key) twitterWrapper.acceptFriendshipAsync(user.account_key, user.key)
} }
override fun onDenyClicked(holder: UserViewHolder, position: Int) { override fun onDenyClicked(holder: UserViewHolder, position: Int) {
val adapter = adapter
val user = adapter.getUser(position) ?: return val user = adapter.getUser(position) ?: return
twitterWrapper.denyFriendshipAsync(user.account_key, user.key) twitterWrapper.denyFriendshipAsync(user.account_key, user.key)
} }

View File

@ -116,7 +116,6 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment<VariousItemsAdapter
val inflater = MenuInflater(context) val inflater = MenuInflater(context)
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo? val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
val position = contextMenuInfo!!.position val position = contextMenuInfo!!.position
val adapter = adapter
when (adapter.getItemViewType(position)) { when (adapter.getItemViewType(position)) {
VariousItemsAdapter.VIEW_TYPE_STATUS -> { VariousItemsAdapter.VIEW_TYPE_STATUS -> {
val dummyAdapter = adapter.dummyAdapter val dummyAdapter = adapter.dummyAdapter
@ -132,7 +131,6 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment<VariousItemsAdapter
if (!userVisibleHint) return false if (!userVisibleHint) return false
val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo
val position = contextMenuInfo.position val position = contextMenuInfo.position
val adapter = adapter
when (adapter.getItemViewType(position)) { when (adapter.getItemViewType(position)) {
VariousItemsAdapter.VIEW_TYPE_STATUS -> { VariousItemsAdapter.VIEW_TYPE_STATUS -> {
val dummyAdapter = adapter.dummyAdapter val dummyAdapter = adapter.dummyAdapter

View File

@ -76,7 +76,6 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<Par
} }
override fun onLoadFinished(loader: Loader<List<ParcelableGroup>?>, data: List<ParcelableGroup>?) { override fun onLoadFinished(loader: Loader<List<ParcelableGroup>?>, data: List<ParcelableGroup>?) {
val adapter = adapter
adapter.setData(data) adapter.setData(data)
if (loader !is IExtendedLoader || loader.fromUser) { if (loader !is IExtendedLoader || loader.fromUser) {
adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE
@ -123,7 +122,6 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<Par
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
val adapter = adapter
val layoutManager = layoutManager val layoutManager = layoutManager
adapter.groupAdapterListener = this adapter.groupAdapterListener = this

View File

@ -128,7 +128,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
refreshEnabled = true refreshEnabled = true
refreshing = false refreshing = false
setLoadMoreIndicatorPosition(ILoadMoreSupportAdapter.NONE) setLoadMoreIndicatorPosition(ILoadMoreSupportAdapter.NONE)
val adapter = adapter
if (adapter.itemCount > 0) { if (adapter.itemCount > 0) {
showContent() showContent()
} else if (loader is MicroBlogAPIStatusesLoader) { } else if (loader is MicroBlogAPIStatusesLoader) {
@ -149,7 +148,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
if (position and ILoadMoreSupportAdapter.START !== 0L || refreshing) return if (position and ILoadMoreSupportAdapter.START !== 0L || refreshing) return
super.onLoadMoreContents(position) super.onLoadMoreContents(position)
if (position == 0L) return if (position == 0L) return
val adapter = adapter
// Load the last item // Load the last item
val idx = adapter.statusStartIndex + adapter.rawStatusCount - 1 val idx = adapter.statusStartIndex + adapter.rawStatusCount - 1
if (idx < 0) return if (idx < 0) return
@ -165,7 +163,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
fun replaceStatusStates(status: ParcelableStatus?) { fun replaceStatusStates(status: ParcelableStatus?) {
if (status == null) return if (status == null) return
val lm = layoutManager val lm = layoutManager
val adapter = adapter
val rangeStart = Math.max(adapter.statusStartIndex, lm.findFirstVisibleItemPosition()) val rangeStart = Math.max(adapter.statusStartIndex, lm.findFirstVisibleItemPosition())
val rangeEnd = Math.min(lm.findLastVisibleItemPosition(), adapter.statusStartIndex + adapter.statusCount - 1) val rangeEnd = Math.min(lm.findLastVisibleItemPosition(), adapter.statusStartIndex + adapter.statusCount - 1)
for (i in rangeStart..rangeEnd) { for (i in rangeStart..rangeEnd) {
@ -183,7 +180,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
override fun triggerRefresh(): Boolean { override fun triggerRefresh(): Boolean {
super.triggerRefresh() super.triggerRefresh()
val adapter = adapter
val accountKeys = accountKeys val accountKeys = accountKeys
if (adapter.statusCount > 0) { if (adapter.statusCount > 0) {
val firstStatus = adapter.getStatus(0)!! val firstStatus = adapter.getStatus(0)!!

View File

@ -78,7 +78,6 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment<
} }
override fun onLoadFinished(loader: Loader<List<ParcelableUserList>>, data: List<ParcelableUserList>) { override fun onLoadFinished(loader: Loader<List<ParcelableUserList>>, data: List<ParcelableUserList>) {
val adapter = adapter
adapter.setData(data) adapter.setData(data)
if (loader !is IExtendedLoader || loader.fromUser) { if (loader !is IExtendedLoader || loader.fromUser) {
adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE
@ -129,7 +128,6 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment<
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
val adapter = adapter
val layoutManager = layoutManager val layoutManager = layoutManager
adapter.userListClickListener = this adapter.userListClickListener = this

View File

@ -63,7 +63,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
val adapter = adapter
adapter.userClickListener = this adapter.userClickListener = this
navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter, navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter,
@ -99,7 +98,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
} }
override fun onLoadFinished(loader: Loader<List<ParcelableUser>?>, data: List<ParcelableUser>?) { override fun onLoadFinished(loader: Loader<List<ParcelableUser>?>, data: List<ParcelableUser>?) {
val adapter = adapter
adapter.setData(data) adapter.setData(data)
if (loader !is IExtendedLoader || loader.fromUser) { if (loader !is IExtendedLoader || loader.fromUser) {
adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE
@ -183,7 +181,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
override fun createItemDecoration(context: Context, recyclerView: RecyclerView, override fun createItemDecoration(context: Context, recyclerView: RecyclerView,
layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? { layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? {
val adapter = adapter
val itemDecoration = DividerItemDecoration(context, val itemDecoration = DividerItemDecoration(context,
(recyclerView.layoutManager as LinearLayoutManager).orientation) (recyclerView.layoutManager as LinearLayoutManager).orientation)
val res = context.resources val res = context.resources
@ -227,7 +224,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
@Subscribe @Subscribe
fun onFriendshipTaskEvent(event: FriendshipTaskEvent) { fun onFriendshipTaskEvent(event: FriendshipTaskEvent) {
val adapter = adapter
val position = findPosition(event.accountKey, event.userKey) val position = findPosition(event.accountKey, event.userKey)
val data = adapter.getData() ?: return val data = adapter.getData() ?: return
if (position < 0 || position >= data.size) return if (position < 0 || position >= data.size) return

View File

@ -120,7 +120,8 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
OnMediaClickListener, StatusClickListener, KeyboardShortcutCallback, ContentListSupport { OnMediaClickListener, StatusClickListener, KeyboardShortcutCallback, ContentListSupport {
private var mItemDecoration: DividerItemDecoration? = null private var mItemDecoration: DividerItemDecoration? = null
override var adapter: StatusAdapter? = null override lateinit var adapter: StatusAdapter
private set
private var layoutManager: LinearLayoutManager? = null private var layoutManager: LinearLayoutManager? = null
private var loadTranslationTask: LoadTranslationTask? = null private var loadTranslationTask: LoadTranslationTask? = null
@ -136,7 +137,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
// Listeners // Listeners
private val conversationsLoaderCallback = object : LoaderCallbacks<List<ParcelableStatus>> { private val conversationsLoaderCallback = object : LoaderCallbacks<List<ParcelableStatus>> {
override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableStatus>> { override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableStatus>> {
val adapter = this@StatusFragment.adapter!! val adapter = this@StatusFragment.adapter
adapter.isRepliesLoading = true adapter.isRepliesLoading = true
adapter.isConversationsLoading = true adapter.isConversationsLoading = true
adapter.updateItemDecoration() adapter.updateItemDecoration()
@ -154,7 +155,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
override fun onLoadFinished(loader: Loader<List<ParcelableStatus>>, data: List<ParcelableStatus>?) { override fun onLoadFinished(loader: Loader<List<ParcelableStatus>>, data: List<ParcelableStatus>?) {
val adapter = this@StatusFragment.adapter!! val adapter = this@StatusFragment.adapter
adapter.updateItemDecoration() adapter.updateItemDecoration()
val conversationLoader = loader as ConversationLoader val conversationLoader = loader as ConversationLoader
var supportedPositions: Long = 0 var supportedPositions: Long = 0
@ -215,8 +216,8 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
override fun onLoadFinished(loader: Loader<StatusActivity?>, data: StatusActivity?) { override fun onLoadFinished(loader: Loader<StatusActivity?>, data: StatusActivity?) {
adapter!!.updateItemDecoration() adapter.updateItemDecoration()
adapter!!.statusActivity = data adapter.statusActivity = data
} }
override fun onLoaderReset(loader: Loader<StatusActivity?>) { override fun onLoaderReset(loader: Loader<StatusActivity?>) {
@ -228,7 +229,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
val activity = activity ?: return val activity = activity ?: return
when (requestCode) { when (requestCode) {
REQUEST_SET_COLOR -> { REQUEST_SET_COLOR -> {
val status = adapter!!.status ?: return val status = adapter.status ?: return
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
if (data == null) return if (data == null) return
val color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT) val color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT)
@ -245,7 +246,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
loaderManager.restartLoader(LOADER_ID_DETAIL_STATUS, args, this) loaderManager.restartLoader(LOADER_ID_DETAIL_STATUS, args, this)
} }
REQUEST_SELECT_ACCOUNT -> { REQUEST_SELECT_ACCOUNT -> {
val status = adapter!!.status ?: return val status = adapter.status ?: return
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
if (data == null || !data.hasExtra(EXTRA_ID)) return if (data == null || !data.hasExtra(EXTRA_ID)) return
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)
@ -271,12 +272,12 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
}) })
adapter = StatusAdapter(this) adapter = StatusAdapter(this)
layoutManager = StatusListLinearLayoutManager(context, recyclerView) layoutManager = StatusListLinearLayoutManager(context, recyclerView)
mItemDecoration = StatusDividerItemDecoration(context, adapter!!, layoutManager!!.orientation) mItemDecoration = StatusDividerItemDecoration(context, adapter, layoutManager!!.orientation)
recyclerView.addItemDecoration(mItemDecoration) recyclerView.addItemDecoration(mItemDecoration)
layoutManager!!.recycleChildrenOnDetach = true layoutManager!!.recycleChildrenOnDetach = true
recyclerView.layoutManager = layoutManager recyclerView.layoutManager = layoutManager
recyclerView.clipToPadding = false recyclerView.clipToPadding = false
adapter!!.statusClickListener = this adapter.statusClickListener = this
recyclerView.adapter = adapter recyclerView.adapter = adapter
registerForContextMenu(recyclerView!!) registerForContextMenu(recyclerView!!)
@ -285,7 +286,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
scrollListener!!.touchSlop = ViewConfiguration.get(context).scaledTouchSlop scrollListener!!.touchSlop = ViewConfiguration.get(context).scaledTouchSlop
navigationHelper = RecyclerViewNavigationHelper(recyclerView!!, layoutManager!!, navigationHelper = RecyclerViewNavigationHelper(recyclerView!!, layoutManager!!,
adapter!!, null) adapter, null)
setState(STATE_LOADING) setState(STATE_LOADING)
@ -293,12 +294,12 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, statusPosition: Int) { override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, statusPosition: Int) {
val status = adapter!!.getStatus(statusPosition) ?: return val status = adapter.getStatus(statusPosition) ?: return
IntentUtils.openMedia(activity, status, media, null, IntentUtils.openMedia(activity, status, media, null,
preferences.getBoolean(SharedPreferenceConstants.KEY_NEW_DOCUMENT_API)) preferences.getBoolean(SharedPreferenceConstants.KEY_NEW_DOCUMENT_API))
val event = MediaEvent.create(activity, status, media, TimelineType.DETAILS, val event = MediaEvent.create(activity, status, media, TimelineType.DETAILS,
adapter!!.mediaPreviewEnabled) adapter.mediaPreviewEnabled)
HotMobiLogger.getInstance(activity).log(status.account_key, event) HotMobiLogger.getInstance(activity).log(status.account_key, event)
} }
@ -308,13 +309,13 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
override fun onItemActionClick(holder: ViewHolder, id: Int, position: Int) { override fun onItemActionClick(holder: ViewHolder, id: Int, position: Int) {
val status = adapter!!.getStatus(position) val status = adapter.getStatus(position)
AbsStatusesFragment.handleStatusActionClick(context, fragmentManager, twitterWrapper, AbsStatusesFragment.handleStatusActionClick(context, fragmentManager, twitterWrapper,
holder as StatusViewHolder, status, id) holder as StatusViewHolder, status, id)
} }
override fun onStatusClick(holder: IStatusViewHolder, position: Int) { override fun onStatusClick(holder: IStatusViewHolder, position: Int) {
IntentUtils.openStatus(activity, adapter!!.getStatus(position)!!, null) IntentUtils.openStatus(activity, adapter.getStatus(position)!!, null)
} }
override fun onStatusLongClick(holder: IStatusViewHolder, position: Int): Boolean { override fun onStatusLongClick(holder: IStatusViewHolder, position: Int): Boolean {
@ -329,20 +330,20 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
override fun onUserProfileClick(holder: IStatusViewHolder, position: Int) { override fun onUserProfileClick(holder: IStatusViewHolder, position: Int) {
val activity = activity val activity = activity
val status = adapter!!.getStatus(position) val status = adapter.getStatus(position)
IntentUtils.openUserProfile(activity, status!!.account_key, status.user_key, IntentUtils.openUserProfile(activity, status!!.account_key, status.user_key,
status.user_screen_name, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API), status.user_screen_name, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API),
Referral.TIMELINE_STATUS) Referral.TIMELINE_STATUS)
} }
override fun onMediaClick(view: View, media: ParcelableMedia?, accountKey: UserKey, extraId: Long) { override fun onMediaClick(view: View, media: ParcelableMedia?, accountKey: UserKey, extraId: Long) {
val status = adapter!!.status val status = adapter.status
if (status == null || media == null) return if (status == null || media == null) return
IntentUtils.openMediaDirectly(activity, accountKey, status, media, null, IntentUtils.openMediaDirectly(activity, accountKey, status, media, null,
preferences.getBoolean(KEY_NEW_DOCUMENT_API)) preferences.getBoolean(KEY_NEW_DOCUMENT_API))
// BEGIN HotMobi // BEGIN HotMobi
val event = MediaEvent.create(activity, status, media, TimelineType.OTHER, val event = MediaEvent.create(activity, status, media, TimelineType.OTHER,
adapter!!.mediaPreviewEnabled) adapter.mediaPreviewEnabled)
HotMobiLogger.getInstance(activity).log(status.account_key, event) HotMobiLogger.getInstance(activity).log(status.account_key, event)
// END HotMobi // END HotMobi
} }
@ -359,7 +360,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
return false return false
} }
if (position == -1) return false if (position == -1) return false
val status = adapter!!.getStatus(position) ?: return false val status = adapter.getStatus(position) ?: return false
val action = handler.getKeyAction(CONTEXT_TAG_STATUS, keyCode, event, metaState) ?: return false val action = handler.getKeyAction(CONTEXT_TAG_STATUS, keyCode, event, metaState) ?: return false
when (action) { when (action) {
ACTION_STATUS_REPLY -> { ACTION_STATUS_REPLY -> {
@ -416,17 +417,17 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
val readPosition = saveReadPosition() val readPosition = saveReadPosition()
val dataExtra = data.extras val dataExtra = data.extras
val details: AccountDetails = dataExtra.getParcelable(EXTRA_ACCOUNT) val details: AccountDetails = dataExtra.getParcelable(EXTRA_ACCOUNT)
if (adapter!!.setStatus(status, details)) { if (adapter.setStatus(status, details)) {
val args = arguments val args = arguments
if (args.containsKey(EXTRA_STATUS)) { if (args.containsKey(EXTRA_STATUS)) {
args.putParcelable(EXTRA_STATUS, status) args.putParcelable(EXTRA_STATUS, status)
} }
adapter!!.loadMoreSupportedPosition = ILoadMoreSupportAdapter.BOTH adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.BOTH
adapter!!.setData(null) adapter.setData(null)
loadConversation(status, null, null) loadConversation(status, null, null)
loadActivity(status) loadActivity(status)
val position = adapter!!.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS) val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
layoutManager!!.scrollToPositionWithOffset(position, 0) layoutManager!!.scrollToPositionWithOffset(position, 0)
} }
@ -440,7 +441,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
setState(STATE_LOADED) setState(STATE_LOADED)
} else { } else {
adapter!!.loadMoreSupportedPosition = ILoadMoreSupportAdapter.NONE adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.NONE
setState(STATE_ERROR) setState(STATE_ERROR)
errorText.text = Utils.getErrorMessage(context, data.exception) errorText.text = Utils.getErrorMessage(context, data.exception)
} }
@ -459,15 +460,15 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
override fun onPrepareOptionsMenu(menu: Menu?) { override fun onPrepareOptionsMenu(menu: Menu?) {
MenuUtils.setItemAvailability(menu, R.id.current_status, adapter!!.status != null) MenuUtils.setItemAvailability(menu, R.id.current_status, adapter.status != null)
super.onPrepareOptionsMenu(menu) super.onPrepareOptionsMenu(menu)
} }
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item!!.itemId) { when (item!!.itemId) {
R.id.current_status -> { R.id.current_status -> {
if (adapter!!.status != null) { if (adapter.status != null) {
val position = adapter!!.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS) val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
recyclerView!!.smoothScrollToPosition(position) recyclerView!!.smoothScrollToPosition(position)
} }
return true return true
@ -478,7 +479,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
private fun setConversation(data: List<ParcelableStatus>?) { private fun setConversation(data: List<ParcelableStatus>?) {
val readPosition = saveReadPosition() val readPosition = saveReadPosition()
val changed = adapter!!.setData(data) val changed = adapter.setData(data)
hasMoreConversation = data != null && changed hasMoreConversation = data != null && changed
restoreReadPosition(readPosition) restoreReadPosition(readPosition)
} }
@ -489,16 +490,16 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
override fun onLoadMoreContents(@IndicatorPosition position: Long) { override fun onLoadMoreContents(@IndicatorPosition position: Long) {
if (!hasMoreConversation) return if (!hasMoreConversation) return
if (position and ILoadMoreSupportAdapter.START !== 0L) { if (position and ILoadMoreSupportAdapter.START !== 0L) {
val start = adapter!!.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION) val start = adapter.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION)
val status = adapter!!.getStatus(start) val status = adapter.getStatus(start)
if (status == null || status.in_reply_to_status_id == null) return if (status == null || status.in_reply_to_status_id == null) return
loadConversation(status, null, status.id) loadConversation(status, null, status.id)
} else if (position and ILoadMoreSupportAdapter.END !== 0L) { } else if (position and ILoadMoreSupportAdapter.END !== 0L) {
val start = adapter!!.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION) val start = adapter.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION)
val status = adapter!!.getStatus(start + adapter!!.statusCount - 1) ?: return val status = adapter.getStatus(start + adapter.statusCount - 1) ?: return
loadConversation(status, status.id, null) loadConversation(status, status.id, null)
} }
adapter!!.loadMoreIndicatorPosition = position adapter.loadMoreIndicatorPosition = position
} }
override fun setControlVisible(visible: Boolean) { override fun setControlVisible(visible: Boolean) {
@ -506,13 +507,13 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
override val reachingEnd: Boolean override val reachingEnd: Boolean
get() = layoutManager!!.findLastCompletelyVisibleItemPosition() >= adapter!!.itemCount - 1 get() = layoutManager!!.findLastCompletelyVisibleItemPosition() >= adapter.itemCount - 1
override val reachingStart: Boolean override val reachingStart: Boolean
get() = layoutManager!!.findFirstCompletelyVisibleItemPosition() <= 1 get() = layoutManager!!.findFirstCompletelyVisibleItemPosition() <= 1
private val status: ParcelableStatus? private val status: ParcelableStatus?
get() = adapter!!.status get() = adapter.status
private fun loadConversation(status: ParcelableStatus?, sinceId: String?, maxId: String?) { private fun loadConversation(status: ParcelableStatus?, sinceId: String?, maxId: String?) {
if (status == null || activity == null) return if (status == null || activity == null) return
@ -555,7 +556,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
private fun displayTranslation(translation: TranslationResult) { private fun displayTranslation(translation: TranslationResult) {
adapter?.translationResult = translation adapter.translationResult = translation
val status = this.status val status = this.status
val context = this.context ?: return val context = this.context ?: return
if (status != null) { if (status != null) {
@ -566,7 +567,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
private fun saveReadPosition(): ReadPosition? { private fun saveReadPosition(): ReadPosition? {
val lm = layoutManager ?: return null val lm = layoutManager ?: return null
val adapter = this.adapter ?: return null val adapter = this.adapter
val position = lm.findFirstVisibleItemPosition() val position = lm.findFirstVisibleItemPosition()
if (position == RecyclerView.NO_POSITION) return null if (position == RecyclerView.NO_POSITION) return null
val itemType = adapter.getItemType(position) val itemType = adapter.getItemType(position)
@ -583,7 +584,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} }
private fun restoreReadPosition(position: ReadPosition?) { private fun restoreReadPosition(position: ReadPosition?) {
val adapter = this.adapter ?: return val adapter = this.adapter
if (position == null) return if (position == null) return
val adapterPosition = adapter.findPositionByItemId(position.statusId) val adapterPosition = adapter.findPositionByItemId(position.statusId)
if (adapterPosition < 0) return if (adapterPosition < 0) return
@ -619,7 +620,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
if (!userVisibleHint || menuInfo == null) return if (!userVisibleHint || menuInfo == null) return
val inflater = MenuInflater(context) val inflater = MenuInflater(context)
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo? val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
val status = adapter!!.getStatus(contextMenuInfo!!.position) val status = adapter.getStatus(contextMenuInfo!!.position)
inflater.inflate(R.menu.action_status, menu) inflater.inflate(R.menu.action_status, menu)
MenuUtils.setupForStatus(context, preferences, menu, status!!, MenuUtils.setupForStatus(context, preferences, menu, status!!,
twitterWrapper) twitterWrapper)
@ -628,7 +629,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
override fun onContextItemSelected(item: MenuItem?): Boolean { override fun onContextItemSelected(item: MenuItem?): Boolean {
if (!userVisibleHint) return false if (!userVisibleHint) return false
val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo
val status = adapter!!.getStatus(contextMenuInfo.position) ?: return false val status = adapter.getStatus(contextMenuInfo.position) ?: return false
if (item.itemId == R.id.share) { if (item.itemId == R.id.share) {
val shareIntent = Utils.createStatusShareIntent(activity, status) val shareIntent = Utils.createStatusShareIntent(activity, status)
val chooser = Intent.createChooser(shareIntent, getString(R.string.share_status)) val chooser = Intent.createChooser(shareIntent, getString(R.string.share_status))
@ -641,15 +642,13 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
@Subscribe @Subscribe
fun notifyStatusListChanged(event: StatusListChangedEvent) { fun notifyStatusListChanged(event: StatusListChangedEvent) {
val adapter = adapter adapter.notifyDataSetChanged()
adapter!!.notifyDataSetChanged()
} }
@Subscribe @Subscribe
fun notifyFavoriteTask(event: FavoriteTaskEvent) { fun notifyFavoriteTask(event: FavoriteTaskEvent) {
if (!event.isSucceeded) return if (!event.isSucceeded) return
val adapter = adapter val status = adapter.findStatusById(event.accountKey, event.statusId)
val status = adapter!!.findStatusById(event.accountKey, event.statusId)
if (status != null) { if (status != null) {
when (event.action) { when (event.action) {
FavoriteTaskEvent.Action.CREATE -> { FavoriteTaskEvent.Action.CREATE -> {
@ -675,7 +674,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
val f = parentFragment val f = parentFragment
if (f is StatusFragment) { if (f is StatusFragment) {
val adapter = f.adapter val adapter = f.adapter
adapter!!.isDetailMediaExpanded = true adapter.isDetailMediaExpanded = true
} }
} }
} }

View File

@ -87,7 +87,6 @@ class UserListMembersFragment : CursorSupportUsersListFragment() {
val accountId = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountId = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY) val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
if (accountId == null || accountId != userKey) return if (accountId == null || accountId != userKey) return
val adapter = adapter
val inflater = MenuInflater(context) val inflater = MenuInflater(context)
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo? val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
inflater.inflate(R.menu.action_user_list_member, menu) inflater.inflate(R.menu.action_user_list_member, menu)
@ -132,7 +131,6 @@ class UserListMembersFragment : CursorSupportUsersListFragment() {
} }
when (event.action) { when (event.action) {
UserListMembersChangedEvent.Action.ADDED -> { UserListMembersChangedEvent.Action.ADDED -> {
val adapter = adapter
val newUsers = Arrays.asList(*event.users) val newUsers = Arrays.asList(*event.users)
val users = adapter.getData() ?: return val users = adapter.getData() ?: return
if (users is MutableList) { if (users is MutableList) {
@ -143,7 +141,6 @@ class UserListMembersFragment : CursorSupportUsersListFragment() {
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
} }
UserListMembersChangedEvent.Action.REMOVED -> { UserListMembersChangedEvent.Action.REMOVED -> {
val adapter = adapter
val removedUsers = Arrays.asList(*event.users) val removedUsers = Arrays.asList(*event.users)
val users = adapter.getData() ?: return val users = adapter.getData() ?: return
if (users is MutableList) { if (users is MutableList) {

View File

@ -101,7 +101,6 @@ class UserListsFragment : ParcelableUserListsFragment() {
} }
private fun removeUserList(id: String) { private fun removeUserList(id: String) {
val adapter = adapter
// final int listsIdx = adapter.findItemPosition(id); // final int listsIdx = adapter.findItemPosition(id);
// if (listsIdx >= 0) { // if (listsIdx >= 0) {
// adapter.removeAt(listsIdx); // adapter.removeAt(listsIdx);

View File

@ -47,7 +47,6 @@ class UserMediaTimelineFragment : AbsContentRecyclerViewFragment<StaggeredGridPa
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
val adapter = adapter
adapter.statusClickListener = this adapter.statusClickListener = this
val loaderArgs = Bundle(arguments) val loaderArgs = Bundle(arguments)
loaderArgs.putBoolean(EXTRA_FROM_USER, true) loaderArgs.putBoolean(EXTRA_FROM_USER, true)
@ -99,7 +98,6 @@ class UserMediaTimelineFragment : AbsContentRecyclerViewFragment<StaggeredGridPa
} }
override fun onLoadFinished(loader: Loader<List<ParcelableStatus>>, data: List<ParcelableStatus>?) { override fun onLoadFinished(loader: Loader<List<ParcelableStatus>>, data: List<ParcelableStatus>?) {
val adapter = adapter
val changed = adapter.setData(data) val changed = adapter.setData(data)
if ((loader as IExtendedLoader).fromUser && loader is MediaTimelineLoader) { if ((loader as IExtendedLoader).fromUser && loader is MediaTimelineLoader) {
val maxId = loader.maxId val maxId = loader.maxId
@ -138,7 +136,6 @@ class UserMediaTimelineFragment : AbsContentRecyclerViewFragment<StaggeredGridPa
if (position and ILoadMoreSupportAdapter.START != 0L) return if (position and ILoadMoreSupportAdapter.START != 0L) return
super.onLoadMoreContents(position) super.onLoadMoreContents(position)
if (position == 0L) return if (position == 0L) return
val adapter = adapter
val maxId = adapter.getStatusId(adapter.statusCount - 1) val maxId = adapter.getStatusId(adapter.statusCount - 1)
getStatuses(maxId, null) getStatuses(maxId, null)
} }

View File

@ -99,7 +99,6 @@ class UserTimelineFragment : ParcelableStatusesFragment() {
override fun onStatusesLoaded(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) { override fun onStatusesLoaded(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) {
val timelineLoader = loader as UserTimelineLoader val timelineLoader = loader as UserTimelineLoader
val adapter = adapter
if (!adapter.hasPinnedStatuses) { if (!adapter.hasPinnedStatuses) {
adapter.pinnedStatuses = timelineLoader.pinnedStatuses adapter.pinnedStatuses = timelineLoader.pinnedStatuses
} }