pref: 一键签到优化
This commit is contained in:
parent
5c2c573624
commit
c6127d66d8
|
|
@ -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_ERROR_MESSAGE
|
||||||
import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_STARTED
|
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_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.components.workers.OKSignWork.Companion.DATA_TOTAL_COUNT
|
||||||
|
import com.huanchengfly.tieba.post.utils.DateTimeUtils
|
||||||
import com.huanchengfly.tieba.post.widgets.CircleProgressView
|
import com.huanchengfly.tieba.post.widgets.CircleProgressView
|
||||||
|
|
||||||
class OKSignProgressAdapter(
|
class OKSignProgressAdapter(
|
||||||
|
|
@ -54,6 +56,7 @@ class OKSignProgressAdapter(
|
||||||
val currentPosition = it.getInt(DATA_CURRENT_POSITION, 0)
|
val currentPosition = it.getInt(DATA_CURRENT_POSITION, 0)
|
||||||
val totalCount = it.getInt(DATA_TOTAL_COUNT, 0)
|
val totalCount = it.getInt(DATA_TOTAL_COUNT, 0)
|
||||||
val accountNickname = it.getString(DATA_ACCOUNT_NICKNAME)
|
val accountNickname = it.getString(DATA_ACCOUNT_NICKNAME)
|
||||||
|
val timestamp = it.getLong(DATA_TIMESTAMP, System.currentTimeMillis())
|
||||||
if (success) {
|
if (success) {
|
||||||
holder.setVisibility(R.id.oksign_progress_close_btn, true)
|
holder.setVisibility(R.id.oksign_progress_close_btn, true)
|
||||||
holder.setVisibility(R.id.oksign_progress_progress, false)
|
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.setImageResource(R.id.oksign_progress_icon, R.drawable.ic_round_check)
|
||||||
holder.setText(
|
holder.setText(
|
||||||
R.id.oksign_progress_title,
|
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(
|
holder.setText(
|
||||||
R.id.oksign_progress_content,
|
R.id.oksign_progress_content,
|
||||||
|
|
|
||||||
|
|
@ -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.api.retrofit.exception.TiebaLocalException
|
||||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
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_SUCCESS
|
||||||
|
import com.huanchengfly.tieba.post.components.workers.OKSignWork.Companion.DATA_TIMESTAMP
|
||||||
import com.huanchengfly.tieba.post.interfaces.Refreshable
|
import com.huanchengfly.tieba.post.interfaces.Refreshable
|
||||||
import com.huanchengfly.tieba.post.models.database.TopForum
|
import com.huanchengfly.tieba.post.models.database.TopForum
|
||||||
import com.huanchengfly.tieba.post.utils.*
|
import com.huanchengfly.tieba.post.utils.*
|
||||||
|
|
@ -187,6 +188,7 @@ class MainForumListFragment : BaseFragment(), Refreshable, Toolbar.OnMenuItemCli
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
WorkManager.getInstance(attachContext).getWorkInfosForUniqueWork("OKSign").get()
|
WorkManager.getInstance(attachContext).getWorkInfosForUniqueWork("OKSign").get()
|
||||||
}
|
}
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
if (workInfos.isNotEmpty()) {
|
if (workInfos.isNotEmpty()) {
|
||||||
val workInfo = workInfos[0]
|
val workInfo = workInfos[0]
|
||||||
val id = workInfo.id
|
val id = workInfo.id
|
||||||
|
|
@ -198,10 +200,20 @@ class MainForumListFragment : BaseFragment(), Refreshable, Toolbar.OnMenuItemCli
|
||||||
val workInfoLiveData =
|
val workInfoLiveData =
|
||||||
WorkManager.getInstance(attachContext).getWorkInfoByIdLiveData(id)
|
WorkManager.getInstance(attachContext).getWorkInfoByIdLiveData(id)
|
||||||
workInfoLiveData.observe(viewLifecycleOwner) {
|
workInfoLiveData.observe(viewLifecycleOwner) {
|
||||||
|
if (it == null) {
|
||||||
|
workInfoLiveData.removeObservers(viewLifecycleOwner)
|
||||||
|
return@observe
|
||||||
|
}
|
||||||
if (it.progress.getBoolean(DATA_SUCCESS, false)) {
|
if (it.progress.getBoolean(DATA_SUCCESS, false)) {
|
||||||
workInfoLiveData.removeObservers(viewLifecycleOwner)
|
workInfoLiveData.removeObservers(viewLifecycleOwner)
|
||||||
}
|
}
|
||||||
if (it.progress.hasKeyWithValueOfType<Boolean>(DATA_SUCCESS)) {
|
if (DateTimeUtils.isToday(
|
||||||
|
it.progress.getLong(
|
||||||
|
DATA_TIMESTAMP,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
) && it.progress.hasKeyWithValueOfType<Boolean>(DATA_SUCCESS)
|
||||||
|
) {
|
||||||
okSignProgressData = it.progress
|
okSignProgressData = it.progress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -210,6 +222,7 @@ class MainForumListFragment : BaseFragment(), Refreshable, Toolbar.OnMenuItemCli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|
|
||||||
|
|
@ -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));
}
}
|
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);
}
}
|
||||||
|
|
@ -31,10 +31,14 @@ object DateTimeUtils {
|
||||||
) {
|
) {
|
||||||
if (calendar.get(Calendar.HOUR_OF_DAY) == currentCalendar.get(Calendar.HOUR_OF_DAY)) {
|
if (calendar.get(Calendar.HOUR_OF_DAY) == currentCalendar.get(Calendar.HOUR_OF_DAY)) {
|
||||||
if (calendar.get(Calendar.MINUTE) == currentCalendar.get(Calendar.MINUTE)) {
|
if (calendar.get(Calendar.MINUTE) == currentCalendar.get(Calendar.MINUTE)) {
|
||||||
|
if (calendar.get(Calendar.SECOND) == currentCalendar.get(Calendar.SECOND)) {
|
||||||
|
calendar.format(context.getString(R.string.relative_date_after))
|
||||||
|
} else {
|
||||||
context.getString(
|
context.getString(
|
||||||
R.string.relative_date_second,
|
R.string.relative_date_second,
|
||||||
currentCalendar.get(Calendar.SECOND) - calendar.get(Calendar.SECOND)
|
currentCalendar.get(Calendar.SECOND) - calendar.get(Calendar.SECOND)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
context.getString(
|
context.getString(
|
||||||
R.string.relative_date_minute,
|
R.string.relative_date_minute,
|
||||||
|
|
|
||||||
|
|
@ -391,10 +391,10 @@
|
||||||
<string name="my_info_about">关于</string>
|
<string name="my_info_about">关于</string>
|
||||||
<string name="pattern_date_long">yyyy-MM-dd</string>
|
<string name="pattern_date_long">yyyy-MM-dd</string>
|
||||||
<string name="pattern_date_short">M月dd日</string>
|
<string name="pattern_date_short">M月dd日</string>
|
||||||
<string name="relative_date_month">%d天前</string>
|
<string name="relative_date_month">%d 天前</string>
|
||||||
<string name="relative_date_hour">%d小时前</string>
|
<string name="relative_date_hour">%d 小时前</string>
|
||||||
<string name="relative_date_minute">%d分钟前</string>
|
<string name="relative_date_minute">%d 分钟前</string>
|
||||||
<string name="relative_date_second">%d秒前</string>
|
<string name="relative_date_second">%d 秒前</string>
|
||||||
<string name="relative_date_after">刚刚</string>
|
<string name="relative_date_after">刚刚</string>
|
||||||
<string name="title_forum_stat">贴吧数据</string>
|
<string name="title_forum_stat">贴吧数据</string>
|
||||||
<string name="title_forum_tops">置顶贴</string>
|
<string name="title_forum_tops">置顶贴</string>
|
||||||
|
|
@ -562,4 +562,5 @@
|
||||||
<string name="tip_check_ci_update">需要 App Center 账号且已加入测试,如果你没有,请不要开启此选项!</string>
|
<string name="tip_check_ci_update">需要 App Center 账号且已加入测试,如果你没有,请不要开启此选项!</string>
|
||||||
<string name="permission_name_post_notifications">通知</string>
|
<string name="permission_name_post_notifications">通知</string>
|
||||||
<string name="desc_permission_post_notifications">用于发送消息通知、显示一键签到进度</string>
|
<string name="desc_permission_post_notifications">用于发送消息通知、显示一键签到进度</string>
|
||||||
|
<string name="title_oksign_finish_time">%s签到完成</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue