Added setting to let user choose if downloaded images in non ephemeral messages should be made visible in native gallery
This commit is contained in:
parent
eef14a847b
commit
287d1535f0
5 changed files with 62 additions and 2 deletions
|
@ -19,7 +19,9 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.chat;
|
package org.linphone.chat;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -34,8 +36,11 @@ import org.linphone.contacts.LinphoneContact;
|
||||||
import org.linphone.core.Address;
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.ChatMessage;
|
import org.linphone.core.ChatMessage;
|
||||||
import org.linphone.core.ChatMessageListenerStub;
|
import org.linphone.core.ChatMessageListenerStub;
|
||||||
|
import org.linphone.core.Content;
|
||||||
import org.linphone.core.EventLog;
|
import org.linphone.core.EventLog;
|
||||||
import org.linphone.core.tools.Log;
|
import org.linphone.core.tools.Log;
|
||||||
|
import org.linphone.settings.LinphonePreferences;
|
||||||
|
import org.linphone.utils.FileUtils;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
import org.linphone.utils.LinphoneUtils;
|
||||||
import org.linphone.utils.SelectableAdapter;
|
import org.linphone.utils.SelectableAdapter;
|
||||||
import org.linphone.utils.SelectableHelper;
|
import org.linphone.utils.SelectableHelper;
|
||||||
|
@ -94,12 +99,34 @@ public class ChatMessagesAdapter extends SelectableAdapter<ChatMessageViewHolder
|
||||||
mTransientMessages.remove(message);
|
mTransientMessages.remove(message);
|
||||||
} else if (state == ChatMessage.State.FileTransferDone) {
|
} else if (state == ChatMessage.State.FileTransferDone) {
|
||||||
Log.i("[Chat Message] File transfer done");
|
Log.i("[Chat Message] File transfer done");
|
||||||
// TODO: make picture public
|
|
||||||
|
// Do not do it for ephemeral messages of if setting is disabled
|
||||||
|
if (!message.isEphemeral()
|
||||||
|
&& LinphonePreferences.instance()
|
||||||
|
.makeDownloadedImagesVisibleInNativeGallery()) {
|
||||||
|
for (Content content : message.getContents()) {
|
||||||
|
if (content.isFile() && content.getFilePath() != null) {
|
||||||
|
addImageToNativeGalery(content.getFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addImageToNativeGalery(String filePath) {
|
||||||
|
if (!FileUtils.isExtensionImage(filePath)) return;
|
||||||
|
|
||||||
|
String mime = FileUtils.getMimeFromFile(filePath);
|
||||||
|
Log.i("[Chat Message] Adding file ", filePath, " to native gallery with MIME ", mime);
|
||||||
|
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(MediaStore.Images.Media.DATA, filePath);
|
||||||
|
values.put(MediaStore.Images.Media.MIME_TYPE, mime);
|
||||||
|
mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatMessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ChatMessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(mItemResource, parent, false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(mItemResource, parent, false);
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class ChatSettingsFragment extends SettingsFragment {
|
||||||
private TextSetting mSharingServer, mMaxSizeForAutoDownloadIncomingFiles;
|
private TextSetting mSharingServer, mMaxSizeForAutoDownloadIncomingFiles;
|
||||||
private BasicSetting mAndroidNotificationSettings;
|
private BasicSetting mAndroidNotificationSettings;
|
||||||
private ListSetting mAutoDownloadIncomingFilesPolicy;
|
private ListSetting mAutoDownloadIncomingFilesPolicy;
|
||||||
private SwitchSetting mHideEmptyRooms, mHideRemovedProxiesRooms;
|
private SwitchSetting mHideEmptyRooms, mHideRemovedProxiesRooms, mMakeDownloadedImagesPublic;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,6 +75,10 @@ public class ChatSettingsFragment extends SettingsFragment {
|
||||||
|
|
||||||
mAutoDownloadIncomingFilesPolicy = mRootView.findViewById(R.id.pref_auto_download_policy);
|
mAutoDownloadIncomingFilesPolicy = mRootView.findViewById(R.id.pref_auto_download_policy);
|
||||||
|
|
||||||
|
mMakeDownloadedImagesPublic =
|
||||||
|
mRootView.findViewById(
|
||||||
|
R.id.pref_android_app_make_downloaded_images_visible_in_native_gallery);
|
||||||
|
|
||||||
mAndroidNotificationSettings = mRootView.findViewById(R.id.pref_android_app_notif_settings);
|
mAndroidNotificationSettings = mRootView.findViewById(R.id.pref_android_app_notif_settings);
|
||||||
|
|
||||||
mHideEmptyRooms = mRootView.findViewById(R.id.pref_android_app_hide_empty_chat_rooms);
|
mHideEmptyRooms = mRootView.findViewById(R.id.pref_android_app_hide_empty_chat_rooms);
|
||||||
|
@ -118,6 +122,14 @@ public class ChatSettingsFragment extends SettingsFragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mMakeDownloadedImagesPublic.setListener(
|
||||||
|
new SettingListenerBase() {
|
||||||
|
@Override
|
||||||
|
public void onBoolValueChanged(boolean newValue) {
|
||||||
|
mPrefs.setDownloadedImagesVisibleInNativeGallery(newValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mAndroidNotificationSettings.setListener(
|
mAndroidNotificationSettings.setListener(
|
||||||
new SettingListenerBase() {
|
new SettingListenerBase() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -165,6 +177,8 @@ public class ChatSettingsFragment extends SettingsFragment {
|
||||||
mAndroidNotificationSettings.setVisibility(View.GONE);
|
mAndroidNotificationSettings.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMakeDownloadedImagesPublic.setChecked(mPrefs.makeDownloadedImagesVisibleInNativeGallery());
|
||||||
|
|
||||||
mHideEmptyRooms.setChecked(LinphonePreferences.instance().hideEmptyChatRooms());
|
mHideEmptyRooms.setChecked(LinphonePreferences.instance().hideEmptyChatRooms());
|
||||||
|
|
||||||
mHideRemovedProxiesRooms.setChecked(
|
mHideRemovedProxiesRooms.setChecked(
|
||||||
|
|
|
@ -1199,6 +1199,16 @@ public class LinphonePreferences {
|
||||||
getLc().setMaxSizeForAutoDownloadIncomingFiles(size);
|
getLc().setMaxSizeForAutoDownloadIncomingFiles(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDownloadedImagesVisibleInNativeGallery(boolean visible) {
|
||||||
|
if (getConfig() == null) return;
|
||||||
|
getConfig().setBool("app", "make_downloaded_images_public_in_gallery", visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean makeDownloadedImagesVisibleInNativeGallery() {
|
||||||
|
if (getConfig() == null) return false;
|
||||||
|
return getConfig().getBool("app", "make_downloaded_images_public_in_gallery", true);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPowerSaverDialogBeenPrompted() {
|
public boolean hasPowerSaverDialogBeenPrompted() {
|
||||||
if (getConfig() == null) return false;
|
if (getConfig() == null) return false;
|
||||||
return getConfig().getBool("app", "android_power_saver_dialog", false);
|
return getConfig().getBool("app", "android_power_saver_dialog", false);
|
||||||
|
|
|
@ -34,6 +34,13 @@
|
||||||
linphone:hint="@string/pref_auto_download_max_size_title"
|
linphone:hint="@string/pref_auto_download_max_size_title"
|
||||||
linphone:title="@string/pref_auto_download_max_size_title" />
|
linphone:title="@string/pref_auto_download_max_size_title" />
|
||||||
|
|
||||||
|
<org.linphone.settings.widget.SwitchSetting
|
||||||
|
android:id="@+id/pref_android_app_make_downloaded_images_visible_in_native_gallery"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
linphone:title="@string/pref_android_app_make_downloaded_images_visible_in_native_gallery_title"
|
||||||
|
linphone:subtitle="@string/pref_android_app_make_downloaded_images_visible_in_native_gallery_desc" />
|
||||||
|
|
||||||
<org.linphone.settings.widget.BasicSetting
|
<org.linphone.settings.widget.BasicSetting
|
||||||
android:id="@+id/pref_android_app_notif_settings"
|
android:id="@+id/pref_android_app_notif_settings"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -500,6 +500,8 @@
|
||||||
<string name="pref_android_app_hide_empty_chat_rooms_title">Hide empty chat rooms</string>
|
<string name="pref_android_app_hide_empty_chat_rooms_title">Hide empty chat rooms</string>
|
||||||
<string name="pref_android_app_hide_chat_rooms_from_removed_proxies_title">Hide chat rooms from removed proxy configs</string>
|
<string name="pref_android_app_hide_chat_rooms_from_removed_proxies_title">Hide chat rooms from removed proxy configs</string>
|
||||||
<string name="pref_android_app_hide_chat_rooms_from_removed_proxies_desc">If you have missing chat rooms, try to uncheck this setting</string>
|
<string name="pref_android_app_hide_chat_rooms_from_removed_proxies_desc">If you have missing chat rooms, try to uncheck this setting</string>
|
||||||
|
<string name="pref_android_app_make_downloaded_images_visible_in_native_gallery_title">Make downloaded images visible in native gallery</string>
|
||||||
|
<string name="pref_android_app_make_downloaded_images_visible_in_native_gallery_desc">Images in ephemeral messages won\'t be</string>
|
||||||
|
|
||||||
<!-- Network settings -->
|
<!-- Network settings -->
|
||||||
<string name="pref_network_title">Network</string>
|
<string name="pref_network_title">Network</string>
|
||||||
|
|
Loading…
Reference in a new issue