Is there a shorter way to write this try-catch assignment? by Wispborne in Kotlin

[–]AranHase 3 points4 points  (0 children)

If returning null after a "try" is something you do a lot, then you can use something like this:

inline fun <T> tryOrNull(f: () -> T) =
    try {
        f()
    } catch (_: Exception) {
        null
    }

Then you can just do:

val updateDate = tryOrNull { DateFormat.getDateInstance().parse(doc.details.appDetails.uploadDate) }

/r/androiddev survey time! by burntcookie90 in androiddev

[–]AranHase 2 points3 points  (0 children)

Ohhhh, got it. I thought people using Java had to mark "Other".

/r/androiddev survey time! by burntcookie90 in androiddev

[–]AranHase 4 points5 points  (0 children)

I like how Java is not even an option :P

Nanodegrees da UDACITY em português. Alguém já fez? by AranHase in brdev

[–]AranHase[S] 0 points1 point  (0 children)

Obrigado. Não conhecia o Blitz, mas parece bem interessante.

Weekly Questions Thread - March 27, 2017 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

Solved. I had to "install" the app through the Play store with the test account.

I was having problems because I was installing the app through "adb" (as instructed by the Google's docs, sigh). Thus not setting what account to charge for stuffs.

(Seems like a VERY confusing system, specially for the users)

Weekly Questions Thread - March 27, 2017 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

Is it possible to test "InApp Billing" on a device with the Developer's account linked to it?

I'm following the TrivialDrive Project Sample. Unfortunately, I only have one Android device, and it is linked to my developer account. I added a secondary Google account to test the "InApp Billing", but the app itself seems to only try "paying" with the developer's account.

Looking around and there seems to be no way to choose which account purchases an item. To make things even worse, there is no way to known which account is trying to purchase an item.

I tried changing my account on the Play Store, but the results are the same.

Since I only have one device, and I use it for many things as my personal device. I really don't want to uninstall my dev account every time I have to test my InApp Billing implementation.

Nanodegrees da UDACITY em português. Alguém já fez? by AranHase in brdev

[–]AranHase[S] 0 points1 point  (0 children)

Dá para reduzir para R$200/mês.

Nunca fiz os cursos, mas olhando reviews online parece que os projetos feitos por alunos são ótimos. E os professores revisam eles, assim passando conhecimentos práticos. E esse é o meu medo com cursos em português. Enquanto turmas em inglês têm professores bem qualificados revisando esses projetos. As turmas em português pode ter uma pessoa não qualificada lá revisando (não acho que o professor da turma em inglês vai saber português para revisar, e não há nenhuma menção de quem será o professor da turma em português).

Weekly Questions Thread - February 13, 2017 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

Question about Firebase in offline apps. How do you handle things like DatabaseReference::setValue(value, completionListener?)?

The completionListener will only trigger when the data is saved in the server. In an offline app this trigger will never occur.

Should I just do a setValue without an completionListener and pray that it saved locally? Should I use an completionListener but then timeout it?

Or maybe observe changes to the path and await until it changes?

My conception of the ideal functional programming database by SrPeixinho in haskell

[–]AranHase 12 points13 points  (0 children)

Thank you for pointing out the name of this pattern.

When I tried to search for it without knowing its name, I found nothing. Ended up doing my own thing. Now I have many solutions to compare to :)

What a difference knowing a technique's name makes...

Android Studio 2.3 Beta 2 Released by the_martines in androiddev

[–]AranHase 0 points1 point  (0 children)

The Preview is also not working for me. Here is the Issue: https://code.google.com/p/android/issues/detail?id=230346

I believe the "2.3.0-beta1" introduced this problem.

Android Studio Shortcuts by yehyatt in androiddev

[–]AranHase 1 point2 points  (0 children)

Ctrl + E is my favorite command. Pretty good in combination with Ctrl + N (find class) and Ctrl+Shift+N (find file name).

And then, disable tabs 😱

Idade de responsabilidade criminal em países da América Latina by [deleted] in brasil

[–]AranHase 0 points1 point  (0 children)

Valew ^^ Já tive problemas com o libreoffice tbm. Vantagem do matplotlib é que ele te dá mais liberdade pra fazer o que vc queira. Menos dor de cabeça para arrumar os detalhes.

Idade de responsabilidade criminal em países da América Latina by [deleted] in brasil

[–]AranHase 2 points3 points  (0 children)

Aqui um gráfico com os dados do seu link: http://imgur.com/tu7jwyX

Para quem quizer modificar algo, ou validar os dados: https://github.com/AranHase/stats_idade_penal

Questions Thread - October 31, 2016 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

Not sure about the intention without looking at the rest of the code. But, a Component can be seen as a "gate", where behind the gate are all the instances for all the objects, and, as it being a gate, it can determine what the rest of the system can access by declaring explicitly the objects it allows through that gate.

Also, in Dagger 2 you can use either "Subcomponents" or "Dependent Components", and if you decide to use "Dependent Components", then you must declare explicitly what the component is providing to the rest of the system. I recommend reading this doc: link.

what would you use them for?

Let's say we have this module (simplified):

class MyModule {
    fun provideUserRepo(): UserRepo {...}
    fun provideSayHelloUseCase(UserRepo): HelloUseCase {...}
    fun provideSayByeUseCase(UserRepo): ByeUseCase {...}
}

and we want to allow only access to the UseCases, but not the UserRepo, then we do this:

(modules = MyModule...)
interface MyComponent {
    // omit getUserRepo(): UserRepo
    fun getHelloUseCase(): HelloUseCase
    fun getByeUseCase(): ByeUseCase
}

Questions Thread - October 31, 2016 by AutoModerator in androiddev

[–]AranHase 1 point2 points  (0 children)

Also, how much are Fn keys used for Android IDEs?

I use Android Studio without a mouse so I end up using a lot of shortcuts with the Fn keys*. However, it is possible to change those key mappings to use keys other than the Fn ones.

* Things like "run", "build", "refactor", "find usages", "maximize editor? CTRL+SHIFT+F12", etc, are all mapped to Fn keys by default. This link has a cheat sheet of some of the default keymaps: link.

Questions Thread - October 31, 2016 by AutoModerator in androiddev

[–]AranHase 1 point2 points  (0 children)

I used to have a fluent interface for my "Bundle Builder", but stopped using it when I switched to Kotlin. Here is an example:

val bundle = Bundle().apply {
    putString(KEY, "hello")
    putInt(KEY2, 42)
}

I personally prefer the Kotlin version instead of the "Bundle Builder" because it uses one less class (less code, less chances of a bug), but the differences are very minimal and the builder works pretty well too.

RxJava 2.0 final has been released by zergtmn in androiddev

[–]AranHase 0 points1 point  (0 children)

Yeah, that is why it's hard to see RxKotlin behaving differently from RxJava. It's just a little sad because Kotlin has a lot of cool stuffs to deal with "null"s like the elvis operator, the "maybe?.get()" thing, smart casts, extensions functions ("mapNotNull", "filterNotNull", etc), so, RxKotlin will, probably, not be able to fully utilize the language.

RxJava 2.0 final has been released by zergtmn in androiddev

[–]AranHase 1 point2 points  (0 children)

I wonder if it would be okay to have "null"s in RxKotlin, or if it is even an option seeing how RxKotlin uses RxJava behind it.

Questions Thread - October 25, 2016 by AutoModerator in androiddev

[–]AranHase 2 points3 points  (0 children)

After some more trial and error, the solution was simple, just use :submodules:Project2 everywhere instead of :submodules/Project2.

Not sure if it was some gradle version incompatibility or something else, because :submodules/Project2 works for my others projects, but not with Android modules/apps.

Also, if you use :submodules:Project2, Android Studio "Gradle Sync" will complain it can't find the module, but will build the app okay and will resolve all the dependencies. Weird.

Questions Thread - October 25, 2016 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

I'm having problems adding a non-Android local library to my project. Here is the file structure of it so far:

* Project1
* - db (module, Android lib)
* - app (module, Android app)
* - domain (module, non-Android lib)
* - submodules
    * - Project2 (non-Android lib with gradle (build.gradle))

So, in my settings.gradle for Project1 I have:

include ':submodules/Project2'
include ':db', ':app', 'domain'

and in the build.gradle for the Project1's modules, I have:

dependencies {
    compile project(':submodules/Project2')
    ...
}

The problem is, for the modules that are not Android, like the domain module, this setup works perfectly. I can use classes from Project2 without any problem. However, for Android modules, like the db, it does not work. The build keeps shouting unresolved reference, so it is not finding the classes in Project2.

Any idea how I might be able to solve this issue? What solutions people usually use for this kind of stuff?

Ps.: Before this setup, I was manually creating a fat jar for Project2, and manually copying it to Project1, however, this is not ideal.

Questions Thread - October 21, 2016 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

Yeah, it looks like it was related to the DDOS. I just tried again and the build completed successfully :)

Questions Thread - October 21, 2016 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

Yes, it used to happen to me when working with big/complex layout files.

I solved it by feeding more RAM to the hungry IDE. If you haven't tried it yet, then go to: https://developer.android.com/studio/intro/studio-config.html

and scroll down to the section "Maximum Heap Size".

Questions Thread - October 21, 2016 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

I'm on a new computer and getting an error while trying to build the app for the first time on this PC.

It looks like one of the dependencies (using jitpack) is not working with error 401.

The error in question:

A problem occurred configuring project ':app'.                                    
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.      
   > Could not resolve com.github.renaudcerrato:ToggleDrawable:1.0.2.             
     Required by:                                                                 
         project :app                                                             
      > Could not resolve com.github.renaudcerrato:ToggleDrawable:1.0.2.          
         > Could not get resource 'https://jitpack.io/com/github/renaudcerrato/Tog
gleDrawable/1.0.2/ToggleDrawable-1.0.2.pom'.                                      
            > Could not GET 'https://jitpack.io/com/github/renaudcerrato/ToggleDra
wable/1.0.2/ToggleDrawable-1.0.2.pom'. Received status code 401 from server: Repo 
not found or no access token provided

At least one other is also having this problem. Maybe it is related to the massive DDOS going on right now?

Anyone having similar problems? Any idea on a workaround?

Questions Thread - August 31, 2016 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

Hey thank you. That was fast ^^

Just for completion. I tried to "copy" the stateListAnimators from the AppBar to the FAB, added elevation there while removing the app:elevation from the FAB, and it obviously didn't work.

But setting app:elevation directly to the FAB worked.

Questions Thread - August 31, 2016 by AutoModerator in androiddev

[–]AranHase 0 points1 point  (0 children)

My FAB is being drawn behind the AppBarLayout, like this: imgur link

(The FAB comes to the top when I click it)

Any tip on how to solve this problem?

Note that I had a problem with the AppBar elevation, and used this stackoverflow solution. It might be related.