Skip to content

Instantly share code, notes, and snippets.

Avatar

Kartik Sharma crazyhitty

View GitHub Profile
@crazyhitty
crazyhitty / issue_with_rx_room_flowable.md
Last active Mar 18, 2020
Issues with RxRoom and Flowable
View issue_with_rx_room_flowable.md

In RxRoom, Flowable will always emit atleast one item, so using single() and isEmpty() functions won't work as expected.

So, the one where you are checking if projects are cached or not using isEmpty() function, room will still emit one item which would be an empty list object. This happens because even if no values exist in db, Room will still create an empty list first and then try to populate it if any items exist. Finally, it would emit the list object even if it is empty.

You can resolve this issue by updating the areProjectsCached() function in ProjectsCacheImpl.kt like this:

override fun areProjectsCached(): Single<Boolean> =
    projectsDatabase.cachedProjectsDao()
        .getProjects()
@crazyhitty
crazyhitty / AsynTaskExample.java
Last active Mar 11, 2018
How to use AsyncTask properly
View AsynTaskExample.java
public class MyActivity extends AppCompatActivity {
private DummyAsyncTask dummyAsyncTask = new DummyAsyncTask(new DummyAsyncTask.StatusCallback() {
@Override
public void progressStarted() {
}
@Override
public void onProgress(int progress) {
View build.gradle
android {
...
signingConfigs {
release {
storeFile file("someDirectory/my_keystore.jks")
storePassword "my_store_pass_here"
keyAlias "my_key_alias_here"
keyPassword "my_key_pass_here"
}
@crazyhitty
crazyhitty / .gitignore
Created Mar 14, 2017
Android gitignore
View .gitignore
# Created by https://www.gitignore.io/api/android,intellij+iml
### Android ###
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
@crazyhitty
crazyhitty / MainActivity.java
Created Aug 7, 2016
Maintaining savedInstanceState in a fragment. Source: http://stackoverflow.com/a/13306633
View MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Only set fragment when saved instance is null
if(savedInstanceState==null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
View print_alphabets_sorted.java
class Main {
public static void main(String[] args) {
for(int i=0; i<26; i++){
System.out.print(getAlphabetsAZ()[i]);
}
}
public static char[] getAlphabetsAZ(){
char[] alphabetArr=new char[26];
int x=0;