Commit 9e9148a0 authored by Filip Wiesner's avatar Filip Wiesner

Seperate NavGraph for BottomNav, Timetable fade-refresh tweak

parent d5ec86b5
......@@ -3,6 +3,64 @@
<component name="navEditor-manualLayoutAlgorithm2">
<option name="myPositions">
<map>
<entry key="bottom_nav_graph.xml">
<value>
<LayoutPositions>
<option name="myPositions">
<map>
<entry key="nav_profile">
<value>
<LayoutPositions>
<option name="myPosition">
<Point>
<option name="x" value="660" />
<option name="y" value="57" />
</Point>
</option>
</LayoutPositions>
</value>
</entry>
<entry key="nav_search">
<value>
<LayoutPositions>
<option name="myPosition">
<Point>
<option name="x" value="474" />
<option name="y" value="60" />
</Point>
</option>
</LayoutPositions>
</value>
</entry>
<entry key="nav_tasks">
<value>
<LayoutPositions>
<option name="myPosition">
<Point>
<option name="x" value="72" />
<option name="y" value="53" />
</Point>
</option>
</LayoutPositions>
</value>
</entry>
<entry key="nav_timetable">
<value>
<LayoutPositions>
<option name="myPosition">
<Point>
<option name="x" value="268" />
<option name="y" value="58" />
</Point>
</option>
</LayoutPositions>
</value>
</entry>
</map>
</option>
</LayoutPositions>
</value>
</entry>
<entry key="nav_graph.xml">
<value>
<LayoutPositions>
......@@ -13,10 +71,19 @@
<LayoutPositions>
<option name="myPosition">
<Point>
<option name="x" value="290" />
<option name="y" value="-195" />
<option name="x" value="-241" />
<option name="y" value="10" />
</Point>
</option>
<option name="myPositions">
<map>
<entry key="onLogged">
<value>
<LayoutPositions />
</value>
</entry>
</map>
</option>
</LayoutPositions>
</value>
</entry>
......@@ -25,18 +92,18 @@
<LayoutPositions>
<option name="myPosition">
<Point>
<option name="x" value="138" />
<option name="y" value="239" />
<option name="x" value="12" />
<option name="y" value="54" />
</Point>
</option>
<option name="myPositions">
<map>
<entry key="action_navigationFragment_to_authFragment">
<entry key="toAuth">
<value>
<LayoutPositions />
</value>
</entry>
<entry key="action_navigationFragment_to_timetableDetailFragment">
<entry key="toEventDetail">
<value>
<LayoutPositions />
</value>
......@@ -51,8 +118,8 @@
<LayoutPositions>
<option name="myPosition">
<Point>
<option name="x" value="483" />
<option name="y" value="128" />
<option name="x" value="389" />
<option name="y" value="328" />
</Point>
</option>
</LayoutPositions>
......
......@@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'
android {
compileSdkVersion 28
......@@ -54,6 +55,7 @@ dependencies {
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
//Dependency injection
implementation "com.google.dagger:dagger:$dagger_version"
implementation "com.google.dagger:dagger-android:$dagger_version"
......@@ -64,8 +66,6 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.tickaroo.tikxml:retrofit-converter:0.8.13'
// implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
// implementation 'com.github.pwittchen:reactivenetwork-rx2:1.0.0'
// Shared Prefs
implementation 'com.chibatching.kotpref:kotpref:2.5.0'
......@@ -77,11 +77,6 @@ dependencies {
kapt 'com.tickaroo.tikxml:processor:0.8.13'
implementation 'net.danlew:android.joda:2.9.9.4'
// Reactive stuff
// implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
// implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.0.0-rc01'
// implementation 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.1.1'
// Animation/Trasnition
implementation 'bg.devlabs.transitioner:transitioner:1.3'
implementation 'com.github.florent37:kotlinpleaseanimate:1.0.4'
......@@ -89,7 +84,6 @@ dependencies {
// Database
implementation "androidx.room:room-runtime:$room_version"
// implementation "androidx.room:room-rxjava2:$room_version"
implementation "androidx.paging:paging-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
......
......@@ -12,6 +12,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".flows.BlackBirdMain">
<nav-graph android:value="@navigation/nav_graph"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......@@ -29,5 +31,4 @@
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.cvut.blackbird
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.cvut.blackbird.extensions.withDefault
import com.cvut.blackbird.flows.NavigationFragment
class NavigationViewModel: ViewModel() {
var selectedDestination = MutableLiveData<Int>() withDefault NavigationFragment.STARTING_SCREEN
}
\ No newline at end of file
package com.cvut.blackbird.extensions
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
import android.graphics.Color
import android.os.Parcel
import android.os.Parcelable
import android.view.View
import android.view.ViewAnimationUtils
import androidx.core.animation.addListener
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
class RevealPosition(private val view: View) {
public var x = view.centerX
public var y = view.centerY
fun top() {y = view.y}
fun down() {y = view.y + view.height}
fun left() {x = view.x}
fun right() {x = view.x + view.width}
}
fun View.centerCircularReveal(duration: Long? = null) = revealFrom(centerX.toInt(), centerY.toInt(), duration)
fun View.revealFrom(xPos: Int, yPos: Int, duration: Long? = null) {
ViewAnimationUtils.createCircularReveal(this, xPos, yPos, 0f, width.toFloat())
.apply { if (duration != null) this.duration = duration }
.start()
}
inline fun View.revealFrom(duration: Long? = null, f:RevealPosition.() -> Unit) {
val pos = RevealPosition(this)
pos.f()
revealFrom(pos.x.toInt(), pos.y.toInt(), duration)
}
/**
* Transition Reveal
*/
class CircularRevealSettings(
val x: Int, val y: Int,
val width: Int, val height: Int,
val startColor: Int = Color.TRANSPARENT,
val endColor: Int = Color.TRANSPARENT
): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readInt(),
parcel.readInt(),
parcel.readInt())
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(x)
parcel.writeInt(y)
parcel.writeInt(width)
parcel.writeInt(height)
}
override fun describeContents() = 0
companion object CREATOR : Parcelable.Creator<CircularRevealSettings> {
override fun createFromParcel(parcel: Parcel): CircularRevealSettings {
return CircularRevealSettings(parcel)
}
override fun newArray(size: Int): Array<CircularRevealSettings?> {
return arrayOfNulls(size)
}
}
}
fun View.registerCircularReveal(settings: CircularRevealSettings) =
doOnLayoutChange {
val duration = 1000L
val finalRadius = Math.sqrt(
(settings.width * settings.width + settings.height * settings.height)
.toDouble()
).toFloat()
val anim: Animator = ViewAnimationUtils.createCircularReveal(this,
settings.x,
settings.y,
0f,
finalRadius
).setDuration(duration)
anim.interpolator = FastOutSlowInInterpolator()
anim.start()
startColorAnimation(settings.startColor, settings.endColor, duration)
}
fun View.startCircularExit(settings: CircularRevealSettings, onFinish: ()->Unit) {
val duration = 500L
val initRadius = Math.sqrt(
(settings.width * settings.width + settings.height * settings.height)
.toDouble()
).toFloat()
val anim: Animator = ViewAnimationUtils.createCircularReveal(this,
settings.x,
settings.y,
initRadius,
0f
).setDuration(duration)
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
onFinish()
}
})
anim.interpolator = FastOutSlowInInterpolator()
anim.start()
startColorAnimation(settings.startColor, settings.endColor, duration)
}
fun View.startColorAnimation(startColor: Int, endColor: Int, duration: Long) {
val anim = ValueAnimator()
anim.setIntValues(startColor, endColor)
anim.setEvaluator(ArgbEvaluator())
anim.addUpdateListener { valueAnimator -> setBackgroundColor(valueAnimator.animatedValue as Int) }
anim.duration = duration
anim.start()
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ import android.opengl.ETC1.getWidth
import android.os.Build
import android.annotation.TargetApi
import android.animation.ValueAnimator
import android.graphics.Color
import android.os.Parcel
import android.os.Parcelable
......@@ -34,31 +35,25 @@ var View.centerY : Float
y = value - (height/2)
}
val coords = IntArray(2)
var View.globalX: Int
get() {
val coords = IntArray(2)
getLocationOnScreen(coords)
return coords[0]
}
set(value) {
val coords = IntArray(2)
getLocationOnScreen(coords)
val topSpace = coords[0] - x
x = value - topSpace
x = value - (coords[0] - x)
}
var View.globalY: Int
get() {
val coords = IntArray(2)
getLocationOnScreen(coords)
return coords[1]
}
set(value) {
val coords = IntArray(2)
getLocationOnScreen(coords)
val topSpace = coords[1] - y
y = value - topSpace
y = value - (coords[1] - y)
}
var View.globalCenterX : Int
......@@ -80,82 +75,6 @@ inline fun ViewGroup.removeViewsMatching(crossinline predicate: (View) -> Boolea
.forEach (::removeView)
}
fun View.centerCircularReveal(duration: Long? = null) = revealFrom(centerX.toInt(), centerY.toInt(), duration)
fun View.revealFrom(xPos: Int, yPos: Int, duration: Long? = null) {
ViewAnimationUtils.createCircularReveal(this, xPos, yPos, 0f, width.toFloat())
.apply { if (duration != null) this.duration = duration }
.start()
}
inline fun View.revealFrom(duration: Long? = null, f:RevealPosition.() -> Unit) {
val pos = RevealPosition(this)
pos.f()
revealFrom(pos.x.toInt(), pos.y.toInt(), duration)
}
class CircularRevealSettings(
val x: Int, val y: Int,
val width: Int, val height: Int
): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readInt(),
parcel.readInt(),
parcel.readInt())
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(x)
parcel.writeInt(y)
parcel.writeInt(width)
parcel.writeInt(height)
}
override fun describeContents() = 0
companion object CREATOR : Parcelable.Creator<CircularRevealSettings> {
override fun createFromParcel(parcel: Parcel): CircularRevealSettings {
return CircularRevealSettings(parcel)
}
override fun newArray(size: Int): Array<CircularRevealSettings?> {
return arrayOfNulls(size)
}
}
}
fun View.registerCircularReveal(settings: CircularRevealSettings, startColor: Int, endColor: Int) =
doOnLayoutChange {
val duration = 500L
val finalRadius = Math.sqrt(
(settings.width * settings.width + settings.height * settings.height)
.toDouble()
).toFloat()
val anim: Animator = ViewAnimationUtils.createCircularReveal(this,
settings.x,
settings.y,
0f,
finalRadius
).setDuration(duration)
anim.interpolator = FastOutSlowInInterpolator()
anim.start()
startColorAnimation(startColor, endColor, duration)
}
fun View.startColorAnimation(startColor: Int, endColor: Int, duration: Long) {
val anim = ValueAnimator()
anim.setIntValues(startColor, endColor)
anim.setEvaluator(ArgbEvaluator())
anim.addUpdateListener { valueAnimator -> setBackgroundColor(valueAnimator.animatedValue as Int) }
anim.duration = duration
anim.start()
}
fun View.setVisible() {visibility = VISIBLE}
fun View.setInvisible() {visibility = INVISIBLE}
fun View.setGone() {visibility = GONE}
......@@ -177,12 +96,3 @@ inline fun View.doOnLayoutChange (crossinline action: (View) -> Unit) {
})
}
class RevealPosition(private val view: View) {
public var x = view.centerX
public var y = view.centerY
fun top() {y = view.y}
fun down() {y = view.y + view.height}
fun left() {x = view.x}
fun right() {x = view.x + view.width}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.cvut.blackbird.flows
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import com.cvut.blackbird.R
......@@ -11,51 +12,23 @@ import kotlinx.android.synthetic.main.black_bird_ac_activity.*
class BlackBirdMain : AppCompatActivity() {
private lateinit var navController: NavController
// private val disposeBag = ArrayList<Disposable>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.black_bird_ac_activity)
supportActionBar?.hide()
navController = NavHostFragment.findNavController(navHost)
disableAuthPop()
// disableAuthPop()
if (UserInfo.username.isBlank())
navController.navigate(R.id.action_navigationFragment_to_authFragment)
navController.navigate(R.id.toAuth)
}
override fun onNavigateUp(): Boolean = findNavController(navHost.id).navigateUp()
override fun onSupportNavigateUp() = findNavController(navHost.id).navigateUp()
private fun disableAuthPop() {
navController.addOnNavigatedListener { _, destination ->
if(destination.id == R.id.authFragment || destination.id == R.id.navigationFragment) supportFragmentManager.popBackStack()
}
}
// override fun onDestroy() {
// super.onDestroy()
// disposeBag.forEach { it.dispose() }
// }
// private fun setupConnectivityObserver() {
// val networkSnack = Snackbar.make(contentView!!,"", Snackbar.LENGTH_SHORT)
// var first = true
// ReactiveNetwork.observeInternetConnectivity()
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .filter {
// if (first && it) {
// first = false
// false
// } else true}
// .subscribe {
// networkSnack.dismiss()
//
// if (it) networkSnack.setText(R.string.network_connected)
// else networkSnack.setText(R.string.network_disconnected)
//
// networkSnack.show()
// AppState.offline = !it
// } disposeTo disposeBag
// }
}
\ No newline at end of file
......@@ -5,72 +5,21 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import com.cvut.blackbird.NavigationViewModel
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.ui.*
import com.cvut.blackbird.R
import com.cvut.blackbird.flows.tasks.TasksFragment
import com.cvut.blackbird.flows.profile.ProfileFragment
import com.cvut.blackbird.flows.search.SearchFragment
import com.cvut.blackbird.flows.timetable.TimetableFragment
import com.cvut.blackbird.flows.timetable.TimetableViewModel
import com.cvut.blackbird.support.glue.bind
import com.cvut.blackbird.support.glue.toPassValueTo
import kotlinx.android.synthetic.main.navigation_fragment.*
class NavigationFragment : Fragment() {
companion object {
const val STARTING_SCREEN = R.id.nav_tasks
}
private lateinit var viewModel: NavigationViewModel
private lateinit var tasksFrament: Fragment
private lateinit var timetableFragment: Fragment
private lateinit var searchFragment: Fragment
private lateinit var profileFragment: ProfileFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
tasksFrament = TasksFragment.newInstance()
timetableFragment = TimetableFragment.newInstance()
searchFragment = SearchFragment.newInstance()
profileFragment = ProfileFragment.newInstance()
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
= inflater.inflate(R.layout.navigation_fragment, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel = ViewModelProviders.of(activity!!).get(NavigationViewModel::class.java)
bottom_navigation.setOnNavigationItemSelectedListener {selected ->
viewModel.selectedDestination.value = selected.itemId
val fragment = when (selected.itemId) {
R.id.nav_tasks -> tasksFrament
R.id.nav_timetable -> timetableFragment
R.id.nav_serach -> searchFragment
R.id.nav_profile -> profileFragment
else -> TODO("what happened ma dude?")
}
activity!!.supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.nav_default_enter_anim, R.anim.nav_default_exit_anim)
.replace(R.id.nav_container, fragment)
.commit