mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 12:42:56 -04:00
Refactor & Documentation
TransferProgressFragment, FileItem & FileListAdapter
This commit is contained in:
parent
f9103e2d5a
commit
ff6768cbaa
@ -1,23 +1,24 @@
|
|||||||
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
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 class FileItem {
|
||||||
public static final short TO_BE_SENT = -1;
|
public static final short TO_BE_SENT = -1; // File yet to be sent
|
||||||
public static final short SENDING = 0;
|
public static final short SENDING = 0; // Being sent
|
||||||
public static final short SENT = +1;
|
public static final short SENT = +1; // Successfully sent
|
||||||
public static final short ERROR = +2;
|
public static final short ERROR = +2; // Error encountered while transferring the file
|
||||||
|
|
||||||
private String fileName = "";
|
private String fileName;
|
||||||
private short fileStatus = TO_BE_SENT;
|
private short fileStatus;
|
||||||
|
|
||||||
public FileItem(String fileName, short fileStatus) {
|
public FileItem(String fileName, short fileStatus) {
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
this.fileStatus = fileStatus;
|
this.fileStatus = fileStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void setFileName(String fileName) {
|
|
||||||
this.fileName = fileName;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void setFileStatus(short fileStatus) {
|
public void setFileStatus(short fileStatus) {
|
||||||
this.fileStatus = fileStatus;
|
this.fileStatus = fileStatus;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,11 @@ import org.kiwix.kiwixmobile.R;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
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> {
|
public class FileListAdapter extends RecyclerView.Adapter<FileListAdapter.FileViewHolder> {
|
||||||
private final ArrayList<FileItem> fileItems;
|
private final ArrayList<FileItem> fileItems;
|
||||||
private LayoutInflater layoutInflater;
|
private LayoutInflater layoutInflater;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
@ -16,33 +14,17 @@ import org.kiwix.kiwixmobile.R;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
//{@link TransferProgressFragment.OnFragmentInteractionListener} interface
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* Part of the local file sharing module, this fragment is used to display the progress of the
|
||||||
* Activities that contain this fragment must implement the
|
* file transfer. It displays a list of files along with their current status (as defined in the
|
||||||
*
|
* {@link FileItem} class.
|
||||||
* to handle interaction events.
|
* */
|
||||||
* Use the {@link TransferProgressFragment#newInstance} factory method to
|
|
||||||
* create an instance of this fragment.
|
|
||||||
*/
|
|
||||||
public class TransferProgressFragment extends Fragment {
|
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 ArrayList<FileItem> fileItems;
|
||||||
private RecyclerView filesRecyclerView;
|
private RecyclerView filesRecyclerView;
|
||||||
private FileListAdapter fileListAdapter;
|
private FileListAdapter fileListAdapter;
|
||||||
|
|
||||||
//private OnFragmentInteractionListener mListener;
|
|
||||||
|
|
||||||
public TransferProgressFragment() {
|
public TransferProgressFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
@ -51,88 +33,22 @@ public class TransferProgressFragment extends Fragment {
|
|||||||
this.fileItems = fileItems;
|
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
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, 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
|
|
||||||
View view = inflater.inflate(R.layout.fragment_transfer_progress, container, false);
|
View view = inflater.inflate(R.layout.fragment_transfer_progress, container, false);
|
||||||
// TODO: RECYCLERVIEW
|
|
||||||
filesRecyclerView = view.findViewById(R.id.recycler_view_transfer_files);
|
filesRecyclerView = view.findViewById(R.id.recycler_view_transfer_files);
|
||||||
|
|
||||||
fileListAdapter = new FileListAdapter(getActivity(), fileItems);
|
fileListAdapter = new FileListAdapter(getActivity(), fileItems);
|
||||||
filesRecyclerView.setAdapter(fileListAdapter);
|
filesRecyclerView.setAdapter(fileListAdapter);
|
||||||
|
|
||||||
filesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
filesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
|
|
||||||
return view;
|
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) {
|
public void changeStatus(int itemIndex, short status) {
|
||||||
fileItems.get(itemIndex).setFileStatus(status);
|
fileItems.get(itemIndex).setFileStatus(status);
|
||||||
fileListAdapter.notifyItemChanged(itemIndex);
|
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);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user