mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-29 08:00:44 -04:00
Increment: After handshake, both devices display list of files being transferred
Next step - Use this list to display progress of transfer
This commit is contained in:
parent
8ba431d00a
commit
be5c377917
@ -62,6 +62,7 @@ dependencies {
|
||||
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion")
|
||||
androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
|
||||
|
@ -32,6 +32,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.fragment.app.ListFragment;
|
||||
|
||||
@ -57,6 +58,7 @@ import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.DeviceListFragment.TAG;
|
||||
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.LocalFileTransferActivity.filePath;
|
||||
|
||||
@ -81,7 +83,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
private ArrayList<Uri> fileUriList;
|
||||
private int totalFiles = -1;
|
||||
private int totalFilesSent = 0;
|
||||
private ArrayList<String> fileNames;
|
||||
private ArrayList<String> fileNames = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
@ -118,6 +120,9 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
fileSender = true;
|
||||
fileUriList = ((LocalFileTransferActivity) getActivity()).getFileURIArrayList();
|
||||
totalFiles = fileUriList.size();
|
||||
|
||||
for(int i = 0; i < fileUriList.size(); i++)
|
||||
fileNames.add(getFileName(fileUriList.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,7 +259,18 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
return (sharedPreferenceUtil.getPrefStorage() + "/Kiwix/");
|
||||
}
|
||||
|
||||
private void displayTransferProgressFragment() {
|
||||
TransferProgressFragment fragment = new TransferProgressFragment(fileNames);
|
||||
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
fragmentTransaction.add(R.id.container_fragment_transfer_progress, fragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
private void startFileTransfer() {
|
||||
|
||||
displayTransferProgressFragment();
|
||||
|
||||
if(groupInfo.groupFormed && !fileSender) {
|
||||
new FileServerAsyncTask(getActivity(), this).execute();
|
||||
Toast.makeText(getActivity(), "File receiving device", Toast.LENGTH_SHORT).show();
|
||||
@ -499,20 +515,20 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
protected void onPostExecute(InetAddress inetAddress) {
|
||||
(deviceListFragment).setClientAddress(inetAddress);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(Uri fileUri) {
|
||||
String fileName = "";
|
||||
String fileUriString = fileUri.toString();
|
||||
public static String getFileName(Uri fileUri) {
|
||||
String fileName = "";
|
||||
String fileUriString = fileUri.toString();
|
||||
|
||||
// Searches for location of last slash in the file path
|
||||
for(int loc = fileUriString.length()-1; loc >= 0; loc--) {
|
||||
if(fileUriString.charAt(loc) == '/') {
|
||||
return fileUriString.substring(loc+1);
|
||||
}
|
||||
// Searches for location of last slash in the file path
|
||||
for(int loc = fileUriString.length()-1; loc >= 0; loc--) {
|
||||
if(fileUriString.charAt(loc) == '/') {
|
||||
return fileUriString.substring(loc+1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public InetAddress getFileReceiverAddress() {
|
||||
|
@ -0,0 +1,53 @@
|
||||
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FileListAdapter extends RecyclerView.Adapter<FileListAdapter.FileViewHolder> {
|
||||
private final ArrayList<String> fileNames;
|
||||
private LayoutInflater layoutInflater;
|
||||
|
||||
public FileListAdapter(Context context, ArrayList<String> fileNames) {
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
this.fileNames = fileNames;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public FileListAdapter.FileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = layoutInflater.inflate(R.layout.item_transfer_list, parent, false);
|
||||
return new FileViewHolder(itemView, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull FileListAdapter.FileViewHolder holder, int position) {
|
||||
String name = fileNames.get(position);
|
||||
holder.fileItemView.setText(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return fileNames.size();
|
||||
}
|
||||
|
||||
class FileViewHolder extends RecyclerView.ViewHolder {
|
||||
public final TextView fileItemView;
|
||||
final FileListAdapter fileListAdapter;
|
||||
|
||||
public FileViewHolder(View itemView, FileListAdapter fileListAdapter) {
|
||||
super(itemView);
|
||||
this.fileItemView = itemView.findViewById(R.id.text_view_file_item_name);
|
||||
this.fileListAdapter = fileListAdapter;
|
||||
}
|
||||
}
|
||||
}
|
@ -518,6 +518,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this feature since reflection of hidden methods/fields is restricted from Pie (& will subsequently lead to exceptions)
|
||||
@Override
|
||||
public void changeDeviceName(String deviceNewName) {
|
||||
try {
|
||||
|
@ -0,0 +1,133 @@
|
||||
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;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
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.
|
||||
*/
|
||||
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<String> fileNames;
|
||||
private RecyclerView filesRecyclerView;
|
||||
private FileListAdapter fileListAdapter;
|
||||
|
||||
//private OnFragmentInteractionListener mListener;
|
||||
|
||||
public TransferProgressFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
public TransferProgressFragment(ArrayList<String> fileNames) {
|
||||
this.fileNames = fileNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
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(), fileNames);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}*/
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".zim_manager.local_file_transfer.LocalFileTransferActivity">>
|
||||
tools:context=".zim_manager.local_file_transfer.LocalFileTransferActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar_local_file_transfer"
|
||||
@ -27,9 +27,18 @@
|
||||
<fragment
|
||||
class="org.kiwix.kiwixmobile.zim_manager.local_file_transfer.DeviceListFragment"
|
||||
android:id="@+id/fragment_device_list"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/app_bar_local_file_transfer"
|
||||
app:layout_constraintBottom_toTopOf="@id/container_fragment_transfer_progress"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container_fragment_transfer_progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/fragment_device_list"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"/>
|
||||
|
32
app/src/main/res/layout/fragment_transfer_progress.xml
Normal file
32
app/src/main/res/layout/fragment_transfer_progress.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".zim_manager.local_file_transfer.TransferProgressFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:id="@+id/text_view_files_for_transfer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="FILES FOR TRANSFER"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="monospace"
|
||||
android:gravity="center"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/recycler_view_transfer_files"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_transfer_files"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_files_for_transfer"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
21
app/src/main/res/layout/item_transfer_list.xml
Normal file
21
app/src/main/res/layout/item_transfer_list.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view_file_item_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="File Name"
|
||||
android:textColor="#000000"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginStart="5dp"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -245,4 +245,7 @@
|
||||
<string name="switch_tabs">Switch tabs</string>
|
||||
<string name="smiling_face">:D</string>
|
||||
<string name="close_all_tabs">Close all tabs</string>
|
||||
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user