From 2b0f519ca54c9bc67de7015e69c2d720f0180397 Mon Sep 17 00:00:00 2001 From: Steven Schoen Date: Wed, 26 Dec 2018 15:28:27 -0500 Subject: [PATCH] Update styles, fix UI issues, remove AHBottomNav --- app/build.gradle | 1 - .../stevenschoen/putionew/PutioActivity.kt | 117 ++++++++---------- .../putionew/files/FilesFragment.kt | 30 ++--- .../add/DestinationPickerFragment.kt | 8 +- app/src/main/res/anim/bottomnav_enter.xml | 16 --- app/src/main/res/anim/bottomnav_exit.xml | 8 -- app/src/main/res/animator/bottomnav_enter.xml | 16 +++ app/src/main/res/animator/bottomnav_exit.xml | 6 + .../main/res/color/bottom_nav_item_tint.xml | 5 + .../main/res/layout/destination_activity.xml | 17 ++- app/src/main/res/layout/file_list.xml | 3 +- app/src/main/res/layout/main.xml | 4 +- app/src/main/res/values/styles.xml | 31 +++-- 13 files changed, 132 insertions(+), 130 deletions(-) delete mode 100644 app/src/main/res/anim/bottomnav_enter.xml delete mode 100644 app/src/main/res/anim/bottomnav_exit.xml create mode 100644 app/src/main/res/animator/bottomnav_enter.xml create mode 100644 app/src/main/res/animator/bottomnav_exit.xml create mode 100644 app/src/main/res/color/bottom_nav_item_tint.xml diff --git a/app/build.gradle b/app/build.gradle index bfc77fd1..960c39b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -93,7 +93,6 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar' implementation 'com.squareup.picasso:picasso:2.71828' - implementation 'com.aurelhubert:ahbottomnavigation:2.2.0' implementation 'com.google.android.exoplayer:exoplayer:2.8.1' def roomVersion = '2.0.0' implementation "androidx.room:room-runtime:$roomVersion" diff --git a/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt b/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt index 33d85236..44401639 100644 --- a/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt +++ b/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt @@ -8,23 +8,20 @@ import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.IntentFilter -import android.graphics.Color import android.os.Bundle import android.preference.PreferenceManager import android.view.Menu import android.view.MenuItem import android.view.View import androidx.appcompat.widget.Toolbar -import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.interpolator.view.animation.FastOutSlowInInterpolator -import com.aurelhubert.ahbottomnavigation.AHBottomNavigation -import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem +import com.google.android.material.bottomnavigation.BottomNavigationView +import com.stevenschoen.putionew.account.AccountFragment import com.stevenschoen.putionew.cast.BaseCastActivity import com.stevenschoen.putionew.files.FileDownloadsMaintenanceService import com.stevenschoen.putionew.files.FilesFragment import com.stevenschoen.putionew.files.FolderLoader -import com.stevenschoen.putionew.account.AccountFragment import com.stevenschoen.putionew.model.files.PutioFile import com.stevenschoen.putionew.model.transfers.PutioTransfer import com.stevenschoen.putionew.transfers.TransfersFragment @@ -34,27 +31,11 @@ import java.util.concurrent.TimeUnit class PutioActivity : BaseCastActivity() { - companion object { - const val EXTRA_GO_TO_TAB = "go_to_tab" - - const val TAB_ACCOUNT = 0 - const val TAB_FILES = 1 - const val TAB_TRANSFERS = 2 - - const val FRAGTAG_ACCOUNT = "account" - const val FRAGTAG_FILES = "files" - const val FRAGTAG_TRANSFERS = "transfers" - - const val STATE_CURRENT_TAB = "current_tab" - - const val noNetworkIntent = "com.stevenschoen.putionew.nonetwork" - } - var init = false - val sharedPrefs by lazy { PreferenceManager.getDefaultSharedPreferences(this) } + val sharedPrefs by lazy { PreferenceManager.getDefaultSharedPreferences(this)!! } - lateinit var bottomNavView: AHBottomNavigation + lateinit var bottomNavView: BottomNavigationView lateinit var addTransferView: View var showingAddTransferFab = true @@ -131,20 +112,14 @@ class PutioActivity : BaseCastActivity() { } if (intent.action != null) { - if (intent.action == Intent.ACTION_SEARCH && filesFragment != null) { + if (intent.action == Intent.ACTION_SEARCH) { val query = intent.getStringExtra(SearchManager.QUERY) - filesFragment!!.addSearch(query) + filesFragment.addSearch(query) } } } } - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - - outState.putInt(STATE_CURRENT_TAB, bottomNavView.currentItem) - } - override fun onCreateOptionsMenu(menu: Menu): Boolean { super.onCreateOptionsMenu(menu) menuInflater.inflate(R.menu.menu_putio, menu) @@ -173,6 +148,8 @@ class PutioActivity : BaseCastActivity() { setContentView(R.layout.main) + setupLayout() + if (savedInstanceState == null) { val accountFragment = Fragment.instantiate(this, AccountFragment::class.java.name) as AccountFragment val filesFragment = FilesFragment.newInstance(this, null) @@ -185,18 +162,15 @@ class PutioActivity : BaseCastActivity() { .add(R.id.main_content_holder, transfersFragment, FRAGTAG_TRANSFERS) .detach(transfersFragment) .commitNow() - } - setupLayout() - - val navItem = savedInstanceState?.getInt(STATE_CURRENT_TAB, TAB_FILES) ?: TAB_FILES - selectTab(navItem, false) + selectTab(TAB_FILES, false) + } addTransferView = findViewById(R.id.main_addtransfer) addTransferView.setOnClickListener { var destinationFolder: PutioFile? = null - if (bottomNavView.currentItem == TAB_FILES) { - destinationFolder = (filesFragment!!.currentPage as FilesFragment.Page.File).file + if (bottomNavView.selectedItemId == TAB_FILES) { + destinationFolder = (filesFragment.currentPage as FilesFragment.Page.File).file } val addTransferIntent = Intent(this@PutioActivity, AddTransferActivity::class.java) if (destinationFolder != null) { @@ -275,11 +249,11 @@ class PutioActivity : BaseCastActivity() { } private fun shouldShowAddTransferFab(): Boolean { - return when (bottomNavView.currentItem) { + return when (bottomNavView.selectedItemId) { TAB_ACCOUNT -> false TAB_FILES -> { val filesFragment = filesFragment - if (filesFragment!!.isSelecting) { + if (filesFragment.isSelecting) { false } else { val currentPage = filesFragment.currentPage @@ -308,30 +282,32 @@ class PutioActivity : BaseCastActivity() { setSupportActionBar(toolbar) bottomNavView = findViewById(R.id.main_bottom_nav) - bottomNavView.defaultBackgroundColor = ContextCompat.getColor(this, R.color.putio_light_canvas) - bottomNavView.accentColor = Color.BLACK - bottomNavView.inactiveColor = Color.parseColor("#80000000") - bottomNavView.addItem(AHBottomNavigationItem(getString(R.string.account), R.drawable.ic_nav_account)) - bottomNavView.addItem(AHBottomNavigationItem(getString(R.string.files), R.drawable.ic_nav_files)) - bottomNavView.addItem(AHBottomNavigationItem(getString(R.string.transfers), R.drawable.ic_nav_transfers)) - bottomNavView.setOnTabSelectedListener(AHBottomNavigation.OnTabSelectedListener { position, wasSelected -> - bottomNavView.post { updateAddTransferFab(true) } - when (position) { - TAB_ACCOUNT, TAB_FILES, TAB_TRANSFERS -> { - showFragment(position, true) - if (position == TAB_FILES && wasSelected) { - filesFragment?.goBackToRoot() - } - return@OnTabSelectedListener true + bottomNavView.apply { + menu.add(0, TAB_ACCOUNT, 0, R.string.account).apply { + setIcon(R.drawable.ic_nav_account) + } + menu.add(0, TAB_FILES, 0, R.string.files).apply { + setIcon(R.drawable.ic_nav_files) + } + menu.add(0, TAB_TRANSFERS, 0, R.string.transfers).apply { + setIcon(R.drawable.ic_nav_transfers) + } + setOnNavigationItemSelectedListener { item -> + post { updateAddTransferFab(true) } + showFragment(item.itemId, true) + true + } + setOnNavigationItemReselectedListener { item -> + if (item.itemId == TAB_FILES) { + filesFragment.goBackToRoot() } } - false - }) + } } fun showFilesAndGoToFile(parentId: Long, id: Long) { selectTab(TAB_FILES, true) - filesFragment!!.goToFile(parentId, id); + filesFragment.goToFile(parentId, id) } private val accountFragment: AccountFragment @@ -350,8 +326,8 @@ class PutioActivity : BaseCastActivity() { } override fun onBackPressed() { - if (bottomNavView.currentItem == TAB_FILES) { - if (!filesFragment!!.goBack(true)) { + if (bottomNavView.selectedItemId == TAB_FILES) { + if (!filesFragment.goBack(true)) { super.onBackPressed() } } else { @@ -362,7 +338,7 @@ class PutioActivity : BaseCastActivity() { private fun showFragment(position: Int, animate: Boolean) { val transaction = supportFragmentManager.beginTransaction() if (animate) { - transaction.setCustomAnimations(R.anim.bottomnav_enter, R.anim.bottomnav_exit) + transaction.setCustomAnimations(R.animator.bottomnav_enter, R.animator.bottomnav_exit) } when (position) { TAB_ACCOUNT -> { @@ -385,8 +361,8 @@ class PutioActivity : BaseCastActivity() { } private fun selectTab(position: Int, animate: Boolean) { - if (bottomNavView.currentItem != position) { - bottomNavView.setCurrentItem(position, false) + if (bottomNavView.selectedItemId != position) { + bottomNavView.selectedItemId = position showFragment(position, animate) } } @@ -400,4 +376,19 @@ class PutioActivity : BaseCastActivity() { } override val castMiniControllerContainerId = R.id.holder_castbar + + companion object { + const val EXTRA_GO_TO_TAB = "go_to_tab" + + const val TAB_ACCOUNT = 0 + const val TAB_FILES = 1 + const val TAB_TRANSFERS = 2 + + private const val FRAGTAG_ACCOUNT = "account" + private const val FRAGTAG_FILES = "files" + private const val FRAGTAG_TRANSFERS = "transfers" + + const val noNetworkIntent = "com.stevenschoen.putionew.nonetwork" + } + } diff --git a/app/src/main/java/com/stevenschoen/putionew/files/FilesFragment.kt b/app/src/main/java/com/stevenschoen/putionew/files/FilesFragment.kt index cb3a8a26..01606428 100644 --- a/app/src/main/java/com/stevenschoen/putionew/files/FilesFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/files/FilesFragment.kt @@ -27,21 +27,6 @@ import java.util.* open class FilesFragment : RxFragment() { - companion object { - const val STATE_PAGES = "pages" - const val STATE_CURRENT_PAGE = "current_page" - - const val EXTRA_FOLDER = "folder" - - fun newInstance(context: Context, folder: PutioFile?): FilesFragment { - val args = Bundle() - if (folder != null) { - args.putParcelable(EXTRA_FOLDER, folder) - } - return Fragment.instantiate(context, FilesFragment::class.java.name, args) as FilesFragment - } - } - open val canSelect = true open val choosingFolder = false open val showSearch = true @@ -318,6 +303,21 @@ open class FilesFragment : RxFragment() { outState.putParcelable(STATE_CURRENT_PAGE, currentPage) } + companion object { + const val STATE_PAGES = "pages" + const val STATE_CURRENT_PAGE = "current_page" + + const val EXTRA_FOLDER = "folder" + + fun newInstance(context: Context, folder: PutioFile?): FilesFragment { + val args = Bundle() + if (folder != null) { + args.putParcelable(EXTRA_FOLDER, folder) + } + return Fragment.instantiate(context, FilesFragment::class.java.name, args) as FilesFragment + } + } + inner class PageFragmentsPagerAdapter : FragmentPagerAdapter(childFragmentManager) { private val fragments = SparseArray() diff --git a/app/src/main/java/com/stevenschoen/putionew/transfers/add/DestinationPickerFragment.kt b/app/src/main/java/com/stevenschoen/putionew/transfers/add/DestinationPickerFragment.kt index e892cafa..979e027b 100644 --- a/app/src/main/java/com/stevenschoen/putionew/transfers/add/DestinationPickerFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/transfers/add/DestinationPickerFragment.kt @@ -25,12 +25,8 @@ class DestinationPickerFragment : RxFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val defaultDestination: PutioFile = - if (savedInstanceState != null && savedInstanceState.containsKey(STATE_DESTINATION)) { - savedInstanceState.getParcelable(STATE_DESTINATION) - } else { - PutioFile.makeRootFolder(resources) - } + val defaultDestination: PutioFile = savedInstanceState?.getParcelable(STATE_DESTINATION) + ?: PutioFile.makeRootFolder(resources) destinationSubject = BehaviorSubject.createDefault(defaultDestination) } diff --git a/app/src/main/res/anim/bottomnav_enter.xml b/app/src/main/res/anim/bottomnav_enter.xml deleted file mode 100644 index 3b2ed9b4..00000000 --- a/app/src/main/res/anim/bottomnav_enter.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/app/src/main/res/anim/bottomnav_exit.xml b/app/src/main/res/anim/bottomnav_exit.xml deleted file mode 100644 index 802a5719..00000000 --- a/app/src/main/res/anim/bottomnav_exit.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - diff --git a/app/src/main/res/animator/bottomnav_enter.xml b/app/src/main/res/animator/bottomnav_enter.xml new file mode 100644 index 00000000..9fad999b --- /dev/null +++ b/app/src/main/res/animator/bottomnav_enter.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/animator/bottomnav_exit.xml b/app/src/main/res/animator/bottomnav_exit.xml new file mode 100644 index 00000000..e04565fd --- /dev/null +++ b/app/src/main/res/animator/bottomnav_exit.xml @@ -0,0 +1,6 @@ + + diff --git a/app/src/main/res/color/bottom_nav_item_tint.xml b/app/src/main/res/color/bottom_nav_item_tint.xml new file mode 100644 index 00000000..5319a188 --- /dev/null +++ b/app/src/main/res/color/bottom_nav_item_tint.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/destination_activity.xml b/app/src/main/res/layout/destination_activity.xml index fdd235b8..783946eb 100644 --- a/app/src/main/res/layout/destination_activity.xml +++ b/app/src/main/res/layout/destination_activity.xml @@ -1,16 +1,19 @@ @@ -22,10 +25,14 @@ />