Popular New Releases in Xiaomi
Valetudo
Valetudo 2022.03.1
XiaomiADBFastbootTools
Xiaomi ADB/Fastboot Tools 7.0.3
python-miio
0.5.11
MiPushFramework
0.3.7.20210106.1425051
ATC_MiThermometer
Release 76
Popular Libraries in Xiaomi
by yanzhenjie java
6513 Apache-2.0
:strawberry: Permissions manager for Android platform.
by Freeyourgadget java
3832 NOASSERTION
We are on codeberg.org now! https://codeberg.org/Freeyourgadget/Gadgetbridge - Gadgetbridge - A free and cloudless replacement for your gadget vendors' closed source Android applications. Supports Pebble, Mi Band, Liveview, HPlus and more.
by brandonlw csharp
3774 MIT
Phison 2251-03 (2303) Custom Firmware & Existing Firmware Patches (BadUSB)
by Hypfer javascript
2954 Apache-2.0
Cloud-free control webinterface for vacuum robots
by Szaki kotlin
2389 MIT
A simple tool for managing Xiaomi devices on desktop using ADB and Fastboot
by rytilahti python
2115 NOASSERTION
Python library & console tool for controlling Xiaomi smart appliances
by dgiese c
1939 GPL-3.0
Xiaomi Smart Home Device Reverse Engineering and Hacking
by MiPushFramework java
1854 GPL-3.0
Let supported push service run system-ly on every Android devices
by atc1441 c
1660
Custom firmware for the Xiaomi Thermometer LYWSD03MMC and Telink Flasher via USB to Serial converter
Trending New libraries in Xiaomi
by atc1441 c
1660
Custom firmware for the Xiaomi Thermometer LYWSD03MMC and Telink Flasher via USB to Serial converter
by PiotrMachowski python
1458 MIT
This tool/script retrieves tokens for all devices connected to Xiaomi cloud and encryption keys for BLE devices.
by AlexxIT python
1360
Control Zigbee, BLE and Mesh devices from Home Assistant with Xiaomi Gateway 3 on original firmware
by ha0y python
1322 Apache-2.0
All-in-one & Easy-to-use. Integrate all your Xiaomi Smart Home - with a single integration and NO YAML files - into Home Assistant.
by al-one python
974 Apache-2.0
Automatic integrate all Xiaomi devices to HomeAssistant via miot-spec, support Wi-Fi, BLE, ZigBee devices.
by PiotrMachowski python
658 MIT
This custom integration provides a way to present a live view of a map for Xiaomi, Roborock, Viomi and Roidmi vacuums without a need for rooting.
by JsBergbau python
466
Read the values of the Xiaomi Mi Bluetooth Temperature sensor 2 including custom encrypted format.
by argrento python
178 MIT
Script to obtain watch or band bluetooth token from Huami servers
by bropat typescript
166 MIT
This shared library allows to control Eufy security devices by connecting to the Eufy cloud servers and local/remote stations over p2p.
Top Authors in Xiaomi
1
23 Libraries
219
2
21 Libraries
233
3
16 Libraries
824
4
12 Libraries
66
5
10 Libraries
236
6
9 Libraries
66
7
9 Libraries
1510
8
8 Libraries
1220
9
8 Libraries
72
10
6 Libraries
599
1
23 Libraries
219
2
21 Libraries
233
3
16 Libraries
824
4
12 Libraries
66
5
10 Libraries
236
6
9 Libraries
66
7
9 Libraries
1510
8
8 Libraries
1220
9
8 Libraries
72
10
6 Libraries
599
Trending Kits in Xiaomi
No Trending Kits are available at this moment for Xiaomi
Trending Discussions on Xiaomi
Filtering property of type array on an array of objects by using another array
OAuth2 Redirect URI not valid
Get the documents of order id 1 that are not in order id 2 MongoDB
How to make completely transparent status bar?
SQL Subquery with OR condition
Service not registered: com.microsoft.identity.common.internal.ui.browser.CustomTabsManager$1@4af7a6e
Why doesn't the data from the server come to the app on the real device?
New instance of a class contains older data given to an older instance
java.lang.IncompatibleClassChangeError,After Upgrade kotlin gradle plugin to 1.5.20
Will i get the entire document from the firestore?
QUESTION
Filtering property of type array on an array of objects by using another array
Asked 2022-Mar-21 at 22:11I have an array of objects that needs to be filtered by using two menus. Each menu returns an array. The values of these arrays will be used to filter the object array.
I have created a codepen example here : https://codepen.io/jonathank2018/pen/LYeZgQG?editors=1010
For this example lets concentrate on the "Aces" menu only. The filtering logic that i am trying to make is the following. scenario 1 : When I select "Services" from the "Aces" menu, the value of "valuesAces" becomes ["Services"]. scenario 2 : When I select "Services" and "Connected" from the "Aces" menu, the value of "valuesAces" becomes ["Services","Connected"]. When I filter "linksArray" with the values returned from "valuesAces", I need the result to be an array with all the objects that have within their aces property at least one of the items in "valuesAces".
for scenario 1 , I expect as result all the objects that have as their aces property ["Services"] as unique value, and ["Services", "othervalues...","othervalues..."].
1scenario1 = [ // services selected
2 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
3 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
4 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
5 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
6 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
7 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
8 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
9 ]
10
for scenario 2 , I expect as result all the objects that have as their aces property ["Services"] , or ["Services", "othervalues...","othervalues..."], or ["Connected"], or ["Services", "Connected","othervalues..."], or ["Connected","othervalues..."].
1scenario1 = [ // services selected
2 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
3 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
4 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
5 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
6 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
7 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
8 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
9 ]
10 let scenario2 = [ //services and connected selected
11 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
12 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
13 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
14 { "src": "Hesai", "target": "Black_Sesame", "aces": [ "Automated", " Connected" ], "topic": [ "AV_Driverless" ] },
15 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
16 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
17 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
18 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
19 { "src": "BMW", "target": "Deutsche_Telekom", "aces": [ "Connected" ], "topic": [ "E/E_Architecture" ] },
20 ]
21
If the object's aces property has at least one or several values from valuesAces, then it needs to be in the result of the filter.
The problem I am currently facing with my codepen example, is that it is not filtering the way I want it to. Right now if i refer to scenario 2, in the result I only find the objects that have as aces property either "Services" or "Connected" as first item of the array , but not the objects that have several items in the aces property and where "Services" or "Connected" are not at index 0. It seems to ignore all other items in the array exept for the first one.
My filtering function looks like this :
1scenario1 = [ // services selected
2 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
3 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
4 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
5 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
6 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
7 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
8 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
9 ]
10 let scenario2 = [ //services and connected selected
11 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
12 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
13 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
14 { "src": "Hesai", "target": "Black_Sesame", "aces": [ "Automated", " Connected" ], "topic": [ "AV_Driverless" ] },
15 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
16 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
17 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
18 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
19 { "src": "BMW", "target": "Deutsche_Telekom", "aces": [ "Connected" ], "topic": [ "E/E_Architecture" ] },
20 ]
21filteredLinks: function(){
22 console.log("1")
23 let result
24 if(this.linksArray){
25 if(
26 (!this.valuesTopic || this.valuesTopic.length == 0) // by topic
27 && (!this.valuesAces || this.valuesAces.length == 0) // by ACES
28 ){
29 console.log("2")
30 result = this.linksArray
31 }else{
32 console.log("3")
33 result = this.linksArray.filter(link => { return (
34 ( !this.valuesTopic || this.valuesTopic.length == 0 || ([...link.topic].some(topic => this.valuesTopic.includes(topic)))) // by topic
35 &&( !this.valuesAces || this.valuesAces.length == 0 || ([...link.aces].some(ace => this.valuesAces.includes(ace)))) // by ACES
36 )})
37 }
38 return result;
39 }
40 },
41
ANSWER
Answered 2022-Mar-21 at 22:11You could filter the linksArray
array based on checking if linksArray.aces
array items exist in valuesAces
as follows:
1scenario1 = [ // services selected
2 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
3 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
4 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
5 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
6 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
7 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
8 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
9 ]
10 let scenario2 = [ //services and connected selected
11 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
12 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
13 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
14 { "src": "Hesai", "target": "Black_Sesame", "aces": [ "Automated", " Connected" ], "topic": [ "AV_Driverless" ] },
15 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
16 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
17 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
18 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
19 { "src": "BMW", "target": "Deutsche_Telekom", "aces": [ "Connected" ], "topic": [ "E/E_Architecture" ] },
20 ]
21filteredLinks: function(){
22 console.log("1")
23 let result
24 if(this.linksArray){
25 if(
26 (!this.valuesTopic || this.valuesTopic.length == 0) // by topic
27 && (!this.valuesAces || this.valuesAces.length == 0) // by ACES
28 ){
29 console.log("2")
30 result = this.linksArray
31 }else{
32 console.log("3")
33 result = this.linksArray.filter(link => { return (
34 ( !this.valuesTopic || this.valuesTopic.length == 0 || ([...link.topic].some(topic => this.valuesTopic.includes(topic)))) // by topic
35 &&( !this.valuesAces || this.valuesAces.length == 0 || ([...link.aces].some(ace => this.valuesAces.includes(ace)))) // by ACES
36 )})
37 }
38 return result;
39 }
40 },
41// Filter linksArray
42linksArray.filter((item) => {
43 return item.aces
44 // 'aces' values in provided codepen has spaces so trim those.
45 // If actual data doesn't have spaces, this map can be removed.
46 .map((i) => {
47 return i.trim()
48 })
49 // Check if 'acesValues' are in 'linksArray.aces' array
50 .some((v) => {
51 return valuesAces.includes(v)
52 })
53})
54
Or as a one liner:
1scenario1 = [ // services selected
2 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
3 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
4 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
5 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
6 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
7 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
8 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
9 ]
10 let scenario2 = [ //services and connected selected
11 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
12 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
13 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
14 { "src": "Hesai", "target": "Black_Sesame", "aces": [ "Automated", " Connected" ], "topic": [ "AV_Driverless" ] },
15 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
16 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
17 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
18 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
19 { "src": "BMW", "target": "Deutsche_Telekom", "aces": [ "Connected" ], "topic": [ "E/E_Architecture" ] },
20 ]
21filteredLinks: function(){
22 console.log("1")
23 let result
24 if(this.linksArray){
25 if(
26 (!this.valuesTopic || this.valuesTopic.length == 0) // by topic
27 && (!this.valuesAces || this.valuesAces.length == 0) // by ACES
28 ){
29 console.log("2")
30 result = this.linksArray
31 }else{
32 console.log("3")
33 result = this.linksArray.filter(link => { return (
34 ( !this.valuesTopic || this.valuesTopic.length == 0 || ([...link.topic].some(topic => this.valuesTopic.includes(topic)))) // by topic
35 &&( !this.valuesAces || this.valuesAces.length == 0 || ([...link.aces].some(ace => this.valuesAces.includes(ace)))) // by ACES
36 )})
37 }
38 return result;
39 }
40 },
41// Filter linksArray
42linksArray.filter((item) => {
43 return item.aces
44 // 'aces' values in provided codepen has spaces so trim those.
45 // If actual data doesn't have spaces, this map can be removed.
46 .map((i) => {
47 return i.trim()
48 })
49 // Check if 'acesValues' are in 'linksArray.aces' array
50 .some((v) => {
51 return valuesAces.includes(v)
52 })
53})
54linksArray.filter((item) => item.aces.map((i) => i.trim()).some((v) => acesValues.includes(v)))
55
Here is an example:
1scenario1 = [ // services selected
2 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
3 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
4 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
5 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
6 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
7 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
8 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
9 ]
10 let scenario2 = [ //services and connected selected
11 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
12 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
13 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
14 { "src": "Hesai", "target": "Black_Sesame", "aces": [ "Automated", " Connected" ], "topic": [ "AV_Driverless" ] },
15 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
16 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
17 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
18 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
19 { "src": "BMW", "target": "Deutsche_Telekom", "aces": [ "Connected" ], "topic": [ "E/E_Architecture" ] },
20 ]
21filteredLinks: function(){
22 console.log("1")
23 let result
24 if(this.linksArray){
25 if(
26 (!this.valuesTopic || this.valuesTopic.length == 0) // by topic
27 && (!this.valuesAces || this.valuesAces.length == 0) // by ACES
28 ){
29 console.log("2")
30 result = this.linksArray
31 }else{
32 console.log("3")
33 result = this.linksArray.filter(link => { return (
34 ( !this.valuesTopic || this.valuesTopic.length == 0 || ([...link.topic].some(topic => this.valuesTopic.includes(topic)))) // by topic
35 &&( !this.valuesAces || this.valuesAces.length == 0 || ([...link.aces].some(ace => this.valuesAces.includes(ace)))) // by ACES
36 )})
37 }
38 return result;
39 }
40 },
41// Filter linksArray
42linksArray.filter((item) => {
43 return item.aces
44 // 'aces' values in provided codepen has spaces so trim those.
45 // If actual data doesn't have spaces, this map can be removed.
46 .map((i) => {
47 return i.trim()
48 })
49 // Check if 'acesValues' are in 'linksArray.aces' array
50 .some((v) => {
51 return valuesAces.includes(v)
52 })
53})
54linksArray.filter((item) => item.aces.map((i) => i.trim()).some((v) => acesValues.includes(v)))
55let linksArray = [
56 { src: 'SemiDrive', target: 'ADAYO', aces: ['Automated', ' Experience'], topic: ['EE_Architecture'] },
57 { src: 'WayRay', target: 'AGP', aces: ['Services'], topic: ['Map_Localisation'] },
58 { src: 'Hesai', target: 'Aiways', aces: ['Automated'], topic: ['Car_Access'] },
59 { src: 'Oxbotica', target: 'AppliedEV', aces: ['Automated'], topic: ['Regulation'] },
60 { src: 'Great_Wall', target: 'Audi', aces: ['Automated', ' Connected', ' Experience', ' Services'], topic: ['AP', ' AVP', ' Infrastructure'] },
61 { src: 'Audi', target: 'BMW', aces: ['Automated', ' Connected', ' Experience', ' Services'], topic: ['AP', ' AVP', ' Infrastructure'] },
62 { src: 'AEye', target: 'Benchmark', aces: ['Automated'], topic: [] },
63 { src: 'Hesai', target: 'Black_Sesame', aces: ['Automated', ' Connected'], topic: ['AV_Driverless'] },
64 { src: 'FAW', target: 'Cambricon', aces: ['Automated'], topic: ['AS_ADAS_uptoL2+'] },
65 { src: 'GM', target: 'Cruise', aces: ['Automated', ' Services'], topic: ['AV_Driverless'] },
66 { src: 'Honda', target: 'Cruise', aces: ['Automated', ' Services'], topic: ['Parking'] },
67 { src: 'Audi', target: 'Daimler', aces: ['Services', ' Connected', ' Experience'], topic: ['AP', ' AVP', ' Infrastructure'] },
68 { src: 'Xiaomi', target: 'Deepmotion', aces: ['Automated', ' Services'], topic: ['ADAS_uptoL2+', ' AVP'] },
69 { src: 'Alibaba', target: 'Deeproute', aces: ['Automated'], topic: ['AD_Driverless'] },
70 { src: 'BMW', target: 'Deutsche_Telekom', aces: ['Connected'], topic: ['E/E_Architecture'] }
71]
72
73let acesValues1 = ['Services']
74let acesValues2 = ['Services', 'Connected']
75
76const filterLinks = (links, aces) =>
77 links.filter((item) => item.aces.map((i) => i.trim()).some((v) => aces.includes(v)))
78
79console.log(filterLinks(linksArray, acesValues1))
80console.log(filterLinks(linksArray, acesValues2))
EDIT
Based on OP's comments, removed leading spaces from linksArray.aces
values and added the topics filter:
1scenario1 = [ // services selected
2 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
3 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
4 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
5 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
6 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
7 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
8 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
9 ]
10 let scenario2 = [ //services and connected selected
11 { "src": "WayRay", "target": "AGP", "aces": [ "Services" ], "topic": [ "Map_Localisation" ] },
12 { "src": "Great_Wall", "target": "Audi", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
13 { "src": "Audi", "target": "BMW", "aces": [ "Automated", " Connected", " Experience", " Services" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
14 { "src": "Hesai", "target": "Black_Sesame", "aces": [ "Automated", " Connected" ], "topic": [ "AV_Driverless" ] },
15 { "src": "GM", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "AV_Driverless" ] },
16 { "src": "Honda", "target": "Cruise", "aces": [ "Automated", " Services" ], "topic": [ "Parking" ] },
17 { "src": "Audi", "target": "Daimler", "aces": [ "Services", " Connected", " Experience" ], "topic": [ "AP", " AVP", " Infrastructure" ] },
18 { "src": "Xiaomi", "target": "Deepmotion", "aces": [ "Automated", " Services" ], "topic": [ "ADAS_uptoL2+", " AVP" ] },
19 { "src": "BMW", "target": "Deutsche_Telekom", "aces": [ "Connected" ], "topic": [ "E/E_Architecture" ] },
20 ]
21filteredLinks: function(){
22 console.log("1")
23 let result
24 if(this.linksArray){
25 if(
26 (!this.valuesTopic || this.valuesTopic.length == 0) // by topic
27 && (!this.valuesAces || this.valuesAces.length == 0) // by ACES
28 ){
29 console.log("2")
30 result = this.linksArray
31 }else{
32 console.log("3")
33 result = this.linksArray.filter(link => { return (
34 ( !this.valuesTopic || this.valuesTopic.length == 0 || ([...link.topic].some(topic => this.valuesTopic.includes(topic)))) // by topic
35 &&( !this.valuesAces || this.valuesAces.length == 0 || ([...link.aces].some(ace => this.valuesAces.includes(ace)))) // by ACES
36 )})
37 }
38 return result;
39 }
40 },
41// Filter linksArray
42linksArray.filter((item) => {
43 return item.aces
44 // 'aces' values in provided codepen has spaces so trim those.
45 // If actual data doesn't have spaces, this map can be removed.
46 .map((i) => {
47 return i.trim()
48 })
49 // Check if 'acesValues' are in 'linksArray.aces' array
50 .some((v) => {
51 return valuesAces.includes(v)
52 })
53})
54linksArray.filter((item) => item.aces.map((i) => i.trim()).some((v) => acesValues.includes(v)))
55let linksArray = [
56 { src: 'SemiDrive', target: 'ADAYO', aces: ['Automated', ' Experience'], topic: ['EE_Architecture'] },
57 { src: 'WayRay', target: 'AGP', aces: ['Services'], topic: ['Map_Localisation'] },
58 { src: 'Hesai', target: 'Aiways', aces: ['Automated'], topic: ['Car_Access'] },
59 { src: 'Oxbotica', target: 'AppliedEV', aces: ['Automated'], topic: ['Regulation'] },
60 { src: 'Great_Wall', target: 'Audi', aces: ['Automated', ' Connected', ' Experience', ' Services'], topic: ['AP', ' AVP', ' Infrastructure'] },
61 { src: 'Audi', target: 'BMW', aces: ['Automated', ' Connected', ' Experience', ' Services'], topic: ['AP', ' AVP', ' Infrastructure'] },
62 { src: 'AEye', target: 'Benchmark', aces: ['Automated'], topic: [] },
63 { src: 'Hesai', target: 'Black_Sesame', aces: ['Automated', ' Connected'], topic: ['AV_Driverless'] },
64 { src: 'FAW', target: 'Cambricon', aces: ['Automated'], topic: ['AS_ADAS_uptoL2+'] },
65 { src: 'GM', target: 'Cruise', aces: ['Automated', ' Services'], topic: ['AV_Driverless'] },
66 { src: 'Honda', target: 'Cruise', aces: ['Automated', ' Services'], topic: ['Parking'] },
67 { src: 'Audi', target: 'Daimler', aces: ['Services', ' Connected', ' Experience'], topic: ['AP', ' AVP', ' Infrastructure'] },
68 { src: 'Xiaomi', target: 'Deepmotion', aces: ['Automated', ' Services'], topic: ['ADAS_uptoL2+', ' AVP'] },
69 { src: 'Alibaba', target: 'Deeproute', aces: ['Automated'], topic: ['AD_Driverless'] },
70 { src: 'BMW', target: 'Deutsche_Telekom', aces: ['Connected'], topic: ['E/E_Architecture'] }
71]
72
73let acesValues1 = ['Services']
74let acesValues2 = ['Services', 'Connected']
75
76const filterLinks = (links, aces) =>
77 links.filter((item) => item.aces.map((i) => i.trim()).some((v) => aces.includes(v)))
78
79console.log(filterLinks(linksArray, acesValues1))
80console.log(filterLinks(linksArray, acesValues2))let linksArray = [
81 { src: 'SemiDrive', target: 'ADAYO', aces: ['Automated', 'Experience'], topic: ['EE_Architecture'] },
82 { src: 'WayRay', target: 'AGP', aces: ['Services'], topic: ['Map_Localisation'] },
83 { src: 'Hesai', target: 'Aiways', aces: ['Automated'], topic: ['Car_Access'] },
84 { src: 'Oxbotica', target: 'AppliedEV', aces: ['Automated'], topic: ['Regulation'] },
85 { src: 'Great_Wall', target: 'Audi', aces: ['Automated', 'Connected', 'Experience', 'Services'], topic: ['AP', ' AVP', ' Infrastructure'] },
86 { src: 'Audi', target: 'BMW', aces: ['Automated', 'Connected', 'Experience', 'Services'], topic: ['AP', ' AVP', ' Infrastructure'] },
87 { src: 'AEye', target: 'Benchmark', aces: ['Automated'], topic: [] },
88 { src: 'Hesai', target: 'Black_Sesame', aces: ['Automated', 'Connected'], topic: ['AV_Driverless'] },
89 { src: 'FAW', target: 'Cambricon', aces: ['Automated'], topic: ['AS_ADAS_uptoL2+'] },
90 { src: 'GM', target: 'Cruise', aces: ['Automated', 'Services'], topic: ['AV_Driverless'] },
91 { src: 'Honda', target: 'Cruise', aces: ['Automated', 'Services'], topic: ['Parking'] },
92 { src: 'Audi', target: 'Daimler', aces: ['Services', 'Connected', 'Experience'], topic: ['AP', ' AVP', ' Infrastructure'] },
93 { src: 'Xiaomi', target: 'Deepmotion', aces: ['Automated', 'Services'], topic: ['ADAS_uptoL2+', 'AVP'] },
94 { src: 'Alibaba', target: 'Deeproute', aces: ['Automated'], topic: ['AD_Driverless'] },
95 { src: 'BMW', target: 'Deutsche_Telekom', aces: ['Connected'], topic: ['E/E_Architecture'] }
96]
97
98let aces = ['Services']
99let topics = ['ADAS_uptoL2+']
100
101const filterLinks = (links, aces, topics) =>
102 links
103 .filter((item) => item.aces.some((v) => (aces.length ? aces.includes(v) : v)))
104 .filter((item) => item.topic.some((v) => (topics.length ? topics.includes(v) : v)))
105
106let result = filterLinks(linksArray, aces, topics)
107
108console.log(result)
QUESTION
OAuth2 Redirect URI not valid
Asked 2022-Mar-06 at 22:42I'm trying to authenticate to OpenStreetMap via OAuth2 using AppAuth. Via Custom Tab I can retrieve the authorization code but the redirect URI does not open my app but gives an Address Not Found error in the Custom Tab. As you can see as I was experimenting around to solve this issue I used app.example.com
as host name, although the package name is com.example.app
, but even if I do use the package name as host name in the redirect URI (and change this in the manifest, gradle, osm etc.), it still does not work but results in an Invalid Redirect URI error. So I would assume something with the redirect URI isn't quite right, but I cannot figure out what it is.
Also I cannot use a custom scheme, as OSM only accepts https redirect URIs.
MainActivity.java:
1private static final String CLIENT_ID = ...;
2private static final String REDIRECT_URI = "https://app.example.com/oauth2redirect";
3...
4AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
5 authorizationServiceConfiguration,
6 CLIENT_ID,
7 ResponseTypeValues.CODE,
8 Uri.parse(REDIRECT_URI));
9builder.setScopes("write_api", "read_prefs");
10
11AuthorizationRequest request = builder.build();
12Intent authorizationIntent = authorizationService.getAuthorizationRequestIntent(request);
13startActivityForResult(authorizationIntent, REQUEST_CODE);
14
Manifest.xml:
1private static final String CLIENT_ID = ...;
2private static final String REDIRECT_URI = "https://app.example.com/oauth2redirect";
3...
4AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
5 authorizationServiceConfiguration,
6 CLIENT_ID,
7 ResponseTypeValues.CODE,
8 Uri.parse(REDIRECT_URI));
9builder.setScopes("write_api", "read_prefs");
10
11AuthorizationRequest request = builder.build();
12Intent authorizationIntent = authorizationService.getAuthorizationRequestIntent(request);
13startActivityForResult(authorizationIntent, REQUEST_CODE);
14 <activity
15 android:name=".MainActivity"
16 android:exported="true">
17 <intent-filter>
18 <action android:name="android.intent.action.MAIN" />
19
20 <category android:name="android.intent.category.LAUNCHER" />
21 </intent-filter>
22
23 <intent-filter>
24 <action android:name="com.example.app.HANDLE_AUTHORIZATION_RESPONSE" />
25 <category android:name="android.intent.category.DEFAULT" />
26 </intent-filter>
27 </activity>
28
29 <activity android:name="net.openid.appauth.RedirectUriReceiverActivity"
30 android:exported="true">
31 <intent-filter>
32 <action android:name="android.intent.action.VIEW"/>
33 <category android:name="android.intent.category.DEFAULT"/>
34 <category android:name="android.intent.category.BROWSABLE"/>
35
36 <data android:scheme="https"
37 android:host="app.example.com"
38 android:pathPrefix="/oauth2redirect"/>
39 </intent-filter>
40 </activity>
41
build.gradle
1private static final String CLIENT_ID = ...;
2private static final String REDIRECT_URI = "https://app.example.com/oauth2redirect";
3...
4AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
5 authorizationServiceConfiguration,
6 CLIENT_ID,
7 ResponseTypeValues.CODE,
8 Uri.parse(REDIRECT_URI));
9builder.setScopes("write_api", "read_prefs");
10
11AuthorizationRequest request = builder.build();
12Intent authorizationIntent = authorizationService.getAuthorizationRequestIntent(request);
13startActivityForResult(authorizationIntent, REQUEST_CODE);
14 <activity
15 android:name=".MainActivity"
16 android:exported="true">
17 <intent-filter>
18 <action android:name="android.intent.action.MAIN" />
19
20 <category android:name="android.intent.category.LAUNCHER" />
21 </intent-filter>
22
23 <intent-filter>
24 <action android:name="com.example.app.HANDLE_AUTHORIZATION_RESPONSE" />
25 <category android:name="android.intent.category.DEFAULT" />
26 </intent-filter>
27 </activity>
28
29 <activity android:name="net.openid.appauth.RedirectUriReceiverActivity"
30 android:exported="true">
31 <intent-filter>
32 <action android:name="android.intent.action.VIEW"/>
33 <category android:name="android.intent.category.DEFAULT"/>
34 <category android:name="android.intent.category.BROWSABLE"/>
35
36 <data android:scheme="https"
37 android:host="app.example.com"
38 android:pathPrefix="/oauth2redirect"/>
39 </intent-filter>
40 </activity>
41android {
42...
43
44defaultConfig {
45 applicationId "com.example.app"
46 ...
47 manifestPlaceholders = [
48 appAuthRedirectScheme: 'app.example.com'
49 ]
50}
51
In OSM I have set the redirect URI to https://app.example.com/oauth2redirect
Weirdly enough it worked once yesterday, but does not anymore since today. I reverted any changes, reset the app, deleted any data and restarted my phone, but couldn't make it work again.
I've tried to show as little code as needed, please let me know if you need further information for solving this problem.
Edit: I just noticed that it works on Pixel 5 API 30 virtual device, but not on my real device (Xiaomi Poco X3 Pro API 30) nor on Nexus 6 API 30 virtual device. I'm quite confused
ANSWER
Answered 2022-Mar-06 at 22:42Using HTTP redirect URIs requires these settings in the build.gradle file, and also has a prerequisite of app link registration via a hosted assetlinks.json file
:
1private static final String CLIENT_ID = ...;
2private static final String REDIRECT_URI = "https://app.example.com/oauth2redirect";
3...
4AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
5 authorizationServiceConfiguration,
6 CLIENT_ID,
7 ResponseTypeValues.CODE,
8 Uri.parse(REDIRECT_URI));
9builder.setScopes("write_api", "read_prefs");
10
11AuthorizationRequest request = builder.build();
12Intent authorizationIntent = authorizationService.getAuthorizationRequestIntent(request);
13startActivityForResult(authorizationIntent, REQUEST_CODE);
14 <activity
15 android:name=".MainActivity"
16 android:exported="true">
17 <intent-filter>
18 <action android:name="android.intent.action.MAIN" />
19
20 <category android:name="android.intent.category.LAUNCHER" />
21 </intent-filter>
22
23 <intent-filter>
24 <action android:name="com.example.app.HANDLE_AUTHORIZATION_RESPONSE" />
25 <category android:name="android.intent.category.DEFAULT" />
26 </intent-filter>
27 </activity>
28
29 <activity android:name="net.openid.appauth.RedirectUriReceiverActivity"
30 android:exported="true">
31 <intent-filter>
32 <action android:name="android.intent.action.VIEW"/>
33 <category android:name="android.intent.category.DEFAULT"/>
34 <category android:name="android.intent.category.BROWSABLE"/>
35
36 <data android:scheme="https"
37 android:host="app.example.com"
38 android:pathPrefix="/oauth2redirect"/>
39 </intent-filter>
40 </activity>
41android {
42...
43
44defaultConfig {
45 applicationId "com.example.app"
46 ...
47 manifestPlaceholders = [
48 appAuthRedirectScheme: 'app.example.com'
49 ]
50}
51manifestPlaceholders = [
52 'appAuthRedirectScheme': 'https'
53]
54
There is a known issue where OAuth HTTPS responses don't automatically return to the app from a Chrome Custom Tab, unless there is a User Gesture first, such as a button click. If possible, show an OAuth consent screen as an initial solution to this.
If you want something to compare against try running my demo app and see if this gives you some ideas. Note that recently I've seen problems on emulators that use APIs 31 and above, though no problems on my Google Pixel phone, which runs Android 12.
QUESTION
Get the documents of order id 1 that are not in order id 2 MongoDB
Asked 2022-Feb-07 at 22:02I have this set of documents
1{_id: ObjectId(""),orderid:1,productName:"Iphone 13"}
2{_id: ObjectId(""),orderid:1,productName:"Xiaomi 11"}
3{_id: ObjectId(""),orderid:1,productName:"Pocophone F1"}
4{_id: ObjectId(""),orderid:1,productName:"Samsung S22"}
5{_id: ObjectId(""),orderid:2,productName:"Iphone 13"}
6{_id: ObjectId(""),orderid:2,productName:"Xiaomi 11"}
7
I am trying to get the product names that are in order 1 but not in order 2, my mongodb query was:
1{_id: ObjectId(""),orderid:1,productName:"Iphone 13"}
2{_id: ObjectId(""),orderid:1,productName:"Xiaomi 11"}
3{_id: ObjectId(""),orderid:1,productName:"Pocophone F1"}
4{_id: ObjectId(""),orderid:1,productName:"Samsung S22"}
5{_id: ObjectId(""),orderid:2,productName:"Iphone 13"}
6{_id: ObjectId(""),orderid:2,productName:"Xiaomi 11"}
7{orderid:{$eq:orderid-1,$ne:orderid}}
8
but it does not work, then I was trying with an aggregate op like:
1{_id: ObjectId(""),orderid:1,productName:"Iphone 13"}
2{_id: ObjectId(""),orderid:1,productName:"Xiaomi 11"}
3{_id: ObjectId(""),orderid:1,productName:"Pocophone F1"}
4{_id: ObjectId(""),orderid:1,productName:"Samsung S22"}
5{_id: ObjectId(""),orderid:2,productName:"Iphone 13"}
6{_id: ObjectId(""),orderid:2,productName:"Xiaomi 11"}
7{orderid:{$eq:orderid-1,$ne:orderid}}
8{
9 $match: {orderid:{$gte:orderid-1}} //this is because allways a will try to get the products name in max orderid - 1 to get that resutl with the last 2 orders
10 $group:{
11 _id: {productname: '$productName'}
12 orders:{$push:'$orderid'}
13 total:{$sum:1}
14 }
15 //Then here i'm trying to get just de maxorderid-1 docs that just have total equal 1 but i cant achive the result.
16}
17
Thanks you so much for your support and answers.
ANSWER
Answered 2022-Feb-07 at 22:02If I've understood correctly you can try something like this:
- First
$group
byproductName
and storeorderids
in an array - The
$match
by values in the array:$and
condition where exists1
and not2
. - And then rebuild the objects using
$unwind
and$project
with the axuliar fieldroot
saved in the$group
stage
1{_id: ObjectId(""),orderid:1,productName:"Iphone 13"}
2{_id: ObjectId(""),orderid:1,productName:"Xiaomi 11"}
3{_id: ObjectId(""),orderid:1,productName:"Pocophone F1"}
4{_id: ObjectId(""),orderid:1,productName:"Samsung S22"}
5{_id: ObjectId(""),orderid:2,productName:"Iphone 13"}
6{_id: ObjectId(""),orderid:2,productName:"Xiaomi 11"}
7{orderid:{$eq:orderid-1,$ne:orderid}}
8{
9 $match: {orderid:{$gte:orderid-1}} //this is because allways a will try to get the products name in max orderid - 1 to get that resutl with the last 2 orders
10 $group:{
11 _id: {productname: '$productName'}
12 orders:{$push:'$orderid'}
13 total:{$sum:1}
14 }
15 //Then here i'm trying to get just de maxorderid-1 docs that just have total equal 1 but i cant achive the result.
16}
17db.collection.aggregate([
18 {
19 "$group": {
20 "_id": "$productName",
21 "orderids": {
22 "$push": "$orderid"
23 },
24 "root": {
25 "$push": "$$ROOT"
26 }
27 }
28 },
29 {
30 "$match": {
31 "$and": [
32 {
33 "orderids": 1
34 },
35 {
36 "orderids": {
37 "$ne": 2
38 }
39 }
40 ]
41 }
42 },
43 {
44 "$unwind": "$root"
45 },
46 {
47 "$project": {
48 "_id": "$root._id",
49 "orderid": "$root.orderid",
50 "productName": "$root.productName"
51 }
52 }
53])
54
Example here
Also, if you only want the productName
, that value is stored in the id
of the group, soy uo don't need the last two stages. Like this example
QUESTION
How to make completely transparent status bar?
Asked 2022-Jan-29 at 10:02I want to make so my status bar is transparent, but also without icons on it. I managed to make it so that bar disappeared, but then it left a line that isn't filled with the background. I want to change that so i can actually see the background without any icons being in the way.
Also, I'm testing it on Xiaomi Redmi Note 8T
Code (with the result seen on the 1st picture)
MainActivity.kt
1import android.os.Bundle
2import android.view.View
3import androidx.appcompat.app.AppCompatActivity
4import androidx.appcompat.app.AppCompatDelegate
5
6class MainActivity : AppCompatActivity() {
7
8 override fun onWindowFocusChanged(hasFocus: Boolean) {
9 super.onWindowFocusChanged(hasFocus)
10 if (hasFocus) hideSystemUI()
11 }
12
13 private fun hideSystemUI() {SYSTEM_UI_FLAG_IMMERSIVE_STICKY
14 window.decorView.systemUiVisibility =
15 (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
16 or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
17 or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
18 or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
19 or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
20 or View.SYSTEM_UI_FLAG_FULLSCREEN)
21 }
22
23 override fun onCreate(savedInstanceState: Bundle?) {
24
25 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
26
27 super.onCreate(savedInstanceState)
28 setContentView(R.layout.activity_main)
29 }
30}
31
Both themes.xml
1import android.os.Bundle
2import android.view.View
3import androidx.appcompat.app.AppCompatActivity
4import androidx.appcompat.app.AppCompatDelegate
5
6class MainActivity : AppCompatActivity() {
7
8 override fun onWindowFocusChanged(hasFocus: Boolean) {
9 super.onWindowFocusChanged(hasFocus)
10 if (hasFocus) hideSystemUI()
11 }
12
13 private fun hideSystemUI() {SYSTEM_UI_FLAG_IMMERSIVE_STICKY
14 window.decorView.systemUiVisibility =
15 (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
16 or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
17 or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
18 or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
19 or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
20 or View.SYSTEM_UI_FLAG_FULLSCREEN)
21 }
22
23 override fun onCreate(savedInstanceState: Bundle?) {
24
25 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
26
27 super.onCreate(savedInstanceState)
28 setContentView(R.layout.activity_main)
29 }
30}
31<resources xmlns:tools="http://schemas.android.com/tools">
32 <style name="Theme.TestingSystemModes" parent="Theme.Design.NoActionBar">
33 <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
34 </style>
35</resources>
36
Here is how it looks with that line:
I want it to look like in the picture below, but without that status bar's icons:
EDIT: I think, it's phone that makes it like that ( in the center there is a camera ) and probably the black line is made to blend in the camera. That's why, whatever i did it didn't disappear. Still, thanks a lot to everyone who tried to help me.
ANSWER
Answered 2021-Jul-29 at 09:54Set these properties in your theme. Thats all
1import android.os.Bundle
2import android.view.View
3import androidx.appcompat.app.AppCompatActivity
4import androidx.appcompat.app.AppCompatDelegate
5
6class MainActivity : AppCompatActivity() {
7
8 override fun onWindowFocusChanged(hasFocus: Boolean) {
9 super.onWindowFocusChanged(hasFocus)
10 if (hasFocus) hideSystemUI()
11 }
12
13 private fun hideSystemUI() {SYSTEM_UI_FLAG_IMMERSIVE_STICKY
14 window.decorView.systemUiVisibility =
15 (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
16 or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
17 or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
18 or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
19 or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
20 or View.SYSTEM_UI_FLAG_FULLSCREEN)
21 }
22
23 override fun onCreate(savedInstanceState: Bundle?) {
24
25 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
26
27 super.onCreate(savedInstanceState)
28 setContentView(R.layout.activity_main)
29 }
30}
31<resources xmlns:tools="http://schemas.android.com/tools">
32 <style name="Theme.TestingSystemModes" parent="Theme.Design.NoActionBar">
33 <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
34 </style>
35</resources>
36<item name="android:windowTranslucentStatus">true</item>
37
QUESTION
SQL Subquery with OR condition
Asked 2021-Nov-16 at 20:34I have the following schema:
1+--------+---------+
2|Name | Brand|
3+--------+---------|
4|John | Iphone|
5|John | Samsung|
6|Carl | Xiaomi|
7|Natan | Iphone|
8|Julie | Samsung|
9+--------+---------+
10
In my result I need to return the names which frame in these 2 scenarios:
1- Have only Iphone
OR
2 - Have a exclusive combination of Iphone and Samsung; This way, I need this output:
1+--------+---------+
2|Name | Brand|
3+--------+---------|
4|John | Iphone|
5|John | Samsung|
6|Carl | Xiaomi|
7|Natan | Iphone|
8|Julie | Samsung|
9+--------+---------+
10+--------+
11|Name |
12+--------+
13|John |
14|Natan |
15+--------+
16
This is what I tried, but with no success:
1+--------+---------+
2|Name | Brand|
3+--------+---------|
4|John | Iphone|
5|John | Samsung|
6|Carl | Xiaomi|
7|Natan | Iphone|
8|Julie | Samsung|
9+--------+---------+
10+--------+
11|Name |
12+--------+
13|John |
14|Natan |
15+--------+
16select name
17from schema
18where brand = 'Iphone' or
19brand in
20 (select brand
21 from schema
22 where brand = 'Iphone' and brand = 'Samsung')
23
ANSWER
Answered 2021-Nov-16 at 14:52You could try using union between the iphone olny and the pair iphone-samsung
1+--------+---------+
2|Name | Brand|
3+--------+---------|
4|John | Iphone|
5|John | Samsung|
6|Carl | Xiaomi|
7|Natan | Iphone|
8|Julie | Samsung|
9+--------+---------+
10+--------+
11|Name |
12+--------+
13|John |
14|Natan |
15+--------+
16select name
17from schema
18where brand = 'Iphone' or
19brand in
20 (select brand
21 from schema
22 where brand = 'Iphone' and brand = 'Samsung')
23 select name
24 from schema
25 where brand = 'Iphone'
26 union
27 select name
28 from schema
29 where brand in ('Iphone' , 'Samsung')
30 group by name
31 having count(distinct brand) = 2
32
QUESTION
Service not registered: com.microsoft.identity.common.internal.ui.browser.CustomTabsManager$1@4af7a6e
Asked 2021-Nov-14 at 02:48I am using msal library in an android app and this crash is occurring on many devices
My user agent cannot be WEBVIEW
1Fatal Exception: java.lang.IllegalArgumentException: Service not registered: com.microsoft.identity.common.internal.ui.browser.CustomTabsManager$1@4af7a6e
2 at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1160)
3 at android.app.ContextImpl.unbindService(ContextImpl.java:1475)
4 at android.content.ContextWrapper.unbindService(ContextWrapper.java:644)
5 at com.microsoft.identity.common.internal.ui.browser.CustomTabsManager.unbind(CustomTabsManager.java:164)
6 at com.microsoft.identity.common.internal.ui.browser.BrowserAuthorizationStrategy.dispose(BrowserAuthorizationStrategy.java:182)
7 at com.microsoft.identity.common.internal.ui.browser.BrowserAuthorizationStrategy.completeAuthorization(BrowserAuthorizationStrategy.java:157)
8 at com.microsoft.identity.common.internal.controllers.LocalMSALController.completeAcquireToken(LocalMSALController.java:258)
9 at com.microsoft.identity.common.internal.commands.InteractiveTokenCommand.notify(InteractiveTokenCommand.java:77)
10 at com.microsoft.identity.common.internal.controllers.CommandDispatcher.completeInteractive(CommandDispatcher.java:608)
11 at com.microsoft.identity.common.internal.controllers.CommandDispatcher.access$1100(CommandDispatcher.java:83)
12 at com.microsoft.identity.common.internal.controllers.CommandDispatcher$4$1.onReceive(CommandDispatcher.java:565)
13 at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
14 at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
15 at android.os.Handler.dispatchMessage(Handler.java:102)
16 at android.os.Looper.loop(Looper.java:148)
17 at android.app.ActivityThread.main(ActivityThread.java:7325)
18 at java.lang.reflect.Method.invoke(Method.java)
19 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
20 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
21
here's my json config file.
1Fatal Exception: java.lang.IllegalArgumentException: Service not registered: com.microsoft.identity.common.internal.ui.browser.CustomTabsManager$1@4af7a6e
2 at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1160)
3 at android.app.ContextImpl.unbindService(ContextImpl.java:1475)
4 at android.content.ContextWrapper.unbindService(ContextWrapper.java:644)
5 at com.microsoft.identity.common.internal.ui.browser.CustomTabsManager.unbind(CustomTabsManager.java:164)
6 at com.microsoft.identity.common.internal.ui.browser.BrowserAuthorizationStrategy.dispose(BrowserAuthorizationStrategy.java:182)
7 at com.microsoft.identity.common.internal.ui.browser.BrowserAuthorizationStrategy.completeAuthorization(BrowserAuthorizationStrategy.java:157)
8 at com.microsoft.identity.common.internal.controllers.LocalMSALController.completeAcquireToken(LocalMSALController.java:258)
9 at com.microsoft.identity.common.internal.commands.InteractiveTokenCommand.notify(InteractiveTokenCommand.java:77)
10 at com.microsoft.identity.common.internal.controllers.CommandDispatcher.completeInteractive(CommandDispatcher.java:608)
11 at com.microsoft.identity.common.internal.controllers.CommandDispatcher.access$1100(CommandDispatcher.java:83)
12 at com.microsoft.identity.common.internal.controllers.CommandDispatcher$4$1.onReceive(CommandDispatcher.java:565)
13 at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
14 at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
15 at android.os.Handler.dispatchMessage(Handler.java:102)
16 at android.os.Looper.loop(Looper.java:148)
17 at android.app.ActivityThread.main(ActivityThread.java:7325)
18 at java.lang.reflect.Method.invoke(Method.java)
19 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
20 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
21 "client_id": "client_id",
22 "authorization_user_agent": "BROWSER",
23 "account_mode": "MULTIPLE",
24 "redirect_uri": "redirect_uri",
25 "authorities": [
26 {
27 "type": "B2C",
28 "authority_url": "authority_url",
29 "default": true
30 },
31 {
32 "type": "B2C",
33 "authority_url": "authority_url"
34 }
35 ],
36 "browser_safelist": [
37 {
38 "browser_package_name": "com.mi.globalbrowser",
39 "browser_signature_hashes": [
40 "g7zGEnZipieE6ZyBA4Bz00kxU8h0F9QTwPLL-dnRVwngI0FJWJiD3rCEJsIQ_VK064SNdxzqggnnnAqT8LI89A=="
41 ]
42 }
43 ]
44}
45
And here's a list of some devices where the crash occurs
moto g(6) play
moto z3 play
Moto G(4) Plus
LG K40S
LG Q60
ZenFone Max Shot (ZB634KL)
and many other not listed here, including xiaomi, samsgung and onePlus
ANSWER
Answered 2021-Oct-25 at 16:41This is the known bug in the microsoft-authentication-library-for-android.
You can authenticate by edit the auth_config.json
file in the Raw folder and change the user agent to this authorized_user_agent
: WEBVIEW
.
You can authenticate the user using the Webview instead of the browser and from this way your app will not be crashed.
Look into this pull-request.
QUESTION
Why doesn't the data from the server come to the app on the real device?
Asked 2021-Nov-04 at 15:00When the application starts, a request is sent to the server (which is located locally on my computer) to get a list of posts. In theory, the server should process the request and return this list of posts. But it doesn't return anything. In LogCat there are no errors, but when debugging, an exception is thrown instead of a server response:
1((SocketTimeoutException)e).detailMessage = failed to connect to /192.168.1.35 (port 9999) from /192.168.1.33 (port 49742) after 30000ms
2
When I try to add new post (post to server via Post method) I get error at LogCat. Here is the text of the error:
1((SocketTimeoutException)e).detailMessage = failed to connect to /192.168.1.35 (port 9999) from /192.168.1.33 (port 49742) after 30000ms
22021-11-02 21:17:29.025 12197-12210/com.example E/SpellCheckerSession: ignoring processOrEnqueueTask due to unexpected mState=TASK_CLOSE scp.mWhat=TASK_CLOSE
32021-11-02 21:17:39.811 12197-12568/com.example E/AndroidRuntime: FATAL EXCEPTION: Thread-4
4 Process: com.example, PID: 12197
5 java.net.SocketTimeoutException: failed to connect to /192.168.1.35 (port 9999) from /192.168.1.33 (port 49918) after 30000ms
6 at libcore.io.IoBridge.connectErrno(IoBridge.java:185)
7 at libcore.io.IoBridge.connect(IoBridge.java:130)
8 at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
9 at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356)
10 at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
11 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
12 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:357)
13 at java.net.Socket.connect(Socket.java:616)
14 at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.kt:63)
15 at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
16 at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
17 at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
18 at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
19 at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
20 at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
21 at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
22 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
23 at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
24 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
25 at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
26 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
27 at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
28 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
29 at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
30 at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
31 at com.example.repository.PostRepositoryImpl.save(PostRepositoryImpl.kt:60)
32 at com.example.viewmodel.PostViewModel$save$1$1.invoke(PostViewModel.kt:54)
33 at com.example.viewmodel.PostViewModel$save$1$1.invoke(PostViewModel.kt:53)
34 at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
35
IP-address and port are correct. On native android-studio emulator I enter address 10.0.2.2:9999 - posts are coming. I use Genymotion emulator (which has its own IP) and enter 192.168.1.35:9999 - the answer from the server comes too. Only the real devices (Xiaomi Redmi 5 and Nexus 5X) do not respond. Help to solve the problem, please!
UPD: Thanks everybody for your help, guys! I've tried everything, but the problem was really caused by the turned on firewall)
ANSWER
Answered 2021-Nov-03 at 17:38The firewall on the server pc can block incoming connections. Switch it off to test.
The server can be bound to localhost only. Dont bind your server and if you have to bind it to 0.0.0.0.
QUESTION
New instance of a class contains older data given to an older instance
Asked 2021-Oct-08 at 11:06I'm trying to analyze some reviews using vader
in python
. I made an Analyzer
class like so:
1class Analyzer:
2 dataframe = None
3 reviews = []
4
5 # other data
6
7 def __init__(self, brand):
8 self.dataframe = pd.read_csv(brand) # using pandas
9 reviews = self.dataframe['Reviews'].tolist()
10
11 def analyze(self):
12 # code for analyze...
13
14 # more codes...
15
and I used this class in main.py
like so:
1class Analyzer:
2 dataframe = None
3 reviews = []
4
5 # other data
6
7 def __init__(self, brand):
8 self.dataframe = pd.read_csv(brand) # using pandas
9 reviews = self.dataframe['Reviews'].tolist()
10
11 def analyze(self):
12 # code for analyze...
13
14 # more codes...
15from analyzer import Analyzer
16
17brands = [
18 'apple',
19 'google',
20 'huawei',
21 'motorola',
22 'nokia',
23 'samsung',
24 'sony',
25 'xiaomi'
26]
27
28for brand in brands:
29 analysis = Analyzer(brand)
30 analysis.analyze()
31 del analysis
32
now the problem is: When brands are given to the class to be analyzed, the older reviews remain in the list.
e.g.:
apple.csv has 1000 reviews and google.csv has 700 reviews. but when google is passed to analyzer, the reviews
list length is not 700, but 1700.
ANSWER
Answered 2021-Oct-08 at 08:56reviews
attribute is for class
and not object
, since you defined it in the body of the class.
define the reviews
in the body of __init__
:
1class Analyzer:
2 dataframe = None
3 reviews = []
4
5 # other data
6
7 def __init__(self, brand):
8 self.dataframe = pd.read_csv(brand) # using pandas
9 reviews = self.dataframe['Reviews'].tolist()
10
11 def analyze(self):
12 # code for analyze...
13
14 # more codes...
15from analyzer import Analyzer
16
17brands = [
18 'apple',
19 'google',
20 'huawei',
21 'motorola',
22 'nokia',
23 'samsung',
24 'sony',
25 'xiaomi'
26]
27
28for brand in brands:
29 analysis = Analyzer(brand)
30 analysis.analyze()
31 del analysis
32class Analyzer:
33
34 # other data
35
36 def __init__(self, brand):
37 self.dataframe = pd.read_csv(brand) # using pandas
38 self.reviews = self.dataframe['Reviews'].tolist()
39
40 def analyze(self):
41 # code for analyze...
42
43 # more codes...
44
QUESTION
java.lang.IncompatibleClassChangeError,After Upgrade kotlin gradle plugin to 1.5.20
Asked 2021-Sep-27 at 15:55I want upgrade kotlin gradle plugin from 1.4.32
to 1.5.20
,but some code occurred error in lower android version device,such as Xiaomi 5.1.1
& Oppo 6.0.1
& Pixel2 6.0
, but it normal in Android 10 devices.
The error info:
1java.lang.IncompatibleClassChangeError: Couldn't find com.example.kotlinupgradedemo.ProgressDialogKt.<clinit>[]
2 at libcore.reflect.AnnotationAccess.indexToMethod(AnnotationAccess.java:608)
3 at libcore.reflect.AnnotationAccess.getEnclosingMethodOrConstructor(AnnotationAccess.java:405)
4 at java.lang.Class.isLocalClass(Class.java:1334)
5 at java.lang.Class.getCanonicalName(Class.java:378)
6 at androidx.lifecycle.Lifecycling.resolveObserverCallbackType(Lifecycling.java:153)
7 at androidx.lifecycle.Lifecycling.getObserverConstructorType(Lifecycling.java:146)
8 at androidx.lifecycle.Lifecycling.lifecycleEventObserver(Lifecycling.java:83)
9 at androidx.lifecycle.LifecycleRegistry$ObserverWithState.<init>(LifecycleRegistry.java:347)
10 at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:174)
11 at com.example.kotlinupgradedemo.ProgressDialogKt.showProgress(ProgressDialog.kt:36)
12 at com.example.kotlinupgradedemo.MainActivity.onCreate(MainActivity.kt:12)
13
My some code(ProgressDialog.kt
):
1java.lang.IncompatibleClassChangeError: Couldn't find com.example.kotlinupgradedemo.ProgressDialogKt.<clinit>[]
2 at libcore.reflect.AnnotationAccess.indexToMethod(AnnotationAccess.java:608)
3 at libcore.reflect.AnnotationAccess.getEnclosingMethodOrConstructor(AnnotationAccess.java:405)
4 at java.lang.Class.isLocalClass(Class.java:1334)
5 at java.lang.Class.getCanonicalName(Class.java:378)
6 at androidx.lifecycle.Lifecycling.resolveObserverCallbackType(Lifecycling.java:153)
7 at androidx.lifecycle.Lifecycling.getObserverConstructorType(Lifecycling.java:146)
8 at androidx.lifecycle.Lifecycling.lifecycleEventObserver(Lifecycling.java:83)
9 at androidx.lifecycle.LifecycleRegistry$ObserverWithState.<init>(LifecycleRegistry.java:347)
10 at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:174)
11 at com.example.kotlinupgradedemo.ProgressDialogKt.showProgress(ProgressDialog.kt:36)
12 at com.example.kotlinupgradedemo.MainActivity.onCreate(MainActivity.kt:12)
13private val ownerToProgressMap = mutableMapOf<LifecycleOwner, Dialog>()
14
15private val progressCleaner = object : LifecycleObserver {
16 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
17 fun onDestroy(owner : LifecycleOwner) {
18 ownerToProgressMap.remove(owner)?.dismiss()
19 owner.lifecycle.removeObserver(this)
20 }
21}
22
23fun LifecycleOwner.showProgress() {
24 val context = when (this) {
25 is Activity -> this
26 is Fragment -> this.context
27 else -> null
28 } ?: return
29
30 ownerToProgressMap[this]
31 ?.apply { show() }
32 ?: Dialog(context).also {
33 it.setTitle("Tips")
34 it.show()
35 }.let {
36 ownerToProgressMap[this] = it
37 this.lifecycle.addObserver(progressCleaner)
38 }
39}
40
41fun LifecycleOwner.dismissProgress() {
42 ownerToProgressMap[this]?.dismiss()
43}
44
I just call it in MainActivity
:
1java.lang.IncompatibleClassChangeError: Couldn't find com.example.kotlinupgradedemo.ProgressDialogKt.<clinit>[]
2 at libcore.reflect.AnnotationAccess.indexToMethod(AnnotationAccess.java:608)
3 at libcore.reflect.AnnotationAccess.getEnclosingMethodOrConstructor(AnnotationAccess.java:405)
4 at java.lang.Class.isLocalClass(Class.java:1334)
5 at java.lang.Class.getCanonicalName(Class.java:378)
6 at androidx.lifecycle.Lifecycling.resolveObserverCallbackType(Lifecycling.java:153)
7 at androidx.lifecycle.Lifecycling.getObserverConstructorType(Lifecycling.java:146)
8 at androidx.lifecycle.Lifecycling.lifecycleEventObserver(Lifecycling.java:83)
9 at androidx.lifecycle.LifecycleRegistry$ObserverWithState.<init>(LifecycleRegistry.java:347)
10 at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:174)
11 at com.example.kotlinupgradedemo.ProgressDialogKt.showProgress(ProgressDialog.kt:36)
12 at com.example.kotlinupgradedemo.MainActivity.onCreate(MainActivity.kt:12)
13private val ownerToProgressMap = mutableMapOf<LifecycleOwner, Dialog>()
14
15private val progressCleaner = object : LifecycleObserver {
16 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
17 fun onDestroy(owner : LifecycleOwner) {
18 ownerToProgressMap.remove(owner)?.dismiss()
19 owner.lifecycle.removeObserver(this)
20 }
21}
22
23fun LifecycleOwner.showProgress() {
24 val context = when (this) {
25 is Activity -> this
26 is Fragment -> this.context
27 else -> null
28 } ?: return
29
30 ownerToProgressMap[this]
31 ?.apply { show() }
32 ?: Dialog(context).also {
33 it.setTitle("Tips")
34 it.show()
35 }.let {
36 ownerToProgressMap[this] = it
37 this.lifecycle.addObserver(progressCleaner)
38 }
39}
40
41fun LifecycleOwner.dismissProgress() {
42 ownerToProgressMap[this]?.dismiss()
43}
44class MainActivity : AppCompatActivity() {
45 override fun onCreate(savedInstanceState: Bundle?) {
46 super.onCreate(savedInstanceState)
47 setContentView(R.layout.activity_main)
48
49 showProgress()
50 }
51}
52
For the complete code, see demo
ANSWER
Answered 2021-Sep-27 at 15:55Take a look to AnnotationAccess.java.
Especially lines
1java.lang.IncompatibleClassChangeError: Couldn't find com.example.kotlinupgradedemo.ProgressDialogKt.<clinit>[]
2 at libcore.reflect.AnnotationAccess.indexToMethod(AnnotationAccess.java:608)
3 at libcore.reflect.AnnotationAccess.getEnclosingMethodOrConstructor(AnnotationAccess.java:405)
4 at java.lang.Class.isLocalClass(Class.java:1334)
5 at java.lang.Class.getCanonicalName(Class.java:378)
6 at androidx.lifecycle.Lifecycling.resolveObserverCallbackType(Lifecycling.java:153)
7 at androidx.lifecycle.Lifecycling.getObserverConstructorType(Lifecycling.java:146)
8 at androidx.lifecycle.Lifecycling.lifecycleEventObserver(Lifecycling.java:83)
9 at androidx.lifecycle.LifecycleRegistry$ObserverWithState.<init>(LifecycleRegistry.java:347)
10 at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:174)
11 at com.example.kotlinupgradedemo.ProgressDialogKt.showProgress(ProgressDialog.kt:36)
12 at com.example.kotlinupgradedemo.MainActivity.onCreate(MainActivity.kt:12)
13private val ownerToProgressMap = mutableMapOf<LifecycleOwner, Dialog>()
14
15private val progressCleaner = object : LifecycleObserver {
16 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
17 fun onDestroy(owner : LifecycleOwner) {
18 ownerToProgressMap.remove(owner)?.dismiss()
19 owner.lifecycle.removeObserver(this)
20 }
21}
22
23fun LifecycleOwner.showProgress() {
24 val context = when (this) {
25 is Activity -> this
26 is Fragment -> this.context
27 else -> null
28 } ?: return
29
30 ownerToProgressMap[this]
31 ?.apply { show() }
32 ?: Dialog(context).also {
33 it.setTitle("Tips")
34 it.show()
35 }.let {
36 ownerToProgressMap[this] = it
37 this.lifecycle.addObserver(progressCleaner)
38 }
39}
40
41fun LifecycleOwner.dismissProgress() {
42 ownerToProgressMap[this]?.dismiss()
43}
44class MainActivity : AppCompatActivity() {
45 override fun onCreate(savedInstanceState: Bundle?) {
46 super.onCreate(savedInstanceState)
47 setContentView(R.layout.activity_main)
48
49 showProgress()
50 }
51}
52 try {
53 return name.equals("<init>")
54 ? declaringClass.getDeclaredConstructor(parametersArray)
55 : declaringClass.getDeclaredMethod(name, parametersArray);
56 } catch (NoSuchMethodException e) {
57 throw new IncompatibleClassChangeError("Couldn't find " + declaringClass.getName()
58 + "." + name + Arrays.toString(parametersArray));
59 }
60
Then look to Class::getDeclaredMethod documentation.
Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object. ... If the name is "<init>"or "<clinit>" a NoSuchMethodException is raised.
Kotlin global property and companion object property initialization compiles to Java static initialization block aka <clinit>.
Puzzle complete. Move LifecycleObserver
declaration from static property somewhere else and problem will be solved.
Why Android 5 and 6 only? I think it's just getDeclaredMethod
implementation differences. We see crashes on Android 5 and 6 only too.
QUESTION
Will i get the entire document from the firestore?
Asked 2021-Sep-20 at 13:41hi. i have a database as in the picture above i have a smartphones collection with many documents(i.e. iphone or xiaomi) inside. i will use react to render this information and i want to load it from part to part. i.e. i want to render all of the smartphones on the main page and filter them... so for the main page i will only need description and ratings and for the full product details i will need tech specs and reviews. imagine that the whole document weight is 1mb 100kb both descriptions 200kb for tech specs 400kb reviews and 200kb ratings my question is:
- if i want to load only ratings and short description for the main page of 100 products. can i get only 300kb data from each product or i will get the whole 100mb data ???
- if i want to edit only camera 64mpx .. can i do this without getting all the document from the DB?
- is there any easy tool to add/edit/remove data in the firestore DB like MongoDBCompass ?
- any information about how read/add/edit operations works in firestore?
ANSWER
Answered 2021-Sep-20 at 13:41if i want to load only ratings and short description for the main page of 100 products
You can load only ratings
as it's a document on it's own document. You cannot load only short description
as you cannot fetch a single field from a document. You'll get both short description
and full description
fields. (Do note that this won't include documents from the sub-collections i.e. reviews, tech specs in this case)
if i want to edit only camera 64mpx .. can i do this without getting all the document from the DB?
As long as you know ID of that document (smartphone document), you can using following update operation:
1const phoneRef = firebase.firestore().collection("smartphones").doc("smart_phone_id")
2
3const mediaRef = phoneRef.collection("tech_specs").doc("media")
4mediaRef.update({ camera: "108px" })
5
is there any easy tool to add/edit/remove data in the firestore DB like MongoDBCompass ?
Firebase's console (where the screenshot is from) is one but there isn't any one click import built natively.
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Xiaomi
Tutorials and Learning Resources are not available at this moment for Xiaomi