Increment: Transferred files now saved in the user-preference 'Kiwix' folder

Location obtained from the SharedPreferenceUtil
This commit is contained in:
Aditya-Sood 2019-06-23 20:44:09 +05:30
parent 2066db6bd9
commit d3704e8f9f
3 changed files with 28 additions and 6 deletions

View File

@ -33,6 +33,7 @@ import org.kiwix.kiwixmobile.search.AutoCompleteAdapter;
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity; import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment; import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment;
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment; import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
import org.kiwix.kiwixmobile.zim_manager.local_file_transfer.LocalFileTransferActivity;
@Singleton @Singleton
@Component(modules = { @Component(modules = {
@ -61,4 +62,6 @@ public interface ApplicationComponent {
void inject(KiwixSettingsActivity.PrefsFragment prefsFragment); void inject(KiwixSettingsActivity.PrefsFragment prefsFragment);
void inject(AutoCompleteAdapter autoCompleteAdapter); void inject(AutoCompleteAdapter autoCompleteAdapter);
void inject(LocalFileTransferActivity localFileTransferActivity);
} }

View File

@ -37,6 +37,7 @@ import androidx.fragment.app.ListFragment;
import org.kiwix.kiwixmobile.BuildConfig; import org.kiwix.kiwixmobile.BuildConfig;
import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -63,6 +64,8 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
public static String TAG = "DeviceListFragment"; public static String TAG = "DeviceListFragment";
private SharedPreferenceUtil sharedPreferenceUtil;
private View fragRootView = null; private View fragRootView = null;
private List<WifiP2pDevice> peerDevices = new ArrayList<WifiP2pDevice>(); private List<WifiP2pDevice> peerDevices = new ArrayList<WifiP2pDevice>();
private WifiP2pDevice userDevice; private WifiP2pDevice userDevice;
@ -205,7 +208,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
// TODO: Disable onclick listener (of list) for connecting to devices // TODO: Disable onclick listener (of list) for connecting to devices
} }
public void setClientAddress(InetAddress clientAddress) { public void setClientAddress(InetAddress clientAddress) {
if(clientAddress != null) selectedPeerDeviceInetAddress = clientAddress; if(clientAddress != null) selectedPeerDeviceInetAddress = clientAddress;
@ -244,6 +246,14 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
return (totalFilesSent == totalFiles); return (totalFilesSent == totalFiles);
} }
public void setSharedPreferenceUtil(SharedPreferenceUtil sharedPreferenceUtil) {
this.sharedPreferenceUtil = sharedPreferenceUtil;
}
public String getZimStorageRootPath() {
return (sharedPreferenceUtil.getPrefStorage() + "/Kiwix/");
}
private void startFileTransfer() { private void startFileTransfer() {
if(groupInfo.groupFormed && !fileSender) { if(groupInfo.groupFormed && !fileSender) {
new FileServerAsyncTask(getActivity(), this).execute(); new FileServerAsyncTask(getActivity(), this).execute();
@ -594,6 +604,8 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
ServerSocket serverSocket = new ServerSocket(FILE_TRANSFER_PORT); ServerSocket serverSocket = new ServerSocket(FILE_TRANSFER_PORT);
Log.d(LocalFileTransferActivity.TAG, "Server: Socket opened at " + FILE_TRANSFER_PORT); Log.d(LocalFileTransferActivity.TAG, "Server: Socket opened at " + FILE_TRANSFER_PORT);
final String KIWIX_ROOT = deviceListFragment.getZimStorageRootPath();
int totalFileCount = deviceListFragment.getTotalFiles(); int totalFileCount = deviceListFragment.getTotalFiles();
for(int currentFile = 1; currentFile <= totalFileCount; currentFile++) { for(int currentFile = 1; currentFile <= totalFileCount; currentFile++) {
Socket client = serverSocket.accept(); Socket client = serverSocket.accept();
@ -602,10 +614,8 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
ArrayList<String> fileNames = deviceListFragment.getFileNames(); ArrayList<String> fileNames = deviceListFragment.getFileNames();
String incomingFileName = fileNames.get(currentFile-1); String incomingFileName = fileNames.get(currentFile-1);
// File selector, file not exists, // TODO:? File selector, file not exists,
//TODO: Change to appropriate file-path final File clientNoteFileLocation = new File(KIWIX_ROOT + incomingFileName);
// Save in the Kiwix app folder
final File clientNoteFileLocation = new File(Environment.getExternalStorageDirectory() + "/KiwixWifi/"+incomingFileName);
File dirs = new File(clientNoteFileLocation.getParent()); File dirs = new File(clientNoteFileLocation.getParent());
if(!dirs.exists()) { if(!dirs.exists()) {
Log.d(LocalFileTransferActivity.TAG, "Parent creation result: "+dirs.mkdirs()); Log.d(LocalFileTransferActivity.TAG, "Parent creation result: "+dirs.mkdirs());

View File

@ -33,11 +33,15 @@ import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import org.kiwix.kiwixmobile.KiwixApplication;
import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import javax.inject.Inject;
public class LocalFileTransferActivity extends AppCompatActivity implements WifiP2pManager.ChannelListener, DeviceListFragment.DeviceActionListener { public class LocalFileTransferActivity extends AppCompatActivity implements WifiP2pManager.ChannelListener, DeviceListFragment.DeviceActionListener {
/*TODO /*TODO
@ -45,10 +49,13 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
* - Handle multiple selected files * - Handle multiple selected files
* */ * */
public static final String TAG = "LocalFileTransferActvty"; 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 Uri filePath = null; // = Environment.getExternalStorageDirectory() + "/Kiwix/temp.txt";///psiram_en_all_2018-09.zim";//Notes/Granblue Fantasy Wiki/Main Page.txt";
private final int PERMISSION_REQUEST_CODE_COARSE_LOCATION = 1; private final int PERMISSION_REQUEST_CODE_COARSE_LOCATION = 1;
@Inject
SharedPreferenceUtil sharedPreferenceUtil;
private boolean isWifiP2pEnabled = false; private boolean isWifiP2pEnabled = false;
private boolean retryChannel = false; private boolean retryChannel = false;
@ -66,6 +73,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_local_file_transfer); setContentView(R.layout.activity_local_file_transfer);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes
KiwixApplication.getApplicationComponent().inject(this);
/*setContentView(R.layout.activity_local_file_transfer); /*setContentView(R.layout.activity_local_file_transfer);
@ -176,6 +184,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
final DeviceListFragment deviceListFragment = (DeviceListFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_device_list); final DeviceListFragment deviceListFragment = (DeviceListFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_device_list);
deviceListFragment.onInitiateDiscovery(); deviceListFragment.onInitiateDiscovery();
deviceListFragment.setSharedPreferenceUtil(sharedPreferenceUtil);
manager.discoverPeers(channel, new WifiP2pManager.ActionListener() { manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
@Override @Override
public void onSuccess() { public void onSuccess() {