Related
This is my first android project (I'm a php developer) but i'm struggling to see how to take this example which uses a nested structure under data for the json array whereas my data is not double nested like this example.
The excample code I am trying to modify is from here https://github.com/datanapps/RetrofitKotlin and the key differences in the json are todo with the nesting.
Original
{
"page": 1,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 1,
"email": "george.bluth#reqres.in",
"first_name": "George",
"last_name": "Bluth",
"avatar": "https://reqres.in/img/faces/1-image.jpg"
},
{
"id": 2,
"email": "james.smith#reqres.in",
"first_name": "James",
"last_name": "Smith",
"avatar": "https://reqres.in/img/faces/1-image.jpg"
}
]
}
whereas mine is simply
[
{
"_id": "62f4cb4e131d9d00046a1b9c",
"device": "AndroidAPS-DexcomG6",
"date": 1660209967000,
"dateString": "2022-08-11T09:26:07.000Z",
"isValid": true,
"sgv": 133,
"direction": "Flat",
"type": "sgv",
"created_at": "2022-08-11T09:26:38.326Z",
"mills": 1660209998326
},
{
"_id": "62f4cb4e131d9d00046a1b9c",
"device": "AndroidAPS-DexcomG6",
"date": 1660209967000,
"dateString": "2022-08-11T09:26:07.000Z",
"isValid": true,
"sgv": 133,
"direction": "Flat",
"type": "sgv",
"created_at": "2022-08-11T09:26:38.326Z",
"mills": 1660209998326
}
]
Specifically I want to query the SGV values, direction and date
Thanks
You "return type" of "method" in Retrofit "interface" will be:
List<MyModel>
And MyModel:
data class MyModel(val _id:String, val device:String,...)
I have the following JSON code for my adaptive card:
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Awesome! 👍",
"wrap": true,
"size": "large",
"weight": "bolder"
}
]
},
{
"type": "TextBlock",
"text": "Let's add some tags and notes to make it more memorable",
"wrap": true
},
{
"type": "Input.ChoiceSet",
"choices": [
{
"title": "Work",
"value": "1"
},
{
"title": "Kids",
"value": "2"
}
],
"id": "tags",
"label": "What influences your current mood?",
"style": "expanded",
"isMultiSelect": true
},
{
"type": "TextBlock",
"text": "Any notes that you would like to add",
"wrap": true
},
{
"type": "Input.Text",
"placeholder": "Write something...",
"id": "notes",
"isMultiline": true
},
{
"type": "Input.Text",
"value": "1",
"id": "moodId",
"isVisible": false
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
]
}
But for some reason it doesn't care for the wrap attribute in Android (iOS is working ok). The MS Teams is refusing my submission because of the horizontal scrollbar, how can I solve this?
iOS
Android
Update:
Tested on:
Xiaomi Redmi Note 8
Android version 11 rkq1.201004.002
Teams version 1416/1.0.0.2021163901/1022
The issue is fixed now. Please update your Teams version and check
I am working on gallery module in which the URL of images coming from web API.In the API there is an event name,image url and description of event.now i want an Album view of particular event.i want to make album of particular event with by default first image and clicking on that album display another images of event.
I want view like this which displayed in image.there is an photo album of particular event and by clicking on that photo album another images of that events are shown.
image
This is My Json Response.
[
{
"Rownumber": 1,
"id": 251,
"image_url": "~/gallery/1635242229_1998256693552243_3617232473282314240_n.jpg",
"Name": "DAMPATI SHIBIR",
"Description": "VIVAHIK JIVAN",
"CreatedDate": "2018-07-02T01:17:23.773",
"CreatedBy": "HIMANSHU_ADMIN",
"TotalRecords": 10
},
{
"Rownumber": 2,
"id": 252,
"image_url": "~/gallery/1635272131_1998256603552252_3478881719728209920_n.jpg",
"Name": "DAMPATI SHIBIR",
"Description": "VIVAHIK JIVAN",
"CreatedDate": "2018-07-02T01:17:23.773",
"CreatedBy": "HIMANSHU_ADMIN",
"TotalRecords": 10
},
{
"Rownumber": 3,
"id": 253,
"image_url": "~/gallery/16WhatsAppImage2018-06-13at11.21.20AM.jpeg",
"Name": "DAMPATI SHIBIR",
"Description": "VIVAHIK JIVAN",
"CreatedDate": "2018-07-02T01:17:23.79",
"CreatedBy": "HIMANSHU_ADMIN",
"TotalRecords": 10
},
{
"Rownumber": 4,
"id": 247,
"image_url": "~/gallery/",
"Name": "MAHAVIR",
"Description": "",
"CreatedDate": "2018-01-27T15:19:49.553",
"CreatedBy": "Bhavesh",
"TotalRecords": 10
},
{
"Rownumber": 5,
"id": 248,
"image_url": "~/gallery/1510991329_460478337432578_9007253566282945229_n.jpg",
"Name": "MAHAVIR",
"Description": "",
"CreatedDate": "2018-01-27T15:20:03.367",
"CreatedBy": "Bhavesh",
"TotalRecords": 10
},
{
"Rownumber": 6,
"id": 249,
"image_url": "~/gallery/15290643_118745158223390_7028747_o.jpg",
"Name": "MAHAVIR",
"Description": "",
"CreatedDate": "2018-01-27T15:20:26.183",
"CreatedBy": "Bhavesh",
"TotalRecords": 10
},
{
"Rownumber": 7,
"id": 250,
"image_url": "~/gallery/14304977_314992211932016_2142854253_n.jpg",
"Name": "MAHAVIR SANKARDHAM 2016",
"Description": "",
"CreatedDate": "2018-01-27T02:57:12.157",
"CreatedBy": "Bhavesh",
"TotalRecords": 10
},
{
"Rownumber": 8,
"id": 244,
"image_url": "~/gallery/14295597_118745108223395_4830375_n.jpg",
"Name": "MAHAVIR SANKARDHAM 2016",
"Description": "",
"CreatedDate": "2018-01-27T00:00:00",
"CreatedBy": "Bhavesh",
"TotalRecords": 10
},
{
"Rownumber": 9,
"id": 245,
"image_url": "~/gallery/1410372160_410043112476101_1188375874765955878_n.jpg",
"Name": "MAHAVIR SANKARDHAM 2016",
"Description": "",
"CreatedDate": "2018-01-27T15:14:12.17",
"CreatedBy": "Bhavesh",
"TotalRecords": 10
},
{
"Rownumber": 10,
"id": 246,
"image_url": "~/gallery/14304977_314992211932016_2142854253_n.jpg",
"Name": "MAHAVIR SANKARDHAM 2016",
"Description": "",
"CreatedDate": "2018-01-27T15:14:42.58",
"CreatedBy": "Bhavesh",
"TotalRecords": 10
}
]
i want to display images in a particualr album which is having same name.
Steps :-
Parse the JSON response to a model
Bind the model to recyclerview
Add GLide library to handle images from Image URL.
Attached a tutorial:-
Gallery
First Creat a Data Class:
data class AlbumInfo(var Rownumber:Int,
var id:Int,
var image_url :String,
var Name :String,
var Description :String,
var CreatedDate :String,
var TotalRecords :String
)
Then the other Data Class for Album
data class AlbumName(var albumName:String, var url :String,var list:List<AlbumInfo>)
Then just do the groupBy() and you will get the required structure
I did on the Basis of Name
var result= list.groupBy { it.Name}.entries.map { (name, group) ->
AlbumName(name, group[0].image_url,group)
}
I guess that will help you. Use the result for your recyclerview.
You will get a response like this.
[
AlbumName(albumName=DAMPATISHIBIR,
url=~/gallery/1635242229_1998256693552243_3617232473282314240_n.jpg,
list=[
AlbumInfo(Rownumber=1,
id=1,
image_url=~/gallery/1635242229_1998256693552243_3617232473282314240_n.jpg,
Name=DAMPATISHIBIR,
Description=VIVAHIKJIVAN,
CreatedDate=2018-07-02T01: 17: 23.773,
TotalRecords=20),
AlbumInfo(Rownumber=2,
id=252,
image_url=~/gallery/1635272131_1998256603552252_3478881719728209920_n.jpg,
Name=DAMPATISHIBIR,
Description=VIVAHIKJIVAN,
CreatedDate=2018-07-02T01: 17: 23.773,
TotalRecords=22)
]),
AlbumName(albumName=MAHAVIR,
url=~/gallery/1635272131_1998256603552252_3478881719728209920_n.jpg,
list=[
AlbumInfo(Rownumber=3,
id=252,
image_url=~/gallery/1635272131_1998256603552252_3478881719728209920_n.jpg,
Name=MAHAVIR,
Description=VIVAHIKJIVAN,
CreatedDate=2018-07-02T01: 17: 23.773,
TotalRecords=22),
AlbumInfo(Rownumber=4,
id=252,
image_url=~/gallery/1635272131_1998256603552252_3478881719728209920_n.jpg,
Name=MAHAVIR,
Description=VIVAHIKJIVAN,
CreatedDate=2018-07-02T01: 17: 23.773,
TotalRecords=22)
]),
AlbumName(albumName=MAHAVIRSANKARDHAM2016,
url=~/gallery/1635272131_1998256603552252_3478881719728209920_n.jpg,
list=[
AlbumInfo(Rownumber=2,
id=252,
image_url=~/gallery/1635272131_1998256603552252_3478881719728209920_n.jpg,
Name=MAHAVIRSANKARDHAM2016,
Description=VIVAHIKJIVAN,
CreatedDate=2018-07-02T01: 17: 23.773,
TotalRecords=22)
])
]
Here's the JSON where jsonObject key is dynamic :
{
"CH000032": [
{
"type": "event",
"details": {
"programID": "MV10000032",
"programType": "MOVIE",
"title": "Titanic",
"year": "1997",
"rating": "PG-13",
"durationSec": 11640,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Movies",
"Action"
],
"description": "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_scale,h_405,w_270/l_Copyright_e3jt1k/v1508831090/Titanic_b0hqo0.jpg"
}
}
],
"CH000033": [
{
"type": "event",
"details": {
"programID": "EP10000132",
"programType": "EPISODE",
"title": "A Chic Bar in Ibiza",
"seriesTitle": "Two and a Half Men",
"seasonNumber": 12,
"epsiodeNumber": 2,
"year": "2014",
"rating": "TV-14",
"durationSec": 1260,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Comedy",
"Romance"
],
"description": "Alan has second thoughts about getting married when Walden has him sign a prenup.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_crop,h_405,w_270//l_Copyright_e3jt1k/v1508831090/2AndHalfmen_splkro.jpg"
}
}
]
}
I would like to parse this JSON. Please let me know how should the class
be written with #SerializedName annotation using Retrofit.
Note : CH000032, CH000033 etc are dynamic.
You can use Map<String, ModelClassName> in your model class for dynamic like below :-
public class Data {
#SerializedName("your_key")
#Expose
private Map<String, ModelClassName> result;
//....
}
this can help to parse dynamic key in retrofit.
What you are asking will take much work , instead a better approach will be to change the structure o json to something like this -
"data": [
{
"type": "event",
"programID": "MV10000032",
"programType": "MOVIE",
"title": "Titanic",
"year": "1997",
"rating": "PG-13",
"durationSec": 11640,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Movies",
"Action"
],
"description": "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_scale,h_405,w_270/l_Copyright_e3jt1k/v1508831090/Titanic_b0hqo0.jpg"
},
{
"type": "event",
"programID": "MV10000032",
"programType": "MOVIE",
"title": "Titanic",
"year": "1997",
"rating": "PG-13",
"durationSec": 11640,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Movies",
"Action"
],
"description": "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_scale,h_405,w_270/l_Copyright_e3jt1k/v1508831090/Titanic_b0hqo0.jpg"
}]
I'm using the LinkedIn Android SDK downloaded from here (version 1.1.4) and have set up authentication already like this:
liSessionManager.init(activity,
Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS), authListener);
and everything works fine, but when I want to get the profile data, returned json is missing fields like summary in job positions and general summary for the given profile.
The request is made like this:
apiHelper.getRequest(activity, GET_LINKED_IN_PROFILE_URL, apiListener);
where GET_LINKED_IN_PROFILE_URL is https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,formatted-name,headline,location,industry,current-share,num-connections,num-connections-capped,summary,specialties,positions,phone-numbers,public-profile-url,picture-url,picture-urls::(original))?format=json.
The response is as follows:
{
"currentShare": {
"author": {
"firstName": "Name",
"id": "***",
"lastName": "Surname"
},
"comment": "I've made my LinkedIn profile visual! Check it out and get yours!",
"content": {
"description": "some descr",
"eyebrowUrl": "http://url.com/me/7827748?m_in&user_id=***",
"resolvedUrl": "http://url.com/me/7827748?m_in&user_id=***",
"shortenedUrl": "http://linkedin.in/url",
"submittedImageUrl": "https://www.url.com/logo-share.png",
"submittedUrl": "https://www.url.com/me/***?m_in&user_id=***",
"thumbnailUrl": "https://media.licdn.com/media-proxy/ext?w=80&h=100&f=&hash=usON2E%2F4FqEGtIT5dsadsaaD&ora=1%2CaFBCTXdkRmpGL2lvQUFBPQ%2CxAVta5g-0R65wFUbzx0776dsaulz-50hKCpDZEXX8HmW3uZHfgasdapuGJ-n08ARIZ3Bex1svPLf5AmX_Us3r",
"title": "title"
},
"id": "s1291360434",
"source": {
"application": {"name": "app"},
"serviceProvider": {"name": "LINKEDIN"}
},
"timestamp": 1346884888000,
"visibility": {"code": "anyone"}
},
"emailAddress": "***#gmail.com",
"firstName": "Name",
"formattedName": "Name Surname",
"headline": "Job position",
"id": "***",
"industry": "Computer Software",
"lastName": "Surname",
"location": {
"country": {"code": "pl"},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"numConnections": 229,
"numConnectionsCapped": false,
"pictureUrl": "https://media.licdn.com/mpr/mprx/photourl",
"pictureUrls": {
"_total": 1,
"values": ["https://media.licdn.com/mpr/mprx/photourl"]
},
"positions": {
"_total": 1,
"values": [{
"company": {
"id": 2795963,
"industry": "Information Technology & Services",
"name": "Company 1",
"size": "11-50",
"type": "Privately Held"
},
"id": ***,
"isCurrent": true,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 1,
"year": 2016
},
"title": "Job position"
}]
},
"publicProfileUrl": "https://www.linkedin.com/in/username/41219"
}
When I use the same url in the API Console at https://apigee.com/console/linkedin, the response looks like this:
{
"currentShare": {
"author": {
"firstName": "Name",
"id": "***",
"lastName": "Surname"
},
"comment": "I've made my LinkedIn profile visual! Check it out and get yours!",
"content": {
"description": "some descr",
"eyebrowUrl": "http://url.com/me/7827748?m_in&user_id=***",
"resolvedUrl": "http://url.com/me/7827748?m_in&user_id=***",
"shortenedUrl": "http://linkedin.com/shortened",
"submittedImageUrl": "https://www.url.com/logo-share.png",
"submittedUrl": "https://www.url.com/me/***?m_in&user_id=***",
"thumbnailUrl": "https://media.licdn.com/media-proxy/ext?w=80&h=100&f=&hash=usON2E%2F4FqEGtIT5dsadsaaD&ora=1%2CaFBCTXdkRmpGL2lvQUFBPQ%2CxAVta5g-0R65wFUbzx0776dsaulz-50hKCpDZEXX8HmW3uZHfgasdapuGJ-n08ARIZ3Bex1svPLf5AmX_Us3r",
"title": "title"
},
"id": "s1291360434",
"source": {
"application": {
"name": "app"
},
"serviceProvider": {
"name": "LINKEDIN"
}
},
"timestamp": 1346884888000,
"visibility": {
"code": "anyone"
}
},
"emailAddress": "***#gmail.com",
"firstName": "Name",
"formattedName": "Name Surname",
"headline": "Job position",
"id": "***",
"industry": "Computer Software",
"lastName": "Surname",
"location": {
"country": {
"code": "pl"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"numConnections": 229,
"numConnectionsCapped": false,
"pictureUrl": "https://media.licdn.com/mpr/mprx/photourl",
"pictureUrls": {
"_total": 1,
"values": [
"https://media.licdn.com/mpr/mprx/photourl"
]
},
"positions": {
"_total": 1,
"values": [
{
"company": {
"id": 2795963,
"industry": "Information Technology & Services",
"name": "Company 1",
"size": "11-50",
"type": "Privately Held"
},
"id": 22222,
"isCurrent": true,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 1,
"year": 2016
},
"title": "Job position"
},
{
"company": {
"id": 611639,
"industry": "Internet",
"name": "Company 2",
"size": "51-200",
"type": "Privately Held"
},
"endDate": {
"month": 2,
"year": 2016
},
"id": 1111,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 4,
"year": 2015
},
"summary": "Summary of job",
"title": "Senior Android Developer"
},
{
"company": {
"id": 1111,
"industry": "Internet",
"name": "Company 2",
"size": "51-200",
"type": "Privately Held"
},
"endDate": {
"month": 3,
"year": 2015
},
"id": 111111,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 4,
"year": 2014
},
"summary": "short summary",
"title": "Android/iOS Developer"
},
{
"company": {
"id": 11111,
"industry": "Internet",
"name": "Company 2",
"size": "51-200",
"type": "Privately Held"
},
"endDate": {
"month": 3,
"year": 2014
},
"id": 1111111,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 2,
"year": 2013
},
"summary": "android applications developer.\ncross-platform mobile application testing (iOS, Windows 8)",
"title": "Junior Android Developer"
},
{
"company": {
"id": 3333,
"industry": "Information Technology & Services",
"name": "Company 3",
"size": "201-500",
"type": "Privately Held"
},
"endDate": {
"month": 11,
"year": 2011
},
"id": 3333333,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Warsaw, Masovian District, Poland"
},
"startDate": {
"month": 7,
"year": 2011
},
"summary": "Intern ",
"title": "Internship"
}
]
},
"publicProfileUrl": "https://www.linkedin.com/in/username/41219"
}
Which shows that the Android SDK's response is missing some job positions and a summary for a profile.
It turned out LinkedIn is not returning fields that have no value. If you don't setup a summary in your profile, then there won't be a field named summary in the response. (Don't expect anything like "summary" : null)
Additionally only first position is returned for a given profile while using r_basicprofile scope. It's confusing since this one profile is returned in the positions array.
based on https://developer.linkedin.com/docs/fields/basic-profile :
Positions - An object representing the member's current position.
See Position Fields for a description of the fields available within this object.
The reason why the API Console's response was having all job positions is because it asked for r_fullprofile scope while authenticating