mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Increment: Transferred files now saved in the user-preference 'Kiwix' folder
Location obtained from the SharedPreferenceUtil
This commit is contained in:
parent
2066db6bd9
commit
d3704e8f9f
@ -33,6 +33,7 @@ import org.kiwix.kiwixmobile.search.AutoCompleteAdapter;
|
||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.zim_manager.local_file_transfer.LocalFileTransferActivity;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
@ -61,4 +62,6 @@ public interface ApplicationComponent {
|
||||
void inject(KiwixSettingsActivity.PrefsFragment prefsFragment);
|
||||
|
||||
void inject(AutoCompleteAdapter autoCompleteAdapter);
|
||||
|
||||
void inject(LocalFileTransferActivity localFileTransferActivity);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ 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;
|
||||
@ -63,6 +64,8 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
|
||||
public static String TAG = "DeviceListFragment";
|
||||
|
||||
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||
|
||||
private View fragRootView = null;
|
||||
private List<WifiP2pDevice> peerDevices = new ArrayList<WifiP2pDevice>();
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
public void setClientAddress(InetAddress clientAddress) {
|
||||
if(clientAddress != null) selectedPeerDeviceInetAddress = clientAddress;
|
||||
|
||||
@ -244,6 +246,14 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
return (totalFilesSent == totalFiles);
|
||||
}
|
||||
|
||||
public void setSharedPreferenceUtil(SharedPreferenceUtil sharedPreferenceUtil) {
|
||||
this.sharedPreferenceUtil = sharedPreferenceUtil;
|
||||
}
|
||||
|
||||
public String getZimStorageRootPath() {
|
||||
return (sharedPreferenceUtil.getPrefStorage() + "/Kiwix/");
|
||||
}
|
||||
|
||||
private void startFileTransfer() {
|
||||
if(groupInfo.groupFormed && !fileSender) {
|
||||
new FileServerAsyncTask(getActivity(), this).execute();
|
||||
@ -594,6 +604,8 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
ServerSocket serverSocket = new ServerSocket(FILE_TRANSFER_PORT);
|
||||
Log.d(LocalFileTransferActivity.TAG, "Server: Socket opened at " + FILE_TRANSFER_PORT);
|
||||
|
||||
final String KIWIX_ROOT = deviceListFragment.getZimStorageRootPath();
|
||||
|
||||
int totalFileCount = deviceListFragment.getTotalFiles();
|
||||
for(int currentFile = 1; currentFile <= totalFileCount; currentFile++) {
|
||||
Socket client = serverSocket.accept();
|
||||
@ -602,10 +614,8 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
ArrayList<String> fileNames = deviceListFragment.getFileNames();
|
||||
String incomingFileName = fileNames.get(currentFile-1);
|
||||
|
||||
// File selector, file not exists,
|
||||
//TODO: Change to appropriate file-path
|
||||
// Save in the Kiwix app folder
|
||||
final File clientNoteFileLocation = new File(Environment.getExternalStorageDirectory() + "/KiwixWifi/"+incomingFileName);
|
||||
// TODO:? File selector, file not exists,
|
||||
final File clientNoteFileLocation = new File(KIWIX_ROOT + incomingFileName);
|
||||
File dirs = new File(clientNoteFileLocation.getParent());
|
||||
if(!dirs.exists()) {
|
||||
Log.d(LocalFileTransferActivity.TAG, "Parent creation result: "+dirs.mkdirs());
|
||||
|
@ -33,11 +33,15 @@ import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
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;
|
||||
|
||||
public class LocalFileTransferActivity extends AppCompatActivity implements WifiP2pManager.ChannelListener, DeviceListFragment.DeviceActionListener {
|
||||
|
||||
/*TODO
|
||||
@ -45,10 +49,13 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
* - 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";
|
||||
private final int PERMISSION_REQUEST_CODE_COARSE_LOCATION = 1;
|
||||
|
||||
@Inject
|
||||
SharedPreferenceUtil sharedPreferenceUtil;
|
||||
|
||||
private boolean isWifiP2pEnabled = false;
|
||||
private boolean retryChannel = false;
|
||||
|
||||
@ -66,6 +73,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_local_file_transfer);
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes
|
||||
KiwixApplication.getApplicationComponent().inject(this);
|
||||
|
||||
/*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);
|
||||
deviceListFragment.onInitiateDiscovery();
|
||||
deviceListFragment.setSharedPreferenceUtil(sharedPreferenceUtil);
|
||||
manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user