|
|
|
|
@ -27,21 +27,19 @@ import com.fongmi.android.tv.databinding.ActivityCollectBinding; |
|
|
|
|
import com.fongmi.android.tv.model.SiteViewModel; |
|
|
|
|
import com.fongmi.android.tv.ui.fragment.CollectFragment; |
|
|
|
|
import com.fongmi.android.tv.ui.presenter.CollectPresenter; |
|
|
|
|
import com.fongmi.android.tv.utils.PausableThreadPoolExecutor; |
|
|
|
|
import com.fongmi.android.tv.utils.PauseThreadPoolExecutor; |
|
|
|
|
import com.fongmi.android.tv.utils.ResUtil; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
public class CollectActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
|
private PauseThreadPoolExecutor mExecutor; |
|
|
|
|
private ActivityCollectBinding mBinding; |
|
|
|
|
private ArrayObjectAdapter mAdapter; |
|
|
|
|
private PausableThreadPoolExecutor mExecutor; |
|
|
|
|
private SiteViewModel mViewModel; |
|
|
|
|
private PageAdapter mPageAdapter; |
|
|
|
|
private List<Site> mSites; |
|
|
|
|
@ -126,7 +124,7 @@ public class CollectActivity extends BaseActivity { |
|
|
|
|
mPageAdapter.notifyDataSetChanged(); |
|
|
|
|
int core = Runtime.getRuntime().availableProcessors(); |
|
|
|
|
int corePoolSize = Math.max(Constant.THREAD_POOL, core); |
|
|
|
|
mExecutor = new PausableThreadPoolExecutor(corePoolSize, corePoolSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); |
|
|
|
|
mExecutor = new PauseThreadPoolExecutor(corePoolSize, corePoolSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); |
|
|
|
|
mBinding.result.setText(getString(R.string.collect_result, getKeyword())); |
|
|
|
|
for (Site site : mSites) mExecutor.execute(() -> search(site)); |
|
|
|
|
} |
|
|
|
|
@ -158,24 +156,21 @@ public class CollectActivity extends BaseActivity { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onBackPressed() { |
|
|
|
|
super.onBackPressed(); |
|
|
|
|
if (mExecutor == null) return; |
|
|
|
|
mExecutor.shutdownNow(); |
|
|
|
|
protected void onResume() { |
|
|
|
|
super.onResume(); |
|
|
|
|
if (mExecutor != null) mExecutor.resume(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onPause() { |
|
|
|
|
super.onPause(); |
|
|
|
|
if (mExecutor == null) return; |
|
|
|
|
mExecutor.pause(); |
|
|
|
|
if (mExecutor != null) mExecutor.pause(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onResume() { |
|
|
|
|
super.onResume(); |
|
|
|
|
if (mExecutor == null) return; |
|
|
|
|
mExecutor.resume(); |
|
|
|
|
public void onBackPressed() { |
|
|
|
|
super.onBackPressed(); |
|
|
|
|
if (mExecutor != null) mExecutor.shutdownNow(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class PageAdapter extends FragmentStatePagerAdapter { |
|
|
|
|
|