mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-10 01:16:15 +00:00
RestoreMessagesActivity: find account to load
+ some fixes
This commit is contained in:
parent
f76de90a6e
commit
80a91635dd
@ -2,6 +2,7 @@ package fr.unix_experience.owncloud_sms.activities.remote_account;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
@ -38,7 +39,12 @@ public class AccountActionsActivity extends AppCompatListActivity {
|
||||
case 0:
|
||||
Intent intent = new Intent(this, RestoreMessagesActivity.class);
|
||||
intent.putExtra("account", _accountName);
|
||||
try {
|
||||
startActivity(intent);
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
Log.e(AccountActionsActivity.TAG, e.getMessage());
|
||||
}
|
||||
break;
|
||||
default: break; // Unhandled
|
||||
}
|
||||
|
@ -1,15 +1,51 @@
|
||||
package fr.unix_experience.owncloud_sms.activities.remote_account;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.R;
|
||||
|
||||
public class RestoreMessagesActivity extends AppCompatActivity {
|
||||
|
||||
Account _account = null;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_restore_messages);
|
||||
|
||||
assert getIntent().getExtras() != null;
|
||||
|
||||
String accountName = getIntent().getExtras().getString("account");
|
||||
|
||||
// accountName cannot be null, devel error
|
||||
assert accountName != null;
|
||||
AccountManager accountManager = AccountManager.get(getBaseContext());
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
Account[] accountList = accountManager.getAccountsByType(getString(R.string.account_type));
|
||||
for (Account element : accountList) {
|
||||
if (element.name.equals(accountName)) {
|
||||
_account = element;
|
||||
}
|
||||
}
|
||||
|
||||
if (_account == null) {
|
||||
throw new IllegalStateException(getString(R.string.err_didnt_find_account_restore));
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TAG = RestoreMessagesActivity.class.getSimpleName();
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public interface ASyncSMSSync {
|
||||
OCSMSNotificationUI.cancel(_context);
|
||||
} catch (IllegalStateException e) { // Fail to read account data
|
||||
OCSMSNotificationUI.notify(_context, _context.getString(R.string.fatal_error),
|
||||
e.toString(), OCSMSNotificationType.SYNC_FAILED.ordinal());
|
||||
e.getMessage(), OCSMSNotificationType.SYNC_FAILED.ordinal());
|
||||
} catch (OCSyncException e) {
|
||||
Log.e(ASyncSMSSync.TAG, _context.getString(e.getErrorId()));
|
||||
OCSMSNotificationUI.notify(_context, _context.getString(R.string.fatal_error),
|
||||
|
@ -55,7 +55,7 @@ class SmsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
OCSMSNotificationUI.cancel(getContext());
|
||||
} catch (IllegalStateException e) {
|
||||
OCSMSNotificationUI.notify(getContext(), getContext().getString(R.string.fatal_error),
|
||||
e.toString(), OCSMSNotificationType.SYNC_FAILED.ordinal());
|
||||
e.getMessage(), OCSMSNotificationType.SYNC_FAILED.ordinal());
|
||||
} catch (OCSyncException e) {
|
||||
OCSMSNotificationUI.cancel(getContext());
|
||||
OCSMSNotificationUI.notify(getContext(), getContext().getString(R.string.fatal_error),
|
||||
|
@ -174,5 +174,6 @@
|
||||
<string name="nothing_to_sync">There is nothing to sync.</string>
|
||||
<string name="feature_not_already_implemented">This feature is not already implemented and will be available soon.</string>
|
||||
<string name="pref_title_minimum_sync_chars">Minimum phonenumber length</string>
|
||||
<string name="err_didnt_find_account_restore">We didn\'t find your account to restore your message, this is a very strange situation.</string>
|
||||
|
||||
</resources>
|
||||
|
@ -161,4 +161,5 @@
|
||||
<string name="nothing_to_sync">Il n\'y a rien à synchroniser.</string>
|
||||
<string name="feature_not_already_implemented">Cette fonctionnalité n\'est pas implémentée mais elle sera disponible bientôt.</string>
|
||||
<string name="pref_title_minimum_sync_chars">Longueur minimale du numéro de téléphone</string>
|
||||
<string name="err_didnt_find_account_restore">Nous n\'avons pas retrouvé le compte que nous souhaitions utiliser pour la restauration. Cette situation est vraiment étrange.</string>
|
||||
</resources>
|
||||
|
@ -246,4 +246,5 @@
|
||||
<string name="nothing_to_sync">There is nothing to sync.</string>
|
||||
<string name="feature_not_already_implemented">This feature is not already implemented and will be available soon.</string>
|
||||
<string name="pref_title_minimum_sync_chars">Minimum phonenumber length</string>
|
||||
<string name="err_didnt_find_account_restore">We didn\'t find your account to restore your message, this is a very strange situation.</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user