A library for fast and safe delivery of parameters for Activities and Fragments.

Related tags

Utility MobidMask
Overview

MorbidMask - 吸血面具

Read this in other languages: 中文, English, Change Log

A library for fast and safe delivery of parameters for Activities and Fragments.

Item introduction:

Each attacker will recover 15% of its health based on the damage dealt.

Bloodsucking:15%

Prepare

  1. Add jitpack to build.gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add dependency
apply plugin: 'kotlin-kapt'

...

dependencies {
	implementation 'com.github.ssseasonnn.MobidMask:morbidmask:1.0.5'
    kapt 'com.github.ssseasonnn.MobidMask:compiler:1.0.5'
}

Start

First Blood

  • Add annotations to the Activity:

    @Params(
        Val("intParam", Int::class),
        Val("booleanParam", Boolean::class),
        Val("stringParam", String::class)
    )
    class TestActivity : AppCompatActivity() 

    The Params annotation tells the Activity what type of parameters it needs and the name of the parameters.

    For example, the parameters of TestActivity are:

    • intParam :Int
    • booleanParam :Boolean
    • stringParam :String
  • Pass parameters to Activity:

    After the Params annotation is compiled, the Director file corresponding to the Activity will be generated. The naming rule is the Activity name + Director suffix.

    For example, the above TestActivity will generate the TestActivityDirector file..

    btn_activity.setOnClickListener {
        //Quickly pass parameters to TestActivity via Director Security
        TestActivityDirector.of(this)
            .intParam(1123123123)
            .booleanParam(true)
            .stringParam("This is string param")
            .direct()
    }
  • Get the parameters passed to the Activity:

    After the Params annotation is compiled, in addition to generating the Director file, the corresponding Params file will be generated. The naming rule is the Activity name + Params suffix.

    For example, the above TestActivity will generate the TestActivityParams file.

    class TestActivity : AppCompatActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_test)
    
            val params = TestActivityParams.of(this)
          
            Log.d("TAG", params.intParam.toString())
            Log.d("TAG", params.booleanParam.toString())
            Log.d("TAG", params.stringParam)
        }
    }

Double Kill

Next, try passing the Fragment parameters.

  • Add Params annotation:

    @Params(
        Val("intParam", Int::class),
        Val("booleanParam", Boolean::class),
        Val("stringParam", String::class)
    )
    class TestFragment : Fragment()
  • Passing parameters to Fragment:

    Similarly, after the Params annotation is compiled, the Director file corresponding to the Fragment will be generated. The naming rule is the Fragment name + Director suffix.

    For example, the above TestFragment will generate the TestFragmentDirector file..

    btn_fragment.setOnClickListener {
          TestFragmentDirector.of()
              .intParam(1123123123)
              .booleanParam(true)
              .stringParam("This is string param")
              .direct {
                  val fragmentTransaction = supportFragmentManager.beginTransaction()
                  fragmentTransaction.add(R.id.fragment_container, it)
                  fragmentTransaction.commit()
          }
    }
  • Get the parameters passed to the Fragment:

    After the Params annotation is compiled, in addition to generating the Director file, the corresponding Params file will be generated. The naming rule is Fragment name + Params suffix.

    For example, the above TestFragment will generate the TestFragmentParams file..

    class TestFragment : Fragment() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            val params = TestFragmentParams.of(this)
          
            Log.d("TAG", params.intParam.toString())
            Log.d("TAG", params.booleanParam.toString())
            Log.d("TAG", params.stringParam)
        }
    }

Triple Kill

Pass the custom data type

In addition to the above basic data types, it also supports custom data types.

  • Add custom type parameters:

    //custom type    
    class CustomEntity(
        val id: Int,
        val content: String
    )
    
    @Params(
        Val("customParam", CustomEntity::class)
    )
    class TestActivity : AppCompatActivity() 
  • Pass custom type parameters:

    btn_activity.setOnClickListener {
        TestActivityDirector.of(this)
            .customParam(CustomEntity(123, "Custom entity content"))
            .direct()
    }

Custom data types are serialized and deserialized by default using Gson, so please keep the custom data type in the release environment to avoid problems.!

Ultra Kill

Generate var type parameters with MutableParams annotations.

As seen above, only the val immutable type parameter can be defined by the Params annotation. To define the var variable type parameter, you can pass MutableParams and Var Declare a variable type parameter.

eg:

@Params(
    Val("charParam", Char::class),
    Val("booleanParam", Boolean::class),
    Val("stringParam", String::class)
)
@MutableParams(
    Var("test", String::class),
    Var("test1", Boolean::class)
)
class TestActivity : AppCompatActivity() 

License

Copyright 2019 Season.Zlc

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.
You might also like...
A small library which will save you from writing the same intent creation code again and again for the most simple tasks

Android Intents A small library which will save you from writing the same intent creation code again and again for the most simple tasks. I found myse

Error handling library for Android and Java

ErrorHandler Error handling library for Android and Java Encapsulate error handling logic into objects that adhere to configurable defaults. Then pass

Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app
Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app

DroidMVP About DroidMVP is a small Android library to help you incorporate the MVP pattern along with Passive View and Presentation Model (yes, those

A library to quickly and easily enable multiple monitoring & support platforms for your mobile apps

You have a small team. Setting up crash reporting tools, event tracking tools, and log management services is not what you want to spend your hours do

A simple Android utils library to write any type of data into cache files and read them later.

CacheUtilsLibrary This is a simple Android utils library to write any type of data into cache files and then read them later, using Gson to serialize

A lightweight library for config and using SharedPreferences

preferences-helper SharePreferences is very popular with any project and all most all project has SharePreferences for saving data. This library will

SharedPreference Library to save all types including your custom types and observe them if need be.

A SharedPreference Library that can be used to store all types including your custom classes and observe them too if needed.

🐫🐍🍢🅿 Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case

KaseChange Multiplatform Kotlin library to convert strings between various case formats Supported Case Formats SCREAMING_SNAKE_CASE snake_case PascalC

Multiplaform kotlin library for calculating text differences. Based on java-diff-utils, supports JVM, JS and native targets.

kotlin-multiplatform-diff This is a port of java-diff-utils to kotlin with multiplatform support. All credit for the implementation goes to original a

Owner
Season
会写点代码
Season
Type safe intent building for services and activities

#IntentBuilder Type safe intent building for services and activities. IntentBuilder is a type safe way of creating intents and populating them with ex

Emil Sjölander 348 Oct 10, 2022
XClipper is a clipboard manager for Windows & Android which helps to track clipboard activities and makes it easier to interact with them.

XClipper XClipper is a clipboard manager for Windows & Android which helps to track clipboard activities and makes it easier to interact with them ❤️

Kaustubh Patange 134 Dec 31, 2022
A lightning fast, transactional, file-based FIFO for Android and Java.

Tape by Square, Inc. Tape is a collection of queue-related classes for Android and Java. QueueFile is a lightning-fast, transactional, file-based FIFO

Square 2.4k Dec 30, 2022
Hornox is a fast BSON serializer, deserializer and node extractor for the JVM.

Hornox is a fast, simple-stupid BSON serializer, deserializer and node extractor for the JVM. Features Full implementation of the BSON Specification w

Txture 1 May 12, 2022
A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Yashovardhan Dhanania 35 Dec 10, 2022
Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Trail Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platfor

Mauricio Togneri 13 Aug 29, 2022
UPnP/DLNA library for Java and Android

Cling EOL: This project is no longer actively maintained, code may be outdated. If you are interested in maintaining and developing this project, comm

4th Line 1.6k Jan 4, 2023
A support library for VectorDrawable and AnimatedVectorDrawable classes introduced in Lollipop

vector-compat A support library for VectorDrawable and AnimatedVectorDrawable introduced in Lollipop with fully backwards compatible tint support (api

Wael N 1.2k Nov 29, 2022
Android library for viewing, editing and sharing in app databases.

DbInspector DbInspector provides a simple way to view the contents of the in-app database for debugging purposes. There is no need to pull the databas

Infinum 924 Jan 4, 2023
Android library to easily serialize and cache your objects to disk using key/value pairs.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Anup Cowkur 667 Dec 22, 2022