Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huawei App Gallery Support Added #451

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.8.21'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
74 changes: 74 additions & 0 deletions example/lib/main_huawei_app_gallery.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2019-2024 Larry Aasen. All rights reserved.
*/

import 'package:flutter/material.dart';
import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
import 'package:upgrader/upgrader.dart';

//Add Your App id , clientId , clientSecret to Your Env file
String appId = "your_app_id";
String clientId = "your_client_id";
String clientSecret = "your_client_secret";

void main() async {
WidgetsFlutterBinding.ensureInitialized();
HmsApiAvailability client = HmsApiAvailability();

// 0: HMS Core (APK) is available.
// 1: No HMS Core (APK) is found on device.
// 2: HMS Core (APK) installed is out of date.
// 3: HMS Core (APK) installed on the device is unavailable.
// 9: HMS Core (APK) installed on the device is not the official version.
// 21: The device is too old to support HMS Core (APK).
int status = await client.isHMSAvailable();

// Clear any saved settings for testing purposes (REMOVE this line in production).
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// Start the app with the appropriate store controller based on Google Play availability.
runApp(MyApp(
isHuawei: status == 0, //change this as your need
));
}

class MyApp extends StatelessWidget {
final bool isHuawei;
const MyApp({
super.key,
required this.isHuawei,
});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Upgrader Huawei Example',
home: UpgradeAlert(
upgrader: Upgrader(
storeController: UpgraderStoreController(
onAndroid: () {
// If Google Play Services are unavailable, use Huawei AppGallery.
if (isHuawei) {
return UpgraderHuaweiStore(
appId: appId,
clientId: clientId,
clientSecret: clientSecret,
);
}
// Otherwise, default to Google Play Store.
return UpgraderPlayStore();
},
),
),
child: Scaffold(
appBar: AppBar(
title: const Text('Upgrader Huawei Example'),
),
body: const Center(
child: Text('Checking for updates...'),
),
),
),
);
}
}
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:

go_router: ^7.1.1
http: ^1.2.2
huawei_hmsavailability: ^6.12.0+300
path: ^1.9.0

upgrader:
Expand Down
257 changes: 257 additions & 0 deletions lib/model/huawei_app_info/app_info_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
import 'package:json_annotation/json_annotation.dart';

part 'app_info_response.g.dart';

@JsonSerializable()
class AppInfoResponse {
@JsonKey(name: "ret")
Ret? ret;
@JsonKey(name: "appInfo")
AppInfo? appInfo;
@JsonKey(name: "auditInfo")
AuditInfo? auditInfo;
@JsonKey(name: "languages")
List<Language>? languages;

AppInfoResponse({
this.ret,
this.appInfo,
this.auditInfo,
this.languages,
});

factory AppInfoResponse.fromJson(Map<String, dynamic> json) =>
_$AppInfoResponseFromJson(json);

Map<String, dynamic> toJson() => _$AppInfoResponseToJson(this);
}

@JsonSerializable()
class AppInfo {
@JsonKey(name: "releaseState")
int? releaseState;
@JsonKey(name: "defaultLang")
String? defaultLang;
@JsonKey(name: "parentType")
int? parentType;
@JsonKey(name: "childType")
int? childType;
@JsonKey(name: "grandChildType")
int? grandChildType;
@JsonKey(name: "privacyPolicy")
String? privacyPolicy;
@JsonKey(name: "appAdapters")
String? appAdapters;
@JsonKey(name: "isFree")
int? isFree;
@JsonKey(name: "price")
String? price;
@JsonKey(name: "priceDetail")
String? priceDetail;
@JsonKey(name: "publishCountry")
String? publishCountry;
@JsonKey(name: "contentRate")
String? contentRate;
@JsonKey(name: "hispaceAutoDown")
int? hispaceAutoDown;
@JsonKey(name: "appTariffType")
String? appTariffType;
@JsonKey(name: "developerNameCn")
String? developerNameCn;
@JsonKey(name: "developerNameEn")
String? developerNameEn;
@JsonKey(name: "developerAddr")
String? developerAddr;
@JsonKey(name: "developerEmail")
String? developerEmail;
@JsonKey(name: "developerPhone")
String? developerPhone;
@JsonKey(name: "developerWebsite")
String? developerWebsite;
@JsonKey(name: "certificateURLs")
String? certificateUrLs;
@JsonKey(name: "publicationURLs")
String? publicationUrLs;
@JsonKey(name: "cultureRecordURLs")
String? cultureRecordUrLs;
@JsonKey(name: "updateTime")
DateTime? updateTime;
@JsonKey(name: "versionNumber")
String? versionNumber;
@JsonKey(name: "familyShareTag")
int? familyShareTag;
@JsonKey(name: "deviceTypes")
List<DeviceType>? deviceTypes;

AppInfo({
this.releaseState,
this.defaultLang,
this.parentType,
this.childType,
this.grandChildType,
this.privacyPolicy,
this.appAdapters,
this.isFree,
this.price,
this.priceDetail,
this.publishCountry,
this.contentRate,
this.hispaceAutoDown,
this.appTariffType,
this.developerNameCn,
this.developerNameEn,
this.developerAddr,
this.developerEmail,
this.developerPhone,
this.developerWebsite,
this.certificateUrLs,
this.publicationUrLs,
this.cultureRecordUrLs,
this.updateTime,
this.versionNumber,
this.familyShareTag,
this.deviceTypes,
});

factory AppInfo.fromJson(Map<String, dynamic> json) =>
_$AppInfoFromJson(json);

Map<String, dynamic> toJson() => _$AppInfoToJson(this);
}

@JsonSerializable()
class DeviceType {
@JsonKey(name: "deviceType")
int? deviceType;
@JsonKey(name: "appAdapters")
String? appAdapters;

DeviceType({
this.deviceType,
this.appAdapters,
});

factory DeviceType.fromJson(Map<String, dynamic> json) =>
_$DeviceTypeFromJson(json);

Map<String, dynamic> toJson() => _$DeviceTypeToJson(this);
}

@JsonSerializable()
class AuditInfo {
@JsonKey(name: "auditOpinion")
String? auditOpinion;

AuditInfo({
this.auditOpinion,
});

factory AuditInfo.fromJson(Map<String, dynamic> json) =>
_$AuditInfoFromJson(json);

Map<String, dynamic> toJson() => _$AuditInfoToJson(this);
}

@JsonSerializable()
class Language {
@JsonKey(name: "lang")
String? lang;
@JsonKey(name: "appName")
String? appName;
@JsonKey(name: "appDesc")
String? appDesc;
@JsonKey(name: "briefInfo")
String? briefInfo;
@JsonKey(name: "newFeatures")
String? newFeatures;
@JsonKey(name: "icon")
String? icon;
@JsonKey(name: "showType")
int? showType;
@JsonKey(name: "videoShowType")
int? videoShowType;
@JsonKey(name: "introPic")
String? introPic;
@JsonKey(name: "deviceMaterials")
List<DeviceMaterial>? deviceMaterials;
@JsonKey(name: "rcmdPic")
String? rcmdPic;

Language({
this.lang,
this.appName,
this.appDesc,
this.briefInfo,
this.newFeatures,
this.icon,
this.showType,
this.videoShowType,
this.introPic,
this.deviceMaterials,
this.rcmdPic,
});

factory Language.fromJson(Map<String, dynamic> json) =>
_$LanguageFromJson(json);

Map<String, dynamic> toJson() => _$LanguageToJson(this);
}

@JsonSerializable()
class DeviceMaterial {
@JsonKey(name: "deviceType")
int? deviceType;
@JsonKey(name: "appIcon")
String? appIcon;
@JsonKey(name: "screenShots")
List<String?>? screenShots;
@JsonKey(name: "showType")
int? showType;
@JsonKey(name: "vrCoverLayeredImage")
List<dynamic>? vrCoverLayeredImage;
@JsonKey(name: "vrRecomGraphic4to3")
List<dynamic>? vrRecomGraphic4To3;
@JsonKey(name: "vrRecomGraphic1to1")
List<dynamic>? vrRecomGraphic1To1;
@JsonKey(name: "promoGraphics")
List<dynamic>? promoGraphics;
@JsonKey(name: "videoShowType")
int? videoShowType;
@JsonKey(name: "rcmdPics")
String? rcmdPics;

DeviceMaterial({
this.deviceType,
this.appIcon,
this.screenShots,
this.showType,
this.vrCoverLayeredImage,
this.vrRecomGraphic4To3,
this.vrRecomGraphic1To1,
this.promoGraphics,
this.videoShowType,
this.rcmdPics,
});

factory DeviceMaterial.fromJson(Map<String, dynamic> json) =>
_$DeviceMaterialFromJson(json);

Map<String, dynamic> toJson() => _$DeviceMaterialToJson(this);
}

@JsonSerializable()
class Ret {
@JsonKey(name: "code")
int? code;
@JsonKey(name: "msg")
String? msg;

Ret({
this.code,
this.msg,
});

factory Ret.fromJson(Map<String, dynamic> json) => _$RetFromJson(json);

Map<String, dynamic> toJson() => _$RetToJson(this);
}
Loading
Loading