Android Retrofit's #Path don't work. Why? - android

I have an app which takes trivia question from api and display. When I use the actual link for take questions it works (https://trivia.willfry.co.uk/api/questions?categories=movies&limit=16 ) . However when I add path for categories, app does not work.
This is work :
#GET("questions?categories=general_knowledge&limit=16")
Call<List<Questions>> general();
However this is not work :
#GET("questions?categories={type}&limit=16")
Call<List<Questions>> getData(#Path("type") String type);
Also when I delete the app from emulator, and install again with path include method, it works just once. Not second time.

categories is not a path parameter, it's a query, do this instead
#GET("questions?limit=16")
Call<List<Questions>> getData(#Query("categories") String categories);
and about the second problem you mentioned, there's noting in the provided code to find out from

Related

Pass custom variable to Bitrise flow through the API

I am setting up a Bitrise on an Android app. I have everything set that is related to the flow, the thing is that I have a custom python builder which requires a parameter. My build-flow is triggered through API, which is working as expected - the only thing missing is passing that parameter to the build script.
What I have currently:
I have added an env-variable; named PARAM
My JSON body, that triggers the build
{
"hook_info":{
"type":"bitrise"
},
"build_params":{
"branch":"master",
"workflow_id":"test_args_script",
"commit_message":"Triggered from postman",
"environments":[
{
"mapped_to":"PARAM",
"value":"123456",
"is_expand":true
}
]
}
}
On the Bitrise flow I have a script step which is actually calling the python script as follows: python builder.py $PARAM
EXPECTATIONS:
My expectations are that the value that will be passed to the script will be the same as the one in the API payload (123456).
If anyone has recently worked on something similar, or if any of you guys can point me out to documentation that will help me to achieve the above I will be really thankful!
I actually found the way. The problem on my end was that I had an env-variable already named the same as the one variable that has been passed from the API. After changing the name to a different one, I was able to get the parameter and pass it to the build script. If anyone needs more info, give me a shout and I can post the payload along with the flow settings.

Ionic2-Calendar now failing on the device

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!

How to present parsed JSON in readable format to users?

So I have JSON, I parsed in and it's sitting there. From my code below it looks like I have put everything into an ArrayList but then what? I mean for example I need the "title" of each JSON object to be an onClick on the first page, is that possible?
Essentially my onPostExceute() is empty/not doing much. Eventually I need to separate each object into it's own page via the onlicks I'm mentioning, but I think I can do that by separating the JSONObjects...? guess I'll come to that when I can.
If I want to separate things should I even be using an ArrayList? It's just what I used for a server test I ran with different code.
Would really appreciate some help. Basically stuck at the last hurdle is how I perceive it. Maybe I'm wrong though. The logs see that the JSON is showing up as one big chunk.
Edit: Removed my code, this is more of a theory question. ListView being the best thing to go with.
yes you can make spearate arraylist for them..and can store them in diferent listviews...on google click you can open new listview showing id and link for google ..and same you can do for microsoft and your other trem.And using onItemClick is a gud option,you can easily get the index of item clicked//

Android XML Parsing Issue - Multiple occurances of same tag

I followed a tutorial located here: http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/ and so far everything worked fine with it. However this only worked nice when there were specific XML tags to go through, such as:
<tag1>
<gettag></gettag>
<gettag2></gettag2>
</tag1>
However my main issue is that I need to get multiple items from within a single tag, like this:
<tag1>
<tag2>text</tag2>
<tag2>text again</tag2>
<tag2>more text</tag2>
</tag1>
I am not able to use the tutorial code to get all of the tag2 items (it stops at the first one). Does anyone know of a good way to grab those "tag2" tags above and spit out the results into a listview?
Any help is appreciated.
Something you may need to do is,
keep a list, If endElement() is tag2, add readtext to list. if endElement is tag1, then create new List and elements.
Check this discussion.

android getIntent().getSerializableExtra() returns null

I am trying to send bean object(implents Serializable) with 16 strings data obtained from a parser. I am sending that using putExtra("string",serializablevalue) and I'm receiving that using getIntent().getSerializable("string"). I have used this option for almost 10 functionalities it works fine for me.But particular this functionality alone always returns me null in receiving location.I have cross checked it while sending.it has value. While in the receiving location.
My doubt will bean with 16 fields could be sent with this method. Suggest me a better solution for this problem.
Try:
getIntent().getExtras().getSerializable("string")
My code works fine with ArrayList<String>. Could you please give me/us your serializable-strings?
On the other side, based on this: http://developer.android.com/reference/android/os/Parcelable.html, then if you use custom class, you need to "transfer" the data between: public void writeToParcel(Parcel out, int flags) and private MyParcelable(Parcel in).
In details, you can write your data to out, and get them from in.
Check if the String are equals to in both activities!!
it happened to me I had one different capital letter, when I corrected it it worked :)

Categories

Resources