resbase (08/11/2018)

This commit is contained in:
kapodamy 2018-11-08 19:03:30 -03:00
parent 21e205a6be
commit 4d6cfd2043
26 changed files with 97 additions and 900 deletions

View file

@ -68,8 +68,8 @@ public class MissionAdapter extends RecyclerView.Adapter<ViewHolder> {
private Deleter mDeleter;
private int mLayout;
private DownloadManager.MissionIterator mIterator;
private Handler mHandler;
private ArrayList<ViewHolderItem> mPendingDownloadsItems = new ArrayList<>();
private Handler mHandler;
private MenuItem mClear;
private View mEmptyMessage;

View file

@ -19,6 +19,7 @@ import us.shandian.giga.ui.adapter.MissionAdapter;
public class Deleter {
private static final int TIMEOUT = 5000;// ms
private static final int DELAY = 350;// ms
private static final int DELAY_RESUME = 400;// ms
private static final String BUNDLE_NAMES = "us.shandian.giga.ui.common.deleter.names";
private static final String BUNDLE_LOCATIONS = "us.shandian.giga.ui.common.deleter.locations";
@ -140,7 +141,7 @@ public class Deleter {
public void resume() {
if (running) return;
mHandler.postDelayed(rShow, (int) (DELAY * 1.5f));// 150% of the delay
mHandler.postDelayed(rShow, DELAY_RESUME);
}
public void dispose(Bundle bundle) {

View file

@ -1,4 +1,4 @@
package us.shandian.giga.ui.common;// TODO: ¡git it!
package us.shandian.giga.ui.common;
import android.graphics.Canvas;
import android.graphics.ColorFilter;

View file

@ -1,12 +0,0 @@
package us.shandian.giga.ui.fragment;
import us.shandian.giga.get.DownloadManager;
import us.shandian.giga.service.DownloadManagerService;
public class AllMissionsFragment extends MissionsFragment {
@Override
protected DownloadManager setupDownloadManager(DownloadManagerService.DMBinder binder) {
return binder.getDownloadManager();
}
}

View file

@ -15,7 +15,6 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@ -47,7 +46,7 @@ public class MissionsFragment extends Fragment {
private Bundle mBundle;
private boolean mForceUpdate;
private final ServiceConnection mConnection = new ServiceConnection() {
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
@ -111,15 +110,6 @@ public class MissionsFragment extends Fragment {
return v;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (menu != null) {
mSwitch = menu.findItem(R.id.switch_mode);
mClear = menu.findItem(R.id.clear_list);
}
}
/**
* Added in API level 23.
*/
@ -129,7 +119,7 @@ public class MissionsFragment extends Fragment {
// Bug: in api< 23 this is never called
// so mActivity=null
// so app crashes with null-pointer exception
// so app crashes with nullpointer exception
mActivity = activity;
}
@ -140,9 +130,11 @@ public class MissionsFragment extends Fragment {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = activity;
}
@Override
public void onDestroy() {
super.onDestroy();
@ -157,28 +149,10 @@ public class MissionsFragment extends Fragment {
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mAdapter != null) {
mAdapter.deleterDispose(outState);
mForceUpdate = true;
mBinder.removeMissionEventListener(mAdapter.getMessenger());
}
}
@Override
public void onResume() {
super.onResume();
if (mAdapter != null) {
mAdapter.deleterResume();
if (mForceUpdate) {
mForceUpdate = false;
mAdapter.forceUpdate();
}
mBinder.addMissionEventListener(mAdapter.getMessenger());
}
public void onPrepareOptionsMenu(Menu menu) {
mSwitch = menu.findItem(R.id.switch_mode);
mClear = menu.findItem(R.id.clear_list);
super.onPrepareOptionsMenu(menu);
}
@Override
@ -203,8 +177,11 @@ public class MissionsFragment extends Fragment {
mList.setLayoutManager(mGridManager);
}
// destroy all created views in the recycler
mList.setAdapter(null);
mAdapter.notifyDataSetChanged();
// re-attach the adapter in grid/lineal mode
mAdapter.setLinear(mLinear);
mList.setAdapter(mAdapter);
@ -214,4 +191,32 @@ public class MissionsFragment extends Fragment {
mPrefs.edit().putBoolean("linear", mLinear).apply();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mAdapter != null) {
mAdapter.deleterDispose(outState);
mForceUpdate = true;
mBinder.removeMissionEventListener(mAdapter.getMessenger());
}
}
@Override
public void onResume() {
super.onResume();
if (mAdapter != null) {
mAdapter.deleterResume();
if (mForceUpdate) {
mForceUpdate = false;
mAdapter.forceUpdate();
}
mBinder.addMissionEventListener(mAdapter.getMessenger());
}
}
}