2018-08-02 13:33:06 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
2018-08-14 05:53:24 +00:00
|
|
|
This file is part of FairEmail.
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-14 05:53:24 +00:00
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
2018-08-02 13:33:06 +00:00
|
|
|
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.
|
|
|
|
|
2018-10-29 10:46:49 +00:00
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
2018-08-02 13:33:06 +00:00
|
|
|
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
|
2018-10-29 10:46:49 +00:00
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-12-31 08:04:33 +00:00
|
|
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
2018-08-02 13:33:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import android.Manifest;
|
2018-09-04 18:06:22 +00:00
|
|
|
import android.annotation.TargetApi;
|
2018-12-27 16:49:37 +00:00
|
|
|
import android.content.ComponentName;
|
2018-08-12 07:51:33 +00:00
|
|
|
import android.content.Context;
|
2018-09-04 18:06:22 +00:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2018-09-07 12:34:54 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
2018-09-04 18:06:22 +00:00
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.os.Bundle;
|
2018-09-04 18:06:22 +00:00
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.provider.Settings;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.view.LayoutInflater;
|
2019-01-14 17:58:50 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.Button;
|
2019-01-15 09:46:25 +00:00
|
|
|
import android.widget.ImageButton;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import java.util.List;
|
2018-11-14 18:58:01 +00:00
|
|
|
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
2018-12-13 09:43:30 +00:00
|
|
|
import androidx.lifecycle.LiveData;
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.lifecycle.Observer;
|
|
|
|
|
2018-08-05 12:09:46 +00:00
|
|
|
public class FragmentSetup extends FragmentEx {
|
2018-09-14 11:33:22 +00:00
|
|
|
private ViewGroup view;
|
|
|
|
|
2018-12-29 17:00:10 +00:00
|
|
|
private Button btnQuick;
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
private TextView tvAccountDone;
|
2019-01-15 09:46:25 +00:00
|
|
|
private Button btnAccount;
|
2018-12-13 09:43:30 +00:00
|
|
|
private TextView tvNoPrimaryDrafts;
|
2018-08-04 15:13:19 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
private TextView tvIdentityDone;
|
2019-01-15 09:46:25 +00:00
|
|
|
private Button btnIdentity;
|
2018-08-04 15:13:19 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
private TextView tvPermissionsDone;
|
2019-01-15 09:46:25 +00:00
|
|
|
private Button btnPermissions;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
private TextView tvDozeDone;
|
2019-01-15 09:46:25 +00:00
|
|
|
private Button btnDoze;
|
2018-09-04 18:06:22 +00:00
|
|
|
|
|
|
|
private Button btnData;
|
|
|
|
|
2019-01-15 09:46:25 +00:00
|
|
|
private Button btnInbox;
|
|
|
|
|
2019-01-14 12:31:23 +00:00
|
|
|
private int textColorPrimary;
|
|
|
|
private int colorWarning;
|
2018-09-07 12:34:54 +00:00
|
|
|
private Drawable check;
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
private static final String[] permissions = new String[]{
|
|
|
|
Manifest.permission.READ_CONTACTS
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2018-08-05 12:09:46 +00:00
|
|
|
setSubtitle(R.string.title_setup);
|
2019-01-14 17:58:50 +00:00
|
|
|
setHasOptionsMenu(true);
|
2018-08-05 12:09:46 +00:00
|
|
|
|
2019-01-14 12:31:23 +00:00
|
|
|
textColorPrimary = Helper.resolveColor(getContext(), android.R.attr.textColorPrimary);
|
|
|
|
colorWarning = Helper.resolveColor(getContext(), R.attr.colorWarning);
|
2018-09-07 12:34:54 +00:00
|
|
|
check = getResources().getDrawable(R.drawable.baseline_check_24, getContext().getTheme());
|
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
view = (ViewGroup) inflater.inflate(R.layout.fragment_setup, container, false);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
// Get controls
|
2018-12-29 17:00:10 +00:00
|
|
|
btnQuick = view.findViewById(R.id.btnQuick);
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
tvAccountDone = view.findViewById(R.id.tvAccountDone);
|
2019-01-15 09:46:25 +00:00
|
|
|
btnAccount = view.findViewById(R.id.btnAccount);
|
2018-12-13 09:43:30 +00:00
|
|
|
tvNoPrimaryDrafts = view.findViewById(R.id.tvNoPrimaryDrafts);
|
2018-08-04 15:13:19 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
tvIdentityDone = view.findViewById(R.id.tvIdentityDone);
|
2019-01-15 09:46:25 +00:00
|
|
|
btnIdentity = view.findViewById(R.id.btnIdentity);
|
2018-08-04 15:13:19 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
tvPermissionsDone = view.findViewById(R.id.tvPermissionsDone);
|
2019-01-15 09:46:25 +00:00
|
|
|
btnPermissions = view.findViewById(R.id.btnPermissions);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
tvDozeDone = view.findViewById(R.id.tvDozeDone);
|
2019-01-15 09:46:25 +00:00
|
|
|
btnDoze = view.findViewById(R.id.btnDoze);
|
2018-09-04 18:06:22 +00:00
|
|
|
|
|
|
|
btnData = view.findViewById(R.id.btnData);
|
|
|
|
|
2019-01-15 09:46:25 +00:00
|
|
|
btnInbox = view.findViewById(R.id.btnInbox);
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
// Wire controls
|
|
|
|
|
2018-12-29 17:00:10 +00:00
|
|
|
btnQuick.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-01-14 11:11:03 +00:00
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentQuickSetup()).addToBackStack("quick");
|
|
|
|
fragmentTransaction.commit();
|
2018-12-29 17:00:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
btnAccount.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2018-08-06 12:29:14 +00:00
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentAccounts()).addToBackStack("accounts");
|
|
|
|
fragmentTransaction.commit();
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
btnIdentity.setOnClickListener(new View.OnClickListener() {
|
2018-08-05 18:46:36 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2018-08-04 15:13:19 +00:00
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
2018-08-06 12:29:14 +00:00
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentIdentities()).addToBackStack("identities");
|
2018-08-04 15:13:19 +00:00
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-06 12:29:14 +00:00
|
|
|
btnPermissions.setOnClickListener(new View.OnClickListener() {
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2018-08-10 16:06:39 +00:00
|
|
|
btnPermissions.setEnabled(false);
|
2019-01-01 19:32:13 +00:00
|
|
|
requestPermissions(permissions, ActivitySetup.REQUEST_PERMISSION);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
btnDoze.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2018-09-20 16:47:28 +00:00
|
|
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
2018-09-04 18:06:22 +00:00
|
|
|
.setMessage(R.string.title_setup_doze_instructions)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
try {
|
|
|
|
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
|
|
|
|
} catch (Throwable ex) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.e(ex);
|
2018-09-04 18:06:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.create()
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
btnData.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@TargetApi(Build.VERSION_CODES.N)
|
|
|
|
public void onClick(View v) {
|
|
|
|
try {
|
|
|
|
startActivity(new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS,
|
|
|
|
Uri.parse("package:" + BuildConfig.APPLICATION_ID)));
|
|
|
|
} catch (Throwable ex) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.e(ex);
|
2018-09-04 18:06:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-15 09:46:25 +00:00
|
|
|
btnInbox.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
// Initialize
|
2018-09-04 18:06:22 +00:00
|
|
|
tvAccountDone.setText(null);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvAccountDone.setCompoundDrawables(null, null, null, null);
|
2018-12-13 09:43:30 +00:00
|
|
|
tvNoPrimaryDrafts.setVisibility(View.GONE);
|
2018-09-07 12:34:54 +00:00
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
tvIdentityDone.setText(null);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvIdentityDone.setCompoundDrawables(null, null, null, null);
|
2019-01-15 09:46:25 +00:00
|
|
|
btnIdentity.setEnabled(false);
|
2018-09-07 12:34:54 +00:00
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
tvPermissionsDone.setText(null);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvPermissionsDone.setCompoundDrawables(null, null, null, null);
|
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
tvDozeDone.setText(null);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvDozeDone.setCompoundDrawables(null, null, null, null);
|
2019-01-15 09:46:25 +00:00
|
|
|
btnDoze.setEnabled(false);
|
2018-09-07 12:34:54 +00:00
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
btnData.setVisibility(View.GONE);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-01-15 09:46:25 +00:00
|
|
|
btnInbox.setEnabled(false);
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
int[] grantResults = new int[permissions.length];
|
|
|
|
for (int i = 0; i < permissions.length; i++)
|
|
|
|
grantResults[i] = ContextCompat.checkSelfPermission(getActivity(), permissions[i]);
|
|
|
|
|
2018-12-08 15:39:44 +00:00
|
|
|
checkPermissions(permissions, grantResults, true);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-06 12:29:14 +00:00
|
|
|
// Create outbox
|
2018-08-12 07:51:33 +00:00
|
|
|
new SimpleTask<Void>() {
|
2018-08-03 16:21:18 +00:00
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
2018-08-12 07:51:33 +00:00
|
|
|
DB db = DB.getInstance(context);
|
2018-08-12 12:47:52 +00:00
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
EntityFolder outbox = db.folder().getOutbox();
|
|
|
|
if (outbox == null) {
|
|
|
|
outbox = new EntityFolder();
|
|
|
|
outbox.name = "OUTBOX";
|
|
|
|
outbox.type = EntityFolder.OUTBOX;
|
2018-12-04 08:01:08 +00:00
|
|
|
outbox.level = 0;
|
2018-08-12 12:47:52 +00:00
|
|
|
outbox.synchronize = false;
|
2018-11-14 09:49:59 +00:00
|
|
|
outbox.sync_days = 0;
|
|
|
|
outbox.keep_days = 0;
|
2018-08-12 12:47:52 +00:00
|
|
|
outbox.id = db.folder().insertFolder(outbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
2018-08-03 16:21:18 +00:00
|
|
|
}
|
2018-08-12 12:47:52 +00:00
|
|
|
|
2018-08-11 16:50:30 +00:00
|
|
|
return null;
|
2018-08-03 16:21:18 +00:00
|
|
|
}
|
2018-08-11 16:50:30 +00:00
|
|
|
|
|
|
|
@Override
|
2018-08-12 07:51:33 +00:00
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2018-12-01 12:04:41 +00:00
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
2018-08-11 16:50:30 +00:00
|
|
|
}
|
2019-01-12 11:48:00 +00:00
|
|
|
}.execute(this, new Bundle(), "outbox:create");
|
2018-08-03 16:21:18 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2018-08-08 05:52:57 +00:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
2018-12-13 09:43:30 +00:00
|
|
|
final DB db = DB.getInstance(getContext());
|
2018-08-08 05:52:57 +00:00
|
|
|
|
2018-12-16 18:35:54 +00:00
|
|
|
db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
|
2018-12-13 09:43:30 +00:00
|
|
|
private boolean done = false;
|
|
|
|
private LiveData<EntityFolder> livePrimaryDrafts = null;
|
|
|
|
private LiveData<EntityFolder> livePrimaryArchive = null;
|
|
|
|
|
2018-08-08 05:52:57 +00:00
|
|
|
@Override
|
2018-12-16 18:35:54 +00:00
|
|
|
public void onChanged(@Nullable List<EntityAccount> accounts) {
|
2018-12-13 09:43:30 +00:00
|
|
|
done = (accounts != null && accounts.size() > 0);
|
|
|
|
|
2019-01-14 17:58:50 +00:00
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
|
2018-09-07 12:34:54 +00:00
|
|
|
tvAccountDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do);
|
2019-01-14 12:31:23 +00:00
|
|
|
tvAccountDone.setTextColor(done ? textColorPrimary : colorWarning);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvAccountDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null);
|
2018-12-13 09:43:30 +00:00
|
|
|
|
2019-01-15 09:46:25 +00:00
|
|
|
btnIdentity.setEnabled(done);
|
|
|
|
btnInbox.setEnabled(done);
|
|
|
|
|
2018-12-13 09:43:30 +00:00
|
|
|
if (livePrimaryDrafts == null)
|
|
|
|
livePrimaryDrafts = db.folder().livePrimaryDrafts();
|
|
|
|
else
|
|
|
|
livePrimaryDrafts.removeObservers(getViewLifecycleOwner());
|
|
|
|
|
|
|
|
if (livePrimaryArchive == null)
|
2018-12-16 07:40:41 +00:00
|
|
|
livePrimaryArchive = db.folder().livePrimaryArchive();
|
2018-12-13 09:43:30 +00:00
|
|
|
else
|
|
|
|
livePrimaryArchive.removeObservers(getViewLifecycleOwner());
|
|
|
|
|
|
|
|
livePrimaryDrafts.observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
|
|
|
|
@Override
|
|
|
|
public void onChanged(EntityFolder drafts) {
|
|
|
|
tvNoPrimaryDrafts.setVisibility(done && drafts == null ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
livePrimaryArchive.observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
|
|
|
|
@Override
|
|
|
|
public void onChanged(EntityFolder archive) {
|
2018-12-27 16:49:37 +00:00
|
|
|
PackageManager pm = getContext().getPackageManager();
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(getContext(), ActivitySearch.class),
|
|
|
|
archive == null
|
|
|
|
? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
|
|
|
: PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
2018-12-13 09:43:30 +00:00
|
|
|
}
|
|
|
|
});
|
2018-08-08 05:52:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-09 12:21:12 +00:00
|
|
|
db.identity().liveIdentities(null, true).observe(getViewLifecycleOwner(), new Observer<List<EntityIdentity>>() {
|
2018-08-08 05:52:57 +00:00
|
|
|
@Override
|
|
|
|
public void onChanged(@Nullable List<EntityIdentity> identities) {
|
2018-09-07 12:34:54 +00:00
|
|
|
boolean done = (identities != null && identities.size() > 0);
|
|
|
|
tvIdentityDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do);
|
2019-01-14 12:31:23 +00:00
|
|
|
tvIdentityDone.setTextColor(done ? textColorPrimary : colorWarning);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvIdentityDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null);
|
2018-08-08 05:52:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-04 18:06:22 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2018-12-09 17:49:52 +00:00
|
|
|
boolean ignoring = true;
|
2018-12-28 08:41:05 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
|
|
|
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
|
|
|
|
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
|
|
|
|
ignoring = pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
|
|
|
|
}
|
|
|
|
}
|
2018-09-04 18:06:22 +00:00
|
|
|
btnDoze.setEnabled(!ignoring);
|
|
|
|
tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do);
|
2019-01-14 12:31:23 +00:00
|
|
|
tvDozeDone.setTextColor(ignoring ? textColorPrimary : colorWarning);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null);
|
2018-09-04 18:06:22 +00:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
2018-12-09 17:49:52 +00:00
|
|
|
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
2018-09-04 18:06:22 +00:00
|
|
|
boolean saving = (cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED);
|
|
|
|
btnData.setVisibility(saving ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:58:50 +00:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_setup, menu);
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPrepareOptionsMenu(Menu menu) {
|
2019-01-15 09:46:25 +00:00
|
|
|
PackageManager pm = getContext().getPackageManager();
|
|
|
|
menu.findItem(R.id.menu_help).setVisible(getIntentHelp().resolveActivity(pm) != null);
|
2019-01-14 17:58:50 +00:00
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2019-01-15 09:46:25 +00:00
|
|
|
case R.id.menu_help:
|
|
|
|
onMenuHelp();
|
2019-01-14 17:58:50 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 09:46:25 +00:00
|
|
|
private void onMenuHelp() {
|
|
|
|
startActivity(getIntentHelp());
|
|
|
|
}
|
|
|
|
|
|
|
|
private Intent getIntentHelp() {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse("https://github.com/M66B/open-source-email/blob/master/SETUP.md#setup-help"));
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
2019-01-01 19:32:13 +00:00
|
|
|
if (requestCode == ActivitySetup.REQUEST_PERMISSION)
|
|
|
|
checkPermissions(permissions, grantResults, false);
|
2018-12-08 15:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkPermissions(String[] permissions, @NonNull int[] grantResults, boolean init) {
|
2018-08-02 13:33:06 +00:00
|
|
|
boolean has = (grantResults.length > 0);
|
|
|
|
for (int result : grantResults)
|
|
|
|
if (result != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
has = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-15 11:34:21 +00:00
|
|
|
tvPermissionsDone.setText(has ? R.string.title_setup_done : R.string.title_setup_to_do);
|
2019-01-14 12:31:23 +00:00
|
|
|
tvPermissionsDone.setTextColor(has ? textColorPrimary : colorWarning);
|
2018-09-07 12:34:54 +00:00
|
|
|
tvPermissionsDone.setCompoundDrawablesWithIntrinsicBounds(has ? check : null, null, null, null);
|
2019-01-15 09:46:25 +00:00
|
|
|
btnPermissions.setEnabled(!has);
|
2018-12-08 08:17:18 +00:00
|
|
|
|
2018-12-08 15:39:44 +00:00
|
|
|
if (has && !init)
|
2018-12-08 08:17:18 +00:00
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
2018-12-08 08:17:18 +00:00
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
for (EntityFolder folder : db.folder().getFoldersSynchronizing())
|
|
|
|
EntityOperation.sync(db, folder.id);
|
|
|
|
return null;
|
|
|
|
}
|
2018-12-11 10:31:31 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
|
|
|
}
|
2019-01-12 11:48:00 +00:00
|
|
|
}.execute(FragmentSetup.this, new Bundle(), "setup:sync");
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|