diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index b568478..4654e95 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -1,8 +1,9 @@ class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server - static String baseUrl = "http://20.203.25.82"; // production server + // static String baseUrl = "http://20.203.25.82"; // production server + static String baseUrl = "http://18.221.16.125"; // new production server static String baseUrlServices = baseUrl + "/services/"; // production server -// static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server + // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String authentication = baseUrlServices + "api/Authentication/"; static String tangheemUsers = baseUrlServices + "api/TangheemUsers/"; static String adminConfiguration = baseUrlServices + "api/AdminConfiguration/"; diff --git a/lib/models/aya_tangheem_type_mapped.dart b/lib/models/aya_tangheem_type_mapped.dart index 3e7691c..2a78743 100644 --- a/lib/models/aya_tangheem_type_mapped.dart +++ b/lib/models/aya_tangheem_type_mapped.dart @@ -46,6 +46,11 @@ class AyatTangheemTypeMappedData { String ayahTextBase; String ayahNos; String ayatNumberInSurahs; + int startIndex; + int endIndex; + String created; + String highlightAyaNos; + List ayahTextList; List property; List voiceNote; @@ -65,6 +70,11 @@ class AyatTangheemTypeMappedData { this.ayahTextBase, this.ayahNos, this.ayatNumberInSurahs, + this.startIndex, + this.endIndex, + this.created, + this.highlightAyaNos, + this.ayahTextList, this.property, this.voiceNote}); @@ -84,6 +94,16 @@ class AyatTangheemTypeMappedData { ayahTextBase = json['ayahTextBase']; ayahNos = json['ayahNos']; ayatNumberInSurahs = json['ayatNumberInSurahs']; + startIndex = json['startIndex']; + endIndex = json['endIndex']; + created = json['created']; + highlightAyaNos = json['highlightAyaNos']; + if (json['ayahTextList'] != null) { + ayahTextList = []; + json['ayahTextList'].forEach((v) { + ayahTextList.add(new AyahTextList.fromJson(v)); + }); + } if (json['property'] != null) { property = []; json['property'].forEach((v) { @@ -115,6 +135,14 @@ class AyatTangheemTypeMappedData { data['ayahTextBase'] = this.ayahTextBase; data['ayahNos'] = this.ayahNos; data['ayatNumberInSurahs'] = this.ayatNumberInSurahs; + data['startIndex'] = this.startIndex; + data['endIndex'] = this.endIndex; + data['created'] = this.created; + data['highlightAyaNos'] = this.highlightAyaNos; + data['ayahTextList'] = this.ayahTextList; + if (this.ayahTextList != null) { + data['ayahTextList'] = this.ayahTextList.map((v) => v.toJson()).toList(); + } if (this.property != null) { data['property'] = this.property.map((v) => v.toJson()).toList(); } @@ -125,10 +153,20 @@ class AyatTangheemTypeMappedData { } String reverseAyatNumber() { - String _ayaTemp = ayahText.substring(0, ayahText.length - ayatNumberInSurah.toString().length); - String _ayaNum = ayahText.substring(ayahText.length - ayatNumberInSurah.toString().length, ayahText.length); + // print("total:${ayahText.length}"); + List ayaNoList = ayatNumberInSurahs.split(",").reversed.toList(); + String text = ""; + for (int i = 0; i < ayahTextList.length; i++) { + text = text + _reverseAyatNumber(ayahTextList[i].ayahText, ayaNoList[i]); + } + return text; + } + + String _reverseAyatNumber(String ayaText, String ayaLength) { + String _ayaTemp = ayaText.substring(0, ayaText.length - ayaLength.toString().length); + String _ayaNum = ayaText.substring(ayaText.length - ayaLength.toString().length, ayaText.length); _ayaNum = _ayaNum.split('').reversed.join(''); - return "$_ayaTemp$_ayaNum"; + return "$_ayaTemp $_ayaNum"; } } @@ -209,3 +247,22 @@ class VoiceNote { return data; } } + +class AyahTextList { + int ayahNo; + String ayahText; + + AyahTextList({this.ayahNo, this.ayahText}); + + AyahTextList.fromJson(Map json) { + ayahNo = json['ayahNo']; + ayahText = json['ayahText']; + } + + Map toJson() { + final Map data = new Map(); + data['ayahNo'] = this.ayahNo; + data['ayahText'] = this.ayahText; + return data; + } +} \ No newline at end of file diff --git a/lib/ui/screens/tangheem_detail_screen.dart b/lib/ui/screens/tangheem_detail_screen.dart index 2eb03d8..1fac97c 100644 --- a/lib/ui/screens/tangheem_detail_screen.dart +++ b/lib/ui/screens/tangheem_detail_screen.dart @@ -249,17 +249,26 @@ class _TangheemDetailScreenState extends State { ], ), SizedBox(height: 8), - TextHighLightWidget( - text: _ayatTangheemTypeMappedData.reverseAyatNumber() ?? "", - valueColor: ColorConsts.primaryBlue, - highlights: _tangheemWords, - highLightFontSize: fontSize, - style: TextStyle( - fontFamily: "UthmanicHafs", - fontSize: fontSize, - fontWeight: FontWeight.bold, - ), + TextHighLightLengthWidget( + text: _ayatTangheemTypeMappedData.reverseAyatNumber(), + startIndex: _ayatTangheemTypeMappedData.startIndex, + endIndex: _ayatTangheemTypeMappedData.endIndex, + textAlign: TextAlign.start, + highlightAya: _ayatTangheemTypeMappedData.highlightText, + highlightAyaNos: _ayatTangheemTypeMappedData.highlightAyaNos??"", + ayahTextList: _ayatTangheemTypeMappedData.ayahTextList, ), + // TextHighLightWidget( + // text: _ayatTangheemTypeMappedData.reverseAyatNumber() ?? "", + // valueColor: ColorConsts.primaryBlue, + // highlights: _tangheemWords, + // highLightFontSize: fontSize, + // style: TextStyle( + // fontFamily: "UthmanicHafs", + // fontSize: fontSize, + // fontWeight: FontWeight.bold, + // ), + // ), SizedBox(height: 16), ListView.separated( itemCount: _tangheemAboveTableList.length, @@ -558,7 +567,7 @@ class _TangheemDetailScreenState extends State { return Container( color: Colors.white, padding: EdgeInsets.all(2), - child: Row( + child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [ for (var property in tangheemPropertyList) Expanded( diff --git a/lib/ui/screens/tangheem_screen.dart b/lib/ui/screens/tangheem_screen.dart index 95aed50..c223f61 100644 --- a/lib/ui/screens/tangheem_screen.dart +++ b/lib/ui/screens/tangheem_screen.dart @@ -118,18 +118,27 @@ class _TangheemScreenState extends State { ), ], ), - TextHighLightWidget( + TextHighLightLengthWidget( text: _dataList[index].reverseAyatNumber(), - valueColor: ColorConsts.secondaryOrange, - highlights: [_dataList[index].highlightText], + startIndex: _dataList[index].startIndex, + endIndex: _dataList[index].endIndex, textAlign: TextAlign.start, - style: TextStyle( - fontFamily: "UthmanicHafs", - fontSize: 16, - color: ColorConsts.primaryBlue, - fontWeight: FontWeight.bold, - ), + highlightAya: _dataList[index].highlightText, + highlightAyaNos: _dataList[index].highlightAyaNos??"", + ayahTextList: _dataList[index].ayahTextList, ), + // TextHighLightWidget( + // text: _dataList[index].reverseAyatNumber(), + // valueColor: ColorConsts.secondaryOrange, + // highlights: [_dataList[index].highlightText], + // textAlign: TextAlign.start, + // style: TextStyle( + // fontFamily: "UthmanicHafs", + // fontSize: 16, + // color: ColorConsts.primaryBlue, + // fontWeight: FontWeight.bold, + // ), + // ), ], ), ), diff --git a/lib/widgets/text_highlight_widget.dart b/lib/widgets/text_highlight_widget.dart index 9ce59b1..614be39 100644 --- a/lib/widgets/text_highlight_widget.dart +++ b/lib/widgets/text_highlight_widget.dart @@ -1,135 +1,229 @@ import 'dart:math'; -import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:tangheem/classes/colors.dart'; +import 'package:tangheem/models/aya_tangheem_type_mapped.dart'; -class TextHighLightWidget extends StatelessWidget { +class TextHighLightLengthWidget extends StatelessWidget { final String text; - final String valueText; - final Color valueColor; - final List highlights; - final TextStyle style; final TextAlign textAlign; + int startIndex; + int endIndex; + final String highlightAyaNos; + final String highlightAya; + final List ayahTextList; final Color highLightColor; - final double highLightFontSize; - final Function(String) onTap; - final Function(String) onAyaTap; - TextHighLightWidget( - {Key key, - this.text, - this.textAlign = TextAlign.center, - this.valueText, - this.valueColor, - this.highlights, - this.highLightColor = ColorConsts.secondaryOrange, - this.style = const TextStyle(), - this.highLightFontSize = 18, - this.onTap, - this.onAyaTap}); + TextHighLightLengthWidget({ + Key key, + this.text, + this.textAlign = TextAlign.center, + this.startIndex, + this.endIndex, + this.highlightAyaNos = "", + this.highlightAya = "", + this.ayahTextList, + this.highLightColor = ColorConsts.secondaryOrange, + }) : super(key: key); + + TextStyle textStyle = TextStyle( + fontFamily: "UthmanicHafs", + fontSize: 16, + color: ColorConsts.primaryBlue, + fontWeight: FontWeight.bold, + ); @override Widget build(BuildContext context) { - if (text == '') { - return _richText(_normalSpan(text)); - } - if (highlights.isEmpty) { - return _richText(_normalSpan(text)); - } - for (int i = 0; i < highlights.length; i++) { - if (highlights[i] == null) { - assert(highlights[i] != null); - return _richText(_normalSpan(text)); - } - if (highlights[i].isEmpty) { - assert(highlights[i].isNotEmpty); - return _richText(_normalSpan(text)); - } - } - List _spans = []; - int _start = 0; - List _lowerCaseHighlights = []; - highlights.forEach((element) { - _lowerCaseHighlights.add(element.toLowerCase()); - }); + // if (startIndex > endIndex) { + // endIndex = endIndex + startIndex; + // } - while (true) { - Map _highlightsMap = Map(); + int actualStartIndex = 0; + if (highlightAyaNos.isNotEmpty) + for (int i = 0; i < ayahTextList.length; i++) { + var eachAyah = ayahTextList[i]; - for (int i = 0; i < highlights.length; i++) { - int _index = text.toLowerCase().indexOf(_lowerCaseHighlights[i], _start); - if (_index >= 0) { - _highlightsMap.putIfAbsent(_index, () => highlights[i]); - } - } - - if (_highlightsMap.isNotEmpty) { - List _indexes = []; - _highlightsMap.forEach((key, value) => _indexes.add(key)); - - int _currentIndex = _indexes.reduce(min); - String _currentHighlight = text.substring(_currentIndex, _currentIndex + _highlightsMap[_currentIndex].length); - - if (_currentIndex == _start) { - _spans.add(_highlightSpan(_currentHighlight)); - _start += _currentHighlight.length; + var abList = highlightAyaNos.split(",").toList(); + if (!(abList.any((e) => e == eachAyah.ayahNo.toString()))) { + //print("e:$e"); + //print("eachAyah.ayahNo:${eachAyah.ayahNo}"); + actualStartIndex += eachAyah.ayahText.length; + //print("actualStartIndex:$actualStartIndex"); } else { - _spans.add(_normalSpan(text.substring(_start, _currentIndex))); - _spans.add(_highlightSpan(_currentHighlight)); - _start = _currentIndex + _currentHighlight.length; + break; } - } else { - _spans.add(_normalSpan(text.substring(_start, text.length))); - break; } + // print("startIndex:$startIndex"); + if (actualStartIndex != 0) { + startIndex = actualStartIndex + startIndex; } + endIndex = (highlightAya.length) + startIndex; + // print("startIndexAf:$startIndex"); + String beforeText = text.substring(0, startIndex); + //print("beforeText:$beforeText"); + // print("endIndex:$endIndex"); + //print("text:${text.length}"); + String highLightText = text.substring(startIndex, endIndex); + // print("highLightText:$highLightText"); + // print("highLightText:${highLightText.length}"); + + String afterText = text.substring(endIndex, text.length); + // print("afterText:$afterText"); + _spans.add(_normalText(beforeText)); + _spans.add(_highlightText(highLightText)); + _spans.add(_normalText(afterText)); - if (valueText != null) { - _spans.add(TextSpan( - text: ' ' + valueText, - style: TextStyle(color: valueColor ?? Color(0xff170026), fontSize: 12, fontWeight: FontWeight.w800), - )); - } return _richText(TextSpan(children: _spans)); } - TextSpan _highlightSpan(String value) { - if (style.color == null) { - return TextSpan( - text: value, - style: style.copyWith(color: highLightColor, fontSize: highLightFontSize), - recognizer: TapGestureRecognizer() - ..onTap = () { - if (onTap != null) { - onTap(value); - } - }); - } else { - return TextSpan(text: value, style: style.copyWith(color: valueColor)); - } + TextSpan _normalText(String text) { + return TextSpan( + text: text, + style: textStyle, + ); } - TextSpan _normalSpan(String value) { - if (style.color == null) { - return TextSpan( - text: value, - style: style.copyWith(color: valueColor), - ); - } else { - return TextSpan(text: value, style: style, children: [ - if (valueText != null) - TextSpan( - text: ' ' + valueText, - style: style, - ) - ]); - } + TextSpan _highlightText(String text) { + return TextSpan( + text: text, + style: textStyle.copyWith(color: highLightColor), + ); } RichText _richText(TextSpan text) { return RichText(key: key, text: text, textAlign: textAlign); } } + +// class TextHighLightWidget extends StatelessWidget { +// final String text; +// final String valueText; +// final Color valueColor; +// final List highlights; +// final TextStyle style; +// final TextAlign textAlign; +// final Color highLightColor; +// final double highLightFontSize; +// final Function(String) onTap; +// final Function(String) onAyaTap; +// +// TextHighLightWidget( +// {Key key, +// this.text, +// this.textAlign = TextAlign.center, +// this.valueText, +// this.valueColor, +// this.highlights, +// this.highLightColor = ColorConsts.secondaryOrange, +// this.style = const TextStyle(), +// this.highLightFontSize = 18, +// this.onTap, +// this.onAyaTap}); +// +// @override +// Widget build(BuildContext context) { +// if (text == '') { +// return _richText(_normalSpan(text)); +// } +// if (highlights.isEmpty) { +// return _richText(_normalSpan(text)); +// } +// for (int i = 0; i < highlights.length; i++) { +// if (highlights[i] == null) { +// assert(highlights[i] != null); +// return _richText(_normalSpan(text)); +// } +// if (highlights[i].isEmpty) { +// assert(highlights[i].isNotEmpty); +// return _richText(_normalSpan(text)); +// } +// } +// +// List _spans = []; +// int _start = 0; +// List _lowerCaseHighlights = []; +// +// highlights.forEach((element) { +// _lowerCaseHighlights.add(element.toLowerCase()); +// }); +// +// while (true) { +// Map _highlightsMap = Map(); +// +// for (int i = 0; i < highlights.length; i++) { +// int _index = text.toLowerCase().indexOf(_lowerCaseHighlights[i], _start); +// if (_index >= 0) { +// _highlightsMap.putIfAbsent(_index, () => highlights[i]); +// } +// } +// +// if (_highlightsMap.isNotEmpty) { +// List _indexes = []; +// _highlightsMap.forEach((key, value) => _indexes.add(key)); +// +// int _currentIndex = _indexes.reduce(min); +// String _currentHighlight = text.substring(_currentIndex, _currentIndex + _highlightsMap[_currentIndex].length); +// +// if (_currentIndex == _start) { +// _spans.add(_highlightSpan(_currentHighlight)); +// _start += _currentHighlight.length; +// } else { +// _spans.add(_normalSpan(text.substring(_start, _currentIndex))); +// _spans.add(_highlightSpan(_currentHighlight)); +// _start = _currentIndex + _currentHighlight.length; +// } +// } else { +// _spans.add(_normalSpan(text.substring(_start, text.length))); +// break; +// } +// } +// +// if (valueText != null) { +// _spans.add(TextSpan( +// text: ' ' + valueText, +// style: TextStyle(color: valueColor ?? Color(0xff170026), fontSize: 12, fontWeight: FontWeight.w800), +// )); +// } +// return _richText(TextSpan(children: _spans)); +// } +// +// TextSpan _highlightSpan(String value) { +// if (style.color == null) { +// return TextSpan( +// text: value, +// style: style.copyWith(color: highLightColor, fontSize: highLightFontSize), +// recognizer: TapGestureRecognizer() +// ..onTap = () { +// if (onTap != null) { +// onTap(value); +// } +// }); +// } else { +// return TextSpan(text: value, style: style.copyWith(color: valueColor)); +// } +// } +// +// TextSpan _normalSpan(String value) { +// if (style.color == null) { +// return TextSpan( +// text: value, +// style: style.copyWith(color: valueColor), +// ); +// } else { +// return TextSpan(text: value, style: style, children: [ +// if (valueText != null) +// TextSpan( +// text: ' ' + valueText, +// style: style, +// ) +// ]); +// } +// } +// +// RichText _richText(TextSpan text) { +// return RichText(key: key, text: text, textAlign: textAlign); +// } +// }