Added search on date

pull/178/head
M66B 5 years ago
parent 5a9dcd9f87
commit 506698ed03

@ -1,5 +1,6 @@
package eu.faircode.email;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
@ -14,8 +15,10 @@ import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.FilterQueryProvider;
import android.widget.ImageButton;
import android.widget.TextView;
@ -27,6 +30,9 @@ import androidx.constraintlayout.widget.Group;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.preference.PreferenceManager;
import java.text.DateFormat;
import java.util.Calendar;
public class FragmentDialogSearch extends FragmentDialogBase {
@NonNull
@Override
@ -48,6 +54,10 @@ public class FragmentDialogSearch extends FragmentDialogBase {
final CheckBox cbHidden = dview.findViewById(R.id.cbHidden);
final CheckBox cbEncrypted = dview.findViewById(R.id.cbEncrypted);
final CheckBox cbAttachments = dview.findViewById(R.id.cbAttachments);
final Button btnBefore = dview.findViewById(R.id.btnBefore);
final Button btnAfter = dview.findViewById(R.id.btnAfter);
final TextView tvBefore = dview.findViewById(R.id.tvBefore);
final TextView tvAfter = dview.findViewById(R.id.tvAfter);
final Group grpMore = dview.findViewById(R.id.grpMore);
boolean pro = ActivityBilling.isPro(getContext());
@ -175,6 +185,20 @@ public class FragmentDialogSearch extends FragmentDialogBase {
}
});
btnAfter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickDate(tvAfter);
}
});
btnBefore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickDate(tvBefore);
}
});
ibMore.setImageLevel(1);
cbSearchIndex.setChecked(fts && pro);
cbSearchIndex.setEnabled(pro);
@ -185,6 +209,8 @@ public class FragmentDialogSearch extends FragmentDialogBase {
cbMessage.setChecked(last_search_message);
cbUnseen.setChecked(filter_seen);
cbFlagged.setChecked(filter_unflagged);
tvAfter.setText(null);
tvBefore.setText(null);
grpMore.setVisibility(View.GONE);
@ -225,6 +251,14 @@ public class FragmentDialogSearch extends FragmentDialogBase {
criteria.with_attachments = cbAttachments.isChecked();
}
Object after = tvAfter.getTag();
Object before = tvBefore.getTag();
if (after != null)
criteria.after = ((Calendar) after).getTimeInMillis();
if (before != null)
criteria.before = ((Calendar) before).getTimeInMillis();
imm.hideSoftInputFromWindow(etQuery.getWindowToken(), 0);
FragmentMessages.search(
@ -258,4 +292,36 @@ public class FragmentDialogSearch extends FragmentDialogBase {
return dialog;
}
private void pickDate(TextView tv) {
Object tag = tv.getTag();
final Calendar cal = (tag == null ? Calendar.getInstance() : (Calendar) tag);
DatePickerDialog picker = new DatePickerDialog(getContext(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, day);
DateFormat DF = Helper.getDateInstance(getContext());
tv.setTag(cal);
tv.setText(DF.format(cal.getTime()));
}
},
cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
picker.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
tv.setTag(null);
tv.setText(null);
}
});
picker.show();
}
}

@ -217,10 +217,61 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbEncrypted" />
<Button
android:id="@+id/btnAfter"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:text="@string/title_search_with_after"
app:layout_constraintEnd_toStartOf="@id/btnBefore"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbAttachments" />
<Button
android:id="@+id/btnBefore"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:text="@string/title_search_with_before"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btnAfter"
app:layout_constraintTop_toBottomOf="@id/cbAttachments" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvAfter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="January 1st, 1970"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="@id/btnAfter"
app:layout_constraintStart_toStartOf="@id/btnAfter"
app:layout_constraintTop_toBottomOf="@id/btnAfter" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvBefore"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="January 1st, 1970"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="@id/btnBefore"
app:layout_constraintStart_toStartOf="@id/btnBefore"
app:layout_constraintTop_toBottomOf="@id/btnBefore" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpMore"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="cbSearchIndex,cbSenders,cbRecipients,cbSubject,cbKeywords,cbMessage,tvAnd,cbUnseen,cbFlagged,cbHidden,cbEncrypted,cbAttachments" />
app:constraint_referenced_ids="
cbSearchIndex,cbSenders,cbRecipients,cbSubject,cbKeywords,cbMessage,
tvAnd,cbUnseen,cbFlagged,cbHidden,cbEncrypted,cbAttachments,
btnAfter,btnBefore,tvBefore,tvAfter" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Loading…
Cancel
Save