diff --git a/app/build.gradle b/app/build.gradle index f670a37433..448f740d2d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1536 - versionName "0.15.36" + versionCode 1537 + versionName "0.15.37" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt b/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt index 9eecfc98ee..bc9a3956bb 100644 --- a/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt +++ b/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt @@ -1,8 +1,11 @@ package org.ole.planet.myplanet +import android.app.Activity import android.app.Application import android.content.Context +import android.content.Intent import android.content.SharedPreferences +import android.os.Bundle import android.os.StrictMode import android.os.StrictMode.VmPolicy import android.provider.Settings @@ -10,16 +13,21 @@ import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.PeriodicWorkRequest import androidx.work.WorkManager import org.ole.planet.myplanet.callback.TeamPageListener +import org.ole.planet.myplanet.datamanager.DatabaseService +import org.ole.planet.myplanet.model.RealmApkLog import org.ole.planet.myplanet.service.AutoSyncWorker import org.ole.planet.myplanet.service.StayOnlineWorker import org.ole.planet.myplanet.service.TaskNotificationWorker -import org.ole.planet.myplanet.ui.sync.SyncActivity +import org.ole.planet.myplanet.service.UserProfileDbHandler import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME import org.ole.planet.myplanet.utilities.LocaleHelper +import org.ole.planet.myplanet.utilities.NotificationUtil.cancellAll import org.ole.planet.myplanet.utilities.Utilities +import org.ole.planet.myplanet.utilities.VersionUtils.getVersionName +import java.util.* import java.util.concurrent.TimeUnit -class MainApplication : Application() { +class MainApplication : Application(), Application.ActivityLifecycleCallbacks { companion object { private const val AUTO_SYNC_WORK_TAG = "autoSyncWork" private const val STAY_ONLINE_WORK_TAG = "stayOnlineWork" @@ -51,23 +59,23 @@ class MainApplication : Application() { super.onCreate() context = this preferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE) - - // Initialize libraries and settings val builder = VmPolicy.Builder() StrictMode.setVmPolicy(builder.build()) builder.detectFileUriExposure() - // Set up auto-sync using WorkManager - if (preferences?.getBoolean("autoSync", false) == true && preferences?.contains("autoSyncInterval")!!) { + if (preferences?.getBoolean("autoSync", false) == true && preferences?.contains("autoSyncInterval") == true) { val syncInterval = preferences?.getInt("autoSyncInterval", 60 * 60) scheduleAutoSyncWork(syncInterval) } else { cancelAutoSyncWork() } - - // Set up other periodic works using WorkManager scheduleStayOnlineWork() scheduleTaskNotificationWork() + + Thread.setDefaultUncaughtExceptionHandler { _: Thread?, e: Throwable -> + handleUncaughtException(e) + } + registerActivityLifecycleCallbacks(this) } private fun scheduleAutoSyncWork(syncInterval: Int?) { @@ -99,4 +107,45 @@ class MainApplication : Application() { super.attachBaseContext(LocaleHelper.onAttach(base, "en")) Utilities.setContext(base) } + + override fun onActivityCreated(activity: Activity, bundle: Bundle?) {} + + override fun onActivityStarted(activity: Activity) {} + + override fun onActivityResumed(activity: Activity) {} + + override fun onActivityPaused(activity: Activity) {} + + override fun onActivityStopped(activity: Activity) {} + + override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {} + + override fun onActivityDestroyed(activity: Activity) { + cancellAll(this) + } + + private fun handleUncaughtException(e: Throwable) { + e.printStackTrace() + val service = DatabaseService(this) + val mRealm = service.realmInstance + if (!mRealm.isInTransaction) { + mRealm.beginTransaction() + } + val log = mRealm.createObject(RealmApkLog::class.java, "${UUID.randomUUID()}") + val model = UserProfileDbHandler(this).userModel + if (model != null) { + log.parentCode = model.parentCode + log.createdOn = model.planetCode + } + log.time = "${Date().time}" + log.page = "" + log.version = getVersionName(this) + log.type = RealmApkLog.ERROR_TYPE_CRASH + log.setError(e) + mRealm.commitTransaction() + val homeIntent = Intent(Intent.ACTION_MAIN) + homeIntent.addCategory(Intent.CATEGORY_HOME) + homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(homeIntent) + } } \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt index 5fbfa7c277..3953e7ac76 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt @@ -43,7 +43,6 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { becomeMember = activityLoginBinding.becomeMember btnGuestLogin = activityLoginBinding.btnGuestLogin imgBtnSetting = activityLoginBinding.imgBtnSetting - syncIcon = activityLoginBinding.syncIcon lblVersion = activityLoginBinding.lblVersion btnLang = activityLoginBinding.btnLang tvAvailableSpace = activityLoginBinding.tvAvailableSpace