mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-24 23:57:30 +00:00
Fix toolbar race condition
This commit is contained in:
parent
fae25ff690
commit
0715819eeb
@ -78,8 +78,7 @@ class MainActivity : BaseLanguageActivity() {
|
|||||||
private var userId: Long = 0
|
private var userId: Long = 0
|
||||||
private var toolbarOwner: Fragment? = null
|
private var toolbarOwner: Fragment? = null
|
||||||
|
|
||||||
lateinit var toolbar: Toolbar
|
private lateinit var toolbar: Toolbar
|
||||||
private set
|
|
||||||
|
|
||||||
var currentTabs: List<Tab> = emptyList()
|
var currentTabs: List<Tab> = emptyList()
|
||||||
private set
|
private set
|
||||||
@ -610,16 +609,6 @@ class MainActivity : BaseLanguageActivity() {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
fun resetToolbar(owner: Fragment) {
|
|
||||||
if (owner != toolbarOwner) return
|
|
||||||
binding.appBarLayout.visibility = View.VISIBLE
|
|
||||||
setScrollingBehaviour()
|
|
||||||
setSupportActionBar(binding.toolbar)
|
|
||||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
|
||||||
toolbarOwner = null
|
|
||||||
}
|
|
||||||
|
|
||||||
val collapsingToolbarView: CollapsingToolbarLayout
|
val collapsingToolbarView: CollapsingToolbarLayout
|
||||||
get() = binding.collapsingToolbarLayout
|
get() = binding.collapsingToolbarLayout
|
||||||
val appbarLayout: AppBarLayout
|
val appbarLayout: AppBarLayout
|
||||||
@ -658,8 +647,11 @@ class MainActivity : BaseLanguageActivity() {
|
|||||||
val rootView: View
|
val rootView: View
|
||||||
get() = binding.root
|
get() = binding.root
|
||||||
|
|
||||||
@Synchronized
|
private val toolbarLock = Any()
|
||||||
fun setToolbar(toolbar: Toolbar, owner: Fragment) {
|
|
||||||
|
fun getToolbar() = synchronized(toolbarLock) { this.toolbar }
|
||||||
|
|
||||||
|
fun setToolbar(toolbar: Toolbar, owner: Fragment) = synchronized(toolbarLock) {
|
||||||
toolbarOwner = owner
|
toolbarOwner = owner
|
||||||
binding.appBarLayout.visibility = View.GONE
|
binding.appBarLayout.visibility = View.GONE
|
||||||
removeScrollingBehaviour()
|
removeScrollingBehaviour()
|
||||||
@ -668,6 +660,16 @@ class MainActivity : BaseLanguageActivity() {
|
|||||||
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)
|
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetToolbar(owner: Fragment) = synchronized(toolbarLock) {
|
||||||
|
if (owner != toolbarOwner) return
|
||||||
|
this.toolbar = binding.toolbar
|
||||||
|
setSupportActionBar(binding.toolbar)
|
||||||
|
binding.appBarLayout.visibility = View.VISIBLE
|
||||||
|
setScrollingBehaviour()
|
||||||
|
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
|
toolbarOwner = null
|
||||||
|
}
|
||||||
|
|
||||||
private fun setNavBarDMUnreadCountBadge(unseenCount: Int) {
|
private fun setNavBarDMUnreadCountBadge(unseenCount: Int) {
|
||||||
val badge = binding.bottomNavView.getOrCreateBadge(R.id.direct_messages_nav_graph)
|
val badge = binding.bottomNavView.getOrCreateBadge(R.id.direct_messages_nav_graph)
|
||||||
if (unseenCount == 0) {
|
if (unseenCount == 0) {
|
||||||
|
@ -364,18 +364,8 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onStop() {
|
||||||
super.onDestroy();
|
super.onStop();
|
||||||
resetToolbar();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
resetToolbar();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetToolbar() {
|
|
||||||
fragmentActivity.resetToolbar(this);
|
fragmentActivity.resetToolbar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,8 +339,8 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onStop() {
|
||||||
super.onDestroyView();
|
super.onStop();
|
||||||
fragmentActivity.resetToolbar(this);
|
fragmentActivity.resetToolbar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,8 +333,8 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onStop() {
|
||||||
super.onDestroyView();
|
super.onStop();
|
||||||
fragmentActivity.resetToolbar(this);
|
fragmentActivity.resetToolbar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,18 +278,8 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onStop() {
|
||||||
super.onDestroy();
|
super.onStop();
|
||||||
resetToolbar();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
resetToolbar();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetToolbar() {
|
|
||||||
fragmentActivity.resetToolbar(this);
|
fragmentActivity.resetToolbar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,8 +368,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateSwipeRefreshState() {
|
private void updateSwipeRefreshState() {
|
||||||
AppExecutors.INSTANCE.getMainThread().execute(() ->
|
AppExecutors.INSTANCE.getMainThread().execute(() -> binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching())
|
||||||
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ class DirectMessageInboxFragment : Fragment(), OnRefreshListener {
|
|||||||
super.onPause()
|
super.onPause()
|
||||||
isPendingRequestTotalBadgeAttached = false
|
isPendingRequestTotalBadgeAttached = false
|
||||||
pendingRequestsMenuItem?.let {
|
pendingRequestsMenuItem?.let {
|
||||||
val menuItemView = ToolbarUtils.getActionMenuItemView(fragmentActivity.toolbar, it.itemId)
|
val menuItemView = ToolbarUtils.getActionMenuItemView(fragmentActivity.getToolbar(), it.itemId)
|
||||||
if (menuItemView != null) {
|
if (menuItemView != null) {
|
||||||
BadgeUtils.detachBadgeDrawable(pendingRequestTotalBadgeDrawable, fragmentActivity.toolbar, it.itemId)
|
BadgeUtils.detachBadgeDrawable(pendingRequestTotalBadgeDrawable, fragmentActivity.getToolbar(), it.itemId)
|
||||||
pendingRequestTotalBadgeDrawable = null
|
pendingRequestTotalBadgeDrawable = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,11 +145,11 @@ class DirectMessageInboxFragment : Fragment(), OnRefreshListener {
|
|||||||
}
|
}
|
||||||
if (count == null || count == 0) {
|
if (count == null || count == 0) {
|
||||||
val menuItemView = ToolbarUtils.getActionMenuItemView(
|
val menuItemView = ToolbarUtils.getActionMenuItemView(
|
||||||
fragmentActivity.toolbar,
|
fragmentActivity.getToolbar(),
|
||||||
pendingRequestsMenuItem1.itemId
|
pendingRequestsMenuItem1.itemId
|
||||||
)
|
)
|
||||||
if (menuItemView != null) {
|
if (menuItemView != null) {
|
||||||
BadgeUtils.detachBadgeDrawable(pendingRequestTotalBadgeDrawable, fragmentActivity.toolbar, pendingRequestsMenuItem1.itemId)
|
BadgeUtils.detachBadgeDrawable(pendingRequestTotalBadgeDrawable, fragmentActivity.getToolbar(), pendingRequestsMenuItem1.itemId)
|
||||||
}
|
}
|
||||||
isPendingRequestTotalBadgeAttached = false
|
isPendingRequestTotalBadgeAttached = false
|
||||||
pendingRequestTotalBadgeDrawable?.number = 0
|
pendingRequestTotalBadgeDrawable?.number = 0
|
||||||
@ -161,7 +161,7 @@ class DirectMessageInboxFragment : Fragment(), OnRefreshListener {
|
|||||||
pendingRequestTotalBadgeDrawable?.number = count
|
pendingRequestTotalBadgeDrawable?.number = count
|
||||||
if (!isPendingRequestTotalBadgeAttached) {
|
if (!isPendingRequestTotalBadgeAttached) {
|
||||||
pendingRequestTotalBadgeDrawable?.let {
|
pendingRequestTotalBadgeDrawable?.let {
|
||||||
BadgeUtils.attachBadgeDrawable(it, fragmentActivity.toolbar, pendingRequestsMenuItem1.itemId)
|
BadgeUtils.attachBadgeDrawable(it, fragmentActivity.getToolbar(), pendingRequestsMenuItem1.itemId)
|
||||||
isPendingRequestTotalBadgeAttached = true
|
isPendingRequestTotalBadgeAttached = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,9 +336,9 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
fragmentActivity.resetToolbar(this);
|
fragmentActivity.resetToolbar(this);
|
||||||
super.onDestroyView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupFeed() {
|
private void setupFeed() {
|
||||||
|
@ -391,8 +391,12 @@ class ProfileFragment : Fragment(), OnRefreshListener, ConfirmDialogFragmentCall
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
mainActivity.resetToolbar(this)
|
mainActivity.resetToolbar(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
setupPostsDone = false
|
setupPostsDone = false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user