mirror of https://github.com/M66B/FairEmail.git
Added calendar selection
This commit is contained in:
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
|
||||
|
||||
@Database(
|
||||
version = 251,
|
||||
version = 252,
|
||||
entities = {
|
||||
EntityIdentity.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("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) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
|
|
|
@ -100,6 +100,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
|
|||
public String category;
|
||||
public String signature; // obsolete
|
||||
public Integer color;
|
||||
public String calendar;
|
||||
|
||||
@NonNull
|
||||
public Boolean synchronize;
|
||||
|
@ -287,6 +288,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
|
|||
json.put("name", name);
|
||||
json.put("category", category);
|
||||
json.put("color", color);
|
||||
json.put("calendar", calendar);
|
||||
|
||||
json.put("synchronize", synchronize);
|
||||
json.put("ondemand", ondemand);
|
||||
|
@ -366,6 +368,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
|
|||
account.category = json.getString("category");
|
||||
if (json.has("color"))
|
||||
account.color = json.getInt("color");
|
||||
account.calendar = json.optString("calendar", null);
|
||||
|
||||
account.synchronize = json.getBoolean("synchronize");
|
||||
if (json.has("ondemand"))
|
||||
|
@ -427,6 +430,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
|
|||
Objects.equals(this.name, other.name) &&
|
||||
Objects.equals(this.category, other.category) &&
|
||||
Objects.equals(this.color, other.color) &&
|
||||
Objects.equals(this.calendar, other.calendar) &&
|
||||
this.synchronize.equals(other.synchronize) &&
|
||||
this.primary.equals(other.primary) &&
|
||||
this.notify.equals(other.notify) &&
|
||||
|
|
|
@ -110,6 +110,8 @@ public class FragmentAccount extends FragmentBase {
|
|||
private ViewButtonColor btnColor;
|
||||
private TextView tvColorPro;
|
||||
|
||||
private Button btnCalendar;
|
||||
|
||||
private Button btnAdvanced;
|
||||
private CheckBox cbSynchronize;
|
||||
private CheckBox cbIgnoreSchedule;
|
||||
|
@ -169,12 +171,14 @@ public class FragmentAccount extends FragmentBase {
|
|||
private long copy = -1;
|
||||
private int auth = AUTH_TYPE_PASSWORD;
|
||||
private String provider = null;
|
||||
private String calendar = null;
|
||||
private String certificate = null;
|
||||
private boolean saving = false;
|
||||
|
||||
private static final int REQUEST_COLOR = 1;
|
||||
private static final int REQUEST_SAVE = 2;
|
||||
private static final int REQUEST_DELETE = 3;
|
||||
private static final int REQUEST_CALENDAR = 2;
|
||||
private static final int REQUEST_SAVE = 3;
|
||||
private static final int REQUEST_DELETE = 4;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -223,6 +227,8 @@ public class FragmentAccount extends FragmentBase {
|
|||
btnColor = view.findViewById(R.id.btnColor);
|
||||
tvColorPro = view.findViewById(R.id.tvColorPro);
|
||||
|
||||
btnCalendar = view.findViewById(R.id.btnCalendar);
|
||||
|
||||
btnAdvanced = view.findViewById(R.id.btnAdvanced);
|
||||
cbSynchronize = view.findViewById(R.id.cbSynchronize);
|
||||
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);
|
||||
|
||||
btnAdvanced.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -895,6 +915,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
args.putString("name", etName.getText().toString());
|
||||
args.putString("category", etCategory.getText().toString());
|
||||
args.putInt("color", btnColor.getColor());
|
||||
args.putString("calendar", calendar);
|
||||
|
||||
args.putBoolean("synchronize", cbSynchronize.isChecked());
|
||||
args.putBoolean("ignore_schedule", cbIgnoreSchedule.isChecked());
|
||||
|
@ -969,6 +990,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
String name = args.getString("name");
|
||||
String category = args.getString("category");
|
||||
Integer color = args.getInt("color");
|
||||
String calendar = args.getString("calendar");
|
||||
|
||||
boolean synchronize = args.getBoolean("synchronize");
|
||||
boolean ignore_schedule = args.getBoolean("ignore_schedule");
|
||||
|
@ -1068,6 +1090,8 @@ public class FragmentAccount extends FragmentBase {
|
|||
return true;
|
||||
if (!Objects.equals(account.color, color))
|
||||
return true;
|
||||
if (!Objects.equals(account.calendar, calendar))
|
||||
return true;
|
||||
if (!Objects.equals(account.synchronize, synchronize))
|
||||
return true;
|
||||
if (ignore_schedule != jconditions.optBoolean("ignore_schedule"))
|
||||
|
@ -1220,6 +1244,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
account.name = name;
|
||||
account.category = category;
|
||||
account.color = color;
|
||||
account.calendar = calendar;
|
||||
|
||||
account.synchronize = synchronize;
|
||||
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:auth", auth);
|
||||
outState.putString("fair:authprovider", provider);
|
||||
outState.putString("fair:calendar", calendar);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
@ -1618,6 +1644,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
|
||||
auth = (account == null ? AUTH_TYPE_PASSWORD : account.auth_type);
|
||||
provider = (account == null ? null : account.provider);
|
||||
calendar = (account == null ? null : account.calendar);
|
||||
|
||||
new SimpleTask<EntityAccount>() {
|
||||
@Override
|
||||
|
@ -1648,6 +1675,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
grpAdvanced.setVisibility(savedInstanceState.getInt("fair:advanced"));
|
||||
auth = savedInstanceState.getInt("fair:auth");
|
||||
provider = savedInstanceState.getString("fair:authprovider");
|
||||
calendar = savedInstanceState.getString("fair:calendar");
|
||||
}
|
||||
|
||||
Helper.setViewsEnabled(view, true);
|
||||
|
@ -1836,6 +1864,15 @@ public class FragmentAccount extends FragmentBase {
|
|||
startActivity(new Intent(getContext(), ActivityBilling.class));
|
||||
}
|
||||
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:
|
||||
if (resultCode == RESULT_OK) {
|
||||
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.USER.equals(folder.type)));
|
||||
|
||||
if (!permission || !received || account == null)
|
||||
if (!permission || !received || account == null || account.calendar == null)
|
||||
EntityLog.log(context, "Event not processed" +
|
||||
" permission=" + permission +
|
||||
" account=" + (account != null) +
|
||||
" calendar=" + (account == null ? null : account.calendar) +
|
||||
" folder=" + (folder != null) + ":" + (folder == null ? null : folder.type) +
|
||||
" received=" + received);
|
||||
else {
|
||||
|
@ -3718,7 +3719,7 @@ public class MessageHelper {
|
|||
String uid = (event.getUid() == null ? null : event.getUid().getValue());
|
||||
|
||||
EntityLog.log(context, EntityLog.Type.General, message, "Processing event" +
|
||||
" uid=" + uid + " method=" + method);
|
||||
" uid=" + uid + " method=" + method + " calendar=" + account.calendar);
|
||||
|
||||
if (icalendar.getMethod() != null &&
|
||||
start != null && end != null &&
|
||||
|
@ -3747,7 +3748,7 @@ public class MessageHelper {
|
|||
CalendarContract.Calendars.VISIBLE + " = 1 AND " +
|
||||
CalendarContract.Calendars.IS_PRIMARY + " = 1 AND " +
|
||||
CalendarContract.Calendars.ACCOUNT_NAME + " = ?",
|
||||
new String[]{account.user},
|
||||
new String[]{account.calendar},
|
||||
null)) {
|
||||
if (cursor.getCount() == 0)
|
||||
EntityLog.log(context, EntityLog.Type.General, message,
|
||||
|
|
|
@ -458,6 +458,16 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
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
|
||||
android:id="@+id/btnAdvanced"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
|
@ -468,7 +478,7 @@
|
|||
android:drawablePadding="6dp"
|
||||
android:text="@string/title_setup_advanced"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvColorPro" />
|
||||
app:layout_constraintTop_toBottomOf="@id/btnCalendar" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbSynchronize"
|
||||
|
|
|
@ -959,6 +959,7 @@
|
|||
<string name="title_advanced_swipe_sensitivity">Left/right swipe sensitivity</string>
|
||||
|
||||
<string name="title_select">Select …</string>
|
||||
<string name="title_select_calendar">Select calendar …</string>
|
||||
<string name="title_identity_name">Your name</string>
|
||||
<string name="title_identity_email">Your email address</string>
|
||||
<string name="title_identity_tenant" translatable="false">Tenant ID</string>
|
||||
|
|
Loading…
Reference in New Issue