กรณีที่ runningFirebase = 0 และติดตั้งแอพใหม่

count = 0

กรณีที่ share data เป็น null ให้
running = 0
setRunning(running)

return count

=======================================================================
กรณีที่ runningFirebase > 0 และติดตั้งแอพใหม่

count = 0

กรณีที่ share data เป็น null ให้
running = 0
setRunning(running)

if(runningFirebase > 0 && running == 0){
    
    count = runningFirebase - running;

    count = 1 - 0
    count = 1
    ----
    count = 2 - 0
    count = 2
}



return count

=======================================================================

กรณีที่ runningFirebase > 0 และ running > 0
count = 0

running > 0

running = getRunning()

if(runningFirebase > 0 && running == 0 ){
    .........
} else if(runningFirebase > 0 && running > 0){
    if(running > runningFirebase){
        running = runningFirebase
        setRunning(running)
    }

    count = runningFirebase - running;

    count = 1 - 1
    count = 0
    ----
    count = 5 - 1
    count = 4
}


return count

=======================================================================

กรณีที่ runningFirebase = 0 และ running > 0
count = 0

running > 0

running = getRunning()

if(runningFirebase > 0 && running == 0 ){
    .........
} else if(runningFirebase > 0 && running > 0){
    .........
} else if(runningFirebase == 0 && running > 0){
    running = runningFirebase
    setRunning(running)

    count = runningFirebase - running;

    count = 0 - 0
    count = 0
}


return count

=======================================================================
สรุปเป็น code

count = 0

running = getRunning() == null ? 0 : getRunning()

if(runningFirebase > 0 && running > 0){
    if(running > runningFirebase){
        running = runningFirebase
    }
    
} else if(runningFirebase == 0 && running > 0){
    running = runningFirebase
}

count = runningFirebase - running;

=======================================================================

กรณี Clear noti count

ให้เช็ต running = runningFirebase

running = runningFirebase
setRunning(running)