Skip to content

Instantly share code, notes, and snippets.

View crazyhitty's full-sized avatar

Kartik Sharma crazyhitty

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

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 March 11, 2018 12:09
How to use AsyncTask properly
public class MyActivity extends AppCompatActivity {
private DummyAsyncTask dummyAsyncTask = new DummyAsyncTask(new DummyAsyncTask.StatusCallback() {
@Override
public void progressStarted() {
}
@Override
public void onProgress(int progress) {
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 March 14, 2017 10:34
Android 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 August 7, 2016 15:30
Maintaining savedInstanceState in a fragment. Source: http://stackoverflow.com/a/13306633
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();
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;