undo delete - code format
This commit is contained in:
parent
09dd044f3d
commit
8b8652d44c
4 changed files with 31 additions and 53 deletions
|
|
@ -25,7 +25,7 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.download.DeleteManager;
|
||||
import org.schabi.newpipe.download.DeleteDownloadManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
|
@ -56,15 +56,15 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
|||
private Activity mContext;
|
||||
private LayoutInflater mInflater;
|
||||
private DownloadManager mDownloadManager;
|
||||
private DeleteManager mDeleteManager;
|
||||
private DeleteDownloadManager mDeleteDownloadManager;
|
||||
private List<DownloadMission> mItemList;
|
||||
private DownloadManagerService.DMBinder mBinder;
|
||||
private int mLayout;
|
||||
|
||||
public MissionAdapter(Activity context, DownloadManagerService.DMBinder binder, DownloadManager downloadManager, DeleteManager deleteManager, boolean isLinear) {
|
||||
public MissionAdapter(Activity context, DownloadManagerService.DMBinder binder, DownloadManager downloadManager, DeleteDownloadManager deleteDownloadManager, boolean isLinear) {
|
||||
mContext = context;
|
||||
mDownloadManager = downloadManager;
|
||||
mDeleteManager = deleteManager;
|
||||
mDeleteDownloadManager = deleteDownloadManager;
|
||||
mBinder = binder;
|
||||
|
||||
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
|
@ -79,7 +79,7 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
|||
|
||||
for (int i = 0; i < mDownloadManager.getCount(); i++) {
|
||||
DownloadMission mission = mDownloadManager.getMission(i);
|
||||
if (!mDeleteManager.contains(mission)) {
|
||||
if (!mDeleteDownloadManager.contains(mission)) {
|
||||
mItemList.add(mDownloadManager.getMission(i));
|
||||
}
|
||||
}
|
||||
|
|
@ -264,7 +264,7 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
|||
|
||||
return true;
|
||||
case R.id.delete:
|
||||
mDeleteManager.add(h.mission);
|
||||
mDeleteDownloadManager.add(h.mission);
|
||||
updateItemList();
|
||||
notifyDataSetChanged();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -21,12 +21,10 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.download.DeleteManager;
|
||||
import org.schabi.newpipe.download.DeleteDownloadManager;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import us.shandian.giga.get.DownloadManager;
|
||||
import us.shandian.giga.get.DownloadMission;
|
||||
import us.shandian.giga.service.DownloadManagerService;
|
||||
import us.shandian.giga.ui.adapter.MissionAdapter;
|
||||
|
||||
|
|
@ -43,7 +41,7 @@ public abstract class MissionsFragment extends Fragment {
|
|||
private GridLayoutManager mGridManager;
|
||||
private LinearLayoutManager mLinearManager;
|
||||
private Context mActivity;
|
||||
private DeleteManager mDeleteManager;
|
||||
private DeleteDownloadManager mDeleteDownloadManager;
|
||||
private Disposable mDeleteDisposable;
|
||||
|
||||
private ServiceConnection mConnection = new ServiceConnection() {
|
||||
|
|
@ -52,8 +50,8 @@ public abstract class MissionsFragment extends Fragment {
|
|||
public void onServiceConnected(ComponentName name, IBinder binder) {
|
||||
mBinder = (DownloadManagerService.DMBinder) binder;
|
||||
mDownloadManager = setupDownloadManager(mBinder);
|
||||
if (mDeleteManager != null) {
|
||||
mDeleteManager.setDownloadManager(mDownloadManager);
|
||||
if (mDeleteDownloadManager != null) {
|
||||
mDeleteDownloadManager.setDownloadManager(mDownloadManager);
|
||||
updateList();
|
||||
}
|
||||
}
|
||||
|
|
@ -66,10 +64,10 @@ public abstract class MissionsFragment extends Fragment {
|
|||
|
||||
};
|
||||
|
||||
public void setDeleteManager(@NonNull DeleteManager deleteManager) {
|
||||
mDeleteManager = deleteManager;
|
||||
public void setDeleteManager(@NonNull DeleteDownloadManager deleteDownloadManager) {
|
||||
mDeleteDownloadManager = deleteDownloadManager;
|
||||
if (mDownloadManager != null) {
|
||||
mDeleteManager.setDownloadManager(mDownloadManager);
|
||||
mDeleteDownloadManager.setDownloadManager(mDownloadManager);
|
||||
updateList();
|
||||
}
|
||||
}
|
||||
|
|
@ -126,8 +124,8 @@ public abstract class MissionsFragment extends Fragment {
|
|||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (mDeleteManager != null) {
|
||||
mDeleteDisposable = mDeleteManager.getUndoObservable().subscribe(mission -> {
|
||||
if (mDeleteDownloadManager != null) {
|
||||
mDeleteDisposable = mDeleteDownloadManager.getUndoObservable().subscribe(mission -> {
|
||||
if (mAdapter != null) {
|
||||
mAdapter.updateItemList();
|
||||
mAdapter.notifyDataSetChanged();
|
||||
|
|
@ -164,7 +162,7 @@ public abstract class MissionsFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void updateList() {
|
||||
mAdapter = new MissionAdapter((Activity) mActivity, mBinder, mDownloadManager, mDeleteManager, mLinear);
|
||||
mAdapter = new MissionAdapter((Activity) mActivity, mBinder, mDownloadManager, mDeleteDownloadManager, mLinear);
|
||||
|
||||
if (mLinear) {
|
||||
mList.setLayoutManager(mLinearManager);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue