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

Be able to setMaxLifecycle during the fragment transaction #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
71 changes: 15 additions & 56 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
os: linux
language: android
jdk: oraclejdk11

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand All @@ -7,63 +10,19 @@ cache:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache

android:
components:
# use the latest revision of Android SDK Tools
- tools
- platform-tools
- tools
# The BuildTools version used by your project
- build-tools-27.0.3
# The SDK version used to compile your project
- android-27
# Additional components
- extra-google-m2repository
- extra-android-m2repository
- extra-android-support

licenses:
- 'android-sdk-preview-license-.+'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'

jdk:
- oraclejdk8


env:
global:
- ANDROID_HOME=~/android-sdk

before_install:
- wget "https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip" -O commandlinetools.zip
- unzip commandlinetools.zip -d $ANDROID_HOME/
- yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --licenses --sdk_root=$ANDROID_HOME

notifications:
email: false

install:
# List and delete unnecessary components to free space
- sdkmanager --list || true
- sdkmanager --uninstall "system-images;android-15;default;armeabi-v7a"
- sdkmanager --uninstall "system-images;android-16;default;armeabi-v7a"
- sdkmanager --uninstall "system-images;android-17;default;armeabi-v7a"
- sdkmanager --uninstall "system-images;android-18;default;armeabi-v7a"
- sdkmanager --uninstall "system-images;android-19;default;armeabi-v7a"
- sdkmanager --uninstall "system-images;android-21;default;armeabi-v7a"
- sdkmanager --uninstall "extras;google;google_play_services"
- sdkmanager --uninstall "extras;android;support"
- sdkmanager --uninstall "platforms;android-10"
- sdkmanager --uninstall "platforms;android-15"
- sdkmanager --uninstall "platforms;android-16"
- sdkmanager --uninstall "platforms;android-17"
- sdkmanager --uninstall "platforms;android-18"
- sdkmanager --uninstall "platforms;android-19"
- sdkmanager --uninstall "platforms;android-20"
- sdkmanager --uninstall "platforms;android-21"
- sdkmanager --uninstall "platforms;android-22"
- sdkmanager --uninstall "platforms;android-23"
- sdkmanager --uninstall "platforms;android-24"
- sdkmanager --uninstall "platforms;android-25"
- sdkmanager --uninstall "platforms;android-26"
- sdkmanager --uninstall "build-tools;25.0.2"
# Update sdk tools to latest version and install/update components
- echo yes | sdkmanager "tools"
- echo yes | sdkmanager "platforms;android-27" # Latest platform required by SDK tools
- echo yes | sdkmanager "extras;android;m2repository"
- echo yes | sdkmanager "extras;google;m2repository"

script:
- ./gradlew jacocoTestReportDebug coveralls
- ./gradlew jacocoTestReportDebug coveralls

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ While having a good architecture and caching most of the data that is presented

This gives the best performance keeping all fragments in the memory so we won't have to wait for the rebuilding of them. However with many tabs and deep navigation stacks this can lead easily to memory consumption issues.

**WARNING** - Keep in mind that using **show and hide does not trigger the usual lifecycle events** of the fragments so app developer has to manually take care of handling state which is usually done in the Fragment onPause/Stop and onResume/Start methods.
**WARNING** - Keep in mind that using **show and hide does not trigger the usual lifecycle events** of the fragments so app developer has to manually take care of handling state which is usually done in the Fragment onPause/Stop and onResume/Start methods. But you can enable *setMaxLifecycleOnSwitch* to force fragments triggering usual lifecycle events, and it's done on the fragment transaction while switching tabs.

```java
mNavController = FragNavController.newBuilder(...)
Expand Down
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ android {
}
}
}

repositories {
jcenter()
repositories {
google()
jcenter()
mavenCentral()
}
}

dependencies {
implementation project(':frag-nav')
implementation "com.google.android.material:material:1.0.0"
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "com.google.android.material:material:1.5.0"
implementation "androidx.appcompat:appcompat:1.4.1"
implementation "com.roughike:bottom-bar:2.3.1"
testImplementation "junit:junit:$rootProject.ext.junitVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".activities.MainActivity">
<activity android:name=".activities.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.ncapdevi.sample.activities

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.ncapdevi.fragnav.FragNavController
import com.ncapdevi.fragnav.FragNavLogger
import com.ncapdevi.fragnav.FragNavSwitchController
Expand Down Expand Up @@ -74,9 +74,9 @@ class BottomTabsActivity : AppCompatActivity(), BaseFragment.FragmentNavigation,
}
}

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

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.ncapdevi.sample.activities

import android.os.Bundle
import com.google.android.material.navigation.NavigationView
import androidx.fragment.app.Fragment
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import android.view.MenuItem
import android.view.View
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import com.google.android.material.navigation.NavigationView
import com.ncapdevi.fragnav.FragNavController
import com.ncapdevi.fragnav.FragNavTransactionOptions
import com.ncapdevi.sample.R
Expand Down Expand Up @@ -71,7 +71,7 @@ class NavDrawerActivity : AppCompatActivity(), NavigationView.OnNavigationItemSe
}
}

override fun onSaveInstanceState(outState: Bundle?) {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
fragNavController.onSaveInstanceState(outState)
}
Expand All @@ -96,7 +96,7 @@ class NavDrawerActivity : AppCompatActivity(), NavigationView.OnNavigationItemSe
return true
}

override fun pushFragment(fragment: Fragment, sharedList: List<Pair<View, String>>?) {
override fun pushFragment(fragment: Fragment, sharedElementList: List<Pair<View, String>>?) {
fragNavController.pushFragment(fragment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package com.ncapdevi.sample.fragments

import android.content.Context
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button

import androidx.fragment.app.Fragment
import com.ncapdevi.sample.R

/**
Expand All @@ -34,7 +33,7 @@ open class BaseFragment : Fragment() {
}
}

override fun onAttach(context: Context?) {
override fun onAttach(context: Context) {
super.onAttach(context)
if (context is FragmentNavigation) {
mFragmentNavigation = context
Expand Down
27 changes: 12 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
buildscript {
ext.kotlin_version = '1.3.31'
ext.spek_version = '2.0.0-rc.1'
ext.kotlin_version = '1.6.10'
ext.spek_version = '2.0.18'
repositories {
jcenter()
google()

mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.3.1.1"
classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.13.0"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.8.2.0"
classpath "org.jacoco:org.jacoco.core:0.8.7"
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "http://dl.bintray.com/jetbrains/spek" }
}
}

repositories {
google()
jcenter()
mavenCentral()
}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
// App dependencies

junitVersion = '4.12'
buildToolsVersion = '28.0.3'
junitVersion = '4.13.2'
buildToolsVersion = '30.0.3'
minSdkVersion = 14
targetSdkVersion = 28
compileSdkVersion = 28
targetSdkVersion = 31
compileSdkVersion = 31
}
Loading