Ionic2-Calendar now failing on the device - android

I am developing an Ionic 4 based app with Angular 8 and have a strange situation that has developed. I am using this calendar.
It seems to be similar to this issue... and you will see I have commented there asking how they solved it to no avail.
It works fine on the browser using ionic -serve and WAS working fine on my android device (I haven't gotten to iOS yet).
There was an andoid update to my phone last week and since then, the calendar page doesnt work any longer.
I have stripped out most of the code and simplified it to the extent that it (almost) works now but I have to remove the datasource object.
This leads me to believe there is something wrong with the data in the datasource which I had found before when incorrectly formatted. However, I am uncertain if this is the issue.
The startTime and endTimes come from the server and are converted from ISO strings like this:
fixAppointmentTimesFromServer(appointment: Appointment) {
appointment.startTime = new Date(appointment.StartTimeServer);
appointment.endTime = new Date(appointment.EndTimeServer);
}
If I log out the type of object in the appoinmtents array like this:
this.userService.appointments.forEach( appt => {
console.log(appt.startTime);
console.log(typeof (appt.startTime));
console.log(appt.endTime);
console.log(typeof (appt.endTime));
});
it shows the start/endTimes as strings so I was wondering if this could be the issue, or if thats just more of the mystery that is JS Date objects..?
Or if anyone can tell me how to actually find and get into the Calendar module to debug it, then that might help?
I've added an additional:
this.platform.ready().then( res => {
...
at the start of the ngOninit().
The whole start/end time thing could just be a red herring...
Any thoughts at all? Thanks

I am answering my own question here since I don't want others to have the same issues I had tracking this down.
The way I was fixing up the date for the ionic2 calendar wasn't adequate (apparently) as it needs a millisecond based Date Object to work properly. Different browser versions seem to operate differently.
So, the way I fix up the dates from the server now is as follows:
fixAppointmentTimesFromServer(appointment: Appointment) {
const start = new Date(appointment.StartTimeServer);
const end = new Date(appointment.EndTimeServer);
appointment.startTime = new Date(Date.UTC(start.getFullYear(), start.getMonth(),
start.getDate(), start.getHours(), start.getMinutes()));
appointment.endTime = new Date(Date.UTC(end.getFullYear(), end.getMonth(), end.getDate(), end.getHours(), end.getMinutes()));
}
This converts first to a string and then converts again to get a UTC (millisecond) based Date object. Which does work.
A word of caution however:
I found that when I wasn't getting the data from the server, but using the already converted data from out of Ionic Storage, it broke again. This needing me to reconvert the data when getting it out of storage. So, this wasn't some 'funny date on the server' to JS thing, moreover a perfect example of how completely ******* up Javascript actually is!

Related

Android get dictionary suggestions (equivalent to UiTextChecker)

I'm trying to implement some code in Android similar to code my colleague has written for iOS.
In his code he takes some input text and asks the system for autocomplete suggestions. The purpose is to guess what the next letter might be, so if the user has typed "pri" the possibilities might most likely be "c" (for "price"), "d" (for "pride"), "g" (for "prig") etc
Now my colleague uses an API in iOS called "UiTextChecker().completions" to get possible completions for the text typed so far. I'm looking for something similar in Android.
I saw this answer from 5 years ago which seems to imply that you have to write your own code, and include your own dictionary. Is this still true? Does anyone know of project (and a dictionary) which can be freely used (or at least have some code to parse and organize the dictionaries referred to), or do I have to write my own dictionary and all the code too?
Seems unlikely so much work would be needed to duplicate a simple call in iOS, but I have not found any examples except many many examples of AutoCompleteTextView with a tiny dictionary of 5 fruit or 10 countries.
Well, I really can't find a way to do this - so I simply imported a list of the most commonly used couple of thousand words in English into my app (comma separated), then have some code like this:
// let's create a list of 1000 words
String thousandWords = resources.getString(R.string.words1000list);
String[] list = thousandWords.split(",");
words = Arrays.asList(list);
and I wrote some code like this (uses Java 8):
public class WordPredicates {
public static Predicate<String> startsWith(final String prefix) {
return p -> p.startsWith(prefix);
}
public static List<String> getCandidates (List<String> wordsList, Predicate<String> predicate) {
return wordsList.stream().filter(predicate).collect(Collectors.<String>toList());
}
}
Then whenever I have some text I want possible completions I simply call:
List<String> completions = WordPredicates.getCandidates(words, WordPredicates.startsWith(word));
Works a treat

The model is updating, but not the UI

I am using the ion-datetime-picker in my ionic project. Everything works fine when I debug it in web browser. When I run it on real device, I found a problem. The input text doesn't update. I check it with chrome://inspect/#devices, I see that the value of the input (model) changes even though the text in the input not changing.
I have added new issue here, hopefully anybody here can help too. Many thanks in advance.
UPDATE
I have tried to add a callback too in this plugin with ng-click, and pass the value accordingly to the scope and after that do some triggerHandler to the input.
$scope.changeme = function(val) {
alert(val)
}
The strength is it alert the value three times. The first time it alert the full date description, the second time it alert with time format as expected like 13:30, and finally the last time it only alert Nan:Nan
I also did $scope.$apply() and it still doesn't help.
Please help. I spent my whole night only for this thing. Thanks in advance.
The plugin (made by me) is not meant to be used with <input> element. Why?
It uses ng-model and it's modelValue-viewValue mechanism which is in conflict with ng-model mechanism of input element
It uses Date instance as it's model, which is in conflict with plain string model of input element
The directive marks element that, when tapped, would open the picker. Tapping input element already has it's own meaning - focusing it.
Use <div ion-datetime-picker ng-model="x">{{x | someFilter}}</div> or whatever fits your needs instead.
See #25 and #21 for more info.

Testing html5 inputs in Android application by Robotium

At start i want to say sorry about my English skill. I write automated test for the hybrid Android application. GUI of this app is written in HTML5/JS/CSS3 (with angularJS framework). I want to test any data form. Form is filled with some data on the start (received from server). To enter new data I have to clear current value and enter the new one. For enter new text i use:
By element = By.cssSelector("...");
solo.waitForWebElement(element);
solo.typeTextInWebElement(element, "foo", 0);
and it works well. I have got problems with data clear. In the Robotium documentation i found method:
solo.clearTextInWebElement(item);
This method cannot get index parameter (I don't know why), it only use the "By" object to catch specified element. I decided to use code like:
By item = By.cssSelector("input:nth-child(3)");
this.solo.waitForWebElement(item);
this.solo.sleep(3000);
this.solo.clearTextInWebElement(item);
but still doesn't work too. I don't know how to test web inputs by Robotium.
If the web elements have name or id attributes then you can use By.id("elementId") or By.name("elementName") to access them.
Your question will be easier to answer if you post more sample code, particularly the html of the elements you're trying to test.

Why does calendar.isSet(field) change to true when calling many of the other methods?

I have a project where the isSet method of a Calendar would be very useful, but between clearing a field and reading the isSet flag for that field I need to call another method of the calendar that is affected by this issue.
Here's a sample to demonstrate what is going on:
Calendar cal = Calendar.getInstance();
Log.d(TAG, Boolean.toString(cal.isSet(Calendar.SECOND))); // true
cal.clear(Calendar.SECOND);
Log.d(TAG, Boolean.toString(cal.isSet(Calendar.SECOND))); // false
cal.getTimeInMillis();
// These other methods I've tried, and I'm sure many more, have the same affect on isSet:
// before(calendar), compareTo(calendar), get(field), add(field, int), set(field, int)
// Note: 'field' in above comment line refers to a field other than Calendar.SECOND
Log.d(TAG, Boolean.toString(cal.isSet(Calendar.SECOND))); // true
I've looked at the source for the Calendar class and I don't see what's causing this. Does anyone know why this is happening? Do I need to track the set fields separately?
Update:
It appears this issue may be Android-specific or perhaps a specific version of Java since a couple answerers said it works for them in standard Java. Just to be clear, the class I'm using is still java.util.Calendar. In case the info might help, I am building against the Android 2.2 platform (API 8).
Update 2:
According to someone in #android-dev on FreeNode and my subsequent research on Wikipedia, this is probably because Dalvik uses a subset of Harmony (a Java implementation) for its class library instead of Java. However, that then gets me wondering why Harmony changes the isSet behavior. Needless to say, this issue sounds like it's way too far upstream for there to be a fix in the Android SDK any time soon, so I'll need to settle for a workaround.
I'll leave the question open since it hasn't been properly answered yet.
Is it bug in Harmony as I suspect or intentional design? If intentional, what is the purpose and is there a way to use it as I'm wanting to use it?
Update 3:
I've posted the issue to the Android issue tracker, now to wait and see if anything happens from it. Please star it if this issue is a problem for you as well. I'm hoping Android has its own fork of Harmony and doesn't need to wait for the fix upstream.
https://code.google.com/p/android/issues/detail?id=16826
Also removed the java tag since this is clearly not a Java issue.
Works as expected for me
Working as expected for me..
Here is the code I have used
import java.util.Calendar;
public class Test {
/**
* #param args
*/
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println(Boolean.toString(cal.isSet(Calendar.SECOND)));
cal.clear(Calendar.SECOND);
System.out.println(Boolean.toString(cal.isSet(Calendar.SECOND)));
cal.getTimeInMillis();
System.out.println(Boolean.toString(cal.isSet(Calendar.SECOND)));
}
}
And here is here is the output in console
true
false
false
Thanks,

Parse JSON into a ListView friendly output

So I have this JSON, which then my activity retrieves to a string:
{"popular":
{"authors_last_month": [
{
"url":"http://activeden.net/user/OXYLUS",
"item":"OXYLUS",
"sales":"1148",
"image":"http://s3.envato.com/files/15599.jpg"
},
{
"url":"http://activeden.net/user/digitalscience",
"item":"digitalscience",
"sales":"681",
"image":"http://s3.envato.com/files/232005.jpg"
}
{
...
}
],
"items_last_week": [
{
"cost":"4.00",
"thumbnail":"http://s3.envato.com/files/227943.jpg",
"url":"http://activeden.net/item/christmas-decoration-balls/75682",
"sales":"43",
"item":"Christmas Decoration Balls",
"rating":"3",
"id":"75682"
},
{
"cost":"30.00",
"thumbnail":"http://s3.envato.com/files/226221.jpg",
"url":"http://activeden.net/item/xml-flip-book-as3/63869",
"sales":"27",
"item":"XML Flip Book / AS3",
"rating":"5",
"id":"63869"
},
{
...
}],
"items_last_three_months": [
{
"cost":"5.00",
"thumbnail":"http://s3.envato.com/files/195638.jpg",
"url":"http://activeden.net/item/image-logo-shiner-effect/55085",
"sales":"641",
"item":"image logo shiner effect",
"rating":"5",
"id":"55085"
},
{
"cost":"15.00",
"thumbnail":"http://s3.envato.com/files/180749.png",
"url":"http://activeden.net/item/banner-rotator-with-auto-delay-time/22243",
"sales":"533",
"item":"BANNER ROTATOR with Auto Delay Time",
"rating":"5",
"id":"22243"},
{
...
}]
}
}
It can be accessed here as well, although it because it's quite a long string, I've trimmed the above down to display what is needed.
Basically, I want to be able to access the items from "items_last_week" and create a list of them - originally my plan was to have the 'thumbnail' on the left with the 'item' next to it, but from playing around with the SDK today it appears too difficult or impossible to achieve this, so I would be more than happy with just having the 'item' data from 'items_last_week' in the list.
Coming from php I'm struggling to use any of the JSON libraries which are available to Java, as it appears to be much more than a line of code which I will need to deserialize (I think that's the right word) the JSON, and they all appear to require some form of additional class, apart from the JSONArray/JSONObject script I have which doesn't like the fact that items_last_week is nested (again, I think that's the JSON terminology) and takes an awful long time to run on the Android emulator.
So, in effect, I need a (preferably simple) way to pass the items_last_week data to a ListView. I understand I will need a custom adapter which I can probably get my head around but I cannot understand, no matter how much of the day I've just spent trying to figure it out, how to access certain parts of a JSON string..
originally my plan was to have the
'thumbnail' on the left with the
'item' next to it, but from playing
around with the SDK today it appears
too difficult or impossible to achieve
this
It is far from impossible, but it will be tedious to get right, unless you use something that already wraps up that pattern for you (and that hopefully is reasonably "right"). On the Web, performance/bandwidth issues were the user's problem -- in mobile, they're your problem.
as it appears to be much more than a
line of code which I will need to
deserialize (I think that's the right
word) the JSON
new JSONObject(data) is one line of code. Now, fetching the JSON, which I presume you are doing from the aforementioned URL, will be several lines of code. Neither the parsing of the JSON nor the fetching of it off the Internet is unique to Android -- all of that would look the same on a desktop Java app, or a Java servlet, or whatever.
apart from the JSONArray/JSONObject
script I have which doesn't like the
fact that items_last_week is nested
I have not had a problem parsing JSON with structures like your file exhibits. Moreover, this is hardly unique to Android -- the JSON parser is used in many other Java-based projects.
and takes an awful long time to run on
the Android emulator
The speed of the emulator is tied to the speed of your development machine. For me, the emulator is usually slower than actual phone hardware...and my desktop is a quad-core. Bear in mind that the emulator is pretending to be an ARM chipset running on your PC, converting ARM opcodes into x86 opcodes on the fly, so it's not going to be fast and won't leverage multiple cores very well.
So, in effect, I need a (preferably
simple) way to pass the
items_last_week data to a ListView.
There is nothing really built into Android to take an arbitrary JSON structure, with arbitrary data, and directly pour it into a ListView. This is not unique to JSON -- XML would exhibit similar phenomenon.
Your choices are:
Create a custom ListAdapter that wraps the parsed JSON.
Convert the parsed JSON into a MatrixCursor (think 2D array of data) and use a SimpleCursorAdapter.
Convert the parsed JSON into an ArrayList<String> and use an ArrayAdapter.
For the short term, option #3 is probably the simplest.
I understand I will need a custom
adapter which I can probably get my
head around but I cannot understand,
no matter how much of the day I've
just spent trying to figure it out,
how to access certain parts of a JSON
string..
And that question is too vague for much in the way of assistance. You might consider opening up a separate question, tagged for Java and JSON, where you get into the details of where you are having problems with the json.org parser.

Categories

Resources