neue Datei: src/git/java/eu/siacs/conversations/utils/ProvisioningUtils.java

neue Datei:     src/quicksy/java/eu/siacs/conversations/ui/EasyOnboardingInviteActivity.java
	neue Datei:     src/quicksy/java/eu/siacs/conversations/ui/EnterNameActivity.java
	neue Datei:     src/quicksy/java/eu/siacs/conversations/utils/SignupUtils.java
This commit is contained in:
Arne 2023-03-19 23:01:26 +01:00
parent 65bc09a811
commit 3222e39241
4 changed files with 190 additions and 0 deletions

View file

@ -0,0 +1,42 @@
package eu.siacs.conversations.utils;
import android.app.Activity;
import android.content.Intent;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.AccountConfiguration;
import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.EditAccountActivity;
import eu.siacs.conversations.xmpp.Jid;
import me.drakeet.support.toast.ToastCompat;
public class ProvisioningUtils {
public static void provision(final Activity activity, final String json) {
final AccountConfiguration accountConfiguration;
try {
accountConfiguration = AccountConfiguration.parse(json);
} catch (final IllegalArgumentException e) {
ToastCompat.makeText(activity, R.string.improperly_formatted_provisioning, ToastCompat.LENGTH_LONG).show();
return;
}
final Jid jid = accountConfiguration.getJid();
final List<Jid> accounts = DatabaseBackend.getInstance(activity).getAccountJids(true);
if (accounts.contains(jid)) {
ToastCompat.makeText(activity, R.string.account_already_exists, ToastCompat.LENGTH_LONG).show();
return;
}
final Intent serviceIntent = new Intent(activity, XmppConnectionService.class);
serviceIntent.setAction(XmppConnectionService.ACTION_PROVISION_ACCOUNT);
serviceIntent.putExtra("address", jid.asBareJid().toEscapedString());
serviceIntent.putExtra("password", accountConfiguration.password);
Compatibility.startService(activity, serviceIntent);
final Intent intent = new Intent(activity, EditAccountActivity.class);
intent.putExtra("jid", jid.asBareJid().toEscapedString());
intent.putExtra("init", true);
activity.startActivity(intent);
}
}

View file

@ -0,0 +1,9 @@
package eu.siacs.conversations.ui;
import eu.siacs.conversations.entities.Account;
public class EasyOnboardingInviteActivity {
public static void launch(Account account, XmppActivity activity) {
throw new IllegalArgumentException("Easy Onboarding is not implemented for Quicksy");
}
}

View file

@ -0,0 +1,81 @@
package eu.siacs.conversations.ui;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import java.util.concurrent.atomic.AtomicBoolean;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityEnterNameBinding;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.AccountUtils;
public class EnterNameActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate {
private ActivityEnterNameBinding binding;
private Account account;
private final AtomicBoolean setNick = new AtomicBoolean(false);
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_enter_name);
setSupportActionBar((Toolbar) this.binding.toolbar);
this.binding.next.setOnClickListener(this::next);
this.setNick.set(savedInstanceState != null && savedInstanceState.getBoolean("set_nick",false));
}
private void next(View view) {
if (account != null) {
String name = this.binding.name.getText().toString().trim();
account.setDisplayName(name);
xmppConnectionService.publishDisplayName(account);
Intent intent = new Intent(this, PublishProfilePictureActivity.class);
intent.putExtra(PublishProfilePictureActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString());
intent.putExtra("setup", true);
startActivity(intent);
}
finish();
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putBoolean("set_nick", this.setNick.get());
super.onSaveInstanceState(savedInstanceState);
}
@Override
protected void refreshUiReal() {
checkSuggestPreviousNick();
}
@Override
void onBackendConnected() {
this.account = AccountUtils.getFirst(xmppConnectionService);
checkSuggestPreviousNick();
}
private void checkSuggestPreviousNick() {
String displayName = this.account == null ? null : this.account.getDisplayName();
if (displayName != null) {
if (setNick.compareAndSet(false, true) && this.binding.name.getText().length() == 0) {
this.binding.name.getText().append(displayName);
}
}
}
@Override
public void onAccountUpdate() {
refreshUi();
}
}

View file

@ -0,0 +1,58 @@
package eu.siacs.conversations.utils;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.ConversationsActivity;
import eu.siacs.conversations.ui.EditAccountActivity;
import eu.siacs.conversations.ui.EnterPhoneNumberActivity;
import eu.siacs.conversations.ui.StartConversationActivity;
import eu.siacs.conversations.ui.TosActivity;
import eu.siacs.conversations.ui.VerifyActivity;
import eu.siacs.conversations.xmpp.Jid;
public class SignupUtils {
public static Intent getSignUpIntent(Activity activity, boolean ignored) {
return getSignUpIntent(activity);
}
public static Intent getSignUpIntent(Activity activity) {
return new Intent(activity, EnterPhoneNumberActivity.class);
}
public static Intent getRedirectionIntent(ConversationsActivity activity) {
final Intent intent;
final Account account = AccountUtils.getFirst(activity.xmppConnectionService);
if (account != null) {
if (account.isOptionSet(Account.OPTION_UNVERIFIED)) {
intent = new Intent(activity, VerifyActivity.class);
} else {
intent = new Intent(activity, StartConversationActivity.class);
}
} else {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
if (preferences.getBoolean("tos",false)) {
intent = getSignUpIntent(activity);
} else {
intent = new Intent(activity, TosActivity.class);
}
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
return intent;
}
public static boolean isSupportTokenRegistry() {
return false;
}
public static Intent getTokenRegistrationIntent(Activity activity, Jid preset, String key) {
return null;
}
}