5 Star 5 Fork 1

HarmonyOS-TPC/Parceler

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0
# Parceler Parceler: Simple Bundle data injection framework. # Parceler includes: * Parceler is a simple, lightweight IntentParams data access extension framework. * Using this framework, you can do: * Store any type of data into the Intentparams * Read key value pair any type of data from Intentparams * Inject data from Intentparams into specified member variables * Inject data from the specified member variable into the Intentparams * More convenient page start value transfer (avoid hard coding of key value) * More importantly: the total number of methods in the framework is less than 100, and there is no additional dependency! * in this libraries we have used two more additional modules like compiler and annotation to communicate the api, annotation and compiler to each other. * using this library any types of fast json we can create very easily. # Usage Instructions 1. A sample project which provides runnable code examples that demonstrate uses of the classes in this project is available in the sample/ folder. 2. The following core classes are the essential interface to create the Parceler: Parceler: The entry point for creating the user interface with the help of Parceler. Configure data converter The data converter is the core class of the framework. Only when the corresponding data converter is configured can the framework support access to any type of data. Because the commonly used data format is JSON. Therefore, the framework has customized their respective converters (FastJsonConverter and GsonConverter) for the popular fastjson and GSON, which is convenient for direct use. Please note that the framework itself does not directly rely on fastjson or GSON, so which converter is used. It depends on which converter is supported by your current operating environment. For example, our project depends on fastjson. Then you can choose to rely on the FastJson converter: Parceler.setDefaultConverter(FastJsonConverter.class); After so much verbosity, it is actually just a sentence of configuration, and then you can directly access the data conveniently. 3. IntentParam data automatic injection The most common usage scenario is to use when performing Ability jump transfer value: The initiation of the injection operation can be placed in the base class for use. So you can add the injection operation to the Ability base class: The initiation of the injection operation can be placed in the base class for use. So you can add the injection operation to the Activity base class: public abstract class BaseAbility extends Ability { @Override public void onStart(Intent intent) { super.onStart(intent); Parceler.toEntity(this, getIntent()); } @Override public void onSaveAbilityState(PacMap outState) { super.onSaveAbilityState(outState); Map<String, Object> maps = outState.getAll(); IntentParams intentParams = null; for (String var : maps.keySet()) { intentParams = new IntentParams(); intentParams.setParam(var, maps.keySet()); } Parceler.toBundle(this, intentParams); } @Override public void onRestoreAbilityState(PacMap inState) { super.onRestoreAbilityState(inState); Map<String, Object> maps = inState.getAll(); IntentParams intentParams = null; for (String var : maps.keySet()) { intentParams = new IntentParams(); intentParams.setParam(var, maps.keySet()); } Parceler.toEntity(this, intentParams); } @Override protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) { super.onAbilityResult(requestCode, resultCode, resultData); Parceler.dispatchActivityResult(this, requestCode, resultCode, resultData); } } Then you can happily use it conveniently in various subcategories: public class UserAbility extends BaseAbility { // Use directly. @Arg User user; // Use the specified key value @Arg("rename_address") Address address; @Arg int age; To ... } Then you can happily use it conveniently in various subcategories: 4. Use BundleBuilder to avoid hard coding the key value Take the UserActivity above as an example. Need to jump to this page and pass the data over. We need to load the data into the Intent: IntentParam bundle = Parceler.createFactory(null) .put("user", user) .put("address", address) .put("age", age) .getBundle(); Intent intent = new Intent(); Operation operation = new Intent.OperationBuilder() .withBundleName("com.lzh.compiler.parcelerdemo") .withAbilityName("com.lzh.compiler.parcelerdemo.UserAbility") .build(); intent.setParam("param",bundle) intent.setOperation(operation); startAbility(intent); # Installation instructions 1.For using parceler(api) module in sample app,include the below library dependency to generate hap file: Add the dependencies in entry/build.gradle as below : dependencies { implementation project(path ':api’) implementation 'org.jetbrains:annotations:15.0' implementation 'com.alibaba:fastjson:1.1.57.android' implementation 'com.google.code.gson:gson:2.8.0' } 2. Using the parceler(api) har file , make sure to add the file in the entry/libs folder and add the below dependency in build.gradle. Modify the dependencies in the entry/build.gradle file : dependencies { implementation fileTree(dir: 'libs', include: ['.jar', '.har']) implementation 'org.jetbrains:annotations:15.0' implementation 'com.alibaba:fastjson:1.1.57.android' implementation 'com.google.code.gson:gson:2.8.0'' } 3. For using parceler(api) from a remote repository in separate application, add the below dependencies and include "api.har" in libs folder of "entry" module : Modify entry build.gradle as below : dependencies { implementation fileTree(dir: 'libs', include: ['*.har']) implementation 'io.openharmony.tpc.thirdlib:Parceler:1.0.1' implementation 'org.jetbrains:annotations:15.0' implementation 'com.alibaba:fastjson:1.1.57.android' implementation 'com.google.code.gson:gson:2.8.0' } # License Copyright 2015 Haoge 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.

About

Simple Bundle data injection framework. expand collapse
Java
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HarmonyOS-tpc/Parceler.git
git@gitee.com:HarmonyOS-tpc/Parceler.git
HarmonyOS-tpc
Parceler
Parceler
master

Search