mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 03:54:18 -04:00
Remove extra stuff
Unnecessary comments, todos, variables, imports, methods
This commit is contained in:
parent
7759a4eb47
commit
36f563e209
@ -1,10 +1,8 @@
|
||||
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.p2p.WifiP2pDevice;
|
||||
import android.net.wifi.p2p.WifiP2pDeviceList;
|
||||
@ -12,15 +10,12 @@ import android.net.wifi.p2p.WifiP2pInfo;
|
||||
import android.net.wifi.p2p.WifiP2pManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
@ -29,22 +24,16 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
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;
|
||||
|
||||
import org.kiwix.kiwixmobile.BuildConfig;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
@ -54,18 +43,14 @@ import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
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.FileItem.TO_BE_SENT;
|
||||
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.LocalFileTransferActivity.filePath;
|
||||
|
||||
public class DeviceListFragment extends ListFragment implements WifiP2pManager.PeerListListener, WifiP2pManager.ConnectionInfoListener {
|
||||
|
||||
public static String TAG = "DeviceListFragment";
|
||||
public static final String TAG = "DeviceListFragment";
|
||||
|
||||
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||
|
||||
@ -134,8 +119,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
selectedPeerDevice = (WifiP2pDevice) getListAdapter().getItem(position);
|
||||
Toast.makeText(getActivity(), selectedPeerDevice.deviceName, Toast.LENGTH_SHORT).show();
|
||||
|
||||
// TODO: Set sender depending upon receiving file URI in activity opening intent
|
||||
//((LocalFileTransferActivity) getActivity()).setFileSender();
|
||||
// TODO: Set sender depending upon receiving file URI in activity opening intent - DONE
|
||||
((DeviceActionListener) getActivity()).connect(selectedPeerDevice);
|
||||
}
|
||||
|
||||
@ -184,7 +168,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
public void onConnectionInfoAvailable(WifiP2pInfo info) {
|
||||
groupInfo = info;
|
||||
|
||||
//TODO: Show progress of file transfer process
|
||||
//TODO: Show progress of file transfer process - DONE
|
||||
|
||||
new PeerGroupHandshakeAsyncTask(this, groupInfo).execute();
|
||||
|
||||
@ -260,34 +244,14 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
|
||||
} else if(groupInfo.groupFormed) {
|
||||
{
|
||||
//Toast.makeText(getActivity(), "Sending file to "+selectedPeerDevice.deviceAddress+"\nSelf: "+userDevice.deviceAddress, Toast.LENGTH_SHORT).show();
|
||||
Log.d(LocalFileTransferActivity.TAG, "Starting file transfer");
|
||||
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage("Transferring file")
|
||||
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
/*Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
|
||||
serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
|
||||
serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_URI, filePath.toString());//FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID+".fileprovider", new File(filePath)).toString());
|
||||
|
||||
if(groupInfo.isGroupOwner) fileReceiverAddress = selectedPeerDeviceInetAddress;
|
||||
else fileReceiverAddress = groupInfo.groupOwnerAddress;
|
||||
|
||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS, fileReceiverAddress.getHostAddress());//getIPFromMac(selectedPeerDevice.deviceAddress));
|
||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8008);
|
||||
getActivity().startService(serviceIntent);*/
|
||||
/*DeviceListFragment parent = ((DeviceListFragment) getActivity().getSupportFragmentManager().findFragmentByTag(TAG));
|
||||
if(parent != null)
|
||||
new FileSenderAsyncTask(getContext(), parent, parent.groupInfo).execute(((LocalFileTransferActivity) getActivity()).getFileURIArrayList());*/
|
||||
}
|
||||
})
|
||||
//.setNegativeButton("No", null)
|
||||
.show();
|
||||
Toast.makeText(getActivity(), "Starting file transfer", Toast.LENGTH_SHORT).show();
|
||||
|
||||
if(groupInfo.isGroupOwner) fileReceiverAddress = selectedPeerDeviceInetAddress;
|
||||
else fileReceiverAddress = groupInfo.groupOwnerAddress;
|
||||
|
||||
//TODO: Fix this
|
||||
for(int i = 0; i < 10000000; i++);
|
||||
|
||||
for(int i = 0; i < totalFiles; i++) {
|
||||
@ -332,17 +296,10 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
}
|
||||
|
||||
public interface DeviceActionListener {
|
||||
|
||||
/*void changeDeviceName(String deviceNewName);*/
|
||||
|
||||
/*void showDetails(WifiP2pDevice device);*/
|
||||
|
||||
void cancelSearch();
|
||||
|
||||
void connect(WifiP2pDevice peerDevice);
|
||||
|
||||
//void disconnect();
|
||||
|
||||
void closeLocalFileTransferActivity();
|
||||
}
|
||||
|
||||
@ -368,7 +325,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
Object object = objectInputStream.readObject();
|
||||
if (object.getClass().equals(String.class) && ((String) object).equals("Request Kiwix File Sharing")) {
|
||||
Log.d(TAG, "Client IP address: "+ client.getInetAddress());
|
||||
//selectedPeerDeviceInetAddress = client.getInetAddress();
|
||||
|
||||
if(deviceListFragment.isFileSender()) {
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(client.getOutputStream());
|
||||
@ -400,7 +356,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
return client.getInetAddress();
|
||||
|
||||
} catch (Exception e) {
|
||||
//Log.d(TAG, e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -450,13 +405,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
/*Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
|
||||
serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
|
||||
serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, Environment.getExternalStorageDirectory() + "/MainPage.txt");
|
||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS, groupInfo.groupOwnerAddress.getHostAddress());
|
||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8008);
|
||||
getActivity().startService(serviceIntent);*/
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -565,7 +513,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String s) {
|
||||
//
|
||||
deviceListFragment.incrementTotalFilesSent();
|
||||
|
||||
deviceListFragment.getActivity().runOnUiThread(new Runnable() {
|
||||
@ -588,7 +535,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
private DeviceListFragment deviceListFragment;
|
||||
private TransferProgressFragment transferProgressFragment;
|
||||
private int fileItemIndex;
|
||||
//private View statusView
|
||||
|
||||
public FileServerAsyncTask(Context context, DeviceListFragment deviceListFragment, TransferProgressFragment transferProgressFragment) {
|
||||
this.context = context;
|
||||
@ -660,13 +606,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
Log.d(LocalFileTransferActivity.TAG, "File transfer complete");
|
||||
((LocalFileTransferActivity) deviceListFragment.getActivity()).closeLocalFileTransferActivity();
|
||||
|
||||
/*File recvFile = new File(filePath);
|
||||
Uri fileUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID+".fileprovider",recvFile);
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(fileUri, "text/plain");
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
context.startActivity(intent);*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -689,7 +628,4 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
return true;
|
||||
}
|
||||
|
||||
/*public interface UpdateProgressCallback {
|
||||
public void changeStatus(int itemIndex, short status);
|
||||
}*/
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import android.net.wifi.p2p.WifiP2pDevice;
|
||||
import android.net.wifi.p2p.WifiP2pManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
@ -38,7 +37,6 @@ import org.kiwix.kiwixmobile.KiwixApplication;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -46,12 +44,11 @@ import javax.inject.Inject;
|
||||
public class LocalFileTransferActivity extends AppCompatActivity implements WifiP2pManager.ChannelListener, DeviceListFragment.DeviceActionListener {
|
||||
|
||||
/*TODO
|
||||
* - Fix activity closure upon file transfer (successful or otherwise)
|
||||
* - Fix activity closure upon file transfer (successful or otherwise) - DONE
|
||||
* - Handle multiple selected files - DONE
|
||||
* */
|
||||
|
||||
public static final String TAG = "LocalFileTransferActvty"; // Not a typo, Tags have a length upper limit of 25 characters
|
||||
public static Uri filePath = null; // = Environment.getExternalStorageDirectory() + "/Kiwix/temp.txt";///psiram_en_all_2018-09.zim";//Notes/Granblue Fantasy Wiki/Main Page.txt";
|
||||
public static final String TAG = "LocalFileTransferActvty"; // Not a typo, 'Log' tags have a length upper limit of 25 characters
|
||||
private final int PERMISSION_REQUEST_CODE_COARSE_LOCATION = 1;
|
||||
|
||||
@Inject
|
||||
@ -67,7 +64,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
private WifiP2pManager.Channel channel;
|
||||
private BroadcastReceiver receiver = null;
|
||||
private Boolean fileSendingDevice = false; // True if intent has file uri
|
||||
// TODO: Set to true if activity opening intent has the file URI
|
||||
// TODO: Set to true if activity opening intent has the file URI- DONE
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -76,34 +73,17 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes
|
||||
KiwixApplication.getApplicationComponent().inject(this);
|
||||
|
||||
/*setContentView(R.layout.activity_local_file_transfer);
|
||||
|
||||
TextView fileUriListView = findViewById(R.id.text_view_file_uris);
|
||||
|
||||
Intent filesIntent = getIntent();
|
||||
ArrayList<Uri> fileURIArrayList = filesIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
|
||||
String uriList = "Selected File URIs:\n\n";
|
||||
if(fileURIArrayList != null && fileURIArrayList.size() > 0) {
|
||||
for(int i = 0; i < fileURIArrayList.size(); i++) {
|
||||
uriList += fileURIArrayList.get(i) + "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
fileUriListView.setText(uriList);*/
|
||||
|
||||
Intent filesIntent = getIntent();
|
||||
fileURIArrayList = filesIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
|
||||
if(fileURIArrayList != null && fileURIArrayList.size() > 0) {
|
||||
//filePath = fileURIArrayList.get(0);
|
||||
setFileSender();
|
||||
}
|
||||
|
||||
Toolbar actionBar = findViewById(R.id.toolbar_local_file_transfer);
|
||||
setSupportActionBar(actionBar);
|
||||
//TODO: Fix this text colour
|
||||
actionBar.setTitle("Local ZIM file transfer");
|
||||
// TODO: Fix this drawable file/colour & text colour
|
||||
// TODO: Fix this drawable file/colour - DONE
|
||||
actionBar.setNavigationIcon(R.drawable.ic_close_white_24dp);
|
||||
actionBar.setNavigationOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
@ -118,11 +98,11 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
||||
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
||||
|
||||
//TODO: Start WiFi
|
||||
//TODO: Start WiFi - DONE through permissions
|
||||
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
|
||||
channel = manager.initialize(this, getMainLooper(), null);
|
||||
|
||||
// TODO: Add manager.removeGroup(channel, null); to remove previous groups
|
||||
// TODO: !!!!!!!!!!!Add manager.removeGroup(channel, null); to remove previous groups
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
@ -210,9 +190,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
return true;
|
||||
} else if(item.getItemId() == R.id.menu_item_cancel_search) {
|
||||
if(manager != null) {
|
||||
// TODO: 'cancelDisconnect', for removing incorrect connections
|
||||
//removeGroupDetails();
|
||||
//disconnect();
|
||||
// TODO: 'cancelDisconnect', for removing incorrect connections - DONE thru cancelSearch
|
||||
cancelSearch();
|
||||
}
|
||||
|
||||
@ -224,29 +202,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
}
|
||||
}
|
||||
|
||||
private void removeGroupDetails() {
|
||||
try {
|
||||
Method deletePersistentGroup = manager.getClass().getMethod("deletePersistentGroup", WifiP2pManager.Channel.class, int.class, WifiP2pManager.ActionListener.class);
|
||||
for(int netId = 0; netId < 32; netId++) {
|
||||
deletePersistentGroup.invoke(manager, channel, netId, new WifiP2pManager.ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Log.d(TAG, "WiFi Direct Group successfully deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
Log.d(TAG, "Group deletion failed: "+getErrorMessage(reason));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.d(TAG, "Error removing group details: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLocationServicesEnabled() {
|
||||
LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
boolean gps_enabled = false;
|
||||
@ -260,11 +215,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
} catch(Exception ex) {ex.printStackTrace();}
|
||||
|
||||
/*if(!gps_enabled && !network_enabled) {
|
||||
// notify user
|
||||
|
||||
}*/
|
||||
|
||||
return (gps_enabled || network_enabled);
|
||||
}
|
||||
|
||||
@ -311,23 +261,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
|
||||
private void requestEnableWifiP2pServices() {
|
||||
|
||||
/*new AlertDialog.Builder(this)
|
||||
.setMessage("Enable WiFi P2P from system settings")
|
||||
.setPositiveButton("Open WiFi Settings", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
|
||||
paramDialogInterface.cancel();
|
||||
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
|
||||
}
|
||||
})
|
||||
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
})
|
||||
.show();*/
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
Fragment prev = getSupportFragmentManager().findFragmentByTag("WifiP2pDialog");
|
||||
if(prev != null) {
|
||||
@ -376,15 +309,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
||||
return;
|
||||
} else {
|
||||
/*new AlertDialog.Builder(this)
|
||||
.setMessage("Cannot discover peers without location services")
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//((MainActivity) getApplicationContext()).finish();
|
||||
}
|
||||
})
|
||||
.show();*/
|
||||
showNeutralDialog("Cannot discover peers without location services");
|
||||
//TODO: Close activity
|
||||
}
|
||||
@ -527,11 +451,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
fileSendingDevice = true;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void showDetails(WifiP2pDevice device) {
|
||||
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void cancelSearch() {
|
||||
|
||||
@ -578,7 +497,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
/*else
|
||||
config.groupOwnerIntent = 15;*/
|
||||
|
||||
//TODO: Show a progress bar between starting & completion of connection
|
||||
//TODO: Show a progress bar between starting & completion of connection - DONE
|
||||
|
||||
manager.connect(channel, config, new WifiP2pManager.ActionListener() {
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user