Easy-Fragment-Argument

Additional

Language
Java
Version
N/A
Created
Feb 11, 2017
Updated
Feb 15, 2017 (Retired)
Owner
Arman (armcha)
Contributor
Arman (armcha)
1
Activity
Badge
Generate
Download
Source code

Easy-Fragment-Argument

This library will help you to pass and receive fragment arguments in easier way


Features

###Support types
String
Boolean(boolean)
Integer(int)
Parcelable
Serializable
More types coming soon

#Download

Gradle:

compile 'com.github.armcha:Easy-Fragment-Argument:0.0.1'

#Usage

Step 1. Use

@Argument

annotation to pass arguments,and name of fragment which will receive arguments

@Argument(FirstFragment.class)
private String name = "Test name";

@Argument(FirstFragment.class)
private User testUser;

Step 2. Create fragment

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        testUser = new User("Google", 123456789, 23);

        Fragment fragment = ArgumentFactory.createFragment(this, new FirstFragment());
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container, fragment)
                .commit();
    }

Step 3. Extend your fragment from

ArgumentFragment

or just override

onAttach

and call

ArgumentFactory.onAttach(this);
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    ArgumentFactory.onAttach(this);
}

Step 4. Declare variable in fragment with

@Argument

annotation

@Argument
private String name;

@Argument
private User testUser;

##NOTE Your variables should have the same name, inside Activity and Fragment

That's all, happy coding :)

Contact

Pull requests are more than welcome. Please fell free to contact me if there is any problem when using the library.

License

  Easy-Fragment-Argument library for Android
  Copyright (c) 2017 Arman Chatikyan (https://github.com/armcha/Easy-Fragment-Argumentw).

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.