Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransitionAnimation #1

Merged
merged 10 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ Check out our [wiki](https://github.com/Trendyol/medusa/wiki)!
* [Grouping fragments](https://github.com/Trendyol/medusa/wiki/Grouping-Fragments)

## Setup
```
```gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```
```
```gradle
dependencies {
implementation 'com.github.trendyol:medusa:0.7.0'
implementation 'com.github.trendyol:medusa:0.8.0'
}
```

Expand All @@ -48,7 +48,7 @@ License
--------


Copyright 2018 Trendyol.com
Copyright 2018-2019 Trendyol.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ android {
dependencies {
implementation project(':medusalib')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/trendyol/medusa/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open class BaseFragment : Fragment() {

var multipleStackNavigator: MultipleStackNavigator? = null

override fun onAttach(context: Context?) {
override fun onAttach(context: Context) {
super.onAttach(context)
initStackNavigator(context)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/trendyol/medusa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.trendyol.medusalib.navigator.MultipleStackNavigator
import com.trendyol.medusalib.navigator.Navigator
import com.trendyol.medusalib.navigator.NavigatorConfiguration
import com.trendyol.medusalib.navigator.transaction.NavigatorTransaction
import com.trendyol.medusalib.navigator.transitionanimation.TransitionAnimationType

class MainActivity : AppCompatActivity(), Navigator.NavigatorListener {

Expand Down
52 changes: 27 additions & 25 deletions app/src/main/java/com/trendyol/medusa/MainActivity2.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.trendyol.medusalib.navigator.Navigator;
import com.trendyol.medusalib.navigator.NavigatorConfiguration;
import com.trendyol.medusalib.navigator.transaction.NavigatorTransaction;
import com.trendyol.medusalib.navigator.transitionanimation.TransitionAnimationType;

import java.util.Arrays;
import java.util.List;
Expand All @@ -28,26 +29,26 @@ public class MainActivity2 extends AppCompatActivity implements Navigator.Naviga
MultipleStackNavigator multipleStackNavigator;

private List<Function0<Fragment>> rootsFragmentProvider = Arrays
.asList(
new Function0<Fragment>() {
@Override
public Fragment invoke() {
return FragmentGenerator.generateNewFragment();
}
},
new Function0<Fragment>() {
@Override
public Fragment invoke() {
return FragmentGenerator.generateNewFragment();
}
},
new Function0<Fragment>() {
@Override
public Fragment invoke() {
return FragmentGenerator.generateNewFragment();
}
}
);
.asList(
new Function0<Fragment>() {
@Override
public Fragment invoke() {
return FragmentGenerator.generateNewFragment();
}
},
new Function0<Fragment>() {
@Override
public Fragment invoke() {
return FragmentGenerator.generateNewFragment();
}
},
new Function0<Fragment>() {
@Override
public Fragment invoke() {
return FragmentGenerator.generateNewFragment();
}
}
);

private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
Expand Down Expand Up @@ -75,11 +76,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
navigation = findViewById(R.id.navigation);

multipleStackNavigator = new MultipleStackNavigator(
getSupportFragmentManager(),
R.id.fragmentContainer,
rootsFragmentProvider,
this,
new NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE));
getSupportFragmentManager(),
R.id.fragmentContainer,
rootsFragmentProvider,
this,
new NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE),
null);

multipleStackNavigator.initialize(savedInstanceState);
final SwitchCompat restartRootFragmentCheckBox = findViewById(R.id.restartSwitch);
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/trendyol/medusa/SampleFragment.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package com.trendyol.medusa

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import com.trendyol.medusalib.navigator.transitionanimation.TransitionAnimationType
import kotlin.random.Random

class SampleFragment : BaseFragment(){
class SampleFragment : BaseFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_sample, container, false)!!
view.findViewById<TextView>(R.id.textview).text = arguments!!.getString(KEY)

view.findViewById<LinearLayout>(R.id.root).setBackgroundColor(Color.argb(255, Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)))

view.findViewById<Button>(R.id.button).setOnClickListener {
multipleStackNavigator!!.start(FragmentGenerator.generateNewFragment())
multipleStackNavigator!!.start(FragmentGenerator.generateNewFragment(), TransitionAnimationType.RIGHT_TO_LEFT)
}
return view
}
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/res/layout/fragment_sample.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"

<LinearLayout android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:background="#ccc000"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">


<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start another"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start another"/>

</LinearLayout>
</LinearLayout>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.3.50'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jan 21 10:31:44 EET 2019
#Tue Oct 22 10:09:51 EET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
4 changes: 2 additions & 2 deletions medusalib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 6
versionName "0.7.0"
versionCode 8
versionName "0.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import com.trendyol.medusalib.navigator.data.FragmentData
import com.trendyol.medusalib.navigator.data.StackItem
import com.trendyol.medusalib.navigator.tag.TagCreator
import com.trendyol.medusalib.navigator.tag.UniqueTagCreator
import com.trendyol.medusalib.navigator.transitionanimation.TransitionAnimationType

open class MultipleStackNavigator(
fragmentManager: FragmentManager,
containerId: Int,
private val rootFragmentProvider: List<() -> Fragment>,
private var navigatorListener: Navigator.NavigatorListener? = null,
private val navigatorConfiguration: NavigatorConfiguration = NavigatorConfiguration()
private val navigatorConfiguration: NavigatorConfiguration = NavigatorConfiguration(),
private val transitionAnimationType: TransitionAnimationType? = null
) : Navigator {

private val tagCreator: TagCreator = UniqueTagCreator()
Expand Down Expand Up @@ -43,14 +45,23 @@ open class MultipleStackNavigator(
}

override fun start(fragment: Fragment, fragmentGroupName: String) {
start(fragment, fragmentGroupName, transitionAnimationType)
}

override fun start(fragment: Fragment, transitionAnimation: TransitionAnimationType) {
start(fragment, DEFAULT_GROUP_NAME, transitionAnimation)
}

override fun start(fragment: Fragment, fragmentGroupName: String, transitionAnimation: TransitionAnimationType?) {

val createdTag = tagCreator.create(fragment)
val currentTabIndex = fragmentStackState.getSelectedTabIndex()
val fragmentData = FragmentData(fragment, createdTag)
val fragmentData = FragmentData(fragment, createdTag, transitionAnimation)

if (fragmentStackState.isSelectedTabEmpty()) {
val rootFragment = getRootFragment(currentTabIndex)
val rootFragmentTag = tagCreator.create(rootFragment)
val rootFragmentData = FragmentData(rootFragment, rootFragmentTag)
val rootFragmentData = FragmentData(rootFragment, rootFragmentTag, transitionAnimation)
fragmentManagerController.disableAndStartFragment(
getCurrentFragmentTag(),
rootFragmentData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.trendyol.medusalib.navigator
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.trendyol.medusalib.navigator.transaction.NavigatorTransaction
import com.trendyol.medusalib.navigator.transitionanimation.TransitionAnimationType

interface Navigator {

Expand Down Expand Up @@ -46,6 +47,27 @@ interface Navigator {
*/
fun start(fragment: Fragment, tabIndex: Int, fragmentGroupName: String)

/**
* Adds new fragment to the fragment stack with given tab index.
* Hide currently active fragment, switches to given tab Index
* and show newly added fragment to the user.
* @param fragment new fragment
* @param fragmentGroupName will be used in case of you want to remove
* @param transitionAnimation will be used start and remove fragment transition animation
* all fragments which has the same group name.
*/
fun start(fragment: Fragment, fragmentGroupName: String, transitionAnimation: TransitionAnimationType?)

/**
* Adds new fragment to the fragment stack with given tab index.
* Hide currently active fragment, switches to given tab Index
* and show newly added fragment to the user.
* @param fragment new fragment
* @param transitionAnimation will be used start and remove fragment transition animation
* all fragments which has the same group name.
*/
fun start(fragment: Fragment, transitionAnimation: TransitionAnimationType)

/**
* Modifies fragment stack. Pops current fragment from
* fragment stack and detaches it. Peeks from fragment stack
Expand Down
Loading