FairEmail/app/src/main/java/eu/faircode/email/ActivityError.java

198 lines
8.4 KiB
Java
Raw Normal View History

2021-07-31 18:13:58 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2023-01-01 07:52:55 +00:00
Copyright 2018-2023 by Marcel Bokhorst (M66B)
2021-07-31 18:13:58 +00:00
*/
2023-11-28 12:48:09 +00:00
import android.content.Context;
2021-07-31 18:13:58 +00:00
import android.content.Intent;
import android.os.Bundle;
2023-11-02 20:08:43 +00:00
import android.view.MenuItem;
2021-07-31 18:13:58 +00:00
import android.view.View;
2021-09-25 14:29:47 +00:00
import android.widget.Button;
2021-07-31 18:13:58 +00:00
import android.widget.ImageButton;
import android.widget.TextView;
2023-09-20 20:40:27 +00:00
import androidx.core.text.method.LinkMovementMethodCompat;
2023-11-28 12:48:09 +00:00
import java.util.List;
2021-07-31 18:13:58 +00:00
public class ActivityError extends ActivityBase {
static final int PI_ERROR = 1;
static final int PI_ALERT = 2;
2021-10-26 13:04:19 +00:00
private TextView tvTitle;
private TextView tvMessage;
private Button btnPassword;
private ImageButton ibSetting;
private ImageButton ibInfo;
2021-07-31 18:13:58 +00:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2022-02-13 13:59:37 +00:00
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
2021-07-31 18:13:58 +00:00
getSupportActionBar().setSubtitle(getString(R.string.title_setup_error));
2021-10-26 13:04:19 +00:00
setContentView(R.layout.activity_error);
tvTitle = findViewById(R.id.tvTitle);
tvMessage = findViewById(R.id.tvMessage);
btnPassword = findViewById(R.id.btnPassword);
ibSetting = findViewById(R.id.ibSetting);
ibInfo = findViewById(R.id.ibInfo);
2021-07-31 18:13:58 +00:00
2021-10-26 13:04:19 +00:00
load();
}
2021-07-31 18:13:58 +00:00
2021-10-26 13:04:19 +00:00
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
load();
}
2021-07-31 18:13:58 +00:00
2023-11-02 20:08:43 +00:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
2021-10-26 13:04:19 +00:00
private void load() {
2021-07-31 18:13:58 +00:00
Intent intent = getIntent();
String type = intent.getStringExtra("type");
String title = intent.getStringExtra("title");
String message = intent.getStringExtra("message");
2021-09-25 14:29:47 +00:00
String provider = intent.getStringExtra("provider");
2021-08-13 12:33:37 +00:00
long account = intent.getLongExtra("account", -1L);
long identity = intent.getLongExtra("identity", -1L);
2021-09-25 14:29:47 +00:00
int protocol = intent.getIntExtra("protocol", -1);
int auth_type = intent.getIntExtra("auth_type", -1);
2021-07-31 18:13:58 +00:00
int faq = intent.getIntExtra("faq", -1);
tvTitle.setText(title);
2023-09-20 20:40:27 +00:00
tvMessage.setMovementMethod(LinkMovementMethodCompat.getInstance());
2021-07-31 18:13:58 +00:00
tvMessage.setText(message);
2023-08-06 14:05:50 +00:00
boolean password = (auth_type == ServiceAuthenticator.AUTH_TYPE_PASSWORD);
btnPassword.setText(password ? R.string.title_password : R.string.title_setup_oauth_authorize);
btnPassword.setCompoundDrawablesRelativeWithIntrinsicBounds(
0, 0,
2023-08-06 14:05:50 +00:00
password ? R.drawable.twotone_edit_24 : R.drawable.twotone_check_24, 0);
2022-09-08 07:03:30 +00:00
btnPassword.setVisibility(account < 0 ? View.GONE : View.VISIBLE);
2021-09-25 14:29:47 +00:00
btnPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
2023-08-06 14:05:50 +00:00
if (auth_type == ServiceAuthenticator.AUTH_TYPE_GMAIL)
startActivity(new Intent(ActivityError.this, ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra("target", "gmail")
2023-11-28 12:48:09 +00:00
.putExtra("personal", intent.getStringExtra("personal"))
.putExtra("address", intent.getStringExtra("address")));
2023-08-06 14:05:50 +00:00
else if (auth_type == ServiceAuthenticator.AUTH_TYPE_OAUTH) {
try {
EmailProvider eprovider = EmailProvider.getProvider(ActivityError.this, provider);
startActivity(new Intent(ActivityError.this, ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra("target", "oauth")
.putExtra("id", eprovider.id)
.putExtra("name", eprovider.description)
.putExtra("privacy", eprovider.oauth.privacy)
.putExtra("askAccount", eprovider.oauth.askAccount)
.putExtra("askTenant", eprovider.oauth.askTenant())
2023-11-28 12:48:09 +00:00
.putExtra("personal", intent.getStringExtra("personal"))
.putExtra("address", intent.getStringExtra("address")));
2023-08-06 14:05:50 +00:00
} catch (Throwable ex) {
Log.e(ex);
startActivity(new Intent(ActivityError.this, ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
}
} else if (auth_type == ServiceAuthenticator.AUTH_TYPE_GRAPH)
startActivity(new Intent(ActivityError.this, ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra("target", "oauth")
.putExtra("id", provider)
.putExtra("name", "Outlook")
.putExtra("askAccount", true)
.putExtra("askTenant", true)
2023-11-28 12:48:09 +00:00
.putExtra("personal", intent.getStringExtra("personal"))
.putExtra("address", intent.getStringExtra("address")));
else
startActivity(new Intent(ActivityError.this, ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra("target", "accounts")
.putExtra("id", account)
.putExtra("protocol", protocol));
2022-09-08 07:03:30 +00:00
finish();
2021-09-25 14:29:47 +00:00
}
});
2021-08-13 12:33:37 +00:00
ibSetting.setVisibility(account < 0 ? View.GONE : View.VISIBLE);
ibSetting.setOnClickListener(new View.OnClickListener() {
@Override
2021-08-13 14:39:44 +00:00
public void onClick(View v) {
v.getContext().startActivity(new Intent(v.getContext(), ActivitySetup.class)
2021-09-27 16:57:39 +00:00
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
2021-09-25 14:29:47 +00:00
.putExtra("target", "accounts")
.putExtra("id", account)
.putExtra("protocol", protocol));
2021-08-13 12:33:37 +00:00
}
});
2021-07-31 18:13:58 +00:00
ibInfo.setVisibility(faq > 0 ? View.VISIBLE : View.GONE);
ibInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Helper.viewFAQ(view.getContext(), faq);
}
});
2023-11-28 12:48:09 +00:00
Bundle args = new Bundle();
args.putLong("account", account);
new SimpleTask<EntityIdentity>() {
@Override
protected EntityIdentity onExecute(Context context, Bundle args) throws Throwable {
long account = args.getLong("account");
DB db = DB.getInstance(context);
List<EntityIdentity> identities = db.identity().getSynchronizingIdentities(account);
return (identities == null || identities.size() != 1 ? null : identities.get(0));
}
@Override
protected void onExecuted(Bundle args, EntityIdentity identity) {
if (identity == null)
return;
intent.putExtra("personal", identity.name);
intent.putExtra("address", identity.email);
}
@Override
protected void onException(Bundle args, Throwable ex) {
// Ignored
}
}.execute(this, args, "error:details");
2021-07-31 18:13:58 +00:00
}
}