Ensure we always have valid timestamps

Non-git repositories deserve love too!

Fixes #530

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2019-07-30 06:24:06 +05:30
parent c635704032
commit 36b0a41578
No known key found for this signature in database
GPG key ID: C2E74282C2133D62
2 changed files with 8 additions and 8 deletions

View file

@ -423,13 +423,13 @@ public class PasswordStore extends AppCompatActivity {
return fullPath.replace(repositoryPath, "").replaceAll("/+", "/"); return fullPath.replace(repositoryPath, "").replaceAll("/+", "/");
} }
public int getLastChangedTimestamp(String fullPath) { public long getLastChangedTimestamp(String fullPath) {
File repoPath = PasswordRepository.getRepositoryDirectory(this); File repoPath = PasswordRepository.getRepositoryDirectory(this);
Repository repository = PasswordRepository.getRepository(repoPath); Repository repository = PasswordRepository.getRepository(repoPath);
if (repository == null) { if (repository == null) {
Log.e(TAG, "getLastChangedTimestamp: No git repository"); Log.d(TAG, "getLastChangedTimestamp: No git repository");
return -1; return new File(fullPath).lastModified();
} }
Git git = new Git(repository); Git git = new Git(repository);
@ -453,7 +453,7 @@ public class PasswordStore extends AppCompatActivity {
return -1; return -1;
} }
return iterator.next().getCommitTime(); return iterator.next().getCommitTime() * 1000;
} }
public void decryptPassword(PasswordItem item) { public void decryptPassword(PasswordItem item) {

View file

@ -79,9 +79,9 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private val name: String by lazy { getName(fullPath) } private val name: String by lazy { getName(fullPath) }
private val lastChangedString: CharSequence by lazy { private val lastChangedString: CharSequence by lazy {
getLastChangedString( getLastChangedString(
intent.getIntExtra( intent.getLongExtra(
"LAST_CHANGED_TIMESTAMP", "LAST_CHANGED_TIMESTAMP",
-1 -1L
) )
) )
} }
@ -701,12 +701,12 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
* Gets a relative string describing when this shape was last changed * Gets a relative string describing when this shape was last changed
* (e.g. "one hour ago") * (e.g. "one hour ago")
*/ */
private fun getLastChangedString(timeStamp: Int): CharSequence { private fun getLastChangedString(timeStamp: Long): CharSequence {
if (timeStamp < 0) { if (timeStamp < 0) {
throw RuntimeException() throw RuntimeException()
} }
return DateUtils.getRelativeTimeSpanString(this, timeStamp.toLong() * 1000, true) return DateUtils.getRelativeTimeSpanString(this, timeStamp, true)
} }
@Suppress("StaticFieldLeak") @Suppress("StaticFieldLeak")