Skip to content

Commit

Permalink
Fix crash with download picture and sync account
Browse files Browse the repository at this point in the history
  • Loading branch information
Margaux Clerc committed Aug 25, 2015
1 parent c2075cc commit 97a0779
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
16 changes: 12 additions & 4 deletions src/org/linphone/ContactsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@ public void initializeContactManager(Context context, ContentResolver contentRes

public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
initializeContactManager(context,contentResolver);
Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getString(R.string.sync_account_type));
AccountManager accountManager = (AccountManager) context.getSystemService(context.ACCOUNT_SERVICE);
if(accountManager.addAccountExplicitly(newAccount, null, null)){
mAccount = newAccount;

Account[] accounts = accountManager.getAccountsByType(context.getPackageName());

if(accounts != null && accounts.length == 0) {
Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getPackageName());
try {
accountManager.addAccountExplicitly(newAccount, null, null);
mAccount = newAccount;
} catch (Exception e) {
mAccount = null;
}
} else {
mAccount = null;
mAccount = accounts[0];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/org/linphone/LinphoneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, LinphoneC
mUploadPendingFileMessage = null;
mUploadingImageStream = null;
} else {
File file = new File(Environment.getExternalStorageDirectory(), msg.getFileTransferInformation().getName());
File file = new File(Environment.getExternalStorageDirectory(), msg.getAppData());
try {
String url = MediaStore.Images.Media.insertImage(getContext().getContentResolver(), file.getPath(), msg.getFileTransferInformation().getName(), null);
String url = MediaStore.Images.Media.insertImage(getContext().getContentResolver(), file.getPath(), file.getName(), null);
msg.setAppData(url);
file.delete();
} catch (FileNotFoundException e) {
Expand Down
28 changes: 15 additions & 13 deletions src/org/linphone/ui/BubbleChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,34 +133,36 @@ public BubbleChat(final Context context, LinphoneChatMessage message) {
ImageView imageView = (ImageView) view.findViewById(R.id.image);

String appData = message.getAppData();
if (appData == null) {
if (appData == null || (! LinphoneManager.getInstance().isMessagePending(nativeMessage) && appData.contains(context.getString(R.string.temp_photo_name_with_date).split("%s")[0]))) {
LinphoneManager.addListener(this);
if(LinphoneManager.getInstance().isMessagePending(nativeMessage)){
download.setEnabled(false);
ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
spinner.setVisibility(View.VISIBLE);
download.setVisibility(View.GONE);
} else {
download.setVisibility(View.VISIBLE);
download.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.setEnabled(false);
spinner.setVisibility(View.VISIBLE);
v.setVisibility(View.GONE);

File file = new File(Environment.getExternalStorageDirectory(), nativeMessage.getFileTransferInformation().getName());
String filename = context.getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis()));
File file = new File(Environment.getExternalStorageDirectory(), filename);
nativeMessage.setListener(LinphoneManager.getInstance());
nativeMessage.setFileTransferFilepath(file.getPath());
nativeMessage.downloadFile();
nativeMessage.setAppData(filename);
LinphoneManager.getInstance().addDownloadMessagePending(nativeMessage);
}
});
}
} else {
LinphoneManager.removeListener(this);
imageView.setVisibility(View.VISIBLE);
loadBitmap(appData, imageView);
if(LinphoneManager.getInstance().isMessagePending(nativeMessage)){
LinphoneManager.addListener(this);
download.setEnabled(false);
ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
spinner.setVisibility(View.VISIBLE);
download.setVisibility(View.GONE);
} else {
LinphoneManager.removeListener(this);
imageView.setVisibility(View.VISIBLE);
loadBitmap(appData, imageView);
}
}
} else {
TextView msgView = (TextView) view.findViewById(R.id.message);
Expand Down

0 comments on commit 97a0779

Please sign in to comment.