cleaned up code
This commit is contained in:
parent
963ff1c3ca
commit
b6a0abe5dc
|
@ -42,7 +42,7 @@ import org.mariotaku.twidere.model.util.AccountUtils
|
|||
|
||||
class AccountSelectorActivity : BaseActivity(), OnClickListener, OnItemClickListener {
|
||||
|
||||
private var adapter: AccountDetailsAdapter? = null
|
||||
private lateinit var adapter: AccountDetailsAdapter
|
||||
|
||||
private var firstCreated: Boolean = false
|
||||
|
||||
|
@ -136,7 +136,6 @@ class AccountSelectorActivity : BaseActivity(), OnClickListener, OnItemClickList
|
|||
}
|
||||
|
||||
fun selectSingleAccount(position: Int) {
|
||||
val adapter = adapter!!
|
||||
val account = adapter.getItem(position)
|
||||
val data = Intent()
|
||||
data.putExtra(EXTRA_ID, account.key.id)
|
||||
|
|
|
@ -217,14 +217,10 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
|
|||
}
|
||||
|
||||
protected fun saveReadPosition() {
|
||||
val layoutManager = layoutManager
|
||||
if (layoutManager != null) {
|
||||
saveReadPosition(layoutManager.findFirstVisibleItemPosition())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableActivity>>, data: List<ParcelableActivity>) {
|
||||
val adapter = adapter
|
||||
val rememberPosition = preferences.getBoolean(KEY_REMEMBER_POSITION, false)
|
||||
val readFromBottom = preferences.getBoolean(KEY_READ_FROM_BOTTOM, false)
|
||||
var lastReadId: Long
|
||||
|
@ -315,7 +311,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
|
|||
}
|
||||
|
||||
override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, position: Int) {
|
||||
val adapter = adapter
|
||||
val status = adapter.getActivity(position)?.getActivityStatus() ?: return
|
||||
IntentUtils.openMedia(activity, status, media, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API))
|
||||
// BEGIN HotMobi
|
||||
|
@ -435,7 +430,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
|
|||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
scrollListener!!.reversed = preferences.getBoolean(KEY_READ_FROM_BOTTOM)
|
||||
val adapter = adapter
|
||||
val layoutManager = layoutManager
|
||||
adapter.setListener(this)
|
||||
registerForContextMenu(recyclerView)
|
||||
|
@ -452,7 +446,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
|
|||
override val reachingEnd: Boolean
|
||||
get() {
|
||||
val lm = layoutManager
|
||||
val adapter = adapter
|
||||
val lastPosition = lm.findLastCompletelyVisibleItemPosition()
|
||||
val itemCount = adapter.itemCount
|
||||
var finalPos = itemCount - 1
|
||||
|
@ -520,7 +513,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
|
|||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
|
||||
if (!userVisibleHint || menuInfo == null) return
|
||||
val adapter = adapter
|
||||
val inflater = MenuInflater(context)
|
||||
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
|
||||
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
|
||||
val adapter = adapter
|
||||
val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo
|
||||
val contextMenuInfo = item.menuInfo as ExtendedRecyclerView.ContextMenuInfo
|
||||
val position = contextMenuInfo.position
|
||||
|
||||
when (adapter.getItemViewType(position)) {
|
||||
|
@ -559,7 +550,6 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
|
|||
|
||||
override fun createItemDecoration(context: Context, recyclerView: RecyclerView,
|
||||
layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? {
|
||||
val adapter = adapter
|
||||
val itemDecoration = object : DividerItemDecoration(context,
|
||||
(recyclerView.layoutManager as LinearLayoutManager).orientation) {
|
||||
override fun isDividerEnabled(childPos: Int): Boolean {
|
||||
|
|
|
@ -42,12 +42,12 @@ import org.mariotaku.twidere.util.TwidereColorUtils
|
|||
* Created by mariotaku on 15/4/16.
|
||||
*/
|
||||
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
|
||||
private val mSystemWindowsInsets = Rect()
|
||||
private val systemWindowsInsets = Rect()
|
||||
|
||||
override fun onControlBarOffsetChanged(activity: IControlBarActivity, offset: Float) {
|
||||
updateRefreshProgressOffset()
|
||||
|
@ -128,9 +128,10 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment
|
|||
}
|
||||
listView.adapter = adapter
|
||||
listView.clipToPadding = false
|
||||
scrollHandler = ListViewScrollHandler(this, ListViewScrollHandler.ListViewCallback(listView))
|
||||
scrollHandler!!.touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
scrollHandler!!.onScrollListener = this
|
||||
scrollHandler = ListViewScrollHandler(this, ListViewScrollHandler.ListViewCallback(listView)).apply {
|
||||
this.touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
this.onScrollListener = this@AbsContentListViewFragment
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -148,7 +149,7 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment
|
|||
listView.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)
|
||||
mSystemWindowsInsets.set(insets)
|
||||
systemWindowsInsets.set(insets)
|
||||
updateRefreshProgressOffset()
|
||||
}
|
||||
|
||||
|
@ -192,14 +193,14 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseSupportFragment
|
|||
|
||||
protected fun updateRefreshProgressOffset() {
|
||||
val activity = activity
|
||||
if (activity !is IControlBarActivity || mSystemWindowsInsets.top == 0 || swipeLayout == null
|
||||
if (activity !is IControlBarActivity || systemWindowsInsets.top == 0 || swipeLayout == null
|
||||
|| refreshing) {
|
||||
return
|
||||
}
|
||||
val density = resources.displayMetrics.density
|
||||
val progressCircleDiameter = swipeLayout.progressCircleDiameter
|
||||
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
|
||||
val swipeDistance = Math.round(64 * density)
|
||||
swipeLayout.setProgressViewOffset(false, swipeStart, swipeStart + swipeDistance)
|
||||
|
|
|
@ -170,7 +170,6 @@ abstract class AbsStatusesFragment protected constructor() :
|
|||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
scrollListener?.reversed = preferences.getBoolean(SharedPreferenceConstants.KEY_READ_FROM_BOTTOM)
|
||||
val adapter = adapter
|
||||
adapter.statusClickListener = this
|
||||
registerForContextMenu(recyclerView)
|
||||
navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter, this)
|
||||
|
@ -223,7 +222,6 @@ abstract class AbsStatusesFragment protected constructor() :
|
|||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
val adapter = adapter
|
||||
adapter.statusClickListener = null
|
||||
super.onDestroy()
|
||||
}
|
||||
|
@ -316,7 +314,6 @@ abstract class AbsStatusesFragment protected constructor() :
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) {
|
||||
val adapter = adapter
|
||||
val rememberPosition = preferences.getBoolean(SharedPreferenceConstants.KEY_REMEMBER_POSITION, false)
|
||||
val readFromBottom = preferences.getBoolean(SharedPreferenceConstants.KEY_READ_FROM_BOTTOM, false)
|
||||
var lastReadPositionKey: Long
|
||||
|
@ -410,7 +407,6 @@ abstract class AbsStatusesFragment protected constructor() :
|
|||
}
|
||||
|
||||
override fun onMediaClick(holder: IStatusViewHolder, view: View, media: ParcelableMedia, statusPosition: Int) {
|
||||
val adapter = adapter
|
||||
val status = adapter.getStatus(statusPosition) ?: return
|
||||
IntentUtils.openMedia(activity, status, media, null,
|
||||
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) {
|
||||
val context = context ?: return
|
||||
val adapter = adapter
|
||||
val status = adapter.getStatus(position) ?: return
|
||||
handleStatusActionClick(context, fragmentManager, twitterWrapper, holder as StatusViewHolder, status, id)
|
||||
}
|
||||
|
||||
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
|
||||
if (adapter.profileImageEnabled) {
|
||||
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) {
|
||||
if (host == null) return
|
||||
if (position == RecyclerView.NO_POSITION) return
|
||||
val adapter = adapter
|
||||
val status = adapter.getStatus(position) ?: return
|
||||
val positionKey = if (status.position_key > 0) status.position_key else status.timestamp
|
||||
readPositionTagWithArguments?.let {
|
||||
|
@ -534,7 +525,6 @@ abstract class AbsStatusesFragment protected constructor() :
|
|||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
|
||||
if (!userVisibleHint || menuInfo == null) return
|
||||
val adapter = adapter
|
||||
val inflater = MenuInflater(context)
|
||||
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
|
||||
val status = adapter.getStatus(contextMenuInfo!!.position)
|
||||
|
@ -542,9 +532,9 @@ abstract class AbsStatusesFragment protected constructor() :
|
|||
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
|
||||
val status = adapter.getStatus(contextMenuInfo.position) ?: return false
|
||||
if (item.itemId == R.id.share) {
|
||||
val shareIntent = Utils.createStatusShareIntent(activity, status)
|
||||
|
|
|
@ -169,7 +169,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<Cursor?>, data: Cursor?) {
|
||||
val adapter = adapter
|
||||
adapter!!.swapCursor(data)
|
||||
if (data != null && data.count > 0) {
|
||||
showContent()
|
||||
|
@ -179,7 +178,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
|
|||
}
|
||||
|
||||
override fun onLoaderReset(loader: Loader<Cursor?>) {
|
||||
val adapter = adapter
|
||||
adapter!!.swapCursor(null)
|
||||
}
|
||||
|
||||
|
@ -254,15 +252,15 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
|
|||
val autoCompleteType: Int
|
||||
autoCompleteType = args.getInt(EXTRA_AUTO_COMPLETE_TYPE, 0)
|
||||
if (autoCompleteType != 0) {
|
||||
val mUserAutoCompleteAdapter: SimpleCursorAdapter
|
||||
val userAutoCompleteAdapter: SimpleCursorAdapter
|
||||
if (autoCompleteType == AUTO_COMPLETE_TYPE_SOURCES) {
|
||||
mUserAutoCompleteAdapter = SourceAutoCompleteAdapter(activity)
|
||||
userAutoCompleteAdapter = SourceAutoCompleteAdapter(activity)
|
||||
} else {
|
||||
val adapter = ComposeAutoCompleteAdapter(activity)
|
||||
adapter.accountKey = Utils.getDefaultAccountKey(activity)
|
||||
mUserAutoCompleteAdapter = adapter
|
||||
userAutoCompleteAdapter = adapter
|
||||
}
|
||||
editText.setAdapter(mUserAutoCompleteAdapter)
|
||||
editText.setAdapter(userAutoCompleteAdapter)
|
||||
editText.threshold = 1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
|||
|
||||
override fun onLoadingFinished() {
|
||||
val accountKeys = accountKeys
|
||||
val adapter = adapter
|
||||
if (adapter.itemCount > 0) {
|
||||
showContent()
|
||||
} else if (accountKeys.isNotEmpty()) {
|
||||
|
@ -100,7 +99,6 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
|||
}
|
||||
val expression = processWhere(where, accountSelectionArgs)
|
||||
val selection = expression.sql
|
||||
val adapter = adapter
|
||||
adapter.showAccountsColor = accountKeys.size > 1
|
||||
val projection = Activities.COLUMNS
|
||||
return CursorActivitiesLoader(context, uri, projection, selection, expression.parameters,
|
||||
|
@ -258,7 +256,6 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
|||
fun replaceStatusStates(result: ParcelableStatus?) {
|
||||
if (result == null) return
|
||||
val lm = layoutManager
|
||||
val adapter = adapter
|
||||
val rangeStart = Math.max(adapter.activityStartIndex, lm.findFirstVisibleItemPosition())
|
||||
val rangeEnd = Math.min(lm.findLastVisibleItemPosition(), adapter.activityStartIndex + adapter.activityCount - 1)
|
||||
loop@ for (i in rangeStart..rangeEnd) {
|
||||
|
|
|
@ -27,14 +27,12 @@ import android.net.Uri
|
|||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.support.v4.content.Loader
|
||||
import android.util.Log
|
||||
import com.squareup.otto.Subscribe
|
||||
import kotlinx.android.synthetic.main.fragment_content_recyclerview.*
|
||||
import org.mariotaku.sqliteqb.library.ArgsArray
|
||||
import org.mariotaku.sqliteqb.library.Columns.Column
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.LOGTAG
|
||||
import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition
|
||||
|
@ -86,7 +84,6 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
|||
} else {
|
||||
where = accountWhere
|
||||
}
|
||||
val adapter = adapter
|
||||
adapter.showAccountsColor = accountKeys.size > 1
|
||||
val projection = Statuses.COLUMNS
|
||||
val selectionArgs = Array(accountKeys.size) {
|
||||
|
@ -103,8 +100,7 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
|||
|
||||
|
||||
private fun showContentOrError() {
|
||||
val accountKeys = accountKeys
|
||||
val adapter = adapter
|
||||
val accountKeys = this.accountKeys
|
||||
if (adapter.itemCount > 0) {
|
||||
showContent()
|
||||
} else if (accountKeys.isNotEmpty()) {
|
||||
|
@ -270,7 +266,6 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
|||
val status = event.status
|
||||
val data = adapterData
|
||||
if (status == null || data == null || data.isEmpty()) return
|
||||
val adapter = adapter
|
||||
val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition()
|
||||
val lastVisiblePosition = layoutManager.findLastVisibleItemPosition()
|
||||
val startIndex = adapter.statusStartIndex
|
||||
|
|
|
@ -73,7 +73,7 @@ import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder
|
|||
|
||||
class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, MultiChoiceModeListener {
|
||||
|
||||
private var adapter: CustomTabsAdapter? = null
|
||||
private lateinit var adapter: CustomTabsAdapter
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
|
@ -95,7 +95,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL
|
||||
listView.setMultiChoiceModeListener(this)
|
||||
listView.onItemClickListener = OnItemClickListener { parent, view, position, id ->
|
||||
val tab = adapter!!.getTab(position)
|
||||
val tab = adapter.getTab(position)
|
||||
val df = TabEditorDialogFragment()
|
||||
df.arguments = Bundle {
|
||||
this[EXTRA_OBJECT] = tab
|
||||
|
@ -105,7 +105,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
listView.adapter = adapter
|
||||
listView.emptyView = emptyView
|
||||
listView.setDropListener { from, to ->
|
||||
adapter!!.drop(from, to)
|
||||
adapter.drop(from, to)
|
||||
if (listView.choiceMode != AbsListView.CHOICE_MODE_NONE) {
|
||||
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.ARGUMENTS, data.getStringExtra(EXTRA_ARGUMENTS))
|
||||
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)
|
||||
SettingsActivity.setShouldRestart(activity)
|
||||
}
|
||||
|
@ -187,7 +187,6 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
val df = TabEditorDialogFragment()
|
||||
df.arguments = Bundle {
|
||||
this[EXTRA_TAB_TYPE] = type
|
||||
val adapter = adapter!!
|
||||
if (!adapter.isEmpty) {
|
||||
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?>) {
|
||||
adapter!!.changeCursor(null)
|
||||
adapter.changeCursor(null)
|
||||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<Cursor?>, cursor: Cursor?) {
|
||||
adapter!!.changeCursor(cursor)
|
||||
adapter.changeCursor(cursor)
|
||||
setListShown(true)
|
||||
}
|
||||
|
||||
|
@ -242,8 +241,8 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
}
|
||||
|
||||
private fun saveTabPositions() {
|
||||
val positions = adapter!!.cursorPositions
|
||||
val c = adapter!!.cursor
|
||||
val positions = adapter.cursorPositions
|
||||
val c = adapter.cursor
|
||||
if (positions != null && c != null && !c.isClosed) {
|
||||
val idIdx = c.getColumnIndex(Tabs._ID)
|
||||
for (i in 0 until positions.size) {
|
||||
|
@ -368,7 +367,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
extraConfigContainer.addView(view)
|
||||
}
|
||||
|
||||
accountSpinner.onItemSelectedListener = object :AdapterView.OnItemSelectedListener {
|
||||
accountSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
|
||||
private fun updateExtraTabs(account: AccountDetails?) {
|
||||
extraConfigurations.forEach {
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.mariotaku.twidere.util.PermissionsManager
|
|||
|
||||
class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<ExtensionInfo>> {
|
||||
|
||||
private var adapter: ExtensionsAdapter? = null
|
||||
private var packageManager: PackageManager? = null
|
||||
private var permissionsManager: PermissionsManager? = null
|
||||
|
||||
|
@ -52,8 +51,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
|
|||
super.onActivityCreated(savedInstanceState)
|
||||
packageManager = activity.packageManager
|
||||
permissionsManager = PermissionsManager(activity)
|
||||
adapter = ExtensionsAdapter(activity)
|
||||
listAdapter = adapter
|
||||
listAdapter = ExtensionsAdapter(activity)
|
||||
listView.setOnCreateContextMenuListener(this)
|
||||
loaderManager.initLoader(0, null, this)
|
||||
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>) {
|
||||
adapter!!.setData(data)
|
||||
(listAdapter as ExtensionsAdapter).setData(data)
|
||||
setListShown(true)
|
||||
}
|
||||
|
||||
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) {
|
||||
openSettings(adapter!!.getItem(position))
|
||||
openSettings((listAdapter as ExtensionsAdapter).getItem(position))
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
adapter!!.notifyDataSetChanged()
|
||||
(listAdapter as ExtensionsAdapter).notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo) {
|
||||
val inflater = MenuInflater(v.context)
|
||||
inflater.inflate(R.menu.action_extension, menu)
|
||||
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) {
|
||||
val intent = Intent(IntentConstants.INTENT_ACTION_EXTENSION_SETTINGS)
|
||||
intent.setClassName(extensionInfo.pname, extensionInfo.settings)
|
||||
|
@ -103,7 +101,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
|
|||
|
||||
override fun onContextItemSelected(item: MenuItem?): Boolean {
|
||||
val adapterMenuInfo = item!!.menuInfo as AdapterContextMenuInfo
|
||||
val extensionInfo = adapter!!.getItem(adapterMenuInfo.position)
|
||||
val extensionInfo = (listAdapter as ExtensionsAdapter).getItem(adapterMenuInfo.position)
|
||||
when (item.itemId) {
|
||||
R.id.settings -> {
|
||||
openSettings(extensionInfo)
|
||||
|
@ -113,7 +111,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
|
|||
}
|
||||
R.id.revoke -> {
|
||||
permissionsManager!!.revoke(extensionInfo.pname)
|
||||
adapter!!.notifyDataSetChanged()
|
||||
(listAdapter as ExtensionsAdapter).notifyDataSetChanged()
|
||||
}
|
||||
else -> {
|
||||
return false
|
||||
|
|
|
@ -59,13 +59,11 @@ class IncomingFriendshipsFragment : CursorSupportUsersListFragment(), IUsersAdap
|
|||
}
|
||||
|
||||
override fun onAcceptClicked(holder: UserViewHolder, position: Int) {
|
||||
val adapter = adapter
|
||||
val user = adapter.getUser(position) ?: return
|
||||
twitterWrapper.acceptFriendshipAsync(user.account_key, user.key)
|
||||
}
|
||||
|
||||
override fun onDenyClicked(holder: UserViewHolder, position: Int) {
|
||||
val adapter = adapter
|
||||
val user = adapter.getUser(position) ?: return
|
||||
twitterWrapper.denyFriendshipAsync(user.account_key, user.key)
|
||||
}
|
||||
|
|
|
@ -116,7 +116,6 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment<VariousItemsAdapter
|
|||
val inflater = MenuInflater(context)
|
||||
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
|
||||
val position = contextMenuInfo!!.position
|
||||
val adapter = adapter
|
||||
when (adapter.getItemViewType(position)) {
|
||||
VariousItemsAdapter.VIEW_TYPE_STATUS -> {
|
||||
val dummyAdapter = adapter.dummyAdapter
|
||||
|
@ -132,7 +131,6 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment<VariousItemsAdapter
|
|||
if (!userVisibleHint) return false
|
||||
val contextMenuInfo = item!!.menuInfo as ExtendedRecyclerView.ContextMenuInfo
|
||||
val position = contextMenuInfo.position
|
||||
val adapter = adapter
|
||||
when (adapter.getItemViewType(position)) {
|
||||
VariousItemsAdapter.VIEW_TYPE_STATUS -> {
|
||||
val dummyAdapter = adapter.dummyAdapter
|
||||
|
|
|
@ -76,7 +76,6 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<Par
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableGroup>?>, data: List<ParcelableGroup>?) {
|
||||
val adapter = adapter
|
||||
adapter.setData(data)
|
||||
if (loader !is IExtendedLoader || loader.fromUser) {
|
||||
adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE
|
||||
|
@ -123,7 +122,6 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<Par
|
|||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
val adapter = adapter
|
||||
val layoutManager = layoutManager
|
||||
adapter.groupAdapterListener = this
|
||||
|
||||
|
|
|
@ -128,7 +128,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
refreshEnabled = true
|
||||
refreshing = false
|
||||
setLoadMoreIndicatorPosition(ILoadMoreSupportAdapter.NONE)
|
||||
val adapter = adapter
|
||||
if (adapter.itemCount > 0) {
|
||||
showContent()
|
||||
} else if (loader is MicroBlogAPIStatusesLoader) {
|
||||
|
@ -149,7 +148,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
if (position and ILoadMoreSupportAdapter.START !== 0L || refreshing) return
|
||||
super.onLoadMoreContents(position)
|
||||
if (position == 0L) return
|
||||
val adapter = adapter
|
||||
// Load the last item
|
||||
val idx = adapter.statusStartIndex + adapter.rawStatusCount - 1
|
||||
if (idx < 0) return
|
||||
|
@ -165,7 +163,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
fun replaceStatusStates(status: ParcelableStatus?) {
|
||||
if (status == null) return
|
||||
val lm = layoutManager
|
||||
val adapter = adapter
|
||||
val rangeStart = Math.max(adapter.statusStartIndex, lm.findFirstVisibleItemPosition())
|
||||
val rangeEnd = Math.min(lm.findLastVisibleItemPosition(), adapter.statusStartIndex + adapter.statusCount - 1)
|
||||
for (i in rangeStart..rangeEnd) {
|
||||
|
@ -183,7 +180,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
|||
|
||||
override fun triggerRefresh(): Boolean {
|
||||
super.triggerRefresh()
|
||||
val adapter = adapter
|
||||
val accountKeys = accountKeys
|
||||
if (adapter.statusCount > 0) {
|
||||
val firstStatus = adapter.getStatus(0)!!
|
||||
|
|
|
@ -78,7 +78,6 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment<
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableUserList>>, data: List<ParcelableUserList>) {
|
||||
val adapter = adapter
|
||||
adapter.setData(data)
|
||||
if (loader !is IExtendedLoader || loader.fromUser) {
|
||||
adapter.loadMoreSupportedPosition = if (hasMoreData(data)) ILoadMoreSupportAdapter.END else ILoadMoreSupportAdapter.NONE
|
||||
|
@ -129,7 +128,6 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment<
|
|||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
val adapter = adapter
|
||||
val layoutManager = layoutManager
|
||||
adapter.userListClickListener = this
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
|
|||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
val adapter = adapter
|
||||
adapter.userClickListener = this
|
||||
|
||||
navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter,
|
||||
|
@ -99,7 +98,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableUser>?>, data: List<ParcelableUser>?) {
|
||||
val adapter = adapter
|
||||
adapter.setData(data)
|
||||
if (loader !is IExtendedLoader || loader.fromUser) {
|
||||
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,
|
||||
layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? {
|
||||
val adapter = adapter
|
||||
val itemDecoration = DividerItemDecoration(context,
|
||||
(recyclerView.layoutManager as LinearLayoutManager).orientation)
|
||||
val res = context.resources
|
||||
|
@ -227,7 +224,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
|
|||
|
||||
@Subscribe
|
||||
fun onFriendshipTaskEvent(event: FriendshipTaskEvent) {
|
||||
val adapter = adapter
|
||||
val position = findPosition(event.accountKey, event.userKey)
|
||||
val data = adapter.getData() ?: return
|
||||
if (position < 0 || position >= data.size) return
|
||||
|
|
|
@ -120,7 +120,8 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
OnMediaClickListener, StatusClickListener, KeyboardShortcutCallback, ContentListSupport {
|
||||
private var mItemDecoration: DividerItemDecoration? = null
|
||||
|
||||
override var adapter: StatusAdapter? = null
|
||||
override lateinit var adapter: StatusAdapter
|
||||
private set
|
||||
|
||||
private var layoutManager: LinearLayoutManager? = null
|
||||
private var loadTranslationTask: LoadTranslationTask? = null
|
||||
|
@ -136,7 +137,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
// Listeners
|
||||
private val conversationsLoaderCallback = object : LoaderCallbacks<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.isConversationsLoading = true
|
||||
adapter.updateItemDecoration()
|
||||
|
@ -154,7 +155,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableStatus>>, data: List<ParcelableStatus>?) {
|
||||
val adapter = this@StatusFragment.adapter!!
|
||||
val adapter = this@StatusFragment.adapter
|
||||
adapter.updateItemDecoration()
|
||||
val conversationLoader = loader as ConversationLoader
|
||||
var supportedPositions: Long = 0
|
||||
|
@ -215,8 +216,8 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<StatusActivity?>, data: StatusActivity?) {
|
||||
adapter!!.updateItemDecoration()
|
||||
adapter!!.statusActivity = data
|
||||
adapter.updateItemDecoration()
|
||||
adapter.statusActivity = data
|
||||
}
|
||||
|
||||
override fun onLoaderReset(loader: Loader<StatusActivity?>) {
|
||||
|
@ -228,7 +229,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
val activity = activity ?: return
|
||||
when (requestCode) {
|
||||
REQUEST_SET_COLOR -> {
|
||||
val status = adapter!!.status ?: return
|
||||
val status = adapter.status ?: return
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) return
|
||||
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)
|
||||
}
|
||||
REQUEST_SELECT_ACCOUNT -> {
|
||||
val status = adapter!!.status ?: return
|
||||
val status = adapter.status ?: return
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null || !data.hasExtra(EXTRA_ID)) return
|
||||
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||
|
@ -271,12 +272,12 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
})
|
||||
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
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.clipToPadding = false
|
||||
adapter!!.statusClickListener = this
|
||||
adapter.statusClickListener = this
|
||||
recyclerView.adapter = adapter
|
||||
registerForContextMenu(recyclerView!!)
|
||||
|
||||
|
@ -285,7 +286,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
scrollListener!!.touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
|
||||
navigationHelper = RecyclerViewNavigationHelper(recyclerView!!, layoutManager!!,
|
||||
adapter!!, null)
|
||||
adapter, null)
|
||||
|
||||
setState(STATE_LOADING)
|
||||
|
||||
|
@ -293,12 +294,12 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
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,
|
||||
preferences.getBoolean(SharedPreferenceConstants.KEY_NEW_DOCUMENT_API))
|
||||
|
||||
val event = MediaEvent.create(activity, status, media, TimelineType.DETAILS,
|
||||
adapter!!.mediaPreviewEnabled)
|
||||
adapter.mediaPreviewEnabled)
|
||||
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) {
|
||||
val status = adapter!!.getStatus(position)
|
||||
val status = adapter.getStatus(position)
|
||||
AbsStatusesFragment.handleStatusActionClick(context, fragmentManager, twitterWrapper,
|
||||
holder as StatusViewHolder, status, id)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -329,20 +330,20 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
|
||||
override fun onUserProfileClick(holder: IStatusViewHolder, position: Int) {
|
||||
val activity = activity
|
||||
val status = adapter!!.getStatus(position)
|
||||
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)
|
||||
}
|
||||
|
||||
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
|
||||
IntentUtils.openMediaDirectly(activity, accountKey, status, media, null,
|
||||
preferences.getBoolean(KEY_NEW_DOCUMENT_API))
|
||||
// BEGIN HotMobi
|
||||
val event = MediaEvent.create(activity, status, media, TimelineType.OTHER,
|
||||
adapter!!.mediaPreviewEnabled)
|
||||
adapter.mediaPreviewEnabled)
|
||||
HotMobiLogger.getInstance(activity).log(status.account_key, event)
|
||||
// END HotMobi
|
||||
}
|
||||
|
@ -359,7 +360,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
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
|
||||
when (action) {
|
||||
ACTION_STATUS_REPLY -> {
|
||||
|
@ -416,17 +417,17 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
val readPosition = saveReadPosition()
|
||||
val dataExtra = data.extras
|
||||
val details: AccountDetails = dataExtra.getParcelable(EXTRA_ACCOUNT)
|
||||
if (adapter!!.setStatus(status, details)) {
|
||||
if (adapter.setStatus(status, details)) {
|
||||
val args = arguments
|
||||
if (args.containsKey(EXTRA_STATUS)) {
|
||||
args.putParcelable(EXTRA_STATUS, status)
|
||||
}
|
||||
adapter!!.loadMoreSupportedPosition = ILoadMoreSupportAdapter.BOTH
|
||||
adapter!!.setData(null)
|
||||
adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.BOTH
|
||||
adapter.setData(null)
|
||||
loadConversation(status, null, null)
|
||||
loadActivity(status)
|
||||
|
||||
val position = adapter!!.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
|
||||
val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
layoutManager!!.scrollToPositionWithOffset(position, 0)
|
||||
}
|
||||
|
@ -440,7 +441,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
setState(STATE_LOADED)
|
||||
} else {
|
||||
adapter!!.loadMoreSupportedPosition = ILoadMoreSupportAdapter.NONE
|
||||
adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.NONE
|
||||
setState(STATE_ERROR)
|
||||
errorText.text = Utils.getErrorMessage(context, data.exception)
|
||||
}
|
||||
|
@ -459,15 +460,15 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
if (adapter.status != null) {
|
||||
val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
|
||||
recyclerView!!.smoothScrollToPosition(position)
|
||||
}
|
||||
return true
|
||||
|
@ -478,7 +479,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
|
||||
private fun setConversation(data: List<ParcelableStatus>?) {
|
||||
val readPosition = saveReadPosition()
|
||||
val changed = adapter!!.setData(data)
|
||||
val changed = adapter.setData(data)
|
||||
hasMoreConversation = data != null && changed
|
||||
restoreReadPosition(readPosition)
|
||||
}
|
||||
|
@ -489,16 +490,16 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
override fun onLoadMoreContents(@IndicatorPosition position: Long) {
|
||||
if (!hasMoreConversation) return
|
||||
if (position and ILoadMoreSupportAdapter.START !== 0L) {
|
||||
val start = adapter!!.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION)
|
||||
val status = adapter!!.getStatus(start)
|
||||
val start = adapter.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION)
|
||||
val status = adapter.getStatus(start)
|
||||
if (status == null || status.in_reply_to_status_id == null) return
|
||||
loadConversation(status, null, status.id)
|
||||
} else if (position and ILoadMoreSupportAdapter.END !== 0L) {
|
||||
val start = adapter!!.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION)
|
||||
val status = adapter!!.getStatus(start + adapter!!.statusCount - 1) ?: return
|
||||
val start = adapter.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION)
|
||||
val status = adapter.getStatus(start + adapter.statusCount - 1) ?: return
|
||||
loadConversation(status, status.id, null)
|
||||
}
|
||||
adapter!!.loadMoreIndicatorPosition = position
|
||||
adapter.loadMoreIndicatorPosition = position
|
||||
}
|
||||
|
||||
override fun setControlVisible(visible: Boolean) {
|
||||
|
@ -506,13 +507,13 @@ 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
|
||||
|
||||
private val status: ParcelableStatus?
|
||||
get() = adapter!!.status
|
||||
get() = adapter.status
|
||||
|
||||
private fun loadConversation(status: ParcelableStatus?, sinceId: String?, maxId: String?) {
|
||||
if (status == null || activity == null) return
|
||||
|
@ -555,7 +556,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
|
||||
|
||||
private fun displayTranslation(translation: TranslationResult) {
|
||||
adapter?.translationResult = translation
|
||||
adapter.translationResult = translation
|
||||
val status = this.status
|
||||
val context = this.context ?: return
|
||||
if (status != null) {
|
||||
|
@ -566,7 +567,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
|
||||
private fun saveReadPosition(): ReadPosition? {
|
||||
val lm = layoutManager ?: return null
|
||||
val adapter = this.adapter ?: return null
|
||||
val adapter = this.adapter
|
||||
val position = lm.findFirstVisibleItemPosition()
|
||||
if (position == RecyclerView.NO_POSITION) return null
|
||||
val itemType = adapter.getItemType(position)
|
||||
|
@ -583,7 +584,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
}
|
||||
|
||||
private fun restoreReadPosition(position: ReadPosition?) {
|
||||
val adapter = this.adapter ?: return
|
||||
val adapter = this.adapter
|
||||
if (position == null) return
|
||||
val adapterPosition = adapter.findPositionByItemId(position.statusId)
|
||||
if (adapterPosition < 0) return
|
||||
|
@ -619,7 +620,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
if (!userVisibleHint || menuInfo == null) return
|
||||
val inflater = MenuInflater(context)
|
||||
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)
|
||||
MenuUtils.setupForStatus(context, preferences, menu, status!!,
|
||||
twitterWrapper)
|
||||
|
@ -628,7 +629,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
override fun onContextItemSelected(item: MenuItem?): Boolean {
|
||||
if (!userVisibleHint) return false
|
||||
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) {
|
||||
val shareIntent = Utils.createStatusShareIntent(activity, status)
|
||||
val chooser = Intent.createChooser(shareIntent, getString(R.string.share_status))
|
||||
|
@ -641,15 +642,13 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
|
||||
@Subscribe
|
||||
fun notifyStatusListChanged(event: StatusListChangedEvent) {
|
||||
val adapter = adapter
|
||||
adapter!!.notifyDataSetChanged()
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun notifyFavoriteTask(event: FavoriteTaskEvent) {
|
||||
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) {
|
||||
when (event.action) {
|
||||
FavoriteTaskEvent.Action.CREATE -> {
|
||||
|
@ -675,7 +674,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
val f = parentFragment
|
||||
if (f is StatusFragment) {
|
||||
val adapter = f.adapter
|
||||
adapter!!.isDetailMediaExpanded = true
|
||||
adapter.isDetailMediaExpanded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ class UserListMembersFragment : CursorSupportUsersListFragment() {
|
|||
val accountId = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
if (accountId == null || accountId != userKey) return
|
||||
val adapter = adapter
|
||||
val inflater = MenuInflater(context)
|
||||
val contextMenuInfo = menuInfo as ExtendedRecyclerView.ContextMenuInfo?
|
||||
inflater.inflate(R.menu.action_user_list_member, menu)
|
||||
|
@ -132,7 +131,6 @@ class UserListMembersFragment : CursorSupportUsersListFragment() {
|
|||
}
|
||||
when (event.action) {
|
||||
UserListMembersChangedEvent.Action.ADDED -> {
|
||||
val adapter = adapter
|
||||
val newUsers = Arrays.asList(*event.users)
|
||||
val users = adapter.getData() ?: return
|
||||
if (users is MutableList) {
|
||||
|
@ -143,7 +141,6 @@ class UserListMembersFragment : CursorSupportUsersListFragment() {
|
|||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
UserListMembersChangedEvent.Action.REMOVED -> {
|
||||
val adapter = adapter
|
||||
val removedUsers = Arrays.asList(*event.users)
|
||||
val users = adapter.getData() ?: return
|
||||
if (users is MutableList) {
|
||||
|
|
|
@ -101,7 +101,6 @@ class UserListsFragment : ParcelableUserListsFragment() {
|
|||
}
|
||||
|
||||
private fun removeUserList(id: String) {
|
||||
val adapter = adapter
|
||||
// final int listsIdx = adapter.findItemPosition(id);
|
||||
// if (listsIdx >= 0) {
|
||||
// adapter.removeAt(listsIdx);
|
||||
|
|
|
@ -47,7 +47,6 @@ class UserMediaTimelineFragment : AbsContentRecyclerViewFragment<StaggeredGridPa
|
|||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
val adapter = adapter
|
||||
adapter.statusClickListener = this
|
||||
val loaderArgs = Bundle(arguments)
|
||||
loaderArgs.putBoolean(EXTRA_FROM_USER, true)
|
||||
|
@ -99,7 +98,6 @@ class UserMediaTimelineFragment : AbsContentRecyclerViewFragment<StaggeredGridPa
|
|||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ParcelableStatus>>, data: List<ParcelableStatus>?) {
|
||||
val adapter = adapter
|
||||
val changed = adapter.setData(data)
|
||||
if ((loader as IExtendedLoader).fromUser && loader is MediaTimelineLoader) {
|
||||
val maxId = loader.maxId
|
||||
|
@ -138,7 +136,6 @@ class UserMediaTimelineFragment : AbsContentRecyclerViewFragment<StaggeredGridPa
|
|||
if (position and ILoadMoreSupportAdapter.START != 0L) return
|
||||
super.onLoadMoreContents(position)
|
||||
if (position == 0L) return
|
||||
val adapter = adapter
|
||||
val maxId = adapter.getStatusId(adapter.statusCount - 1)
|
||||
getStatuses(maxId, null)
|
||||
}
|
||||
|
|
|
@ -99,7 +99,6 @@ class UserTimelineFragment : ParcelableStatusesFragment() {
|
|||
|
||||
override fun onStatusesLoaded(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) {
|
||||
val timelineLoader = loader as UserTimelineLoader
|
||||
val adapter = adapter
|
||||
if (!adapter.hasPinnedStatuses) {
|
||||
adapter.pinnedStatuses = timelineLoader.pinnedStatuses
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue