Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.allsoftdroid.audiobook.feature_downloader.presentation.DownloadManage
import com.allsoftdroid.audiobook.feature_mini_player.presentation.MiniPlayerFragment
import com.allsoftdroid.audiobook.presentation.viewModel.MainActivityViewModel
import com.allsoftdroid.audiobook.utility.MovableFrameLayout
import com.allsoftdroid.audiobook.utility.StoragePermissionHandler
import com.allsoftdroid.common.base.utils.StoragePermissionHandler
import com.allsoftdroid.common.base.activity.BaseActivity
import com.allsoftdroid.common.base.extension.Event
import com.allsoftdroid.common.base.network.ConnectionLiveData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.allsoftdroid.audiobook.utility
package com.allsoftdroid.common.base.utils

import android.Manifest
import android.app.Activity
Expand All @@ -22,7 +22,8 @@ class StoragePermissionHandler {
fun requestPermission(context: Activity){
ActivityCompat.requestPermissions(context,
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE),
MY_PERMISSIONS_REQUEST_READ_WRITE_STORAGE)
MY_PERMISSIONS_REQUEST_READ_WRITE_STORAGE
)
}

fun isRequestGrantedFor(requestCode:Int,grantResults: IntArray):Boolean{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class AudioBookListFragment : BaseUIFragment(){
booksViewModel.audioBooks.observe(viewLifecycleOwner, Observer {
it?.let {
if(!booksViewModel.isSearching){
// setVisibility(binding.networkNoConnection,set=false)
if(it.isNotEmpty()) setVisibility(binding.networkNoConnection,set=false)
bookAdapter.submitList(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.allsoftdroid.common.base.store.audioPlayer.*
import com.allsoftdroid.common.base.store.downloader.*
import com.allsoftdroid.common.base.utils.BindingUtils.getNormalizedText
import com.allsoftdroid.common.base.utils.ShareUtils
import com.allsoftdroid.common.base.utils.StoragePermissionHandler
import com.allsoftdroid.feature.book_details.R
import com.allsoftdroid.feature.book_details.databinding.FragmentAudiobookDetailsBinding
import com.allsoftdroid.feature.book_details.di.BookDetailsModule
Expand Down Expand Up @@ -274,12 +275,17 @@ class AudioBookDetailsFragment : BaseUIFragment(),KoinComponent {
}

dataBinding.imgViewBookDownload.setOnClickListener {
val isSent = bookDetailsViewModel.downloadAllChapters()
if (!isSent) {
Toast.makeText(this.requireActivity(),getString(R.string.download_soon_start),Toast.LENGTH_SHORT).show()
}
if(StoragePermissionHandler.isPermissionGranted(requireActivity())){
val isSent = bookDetailsViewModel.downloadAllChapters()
if(!isSent){
Toast.makeText(requireActivity(),getText(R.string.download_soon_start),Toast.LENGTH_SHORT).show()
}else{
dataBinding.imgViewBookDownload.setBackgroundResource(R.drawable.gradiant_background)
}

it.setBackgroundResource(R.drawable.gradiant_background)
}else{
StoragePermissionHandler.requestPermission(requireActivity())
}
}

dataBinding.bookMediaActionsPlay.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ internal class BookDetailsViewModel(
private val getFetchAdditionalBookDetailsUseCase: FetchAdditionalBookDetailsUsecase,
private val listenLaterUsecase: ListenLaterUsecase,
private val getTrackListUsecase : GetTrackListUsecase) : ViewModel(){
private var isMultiDownloadEventSent: Boolean = false

/**
* cancelling this job cancels all the job started by this viewmodel
*/
Expand All @@ -56,8 +58,6 @@ internal class BookDetailsViewModel(
private var currentPlayingTrack : Int = /*state.trackPlaying*/ 0
fun getCurrentPlayingTrack() = if (currentPlayingTrack<1) 1 else currentPlayingTrack

private var isMultiDownloadEventSent:Boolean = false /* status of multi download event*/

// when back button is pressed in the UI
private var _backArrowPressed = MutableLiveData<Event<Boolean>>()
val backArrowPressed: LiveData<Event<Boolean>>
Expand Down Expand Up @@ -553,6 +553,8 @@ internal class BookDetailsViewModel(

if (isMultiDownloadEventSent) return false

isMultiDownloadEventSent = true

viewModelScope.launch {
val downloads = mutableListOf<Download>()

Expand All @@ -572,11 +574,11 @@ internal class BookDetailsViewModel(
)
)
}

Timber.d("Total chapters to be downloaded is ${downloads.size}")
downloaderAction(MultiDownload(downloads = downloads))
}
}

downloaderAction(MultiDownload(downloads = downloads))
isMultiDownloadEventSent = true
}

return isMultiDownloadEventSent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,27 @@ else if(downloadEvent instanceof Downloaded){
}

private void addToDownloadQueueRequest(Download obj) {

mDownloadQueue.put(obj.getUrl(),obj);

if(mDownloadQueue.size()==1){
Timber.d("Downloading as it is first request");
downloadOldestRequest();
}else{
insertDownloadDatabase(DOWNLOADER_PENDING_ID,obj.getName(),obj.getUrl());
Timber.d("Added to download queue");
}
insertDownloadDatabase(DOWNLOADER_PENDING_ID,obj.getName(),obj.getUrl());

mDownloadEventStore.publish(
new Event<DownloadEvent>(new Downloading(obj.getUrl(),obj.getBookId(),obj.getChapterIndex()))
);

if(mDownloadQueue.size()==1){
Timber.d("Downloading as it is first request");
downloadOldestRequest();
}
}

private void downloadNext(String removeUrl) {
mDownloadQueue.remove(removeUrl);
mDownloadObserver.stopWatching();
isDownloading = false;

if(mDownloadQueue.size()>0){
if(!mDownloadQueue.isEmpty()){
downloadOldestRequest();
}

Expand Down Expand Up @@ -232,7 +232,7 @@ private long download(String URL, String name, String description, String subPat


if(downloadId !=DOWNLOADER_PROTOCOL_NOT_SUPPORTED){
Timber.d("Downloader doesn't support this protocol for file from URL: =>%s", URL);
Timber.d("Downloader support this protocol for file from URL: =>%s", URL);
insertDownloadDatabase(downloadId,name,URL);
}else {

Expand Down Expand Up @@ -383,8 +383,13 @@ public void removeFromDownloadDatabase(long downloadId){

@Override
public void bulkDownload(List<Download> downloads){
for(Download download : downloads){
addToDownloadQueueRequest(download);
if(!downloads.isEmpty()){
Timber.d("Received bulk download request:%s", downloads.size());
for(Download download : downloads){
addToDownloadQueueRequest(download);
}
}else {
Timber.d("Empty multi download request");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder _holder, fin
})
);



if(mDownloader.getStatusByDownloadId(holder.downloadId)==null){
downloadInterrupted(holder);
}else if(mDownloader.getStatusByDownloadId(holder.downloadId).length>0 &&
Expand Down Expand Up @@ -180,7 +178,10 @@ private void downloadCompleted(final ViewHolderDownloadCursor holder,long downlo
holder.mDeleteButton.setVisibility(View.VISIBLE);
holder.mDeleteButton.setOnClickListener(view -> DeleteFileHandler(mDownloader,holder.downloadId));
holder.mProgressBar.setVisibility(View.GONE);
holder.mProgressDetails.setText(Utility.bytes2String(mDownloader.getProgress(downloadId)[1]));
long[] progress = mDownloader.getProgress(downloadId);
if(progress != null){
holder.mProgressDetails.setText(Utility.bytes2String(progress[1]));
}
holder.mFileName.setOnClickListener(view -> mDownloader.openDownloadedFile(mContext,holder.downloadId));
}

Expand Down Expand Up @@ -210,6 +211,9 @@ private void DeleteFileHandler(final IDownloader downloader, final long download
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}else {
downloader.removeFromDownloadDatabase(downloadId);
mDownloaderRefresh.ReloadAdapter();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class MiniPlayerViewModel(
currentPlayingIndex = event.position
}

is PlaySelectedTrack -> {
setShouldPlay(play = true)
}

is Play -> {
setShouldPlay(play = true)
}
Expand Down