fix expiry check in edit key ui
This commit is contained in:
@@ -24,6 +24,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -36,6 +37,8 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -72,16 +75,18 @@ public class EditSubkeyExpiryDialogFragment extends DialogFragment {
|
|||||||
/**
|
/**
|
||||||
* Creates dialog
|
* Creates dialog
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
|
||||||
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
||||||
long creation = getArguments().getLong(ARG_CREATION);
|
long creation = getArguments().getLong(ARG_CREATION);
|
||||||
long expiry = getArguments().getLong(ARG_EXPIRY);
|
long expiry = getArguments().getLong(ARG_EXPIRY);
|
||||||
|
|
||||||
Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
final Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||||
creationCal.setTime(new Date(creation * 1000));
|
creationCal.setTime(new Date(creation * 1000));
|
||||||
final Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||||
expiryCal.setTime(new Date(expiry * 1000));
|
expiryCal.setTime(new Date(expiry * 1000));
|
||||||
|
|
||||||
// date picker works with default time zone, we need to convert from UTC to default timezone
|
// date picker works with default time zone, we need to convert from UTC to default timezone
|
||||||
@@ -175,10 +180,13 @@ public class EditSubkeyExpiryDialogFragment extends DialogFragment {
|
|||||||
selectedCal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
selectedCal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
||||||
long numDays = (selectedCal.getTimeInMillis() / 86400000)
|
long numDays = (selectedCal.getTimeInMillis() / 86400000)
|
||||||
- (expiryCal.getTimeInMillis() / 86400000);
|
- (creationCal.getTimeInMillis() / 86400000);
|
||||||
if (numDays <= 0) {
|
if (numDays <= 0) {
|
||||||
Log.e(Constants.TAG, "Should not happen! Expiry num of days <= 0!");
|
Activity activity = getActivity();
|
||||||
throw new RuntimeException();
|
if (activity != null) {
|
||||||
|
Notify.create(activity, R.string.error_expiry_past, Style.ERROR).show();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
expiry = selectedCal.getTime().getTime() / 1000;
|
expiry = selectedCal.getTime().getTime() / 1000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1434,7 +1434,8 @@
|
|||||||
<string name="file_delete_exception">"Original file could not be deleted!"</string>
|
<string name="file_delete_exception">"Original file could not be deleted!"</string>
|
||||||
<string name="error_clipboard_empty">"Clipboard is empty!"</string>
|
<string name="error_clipboard_empty">"Clipboard is empty!"</string>
|
||||||
<string name="error_clipboard_copy">"Error copying data to clipboard!"</string>
|
<string name="error_clipboard_copy">"Error copying data to clipboard!"</string>
|
||||||
<string name="error_scan_fp">Error scanning fingerprint!</string>
|
<string name="error_scan_fp">"Error scanning fingerprint!"</string>
|
||||||
<string name="error_scan_match">Fingerprints did not match!</string>
|
<string name="error_scan_match">"Fingerprints did not match!"</string>
|
||||||
|
<string name="error_expiry_past">"Expiry date is in the past!"</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user