use of com.fedorvlasov.lazylist.ImageLoader in project MiMangaNu by raulhaag.
the class DetailsFragment method onStart.
@Override
public void onStart() {
super.onStart();
Thread t0 = new Thread(new Runnable() {
@Override
public void run() {
try {
List<Manga> mangas = Database.getMangas(getContext(), null, true);
for (Manga m : mangas) {
if (m.getPath().equals(manga.getPath())) {
mangaAlreadyAdded = true;
if (floatingActionButton_add != null)
floatingActionButton_add.hide();
}
}
} catch (Exception e) {
Log.e(TAG, "Exception", e);
Util.getInstance().toast(getContext(), Log.getStackTraceString(e));
}
}
});
t0.start();
data = (ControlInfo) getView().findViewById(R.id.datos);
swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.str);
ActionBar mActBar = getActivity().getActionBar();
if (mActBar != null) {
mActBar.setDisplayHomeAsUpEnabled(true);
}
floatingActionButton_add = (FloatingActionButton) getView().findViewById(R.id.floatingActionButton_add);
floatingActionButton_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mangaAlreadyAdded) {
AsyncAddManga nAsyncAddManga = new AsyncAddManga(manga, getActivity(), getView(), false, false, true);
nAsyncAddManga.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
AnimatorSet set = new AnimatorSet();
ObjectAnimator anim1 = ObjectAnimator.ofFloat(floatingActionButton_add, "alpha", 1.0f, 0.0f);
anim1.setDuration(0);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
ObjectAnimator anim2 = ObjectAnimator.ofFloat(floatingActionButton_add, "y", displayMetrics.heightPixels);
anim2.setDuration(500);
set.playSequentially(anim2, anim1);
set.start();
} else {
Util.getInstance().showFastSnackBar(getString(R.string.already_on_db), getView(), getContext());
}
}
});
int[] colors = ThemeColors.getColors(PreferenceManager.getDefaultSharedPreferences(getActivity()));
floatingActionButton_add.setBackgroundTintList(ColorStateList.valueOf(colors[1]));
swipeRefreshLayout.setColorSchemeColors(colors[0], colors[1]);
data.setColor(MainActivity.darkTheme, colors[0]);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
window.setNavigationBarColor(colors[0]);
window.setStatusBarColor(colors[4]);
}
if (getActivity() != null) {
((MainActivity) getActivity()).setTitle(getResources().getString(R.string.datosde) + " " + title);
}
manga = new Manga(id, title, path, false);
manga.setImages(img);
data.enableTitleCopy(getActivity(), manga.getTitle());
serverBase = ServerBase.getServer(id, getContext());
imageLoader = new ImageLoader(getContext());
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
loadDetailsTask = (LoadDetailsTask) new LoadDetailsTask().execute();
}
});
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(true);
}
});
loadDetailsTask = (LoadDetailsTask) new LoadDetailsTask().execute();
}
use of com.fedorvlasov.lazylist.ImageLoader in project MiMangaNu by raulhaag.
the class MangaFragment method onActivityCreated.
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
pm = PreferenceManager.getDefaultSharedPreferences(getActivity());
super.onCreate(savedInstanceState);
if (mMangaId == -1) {
getActivity().onBackPressed();
}
mManga = Database.getManga(getActivity(), mMangaId);
mServerBase = ServerBase.getServer(mManga.getServerId(), getContext());
if (getView() == null) {
try {
finalize();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
} else {
mListView = getView().findViewById(R.id.list);
swipeReLayout = getView().findViewById(R.id.str);
readerOptions = getView().findViewById(R.id.reader_options);
mImageLoader = new ImageLoader(getActivity());
final int[] colors = ThemeColors.getColors(pm);
readerOptions.setBackgroundColor(colors[0]);
readerOptions.setManga(mManga);
swipeReLayout.setColorSchemeColors(colors[0], colors[1]);
if (savedInstanceState != null) {
if (searchForNewChapters.getStatus() == AsyncTask.Status.RUNNING) {
swipeReLayout.post(new Runnable() {
@Override
public void run() {
swipeReLayout.setRefreshing(true);
}
});
}
}
swipeReLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if ((searchForNewChapters.getStatus() != AsyncTask.Status.RUNNING)) {
searchForNewChapters = new SearchForNewChapters();
searchForNewChapters.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
mListView.setDivider(new ColorDrawable(colors[0]));
mListView.setDividerHeight(1);
mInfo = new ControlInfoNoScroll(getActivity());
mListView.addHeaderView(mInfo);
mInfo.setColor(MainActivity.darkTheme, colors[0]);
mInfo.enableTitleCopy(getActivity(), mManga.getTitle());
ChapterAdapter.setColor(MainActivity.darkTheme, colors[1], colors[0]);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Chapter c = (Chapter) mListView.getAdapter().getItem(position);
getPagesTask = new GetPagesTask();
getPagesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, c);
}
});
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
mListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
return false;
}
@Override
public void onDestroyActionMode(android.view.ActionMode mode) {
mChapterAdapter.clearSelection();
}
@Override
public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.listitem_capitulo_menu_cab, menu);
return true;
}
@Override
public boolean onActionItemClicked(final android.view.ActionMode mode, MenuItem item) {
final SparseBooleanArray selection = mChapterAdapter.getSelection();
final ServerBase serverBase = ServerBase.getServer(mManga.getServerId(), getContext());
boolean finish = true;
switch(item.getItemId()) {
case R.id.select_all:
mChapterAdapter.selectAll();
return true;
case R.id.unselect:
mChapterAdapter.clearSelection();
return true;
case R.id.select_from:
mChapterAdapter.selectFrom(selection.keyAt(0));
return true;
case R.id.select_to:
mChapterAdapter.selectTo(selection.keyAt(0));
return true;
case R.id.download_selection:
new AsyncAddChapters().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mChapterAdapter.getSelectedChapters());
break;
case R.id.mark_as_read_and_delete_images:
markSelectedAsRead = new MarkSelectedAsRead(selection.size());
markSelectedAsRead.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
deleteImages = new DeleteImages(serverBase, selection.size());
deleteImages.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case R.id.delete_images:
deleteImages = new DeleteImages(serverBase, selection.size());
deleteImages.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case R.id.remove_chapter:
finish = false;
new AlertDialog.Builder(getContext()).setTitle(R.string.app_name).setMessage(R.string.delete_confirm).setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (selection.size() < 8) {
// Remove chapters on UI Thread
for (int i = selection.size() - 1; i >= 0; i--) {
Chapter chapter = mChapterAdapter.getItem(selection.keyAt(i));
chapter.delete(getActivity(), mManga, serverBase);
mChapterAdapter.remove(chapter);
mode.finish();
}
} else {
removeChapters = new RemoveChapters(serverBase, selection.size(), mode);
removeChapters.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
dialog.dismiss();
}
}).show();
break;
case R.id.reset_chapter:
resetChapters = new ResetChapters(serverBase, selection.size());
resetChapters.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case R.id.mark_selected_as_read:
markSelectedAsRead = new MarkSelectedAsRead(selection.size());
markSelectedAsRead.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case R.id.mark_selected_as_unread:
markSelectedAsUnread = new MarkSelectedAsUnread(selection.size());
markSelectedAsUnread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
}
mChapterAdapter.notifyDataSetChanged();
if (finish)
mode.finish();
return false;
}
@Override
public void onItemCheckedStateChanged(android.view.ActionMode mode, int position, long id, boolean checked) {
mChapterAdapter.setSelectedOrUnselected(position);
}
});
getActivity().setTitle(mManga.getTitle());
Database.updateMangaRead(getActivity(), mManga.getId());
loadInfo(mManga);
chapters_order = pm.getInt(CHAPTERS_ORDER, 1);
hide_read = pm.getBoolean(CHAPTERS_HIDE_READ, false);
}
}
Aggregations