Skip to content

Commit

Permalink
Initial librarian usage
Browse files Browse the repository at this point in the history
  • Loading branch information
a-pavlov committed Feb 17, 2022
1 parent 41bc919 commit 40c4b40
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 13 deletions.
4 changes: 2 additions & 2 deletions android/jdonkey/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.dkf.jmule"
android:installLocation="auto"
android:versionCode="32"
android:versionName="32">
android:versionCode="33"
android:versionName="33">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Expand Down
17 changes: 9 additions & 8 deletions android/jdonkey/src/main/java/org/dkf/jmule/AndroidPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,23 @@ public static String getRelativeFolderPath(File f) {
String fileTypeSubfolder = AndroidPaths.getFileTypeExternalRelativeFolderName(fileType);

// "Music/FrostWire"
String mediaStoreFolderPrefix = fileTypeSubfolder + "/FrostWire";
String mediaStoreFolderPrefix = fileTypeSubfolder + "/JED2K";
mediaStoreFolderPrefix = mediaStoreFolderPrefix.replace("//","/");
return mediaStoreFolderPrefix;

String fullOriginalFilePath = f.getAbsolutePath();
//String fullOriginalFilePath = f.getAbsolutePath();

// BTEngine.ctx.dataDir -> /storage/emulated/0/Android/data/com.frostwire.android/files/FrostWire/TorrentData
// Let's remove this from the fullOriginalFilePath and we should now have only either the file name by itself
// or the torrent folders and sub-folders containing it
String removedDataPathFromFilePath = fullOriginalFilePath.replace(Platforms.data().getAbsolutePath() + "/", "");
//String removedDataPathFromFilePath = fullOriginalFilePath.replace(Platforms.data().getAbsolutePath() + "/", "");

// Single file download, not contained by folders or sub-folders
if (removedDataPathFromFilePath.equals(f.getName())) {
return mediaStoreFolderPrefix;
}
//if (removedDataPathFromFilePath.equals(f.getName())) {
// return mediaStoreFolderPrefix;
//}

String fileFoldersWithoutDataPath = removedDataPathFromFilePath.replace(f.getName(), "");
return (mediaStoreFolderPrefix + "/" + fileFoldersWithoutDataPath).replace("//","/");
//String fileFoldersWithoutDataPath = removedDataPathFromFilePath.replace(f.getName(), "");
//return (mediaStoreFolderPrefix + "/" + fileFoldersWithoutDataPath).replace("//","/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private void load() {
defaultValues.put(Constants.PREF_KEY_GUI_SHOW_NEW_TRANSFER_DIALOG, true);
defaultValues.put(Constants.PREF_KEY_GUI_SAFE_MODE, true);
defaultValues.put(Constants.PREF_KEY_GUI_ALERTED_SAFE_MODE, false);
defaultValues.put(Constants.PREF_KEY_GUI_SHARE_MEDIA_DOWNLOADS, true);

defaultValues.put(Constants.PREF_KEY_SEARCH_COUNT_DOWNLOAD_FOR_TORRENT_DEEP_SCAN, 20);
defaultValues.put(Constants.PREF_KEY_SEARCH_COUNT_ROUNDS_FOR_TORRENT_DEEP_SCAN, 10);
Expand Down
1 change: 1 addition & 0 deletions android/jdonkey/src/main/java/org/dkf/jmule/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private Constants() {
public static final String PREF_KEY_GUI_SHOW_NEW_TRANSFER_DIALOG = "jmule.prefs.gui.show_new_transfer_dialog";
public static final String PREF_KEY_GUI_SAFE_MODE = "jmule.prefs.gui.safe_mode";
public static final String PREF_KEY_GUI_ALERTED_SAFE_MODE = "jmule.prefs.gui.alerted.safe_mode";
public static final String PREF_KEY_GUI_SHARE_MEDIA_DOWNLOADS = "jmule.prefs.gui.share_media_downloads";

// ed2k common and servers
public static final String PREF_KEY_USER_AGENT = "jmule.prefs.user_agent";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public boolean write(File file, byte[] data) {

@Override
public void scan(File file) {
// LOG.warn("Scan of file not implemented");
LOG.warn("Default filesystem: Scan of file is not implemented");
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions android/jdonkey/src/main/java/org/dkf/jmule/ED2KService.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@ public void run() {
createTransferNotification(getResources().getString(R.string.transfer_finished), EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION, ((TransferFinishedAlert) a).hash);
}
});

if (ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_GUI_SHARE_MEDIA_DOWNLOADS)) {
log.info("[ED2K service] publish completed transfer");
TransferHandle handle = session.findTransfer(((TransferFinishedAlert) a).hash);
if (handle.isValid()) {
Platforms.fileSystem().scan(handle.getFile());
}
}
} else if (a instanceof TransferDiskIOErrorAlert) {
TransferDiskIOErrorAlert errorAlert = (TransferDiskIOErrorAlert) a;
log.error("[ED2K service] disk i/o error: {}", errorAlert.ec);
Expand Down
9 changes: 7 additions & 2 deletions android/jdonkey/src/main/java/org/dkf/jmule/Librarian.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ private void mediaStoreInsert(Context context, File srcFile) {
if (srcFile.isDirectory()) {
return;
}

Uri audioUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

// Add to MediaStore
Expand Down Expand Up @@ -567,6 +568,7 @@ private void mediaStoreInsert(Context context, File srcFile) {
}

values.put(MediaColumns.DISPLAY_NAME, srcFile.getName());
values.put(MediaColumns.TITLE, srcFile.getName());
values.put(MediaColumns.MIME_TYPE, MimeDetector.getMimeType(FilenameUtils.getExtension(srcFile.getName())));
values.put(MediaColumns.DATE_ADDED, System.currentTimeMillis() / 1000);
values.put(MediaColumns.DATE_MODIFIED, System.currentTimeMillis() / 1000);
Expand All @@ -584,6 +586,9 @@ private void mediaStoreInsert(Context context, File srcFile) {
} else {
values.put(MediaColumns.TITLE, srcFile.getName());
}

LOG.info("DISPLAY_NAME: {} TITLE {}", values.get(MediaColumns.DISPLAY_NAME), values.get(MediaColumns.TITLE));

Uri insertedUri = resolver.insert(mediaStoreCollectionUri, values);
if (insertedUri == null) {
LOG.error("mediaStoreInsert -> could not perform media store insertion");
Expand All @@ -601,8 +606,8 @@ private boolean alreadyInMediaStore(Context context, TableFetcher fetcher, final
// let's fix our relativePath search to be only from "com.frostwire.android/..."
String normalizedRelativePath = relativeFolderPath;

if (normalizedRelativePath.contains("com.frostwire.android")) {
normalizedRelativePath = relativeFolderPath.substring(relativeFolderPath.indexOf("com.frostwire.android"));
if (normalizedRelativePath.contains("org.dkf.jmule")) {
normalizedRelativePath = relativeFolderPath.substring(relativeFolderPath.indexOf("org.dkf.jmule"));
}

String normalizedDisplayName = displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private void setupComponents() {
setupOtherOptions();
setupTransferOptions();
useWordsFilterCheckbox();
shareMediaDownloadsCheckbox();
}

private void setupTransferOptions() {
Expand Down Expand Up @@ -341,6 +342,18 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
}

private void shareMediaDownloadsCheckbox() {
final CheckBoxPreference shareMediaDownloads = (CheckBoxPreference) findPreference(Constants.PREF_KEY_GUI_SHARE_MEDIA_DOWNLOADS);
if (shareMediaDownloads != null) {
shareMediaDownloads.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
});
}
}

private void setupStorageOption() {
// intentional repetition of preference value here
String kitkatKey = "jmule.prefs.storage.path";
Expand Down
2 changes: 2 additions & 0 deletions android/jdonkey/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
<string name="mule_start_engine_service_security_exception">Mule no pudo iniciarse correctamente por falta de permisos. Por favor ceda los permisos necesarios y reinicie la aplicación</string>
<string name="safe_mode">Modo seguro</string>
<string name="safe_mode_summary">Al desactivar este cheque, usted acepta recibir todos los resultados de la consulta. De lo contrario, los resultados se filtrarán</string>
<string name="share_media_downloads">Publicar descargas de medios</string>
<string name="share_media_downloads_summary">Compartir archivos multimedia descargados en la biblioteca multimedia de Android</string>
<string name="wizard_safe_mode">Modo seguro</string>
<string name="wizard_safe_mode_summary">Al desactivar este cheque, usted acepta recibir todos los resultados de búsqueda en la solicitud. De lo contrario, los resultados de la búsqueda se filtrarán</string>
<string name="search_forbidden_title">Buscar denegado</string>
Expand Down
2 changes: 2 additions & 0 deletions android/jdonkey/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
<string name="mule_start_engine_service_security_exception">Impossibile avviare correttamente Mule su Android a causa della mancanza di permessi. Concedere i permessi necessari e riavviare l\'applicazione</string>
<string name="safe_mode_summary">Disattivando questa casella accetti di ricevere tutti i risultati corrispondenti. In caso contrario, i risultati verranno filtrati</string>
<string name="safe_mode">Mostra tutto</string>
<string name="share_media_downloads">Pubblica download multimediali</string>
<string name="share_media_downloads_summary">Condividi i file multimediali scaricati nella libreria multimediale Android</string>
<string name="wizard_safe_mode">Mostra tutto</string>
<string name="wizard_safe_mode_summary">Disattivando questa casella accetti di ricevere tutti i risultati di ricerca corrispondenti. In caso contrario, i risultati verranno filtrati</string>
<string name="search_forbidden_title">Ricerca vietata</string>
Expand Down
2 changes: 2 additions & 0 deletions android/jdonkey/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@
<string name="mule_start_engine_service_security_exception">Mule не может запуститься из-за отсутствия разрешений. Дайте необходимые разрешения и попробуйте снова</string>
<string name="safe_mode_summary">Выключая этот чек бокс вы соглашаетесь получать все результаты соответствующие запросу. В противном случае результаты будут фильтроваться</string>
<string name="safe_mode">Безопасный режим</string>
<string name="share_media_downloads">Публиковать скачанные медиафайлы</string>
<string name="share_media_downloads_summary">Публиковать скачанные медиа файлы в медиа библиотеке Android</string>
<string name="wizard_safe_mode">Безопасный режим</string>
<string name="wizard_safe_mode_summary">Выключая этот чек бокс вы соглашаетесь получать все результаты поиска соответствующие запросу. В противном случае результаты поиска будут фильтроваться</string>
<string name="search_forbidden_title">Поиск запрещен</string>
Expand Down
2 changes: 2 additions & 0 deletions android/jdonkey/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
<string name="notify_jdonkey_is_running">Notify if Mule on Android is running</string>
<string name="notify_jdonkey_is_running_summary">Show a permanent Android notification with status of transfers</string>
<string name="safe_mode">Safe mode</string>
<string name="share_media_downloads">Share media downloads</string>
<string name="share_media_downloads_summary">Share downloaded media files in Android media library</string>
<string name="safe_mode_summary">By disabling this checkbox you agree to see any published materials having been requested. Otherwise search results will be filtered</string>
<string name="storage_picker_treeuri_null">No storage path was selected</string>
<string name="storage_picker_treeuri_not_directory">The selected path is not a directory</string>
Expand Down
6 changes: 6 additions & 0 deletions android/jdonkey/src/main/res/xml/application_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
android:summary="@string/safe_mode_summary"
android:enabled="true" />

<CheckBoxPreference
android:key="jmule.prefs.gui.share_media_downloads"
android:title="@string/share_media_downloads"
android:summary="@string/share_media_downloads_summary"
android:enabled="true" />

</PreferenceScreen>

<PreferenceCategory android:key="jmule.prefs.dht">
Expand Down

0 comments on commit 40c4b40

Please sign in to comment.