added active downloads badge in the downloads bottom navigation icon
This commit is contained in:
parent
d08dcb90e3
commit
de044b7968
6 changed files with 23 additions and 4 deletions
|
|
@ -29,6 +29,7 @@ import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import com.deniscerri.ytdlnis.database.viewmodel.CookieViewModel
|
import com.deniscerri.ytdlnis.database.viewmodel.CookieViewModel
|
||||||
|
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||||
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
|
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
|
||||||
import com.deniscerri.ytdlnis.ui.BaseActivity
|
import com.deniscerri.ytdlnis.ui.BaseActivity
|
||||||
import com.deniscerri.ytdlnis.ui.HomeFragment
|
import com.deniscerri.ytdlnis.ui.HomeFragment
|
||||||
|
|
@ -36,6 +37,7 @@ import com.deniscerri.ytdlnis.ui.downloads.DownloadQueueActivity
|
||||||
import com.deniscerri.ytdlnis.ui.more.settings.SettingsActivity
|
import com.deniscerri.ytdlnis.ui.more.settings.SettingsActivity
|
||||||
import com.deniscerri.ytdlnis.util.ThemeUtil
|
import com.deniscerri.ytdlnis.util.ThemeUtil
|
||||||
import com.deniscerri.ytdlnis.util.UpdateUtil
|
import com.deniscerri.ytdlnis.util.UpdateUtil
|
||||||
|
import com.google.android.exoplayer2.offline.Download
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.elevation.SurfaceColors
|
import com.google.android.material.elevation.SurfaceColors
|
||||||
import com.google.android.material.navigation.NavigationBarView
|
import com.google.android.material.navigation.NavigationBarView
|
||||||
|
|
@ -57,6 +59,7 @@ class MainActivity : BaseActivity() {
|
||||||
private lateinit var preferences: SharedPreferences
|
private lateinit var preferences: SharedPreferences
|
||||||
private lateinit var resultViewModel: ResultViewModel
|
private lateinit var resultViewModel: ResultViewModel
|
||||||
private lateinit var cookieViewModel: CookieViewModel
|
private lateinit var cookieViewModel: CookieViewModel
|
||||||
|
private lateinit var downloadViewModel: DownloadViewModel
|
||||||
private lateinit var navigationView: View
|
private lateinit var navigationView: View
|
||||||
private lateinit var navHostFragment : NavHostFragment
|
private lateinit var navHostFragment : NavHostFragment
|
||||||
|
|
||||||
|
|
@ -68,6 +71,7 @@ class MainActivity : BaseActivity() {
|
||||||
context = baseContext
|
context = baseContext
|
||||||
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
|
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
|
||||||
cookieViewModel = ViewModelProvider(this)[CookieViewModel::class.java]
|
cookieViewModel = ViewModelProvider(this)[CookieViewModel::class.java]
|
||||||
|
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
|
||||||
preferences = context.getSharedPreferences("root_preferences", MODE_PRIVATE)
|
preferences = context.getSharedPreferences("root_preferences", MODE_PRIVATE)
|
||||||
|
|
||||||
if (preferences.getBoolean("incognito", false)){
|
if (preferences.getBoolean("incognito", false)){
|
||||||
|
|
@ -127,6 +131,19 @@ class MainActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val activeDownloadsBadge = (navigationView as NavigationBarView).getOrCreateBadge(R.id.historyFragment)
|
||||||
|
downloadViewModel.activeDownloadsCount.observe(this){
|
||||||
|
if (it == 0) {
|
||||||
|
activeDownloadsBadge.isVisible = false
|
||||||
|
activeDownloadsBadge.clearNumber()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
activeDownloadsBadge.isVisible = true
|
||||||
|
activeDownloadsBadge.number = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.navigationBarColor = SurfaceColors.SURFACE_2.getColor(this)
|
||||||
}
|
}
|
||||||
if (navigationView is NavigationView){
|
if (navigationView is NavigationView){
|
||||||
(navigationView as NavigationView).setCheckedItem(graph.startDestinationId)
|
(navigationView as NavigationView).setCheckedItem(graph.startDestinationId)
|
||||||
|
|
@ -160,8 +177,6 @@ class MainActivity : BaseActivity() {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.navigationBarColor = SurfaceColors.SURFACE_2.getColor(this)
|
|
||||||
|
|
||||||
cookieViewModel.updateCookiesFile()
|
cookieViewModel.updateCookiesFile()
|
||||||
val intent = intent
|
val intent = intent
|
||||||
handleIntents(intent)
|
handleIntents(intent)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ interface DownloadDao {
|
||||||
@Query("SELECT * FROM downloads WHERE status='Active'")
|
@Query("SELECT * FROM downloads WHERE status='Active'")
|
||||||
fun getActiveDownloads() : LiveData<List<DownloadItem>>
|
fun getActiveDownloads() : LiveData<List<DownloadItem>>
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(*) FROM downloads WHERE status='Active'")
|
||||||
|
fun getActiveDownloadsCount() : LiveData<Int>
|
||||||
|
|
||||||
@Query("SELECT * FROM downloads WHERE status='Active'")
|
@Query("SELECT * FROM downloads WHERE status='Active'")
|
||||||
fun getActiveDownloadsList() : List<DownloadItem>
|
fun getActiveDownloadsList() : List<DownloadItem>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||||
class DownloadRepository(private val downloadDao: DownloadDao) {
|
class DownloadRepository(private val downloadDao: DownloadDao) {
|
||||||
val allDownloads : LiveData<List<DownloadItem>> = downloadDao.getAllDownloads()
|
val allDownloads : LiveData<List<DownloadItem>> = downloadDao.getAllDownloads()
|
||||||
val activeDownloads : LiveData<List<DownloadItem>> = downloadDao.getActiveDownloads()
|
val activeDownloads : LiveData<List<DownloadItem>> = downloadDao.getActiveDownloads()
|
||||||
|
val activeDownloadsCount : LiveData<Int> = downloadDao.getActiveDownloadsCount()
|
||||||
val queuedDownloads : LiveData<List<DownloadItem>> = downloadDao.getQueuedDownloads()
|
val queuedDownloads : LiveData<List<DownloadItem>> = downloadDao.getQueuedDownloads()
|
||||||
val cancelledDownloads : LiveData<List<DownloadItem>> = downloadDao.getCancelledDownloads()
|
val cancelledDownloads : LiveData<List<DownloadItem>> = downloadDao.getCancelledDownloads()
|
||||||
val erroredDownloads : LiveData<List<DownloadItem>> = downloadDao.getErroredDownloads()
|
val erroredDownloads : LiveData<List<DownloadItem>> = downloadDao.getErroredDownloads()
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
|
||||||
val allDownloads : LiveData<List<DownloadItem>>
|
val allDownloads : LiveData<List<DownloadItem>>
|
||||||
val queuedDownloads : LiveData<List<DownloadItem>>
|
val queuedDownloads : LiveData<List<DownloadItem>>
|
||||||
val activeDownloads : LiveData<List<DownloadItem>>
|
val activeDownloads : LiveData<List<DownloadItem>>
|
||||||
|
val activeDownloadsCount : LiveData<Int>
|
||||||
val cancelledDownloads : LiveData<List<DownloadItem>>
|
val cancelledDownloads : LiveData<List<DownloadItem>>
|
||||||
val erroredDownloads : LiveData<List<DownloadItem>>
|
val erroredDownloads : LiveData<List<DownloadItem>>
|
||||||
val processingDownloads : LiveData<List<DownloadItem>>
|
val processingDownloads : LiveData<List<DownloadItem>>
|
||||||
|
|
@ -54,6 +55,7 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
|
||||||
allDownloads = repository.allDownloads
|
allDownloads = repository.allDownloads
|
||||||
queuedDownloads = repository.queuedDownloads
|
queuedDownloads = repository.queuedDownloads
|
||||||
activeDownloads = repository.activeDownloads
|
activeDownloads = repository.activeDownloads
|
||||||
|
activeDownloadsCount = repository.activeDownloadsCount
|
||||||
processingDownloads = repository.processingDownloads
|
processingDownloads = repository.processingDownloads
|
||||||
cancelledDownloads = repository.cancelledDownloads
|
cancelledDownloads = repository.cancelledDownloads
|
||||||
erroredDownloads = repository.erroredDownloads
|
erroredDownloads = repository.erroredDownloads
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,4 @@
|
||||||
style="@style/Widget.Material3.Chip.Filter"
|
style="@style/Widget.Material3.Chip.Filter"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:theme="@style/Theme.Material3.DayNight"
|
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,4 @@
|
||||||
style="@style/Widget.Material3.Chip.Suggestion.Elevated"
|
style="@style/Widget.Material3.Chip.Suggestion.Elevated"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:theme="@style/Theme.Material3.DayNight"
|
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue