Fix crash with download picture and sync account

This commit is contained in:
Margaux Clerc 2015-08-25 11:23:51 +02:00
parent c2075cc2a0
commit 97a077900f
3 changed files with 29 additions and 19 deletions

View file

@ -90,13 +90,21 @@ public class ContactsManager {
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)){
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;
} else {
} catch (Exception e) {
mAccount = null;
}
} else {
mAccount = accounts[0];
}
}
public String getDisplayName(String firstName, String lastName) {

View file

@ -284,9 +284,9 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
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) {

View file

@ -133,14 +133,8 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
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
@ -148,20 +142,28 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
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 {
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);
if (msgView != null) {