Refactor & Documentation

TransferProgressFragment, FileItem & FileListAdapter
This commit is contained in:
Aditya-Sood 2019-06-29 21:55:50 +05:30
parent f9103e2d5a
commit ff6768cbaa
3 changed files with 24 additions and 102 deletions

View File

@ -1,23 +1,24 @@
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
/**
* Helper class, part of the local file sharing module.
*
* Defines a file-item to represent the files being transferred.
* */
public class FileItem {
public static final short TO_BE_SENT = -1;
public static final short SENDING = 0;
public static final short SENT = +1;
public static final short ERROR = +2;
public static final short TO_BE_SENT = -1; // File yet to be sent
public static final short SENDING = 0; // Being sent
public static final short SENT = +1; // Successfully sent
public static final short ERROR = +2; // Error encountered while transferring the file
private String fileName = "";
private short fileStatus = TO_BE_SENT;
private String fileName;
private short fileStatus;
public FileItem(String fileName, short fileStatus) {
this.fileName = fileName;
this.fileStatus = fileStatus;
}
/*public void setFileName(String fileName) {
this.fileName = fileName;
}*/
public void setFileStatus(short fileStatus) {
this.fileStatus = fileStatus;
}

View File

@ -15,6 +15,11 @@ import org.kiwix.kiwixmobile.R;
import java.util.ArrayList;
/**
* Helper class, part of the local file sharing module.
*
* Defines the Adapter for the list of file-items displayed in {@link TransferProgressFragment}
* */
public class FileListAdapter extends RecyclerView.Adapter<FileListAdapter.FileViewHolder> {
private final ArrayList<FileItem> fileItems;
private LayoutInflater layoutInflater;

View File

@ -1,7 +1,5 @@
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@ -16,33 +14,17 @@ import org.kiwix.kiwixmobile.R;
import java.util.ArrayList;
//{@link TransferProgressFragment.OnFragmentInteractionListener} interface
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
*
* to handle interaction events.
* Use the {@link TransferProgressFragment#newInstance} factory method to
* create an instance of this fragment.
*/
* Part of the local file sharing module, this fragment is used to display the progress of the
* file transfer. It displays a list of files along with their current status (as defined in the
* {@link FileItem} class.
* */
public class TransferProgressFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private ArrayList<FileItem> fileItems;
private RecyclerView filesRecyclerView;
private FileListAdapter fileListAdapter;
//private OnFragmentInteractionListener mListener;
public TransferProgressFragment() {
// Required empty public constructor
}
@ -51,88 +33,22 @@ public class TransferProgressFragment extends Fragment {
this.fileItems = fileItems;
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment TransferProgressFragment.
*/
// TODO: Rename and change types and number of parameters
public static TransferProgressFragment newInstance(String param1, String param2) {
TransferProgressFragment fragment = new TransferProgressFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_transfer_progress, container, false);
// TODO: RECYCLERVIEW
filesRecyclerView = view.findViewById(R.id.recycler_view_transfer_files);
fileListAdapter = new FileListAdapter(getActivity(), fileItems);
filesRecyclerView.setAdapter(fileListAdapter);
filesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
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 changeStatus(int itemIndex, short status) {
fileItems.get(itemIndex).setFileStatus(status);
fileListAdapter.notifyItemChanged(itemIndex);
}
/**
* 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);
}*/
}