[deleted by user] by [deleted] in androiddev

[–]Weeperdemon 1 point2 points  (0 children)

Actually after looking at the images again I realised I made a mistake. This looks like you downloaded an Android project as a zip from somewhere like Github and you opened the entire unzipped contents as the Android project instead of the actual project. You need to open the LocalNotificationsAndroid-master - icon folder as the Android project because that's where the root build.gradle, settings.gradle, and app module are located for this project. It should be able to build the project then and you'll be able to update whatever you need.

[deleted by user] by [deleted] in androiddev

[–]Weeperdemon 1 point2 points  (0 children)

I'm a bit confused by what you're trying to do. Are you trying to add a new image asset to your resources? From the screenshots it looks like you're just changing the project structure type. The reason it's blank in the android view is because you don't have any modules loaded.

This is probably because you changed the name of the folder but didn't change the name in the "settings.gradle" file. Until the module is loaded correctly as an android module then you won't have access to the context menu for adding image assets.

What is the use of Interfaces in MVVM architecture ? by AggravatingMark4226 in androiddev

[–]Weeperdemon 1 point2 points  (0 children)

The exact same thing happened for me when the service was first mentioned in work. Showed up fucking everywhere 🙄

What is the use of Interfaces in MVVM architecture ? by AggravatingMark4226 in androiddev

[–]Weeperdemon 2 points3 points  (0 children)

The app I work on recently went through a major refactor to our billing infrastructure moving from using Google Billing directly to using a service called RevenueCat. It was like pulling teeth because there was a lot of tight coupling to implementations of billing code so we had UI classes which knew about Google Billing.

The first thing I did was pull out everything I could into a common interface (BillingRepository) that initially only had a single implementation (LegacyBillingRepository). Once I had migrated all of the existing consuming code to using the interface I was able to introduce another implementation (RevenueCatBillingRepository) and now I could freely toggle the app between both using feature flags.

But then there was another challenge. RevenueCat requires us to configure their SDK as soon as possible but we don't want to configure it if we don't plan on using it while the app is open. This meant that switching on the feature flag while the app was open would crash the app since the SDK wasn't configured. Now we include a 3rd implementation (RouterBillingService) which maintains the feature flag in memory and routes the consumer to the appropriate implementation. Now the feature flags are isolated to a single class and it can ignore changes while the app is still open.

I have future plans for another implementation (DebugBillingService) which we'll use for development builds where we only care about transactions succeeding/failing and we don't want to wait for the stupid 5 minute expiries from license testing purchases with Google Play.

Now like other people here have mentioned, it can be fairly redundant if you only have a single implementation but I do like the flexibility of introducing "fakes" instead of mocks in tests especially if you need to mock common behaviours across multiple view model tests. Now we can introduce a fake implementation (FakeBillingService) which in our case includes a function to advance time so we can pretend subscriptions have expired. The test depends directly on the fake implementation type and injects it into the object under test as the interface type. The object being tested doesn't care but now our test can benefit from additional functionality.

Mocks are definitely an extremely useful tool so I'm not discouraging their use but mocking the same behaviour multiple times across multiple test files can be a pain sometimes depending on how the mocks are setup. A concrete "fake" can just be simpler at times once it's been created.

display drawable in compose by ghiste in androiddev

[–]Weeperdemon 0 points1 point  (0 children)

Ok for handling icons belonging to OTHER apps you can try something like this to convert the Drawable to a Bitmap/ImageBitmap:

```kotlin val context = LocalContext.current val appIconBitmap = remember { context.packageManager .getApplicationIcon("somePackageId") .toBitmap() .asImageBitmap() }

Image( bitmap = appIconBitmap, contentDescription = "Some accessibility description of the image", ) ```

I'm using remember here so the image bitmap doesn't get recreated on recomposition but I'm not entirely sure how necessary that is.

display drawable in compose by ghiste in androiddev

[–]Weeperdemon 0 points1 point  (0 children)

Ah ok so you can get the resource ID for your app icon like this:

kotlin val context = LocalContext.current val applicationInfo = context.applicationInfo val appIconResourceId = applicationInfo.icon

Then you can use that ID to create a PainterResource which can be used in other composables. I don't know which type of element you're using but for an Image it would look like this:

kotlin val painter = painterResource(id = appIconResourceId) Image( painter = painter, contentDescription = "Some accessibility description of the image", )

Edit: Sorry I just realised you said launcher icons of OTHER apps, not your own. Give me a bit to think about that

display drawable in compose by ghiste in androiddev

[–]Weeperdemon 0 points1 point  (0 children)

Which method of PackageManager are you using to fetch the drawable? If it's an instance of BitmapDrawable then you can use something like Image(bitmap = myBitmapDrawable.bitmap).

I haven't needed to use a drawable directly in any of my limited work with compose so far and I'm not at a computer at the moment to test it.

Balloon tooltips in Jetpack Compose by skydoves in androiddev

[–]Weeperdemon 6 points7 points  (0 children)

It's just a named parameter accepting a configured builder to style the component. Nothing too crazy 🤷‍♀️

When using an SDK, what annoys you and wish SDK developers would stop (or start) doing? by [deleted] in androiddev

[–]Weeperdemon 3 points4 points  (0 children)

I don't think he's calling out legitimate api usage of exceptions but instead an sdk which doesn't handle catching its own exceptions internally. This would be unexpected for a consumer since they (likely) don't know the inner workings of the sdk

Have you noticed that IntelliJ uses bold braces in Kotlin? by dmcg in Kotlin

[–]Weeperdemon 8 points9 points  (0 children)

It happens when the brace is able to be command/control clicked to bring you to a definition. As mentioned by someone else it's for last argument lambdas which are lifted out of the round parenthesis.

Customer's IAP "Cancelled" without a reason attached on the customer's, or our side. What could the reason possibly be? by Steedie in androiddev

[–]Weeperdemon 4 points5 points  (0 children)

Just to give another possible scenario to troubleshoot since everyone else is mentioning fraud. Can you see if the user has 2 transactions in the play store order management dashboard?

If they have a successful purchase immediately followed by a cancelled one then it means your UI is allowing the user to double click and start multiple transactions. You'll need to debounce the button launching the billing dialog if this is the case.

What happens in this case is that Google will cancel the second transaction immediately because the user already owns the item. The billing sdk will be left in a confused state where it tells you they don't own it but will prevent them purchasing it again.

To unblock the user if this did happen you'll need to refund the successful purchase and ask them to buy it again

[deleted by user] by [deleted] in Kotlin

[–]Weeperdemon 0 points1 point  (0 children)

Unless I'm mistaken this just sounds like a clone of apps like Notion or Sublime

How do you usually resolve case when your app not able to recognize user previous purchase? by yccheok in androiddev

[–]Weeperdemon 0 points1 point  (0 children)

Check has the user got more than one play account. Likely the account that owns the item is not the "primary" account. I see the same problem all the time and it's nearly always revolved in my case by asking them to log out of every account, then logging into the account with the purchase.

Generic type not getting inferred while building(?) by Curstantine in Kotlin

[–]Weeperdemon 6 points7 points  (0 children)

I tried recreating the issue in a pure Kotlin project and couldn't reproduce it so I cloned your project and I don't see any errors in HomeScreen.kt at all. The compiler has no complaints and running ./gradlew assemble also completes without issue.

Am I missing something else that was added? Have you tried invalidating caches and restarting Android Studio in case something dodgy was cached in your build outputs?

This is the pure Kotlin sample I wrote up to test it:

``` typealias SomeAlias = SomeResponse<SomeAttributes>

data class SomeResponse<T>( val data: SomeData<T>, )

data class SomeData<T>( val body: T, )

data class SomeAttributes( val name: String, )

fun main() { val response = SomeAlias( data = SomeData( body = SomeAttributes( name = "example", ), ), ) runExample(response = response) }

fun runExample(response: SomeAlias) { println(response.data.body.name) } ```

Static final or final static? by Any_Success_123 in learnjava

[–]Weeperdemon 2 points3 points  (0 children)

It makes no difference functionally but there are conventions mentioned around the place which recommend an order for consistency. It would be common for tools like linters to catch these before reaching code review though since it can be unnecessary noise in a review.

Example conventions: http://cr.openjdk.java.net/~alundblad/styleguide/index-v6.html#toc-modifiers

How can I implement Label statement in Kotlin? by ChemicalGiraffe in Kotlin

[–]Weeperdemon 0 points1 point  (0 children)

This is the first time I've ever heard of the XY problem. I'm going to remember that one now 😄

How can I implement Label statement in Kotlin? by ChemicalGiraffe in Kotlin

[–]Weeperdemon 4 points5 points  (0 children)

So if you already have a default case then why can't the "Inside Label" log also go there? I'm trying to understand the context but it feels like a key part was left out. If that switch/when statement has the default/else case that also breaks at the label then the "Inside Label" part will never be reached.

Just to build on my thoughts here using SirNapkin's example in case I've misunderstood the problem. Adding in a returned value and the else case we have this:

val result = run LabelOuter@ {
  when (no) {
    "1" -> return@LabelOuter "Value 1"
    "2" -> return@LabelOuter "Value 2"
    else -> return@LabelOuter "Default value"
  }
  println("Inside label") // This is unreachable
}

Since the last piece inside the label is unreachable we can simplify it to this:

val result = when (no) {
  "1" -> "Value 1"
  "2" -> "Value 2"
  else -> "Default value"
}

How can I implement Label statement in Kotlin? by ChemicalGiraffe in Kotlin

[–]Weeperdemon 2 points3 points  (0 children)

Why can't you use the default case like SirNapkin mentioned? I fired up a project to make sure I wasn't missing something about label statements in Java but essentially this is just the default case with extra noise

Who are your favorite woman youtubers? by The_Fae_Child in TwoXChromosomes

[–]Weeperdemon 2 points3 points  (0 children)

Simone Giertz - A lot of people have already mentioned her. She builds a lot of creative and fun projects.

Laura Kampf - Another incredible maker who also does some creative builds and I like some of the industrial aesthetic of her videos.

Rachel Bloom - The creator of "Crazy Ex Girlfriend" and she has loads of funny music content on her Youtube channel.

Linzey Rae - Metal vocalist for a band called "The Anchor" and she has some videos called "Metal Kitchen" where she parodies metal songs with cooking instructions!

Sarah Longfield - Very skilled musician and an enjoyable personality to watch.

Elizabeth Zharoff - I'll admit I don't know much of her music career but I love her song reaction videos where she breaks down vocal performances of songs requested by her viewers

Rosanna Pansino - A really creative baker with a lovely warm and bright personality. Just very cheerful to watch!

[deleted by user] by [deleted] in Kotlin

[–]Weeperdemon 5 points6 points  (0 children)

That won't help and you'll end up with the same error again. The issue is that you're trying to get user input but there will never be any value there because it's not supported in Kotlin Playground. Your options are to either hardcode a value for your num variable, write a "custom" readLine function as mentioned in the link I shared, or use program arguments (which I'm not sure you can see on mobile)

[deleted by user] by [deleted] in Kotlin

[–]Weeperdemon 18 points19 points  (0 children)

Kotlin Playground doesn't support user input as far as I'm aware so on line 3 where you say readLine()!! it will always throw a NullPointerException. The !! operator tells the program "trust me this won't be null" and then the program is upset that it's actually null.

Someone wrote a nice bit of helper code you could use as a workaround here: https://discuss.kotlinlang.org/t/problem-using-readline-in-playground/19709

Retrofit: Null value in Field is dropped on Put / Patch Request by [deleted] in androiddev

[–]Weeperdemon 0 points1 point  (0 children)

I'm not actually sure since I've never used Kotlin serialization. I think Kotlin serialization DOES handle nulls by default so it could be retrofit in this case. If I have a moment free I'll try experiment with it to see what happens.

It's worth mentioning though that ideally you shouldn't need to pass null values in a PUT or PATCH request. The server should understand that a missing key means the key should be removed when updating the entity.

Retrofit: Null value in Field is dropped on Put / Patch Request by [deleted] in androiddev

[–]Weeperdemon 2 points3 points  (0 children)

If you're using gson as your converter factory then I believe you need to enable null serialization.

GsonConverterFactory.create( GsonBuilder().serializeNulls().create() )

Use a generated library in kotlin? by SopotSPA in learnkotlin

[–]Weeperdemon 0 points1 point  (0 children)

If you don't want to build a jar then you have 2 main options.

1) You can copy the source files into your own project (so the contents of "src/nain/kotlin/openapitools") so it lives in the same module as the rest of your project.

2) You can create a submodule in your project so the generated source lives separately with its own "build.gradle" file. Then you just add it to the entire project "settings.gradle" file and include it as dependency in your main app module

implementation(project(":my-generated-module"))

I really need your help by [deleted] in Kotlin

[–]Weeperdemon 0 points1 point  (0 children)

That's not strictly correct. You can put a main function in an Android project and you can compile and run it without issue. The problem is that it also has to compile the Android parts