conversations-classic/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java

105 lines
2.9 KiB
Java
Raw Normal View History

2016-04-19 16:03:24 +00:00
package eu.siacs.conversations.ui;
import android.content.Intent;
import android.content.pm.ActivityInfo;
2016-04-19 16:03:24 +00:00
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
2016-04-19 16:03:24 +00:00
import android.widget.Button;
import java.util.List;
2016-04-19 16:03:24 +00:00
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.utils.XmppUri;
public class WelcomeActivity extends XmppActivity {
public static final String EXTRA_INVITE_URI = "eu.siacs.conversations.invite_uri";
@Override
protected void refreshUiReal() {
}
@Override
void onBackendConnected() {
2016-04-19 16:03:24 +00:00
}
2016-04-19 16:03:24 +00:00
@Override
public void onStart() {
super.onStart();
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
}
@Override
public void onNewIntent(Intent intent) {
if (intent != null) {
setIntent(intent);
}
}
2016-04-19 16:03:24 +00:00
@Override
protected void onCreate(final Bundle savedInstanceState) {
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
final ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setDisplayShowHomeEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
}
final Button createAccount = findViewById(R.id.create_account);
createAccount.setOnClickListener(v -> {
final Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
addInviteUri(intent);
startActivity(intent);
2016-04-19 16:03:24 +00:00
});
final Button useOwnProvider = findViewById(R.id.use_own_provider);
useOwnProvider.setOnClickListener(v -> {
List<Account> accounts = xmppConnectionService.getAccounts();
Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class);
if (accounts.size() == 1) {
intent.putExtra("jid", accounts.get(0).getJid().toBareJid().toString());
intent.putExtra("init", true);
} else if (accounts.size() >= 1) {
intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class);
2016-04-19 16:03:24 +00:00
}
addInviteUri(intent);
startActivity(intent);
2016-04-19 16:03:24 +00:00
});
}
public void addInviteUri(Intent intent) {
addInviteUri(intent, getIntent());
}
public static void addInviteUri(Intent intent, XmppUri uri) {
if (uri.isJidValid()) {
intent.putExtra(EXTRA_INVITE_URI, uri.toString());
}
}
public static void addInviteUri(Intent to, Intent from) {
if (from != null && from.hasExtra(EXTRA_INVITE_URI)) {
to.putExtra(EXTRA_INVITE_URI, from.getStringExtra(EXTRA_INVITE_URI));
}
}
public static void launch(AppCompatActivity activity) {
Intent intent = new Intent(activity, WelcomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.startActivity(intent);
activity.overridePendingTransition(0,0);
}
2016-04-19 16:03:24 +00:00
}