diff options
author | Renard1911 | 2016-04-11 17:52:55 -0300 |
---|---|---|
committer | Renard1911 | 2016-04-11 17:52:55 -0300 |
commit | c94f0e1d27f0a92a17b2e65363bdce6461249d95 (patch) | |
tree | 6990d471d884ad87a2be9234e40fd2a91f6bb827 /app/src/main/java/layout | |
parent | 0f3adf23154e6d7e0eaced70a31676d71bef8e34 (diff) | |
parent | 90ee611af8ba4c38e70f27eb0df55e9134ad625c (diff) | |
download | BaiApp-c94f0e1d27f0a92a17b2e65363bdce6461249d95.tar.gz BaiApp-c94f0e1d27f0a92a17b2e65363bdce6461249d95.tar.xz BaiApp-c94f0e1d27f0a92a17b2e65363bdce6461249d95.zip |
Merge pull request #1 from Renard1911/devv1.6.0
Dev
Diffstat (limited to 'app/src/main/java/layout')
-rw-r--r-- | app/src/main/java/layout/FragmentBoardItemList.java (renamed from app/src/main/java/layout/fragmentThreadList.java) | 20 | ||||
-rw-r--r-- | app/src/main/java/layout/FragmentImage.java | 211 |
2 files changed, 224 insertions, 7 deletions
diff --git a/app/src/main/java/layout/fragmentThreadList.java b/app/src/main/java/layout/FragmentBoardItemList.java index c06fd93..149def3 100644 --- a/app/src/main/java/layout/fragmentThreadList.java +++ b/app/src/main/java/layout/FragmentBoardItemList.java @@ -38,6 +38,7 @@ import org.bienvenidoainternet.baiparser.MainActivity; import org.bienvenidoainternet.baiparser.R; import org.bienvenidoainternet.baiparser.RecentPostAdapter; import org.bienvenidoainternet.baiparser.ResponseActivity; +import org.bienvenidoainternet.baiparser.ThemeManager; import org.bienvenidoainternet.baiparser.ThreadListAdapter; import org.bienvenidoainternet.baiparser.structure.Board; import org.bienvenidoainternet.baiparser.structure.BoardItem; @@ -55,7 +56,7 @@ import java.net.URLDecoder; import java.util.ArrayList; import java.util.List; -public class fragmentThreadList extends Fragment { +public class FragmentBoardItemList extends Fragment { public static final String ARG_CURRENTBOARD = "currentBoard", ARG_THREAD_ID = "currentThreadId", ARG_MAIN_FRAGMENT = "imMainFragment", SAVED_BOARDITEMS = "savedBoardItems", RECENT_POST_MODE = "recentpostmode", ARG_CURRENT_THREAD = "currentThread"; List<ReplyID> idList = new ArrayList<>(); @@ -80,13 +81,15 @@ public class fragmentThreadList extends Fragment { LinearLayout layoutThreadProcess; TextView txtThreadProcess; - public fragmentThreadList() { + ThemeManager tm; + + public FragmentBoardItemList() { // Required empty public constructor } - public static fragmentThreadList newInstance(boolean mainFragment, Board board, BoardItem thread){ - fragmentThreadList fragment = new fragmentThreadList(); + public static FragmentBoardItemList newInstance(boolean mainFragment, Board board, BoardItem thread){ + FragmentBoardItemList fragment = new FragmentBoardItemList(); Bundle args = new Bundle(); args.putParcelable(ARG_CURRENTBOARD, board); args.putParcelable(ARG_CURRENT_THREAD, thread); @@ -104,6 +107,7 @@ public class fragmentThreadList extends Fragment { this.currentThread = getArguments().getParcelable(ARG_CURRENT_THREAD); this.imMainFragment = getArguments().getBoolean(ARG_MAIN_FRAGMENT); } + tm = new ThemeManager(getActivity()); } @Override @@ -130,7 +134,7 @@ public class fragmentThreadList extends Fragment { // Aplicación del Tema settings = PreferenceManager.getDefaultSharedPreferences(this.getContext()); - int themeResId = ((MainActivity)getActivity()).getCurrentThemeId(); + int themeResId = tm.getCurrentThemeId(); Context context = new ContextThemeWrapper(getActivity(), themeResId); LayoutInflater localInflater = inflater.cloneInContext(context); View v = localInflater.inflate(R.layout.fragment_fragment_thread_list, container, false); @@ -145,14 +149,14 @@ public class fragmentThreadList extends Fragment { this.loadingBar = (ProgressBar)rootView.findViewById(R.id.progressBar); // Agregamos color al divider del listview - ColorDrawable cd = new ColorDrawable((((MainActivity) getActivity()).themeManager).getMarginColor()); + ColorDrawable cd = new ColorDrawable(tm.getMarginColor()); listViewBoardItems.setDivider(cd); listViewBoardItems.setDividerHeight(1); // registramos los menus del listview registerForContextMenu(listViewBoardItems); // Creamos los dos adaptadores y los seteamos dependiendo del modo del fragmento - listViewAdapter = new ThreadListAdapter(v.getContext(), boardItems, (((MainActivity) getActivity()).themeManager)); + listViewAdapter = new ThreadListAdapter(v.getContext(), boardItems, tm); recentPostAdapter = new RecentPostAdapter(v.getContext(), boardItems); if (recentPostMode){ listViewBoardItems.setAdapter(recentPostAdapter); @@ -517,6 +521,7 @@ public class fragmentThreadList extends Fragment { } } listViewAdapter.notifyDataSetChanged(); + listViewAdapter.updateBoardItems(boardItems); loadingMoreThreads = false; if (boardItems.isEmpty()){ mListener.updateToolbar(currentBoard, currentThread); @@ -610,6 +615,7 @@ public class fragmentThreadList extends Fragment { } } listViewAdapter.notifyDataSetChanged(); + listViewAdapter.updateBoardItems(boardItems); if (settings.getBoolean("setting_scrollatnewthread", true)){ listViewBoardItems.setSelection(boardItems.size()); mListener.showActionButton(); diff --git a/app/src/main/java/layout/FragmentImage.java b/app/src/main/java/layout/FragmentImage.java new file mode 100644 index 0000000..f337e5f --- /dev/null +++ b/app/src/main/java/layout/FragmentImage.java @@ -0,0 +1,211 @@ +package layout; + +import android.content.Context; +import android.content.ContextWrapper; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; + +import com.davemorrissey.labs.subscaleview.ImageSource; +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; +import com.koushikdutta.async.future.FutureCallback; +import com.koushikdutta.ion.Ion; + +import org.bienvenidoainternet.baiparser.R; +import org.bienvenidoainternet.baiparser.ViewerActivity; +import org.bienvenidoainternet.baiparser.structure.BoardItemFile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; + +import pl.droidsonroids.gif.GifDrawable; +import pl.droidsonroids.gif.GifImageView; + +/** + * A simple {@link Fragment} subclass. + * Activities that contain this fragment must implement the + * {@link FragmentImage.OnFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link FragmentImage#newInstance} factory method to + * create an instance of this fragment. + */ +public class FragmentImage extends Fragment { + private static final String ARG_BOARD_ITEM = "param1"; + + public BoardItemFile boardItemFile; + + private OnFragmentInteractionListener mListener; + private SubsamplingScaleImageView imageView; + private GifImageView gifView; + private static final String ARG_FILE_URL = "fileURL"; + private ProgressBar downloadBar; + + public FragmentImage() { + // Required empty public constructor + } + + public static FragmentImage newInstance(BoardItemFile boardItemFile) { + FragmentImage fragment = new FragmentImage(); + Bundle args = new Bundle(); + args.putParcelable(ARG_BOARD_ITEM, boardItemFile); +// args.putString(ARG_FILE_URL, file); + fragment.setArguments(args); + Log.v("FragmentImage", fragment.toString() + " new Fragment"); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { +// currentThread = getArguments().getParcelable(ARG_BOARD_ITEM); + boardItemFile = getArguments().getParcelable(ARG_BOARD_ITEM); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_fragment_image, container, false); + imageView = (SubsamplingScaleImageView) view.findViewById(R.id.imageView); + gifView = (GifImageView) view.findViewById(R.id.gifView); + imageView.setVisibility(View.GONE); + gifView.setVisibility(View.GONE); + RelativeLayout layoutOpenBrowser = (RelativeLayout) view.findViewById(R.id.layoutOpenBrowser); + if (boardItemFile.file != null) { + if (!boardItemFile.file.endsWith(".webm") && !boardItemFile.file.endsWith(".swf")) { + layoutOpenBrowser.setVisibility(View.GONE); + downloadFile(); + }else{ + layoutOpenBrowser.setVisibility(View.VISIBLE); + } + } + Button btnOpenBrowser = (Button) view.findViewById(R.id.btnLaunchBrowser); + btnOpenBrowser.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(boardItemFile.fileURL)); + in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + v.getContext().startActivity(in); + } + }); + return view; + } + + // TODO: Rename method, update argument and hook method into UI event + public void onButtonPressed(Uri uri) { + if (mListener != null) { + mListener.onFragmentInteraction(uri); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnFragmentInteractionListener) { + mListener = (OnFragmentInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + public void setDownloadBar(ProgressBar downloadBar) { + this.downloadBar = downloadBar; + } + + /** + * 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. + * <p/> + * See the Android Training lesson <a href= + * "http://developer.android.com/training/basics/fragments/communicating.html" + * >Communicating with Other Fragments</a> for more information. + */ + public interface OnFragmentInteractionListener { + // TODO: Update argument type and name + void onFragmentInteraction(Uri uri); + } + + private void downloadFile() { + downloadBar = ((ViewerActivity)getActivity()).barDownload; + downloadBar.setVisibility(View.VISIBLE); + ContextWrapper cw = new ContextWrapper(getContext()); + File directory = cw.getDir("src", Context.MODE_PRIVATE); + final File filePath = new File(directory, boardItemFile.boardDir + "_" + boardItemFile.file); + if (filePath.exists()) { + downloadBar.setVisibility(View.GONE); + if (boardItemFile.file.endsWith(".gif")) { + try { + GifDrawable gifFromFile = new GifDrawable(filePath); + gifView.setImageDrawable(gifFromFile); + gifView.setVisibility(View.VISIBLE); + imageView.setVisibility(View.GONE); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + imageView.setImage(ImageSource.uri(filePath.toURI().getPath())); + imageView.setVisibility(View.VISIBLE); + gifView.setVisibility(View.GONE); + } + } + Ion.with(getContext()) + .load(boardItemFile.fileURL) + .progressBar(downloadBar) + .asInputStream() + .setCallback(new FutureCallback<InputStream>() { + @Override + public void onCompleted(Exception e, InputStream result) { + downloadBar.setVisibility(View.GONE); + if (e != null) { + e.printStackTrace(); + } else { + FileOutputStream fout; + try { + fout = new FileOutputStream(filePath); + final byte data[] = new byte[1024]; + int count; + while ((count = result.read(data, 0, 1024)) != -1) { + fout.write(data, 0, count); + } + } catch (Exception e1) { + e1.printStackTrace(); + } + if (boardItemFile.file.endsWith(".gif")) { + try { + GifDrawable gifFromFile = new GifDrawable(filePath); + gifView.setImageDrawable(gifFromFile); + gifView.setVisibility(View.VISIBLE); + imageView.setVisibility(View.GONE); + } catch (Exception e2) { + e2.printStackTrace(); + } + } else { + imageView.setImage(ImageSource.uri(filePath.toURI().getPath())); + gifView.setVisibility(View.GONE); + imageView.setVisibility(View.VISIBLE); + } + } + } + }); + } +} |