parent
39160c8ff0
commit
ba73cf9bcf
@ -0,0 +1,81 @@ |
||||
package xyz.fycz.myreader.ui.activity |
||||
|
||||
import android.os.Bundle |
||||
import android.text.TextUtils |
||||
import androidx.appcompat.widget.Toolbar |
||||
import xyz.fycz.myreader.R |
||||
import xyz.fycz.myreader.application.App |
||||
import xyz.fycz.myreader.base.BaseActivity |
||||
import xyz.fycz.myreader.base.adapter2.onClick |
||||
import xyz.fycz.myreader.databinding.ActivityRemoveAdBinding |
||||
import xyz.fycz.myreader.util.help.RelativeDateHelp |
||||
import xyz.fycz.myreader.util.utils.AdUtils |
||||
|
||||
/** |
||||
* @author fengyue |
||||
* @date 2022/3/3 17:04 |
||||
*/ |
||||
class RemoveAdActivity : BaseActivity() { |
||||
private lateinit var binding: ActivityRemoveAdBinding |
||||
private var rewardLastTime = 0L |
||||
|
||||
override fun bindView() { |
||||
binding = ActivityRemoveAdBinding.inflate(layoutInflater) |
||||
setContentView(binding.root) |
||||
} |
||||
|
||||
override fun setUpToolbar(toolbar: Toolbar?) { |
||||
super.setUpToolbar(toolbar) |
||||
setStatusBarColor(R.color.colorPrimary, true) |
||||
supportActionBar?.title = getString(R.string.remove_ad) |
||||
} |
||||
|
||||
override fun initData(savedInstanceState: Bundle?) { |
||||
super.initData(savedInstanceState) |
||||
initRewardTime() |
||||
} |
||||
|
||||
fun initRewardTime() { |
||||
kotlin.runCatching { |
||||
val rewardTime = AdUtils.getSp().getString("rewardLastTime") |
||||
if (!TextUtils.isEmpty(rewardTime)) { |
||||
rewardLastTime = AdUtils.SDF.parse(rewardTime).time |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun initWidget() { |
||||
super.initWidget() |
||||
countRewardTime() |
||||
binding.tvTip.text = getString( |
||||
R.string.remove_ad_tip, |
||||
AdUtils.getAdConfig().removeAdTime, |
||||
AdUtils.getAdConfig().totalRemove, |
||||
AdUtils.getAdConfig().maxRemove |
||||
) |
||||
} |
||||
|
||||
private fun countRewardTime() { |
||||
val dur = rewardLastTime - System.currentTimeMillis() |
||||
if (dur > 0) { |
||||
binding.tvCurRemoveAdTime.text = getString( |
||||
R.string.cur_remove_ad_time, |
||||
RelativeDateHelp.formatDuring(dur) |
||||
) |
||||
App.getHandler().postDelayed({ countRewardTime() }, 1000) |
||||
} else { |
||||
binding.tvCurRemoveAdTime.text = getString(R.string.cur_remove_ad_time, "无记录") |
||||
} |
||||
} |
||||
|
||||
override fun initClick() { |
||||
super.initClick() |
||||
binding.rlRewardVideo.onClick { |
||||
AdUtils.showRewardVideoAd(this) { |
||||
AdUtils.removeAdReward() |
||||
initRewardTime() |
||||
countRewardTime() |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<include layout="@layout/toolbar" /> |
||||
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/tv_tip" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@color/colorForeground" |
||||
android:padding="15dp" |
||||
android:text="@string/remove_ad_tip" |
||||
android:textColor="@color/textSecondary" |
||||
android:textSize="@dimen/text_small_size" /> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/ll_splash_ad_times" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="60dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:orientation="vertical" |
||||
android:paddingLeft="20dp" |
||||
android:paddingTop="8dp" |
||||
android:paddingRight="20dp"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/remove_ad_reward" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/tv_cur_remove_ad_time" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:paddingTop="5dp" |
||||
android:text="@string/cur_remove_ad_time" |
||||
android:textColor="@color/textSecondary" /> |
||||
</LinearLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_reward_video" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:paddingLeft="20dp" |
||||
android:paddingRight="20dp"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/watch_rewarded_video" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
</RelativeLayout> |
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue