Fix issue in received image display + manually give picture bytes to liblinphone (instead of using setFileTransferFilePath) + added migration code to update the sharing server url
This commit is contained in:
parent
f90327e58c
commit
48a8ea1a70
9 changed files with 70 additions and 53 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
|
android:visibility="gone"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
|
android:visibility="gone"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<ImageView
|
<ImageView
|
||||||
android:contentDescription="@string/content_description_message_status"
|
android:contentDescription="@string/content_description_message_status"
|
||||||
android:id="@+id/status"
|
android:id="@+id/status"
|
||||||
|
android:visibility="gone"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
|
android:visibility="gone"
|
||||||
android:linksClickable="true"
|
android:linksClickable="true"
|
||||||
android:autoLink="web"
|
android:autoLink="web"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
|
|
|
@ -9,12 +9,14 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
android:layout_gravity="left"
|
android:layout_gravity="left"
|
||||||
|
android:visibility="gone"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
|
android:visibility="gone"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right"
|
||||||
|
android:visibility="gone"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:linksClickable="true"
|
android:linksClickable="true"
|
||||||
android:autoLink="web"
|
android:autoLink="web"
|
||||||
|
@ -17,6 +18,7 @@
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
|
android:visibility="gone"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -12,7 +12,7 @@ keepalive_period=30000
|
||||||
size=vga
|
size=vga
|
||||||
|
|
||||||
[app]
|
[app]
|
||||||
sharing_server=https://www.linphone.org:444/upload.php
|
sharing_server=https://www.linphone.org:444/lft.php
|
||||||
tunnel=disabled
|
tunnel=disabled
|
||||||
|
|
||||||
[tunnel]
|
[tunnel]
|
||||||
|
|
|
@ -18,6 +18,7 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -104,6 +105,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
private ByteArrayOutputStream mDownloadedImageStream;
|
private ByteArrayOutputStream mDownloadedImageStream;
|
||||||
|
private ByteArrayInputStream mUploadingImageStream;
|
||||||
private int mDownloadedImageStreamSize;
|
private int mDownloadedImageStreamSize;
|
||||||
private LinphoneChatMessage currentMessageInFileTransferUploadState;
|
private LinphoneChatMessage currentMessageInFileTransferUploadState;
|
||||||
|
|
||||||
|
@ -498,13 +500,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||||
byte[] byteArray = stream.toByteArray();
|
byte[] byteArray = stream.toByteArray();
|
||||||
|
mUploadingImageStream = new ByteArrayInputStream(byteArray);
|
||||||
|
|
||||||
LinphoneContent content = LinphoneCoreFactory.instance().createLinphoneContent("image", "jpeg", byteArray, null);
|
LinphoneContent content = LinphoneCoreFactory.instance().createLinphoneContent("image", "jpeg", byteArray, null);
|
||||||
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
||||||
content.setName(fileName);
|
content.setName(fileName);
|
||||||
|
|
||||||
LinphoneChatMessage message = chatRoom.createFileTransferMessage(content);
|
LinphoneChatMessage message = chatRoom.createFileTransferMessage(content);
|
||||||
message.setFileTransferFilepath(path);
|
|
||||||
message.setListener(this);
|
message.setListener(this);
|
||||||
message.setAppData(path);
|
message.setAppData(path);
|
||||||
|
|
||||||
|
@ -630,20 +632,26 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == State.FileTransferDone && mDownloadedImageStream != null) {
|
if (state == State.FileTransferDone) {
|
||||||
byte[] bytes = mDownloadedImageStream.toByteArray();
|
if (mDownloadedImageStream != null) {
|
||||||
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, mDownloadedImageStreamSize);
|
byte[] bytes = mDownloadedImageStream.toByteArray();
|
||||||
|
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, mDownloadedImageStreamSize);
|
||||||
|
|
||||||
String path = msg.getExternalBodyUrl();
|
String path = msg.getExternalBodyUrl();
|
||||||
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
||||||
String url = MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), bm, fileName, null);
|
String url = MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), bm, fileName, null);
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
msg.setAppData(url);
|
msg.setAppData(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
mDownloadedImageStream = null;
|
||||||
|
mDownloadedImageStreamSize = 0;
|
||||||
|
} else if (mUploadingImageStream != null) {
|
||||||
|
mUploadingImageStream = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mDownloadedImageStream = null;
|
if (state == State.FileTransferDone || state == State.FileTransferError) {
|
||||||
mDownloadedImageStreamSize = 0;
|
|
||||||
} else if (state == State.FileTransferDone || state == State.FileTransferError) {
|
|
||||||
uploadLayout.setVisibility(View.GONE);
|
uploadLayout.setVisibility(View.GONE);
|
||||||
textLayout.setVisibility(View.VISIBLE);
|
textLayout.setVisibility(View.VISIBLE);
|
||||||
progressBar.setProgress(0);
|
progressBar.setProgress(0);
|
||||||
|
@ -671,7 +679,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLinphoneChatMessageFileTransferSent(LinphoneChatMessage msg, LinphoneContent content, int offset, int size, LinphoneBuffer bufferToFill) {
|
public void onLinphoneChatMessageFileTransferSent(LinphoneChatMessage msg, LinphoneContent content, int offset, int size, LinphoneBuffer bufferToFill) {
|
||||||
|
if (mUploadingImageStream != null && size > 0) {
|
||||||
|
byte[] data = new byte[size];
|
||||||
|
int read = mUploadingImageStream.read(data, 0, size);
|
||||||
|
bufferToFill.setContent(data);
|
||||||
|
bufferToFill.setSize(read);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -484,6 +484,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
|
|
||||||
PreferencesMigrator prefMigrator = new PreferencesMigrator(mServiceContext);
|
PreferencesMigrator prefMigrator = new PreferencesMigrator(mServiceContext);
|
||||||
prefMigrator.migrateRemoteProvisioningUriIfNeeded();
|
prefMigrator.migrateRemoteProvisioningUriIfNeeded();
|
||||||
|
prefMigrator.migrateSharingServerUrlIfNeeded();
|
||||||
|
|
||||||
if (prefMigrator.isMigrationNeeded()) {
|
if (prefMigrator.isMigrationNeeded()) {
|
||||||
prefMigrator.doMigration();
|
prefMigrator.doMigration();
|
||||||
|
|
|
@ -103,6 +103,14 @@ public class PreferencesMigrator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void migrateSharingServerUrlIfNeeded() {
|
||||||
|
String currentUrl = mNewPrefs.getConfig().getString("app", "sharing_server", null);
|
||||||
|
if (currentUrl == null || currentUrl.equals("https://www.linphone.org:444/upload.php")) {
|
||||||
|
mNewPrefs.setSharingPictureServerUrl("https://www.linphone.org:444/lft.php");
|
||||||
|
mNewPrefs.getConfig().sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void doAccountsMigration() {
|
private void doAccountsMigration() {
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
lc.clearAuthInfos();
|
lc.clearAuthInfos();
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map.Entry;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.LinphoneChatMessage;
|
import org.linphone.core.LinphoneChatMessage;
|
||||||
import org.linphone.core.LinphoneChatMessage.State;
|
import org.linphone.core.LinphoneChatMessage.State;
|
||||||
|
import org.linphone.core.LinphoneContent;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
@ -135,44 +136,15 @@ public class BubbleChat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
String externalBodyUrl = message.getExternalBodyUrl();
|
||||||
if (msgView != null) {
|
LinphoneContent fileTransferContent = message.getFileTransferInformation();
|
||||||
Spanned text = null;
|
if (externalBodyUrl != null || fileTransferContent != null) {
|
||||||
String msg = message.getText();
|
|
||||||
if (msg != null) {
|
|
||||||
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
|
||||||
text = getSmiledText(context, getTextWithHttpLinks(msg));
|
|
||||||
} else {
|
|
||||||
text = getTextWithHttpLinks(msg);
|
|
||||||
}
|
|
||||||
msgView.setText(text);
|
|
||||||
msgView.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
msgView.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
msgView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.getExternalBodyUrl() != null || message.getFileTransferInformation() != null) {
|
|
||||||
if (message.getAppData() == null) {
|
|
||||||
String appData = null;
|
|
||||||
if (message.getExternalBodyUrl() != null) {
|
|
||||||
appData = message.getExternalBodyUrl();
|
|
||||||
} else if (message.getFileTransferInformation() != null) {
|
|
||||||
appData = message.getFileTransferInformation().getDataAsString();
|
|
||||||
}
|
|
||||||
message.setAppData(appData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String appData = message.getAppData();
|
|
||||||
if (appData != null) {
|
|
||||||
Button download = (Button) layout.findViewById(R.id.download);
|
Button download = (Button) layout.findViewById(R.id.download);
|
||||||
ImageView imageView = (ImageView) layout.findViewById(R.id.image);
|
ImageView imageView = (ImageView) layout.findViewById(R.id.image);
|
||||||
|
|
||||||
if (appData.startsWith("http")) {
|
String appData = message.getAppData();
|
||||||
|
if (appData == null) {
|
||||||
download.setVisibility(View.VISIBLE);
|
download.setVisibility(View.VISIBLE);
|
||||||
imageView.setVisibility(View.GONE);
|
|
||||||
download.setOnClickListener(new OnClickListener() {
|
download.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -186,7 +158,6 @@ public class BubbleChat {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
download.setVisibility(View.GONE);
|
|
||||||
imageView.setVisibility(View.VISIBLE);
|
imageView.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
|
@ -216,6 +187,22 @@ public class BubbleChat {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
||||||
|
if (msgView != null) {
|
||||||
|
Spanned text = null;
|
||||||
|
String msg = message.getText();
|
||||||
|
if (msg != null) {
|
||||||
|
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
||||||
|
text = getSmiledText(context, getTextWithHttpLinks(msg));
|
||||||
|
} else {
|
||||||
|
text = getTextWithHttpLinks(msg);
|
||||||
|
}
|
||||||
|
msgView.setText(text);
|
||||||
|
msgView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
msgView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView timeView = (TextView) layout.findViewById(R.id.time);
|
TextView timeView = (TextView) layout.findViewById(R.id.time);
|
||||||
|
|
Loading…
Reference in a new issue