Added FFSend option

pull/209/head
M66B 3 years ago
parent 4ba04ca05f
commit 9b9c6cb6a2

@ -10,7 +10,7 @@ public class FFSend {
static final String FF_DEFAULT_SERVER = ""; static final String FF_DEFAULT_SERVER = "";
static final String FF_INSTANCES = ""; static final String FF_INSTANCES = "";
public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String server) { public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String host) {
return null; return null;
} }
} }

@ -56,7 +56,7 @@ public class FFSend {
private static final int FF_TIMEOUT = 20 * 1000; private static final int FF_TIMEOUT = 20 * 1000;
public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String server) throws Throwable { public static String upload(InputStream is, DocumentFile dfile, int dLimit, int timeLimit, String host) throws Throwable {
String result; String result;
SecureRandom rnd = new SecureRandom(); SecureRandom rnd = new SecureRandom();
@ -65,7 +65,7 @@ public class FFSend {
JSONObject jupload = getMetadata(dfile, dLimit, timeLimit, secret); JSONObject jupload = getMetadata(dfile, dLimit, timeLimit, secret);
Uri uri = Uri.parse("wss://" + Uri.parse(server).getHost() + "/api/ws"); Uri uri = Uri.parse("wss://" + Uri.parse(host).getHost() + "/api/ws");
WebSocket ws = new WebSocketFactory().createSocket(uri.toString(), FF_TIMEOUT); WebSocket ws = new WebSocketFactory().createSocket(uri.toString(), FF_TIMEOUT);

@ -102,6 +102,9 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
sbTLimit = view.findViewById(R.id.sbTLimit); sbTLimit = view.findViewById(R.id.sbTLimit);
Group grpUpload = view.findViewById(R.id.grpUpload); Group grpUpload = view.findViewById(R.id.grpUpload);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean ffsend_enabled = prefs.getBoolean("ffsend_enabled", false);
etLink.addTextChangedListener(new TextWatcher() { etLink.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -306,7 +309,8 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
pbUpload.setVisibility(View.GONE); pbUpload.setVisibility(View.GONE);
grpUpload.setVisibility(BuildConfig.PLAY_STORE_RELEASE ? View.GONE : View.VISIBLE); grpUpload.setVisibility(ffsend_enabled && !BuildConfig.PLAY_STORE_RELEASE
? View.VISIBLE : View.GONE);
return new AlertDialog.Builder(context) return new AlertDialog.Builder(context)
.setView(view) .setView(view)
@ -391,11 +395,11 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
args.putString("title", dfile.getName()); args.putString("title", dfile.getName());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String server = prefs.getString("ff_send", FFSend.FF_DEFAULT_SERVER); String ffsend_host = prefs.getString("ffsend_host", FFSend.FF_DEFAULT_SERVER);
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
try (InputStream is = resolver.openInputStream(uri)) { try (InputStream is = resolver.openInputStream(uri)) {
return FFSend.upload(is, dfile, dlimit, tlimit * 60 * 60, server); return FFSend.upload(is, dfile, dlimit, tlimit * 60 * 60, ffsend_host);
} }
} }

@ -126,6 +126,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvVirusTotalPrivacy; private TextView tvVirusTotalPrivacy;
private EditText etVirusTotal; private EditText etVirusTotal;
private ImageButton ibVirusTotal; private ImageButton ibVirusTotal;
private SwitchCompat swFFSend;
private EditText etFFSend; private EditText etFFSend;
private ImageButton ibFFSend; private ImageButton ibFFSend;
private SwitchCompat swUpdates; private SwitchCompat swUpdates;
@ -229,7 +230,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
"sort_answers", "shortcuts", "fts", "sort_answers", "shortcuts", "fts",
"classification", "class_min_probability", "class_min_difference", "classification", "class_min_probability", "class_min_difference",
"language", "lt_enabled", "deepl_enabled", "vt_enabled", "vt_apikey", "ff_send", "language", "lt_enabled", "deepl_enabled", "vt_enabled", "vt_apikey", "ffsend_enabled", "ffsend_host",
"updates", "weekly", "show_changelog", "updates", "weekly", "show_changelog",
"crash_reports", "cleanup_attachments", "crash_reports", "cleanup_attachments",
"watchdog", "experiments", "main_log", "protocol", "log_level", "debug", "leak_canary", "watchdog", "experiments", "main_log", "protocol", "log_level", "debug", "leak_canary",
@ -320,6 +321,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvVirusTotalPrivacy = view.findViewById(R.id.tvVirusTotalPrivacy); tvVirusTotalPrivacy = view.findViewById(R.id.tvVirusTotalPrivacy);
etVirusTotal = view.findViewById(R.id.etVirusTotal); etVirusTotal = view.findViewById(R.id.etVirusTotal);
ibVirusTotal = view.findViewById(R.id.ibVirusTotal); ibVirusTotal = view.findViewById(R.id.ibVirusTotal);
swFFSend = view.findViewById(R.id.swFFSend);
etFFSend = view.findViewById(R.id.etFFSend); etFFSend = view.findViewById(R.id.etFFSend);
ibFFSend = view.findViewById(R.id.ibFFSend); ibFFSend = view.findViewById(R.id.ibFFSend);
swUpdates = view.findViewById(R.id.swUpdates); swUpdates = view.findViewById(R.id.swUpdates);
@ -695,6 +697,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
swFFSend.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("ffsend_enabled", checked).apply();
}
});
etFFSend.setHint(FFSend.FF_DEFAULT_SERVER); etFFSend.setHint(FFSend.FF_DEFAULT_SERVER);
etFFSend.addTextChangedListener(new TextWatcher() { etFFSend.addTextChangedListener(new TextWatcher() {
@Override @Override
@ -711,9 +720,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
String apikey = s.toString().trim(); String apikey = s.toString().trim();
if (TextUtils.isEmpty(apikey)) if (TextUtils.isEmpty(apikey))
prefs.edit().remove("ff_send").apply(); prefs.edit().remove("ffsend_host").apply();
else else
prefs.edit().putString("ff_send", apikey).apply(); prefs.edit().putString("ffsend_host", apikey).apply();
} }
}); });
@ -1742,7 +1751,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
if ("last_cleanup".equals(key)) if ("last_cleanup".equals(key))
setLastCleanup(prefs.getLong(key, -1)); setLastCleanup(prefs.getLong(key, -1));
if ("vt_apikey".equals(key) || "ff_send".equals(key)) if ("vt_apikey".equals(key) || "ffsend_host".equals(key))
return; return;
setOptions(); setOptions();
@ -1889,7 +1898,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false)); swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false));
swVirusTotal.setChecked(prefs.getBoolean("vt_enabled", false)); swVirusTotal.setChecked(prefs.getBoolean("vt_enabled", false));
etVirusTotal.setText(prefs.getString("vt_apikey", null)); etVirusTotal.setText(prefs.getString("vt_apikey", null));
etFFSend.setText(prefs.getString("ff_send", null)); swFFSend.setChecked(prefs.getBoolean("ffsend_enabled", false));
etFFSend.setText(prefs.getString("ffsend_host", null));
swUpdates.setChecked(prefs.getBoolean("updates", true)); swUpdates.setChecked(prefs.getBoolean("updates", true));
swCheckWeekly.setChecked(prefs.getBoolean("weekly", Helper.hasPlayStore(getContext()))); swCheckWeekly.setChecked(prefs.getBoolean("weekly", Helper.hasPlayStore(getContext())));
swCheckWeekly.setEnabled(swUpdates.isChecked()); swCheckWeekly.setEnabled(swUpdates.isChecked());

@ -359,7 +359,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_deepl" android:text="@string/title_advanced_deepl"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -439,18 +438,16 @@
app:layout_constraintTop_toBottomOf="@id/etVirusTotal" app:layout_constraintTop_toBottomOf="@id/etVirusTotal"
app:srcCompat="@drawable/twotone_info_24" /> app:srcCompat="@drawable/twotone_info_24" />
<TextView <androidx.appcompat.widget.SwitchCompat
android:id="@+id/tvFFSend" android:id="@+id/swFFSend"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:layout_marginEnd="48dp" android:text="@string/title_advanced_ffsend"
android:text="@string/title_advanced_ffsend_server"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibVirusTotal" /> app:layout_constraintTop_toBottomOf="@id/ibVirusTotal"
app:switchPadding="12dp" />
<EditText <EditText
android:id="@+id/etFFSend" android:id="@+id/etFFSend"
@ -462,7 +459,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFFSend" /> app:layout_constraintTop_toBottomOf="@id/swFFSend" />
<ImageButton <ImageButton
android:id="@+id/ibFFSend" android:id="@+id/ibFFSend"
@ -640,7 +637,7 @@
android:id="@+id/grpFFSend" android:id="@+id/grpFFSend"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="tvFFSend,etFFSend,ibFFSend" /> app:constraint_referenced_ids="swFFSend,etFFSend,ibFFSend" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpUpdates" android:id="@+id/grpUpdates"

@ -734,6 +734,7 @@
<string name="title_advanced_lt">LanguageTool integration</string> <string name="title_advanced_lt">LanguageTool integration</string>
<string name="title_advanced_deepl">DeepL integration</string> <string name="title_advanced_deepl">DeepL integration</string>
<string name="title_advanced_virus_total">VirusTotal integration</string> <string name="title_advanced_virus_total">VirusTotal integration</string>
<string name="title_advanced_ffsend" translatable="false">FFSend integration</string>
<string name="title_advanced_ffsend_server" translatable="false">FFSend server</string> <string name="title_advanced_ffsend_server" translatable="false">FFSend server</string>
<string name="title_advanced_sdcard">I want to use an sdcard</string> <string name="title_advanced_sdcard">I want to use an sdcard</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string> <string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>

Loading…
Cancel
Save