Skip to content

Commit bada341

Browse files
committed
Implement add,select and filter tag functionality.
1 parent c5e476b commit bada341

File tree

9 files changed

+790
-32
lines changed

9 files changed

+790
-32
lines changed

lib/Api/event_handler_api.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,13 @@ class EventHandlerApi {
200200
Provider.of<FilterProvider>(context, listen: false);
201201
var maptrackerURIs = {};
202202
var mapStatus = {};
203+
Map<String, dynamic> mapTags = {};
203204
List<String> statusList = [];
205+
filterProvider.tagListMain = [];
206+
filterProvider.mapTags = {'Untagged': 0};
204207
torrentLength = torrentList.length.toString();
208+
209+
//For torrent TrackerURIs
205210
filterProvider.trackerURIsListMain = [];
206211
try {
207212
for (int i = 0; i < torrentList.length; i++) {
@@ -227,6 +232,35 @@ class EventHandlerApi {
227232
} catch (e) {
228233
print(e);
229234
}
235+
236+
//For torrent tags
237+
try {
238+
for (int i = 0; i < torrentList.length; i++) {
239+
if (torrentList[i].tags.isEmpty) {
240+
filterProvider.mapTags.update('Untagged', (value) => ++value);
241+
}
242+
for (int j = 0; j < torrentList[i].tags.length; j++) {
243+
filterProvider.tagListMain.add(torrentList[i].tags[j].toString());
244+
filterProvider.setTagsListMain(filterProvider.tagListMain);
245+
}
246+
}
247+
} catch (e) {
248+
print(e);
249+
}
250+
try {
251+
filterProvider.tagListMain.forEach((element) {
252+
if (!mapTags.containsKey(element)) {
253+
mapTags[element] = 1;
254+
} else {
255+
mapTags[element] += 1;
256+
}
257+
});
258+
filterProvider.setmapTags(mapTags);
259+
} catch (e) {
260+
print(e);
261+
}
262+
263+
//For torrent status
230264
try {
231265
for (int i = 0; i < torrentList.length; i++) {
232266
for (int j = 0; j < torrentList[i].status.length; j++) {
@@ -237,7 +271,6 @@ class EventHandlerApi {
237271
} catch (e) {
238272
print(e);
239273
}
240-
241274
try {
242275
statusList.forEach((element) {
243276
if (!mapStatus.containsKey(element)) {

lib/Api/torrent_api.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,38 @@ class TorrentApi {
347347
return false;
348348
}
349349
}
350+
351+
static Future<void> setTags(
352+
{required List<String> tagLits,
353+
required String hashes,
354+
required BuildContext context}) async {
355+
try {
356+
String url = Provider.of<ApiProvider>(context, listen: false).baseUrl +
357+
ApiProvider.setTags;
358+
print('---SET TAGS---');
359+
print(url);
360+
Response response;
361+
Dio dio = new Dio();
362+
//Headers
363+
dio.options.headers['Accept'] = "application/json";
364+
dio.options.headers['Content-Type'] = "application/json";
365+
dio.options.headers['Connection'] = "keep-alive";
366+
dio.options.headers['Cookie'] =
367+
Provider.of<UserDetailProvider>(context, listen: false).token;
368+
Map<String, dynamic> mp = Map();
369+
mp['hashes'] = [hashes];
370+
mp['tags'] = tagLits;
371+
String rawBody = json.encode(mp);
372+
response = await dio.patch(
373+
url,
374+
data: rawBody,
375+
);
376+
if (response.statusCode == 200) {
377+
} else {
378+
print('--TAG ADDED--');
379+
}
380+
} catch (e) {
381+
print(e);
382+
}
383+
}
350384
}

0 commit comments

Comments
 (0)