clear the download queue

This commit is contained in:
Kevin Richter 2016-02-09 16:34:41 +01:00
parent 4be0b2502e
commit 50d71d1395
3 changed files with 19 additions and 9 deletions

View File

@ -4,15 +4,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.*;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.kanade.tachiyomi.R; import eu.kanade.tachiyomi.R;
@ -22,6 +14,9 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment;
import nucleus.factory.RequiresPresenter; import nucleus.factory.RequiresPresenter;
import rx.Subscription; import rx.Subscription;
import java.util.ArrayList;
import java.util.List;
@RequiresPresenter(DownloadPresenter.class) @RequiresPresenter(DownloadPresenter.class)
public class DownloadFragment extends BaseRxFragment<DownloadPresenter> { public class DownloadFragment extends BaseRxFragment<DownloadPresenter> {
@ -66,6 +61,10 @@ public class DownloadFragment extends BaseRxFragment<DownloadPresenter> {
startButton = menu.findItem(R.id.start_queue); startButton = menu.findItem(R.id.start_queue);
pauseButton = menu.findItem(R.id.pause_queue); pauseButton = menu.findItem(R.id.pause_queue);
if(adapter.getItemCount() > 0) {
menu.findItem(R.id.clear_queue).setVisible(true);
}
// Menu seems to be inflated after onResume in fragments, so we initialize them here // Menu seems to be inflated after onResume in fragments, so we initialize them here
startButton.setVisible(!isRunning && !getPresenter().downloadManager.getQueue().isEmpty()); startButton.setVisible(!isRunning && !getPresenter().downloadManager.getQueue().isEmpty());
pauseButton.setVisible(isRunning); pauseButton.setVisible(isRunning);
@ -80,6 +79,11 @@ public class DownloadFragment extends BaseRxFragment<DownloadPresenter> {
case R.id.pause_queue: case R.id.pause_queue:
DownloadService.stop(getActivity()); DownloadService.stop(getActivity());
break; break;
case R.id.clear_queue: // Not sure if this is correct
DownloadService.stop(getActivity());
getPresenter().downloadManager.getQueue().clear();
onNextDownloads(new ArrayList<>());
break;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

View File

@ -14,4 +14,9 @@
android:visible="false" android:visible="false"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item android:title="@string/action_clear"
android:id="@+id/clear_queue"
android:visible="false"
app:showAsAction="never"/>
</menu> </menu>

View File

@ -36,6 +36,7 @@
<string name="action_start">Start</string> <string name="action_start">Start</string>
<string name="action_stop">Stop</string> <string name="action_stop">Stop</string>
<string name="action_pause">Pause</string> <string name="action_pause">Pause</string>
<string name="action_clear">Clear</string>
<string name="action_previous_chapter">Previous chapter</string> <string name="action_previous_chapter">Previous chapter</string>
<string name="action_next_chapter">Next chapter</string> <string name="action_next_chapter">Next chapter</string>
<string name="action_retry">Retry</string> <string name="action_retry">Retry</string>