mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-24 05:04:50 -04:00
Refactor: Use static factory method for TransferProgressFragment
This commit is contained in:
parent
ab9f9368f3
commit
fc814159e7
@ -143,7 +143,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void displayTransferProgressFragment() {
|
private void displayTransferProgressFragment() {
|
||||||
transferProgressFragment = new TransferProgressFragment(filesToSend);
|
transferProgressFragment = TransferProgressFragment.newInstance(filesToSend);
|
||||||
FragmentManager fragmentManager = localFileTransferActivity.getSupportFragmentManager();
|
FragmentManager fragmentManager = localFileTransferActivity.getSupportFragmentManager();
|
||||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
fragmentTransaction.add(R.id.container_fragment_transfer_progress, transferProgressFragment)
|
fragmentTransaction.add(R.id.container_fragment_transfer_progress, transferProgressFragment)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -12,7 +14,8 @@ import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.FileItem.Fil
|
|||||||
*
|
*
|
||||||
* Defines a file-item to represent the files being transferred.
|
* Defines a file-item to represent the files being transferred.
|
||||||
* */
|
* */
|
||||||
public class FileItem {
|
public class FileItem implements Parcelable {
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef({TO_BE_SENT, SENDING, SENT, ERROR})
|
@IntDef({TO_BE_SENT, SENDING, SENT, ERROR})
|
||||||
public @interface FileStatus {
|
public @interface FileStatus {
|
||||||
@ -30,6 +33,38 @@ public class FileItem {
|
|||||||
this.fileStatus = fileStatus;
|
this.fileStatus = fileStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For making FileItem a Parcelable
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(fileName);
|
||||||
|
dest.writeInt(fileStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<FileItem> CREATOR
|
||||||
|
= new Parcelable.Creator<FileItem>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileItem createFromParcel(Parcel source) {
|
||||||
|
return (new FileItem(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileItem[] newArray(int size) {
|
||||||
|
return new FileItem[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public FileItem(Parcel parcel) {
|
||||||
|
this.fileName = parcel.readString();
|
||||||
|
this.fileStatus = parcel.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper methods
|
||||||
public void setFileStatus(@FileStatus int fileStatus) {
|
public void setFileStatus(@FileStatus int fileStatus) {
|
||||||
this.fileStatus = fileStatus;
|
this.fileStatus = fileStatus;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
@ -34,8 +35,19 @@ public class TransferProgressFragment extends Fragment {
|
|||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransferProgressFragment(ArrayList<FileItem> fileItems) {
|
public static TransferProgressFragment newInstance(ArrayList<FileItem> fileItems) {
|
||||||
this.fileItems = fileItems;
|
TransferProgressFragment fragment = new TransferProgressFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelableArrayList("FILE_ITEMS", fileItems);
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Bundle bundle = this.getArguments();
|
||||||
|
this.fileItems = bundle.getParcelableArrayList("FILE_ITEMS");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user