ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - massivedisaster/AFM: An library to help android developers working easly with activities and fragments (Kotlin version)
An library to help android developers working easly with activities and fragments (Kotlin version) - massivedisaster/AFM
Visit Site

GitHub - massivedisaster/AFM: An library to help android developers working easly with activities and fragments (Kotlin version)

GitHub - massivedisaster/AFM: An library to help android developers working easly with activities and fragments (Kotlin version)

AFM

Download Build Status APILicense: MIT Awesome Kotlin Badge

An library to help android developer working easly with activities and fragments (Kotlin)

Motivation

  • Accelerate the process and abstract the logic of opening, adding and replacing fragments in an activity;
  • Reduce the number of activities declared in the project;
  • Get access to Activity::onBackPressed() inside of the fragments.
  • Add animated transitions between fragments in an easy way;
  • Easy way to work with shared elements;

Download

To use the AFM, add the compile dependency with the latest version.

Gradle

Add the AFM to your build.gradle:

dependencies {
    compile 'com.massivedisaster:afm:0.0.1'
}

Maven

In the pom.xml file:

<dependency>
    <groupId>com.massivedisaster</groupId>
    <artifactId>afm</artifactId>
    <version>0.0.1</version>
</dependency>

Usage

1. Create your Activity

Create a new activity and extends the BaseActivity.

class ActivityPrimaryTheme : BaseActivity() {

    // The layout resource you want to find the FrameLayout.
    override fun layoutToInflate(): Int {
        return R.layout.activity_fullscreen
    }

    // The FrameLayout id you want to inject the fragments.
    override fun getContainerViewId(): Int {
        return R.id.frmContainer
    }
}

Create the layout to be used by your AbstractFragmentActivity.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frmContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

2. Opening, adding or replacing fragments in your AbstractFragmentActivity.

Open a new AbstractFragmentActivity with a fragment.

ActivityCall.init(context, ActivityPrimaryTheme::class, FragmentExample::class)
                .build()

Add a new Fragment in the actual AbstractFragmentActivity.

FragmentCall.init(activity, FragmentExample::class)
                .build()

Replace a new Fragment in the actual AbstractFragmentActivity.

FragmentCall.init(activity as BaseActivity, FragmentExample::class)
                .setTransitionType(FragmentCall.TransitionType.REPLACE)
                .build()

3. Default Fragment

You can set a default fragment in you BaseActivity. An example, if your BaseActivity is started by an external intent you need to define a default fragment.

class ActivityPrimaryTheme : BaseActivity() {
    ...

    override fun getDefaultFragment(): KClass<out Fragment>? {
        return FragmentSplash::class
    }
}

4. Fragment Transaction Animations.

When you add or replace fragments in the old way you can set a custom animations for the transactions. So, you can set custom animation in easly way using this library.

Single Transaction Animation

If you want to add a single animation only for one transaction you can do this:

FragmentCall.init(activity as BaseActivity, FragmentAddReplace::class)
    .setTransitionType(FragmentCall.TransitionType.ADD)
    .setTransactionAnimation(object : TransactionAnimation {
        override val animationEnter: Int
            get() = R.anim.enter_from_right

        override val animationExit: Int
            get() = R.anim.exit_from_left

        override val animationPopEnter: Int
            get() = R.anim.pop_enter

        override val animationPopExit: Int
            get() = R.anim.pop_exit
    }).build()

Attention: This only works in transactions between fragments, i.e. add and replace

Custom animation for all transactions.

If you want to add a custom animation for all transactions inside of a AbstractFragmentActivity you can override the follow methods:

abstract class ActivityPrimaryTheme : BaseActivity() {

    ...

    override val animationEnter: Int
        get() = android.R.anim.fade_in

    override val animationExit: Int
        get() = android.R.anim.fade_out

    override val animationPopEnter: Int
        get() = android.R.anim.fade_in

    override val animationPopExit: Int
        get() = android.R.anim.fade_out

}

5. Shared Elements

If you want to make your app beautiful you need to put some cool animation on it! Shared elements are introduce in API 21 and makes the transactions so great and sweet. So, now it's very easy to share elements between fragments or activities. Let's take a look:

Activity A

...
.addSharedElement(view, "sharedElement")
...
.build()

Activity B

ViewCompat.setTransitionName(view, "sharedElement")

or

<View
  ...
  android:transitionName="sharedElement" />

Attention: Shared elements doesn't work when you use add! Well if you remove the first fragment it's possible, i.e. a replace :)

6. Custom Intents

Sometimes you want to add more information to the Intent or set some flags. You can use the follow method to open a new BaseActivity:

.setFlags(flags)

7. Fragment#OnBackPressed

Allows to have back pressed events in Fragments.

class FragmentOnBackPressed : Fragment(), OnBackPressedListener {

    ...

    @Override
    override fun onBackPressed(): Boolean {
      // Do what you want here! If you return true the activity will not process the OnBackPressed
    }

}

Goodies

  • You can pass a tag to be applied in the Fragment.
  • You can pass REQUEST_CODE to the startActivityForResult.
  • You can addToBackStack.
  • You can pass data between fragments using a Bundle.
  • You can get access to the original FragmentTransaction.
  • You can use DataBinding in your DataBindingBaseActivity, all you need is override initializeDataBinding() and bind the view!

Sample

Sample app can be found in the sample module. Alternatively, you can use dryrun to run the sample.

The Sample app don't require any configuration to interact.

Contributing

CONTRIBUTING

License

MIT LICENSE

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory