pull/21/head
fengyuecanzhu 3 years ago
parent 39160c8ff0
commit ba73cf9bcf
  1. 2
      .idea/misc.xml
  2. 1
      app/src/main/AndroidManifest.xml
  3. 3
      app/src/main/java/xyz/fycz/myreader/application/App.java
  4. 81
      app/src/main/java/xyz/fycz/myreader/ui/activity/RemoveAdActivity.kt
  5. 3
      app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java
  6. 69
      app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java
  7. 64
      app/src/main/res/layout/activity_remove_ad.xml
  8. 9
      app/src/main/res/layout/fragment_mine.xml
  9. 5
      app/src/main/res/values/strings.xml

@ -15,6 +15,7 @@
<entry key="..\:/android/FYReader/app/src/main/res/drawable/reboot_ic.xml" value="0.20925925925925926" />
<entry key="..\:/android/FYReader/app/src/main/res/drawable/selector_btn_add.xml" value="0.17777777777777778" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_about.xml" value="0.12132725430597771" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_ad_setting.xml" value="0.21557971014492755" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_auth_email.xml" value="0.1897644927536232" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_book_detail.xml" value="0.12132725430597771" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_catalog.xml" value="0.21557971014492755" />
@ -28,6 +29,7 @@
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_more_setting.xml" value="0.264" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_read.xml" value="0.17028985507246377" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_register.xml" value="0.2796934865900383" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_remove_ad.xml" value="0.21557971014492755" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_search_book.xml" value="0.26904376012965964" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_search_word.xml" value="0.144" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_source_debug.xml" value="0.2391304347826087" />

@ -130,6 +130,7 @@
<activity android:name=".ui.activity.RestartActivity" />
<activity android:name=".ui.activity.CrashActivity" />
<activity android:name=".ui.activity.SourceSubscribeActivity" />
<activity android:name=".ui.activity.RemoveAdActivity" />
<receiver android:name=".util.notification.NotificationClickReceiver" />
<receiver android:name=".ui.presenter.BookcasePresenter$cancelDownloadReceiver" />

@ -88,8 +88,7 @@ public class App extends Application {
initNightTheme();
// LLog.init(APPCONST.LOG_DIR);
initDialogX();
if (!debug)
AdUtils.initAd();
AdUtils.initAd();
}

@ -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()
}
}
}
}

@ -57,6 +57,7 @@ import xyz.fycz.myreader.ui.activity.LoginActivity;
import xyz.fycz.myreader.ui.activity.MainActivity;
import xyz.fycz.myreader.ui.activity.MoreSettingActivity;
import xyz.fycz.myreader.ui.activity.ReadRecordActivity;
import xyz.fycz.myreader.ui.activity.RemoveAdActivity;
import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.ui.dialog.LoadingDialog;
import xyz.fycz.myreader.util.SharedPreUtils;
@ -408,7 +409,7 @@ public class MineFragment extends BaseFragment {
}).setCancelButton(R.string.cancel);
});
binding.mineRlAdSetting.setOnClickListener(v -> startActivity(new Intent(getActivity(), AdSettingActivity.class)));
binding.mineRlRemoveAd.setOnClickListener(v -> startActivity(new Intent(getActivity(), RemoveAdActivity.class)));
binding.mineRlAbout.setOnClickListener(v -> {
Intent aboutIntent = new Intent(getActivity(), AboutActivity.class);

@ -1,6 +1,7 @@
package xyz.fycz.myreader.util.utils;
import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@ -14,6 +15,11 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.annotations.NonNull;
@ -26,6 +32,7 @@ import xyz.fycz.myreader.entity.ad.AdBean;
import xyz.fycz.myreader.entity.ad.AdConfig;
import xyz.fycz.myreader.model.user.UserService;
import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.help.DateHelper;
/**
@ -36,6 +43,7 @@ public class AdUtils {
public static final String TAG = AdUtils.class.getSimpleName();
private static boolean hasInitAd = false;
private static AdConfig adConfig;
public static final DateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
static {
String config = getSp().getString("adConfig");
@ -51,6 +59,7 @@ public class AdUtils {
}
public static Single<Boolean> checkHasAd() {
if (hasRemoveAdReward()) return Single.just(false);
initAd();
return Single.create((SingleOnSubscribe<Boolean>) emitter -> {
boolean hasAd = false;
@ -175,7 +184,7 @@ public class AdUtils {
return currentTime - adConfigTime >= adConfig.getExpireTime() * 60L * 1000;
}
public static boolean adTime(String adTag, AdBean adBean){
public static boolean adTime(String adTag, AdBean adBean) {
if (adBean.getStatus() == 0) return false;
long adTime = getSp().getLong(adTag + "Time");
long currentTime = System.currentTimeMillis();
@ -293,6 +302,64 @@ public class AdUtils {
}
}
public static void removeAdReward() {
if (canAddReward()) {
try {
String rewardTime = getSp().getString("rewardLastTime");
long current = System.currentTimeMillis();
long rewardLastTime = System.currentTimeMillis();
if (!TextUtils.isEmpty(rewardTime)) {
rewardLastTime = SDF.parse(rewardTime).getTime();
}
if (rewardLastTime < current) rewardLastTime = current;
rewardLastTime += adConfig.getRemoveAdTime() * 60L * 60 * 1000;
getSp().putString("rewardLastTime", SDF.format(rewardLastTime));
rewardCountPlus();
} catch (ParseException e) {
e.printStackTrace();
ToastUtils.showError("" + e.getLocalizedMessage());
}
ToastUtils.showSuccess("奖励获取成功");
} else {
ToastUtils.showWarring("已达到单日最大获得奖励次数");
}
}
private static void rewardCountPlus() {
String today = DateHelper.getYearMonthDay1();
String[] rewardCount = getSp().getString("rewardCount").split(":");
int count;
if (today.equals(rewardCount[0])) {
count = Integer.parseInt(rewardCount[1]);
} else {
count = 0;
}
count++;
getSp().putString("rewardCount", today + ":" + count);
}
public static boolean canAddReward() {
String today = DateHelper.getYearMonthDay1();
String[] rewardCount = getSp().getString("rewardCount").split(":");
if (today.equals(rewardCount[0]) && rewardCount.length > 1) {
return Integer.parseInt(rewardCount[1]) < adConfig.getMaxRemove();
}
return true;
}
public static boolean hasRemoveAdReward() {
String rewardTime = getSp().getString("rewardLastTime");
long rewardLastTime = 0;
try {
if (!TextUtils.isEmpty(rewardTime)) {
rewardLastTime = SDF.parse(rewardTime).getTime();
}
} catch (ParseException e) {
e.printStackTrace();
}
return rewardLastTime > System.currentTimeMillis();
}
public static AdConfig getAdConfig() {
return adConfig;
}

@ -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>

@ -368,8 +368,7 @@
android:textSize="@dimen/text_normal_size" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/mine_rl_ad_setting"
android:visibility="gone"
android:id="@+id/mine_rl_remove_ad"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/selector_common_bg"
@ -377,7 +376,7 @@
android:paddingRight="20dp">
<ImageView
android:id="@+id/iv_ad_setting"
android:id="@+id/iv_remove_ad"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
@ -392,8 +391,8 @@
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_toEndOf="@id/iv_ad_setting"
android:text="@string/ad_setting"
android:layout_toEndOf="@id/iv_remove_ad"
android:text="@string/remove_ad"
android:textColor="@color/textSecondary"
android:textSize="@dimen/text_normal_size" />

@ -465,6 +465,10 @@
<string name="ad_setting">广告设置</string>
<string name="splash_ad">开屏广告</string>
<string name="splash_ad_times">每日广告显示次数</string>
<string name="remove_ad_reward">免广告奖励</string>
<string name="remove_ad">去除广告</string>
<string name="cur_remove_ad_time">当前免除广告时长:%s</string>
<string name="remove_ad_tip">去除广告规则\n1、观看激励视频即可去除应用内所有广告(包括开屏)\n2、每次观看完成可获得%d小时的免广告时间,最多可累计%d小时\n3、每日最多有%d次获得免广告时长的机会</string>
<string name="splash_cur_ad_times" formatted="false">当前次数:%s,今日已显示次数:%s</string>
<string name="ad">广告总开关</string>
<string name="book_detail_ad">详情页广告</string>
@ -479,6 +483,7 @@
<string name="ad_support_tip">点击下列广告即可支持作者,建议在WIFI环境下点击</string>
<string name="flow_ad_tip">信息流广告(下载的文件可在广告设置中清除)</string>
<string name="rewarded_video">激励视频</string>
<string name="watch_rewarded_video">观看激励视频</string>
<string name="ad_file">广告下载/缓存</string>
<string name="delete_ad_file">清除广告文件</string>
<string name="cover_path">封面地址</string>

Loading…
Cancel
Save