• Breaking News

    [Android][timeline][#f39c12]

    Monday, May 30, 2022

    Is there a shorter way of doing this, maybe with sealed classes? Android Dev

    Is there a shorter way of doing this, maybe with sealed classes? Android Dev


    Is there a shorter way of doing this, maybe with sealed classes?

    Posted: 30 May 2022 08:09 PM PDT

    I need an Optional where the 'None' string representation is "", and the 'Something' string representation is its stored value. I also need to be able to get back to that Optional from the string representation (reification if you will.)

    Tests to demonstrate usage of what I cooked up below. class OptionalFilterTest { @Test fun checkOptionalFilters() { assertEquals(Filtered("male").value, "male") assertEquals(NoFilter().value, "") assertTrue(OptionalFilter.reify("") is NoFilter) assertTrue (OptionalFilter.reify("female") is Filtered) assertEquals (OptionalFilter.reify("female").value, "female") } }

    Wondering if there is a way to do this with less code, or with something built into Kotlin. I confess to not really being able to grok sealed classes. ``` abstract class OptionalFilter { abstract val value: String companion object { fun reify(filter:String): OptionalFilter { if (filter == "") { return NoFilter() } else { return Filtered(filter) } } } }

    data class Filtered(val filter: String) : OptionalFilter() { override val value = filter }

    // a little awkward that this is not also a data class? class NoFilter : OptionalFilter() { override val value = "" } ```

    submitted by /u/Place-Wide
    [link] [comments]

    In-App Reviews API on Kids app

    Posted: 30 May 2022 05:16 PM PDT

    Does anyone know if it is okay to use the In-App Reviews API on a "Designed for Families" app, or does it need to be behind some type of parental wall?

    I have searched high and low for this answer and can't find anything.

    submitted by /u/factfoundry
    [link] [comments]

    Is there something you can pass into a Room query 'where' clause that returns all results?

    Posted: 30 May 2022 04:45 PM PDT

    If I have a Room Dao query like so: @Query("select * from foo where type=:type and origin=:origin") fun foo(type: String?, origin: String?): DataSource.Factory<Int, Foo>

    Is there something I can pass in as type or origin where the effect would be that I didn't have that where clause? Something like '*'? Would null do it? foo(null, "barney") would be the equivalent of select * from foo where origin = 'barney' // no where type=... clause

    submitted by /u/Place-Wide
    [link] [comments]

    What's the best practice for doing a network operation off the main thread?

    Posted: 30 May 2022 04:33 PM PDT

    I have a for loop that has a line of code that does a network operation. I need to run this network operation off the main thread. How should I go about this? The rest of the body in the for loop is dependent on the line of code with the network operation so I would also probably need to move the other code in the for loop with the network operation code line.

    submitted by /u/techsavvynerd91
    [link] [comments]

    changing name of airplane mode

    Posted: 30 May 2022 05:18 PM PDT

    I've got a Google Pixel 5a w/ 5G, with the latest version of Android 12 and dev mode enabled, I'm trying to see if theresa way to change the name of Airplane Mode to something else. A joke with a friend calls it "Shabbat Mode" and I was trying to see if theres a way to change it to that instead of Airplane Mode

    submitted by /u/KingLego2006
    [link] [comments]

    No comments:

    Post a Comment

    Fashion

    Beauty

    Travel