diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index fa120d454..2fd8e5802 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -168,16 +168,17 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio public static final long DRAWER_UNREAD_CHATS = 2; public static final long DRAWER_DIRECT_MESSAGES = 3; public static final long DRAWER_MANAGE_ACCOUNT = 4; - public static final long DRAWER_MANAGE_PHONE_ACCOUNTS = 5; - public static final long DRAWER_CHANNELS = 6; - public static final long DRAWER_CHAT_REQUESTS = 7; - public static final long DRAWER_SETTINGS = 8; - public static final long DRAWER_START_CHAT = 9; - public static final long DRAWER_START_CHAT_CONTACT = 10; - public static final long DRAWER_START_CHAT_NEW = 11; - public static final long DRAWER_START_CHAT_GROUP = 12; - public static final long DRAWER_START_CHAT_PUBLIC = 13; - public static final long DRAWER_START_CHAT_DISCOVER = 14; + public static final long DRAWER_ADD_ACCOUNT = 5; + public static final long DRAWER_MANAGE_PHONE_ACCOUNTS = 6; + public static final long DRAWER_CHANNELS = 7; + public static final long DRAWER_CHAT_REQUESTS = 8; + public static final long DRAWER_SETTINGS = 9; + public static final long DRAWER_START_CHAT = 10; + public static final long DRAWER_START_CHAT_CONTACT = 11; + public static final long DRAWER_START_CHAT_NEW = 12; + public static final long DRAWER_START_CHAT_GROUP = 13; + public static final long DRAWER_START_CHAT_PUBLIC = 14; + public static final long DRAWER_START_CHAT_DISCOVER = 15; //secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment private static final @IdRes @@ -377,7 +378,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio phoneAccounts.setIdentifier(DRAWER_MANAGE_PHONE_ACCOUNTS); com.mikepenz.materialdrawer.model.interfaces.NameableKt.setNameText(phoneAccounts, "Manage Phone Accounts"); com.mikepenz.materialdrawer.model.interfaces.IconableKt.setIconRes(phoneAccounts, R.drawable.ic_call_24dp); - accountHeader.addProfile(phoneAccounts, accountHeader.getProfiles().size() - 1); + accountHeader.addProfile(phoneAccounts, accountHeader.getProfiles().size() - 2); } final boolean nightMode = Activities.isNightMode(this); @@ -414,7 +415,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio final var badgeNumber = accountUnreads.get(a); p.setBadge(new com.mikepenz.materialdrawer.holder.StringHolder(badgeNumber == null || badgeNumber < 1 ? " " : badgeNumber.toString())); if (alreadyInHeader == null) { - accountHeader.addProfile(p, accountHeader.getProfiles().size() - (hasPhoneAccounts ? 2 : 1)); + accountHeader.addProfile(p, accountHeader.getProfiles().size() - (hasPhoneAccounts ? 3 : 2)); } else { accountHeader.updateProfile(p); } @@ -467,10 +468,16 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio accountHeader = new com.mikepenz.materialdrawer.widget.AccountHeaderView(this); final var manageAccount = new com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem(); manageAccount.setIdentifier(DRAWER_MANAGE_ACCOUNT); - com.mikepenz.materialdrawer.model.interfaces.NameableKt.setNameText(manageAccount, getString(R.string.title_activity_manage_accounts)); + com.mikepenz.materialdrawer.model.interfaces.NameableKt.setNameText(manageAccount, getResources().getString(R.string.action_accounts)); com.mikepenz.materialdrawer.model.interfaces.IconableKt.setIconRes(manageAccount, R.drawable.ic_settings_24dp); accountHeader.addProfiles(manageAccount); + final var addAccount = new com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem(); + addAccount.setIdentifier(DRAWER_ADD_ACCOUNT); + com.mikepenz.materialdrawer.model.interfaces.NameableKt.setNameText(addAccount, getResources().getString(R.string.action_add_account)); + com.mikepenz.materialdrawer.model.interfaces.IconableKt.setIconRes(addAccount, R.drawable.ic_add_24dp); + accountHeader.addProfiles(addAccount); + final var color = MaterialColors.getColor(binding.drawer, com.google.android.material.R.attr.colorPrimaryContainer); final var textColor = MaterialColors.getColor(binding.drawer, com.google.android.material.R.attr.colorOnPrimaryContainer); @@ -597,6 +604,11 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio return false; } + if (id == DRAWER_ADD_ACCOUNT) { + startActivity(new Intent(this, EditAccountActivity.class)); + return false; + } + if (id == DRAWER_MANAGE_PHONE_ACCOUNTS) { final String[] permissions; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index bd685ea79..770dfae7e 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -96,6 +96,9 @@ import eu.siacs.conversations.xmpp.XmppConnection.Features; import eu.siacs.conversations.xmpp.forms.Data; import eu.siacs.conversations.xmpp.pep.Avatar; +import static eu.siacs.conversations.utils.PermissionUtils.allGranted; +import static eu.siacs.conversations.utils.PermissionUtils.writeGranted; + import okhttp3.HttpUrl; import org.openintents.openpgp.util.OpenPgpUtils; @@ -117,6 +120,7 @@ public class EditAccountActivity extends OmemoActivity public static final String EXTRA_OPENED_FROM_NOTIFICATION = "opened_from_notification"; public static final String EXTRA_FORCE_REGISTER = "force_register"; + private static final int REQUEST_IMPORT_BACKUP = 0x63fb; private static final int REQUEST_DATA_SAVER = 0xf244; private static final int REQUEST_CHANGE_STATUS = 0xee11; private static final int REQUEST_ORBOT = 0xff22; @@ -842,9 +846,11 @@ public class EditAccountActivity extends OmemoActivity final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs); final MenuItem changePresence = menu.findItem(R.id.action_change_presence); final MenuItem share = menu.findItem(R.id.action_share); + final MenuItem importBackup = menu.findItem(R.id.action_import_backup); renewCertificate.setVisible(mAccount != null && mAccount.getPrivateKeyAlias() != null); share.setVisible(mAccount != null && !mInitMode); + importBackup.setVisible(mAccount == null || mInitMode); if (mAccount != null && mAccount.isOnlineAndConnected()) { if (!mAccount.getXmppConnection().getFeatures().blocking()) { @@ -1094,6 +1100,11 @@ public class EditAccountActivity extends OmemoActivity case R.id.action_change_presence: changePresence(); break; + case R.id.action_import_backup: + if (hasStoragePermission(REQUEST_IMPORT_BACKUP)) { + startActivity(new Intent(this, ImportBackupActivity.class)); + } + break; } return super.onOptionsItemSelected(item); } @@ -1805,4 +1816,24 @@ public class EditAccountActivity extends OmemoActivity public void OnUpdateBlocklist(Status status) { refreshUi(); } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + if (grantResults.length > 0) { + if (allGranted(grantResults)) { + switch (requestCode) { + case REQUEST_IMPORT_BACKUP: + startActivity(new Intent(this, ImportBackupActivity.class)); + break; + } + } else { + Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); + } + } + if (writeGranted(grantResults, permissions)) { + if (xmppConnectionService != null) { + xmppConnectionService.restartFileObserver(); + } + } + } } diff --git a/src/main/res/menu/editaccount.xml b/src/main/res/menu/editaccount.xml index d7dcf571a..51383f2ae 100644 --- a/src/main/res/menu/editaccount.xml +++ b/src/main/res/menu/editaccount.xml @@ -1,6 +1,12 @@
\ No newline at end of file + diff --git a/src/monocleschat/res/drawable/backup_restore_24dp.xml b/src/monocleschat/res/drawable/backup_restore_24dp.xml new file mode 100644 index 000000000..2c551ca49 --- /dev/null +++ b/src/monocleschat/res/drawable/backup_restore_24dp.xml @@ -0,0 +1,11 @@ +