Added calendar selection

pull/209/head
M66B 2 years ago
parent 32c15e7800
commit dae313849d

File diff suppressed because it is too large Load Diff

@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 251, version = 252,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -2531,6 +2531,11 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `folder` ADD COLUMN `auto_classify_target` INTEGER NOT NULL DEFAULT 0"); db.execSQL("ALTER TABLE `folder` ADD COLUMN `auto_classify_target` INTEGER NOT NULL DEFAULT 0");
db.execSQL("UPDATE `folder` SET auto_classify_target = auto_classify WHERE auto_classify <> 0"); db.execSQL("UPDATE `folder` SET auto_classify_target = auto_classify WHERE auto_classify <> 0");
} }
}).addMigrations(new Migration(251, 252) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
db.execSQL("ALTER TABLE `account` ADD COLUMN `calendar` TEXT");
}
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -100,6 +100,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
public String category; public String category;
public String signature; // obsolete public String signature; // obsolete
public Integer color; public Integer color;
public String calendar;
@NonNull @NonNull
public Boolean synchronize; public Boolean synchronize;
@ -287,6 +288,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
json.put("name", name); json.put("name", name);
json.put("category", category); json.put("category", category);
json.put("color", color); json.put("color", color);
json.put("calendar", calendar);
json.put("synchronize", synchronize); json.put("synchronize", synchronize);
json.put("ondemand", ondemand); json.put("ondemand", ondemand);
@ -366,6 +368,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
account.category = json.getString("category"); account.category = json.getString("category");
if (json.has("color")) if (json.has("color"))
account.color = json.getInt("color"); account.color = json.getInt("color");
account.calendar = json.optString("calendar", null);
account.synchronize = json.getBoolean("synchronize"); account.synchronize = json.getBoolean("synchronize");
if (json.has("ondemand")) if (json.has("ondemand"))
@ -427,6 +430,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
Objects.equals(this.name, other.name) && Objects.equals(this.name, other.name) &&
Objects.equals(this.category, other.category) && Objects.equals(this.category, other.category) &&
Objects.equals(this.color, other.color) && Objects.equals(this.color, other.color) &&
Objects.equals(this.calendar, other.calendar) &&
this.synchronize.equals(other.synchronize) && this.synchronize.equals(other.synchronize) &&
this.primary.equals(other.primary) && this.primary.equals(other.primary) &&
this.notify.equals(other.notify) && this.notify.equals(other.notify) &&

@ -110,6 +110,8 @@ public class FragmentAccount extends FragmentBase {
private ViewButtonColor btnColor; private ViewButtonColor btnColor;
private TextView tvColorPro; private TextView tvColorPro;
private Button btnCalendar;
private Button btnAdvanced; private Button btnAdvanced;
private CheckBox cbSynchronize; private CheckBox cbSynchronize;
private CheckBox cbIgnoreSchedule; private CheckBox cbIgnoreSchedule;
@ -169,12 +171,14 @@ public class FragmentAccount extends FragmentBase {
private long copy = -1; private long copy = -1;
private int auth = AUTH_TYPE_PASSWORD; private int auth = AUTH_TYPE_PASSWORD;
private String provider = null; private String provider = null;
private String calendar = null;
private String certificate = null; private String certificate = null;
private boolean saving = false; private boolean saving = false;
private static final int REQUEST_COLOR = 1; private static final int REQUEST_COLOR = 1;
private static final int REQUEST_SAVE = 2; private static final int REQUEST_CALENDAR = 2;
private static final int REQUEST_DELETE = 3; private static final int REQUEST_SAVE = 3;
private static final int REQUEST_DELETE = 4;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -223,6 +227,8 @@ public class FragmentAccount extends FragmentBase {
btnColor = view.findViewById(R.id.btnColor); btnColor = view.findViewById(R.id.btnColor);
tvColorPro = view.findViewById(R.id.tvColorPro); tvColorPro = view.findViewById(R.id.tvColorPro);
btnCalendar = view.findViewById(R.id.btnCalendar);
btnAdvanced = view.findViewById(R.id.btnAdvanced); btnAdvanced = view.findViewById(R.id.btnAdvanced);
cbSynchronize = view.findViewById(R.id.cbSynchronize); cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbIgnoreSchedule = view.findViewById(R.id.cbIgnoreSchedule); cbIgnoreSchedule = view.findViewById(R.id.cbIgnoreSchedule);
@ -430,6 +436,20 @@ public class FragmentAccount extends FragmentBase {
} }
}); });
btnCalendar.setVisibility(BuildConfig.PLAY_STORE_RELEASE ? View.GONE : View.VISIBLE);
btnCalendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putString("account", calendar);
FragmentDialogCalendar fragment = new FragmentDialogCalendar();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentAccount.this, REQUEST_CALENDAR);
fragment.show(getParentFragmentManager(), "account:calendar");
}
});
Helper.linkPro(tvColorPro); Helper.linkPro(tvColorPro);
btnAdvanced.setOnClickListener(new View.OnClickListener() { btnAdvanced.setOnClickListener(new View.OnClickListener() {
@ -895,6 +915,7 @@ public class FragmentAccount extends FragmentBase {
args.putString("name", etName.getText().toString()); args.putString("name", etName.getText().toString());
args.putString("category", etCategory.getText().toString()); args.putString("category", etCategory.getText().toString());
args.putInt("color", btnColor.getColor()); args.putInt("color", btnColor.getColor());
args.putString("calendar", calendar);
args.putBoolean("synchronize", cbSynchronize.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("ignore_schedule", cbIgnoreSchedule.isChecked()); args.putBoolean("ignore_schedule", cbIgnoreSchedule.isChecked());
@ -969,6 +990,7 @@ public class FragmentAccount extends FragmentBase {
String name = args.getString("name"); String name = args.getString("name");
String category = args.getString("category"); String category = args.getString("category");
Integer color = args.getInt("color"); Integer color = args.getInt("color");
String calendar = args.getString("calendar");
boolean synchronize = args.getBoolean("synchronize"); boolean synchronize = args.getBoolean("synchronize");
boolean ignore_schedule = args.getBoolean("ignore_schedule"); boolean ignore_schedule = args.getBoolean("ignore_schedule");
@ -1068,6 +1090,8 @@ public class FragmentAccount extends FragmentBase {
return true; return true;
if (!Objects.equals(account.color, color)) if (!Objects.equals(account.color, color))
return true; return true;
if (!Objects.equals(account.calendar, calendar))
return true;
if (!Objects.equals(account.synchronize, synchronize)) if (!Objects.equals(account.synchronize, synchronize))
return true; return true;
if (ignore_schedule != jconditions.optBoolean("ignore_schedule")) if (ignore_schedule != jconditions.optBoolean("ignore_schedule"))
@ -1220,6 +1244,7 @@ public class FragmentAccount extends FragmentBase {
account.name = name; account.name = name;
account.category = category; account.category = category;
account.color = color; account.color = color;
account.calendar = calendar;
account.synchronize = synchronize; account.synchronize = synchronize;
jconditions.put("ignore_schedule", ignore_schedule); jconditions.put("ignore_schedule", ignore_schedule);
@ -1481,6 +1506,7 @@ public class FragmentAccount extends FragmentBase {
outState.putInt("fair:advanced", grpAuthorize == null ? View.VISIBLE : grpAdvanced.getVisibility()); outState.putInt("fair:advanced", grpAuthorize == null ? View.VISIBLE : grpAdvanced.getVisibility());
outState.putInt("fair:auth", auth); outState.putInt("fair:auth", auth);
outState.putString("fair:authprovider", provider); outState.putString("fair:authprovider", provider);
outState.putString("fair:calendar", calendar);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -1618,6 +1644,7 @@ public class FragmentAccount extends FragmentBase {
auth = (account == null ? AUTH_TYPE_PASSWORD : account.auth_type); auth = (account == null ? AUTH_TYPE_PASSWORD : account.auth_type);
provider = (account == null ? null : account.provider); provider = (account == null ? null : account.provider);
calendar = (account == null ? null : account.calendar);
new SimpleTask<EntityAccount>() { new SimpleTask<EntityAccount>() {
@Override @Override
@ -1648,6 +1675,7 @@ public class FragmentAccount extends FragmentBase {
grpAdvanced.setVisibility(savedInstanceState.getInt("fair:advanced")); grpAdvanced.setVisibility(savedInstanceState.getInt("fair:advanced"));
auth = savedInstanceState.getInt("fair:auth"); auth = savedInstanceState.getInt("fair:auth");
provider = savedInstanceState.getString("fair:authprovider"); provider = savedInstanceState.getString("fair:authprovider");
calendar = savedInstanceState.getString("fair:calendar");
} }
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
@ -1836,6 +1864,15 @@ public class FragmentAccount extends FragmentBase {
startActivity(new Intent(getContext(), ActivityBilling.class)); startActivity(new Intent(getContext(), ActivityBilling.class));
} }
break; break;
case REQUEST_CALENDAR:
if (resultCode == RESULT_OK && data != null) {
if (ActivityBilling.isPro(getContext()) || true) {
Bundle args = data.getBundleExtra("args");
calendar = args.getString("account");
} else
startActivity(new Intent(getContext(), ActivityBilling.class));
}
break;
case REQUEST_SAVE: case REQUEST_SAVE:
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
final boolean save = (btnSave.getVisibility() == View.VISIBLE); final boolean save = (btnSave.getVisibility() == View.VISIBLE);

@ -0,0 +1,124 @@
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-2022 by Marcel Bokhorst (M66B)
*/
import static android.app.Activity.RESULT_OK;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CalendarContract;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class FragmentDialogCalendar extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Context context = getContext();
final ContentResolver resolver = context.getContentResolver();
String selectedAccount = getArguments().getString("account");
List<Calendar> calendars = new ArrayList<>();
try (Cursor cursor = resolver.query(CalendarContract.Calendars.CONTENT_URI,
new String[]{
CalendarContract.Calendars._ID,
CalendarContract.Calendars.ACCOUNT_NAME,
CalendarContract.Calendars.ACCOUNT_TYPE
},
CalendarContract.Calendars.VISIBLE + " = 1 AND " +
CalendarContract.Calendars.IS_PRIMARY + " = 1",
null,
CalendarContract.Calendars.ACCOUNT_NAME)) {
while (cursor.moveToNext()) {
long id = cursor.getLong(0);
String account = cursor.getString(1);
String type = cursor.getString(2);
if (account != null)
calendars.add(new Calendar(id, account, type));
}
}
int checkedItem = -1;
List<String> names = new ArrayList<>();
for (int i = 0; i < calendars.size(); i++) {
Calendar calendar = calendars.get(i);
names.add(calendar.getTitle());
if (calendar.account.equals(selectedAccount))
checkedItem = i;
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.title_select_calendar);
builder.setSingleChoiceItems(names.toArray(new String[0]), checkedItem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Calendar calendar = calendars.get(which);
getArguments().putLong("id", calendar.id);
getArguments().putString("account", calendar.account);
getArguments().putString("type", calendar.type);
sendResult(RESULT_OK);
dismiss();
}
});
builder.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getArguments().putLong("id", -1);
getArguments().putString("account", null);
getArguments().putString("type", null);
sendResult(RESULT_OK);
}
});
builder.setPositiveButton(android.R.string.cancel, null);
return builder.create();
}
private class Calendar {
Calendar(long id, String account, String type) {
this.id = id;
this.account = account;
this.type = type;
}
private long id;
private String account;
private String type;
String getTitle() {
return (this.account == null ? "-" : this.account);
}
}
}

@ -3696,10 +3696,11 @@ public class MessageHelper {
EntityFolder.SYSTEM.equals(folder.type) || EntityFolder.SYSTEM.equals(folder.type) ||
EntityFolder.USER.equals(folder.type))); EntityFolder.USER.equals(folder.type)));
if (!permission || !received || account == null) if (!permission || !received || account == null || account.calendar == null)
EntityLog.log(context, "Event not processed" + EntityLog.log(context, "Event not processed" +
" permission=" + permission + " permission=" + permission +
" account=" + (account != null) + " account=" + (account != null) +
" calendar=" + (account == null ? null : account.calendar) +
" folder=" + (folder != null) + ":" + (folder == null ? null : folder.type) + " folder=" + (folder != null) + ":" + (folder == null ? null : folder.type) +
" received=" + received); " received=" + received);
else { else {
@ -3718,7 +3719,7 @@ public class MessageHelper {
String uid = (event.getUid() == null ? null : event.getUid().getValue()); String uid = (event.getUid() == null ? null : event.getUid().getValue());
EntityLog.log(context, EntityLog.Type.General, message, "Processing event" + EntityLog.log(context, EntityLog.Type.General, message, "Processing event" +
" uid=" + uid + " method=" + method); " uid=" + uid + " method=" + method + " calendar=" + account.calendar);
if (icalendar.getMethod() != null && if (icalendar.getMethod() != null &&
start != null && end != null && start != null && end != null &&
@ -3747,7 +3748,7 @@ public class MessageHelper {
CalendarContract.Calendars.VISIBLE + " = 1 AND " + CalendarContract.Calendars.VISIBLE + " = 1 AND " +
CalendarContract.Calendars.IS_PRIMARY + " = 1 AND " + CalendarContract.Calendars.IS_PRIMARY + " = 1 AND " +
CalendarContract.Calendars.ACCOUNT_NAME + " = ?", CalendarContract.Calendars.ACCOUNT_NAME + " = ?",
new String[]{account.user}, new String[]{account.calendar},
null)) { null)) {
if (cursor.getCount() == 0) if (cursor.getCount() == 0)
EntityLog.log(context, EntityLog.Type.General, message, EntityLog.log(context, EntityLog.Type.General, message,

@ -458,6 +458,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvColorHint" /> app:layout_constraintTop_toBottomOf="@id/tvColorHint" />
<Button
android:id="@+id/btnCalendar"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_select_calendar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvColorPro" />
<Button <Button
android:id="@+id/btnAdvanced" android:id="@+id/btnAdvanced"
style="?android:attr/buttonStyleSmall" style="?android:attr/buttonStyleSmall"
@ -468,7 +478,7 @@
android:drawablePadding="6dp" android:drawablePadding="6dp"
android:text="@string/title_setup_advanced" android:text="@string/title_setup_advanced"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvColorPro" /> app:layout_constraintTop_toBottomOf="@id/btnCalendar" />
<CheckBox <CheckBox
android:id="@+id/cbSynchronize" android:id="@+id/cbSynchronize"

@ -959,6 +959,7 @@
<string name="title_advanced_swipe_sensitivity">Left/right swipe sensitivity</string> <string name="title_advanced_swipe_sensitivity">Left/right swipe sensitivity</string>
<string name="title_select">Select &#8230;</string> <string name="title_select">Select &#8230;</string>
<string name="title_select_calendar">Select calendar &#8230;</string>
<string name="title_identity_name">Your name</string> <string name="title_identity_name">Your name</string>
<string name="title_identity_email">Your email address</string> <string name="title_identity_email">Your email address</string>
<string name="title_identity_tenant" translatable="false">Tenant ID</string> <string name="title_identity_tenant" translatable="false">Tenant ID</string>

Loading…
Cancel
Save