项目作者: mafixmafix

项目描述 :
A version checker for Android
高级语言: Java
项目地址: git://github.com/mafixmafix/VersionCheckerSample.git
创建时间: 2019-01-13T13:32:23Z
项目社区:https://github.com/mafixmafix/VersionCheckerSample

开源协议:

下载


VersionChecker

A small, fast, efficient and flexible open source library that checks for your app updates from REST APIs.

Documentation

Will be added as soon as possible!

Build

Building with gradle is fairly straight forward:

  1. git clone https://github.com/mafixmafix/VersionCheckerSample.git
  2. cd VersionCheckerSample
  3. ./gradlew build

Installation

You will need to include the version-checker-0.x.aar in your application’s runtime.

Maven

  1. <dependency>
  2. <groupId>tk.pallas.versionchecker</groupId>
  3. <artifactId>version-checker</artifactId>
  4. <version>0.1.0</version>
  5. <type>pom</type>
  6. </dependency>

Gradle

  1. // Add VersionChecker dependencies
  2. dependencies {
  3. implementation 'tk.pallas.versionchecker:version-checker:0.1.0'
  4. }

Ivy

  1. <dependency org='tk.pallas.versionchecker' name='version-checker' rev='0.1.0'></dependency>

Note: library is available ONLY on JCenter.

Usage

1. Create POJO class from JSON response.

JSON response:

  1. {
  2. "data": {
  3. "id": 2,
  4. "first_name": "Janet",
  5. "last_name": "Weaver",
  6. "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
  7. }
  8. }

POJO class:

  1. public class ResultModel {
  2. Data data;
  3. public Data getData() {
  4. return data;
  5. }
  6. public void setData(Data data) {
  7. this.data = data;
  8. }
  9. @NonNull
  10. @Override
  11. public String toString() {
  12. return data.toString();
  13. }
  14. public static class Data {
  15. Integer id;
  16. String first_name;
  17. String last_name;
  18. String avatar;
  19. public Integer getId() {
  20. return id;
  21. }
  22. public void setId(Integer id) {
  23. this.id = id;
  24. }
  25. public String getFirst_name() {
  26. return first_name;
  27. }
  28. public void setFirst_name(String first_name) {
  29. this.first_name = first_name;
  30. }
  31. public String getLast_name() {
  32. return last_name;
  33. }
  34. public void setLast_name(String last_name) {
  35. this.last_name = last_name;
  36. }
  37. public String getAvatar() {
  38. return avatar;
  39. }
  40. public void setAvatar(String avatar) {
  41. this.avatar = avatar;
  42. }
  43. }
  44. }

Note:

2. Create VersionChecker instance in AppModule.

  1. @Module
  2. public abstract class AppModule {
  3. @Provides
  4. static VersionChecker provideVersionChecker(VersionCheckerClient versionCheckerClient) {
  5. return VersionChecker.Builder.getInstance()
  6. .versionCheckerClient(versionCheckerClient)
  7. .build();
  8. }
  9. @Provides
  10. static VersionCheckerClient provideVersionCheckerClient(Context context, Condition<ResultModel> condition) {
  11. return VersionCheckerClient
  12. .Builder
  13. .getInstance()
  14. .appContext(context)
  15. .condition(condition)
  16. .result(ResultModel.class)
  17. .url("https://reqres.in/api/users/2") // Fake REST_API :)
  18. .build();
  19. }
  20. @Provides
  21. static Condition<ResultModel> provideCondition() {
  22. return new Condition<ResultModel>() {
  23. @Override
  24. public void whatHappen(IVersion<ResultModel> version) {
  25. if (version.getNetworkInfo().isConnected() && version.getTag().equals(MainActivity.TAG)) {
  26. if (version.getResult() != null) {
  27. Log.d("VersionChecker", version.getResult().toString());
  28. ((MainActivity) version.getActivity()).openDialogFragment();
  29. }
  30. }
  31. }
  32. };
  33. }
  34. @Singleton
  35. @Binds
  36. abstract Context bindContext(App app);
  37. }

Note:

  • Sample is based on Dagger2 DI Framework.
  • VersionChecker instance MUST be created in application scope.

3. Invoke start method in onResume method of your activity.

  1. @Override
  2. protected void onResume() {
  3. super.onResume();
  4. versionChecker.start(this, TAG);
  5. }

Note:

  • DON’T invoke start method in any other activity callbacks.(e.g.,onCreate)
  • You can invoke start method in multiple activities!

4. Enjoy!:smiley:

Note:

  • See the sample for more information.

Dependencies

Note: All dependencies will be removed in 1.x version.:wink:

R8 / ProGuard

Will be added as soon as possible!

Contributing

Of course, Pull Requests are welcome.

Here are the few rules we’d like you to respect if you do so:

  • Only edit the code related to the suggested change, so DON’T automatically format the classes you’ve edited.
  • Use IntelliJ default formatting rules.
  • Regarding licensing:
    • You must be the original author of the code you suggest.
    • You must give the copyright to the VersionChecker Project.

License

  1. Copyright 2019 Pallas
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.