fix sharedPre

pull/21/head
fengyuecanzhu 3 years ago
parent 3b795e9639
commit 54ee1db351
  1. 5
      .idea/jarRepositories.xml
  2. 2
      .idea/misc.xml
  3. 3
      app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java
  4. 21
      app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java
  5. 3
      app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java
  6. 115
      app/src/main/java/xyz/fycz/myreader/util/SharedPreAdUtils.java
  7. 19
      app/src/main/java/xyz/fycz/myreader/util/SharedPreUtils.java
  8. 24
      app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java
  9. 1
      app/src/main/res/layout/activity_donate.xml
  10. 25
      app/src/main/res/layout/layout_about_content.xml
  11. 3
      app/src/main/res/values/strings.xml

@ -31,5 +31,10 @@
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven3" />
<option name="name" value="maven3" />
<option name="url" value="http://maven.aliyun.com/nexus/content/repositories/releases/" />
</remote-repository>
</component>
</project>

@ -3,6 +3,7 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_donate.xml" value="0.264" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_more_setting.xml" value="0.2" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_user_info.xml" value="0.2" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/fragment_private_bookcase.xml" value="0.12132725430597771" />
@ -13,6 +14,7 @@
<entry key="..\:/android/FYReader/app/src/main/res/layout/item_find_source.xml" value="0.12132725430597771" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/item_source_edit.xml" value="0.22826086956521738" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/item_subscribe_source.xml" value="0.2" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/layout_about_content.xml" value="0.12132725430597771" />
</map>
</option>
</component>

@ -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<ActivityAboutBinding> {
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<ActivityAboutBinding> {
});
});
});
binding.il.rlResetPangle.setOnClickListener(v -> AdUtils.resetPangleId());
}
void openIntent(String intentName, String address) {

@ -60,26 +60,7 @@ public class DonateActivity extends BaseActivity<ActivityDonateBinding> {
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

@ -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<ActivitySplashBinding> {
@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();

@ -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<String, ?> getAll() {
return sharedReadable.getAll();
}
}

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

@ -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<Boolean> 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;
}

@ -109,7 +109,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout

@ -362,6 +362,31 @@
app:srcCompat="@drawable/ic_right_arrow"
app:tint="@color/textSecondary" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_reset_pangle"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/selector_common_bg"
android:gravity="center"
android:paddingStart="20dp"
android:paddingEnd="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/reset_pangle"
android:textColor="@color/textPrimary"
android:textSize="@dimen/text_normal_size" />
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
app:srcCompat="@drawable/ic_right_arrow"
app:tint="@color/textSecondary" />
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

@ -481,7 +481,7 @@
<string name="qq_skm">QQ收款码</string>
<string name="ad_support">广告支持作者</string>
<string name="ad_support_tip">点击下列广告即可支持作者,建议在WIFI环境下点击</string>
<string name="flow_ad_tip">信息流广告(下载的文件可在广告设置中清除)</string>
<string name="flow_ad_tip">信息流广告</string>
<string name="rewarded_video">激励视频</string>
<string name="watch_rewarded_video">观看激励视频</string>
<string name="ad_file">广告下载/缓存</string>
@ -587,6 +587,7 @@
<string name="no_proxy_sources_tip">选择需要禁用代理的书源</string>
<string name="enable_proxy">启用代理</string>
<string name="edit">编辑</string>
<string name="reset_pangle">ResetPangleId</string>
<string-array name="reset_screen_time">
<item>跟随系统</item>

Loading…
Cancel
Save