@@ -17,6 +17,10 @@ class AndroidAppRepository implements AppRepository {
1717
1818 @override
1919 AsyncResult <AppEntity > addInfo (AppEntity app) async {
20+ if (app.appNotInstall) {
21+ return Failure (AndroidPluginException ('App not installed: ${app .repository .projectName }' ));
22+ }
23+
2024 final package = await _androidPackage.getInfoById (app.packageInfo.id);
2125 if (package == null ) {
2226 return Failure (AndroidPluginException ('Package not found: ${app .packageInfo .id }' ));
@@ -101,22 +105,30 @@ class AndroidAppRepository implements AppRepository {
101105 .map (_jsonDecode)
102106 .map (_listToApps)
103107 .recover (_recoverEmptyList)
104- .map (
105- (apps) => apps.map ((a) => a.toNotInstalled ()).toList (),
106- );
108+ .flatMap (_addInfos);
107109 }
108110
109111 @override
110112 AsyncResult <AppEntity > putApp (AppEntity app) {
111113 return fetchApps () //
112- .flatMap ((apps) {
113- if (apps.indexWhere ((element) => element.repository == app.repository) != - 1 ) {
114- return const Failure <String , Exception >(RemoteRepositoryException ('App already exists' ));
114+ .map ((apps) {
115+ final index = apps.indexWhere ((a) => a.repository == app.repository);
116+ if (index != - 1 ) {
117+ final newApps = [
118+ ...apps.sublist (0 , index),
119+ app.copyWith.packageInfo (imageBytes: []),
120+ ...apps.sublist (index + 1 ),
121+ ].map ((a) => a.toJson ()).toList ();
122+ return newApps;
115123 }
116124
117- final newApps = [...apps, app.toNotInstalled ()].map ((a) => a.toJson ()).toList ();
118- return Success (jsonEncode (newApps));
125+ final newApps = [
126+ ...apps,
127+ app.copyWith.packageInfo (imageBytes: []),
128+ ].map ((a) => a.toJson ()).toList ();
129+ return newApps;
119130 })
131+ .map (jsonEncode)
120132 .flatMap ((json) => _localStorage.saveData (_localAndroidAppKey, json))
121133 .pure (app);
122134 }
@@ -143,7 +155,7 @@ class AndroidAppRepository implements AppRepository {
143155 }
144156
145157 List <AppEntity > _listToApps (List <Map <String , Object ?>> list) {
146- return list.map (NotInstalledAppEntity .fromJson).toList ();
158+ return list.map (AppEntity .fromJson).toList ();
147159 }
148160
149161 List <Map <String , Object ?>> _jsonDecode (String json) {
@@ -156,4 +168,15 @@ class AndroidAppRepository implements AppRepository {
156168 return [];
157169 }
158170 }
171+
172+ AsyncResult <List <AppEntity >> _addInfos (List <AppEntity > apps) async {
173+ final List <AppEntity > newApps = [];
174+
175+ for (final app in apps) {
176+ final result = await addInfo (app);
177+ newApps.add (result.getOrDefault (app));
178+ }
179+
180+ return Success (newApps);
181+ }
159182}
0 commit comments