Skip to content

Commit

Permalink
Update styles, fix UI issues, remove AHBottomNav
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Dec 26, 2018
1 parent d13cbb7 commit 2b0f519
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 130 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
117 changes: 54 additions & 63 deletions app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 -> {
Expand All @@ -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)
}
}
Expand All @@ -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"
}

}
30 changes: 15 additions & 15 deletions app/src/main/java/com/stevenschoen/putionew/files/FilesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Fragment>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
16 changes: 0 additions & 16 deletions app/src/main/res/anim/bottomnav_enter.xml

This file was deleted.

8 changes: 0 additions & 8 deletions app/src/main/res/anim/bottomnav_exit.xml

This file was deleted.

16 changes: 16 additions & 0 deletions app/src/main/res/animator/bottomnav_enter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="alpha"
android:valueFrom="0.0"
android:valueTo="1.0"
/>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/linear_out_slow_in"
android:propertyName="translationY"
android:valueFrom="40dp"
android:valueTo="0dp"
/>
</set>
6 changes: 6 additions & 0 deletions app/src/main/res/animator/bottomnav_exit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="alpha"
android:valueTo="0.0"
/>
5 changes: 5 additions & 0 deletions app/src/main/res/color/bottom_nav_item_tint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="1.0" android:color="?colorOnSurface" android:state_checked="true"/>
<item android:alpha="0.6" android:color="?colorOnSurface"/>
</selector>
17 changes: 12 additions & 5 deletions app/src/main/res/layout/destination_activity.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".files.DestinationFolderActivity"
>

<androidx.appcompat.widget.Toolbar
android:id="@+id/destination_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F8F8F8"
android:background="?colorSurface"
android:elevation="@dimen/appBarElevation"
app:title="@string/choose_folder"
/>

Expand All @@ -22,10 +25,14 @@
/>

<LinearLayout
android:id="@+id/buttonbar"
style="@style/ButtonBar"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface"
android:elevation="@dimen/appBarElevation"
android:gravity="end"
android:orientation="horizontal"
android:paddingVertical="8dp"
android:paddingEnd="16dp"
>

<Button
Expand All @@ -38,7 +45,7 @@

<Button
android:id="@+id/destination_choose"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose_folder"
Expand Down
Loading

0 comments on commit 2b0f519

Please sign in to comment.