X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fandroid%2FAndroidReaderBook.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fandroid%2FAndroidReaderBook.java;h=5d3f65daf1a1859530466bad54bc04a56f06e6a8;hb=649684189468206b46778bbc18d8bb47e66f7be1;hp=0000000000000000000000000000000000000000;hpb=9b05b757e2e817cd4ecd561032a66f63c158398d;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java b/src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java new file mode 100644 index 0000000..5d3f65d --- /dev/null +++ b/src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java @@ -0,0 +1,118 @@ +package be.nikiroo.fanfix.reader.android; + +import android.app.Activity; +import android.app.Fragment; +import android.graphics.Bitmap; +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +import java.io.IOException; + +import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.reader.Reader; +import be.nikiroo.utils.Image; +import be.nikiroo.utils.android.ImageUtilsAndroid; + +public class AndroidReaderBook extends Fragment { + private Reader reader; + private OnFragmentInteractionListener listener; + private MetaData meta; + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated to + * the activity and potentially other fragments contained in that activity. + *

+ * See the Android Training lesson Communicating with Other Fragments for more information. + */ + public interface OnFragmentInteractionListener { + void onFragmentInteraction(MetaData meta); + } + + public AndroidReaderBook() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_android_reader_book, + container, false); + } + + @Override + public void onAttach(Activity context) { + super.onAttach(context); + if (context instanceof OnFragmentInteractionListener) { + listener = (OnFragmentInteractionListener) context; + } + } + + @Override + public void onDetach() { + super.onDetach(); + listener = null; + } + + public void fill(final Reader reader, final String luid) { + View view = getView(); + if (view == null) { + return; + } + + final ImageView cover = view.findViewById(R.id.cover); + final TextView title = view.findViewById(R.id.title); + final FrameLayout frame = view.findViewById(R.id.coverWidget); + + new AsyncTask() { + @Override + protected MetaData doInBackground(Void[] objects) { + return Instance.getLibrary().getInfo(luid); + } + + @Override + protected void onPostExecute(MetaData meta) { + AndroidReaderBook.this.meta = meta; + + if (meta != null) { + title.setText(meta.getTitle()); + try { + Image coverImage = reader.getLibrary().getCover( + meta.getLuid()); + if (coverImage != null) { + Bitmap coverBitmap = ImageUtilsAndroid + .fromImage(coverImage); + coverBitmap = Bitmap.createScaledBitmap( + coverBitmap, 128, 128, true); + cover.setImageBitmap(coverBitmap); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + frame.setClickable(true); + frame.setFocusable(true); + frame.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OnFragmentInteractionListener llistener = listener; + if (llistener != null) { + llistener + .onFragmentInteraction(AndroidReaderBook.this.meta); + } + } + }); + } + }.execute(); + } +}