diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt index e073ed083..cb2c44b5e 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt @@ -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) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt index 112710ead..9af4c9bf3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt @@ -217,14 +217,10 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec } protected fun saveReadPosition() { - val layoutManager = layoutManager - if (layoutManager != null) { - saveReadPosition(layoutManager.findFirstVisibleItemPosition()) - } + saveReadPosition(layoutManager.findFirstVisibleItemPosition()) } override fun onLoadFinished(loader: Loader>, data: List) { - 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 { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListViewFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListViewFragment.kt index 254f270bf..be1154402 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListViewFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListViewFragment.kt @@ -42,12 +42,12 @@ import org.mariotaku.twidere.util.TwidereColorUtils * Created by mariotaku on 15/4/16. */ abstract class AbsContentListViewFragment : 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 : 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 : 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 : 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) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsStatusesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsStatusesFragment.kt index 614cd735d..2f6799615 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsStatusesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsStatusesFragment.kt @@ -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?>, data: List?) { - 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) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt index 4557ede68..30d82452a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt @@ -169,7 +169,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment, data: Cursor?) { - val adapter = adapter adapter!!.swapCursor(data) if (data != null && data.count > 0) { showContent() @@ -179,7 +178,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment) { - val adapter = adapter adapter!!.swapCursor(null) } @@ -254,15 +252,15 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment 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) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt index eeea4ccdb..b1acd9a0b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt @@ -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 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt index c022f9b8a..e5344616f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt @@ -73,7 +73,7 @@ import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks, 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, 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, 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, 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, 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, Mult override fun onLoaderReset(loader: Loader) { - adapter!!.changeCursor(null) + adapter.changeCursor(null) } override fun onLoadFinished(loader: Loader, cursor: Cursor?) { - adapter!!.changeCursor(cursor) + adapter.changeCursor(cursor) setListShown(true) } @@ -242,8 +241,8 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks, 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, Mult extraConfigContainer.addView(view) } - accountSpinner.onItemSelectedListener = object :AdapterView.OnItemSelectedListener { + accountSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { private fun updateExtraTabs(account: AccountDetails?) { extraConfigurations.forEach { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtensionsListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtensionsListFragment.kt index 717ab0752..222a8e8e2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtensionsListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtensionsListFragment.kt @@ -44,7 +44,6 @@ import org.mariotaku.twidere.util.PermissionsManager class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks> { - private var adapter: ExtensionsAdapter? = null private var packageManager: PackageManager? = null private var permissionsManager: PermissionsManager? = null @@ -52,8 +51,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks>, data: List) { - adapter!!.setData(data) + (listAdapter as ExtensionsAdapter).setData(data) setListShown(true) } override fun onLoaderReset(loader: Loader>) { - 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 { openSettings(extensionInfo) @@ -113,7 +111,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks { permissionsManager!!.revoke(extensionInfo.pname) - adapter!!.notifyDataSetChanged() + (listAdapter as ExtensionsAdapter).notifyDataSetChanged() } else -> { return false diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt index abcc59cd2..bdbf7f048 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt @@ -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) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ItemsListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ItemsListFragment.kt index 468ec7f0f..82a7e3814 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ItemsListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ItemsListFragment.kt @@ -116,7 +116,6 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment { val dummyAdapter = adapter.dummyAdapter @@ -132,7 +131,6 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment { val dummyAdapter = adapter.dummyAdapter diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt index 2d46a60ca..a8b1f09f2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt @@ -76,7 +76,6 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment?>, data: List?) { - 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 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)!! diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt index d162d00f2..6d7851797 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt @@ -78,7 +78,6 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment< } override fun onLoadFinished(loader: Loader>, data: List) { - 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 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt index 00a72df89..8e214e6ef 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt @@ -63,7 +63,6 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?>, data: List?) { - 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= data.size) return diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt index 360a775d3..628ebda36 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt @@ -120,7 +120,8 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks> { override fun onCreateLoader(id: Int, args: Bundle): Loader> { - 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>, data: List?) { - 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, data: StatusActivity?) { - adapter!!.updateItemDecoration() - adapter!!.statusActivity = data + adapter.updateItemDecoration() + adapter.statusActivity = data } override fun onLoaderReset(loader: Loader) { @@ -228,7 +229,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks { - 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 { - 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(EXTRA_ACCOUNT_KEY) @@ -271,12 +272,12 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks { @@ -416,17 +417,17 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks { - 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?) { 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= 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 { @@ -675,7 +674,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(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) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsFragment.kt index 023283bfa..9707dcfe6 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsFragment.kt @@ -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); diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt index 0e4dd5328..01b06e709 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt @@ -47,7 +47,6 @@ class UserMediaTimelineFragment : AbsContentRecyclerViewFragment>, data: List?) { - 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?>, data: List?) { val timelineLoader = loader as UserTimelineLoader - val adapter = adapter if (!adapter.hasPinnedStatuses) { adapter.pinnedStatuses = timelineLoader.pinnedStatuses }