From c6127d66d863816938c30950d113e751a66aca61 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Tue, 30 Aug 2022 16:49:59 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E4=B8=80=E9=94=AE=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/adapters/OKSignProgressAdapter.kt | 8 +++- .../post/fragments/MainForumListFragment.kt | 47 ++++++++++++------- .../post/services/OKSignTileService.java | 2 +- .../tieba/post/utils/DateTimeUtils.kt | 12 +++-- app/src/main/res/values/strings.xml | 9 ++-- 5 files changed, 51 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/adapters/OKSignProgressAdapter.kt b/app/src/main/java/com/huanchengfly/tieba/post/adapters/OKSignProgressAdapter.kt index dda8cef4..7305c4fa 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/adapters/OKSignProgressAdapter.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/adapters/OKSignProgressAdapter.kt @@ -16,7 +16,9 @@ import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_ import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_ERROR_MESSAGE import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_STARTED import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_SUCCESS +import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_TIMESTAMP import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_TOTAL_COUNT +import com.huanchengfly.tieba.post.utils.DateTimeUtils import com.huanchengfly.tieba.post.widgets.CircleProgressView class OKSignProgressAdapter( @@ -54,6 +56,7 @@ class OKSignProgressAdapter( val currentPosition = it.getInt(DATA_CURRENT_POSITION, 0) val totalCount = it.getInt(DATA_TOTAL_COUNT, 0) val accountNickname = it.getString(DATA_ACCOUNT_NICKNAME) + val timestamp = it.getLong(DATA_TIMESTAMP, System.currentTimeMillis()) if (success) { holder.setVisibility(R.id.oksign_progress_close_btn, true) holder.setVisibility(R.id.oksign_progress_progress, false) @@ -63,7 +66,10 @@ class OKSignProgressAdapter( holder.setImageResource(R.id.oksign_progress_icon, R.drawable.ic_round_check) holder.setText( R.id.oksign_progress_title, - context.getString(R.string.title_oksign_finish) + context.getString( + R.string.title_oksign_finish_time, + DateTimeUtils.getRelativeTimeString(context, timestamp) + ) ) holder.setText( R.id.oksign_progress_content, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/fragments/MainForumListFragment.kt b/app/src/main/java/com/huanchengfly/tieba/post/fragments/MainForumListFragment.kt index e3477a11..bfa3d461 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/fragments/MainForumListFragment.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/fragments/MainForumListFragment.kt @@ -34,6 +34,7 @@ import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaException import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaLocalException import com.huanchengfly.tieba.post.components.MyViewHolder import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_SUCCESS +import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_TIMESTAMP import com.huanchengfly.tieba.post.interfaces.Refreshable import com.huanchengfly.tieba.post.models.database.TopForum import com.huanchengfly.tieba.post.utils.* @@ -187,26 +188,38 @@ class MainForumListFragment : BaseFragment(), Refreshable, Toolbar.OnMenuItemCli withContext(Dispatchers.IO) { WorkManager.getInstance(attachContext).getWorkInfosForUniqueWork("OKSign").get() } - if (workInfos.isNotEmpty()) { - val workInfo = workInfos[0] - val id = workInfo.id - if (appPreferences.oksignWorkId != id.toString()) { - appPreferences.oksignWorkId = id.toString() - okSignProgressAdapter.data = null - okSignProgressAdapter.closed = false - } - val workInfoLiveData = - WorkManager.getInstance(attachContext).getWorkInfoByIdLiveData(id) - workInfoLiveData.observe(viewLifecycleOwner) { - if (it.progress.getBoolean(DATA_SUCCESS, false)) { - workInfoLiveData.removeObservers(viewLifecycleOwner) + withContext(Dispatchers.Main) { + if (workInfos.isNotEmpty()) { + val workInfo = workInfos[0] + val id = workInfo.id + if (appPreferences.oksignWorkId != id.toString()) { + appPreferences.oksignWorkId = id.toString() + okSignProgressAdapter.data = null + okSignProgressAdapter.closed = false } - if (it.progress.hasKeyWithValueOfType(DATA_SUCCESS)) { - okSignProgressData = it.progress + val workInfoLiveData = + WorkManager.getInstance(attachContext).getWorkInfoByIdLiveData(id) + workInfoLiveData.observe(viewLifecycleOwner) { + if (it == null) { + workInfoLiveData.removeObservers(viewLifecycleOwner) + return@observe + } + if (it.progress.getBoolean(DATA_SUCCESS, false)) { + workInfoLiveData.removeObservers(viewLifecycleOwner) + } + if (DateTimeUtils.isToday( + it.progress.getLong( + DATA_TIMESTAMP, + System.currentTimeMillis() + ) + ) && it.progress.hasKeyWithValueOfType(DATA_SUCCESS) + ) { + okSignProgressData = it.progress + } } + } else { + okSignProgressData = null } - } else { - okSignProgressData = null } } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignTileService.java b/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignTileService.java index c9c80f69..eb18dd1c 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignTileService.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignTileService.java @@ -1 +1 @@ -package com.huanchengfly.tieba.post.services; import android.annotation.TargetApi; import android.content.Intent; import android.service.quicksettings.Tile; import android.service.quicksettings.TileService; import com.huanchengfly.tieba.post.activities.OKSignActivity; @TargetApi(24) public class OKSignTileService extends TileService { @Override public void onStartListening() { super.onStartListening(); if (getQsTile() == null) { return; } getQsTile().setState(Tile.STATE_INACTIVE); getQsTile().updateTile(); } @Override public void onStopListening() { super.onStopListening(); if (getQsTile() == null) { return; } getQsTile().setState(Tile.STATE_INACTIVE); getQsTile().updateTile(); } @Override public void onClick() { super.onClick(); startActivity(new Intent(this, OKSignActivity.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } } \ No newline at end of file +package com.huanchengfly.tieba.post.services; import android.annotation.TargetApi; import android.service.quicksettings.Tile; import android.service.quicksettings.TileService; import com.huanchengfly.tieba.post.utils.TiebaUtil; @TargetApi(24) public class OKSignTileService extends TileService { @Override public void onStartListening() { super.onStartListening(); if (getQsTile() == null) { return; } getQsTile().setState(Tile.STATE_INACTIVE); getQsTile().updateTile(); } @Override public void onStopListening() { super.onStopListening(); if (getQsTile() == null) { return; } getQsTile().setState(Tile.STATE_INACTIVE); getQsTile().updateTile(); } @Override public void onClick() { super.onClick(); // startActivity(new Intent(this, OKSignActivity.class) // .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); TiebaUtil.startSign(this); } } \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/DateTimeUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/DateTimeUtils.kt index f07b106a..873d9ef7 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/DateTimeUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/DateTimeUtils.kt @@ -31,10 +31,14 @@ object DateTimeUtils { ) { if (calendar.get(Calendar.HOUR_OF_DAY) == currentCalendar.get(Calendar.HOUR_OF_DAY)) { if (calendar.get(Calendar.MINUTE) == currentCalendar.get(Calendar.MINUTE)) { - context.getString( - R.string.relative_date_second, - currentCalendar.get(Calendar.SECOND) - calendar.get(Calendar.SECOND) - ) + if (calendar.get(Calendar.SECOND) == currentCalendar.get(Calendar.SECOND)) { + calendar.format(context.getString(R.string.relative_date_after)) + } else { + context.getString( + R.string.relative_date_second, + currentCalendar.get(Calendar.SECOND) - calendar.get(Calendar.SECOND) + ) + } } else { context.getString( R.string.relative_date_minute, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ce3a7dd0..d52cba63 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -391,10 +391,10 @@ 关于 yyyy-MM-dd M月dd日 - %d天前 - %d小时前 - %d分钟前 - %d秒前 + %d 天前 + %d 小时前 + %d 分钟前 + %d 秒前 刚刚 贴吧数据 置顶贴 @@ -562,4 +562,5 @@ 需要 App Center 账号且已加入测试,如果你没有,请不要开启此选项! 通知 用于发送消息通知、显示一键签到进度 + %s签到完成