|
|
|
@ -31,6 +31,7 @@ import android.view.View |
|
|
|
|
import android.widget.ImageView |
|
|
|
|
import androidx.appcompat.app.ActionBarDrawerToggle |
|
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout |
|
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
import androidx.core.content.pm.ShortcutManagerCompat |
|
|
|
|
import androidx.emoji.text.EmojiCompat |
|
|
|
@ -59,7 +60,10 @@ import com.keylesspalace.tusky.interfaces.ActionButtonActivity |
|
|
|
|
import com.keylesspalace.tusky.interfaces.ReselectableFragment |
|
|
|
|
import com.keylesspalace.tusky.pager.MainPagerAdapter |
|
|
|
|
import com.keylesspalace.tusky.util.* |
|
|
|
|
import com.mikepenz.iconics.IconicsDrawable |
|
|
|
|
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial |
|
|
|
|
import com.mikepenz.iconics.utils.colorInt |
|
|
|
|
import com.mikepenz.iconics.utils.sizeDp |
|
|
|
|
import com.mikepenz.materialdrawer.iconics.iconicsIcon |
|
|
|
|
import com.mikepenz.materialdrawer.model.* |
|
|
|
|
import com.mikepenz.materialdrawer.model.interfaces.* |
|
|
|
@ -89,8 +93,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje |
|
|
|
|
private lateinit var drawerToggle: ActionBarDrawerToggle |
|
|
|
|
|
|
|
|
|
private var notificationTabPosition = 0 |
|
|
|
|
|
|
|
|
|
private var adapter: MainPagerAdapter? = null |
|
|
|
|
private var onTabSelectedListener: OnTabSelectedListener? = null |
|
|
|
|
|
|
|
|
|
private val emojiInitCallback = object : InitCallback() { |
|
|
|
|
override fun onInitialized() { |
|
|
|
@ -160,6 +163,19 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje |
|
|
|
|
val composeIntent = Intent(applicationContext, ComposeActivity::class.java) |
|
|
|
|
startActivity(composeIntent) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mainToolbar.menu.add(R.string.action_search).apply { |
|
|
|
|
setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM) |
|
|
|
|
icon = IconicsDrawable(this@MainActivity, GoogleMaterial.Icon.gmd_search).apply { |
|
|
|
|
sizeDp = 20 |
|
|
|
|
colorInt = ThemeUtils.getColor(this@MainActivity, android.R.attr.textColorPrimary) |
|
|
|
|
} |
|
|
|
|
setOnMenuItemClickListener { |
|
|
|
|
startActivity(SearchActivity.getIntent(this@MainActivity)) |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setupDrawer(savedInstanceState) |
|
|
|
|
|
|
|
|
|
/* Fetch user info while we're doing other things. This has to be done after setting up the |
|
|
|
@ -168,30 +184,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje |
|
|
|
|
|
|
|
|
|
setupTabs(showNotificationTab) |
|
|
|
|
|
|
|
|
|
val pageMargin = resources.getDimensionPixelSize(R.dimen.tab_page_margin) |
|
|
|
|
viewPager.setPageTransformer(MarginPageTransformer(pageMargin)) |
|
|
|
|
|
|
|
|
|
val uswSwipeForTabs = PreferenceManager.getDefaultSharedPreferences(this) |
|
|
|
|
.getBoolean("enableSwipeForTabs", true) |
|
|
|
|
viewPager.isUserInputEnabled = uswSwipeForTabs |
|
|
|
|
|
|
|
|
|
tabLayout.addOnTabSelectedListener(object : OnTabSelectedListener { |
|
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
|
if (tab.position == notificationTabPosition) { |
|
|
|
|
NotificationHelper.clearNotificationsForActiveAccount(this@MainActivity, accountManager) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) {} |
|
|
|
|
|
|
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) { |
|
|
|
|
val fragment = adapter?.getFragment(tab.position) |
|
|
|
|
if (fragment is ReselectableFragment) { |
|
|
|
|
(fragment as ReselectableFragment).onReselect() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// Setup push notifications |
|
|
|
|
if (NotificationHelper.areNotificationsEnabled(this, accountManager)) { |
|
|
|
|
NotificationHelper.enablePullNotifications(this) |
|
|
|
@ -377,13 +369,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje |
|
|
|
|
startActivityWithSlideInAnimation(ListsActivity.newIntent(context)) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
primaryDrawerItem { |
|
|
|
|
nameRes = R.string.action_search |
|
|
|
|
iconicsIcon = GoogleMaterial.Icon.gmd_search |
|
|
|
|
onClick = { |
|
|
|
|
startActivityWithSlideInAnimation(SearchActivity.getIntent(context)) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
primaryDrawerItem { |
|
|
|
|
nameRes = R.string.action_access_saved_toot |
|
|
|
|
iconRes = R.drawable.ic_notebook |
|
|
|
@ -462,20 +447,37 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun setupTabs(selectNotificationTab: Boolean) { |
|
|
|
|
val preferences = PreferenceManager.getDefaultSharedPreferences(this) |
|
|
|
|
|
|
|
|
|
val activeTabLayout = if(preferences.getString("mainNavPosition", "top") == "bottom") { |
|
|
|
|
val actionBarSize = ThemeUtils.getDimension(this, R.attr.actionBarSize) |
|
|
|
|
val fabMargin = resources.getDimensionPixelSize(R.dimen.fabMargin) |
|
|
|
|
(composeButton.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = actionBarSize + fabMargin |
|
|
|
|
tabLayout.hide() |
|
|
|
|
bottomTabLayout |
|
|
|
|
} else { |
|
|
|
|
bottomNav.hide() |
|
|
|
|
(viewPager.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = 0 |
|
|
|
|
(composeButton.layoutParams as CoordinatorLayout.LayoutParams).anchorId = R.id.viewPager |
|
|
|
|
tabLayout |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val tabs = accountManager.activeAccount!!.tabPreferences |
|
|
|
|
adapter = MainPagerAdapter(tabs, this) |
|
|
|
|
|
|
|
|
|
val adapter = MainPagerAdapter(tabs, this) |
|
|
|
|
viewPager.adapter = adapter |
|
|
|
|
TabLayoutMediator(tabLayout, viewPager, TabConfigurationStrategy { _: TabLayout.Tab?, _: Int -> }).attach() |
|
|
|
|
tabLayout.removeAllTabs() |
|
|
|
|
TabLayoutMediator(activeTabLayout, viewPager, TabConfigurationStrategy { _: TabLayout.Tab?, _: Int -> }).attach() |
|
|
|
|
activeTabLayout.removeAllTabs() |
|
|
|
|
for (i in tabs.indices) { |
|
|
|
|
val tab = tabLayout.newTab() |
|
|
|
|
val tab = activeTabLayout.newTab() |
|
|
|
|
.setIcon(tabs[i].icon) |
|
|
|
|
if (tabs[i].id == LIST) { |
|
|
|
|
tab.contentDescription = tabs[i].arguments[1] |
|
|
|
|
} else { |
|
|
|
|
tab.setContentDescription(tabs[i].text) |
|
|
|
|
} |
|
|
|
|
tabLayout.addTab(tab) |
|
|
|
|
activeTabLayout.addTab(tab) |
|
|
|
|
|
|
|
|
|
if (tabs[i].id == NOTIFICATIONS) { |
|
|
|
|
notificationTabPosition = i |
|
|
|
|
if (selectNotificationTab) { |
|
|
|
@ -483,6 +485,40 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val pageMargin = resources.getDimensionPixelSize(R.dimen.tab_page_margin) |
|
|
|
|
viewPager.setPageTransformer(MarginPageTransformer(pageMargin)) |
|
|
|
|
|
|
|
|
|
val uswSwipeForTabs = preferences.getBoolean("enableSwipeForTabs", true) |
|
|
|
|
viewPager.isUserInputEnabled = uswSwipeForTabs |
|
|
|
|
|
|
|
|
|
onTabSelectedListener?.let { |
|
|
|
|
activeTabLayout.removeOnTabSelectedListener(it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onTabSelectedListener = object : OnTabSelectedListener { |
|
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
|
if (tab.position == notificationTabPosition) { |
|
|
|
|
NotificationHelper.clearNotificationsForActiveAccount(this@MainActivity, accountManager) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mainToolbar.title = tabs[tab.position].title(this@MainActivity) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) {} |
|
|
|
|
|
|
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) { |
|
|
|
|
val fragment = adapter.getFragment(tab.position) |
|
|
|
|
if (fragment is ReselectableFragment) { |
|
|
|
|
(fragment as ReselectableFragment).onReselect() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.also { |
|
|
|
|
activeTabLayout.addOnTabSelectedListener(it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mainToolbar.title = tabs[0].title(this@MainActivity) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun handleProfileClick(profile: IProfile, current: Boolean): Boolean { |
|
|
|
|