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,12 +90,20 @@ public class ContactsManager {
public void initializeSyncAccount(Context context, ContentResolver contentResolver) { public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
initializeContactManager(context,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); 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 { } else {
mAccount = null; mAccount = accounts[0];
} }
} }

View file

@ -284,9 +284,9 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
mUploadPendingFileMessage = null; mUploadPendingFileMessage = null;
mUploadingImageStream = null; mUploadingImageStream = null;
} else { } else {
File file = new File(Environment.getExternalStorageDirectory(), msg.getFileTransferInformation().getName()); File file = new File(Environment.getExternalStorageDirectory(), msg.getAppData());
try { 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); msg.setAppData(url);
file.delete(); file.delete();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

View file

@ -133,14 +133,8 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
ImageView imageView = (ImageView) view.findViewById(R.id.image); ImageView imageView = (ImageView) view.findViewById(R.id.image);
String appData = message.getAppData(); 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); 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.setVisibility(View.VISIBLE);
download.setOnClickListener(new OnClickListener() { download.setOnClickListener(new OnClickListener() {
@Override @Override
@ -148,19 +142,27 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
v.setEnabled(false); v.setEnabled(false);
spinner.setVisibility(View.VISIBLE); spinner.setVisibility(View.VISIBLE);
v.setVisibility(View.GONE); v.setVisibility(View.GONE);
String filename = context.getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis()));
File file = new File(Environment.getExternalStorageDirectory(), nativeMessage.getFileTransferInformation().getName()); File file = new File(Environment.getExternalStorageDirectory(), filename);
nativeMessage.setListener(LinphoneManager.getInstance()); nativeMessage.setListener(LinphoneManager.getInstance());
nativeMessage.setFileTransferFilepath(file.getPath()); nativeMessage.setFileTransferFilepath(file.getPath());
nativeMessage.downloadFile(); nativeMessage.downloadFile();
nativeMessage.setAppData(filename);
LinphoneManager.getInstance().addDownloadMessagePending(nativeMessage); LinphoneManager.getInstance().addDownloadMessagePending(nativeMessage);
} }
}); });
}
} else { } else {
LinphoneManager.removeListener(this); if(LinphoneManager.getInstance().isMessagePending(nativeMessage)){
imageView.setVisibility(View.VISIBLE); LinphoneManager.addListener(this);
loadBitmap(appData, imageView); 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 { } else {
TextView msgView = (TextView) view.findViewById(R.id.message); TextView msgView = (TextView) view.findViewById(R.id.message);