From 54ee1db3517e0022378e801f90f39fb7f9db7e26 Mon Sep 17 00:00:00 2001
From: fengyuecanzhu <1021300691@qq.com>
Date: Sat, 26 Mar 2022 10:59:42 +0800
Subject: [PATCH] fix sharedPre
---
.idea/jarRepositories.xml | 5 +
.idea/misc.xml | 2 +
.../myreader/ui/activity/AboutActivity.java | 3 +
.../myreader/ui/activity/DonateActivity.java | 21 +---
.../myreader/ui/activity/SplashActivity.java | 3 +-
.../fycz/myreader/util/SharedPreAdUtils.java | 115 ++++++++++++++++++
.../fycz/myreader/util/SharedPreUtils.java | 19 +--
.../xyz/fycz/myreader/util/utils/AdUtils.java | 24 +++-
app/src/main/res/layout/activity_donate.xml | 1 -
.../main/res/layout/layout_about_content.xml | 25 ++++
app/src/main/res/values/strings.xml | 3 +-
11 files changed, 182 insertions(+), 39 deletions(-)
create mode 100644 app/src/main/java/xyz/fycz/myreader/util/SharedPreAdUtils.java
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index ab56054..3783618 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -31,5 +31,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 7d3b213..88ef7a3 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,6 +3,7 @@
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java
index 68644aa..e160762 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java
@@ -32,6 +32,7 @@ import xyz.fycz.myreader.util.ShareUtils;
import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.ZipUtils;
+import xyz.fycz.myreader.util.utils.AdUtils;
import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.util.utils.OkHttpUtils;
import xyz.fycz.myreader.util.utils.RxUtils;
@@ -62,6 +63,7 @@ public class AboutActivity extends BaseActivity {
super.initWidget();
binding.il.tvVersionName.setText(String.format("风月读书v%s", App.getStrVersionName()));
binding.il.rlLanZou.setVisibility(App.isDebug() ? View.VISIBLE : View.GONE);
+ binding.il.rlResetPangle.setVisibility(App.isDebug() ? View.VISIBLE : View.GONE);
}
@Override
@@ -136,6 +138,7 @@ public class AboutActivity extends BaseActivity {
});
});
});
+ binding.il.rlResetPangle.setOnClickListener(v -> AdUtils.resetPangleId());
}
void openIntent(String intentName, String address) {
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java
index da2536c..8539add 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java
@@ -60,26 +60,7 @@ public class DonateActivity extends BaseActivity {
private void initAd() {
binding.llAdSupport.setVisibility(View.VISIBLE);
- /*new DdSdkFlowAd().getFlowViews(DonateActivity.this, 4, new DdSdkFlowAd.FlowCallback() {
- // 信息流广告拉取完毕后返回的 views
- @Override
- public void getFlowView(View view) {
- binding.llAdSupport.addView(view, 2);
- }
-
- // 信息流广告展示后调用
- @Override
- public void show() {
- AdUtils.adRecord("flow","adShow");
- Log.d(TAG, "信息流广告展示成功");
- }
-
- // 广告拉取失败调用
- @Override
- public void error(String msg) {
- Log.d(TAG, "广告拉取失败\n" + msg);
- }
- });*/
+ AdUtils.getFlowAd(this, 1, view -> binding.llAdSupport.addView(view, 2), null);
}
@Override
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java
index ede69cc..56ef387 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java
@@ -35,6 +35,7 @@ import xyz.fycz.myreader.databinding.ActivitySplashBinding;
import xyz.fycz.myreader.greendao.service.BookGroupService;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog;
import xyz.fycz.myreader.util.IOUtils;
+import xyz.fycz.myreader.util.SharedPreAdUtils;
import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.help.DateHelper;
@@ -220,7 +221,7 @@ public class SplashActivity extends BaseActivity {
@Override
public void show() {
handler.removeCallbacks(adTimeOutRunnable);
- SharedPreUtils.getInstance(true).putLong("splashAdTime", System.currentTimeMillis());
+ SharedPreAdUtils.getInstance().putLong("splashAdTime", System.currentTimeMillis());
Log.d(TAG, "广告展示成功");
AdUtils.adRecord("splash", "adShow");
countTodayAd();
diff --git a/app/src/main/java/xyz/fycz/myreader/util/SharedPreAdUtils.java b/app/src/main/java/xyz/fycz/myreader/util/SharedPreAdUtils.java
new file mode 100644
index 0000000..d3223f6
--- /dev/null
+++ b/app/src/main/java/xyz/fycz/myreader/util/SharedPreAdUtils.java
@@ -0,0 +1,115 @@
+package xyz.fycz.myreader.util;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+import xyz.fycz.myreader.application.App;
+
+import java.util.Map;
+
+/**
+ * SharedPreferences工具类
+ */
+
+public class SharedPreAdUtils {
+ public static final String SHARED_NAME = "FYReader_ad_pref";
+ private static SharedPreAdUtils sInstance;
+ private SharedPreferences sharedReadable;
+ private SharedPreferences.Editor sharedWritable;
+
+ private SharedPreAdUtils() {
+ sharedReadable = App.getmContext()
+ .getSharedPreferences(SHARED_NAME, Context.MODE_MULTI_PROCESS);
+ sharedWritable = sharedReadable.edit();
+ }
+
+ public static SharedPreAdUtils getInstance() {
+ if (sInstance == null) {
+ synchronized (SharedPreAdUtils.class) {
+ if (sInstance == null) {
+ sInstance = new SharedPreAdUtils();
+ }
+ }
+ }
+ return sInstance;
+ }
+
+ public SharedPreferences getSharedPreferences() {
+ return sharedReadable;
+ }
+
+ public void putString(String key, String value) {
+ sharedWritable.putString(key, value);
+ sharedWritable.apply();
+ }
+
+ public void putInt(String key, int value) {
+ sharedWritable.putInt(key, value);
+ sharedWritable.apply();
+ }
+
+ public void putBoolean(String key, boolean value) {
+ sharedWritable.putBoolean(key, value);
+ sharedWritable.apply();
+ }
+
+ public void putFloat(String key, float value) {
+ sharedWritable.putFloat(key, value);
+ sharedWritable.apply();
+ }
+
+ public void putLong(String key, long value) {
+ sharedWritable.putLong(key, value);
+ sharedWritable.apply();
+ }
+
+ public String getString(String key) {
+ return getString(key, "");
+ }
+
+ public String getString(String key, String def) {
+ return sharedReadable.getString(key, def);
+ }
+
+ public int getInt(String key) {
+ return getInt(key, 0);
+ }
+
+ public int getInt(String key, int def) {
+ return sharedReadable.getInt(key, def);
+ }
+
+ public boolean getBoolean(String key) {
+ return getBoolean(key, false);
+ }
+
+ public boolean getBoolean(String key, boolean def) {
+ return sharedReadable.getBoolean(key, def);
+ }
+
+ public float getFloat(String key) {
+ return getFloat(key, 0);
+ }
+
+ public float getFloat(String key, float def) {
+ return sharedReadable.getFloat(key, def);
+ }
+
+ public long getLong(String key) {
+ return getLong(key, 0);
+ }
+
+ public long getLong(String key, long def) {
+ return sharedReadable.getLong(key, def);
+ }
+
+ public void remove(String key) {
+ sharedWritable.remove(key).apply();
+ }
+
+ public Map getAll() {
+ return sharedReadable.getAll();
+ }
+
+}
+
diff --git a/app/src/main/java/xyz/fycz/myreader/util/SharedPreUtils.java b/app/src/main/java/xyz/fycz/myreader/util/SharedPreUtils.java
index da2a5a0..830aaaa 100644
--- a/app/src/main/java/xyz/fycz/myreader/util/SharedPreUtils.java
+++ b/app/src/main/java/xyz/fycz/myreader/util/SharedPreUtils.java
@@ -13,25 +13,17 @@ import java.util.Map;
public class SharedPreUtils {
public static final String SHARED_NAME = "FYReader_pref";
- public static final String AD_SHARED_NAME = "FYReader_ad_pref";
private static SharedPreUtils sInstance;
- private final SharedPreferences[] sharedReadables;
private SharedPreferences sharedReadable;
private SharedPreferences.Editor sharedWritable;
private SharedPreUtils() {
- sharedReadables = new SharedPreferences[]{
- App.getmContext().getSharedPreferences(SHARED_NAME, Context.MODE_MULTI_PROCESS),
- App.getmContext().getSharedPreferences(AD_SHARED_NAME, Context.MODE_MULTI_PROCESS)
- };
+ sharedReadable = App.getmContext()
+ .getSharedPreferences(SHARED_NAME, Context.MODE_MULTI_PROCESS);
+ sharedWritable = sharedReadable.edit();
}
-
- //不能
+
public static SharedPreUtils getInstance() {
- return getInstance(false);
- }
-
- public static SharedPreUtils getInstance(boolean ad) {
if (sInstance == null) {
synchronized (SharedPreUtils.class) {
if (sInstance == null) {
@@ -39,8 +31,6 @@ public class SharedPreUtils {
}
}
}
- sInstance.sharedReadable = sInstance.sharedReadables[!ad ? 0 : 1];
- sInstance.sharedWritable = sInstance.sharedReadable.edit();
return sInstance;
}
@@ -122,3 +112,4 @@ public class SharedPreUtils {
}
}
+
diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java b/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java
index 248c188..5282aef 100644
--- a/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java
+++ b/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java
@@ -1,6 +1,7 @@
package xyz.fycz.myreader.util.utils;
import android.app.Activity;
+import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -15,6 +16,8 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.File;
+import java.io.FilenameFilter;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -32,6 +35,7 @@ import xyz.fycz.myreader.entity.ad.AdBean;
import xyz.fycz.myreader.entity.ad.AdConfig;
import xyz.fycz.myreader.model.user.User;
import xyz.fycz.myreader.model.user.UserService;
+import xyz.fycz.myreader.util.SharedPreAdUtils;
import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.help.DateHelper;
@@ -56,8 +60,8 @@ public class AdUtils {
}
}
- public static SharedPreUtils getSp() {
- return SharedPreUtils.getInstance(true);
+ public static SharedPreAdUtils getSp() {
+ return SharedPreAdUtils.getInstance();
}
public static Single checkHasAd() {
@@ -371,6 +375,22 @@ public class AdUtils {
return rewardLastTime > System.currentTimeMillis();
}
+ public static void resetPangleId() {
+ String root = App.getmContext().getFilesDir().getParent();
+ String sharePath = root + File.separator + "shared_prefs";
+ String c1 = root + File.separator + "cache216data.dat";
+ String c2 = root + File.separator + "cache216statistics.dat";
+ FileUtils.deleteFile(c1);
+ FileUtils.deleteFile(c2);
+ File shared = new File(sharePath);
+ if (shared.exists() && shared.isDirectory()) {
+ File[] files = shared.listFiles((dir, name) -> !name.startsWith("FYReader"));
+ for (File file :files) {
+ file.delete();
+ }
+ }
+ }
+
public static AdConfig getAdConfig() {
return adConfig;
}
diff --git a/app/src/main/res/layout/activity_donate.xml b/app/src/main/res/layout/activity_donate.xml
index 522864f..0d8b8ff 100644
--- a/app/src/main/res/layout/activity_donate.xml
+++ b/app/src/main/res/layout/activity_donate.xml
@@ -109,7 +109,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:visibility="gone"
tools:visibility="visible">
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3a7b223..eeedf60 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -481,7 +481,7 @@
QQ收款码
广告支持作者
点击下列广告即可支持作者,建议在WIFI环境下点击
- 信息流广告(下载的文件可在广告设置中清除)
+ 信息流广告
激励视频
观看激励视频
广告下载/缓存
@@ -587,6 +587,7 @@
选择需要禁用代理的书源
启用代理
编辑
+ ResetPangleId
- 跟随系统