Fix crash with download picture and sync account
This commit is contained in:
parent
c2075cc2a0
commit
97a077900f
3 changed files with 29 additions and 19 deletions
|
@ -90,12 +90,20 @@ 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)){
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,19 +142,27 @@ 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 {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue