Added FFSend limits

pull/209/head
M66B 2 years ago
parent 2b5848ddaa
commit f3e7b25e43

@ -5,6 +5,8 @@ import androidx.documentfile.provider.DocumentFile;
import java.io.InputStream;
public class FFSend {
static final int FF_DEFAULT_DLIMIT = 0;
static final int FF_DEFAULT_TLIMIT = 0;
static final String FF_DEFAULT_SERVER = "";
static final String FF_INSTANCES = "";

@ -49,6 +49,8 @@ public class FFSend {
--data '{"owner_token": "..."}'
*/
static final int FF_DEFAULT_DLIMIT = 10;
static final int FF_DEFAULT_TLIMIT = 36; // hours
static final String FF_DEFAULT_SERVER = "https://send.vis.ee/";
static final String FF_INSTANCES = "https://github.com/timvisee/send-instances/";

@ -45,6 +45,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.documentfile.provider.DocumentFile;
import androidx.preference.PreferenceManager;
@ -63,6 +64,8 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
private EditText etTitle;
private Button btnUpload;
private ProgressBar pbUpload;
private EditText etDlimit;
private EditText etTlimit;
private static final int METADATA_CONNECT_TIMEOUT = 10 * 1000; // milliseconds
private static final int METADATA_READ_TIMEOUT = 15 * 1000; // milliseconds
@ -91,6 +94,9 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
final ProgressBar pbWait = view.findViewById(R.id.pbWait);
btnUpload = view.findViewById(R.id.btnUpload);
pbUpload = view.findViewById(R.id.pbUpload);
etDlimit = view.findViewById(R.id.etDlimit);
etTlimit = view.findViewById(R.id.etTlimit);
Group grpUpload = view.findViewById(R.id.grpUpload);
etLink.addTextChangedListener(new TextWatcher() {
@Override
@ -257,9 +263,12 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
etTitle.setText(savedInstanceState.getString("fair:text"));
}
btnUpload.setVisibility(BuildConfig.PLAY_STORE_RELEASE ? View.GONE : View.VISIBLE);
etDlimit.setHint(Integer.toString(FFSend.FF_DEFAULT_DLIMIT));
etTlimit.setHint(Integer.toString(FFSend.FF_DEFAULT_TLIMIT));
pbWait.setVisibility(View.GONE);
pbUpload.setVisibility(View.GONE);
grpUpload.setVisibility(BuildConfig.PLAY_STORE_RELEASE ? View.GONE : View.VISIBLE);
return new AlertDialog.Builder(context)
.setView(view)
@ -300,23 +309,32 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
private void onFFSend(Uri uri) {
Bundle args = new Bundle();
args.putParcelable("uri", uri);
args.putString("dlimit", etDlimit.getText().toString());
args.putString("tlimit", etTlimit.getText().toString());
new SimpleTask<String>() {
@Override
protected void onPreExecute(Bundle args) {
btnUpload.setEnabled(false);
etDlimit.setEnabled(false);
etTlimit.setEnabled(false);
pbUpload.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Bundle args) {
btnUpload.setEnabled(true);
etDlimit.setEnabled(true);
etTlimit.setEnabled(true);
pbUpload.setVisibility(View.GONE);
}
@Override
protected String onExecute(Context context, Bundle args) throws Throwable {
Uri uri = args.getParcelable("uri");
String _dlimit = args.getString("dlimit");
String _tlimit = args.getString("tlimit");
if (uri == null)
throw new FileNotFoundException("uri");
@ -327,6 +345,9 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
if (dfile == null)
throw new FileNotFoundException("dfile");
int dlimit = (TextUtils.isEmpty(_dlimit) ? FFSend.FF_DEFAULT_DLIMIT : Integer.parseInt(_dlimit));
int tlimit = (TextUtils.isEmpty(_tlimit) ? FFSend.FF_DEFAULT_TLIMIT : Integer.parseInt(_tlimit));
args.putString("title", dfile.getName());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -334,7 +355,7 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
ContentResolver resolver = context.getContentResolver();
try (InputStream is = resolver.openInputStream(uri)) {
return FFSend.upload(is, dfile, 10, 60 * 60, server);
return FFSend.upload(is, dfile, dlimit, tlimit * 60 * 60, server);
}
}

@ -138,5 +138,57 @@
app:layout_constraintBottom_toBottomOf="@id/btnUpload"
app:layout_constraintStart_toEndOf="@id/btnUpload"
app:layout_constraintTop_toTopOf="@id/btnUpload" />
<TextView
android:id="@+id/tvDLimit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:labelFor="@+id/etLink"
android:text="@string/title_style_link_ffsend_dlimit"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnUpload" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etDlimit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="3"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDLimit" />
<TextView
android:id="@+id/tvTLimit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:labelFor="@+id/etLink"
android:text="@string/title_style_link_ffsend_tlimit"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDlimit" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etTlimit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="3"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTLimit" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpUpload"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="btnUpload,tvDLimit,etDlimit,tvTLimit,etTlimit" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>

@ -1420,6 +1420,8 @@
<string name="title_style_link_metadata">Fetch title</string>
<string name="title_style_link_metadata_remark">This will fetch the title at the entered address</string>
<string name="title_style_link_ffsend" translatable="false">FFSend</string>
<string name="title_style_link_ffsend_dlimit" translatable="false">Download limit (count)</string>
<string name="title_style_link_ffsend_tlimit" translatable="false">Time limit (hours)</string>
<string name="title_add_image">Add image</string>
<string name="title_add_image_inline">Insert</string>

Loading…
Cancel
Save