Skip to content

Commit c7b75e5

Browse files
Fix for issue #47
1 parent 3385952 commit c7b75e5

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

CHANGELOG.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
1-
v1.3.3 [Apr 2, 2017]
2-
========
1+
## v1.3.4
2+
3+
- [FIX]: Issue [#47](https://github.com/curioustechizen/android-ago/issues/47)
4+
- [TRANSLATIONS]: Correct translations for Dutch, added Danish
5+
6+
7+
## v1.3.3 [Apr 2, 2017]
8+
39

410
- [CHANGE]: Bumped versions of compileSdkVersion, targetSdkVersion, Gradle, Android Gradle plugin and buildToolsVersion
511
- [TRANSLATIONS]: Spanish, Ukrainian, Norwegian, Arabic, Dutch, Romanian
612

713

8-
v1.3.2 [Jun 12, 2016]
9-
========
14+
## v1.3.2 [Jun 12, 2016]
15+
1016

1117
- [BUGFIX]: Fixed memory leak in `RelativeTimeTextView`
1218
- [TRANSLATIONS]: French, Portuguese
1319

1420

1521

16-
v1.3.1 [May 15, 2016]
17-
========
22+
## v1.3.1 [May 15, 2016]
23+
1824

1925
- [TRANSLATIONS]: Hebrew, Russian, Chinese, Slovak, German
2026

2127

22-
v1.3.0 [Feb 14, 2014]
23-
========
28+
## v1.3.0 [Feb 14, 2014]
29+
2430

2531
- [CHANGE]: Set minSdk to 8
2632
- [CHANGE]: Cleaned up unnecessary resources
2733
- [MISC]: Update to latest build tools
2834
- [NEW]: Included tasks for publishing to Maven Central
2935

3036

31-
v1.2.0 [Dec 16, 2014]
32-
========
37+
## v1.2.0 [Dec 16, 2014]
38+
3339

3440
- [BUGFIX]: NPE seen when the RelativeTimeTextView has an initial visibility="gone"
3541
- [BUGFIX]: RelativeTimeTextView does not show anything if the reference time was only set using the XML attribute reference_time
3642
- [MISC]: Updated gradle files to 1.0.0
3743

3844

39-
v1.1.1 [Sep 2, 2014]
40-
========
45+
## v1.1.1 [Sep 2, 2014]
46+
4147

4248
- [FEATURE]: Added option to add prefix and suffix to the RelativeTimeTextView (Credit @xiprox )
4349
- [MISC]: Updated to recent versions of gradle, gradle plugin, build tools.
4450

4551

4652

47-
v1.1.0 [Aug 21, 2014]
48-
========
53+
## v1.1.0 [Aug 21, 2014]
54+
4955

5056
- [FEATURE]: Added Gradle Support. (Credit to @intrications )
5157
- [BUGFIX]: #2

android-ago/src/com/github/curioustechizen/ago/RelativeTimeTextView.java

+23-14
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void setReferenceTime(long referenceTime) {
128128
/*
129129
* Instantiate a new runnable with the new reference time
130130
*/
131-
mUpdateTimeTask = new UpdateTimeRunnable(this, mReferenceTime);
131+
initUpdateTimeTask();
132132

133133
/*
134134
* Start a new schedule.
@@ -186,10 +186,15 @@ protected void onVisibilityChanged(View changedView, int visibility) {
186186
}
187187

188188
private void startTaskForPeriodicallyUpdatingRelativeTime() {
189+
if(mUpdateTimeTask.isDetached()) initUpdateTimeTask();
189190
mHandler.post(mUpdateTimeTask);
190191
isUpdateTaskRunning = true;
191192
}
192193

194+
private void initUpdateTimeTask() {
195+
mUpdateTimeTask = new UpdateTimeRunnable(this, mReferenceTime);
196+
}
197+
193198
private void stopTaskForPeriodicallyUpdatingRelativeTime() {
194199
if(isUpdateTaskRunning) {
195200
mUpdateTimeTask.detach();
@@ -247,26 +252,30 @@ private SavedState(Parcel in) {
247252
referenceTime = in.readLong();
248253
}
249254
}
250-
251-
private static class UpdateTimeRunnable implements Runnable{
252255

253-
private long mRefTime;
254-
private final WeakReference<RelativeTimeTextView> weakRefRttv;
255-
256-
UpdateTimeRunnable(RelativeTimeTextView rttv, long refTime){
257-
this.mRefTime = refTime;
256+
private static class UpdateTimeRunnable implements Runnable {
257+
258+
private long mRefTime;
259+
private final WeakReference<RelativeTimeTextView> weakRefRttv;
260+
261+
UpdateTimeRunnable(RelativeTimeTextView rttv, long refTime) {
262+
this.mRefTime = refTime;
258263
weakRefRttv = new WeakReference<>(rttv);
259264
}
260265

266+
boolean isDetached() {
267+
return weakRefRttv.get() == null;
268+
}
269+
261270
void detach() {
262271
weakRefRttv.clear();
263272
}
264273

265-
@Override
266-
public void run() {
274+
@Override
275+
public void run() {
267276
RelativeTimeTextView rttv = weakRefRttv.get();
268-
if(rttv == null) return;
269-
long difference = Math.abs(System.currentTimeMillis() - mRefTime);
277+
if (rttv == null) return;
278+
long difference = Math.abs(System.currentTimeMillis() - mRefTime);
270279
long interval = INITIAL_UPDATE_INTERVAL;
271280
if (difference > DateUtils.WEEK_IN_MILLIS) {
272281
interval = DateUtils.WEEK_IN_MILLIS;
@@ -277,7 +286,7 @@ public void run() {
277286
}
278287
rttv.updateTextDisplay();
279288
rttv.mHandler.postDelayed(this, interval);
280-
281-
}
289+
290+
}
282291
}
283292
}

0 commit comments

Comments
 (0)