-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
249 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,6 @@ app.*.map.json | |
|
||
# key file | ||
key.properties | ||
|
||
#scrath file | ||
test.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:async'; | ||
import 'package:waktusolatmalaysia/models/waktusolatappapi.dart'; | ||
import 'package:waktusolatmalaysia/networking/Response.dart'; | ||
import 'package:waktusolatmalaysia/repository/azanpro_repository.dart'; | ||
|
||
class WaktusolatappBloc { | ||
AzanTimesTodayRepository _prayerTimeRepository; | ||
StreamController _prayDataController; | ||
bool _isStreaming; | ||
|
||
StreamSink<Response<WaktuSolatApp>> get prayDataSink => | ||
_prayDataController.sink; | ||
|
||
Stream<Response<WaktuSolatApp>> get prayDataStream => | ||
_prayDataController.stream; | ||
|
||
WaktusolatappBloc(String category, String format) { | ||
_prayDataController = StreamController<Response<WaktuSolatApp>>(); | ||
_prayerTimeRepository = AzanTimesTodayRepository(); | ||
_isStreaming = true; | ||
// format = format == null ? '' : format; | ||
fetchPrayerTime(category, format); | ||
} | ||
|
||
fetchPrayerTime(String category, String format) async { | ||
prayDataSink.add(Response.loading('Getting prayer times')); | ||
try { | ||
WaktuSolatApp prayerTime = | ||
await _prayerTimeRepository.fetchAzanTodayWSA(category, format); | ||
prayDataSink.add(Response.completed(prayerTime)); | ||
} catch (e) { | ||
prayDataSink.add(Response.error(e.toString())); | ||
print('Error caught: ' + e.toString()); | ||
} | ||
} | ||
|
||
dispose() { | ||
_isStreaming = false; | ||
_prayDataController?.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
class WaktuSolatApp { | ||
bool success; | ||
Data data; | ||
|
||
WaktuSolatApp({this.success, this.data}); | ||
|
||
WaktuSolatApp.fromJson(Map<String, dynamic> json) { | ||
success = json['success']; | ||
data = json['data'] != null ? new Data.fromJson(json['data']) : null; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['success'] = this.success; | ||
if (this.data != null) { | ||
data['data'] = this.data.toJson(); | ||
} | ||
return data; | ||
} | ||
} | ||
|
||
class Data { | ||
Zone zone; | ||
int month; | ||
int year; | ||
List<PrayTimes> prayTimes; | ||
|
||
Data({this.zone, this.month, this.year, this.prayTimes}); | ||
|
||
Data.fromJson(Map<String, dynamic> json) { | ||
zone = json['zone'] != null ? new Zone.fromJson(json['zone']) : null; | ||
month = json['month']; | ||
year = json['year']; | ||
if (json['pray_times'] != null) { | ||
prayTimes = new List<PrayTimes>(); | ||
json['pray_times'].forEach((v) { | ||
prayTimes.add(new PrayTimes.fromJson(v)); | ||
}); | ||
} | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
if (this.zone != null) { | ||
data['zone'] = this.zone.toJson(); | ||
} | ||
data['month'] = this.month; | ||
data['year'] = this.year; | ||
if (this.prayTimes != null) { | ||
data['pray_times'] = this.prayTimes.map((v) => v.toJson()).toList(); | ||
} | ||
return data; | ||
} | ||
} | ||
|
||
class Zone { | ||
String code; | ||
String location; | ||
String state; | ||
String country; | ||
|
||
Zone({this.code, this.location, this.state, this.country}); | ||
|
||
Zone.fromJson(Map<String, dynamic> json) { | ||
code = json['code']; | ||
location = json['location']; | ||
state = json['state']; | ||
country = json['country']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['code'] = this.code; | ||
data['location'] = this.location; | ||
data['state'] = this.state; | ||
data['country'] = this.country; | ||
return data; | ||
} | ||
} | ||
|
||
class PrayTimes { | ||
String hijriDate; | ||
String date; | ||
int subuh; | ||
int imsak; | ||
int dhuha; | ||
int syuruk; | ||
int maghrib; | ||
int isyak; | ||
int zohor; | ||
int asar; | ||
|
||
PrayTimes( | ||
{this.hijriDate, | ||
this.date, | ||
this.subuh, | ||
this.imsak, | ||
this.dhuha, | ||
this.syuruk, | ||
this.maghrib, | ||
this.isyak, | ||
this.zohor, | ||
this.asar}); | ||
|
||
PrayTimes.fromJson(Map<String, dynamic> json) { | ||
hijriDate = json['hijri_date']; | ||
date = json['date']; | ||
subuh = json['subuh']; | ||
imsak = json['imsak']; | ||
dhuha = json['dhuha']; | ||
syuruk = json['syuruk']; | ||
maghrib = json['maghrib']; | ||
isyak = json['isyak']; | ||
zohor = json['zohor']; | ||
asar = json['asar']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['hijri_date'] = this.hijriDate; | ||
data['date'] = this.date; | ||
data['subuh'] = this.subuh; | ||
data['imsak'] = this.imsak; | ||
data['dhuha'] = this.dhuha; | ||
data['syuruk'] = this.syuruk; | ||
data['maghrib'] = this.maghrib; | ||
data['isyak'] = this.isyak; | ||
data['zohor'] = this.zohor; | ||
data['asar'] = this.asar; | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:intl/intl.dart'; | ||
import 'package:waktusolatmalaysia/models/azanproapi.dart'; | ||
import 'package:waktusolatmalaysia/models/waktusolatappapi.dart'; | ||
import 'package:waktusolatmalaysia/networking/ApiProvider.dart'; | ||
|
||
var now = DateTime.now(); | ||
var currentMonthFormatter = DateFormat('MM'); | ||
var currentYearFormatter = DateFormat('y'); | ||
|
||
class AzanTimesTodayRepository { | ||
String currentMonth = currentMonthFormatter.format(now); | ||
String currentYear = currentYearFormatter.format(now); | ||
ApiProvider _provider = ApiProvider(); | ||
|
||
Future<AzanPro> fetchAzanToday(String category, String format) async { | ||
final response = | ||
await _provider.get("times/today.json?zone=" + category + format); | ||
return AzanPro.fromJson(response); | ||
} | ||
|
||
Future<WaktuSolatApp> fetchAzanTodayWSA( | ||
String category, String format) async { | ||
final response = await _provider | ||
.get("?month=$currentMonth&year=$currentYear&zone=$category"); | ||
return WaktuSolatApp.fromJson(response); | ||
} | ||
} |
Oops, something went wrong.