piri

General

Category
Free
Tag
APT
License
N/A
Registered
Jun 5, 2017
Favorites
0
Link
https://github.com/savepopulation/piri
See also
GsonValue
Featured
BundleArgs
Freighter
OnActivityResult

Additional

Language
Java
Version
N/A
Created
May 8, 2017
Updated
Nov 6, 2017 (Retired)
Owner
Taylan Sabırcan (savepopulation)
Contributors
Vladislav Bauer (vbauer)
Mert Şimşek (iammert)
Taylan Sabırcan (savepopulation)
3
Activity
Badge
Generate
Download
Source code

piri

Piri is a lightweight annotation processing library that generates static factory methods for your Activities and Fragments.

How to use?

Add PiriActivity annotation to your Activity.

@PiriActivity
public class YourActivity extends AppCompatActivity {
...
}

And start YourActivity from another Activity.

public class MainActivity extends AppCompatActivity {
...
 navButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Intent intent = PiriIntentFactory.newIntentForYourActivity(MainActivity.this);
                startActivity(intent);
            }
        });
...
}

If you want to pass data to YourActivity with Piri add PiriParam annotation to your fields in your Activity and receive data from bundle.

@PiriActivity
public class YourActivity extends AppCompatActivity {
    
    @PiriParam(key = "extra_id")
    private Long id;

    @PiriParam(key = "extra_name")
    private String name;
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_your);

        final Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            id = bundle.getLong("extra_id");
            name = bundle.getString("extra_name");
        }

        // INIT UI
        ...
    }
}

And start YourActivity like the following:

public class MainActivity extends AppCompatActivity {
...

 final Long id = 1234567890L;
 final String name = "PiriExample";
 navButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Intent intent = PiriIntentFactory.newIntentForYourActivity(MainActivity.this,id,name);
                startActivity(intent);
            }
        });
...
}

Now you can generate your fragment instances with Piri.

Add PiriFragment annotation to your Fragments.

@PiriFragment
public class SampleFragment extends Fragment{
    
    private static final String EXTRA_ID = "extra_id";
    private static final String EXTRA_USER = "extra_user";
    private static final String EXTRA_BOOK = "extra_book";

    @PiriParam(key = EXTRA_ID)
    private Long id;

    @PiriParam(key = EXTRA_USER)
    private User user;

    @PiriParam(key = EXTRA_BOOK)
    private Book book;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args != null) {
            id = args.getLong(EXTRA_ID, 0);
            user = args.getParcelable(EXTRA_USER);
            book = (Book) args.getSerializable(EXTRA_BOOK);
        }
    }
}

Where Piri comes from?

https://en.wikipedia.org/wiki/P%C3%AEr%C3%AE_Reis