mirror of https://github.com/M66B/FairEmail.git
parent
2a1b403636
commit
b48532f8bd
@ -0,0 +1,157 @@
|
|||||||
|
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/>.
|
||||||
|
|
||||||
|
Copyright 2018-2024 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.constraintlayout.widget.Group;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FragmentDialogPwned extends FragmentDialogBase {
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||||
|
final Context context = getContext();
|
||||||
|
final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_pwned, null);
|
||||||
|
final TextView tvPwned = dview.findViewById(R.id.tvPwned);
|
||||||
|
final Button btnCheck = dview.findViewById(R.id.btnCheck);
|
||||||
|
final ContentLoadingProgressBar pbCheck = dview.findViewById(R.id.pbCheck);
|
||||||
|
final TextView tvPrivacy = dview.findViewById(R.id.tvPrivacy);
|
||||||
|
final Group grpReady = dview.findViewById(R.id.grpReady);
|
||||||
|
|
||||||
|
final int colorError = Helper.resolveColor(context, androidx.appcompat.R.attr.colorError);
|
||||||
|
final int colorVerified = Helper.resolveColor(context, R.attr.colorVerified);
|
||||||
|
|
||||||
|
btnCheck.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
new SimpleTask<SpannableStringBuilder>() {
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute(Bundle args) {
|
||||||
|
btnCheck.setEnabled(false);
|
||||||
|
pbCheck.setVisibility(View.VISIBLE);
|
||||||
|
grpReady.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Bundle args) {
|
||||||
|
btnCheck.setEnabled(true);
|
||||||
|
pbCheck.setVisibility(View.GONE);
|
||||||
|
grpReady.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpannableStringBuilder onExecute(Context context, Bundle args) throws Throwable {
|
||||||
|
SpannableStringBuilder ssb = new SpannableStringBuilder();
|
||||||
|
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
List<EntityAccount> accounts = db.account().getAccounts();
|
||||||
|
if (accounts != null)
|
||||||
|
for (EntityAccount account : accounts)
|
||||||
|
if (account.auth_type == AUTH_TYPE_PASSWORD &&
|
||||||
|
!TextUtils.isEmpty(account.password)) {
|
||||||
|
check(context, account.name, account.password, ssb);
|
||||||
|
List<EntityIdentity> identities = db.identity().getIdentities(account.id);
|
||||||
|
if (identities != null)
|
||||||
|
for (EntityIdentity identity : identities)
|
||||||
|
if (identity.auth_type == AUTH_TYPE_PASSWORD &&
|
||||||
|
!account.password.equals(identity.password))
|
||||||
|
check(context, account.name + "/" + identity.user, identity.password, ssb);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ssb;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void check(Context context, String name, String password, SpannableStringBuilder ssb) throws NoSuchAlgorithmException, IOException {
|
||||||
|
Integer count = HaveIBeenPwned.check(password, context);
|
||||||
|
boolean pwned = (count != null && count != 0);
|
||||||
|
|
||||||
|
if (ssb.length() > 0)
|
||||||
|
ssb.append('\n');
|
||||||
|
|
||||||
|
ssb.append(name).append(": ");
|
||||||
|
int start = ssb.length();
|
||||||
|
ssb.append(pwned ? "PWNED!" : "OK");
|
||||||
|
|
||||||
|
if (pwned) {
|
||||||
|
ssb.setSpan(new ForegroundColorSpan(colorError), start, ssb.length(), 0);
|
||||||
|
ssb.setSpan(new StyleSpan(Typeface.BOLD), start, ssb.length(), 0);
|
||||||
|
} else
|
||||||
|
ssb.setSpan(new ForegroundColorSpan(colorVerified), start, ssb.length(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onExecuted(Bundle args, SpannableStringBuilder ssb) {
|
||||||
|
tvPwned.setText(ssb);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
tvPwned.setText(Log.formatThrowable(ex));
|
||||||
|
}
|
||||||
|
}.execute(FragmentDialogPwned.this, new Bundle(), "pwned");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
pbCheck.setVisibility(View.GONE);
|
||||||
|
grpReady.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
tvPrivacy.setText(BuildConfig.PWNED_PRIVACY);
|
||||||
|
tvPrivacy.getPaint().setUnderlineText(true);
|
||||||
|
tvPrivacy.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Helper.view(v.getContext(), Uri.parse(BuildConfig.PWNED_PRIVACY), true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return new AlertDialog.Builder(context)
|
||||||
|
.setView(dview)
|
||||||
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,64 +1,78 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="24dp"
|
android:padding="24dp"
|
||||||
tools:context="eu.faircode.email.ActivitySetup">
|
android:scrollbarStyle="outsideOverlay">
|
||||||
|
|
||||||
<TextView
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/tvCaption"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:drawableStart="@drawable/twotone_security_24"
|
|
||||||
android:drawablePadding="6dp"
|
|
||||||
android:text="@string/title_pawned"
|
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<ScrollView
|
<TextView
|
||||||
android:id="@+id/scroll"
|
android:id="@+id/tvCaption"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="24dp"
|
android:drawableStart="@drawable/twotone_security_24"
|
||||||
android:orientation="vertical"
|
android:drawablePadding="6dp"
|
||||||
android:scrollbarStyle="outsideOverlay"
|
android:text="@string/title_pawned"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvCaption">
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvPwned"
|
android:id="@+id/tvPwned"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Pwned"
|
android:layout_marginTop="24dp"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
android:text="Pwned"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
<eu.faircode.email.ContentLoadingProgressBar
|
<Button
|
||||||
android:id="@+id/pbWait"
|
android:id="@+id/btnCheck"
|
||||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_marginTop="24dp"
|
||||||
android:layout_marginTop="24dp"
|
android:drawableEnd="@drawable/twotone_check_24"
|
||||||
android:indeterminate="true"
|
android:drawablePadding="6dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:text="@string/title_check"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/scroll" />
|
app:layout_constraintTop_toBottomOf="@id/tvPwned" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Group
|
<eu.faircode.email.ContentLoadingProgressBar
|
||||||
android:id="@+id/grpReady"
|
android:id="@+id/pbCheck"
|
||||||
android:layout_width="0dp"
|
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||||
android:layout_height="0dp"
|
android:layout_width="24dp"
|
||||||
app:constraint_referenced_ids="scroll" />
|
android:layout_height="24dp"
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
android:layout_marginStart="12dp"
|
||||||
|
android:indeterminate="true"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/btnCheck"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/btnCheck"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/btnCheck" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvPrivacy"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:drawableEnd="@drawable/twotone_open_in_new_12"
|
||||||
|
android:drawablePadding="6dp"
|
||||||
|
android:text="@string/title_privacy_policy"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textColor="?android:attr/textColorLink"
|
||||||
|
app:drawableTint="?android:attr/textColorLink"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/btnCheck" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Group
|
||||||
|
android:id="@+id/grpReady"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:constraint_referenced_ids="tvPwned" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</ScrollView>
|
Loading…
Reference in new issue