diff --git a/lib_common/src/main/java/gov/anzong/androidnga/common/PreferenceKey.java b/lib_common/src/main/java/gov/anzong/androidnga/common/PreferenceKey.java index c560b9845..afa187cd8 100644 --- a/lib_common/src/main/java/gov/anzong/androidnga/common/PreferenceKey.java +++ b/lib_common/src/main/java/gov/anzong/androidnga/common/PreferenceKey.java @@ -44,6 +44,8 @@ public class PreferenceKey { public static final String BOOKMARK_BOARD = "bookmark_board"; + public static final String CHECK_IN_LAST_TIME = "check_in_last_time"; + public static final String USER_ACTIVE_INDEX = "user_active_index"; public static final String SORT_BY_POST = "sort_by_post"; diff --git a/nga_phone_base_3.0/src/main/java/gov/anzong/androidnga/NgaClientApp.java b/nga_phone_base_3.0/src/main/java/gov/anzong/androidnga/NgaClientApp.java index 0b96b08b0..b80e2a833 100644 --- a/nga_phone_base_3.0/src/main/java/gov/anzong/androidnga/NgaClientApp.java +++ b/nga_phone_base_3.0/src/main/java/gov/anzong/androidnga/NgaClientApp.java @@ -16,12 +16,14 @@ import gov.anzong.androidnga.base.util.ContextUtils; import gov.anzong.androidnga.base.util.PreferenceUtils; import gov.anzong.androidnga.base.util.ThreadUtils; +import gov.anzong.androidnga.base.util.ToastUtils; import gov.anzong.androidnga.common.PreferenceKey; import gov.anzong.androidnga.common.util.ReflectUtils; import gov.anzong.androidnga.db.AppDatabase; import sp.phone.common.FilterKeywordsManagerImpl; import sp.phone.common.UserManagerImpl; import sp.phone.common.VersionUpgradeHelper; +import sp.phone.task.CheckInTask; public class NgaClientApp extends Application { @@ -39,6 +41,7 @@ public void onCreate() { AppDatabase.init(this); initCoreModule(); initRouter(); + checkIn(); super.onCreate(); // fixWebViewMultiProcessException(); @@ -62,7 +65,7 @@ private void fixWebViewMultiProcessException() { if (dirs != null) { for (File dir : dirs) { if (dir.getName().contains("webview")) { - if (!dir.getName().contains("webview_" + ppid)){ + if (!dir.getName().contains("webview_" + ppid)) { ThreadUtils.postOnSubThread(() -> { try { FileUtils.deleteDirectory(dir); @@ -109,6 +112,10 @@ private void checkNewVersion() { } } + private void checkIn() { + CheckInTask.execute(); + } + public static boolean isNewVersion() { return sNewVersion; } diff --git a/nga_phone_base_3.0/src/main/java/sp/phone/http/retrofit/RetrofitHelper.java b/nga_phone_base_3.0/src/main/java/sp/phone/http/retrofit/RetrofitHelper.java index a3af04132..95d5238df 100644 --- a/nga_phone_base_3.0/src/main/java/sp/phone/http/retrofit/RetrofitHelper.java +++ b/nga_phone_base_3.0/src/main/java/sp/phone/http/retrofit/RetrofitHelper.java @@ -105,6 +105,7 @@ public OkHttpClient.Builder createOkHttpClientBuilder() { Request request = original.newBuilder() .header("Cookie", cookie) .header("User-Agent", mUserAgent) + .header("X-User-Agent", "Nga_Official") .method(original.method(), original.body()) .build(); return chain.proceed(request); diff --git a/nga_phone_base_3.0/src/main/java/sp/phone/task/CheckInTask.java b/nga_phone_base_3.0/src/main/java/sp/phone/task/CheckInTask.java new file mode 100644 index 000000000..d5c96d3a2 --- /dev/null +++ b/nga_phone_base_3.0/src/main/java/sp/phone/task/CheckInTask.java @@ -0,0 +1,50 @@ +package sp.phone.task; + +import static sp.phone.util.ActivityUtils.showToast; + +import java.util.Calendar; +import java.util.Date; + +import gov.anzong.androidnga.Utils; +import gov.anzong.androidnga.base.util.PreferenceUtils; +import gov.anzong.androidnga.common.PreferenceKey; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; +import sp.phone.http.retrofit.RetrofitHelper; +import sp.phone.http.retrofit.RetrofitService; +import sp.phone.rxjava.BaseSubscriber; +import sp.phone.util.StringUtils; + +/** + * 签到 + * Created by mlzzen on 2023/7/7. + */ +public class CheckInTask { + private static final String url = Utils.getNGAHost() + "nuke.php?__lib=check_in&__act=check_in&lite=js"; + + public static void execute() { + Calendar cal1 = Calendar.getInstance(); + Calendar cal2 = Calendar.getInstance(); + long checkInLastTime = PreferenceUtils.getData(PreferenceKey.CHECK_IN_LAST_TIME, new Date().getTime() - 24 * 3600 * 1000); + cal1.setTime(new Date(checkInLastTime)); + cal2.setTime(new Date()); + if (cal1.get(Calendar.DAY_OF_YEAR) != cal2.get(Calendar.DAY_OF_YEAR)) { + RetrofitService service = RetrofitHelper.getInstance().getService(); + service.post(url) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new BaseSubscriber() { + @Override + public void onNext(String result) { + String msg = StringUtils.getStringBetween(result, 0, "{\"0\":\"", "\"},\"time\"").result; + if (msg.indexOf("签到成功") != -1) { + showToast("签到成功"); + } + if (msg.indexOf("签到成功") != -1 || msg.indexOf("今天已经签到") != -1) { + PreferenceUtils.putData(PreferenceKey.CHECK_IN_LAST_TIME, new Date().getTime()); + } + } + }); + } + } +}