Skip to content

Commit

Permalink
Merge pull request #150 from ncapdevi/remove-builder
Browse files Browse the repository at this point in the history
remove-builder
  • Loading branch information
ncapdevi authored Apr 22, 2018
2 parents 7930919 + 360a68f commit 07bae82
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 335 deletions.
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,89 +10,95 @@ import com.ncapdevi.fragnav.FragNavLogger
import com.ncapdevi.fragnav.FragNavSwitchController
import com.ncapdevi.fragnav.FragNavTransactionOptions
import com.ncapdevi.fragnav.tabhistory.FragNavTabHistoryController
import com.ncapdevi.fragnav.tabhistory.UniqueTabHistoryStrategy
import com.ncapdevi.sample.R
import com.ncapdevi.sample.fragments.*
import com.roughike.bottombar.BottomBar


class BottomTabsActivity : AppCompatActivity(), BaseFragment.FragmentNavigation, FragNavController.TransactionListener, FragNavController.RootFragmentListener {
override val numberOfRootFragments: Int = 5

private var fragNavController: FragNavController? = null
private val fragNavController: FragNavController = FragNavController(supportFragmentManager, R.id.container)

private lateinit var bottomBar: BottomBar

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(com.ncapdevi.sample.R.layout.activity_bottom_tabs)

val bottomBar = findViewById<BottomBar>(R.id.bottomBar)

fragNavController = FragNavController.newBuilder(savedInstanceState,
supportFragmentManager,
R.id.container)
.transactionListener(this)
.rootFragmentListener(this, 5)
.switchController(FragNavTabHistoryController.UNIQUE_TAB_HISTORY, object : FragNavSwitchController {
override fun switchTab(index: Int, transactionOptions: FragNavTransactionOptions?) {
bottomBar.selectTabAtPosition(index)
}
})
.fragmentHideStrategy(FragNavController.DETACH_ON_NAVIGATE_HIDE_ON_SWITCH)
.eager(true)
.logger(object : FragNavLogger {
override fun error(message: String, throwable: Throwable) {
Log.e(TAG, message, throwable)
}
})
.build()
bottomBar = findViewById(R.id.bottomBar)

fragNavController.apply {
transactionListener = this@BottomTabsActivity
rootFragmentListener = this@BottomTabsActivity
createEager = true
fragNavLogger = object : FragNavLogger {
override fun error(message: String, throwable: Throwable) {
Log.e(TAG, message, throwable)
}
}

fragmentHideStrategy = FragNavController.DETACH_ON_NAVIGATE_HIDE_ON_SWITCH

navigationStrategy = UniqueTabHistoryStrategy(object : FragNavSwitchController {
override fun switchTab(index: Int, transactionOptions: FragNavTransactionOptions?) {
bottomBar.selectTabAtPosition(index)
}
})
}

fragNavController.initialize(INDEX_NEARBY, savedInstanceState)

val initial = savedInstanceState == null
if (initial) {
bottomBar.selectTabAtPosition(INDEX_NEARBY)
}


fragNavController?.executePendingTransactions()
fragNavController.executePendingTransactions()
bottomBar.setOnTabSelectListener({ tabId ->
when (tabId) {
R.id.bb_menu_recents -> fragNavController?.switchTab(INDEX_RECENTS)
R.id.bb_menu_favorites -> fragNavController?.switchTab(INDEX_FAVORITES)
R.id.bb_menu_nearby -> fragNavController?.switchTab(INDEX_NEARBY)
R.id.bb_menu_friends -> fragNavController?.switchTab(INDEX_FRIENDS)
R.id.bb_menu_food -> fragNavController?.switchTab(INDEX_FOOD)
R.id.bb_menu_recents -> fragNavController.switchTab(INDEX_RECENTS)
R.id.bb_menu_favorites -> fragNavController.switchTab(INDEX_FAVORITES)
R.id.bb_menu_nearby -> fragNavController.switchTab(INDEX_NEARBY)
R.id.bb_menu_friends -> fragNavController.switchTab(INDEX_FRIENDS)
R.id.bb_menu_food -> fragNavController.switchTab(INDEX_FOOD)
}
}, initial)

bottomBar.setOnTabReselectListener { fragNavController?.clearStack() }
bottomBar.setOnTabReselectListener { fragNavController.clearStack() }

}

override fun onBackPressed() {
if (fragNavController?.popFragment()?.not() == true) {
if (fragNavController.popFragment().not()) {
super.onBackPressed()
}
}

override fun onSaveInstanceState(outState: Bundle?) {
super.onSaveInstanceState(outState)
fragNavController?.onSaveInstanceState(outState!!)
fragNavController.onSaveInstanceState(outState!!)

}

override fun pushFragment(fragment: Fragment) {
fragNavController?.pushFragment(fragment)
fragNavController.pushFragment(fragment)

}

override fun onTabTransaction(fragment: Fragment?, index: Int) {
// If we have a backstack, show the back button
supportActionBar?.setDisplayHomeAsUpEnabled(fragNavController?.isRootFragment?.not() == true)
supportActionBar?.setDisplayHomeAsUpEnabled(fragNavController.isRootFragment.not())

}


override fun onFragmentTransaction(fragment: Fragment?, transactionType: FragNavController.TransactionType) {
//do fragmentty stuff. Maybe change title, I'm not going to tell you how to live your life
// If we have a backstack, show the back button
supportActionBar?.setDisplayHomeAsUpEnabled(fragNavController?.isRootFragment?.not() == true)
supportActionBar?.setDisplayHomeAsUpEnabled(fragNavController.isRootFragment.not())

}

Expand All @@ -109,7 +115,7 @@ class BottomTabsActivity : AppCompatActivity(), BaseFragment.FragmentNavigation,

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> fragNavController?.popFragment()
android.R.id.home -> fragNavController.popFragment()
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NavDrawerActivity : AppCompatActivity(), NavigationView.OnNavigationItemSe
//Better convention to properly name the indices what they are in your app


private var fragNavController: FragNavController? = null
private var fragNavController: FragNavController = FragNavController(supportFragmentManager, R.id.container)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -51,48 +51,51 @@ class NavDrawerActivity : AppCompatActivity(), NavigationView.OnNavigationItemSe
RecentsFragment.newInstance(0),
FavoritesFragment.newInstance(0))

fragNavController = FragNavController.newBuilder(savedInstanceState, supportFragmentManager, R.id.container)
.rootFragments(fragments)
.defaultTransactionOptions(FragNavTransactionOptions.newBuilder().customAnimations(R.anim.slide_in_from_right, R.anim.slide_out_to_left, R.anim.slide_in_from_left, R.anim.slide_out_to_right).build())
.build()
fragNavController.apply {
rootFragments = fragments
defaultTransactionOptions = FragNavTransactionOptions.newBuilder().customAnimations(R.anim.slide_in_from_right, R.anim.slide_out_to_left, R.anim.slide_in_from_left, R.anim.slide_out_to_right).build()
}

fragNavController.initialize(INDEX_RECENTS,savedInstanceState)


}

override fun onBackPressed() {
val drawer = findViewById<DrawerLayout>(R.id.drawer_layout)
when {
drawer.isDrawerOpen(GravityCompat.START) -> drawer.closeDrawer(GravityCompat.START)
fragNavController?.isRootFragment?.not() == true -> fragNavController?.popFragment()
fragNavController.isRootFragment.not() -> fragNavController.popFragment()
else -> super.onBackPressed()
}
}

override fun onSaveInstanceState(outState: Bundle?) {
super.onSaveInstanceState(outState)
fragNavController?.onSaveInstanceState(outState)
fragNavController.onSaveInstanceState(outState)
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.bb_menu_recents -> fragNavController?.switchTab(INDEX_RECENTS)
R.id.bb_menu_favorites -> fragNavController?.switchTab(INDEX_FAVORITES)
R.id.bb_menu_nearby -> fragNavController?.switchTab(INDEX_NEARBY)
R.id.bb_menu_friends -> fragNavController?.switchTab(INDEX_FRIENDS)
R.id.bb_menu_food -> fragNavController?.switchTab(INDEX_FOOD)
R.id.bb_menu_recents2 -> fragNavController?.switchTab(INDEX_RECENTS2)
R.id.bb_menu_favorites2 -> fragNavController?.switchTab(INDEX_FAVORITES2)
R.id.bb_menu_nearby2 -> fragNavController?.switchTab(INDEX_NEARBY2)
R.id.bb_menu_friends2 -> fragNavController?.switchTab(INDEX_FRIENDS2)
R.id.bb_menu_food2 -> fragNavController?.switchTab(INDEX_FOOD2)
R.id.bb_menu_recents3 -> fragNavController?.switchTab(INDEX_RECENTS3)
R.id.bb_menu_favorites3 -> fragNavController?.switchTab(INDEX_FAVORITES3)
R.id.bb_menu_recents -> fragNavController.switchTab(INDEX_RECENTS)
R.id.bb_menu_favorites -> fragNavController.switchTab(INDEX_FAVORITES)
R.id.bb_menu_nearby -> fragNavController.switchTab(INDEX_NEARBY)
R.id.bb_menu_friends -> fragNavController.switchTab(INDEX_FRIENDS)
R.id.bb_menu_food -> fragNavController.switchTab(INDEX_FOOD)
R.id.bb_menu_recents2 -> fragNavController.switchTab(INDEX_RECENTS2)
R.id.bb_menu_favorites2 -> fragNavController.switchTab(INDEX_FAVORITES2)
R.id.bb_menu_nearby2 -> fragNavController.switchTab(INDEX_NEARBY2)
R.id.bb_menu_friends2 -> fragNavController.switchTab(INDEX_FRIENDS2)
R.id.bb_menu_food2 -> fragNavController.switchTab(INDEX_FOOD2)
R.id.bb_menu_recents3 -> fragNavController.switchTab(INDEX_RECENTS3)
R.id.bb_menu_favorites3 -> fragNavController.switchTab(INDEX_FAVORITES3)
}
val drawer = findViewById<DrawerLayout>(R.id.drawer_layout)
drawer.closeDrawer(GravityCompat.START)
return true
}

override fun pushFragment(fragment: Fragment) {
fragNavController?.pushFragment(fragment)
fragNavController.pushFragment(fragment)
}
}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.2.21'
ext.kotlin_version = '1.2.40'
repositories {
jcenter()
google()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,7 +26,7 @@ ext {
// App dependencies

junitVersion = '4.12'
supportVersion = '27.0.2'
supportVersion = '27.1.1'
buildToolsVersion = '27.0.3'
minSdkVersion = 14
targetSdkVersion = 27
Expand Down
4 changes: 2 additions & 2 deletions frag-nav/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ apply plugin: 'maven'
apply plugin: 'com.github.kt3k.coveralls'

ext {
libraryVersionCode = 23
libraryVersionName = '2.4.0'
libraryVersionCode = 24
libraryVersionName = '3.0.0-RC'

//Bintray and Maven
bintrayRepo = 'maven'
Expand Down
Loading

0 comments on commit 07bae82

Please sign in to comment.