1
0
Fork 1

Add account from drawer

And import backup from toolbar of add account

(cherry picked from commit eefb6da098f241aa13ed2d69086a8af53f16922b)
This commit is contained in:
Stephen Paul Weber 2024-11-20 06:32:44 +01:00 committed by Arne
parent 29281d46b7
commit 78dc6c3ec7
4 changed files with 74 additions and 14 deletions

View file

@ -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) {

View file

@ -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();
}
}
}
}

View file

@ -1,6 +1,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_import_backup"
android:title="@string/restore_backup"
android:icon="@drawable/backup_restore_24dp"
app:showAsAction="always" />
<item
android:id="@+id/action_change_presence"
android:icon="@drawable/ic_announcement_24dp"
@ -64,4 +70,4 @@
android:orderInCategory="100"
app:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
</menu>

View file

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M480,560Q447,560 423.5,536.5Q400,513 400,480Q400,447 423.5,423.5Q447,400 480,400Q513,400 536.5,423.5Q560,447 560,480Q560,513 536.5,536.5Q513,560 480,560ZM480,840Q341,840 239,748.5Q137,657 122,520L204,520Q218,624 296.5,692Q375,760 480,760Q597,760 678.5,678.5Q760,597 760,480Q760,363 678.5,281.5Q597,200 480,200Q411,200 351,232Q291,264 250,320L360,320L360,400L120,400L120,160L200,160L200,254Q251,190 324.5,155Q398,120 480,120Q555,120 620.5,148.5Q686,177 734.5,225.5Q783,274 811.5,339.5Q840,405 840,480Q840,555 811.5,620.5Q783,686 734.5,734.5Q686,783 620.5,811.5Q555,840 480,840Z"/>
</vector>