diff --git a/app/build.gradle b/app/build.gradle index 92490230f9..0122ed0e2a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1414 - versionName "0.14.14" + versionCode 1415 + versionName "0.14.15" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/callback/OnHomeItemClickListener.kt b/app/src/main/java/org/ole/planet/myplanet/callback/OnHomeItemClickListener.kt index 4fc5a51eb8..b8aef76b84 100644 --- a/app/src/main/java/org/ole/planet/myplanet/callback/OnHomeItemClickListener.kt +++ b/app/src/main/java/org/ole/planet/myplanet/callback/OnHomeItemClickListener.kt @@ -5,7 +5,7 @@ import org.ole.planet.myplanet.model.RealmMyLibrary import org.ole.planet.myplanet.model.RealmStepExam interface OnHomeItemClickListener { - fun openCallFragment(f: Fragment?) + fun openCallFragment(f: Fragment) fun openLibraryDetailFragment(library: RealmMyLibrary?) fun showRatingDialog(resource: String?, resource_id: String?, title: String?, listener: OnRatingChangeListener?) diff --git a/app/src/main/java/org/ole/planet/myplanet/datamanager/ManagerSync.kt b/app/src/main/java/org/ole/planet/myplanet/datamanager/ManagerSync.kt index 5f435ffb27..328fe50124 100644 --- a/app/src/main/java/org/ole/planet/myplanet/datamanager/ManagerSync.kt +++ b/app/src/main/java/org/ole/planet/myplanet/datamanager/ManagerSync.kt @@ -29,7 +29,7 @@ class ManagerSync private constructor(context: Context) { mRealm = dbService.realmInstance } - fun login(userName: String, password: String, listener: SyncListener) { + fun login(userName: String?, password: String?, listener: SyncListener) { listener.onSyncStarted() Utilities.log(Utilities.getUrl() + "/org.couchdb.user:" + userName) val apiInterface = ApiClient.client?.create(ApiInterface::class.java) diff --git a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt index cd3b9698a8..61a1844ddd 100644 --- a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt +++ b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt @@ -340,7 +340,7 @@ class Service(private val context: Context) { } interface CheckVersionCallback { - fun onUpdateAvailable(info: MyPlanet, cancelable: Boolean) + fun onUpdateAvailable(info: MyPlanet?, cancelable: Boolean) fun onCheckingVersion() fun onError(msg: String, blockSync: Boolean) } diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmMyTeam.kt b/app/src/main/java/org/ole/planet/myplanet/model/RealmMyTeam.kt index 9b88d86d1b..d170435f34 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmMyTeam.kt +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmMyTeam.kt @@ -305,7 +305,7 @@ open class RealmMyTeam : RealmObject() { } @JvmStatic - fun getUsers(teamId: String, mRealm: Realm, docType: String): MutableList { + fun getUsers(teamId: String?, mRealm: Realm, docType: String): MutableList { var query = mRealm.where(RealmMyTeam::class.java).equalTo("teamId", teamId) if (docType.isNotEmpty()) { query = query.equalTo("docType", docType) diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmUserModel.kt b/app/src/main/java/org/ole/planet/myplanet/model/RealmUserModel.kt index cf5d78e281..2860f38117 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmUserModel.kt +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmUserModel.kt @@ -174,7 +174,7 @@ open class RealmUserModel : RealmObject() { companion object { @JvmStatic - fun createGuestUser(username: String, mRealm: Realm, settings: SharedPreferences): RealmUserModel? { + fun createGuestUser(username: String?, mRealm: Realm, settings: SharedPreferences): RealmUserModel? { val `object` = JsonObject() `object`.addProperty("_id", "guest_$username") `object`.addProperty("name", username) diff --git a/app/src/main/java/org/ole/planet/myplanet/model/User.kt b/app/src/main/java/org/ole/planet/myplanet/model/User.kt index 4e2916cdcc..850065bad9 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/User.kt +++ b/app/src/main/java/org/ole/planet/myplanet/model/User.kt @@ -1,9 +1,9 @@ package org.ole.planet.myplanet.model data class User( - val fullName: String, - val name: String, - var password: String, - val image: String, - var source: String + val fullName: String? = null, + val name: String? = null, + var password: String? = null, + val image: String? = null, + var source: String? = null ) \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.kt b/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.kt index 010df9742b..7644187484 100644 --- a/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.kt +++ b/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.kt @@ -82,9 +82,9 @@ class AutoSyncWorker(private val context: Context, workerParams: WorkerParameter } } - override fun onUpdateAvailable(info: MyPlanet, cancelable: Boolean) { + override fun onUpdateAvailable(info: MyPlanet?, cancelable: Boolean) { if (Constants.showBetaFeature(Constants.KEY_AUTOUPDATE, context)) { - startDownloadUpdate(context, Utilities.getApkUpdateUrl(info.localapkpath), null) + startDownloadUpdate(context, Utilities.getApkUpdateUrl(info?.localapkpath), null) } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt index 7e98d331bc..b99cafd079 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt @@ -297,7 +297,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, B profileDbHandler.onDestory() } - override fun openCallFragment(f: Fragment?) { + override fun openCallFragment(f: Fragment) { openCallFragment(f, "") } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite index 2a3351ed07..d6d2d0c980 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite @@ -297,7 +297,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, B profileDbHandler.onDestory() } - override fun openCallFragment(f: Fragment?) { + override fun openCallFragment(f: Fragment) { openCallFragment(f, "") } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt index 941684ffa5..03c55cc625 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt @@ -64,9 +64,9 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack return true } - fun openCallFragment(newfragment: Fragment?, tag: String?) { + fun openCallFragment(newfragment: Fragment, tag: String?) { val fragmentTransaction = supportFragmentManager.beginTransaction() - fragmentTransaction.replace(R.id.fragment_container, newfragment!!, tag) + fragmentTransaction.replace(R.id.fragment_container, newfragment, tag) supportFragmentManager.addOnBackStackChangedListener(this) fragmentTransaction.addToBackStack("") fragmentTransaction.commit() @@ -107,7 +107,7 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack val mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) val intent = Intent(Settings.ACTION_WIFI_SETTINGS) startActivity(intent) - if (mWifi!!.isConnected) { + if (mWifi?.isConnected == true) { wifi.setWifiEnabled(false) if (resIcon != null) { DrawableCompat.setTintMode(resIcon.mutate(), PorterDuff.Mode.SRC_ATOP) @@ -131,7 +131,7 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack val id = settings.getInt("LastWifiID", -1) Utilities.log("LAST SSID $id") val wifiManager = applicationContext.getSystemService(WIFI_SERVICE) as WifiManager - var netId = -1 + val netId: Int if (wifiManager == null) { Utilities.toast(this, getString(R.string.unable_to_connect_to_planet_wifi)) return 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 8b658a78b1..baed682d6e 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 @@ -65,7 +65,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { } if (intent.hasExtra("versionInfo")) { onUpdateAvailable( - (intent.getSerializableExtra("versionInfo") as MyPlanet?)!!, + (intent.getSerializableExtra("versionInfo") as MyPlanet?), intent.getBooleanExtra("cancelable", false) ) } else { @@ -98,8 +98,8 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { fun getTeamMembers() { selectedTeamId = prefData.getSELECTEDTEAMID().toString() - if (selectedTeamId!!.isNotEmpty()) { - users = RealmMyTeam.getUsers(selectedTeamId!!, mRealm, "") + if (selectedTeamId?.isNotEmpty() == true) { + users = RealmMyTeam.getUsers(selectedTeamId, mRealm, "") val userList = (users as MutableList?)?.map { User(it.getFullName(), it.name ?: "", "", it.userImage ?: "", "team") } ?: emptyList() @@ -113,7 +113,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { mAdapter = if (mAdapter == null) { TeamListAdapter(prefData.getSAVEDUSERS().toMutableList(), this, this) } else { - mAdapter!!.clearList() + mAdapter?.clearList() TeamListAdapter(prefData.getSAVEDUSERS().toMutableList(), this, this) } @@ -131,7 +131,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { } override fun onItemClick(user: User) { - if (user.password.isEmpty() && user.source != "guest") { + if (user.password?.isEmpty() == true && user.source != "guest") { Glide.with(this) .load(user.image) .placeholder(R.drawable.profile) diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.kt index 045981d30f..116c87df89 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.kt @@ -43,7 +43,7 @@ abstract class ProcessUserDataActivity : PermissionActivity(), SuccessListener { override fun onReceive(context: Context, intent: Intent) { if (intent.action == DashboardActivity.MESSAGE_PROGRESS && progressDialog != null) { val download = intent.getParcelableExtra("download") - checkDownloadResult(download, progressDialog!!) + checkDownloadResult(download, progressDialog) } } } @@ -59,18 +59,16 @@ abstract class ProcessUserDataActivity : PermissionActivity(), SuccessListener { return true } - fun checkDownloadResult(download: Download?, progressDialog: ProgressDialog) { - if (!download!!.failed) { - progressDialog.setMessage(getString(R.string.downloading) + download.progress + "% " + getString( - R.string.complete - )) + fun checkDownloadResult(download: Download?, progressDialog: ProgressDialog?) { + if (!download?.failed!!) { + progressDialog?.setMessage("${getString(R.string.downloading)}${download.progress}% ${getString(R.string.complete)}") if (download.completeAll) { - progressDialog.dismiss() - installApk(this, download.fileUrl!!) + progressDialog?.dismiss() + installApk(this, download.fileUrl) } } else { - progressDialog.dismiss() - showError(progressDialog, download.message!!) + progressDialog?.dismiss() + showError(progressDialog, download.message) } } @@ -139,33 +137,33 @@ abstract class ProcessUserDataActivity : PermissionActivity(), SuccessListener { } fun startUpload() { - progressDialog!!.setMessage(getString(R.string.uploading_data_to_server_please_wait)) - progressDialog!!.show() + progressDialog?.setMessage(getString(R.string.uploading_data_to_server_please_wait)) + progressDialog?.show() Utilities.log("Upload : upload started") UploadToShelfService.instance?.uploadUserData { - UploadToShelfService.instance!!.uploadHealth() + UploadToShelfService.instance?.uploadHealth() } UploadManager.instance?.uploadUserActivities(this) - UploadManager.instance!!.uploadExamResult(this) - UploadManager.instance!!.uploadFeedback(this) - UploadManager.instance!!.uploadAchievement() - UploadManager.instance!!.uploadResourceActivities("") - UploadManager.instance!!.uploadCourseActivities() - UploadManager.instance!!.uploadSearchActivity() - UploadManager.instance!!.uploadNews() - UploadManager.instance!!.uploadTeams() - UploadManager.instance!!.uploadResource(this) - UploadManager.instance!!.uploadRating(this) - UploadManager.instance!!.uploadTeamTask() - UploadManager.instance!!.uploadCrashLog(this) - UploadManager.instance!!.uploadSubmitPhotos(this) - UploadManager.instance!!.uploadActivities(this) + UploadManager.instance?.uploadExamResult(this) + UploadManager.instance?.uploadFeedback(this) + UploadManager.instance?.uploadAchievement() + UploadManager.instance?.uploadResourceActivities("") + UploadManager.instance?.uploadCourseActivities() + UploadManager.instance?.uploadSearchActivity() + UploadManager.instance?.uploadNews() + UploadManager.instance?.uploadTeams() + UploadManager.instance?.uploadResource(this) + UploadManager.instance?.uploadRating(this) + UploadManager.instance?.uploadTeamTask() + UploadManager.instance?.uploadCrashLog(this) + UploadManager.instance?.uploadSubmitPhotos(this) + UploadManager.instance?.uploadActivities(this) Toast.makeText(this, getString(R.string.uploading_activities_to_server_please_wait), Toast.LENGTH_SHORT).show() } - protected fun hideKeyboard(view: View) { + protected fun hideKeyboard(view: View?) { val `in` = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager - `in`.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) + `in`.hideSoftInputFromWindow(view?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) } fun saveUserInfoPref(settings: SharedPreferences, password: String?, user: RealmUserModel) { @@ -177,7 +175,7 @@ abstract class ProcessUserDataActivity : PermissionActivity(), SuccessListener { editor.putString("firstName", user.firstName) editor.putString("lastName", user.lastName) editor.putString("middleName", user.middleName) - editor.putBoolean("isUserAdmin", user.userAdmin!!) + user.userAdmin?.let { editor.putBoolean("isUserAdmin", it) } editor.putLong("lastLogin", System.currentTimeMillis()) editor.apply() } @@ -193,10 +191,10 @@ abstract class ProcessUserDataActivity : PermissionActivity(), SuccessListener { private fun getUserInfo(uri: Uri): Array { val ar = arrayOf("", "") - val info = uri.userInfo!!.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - if (info.size > 1) { - ar[0] = info[0] - ar[1] = info[1] + val info = uri.userInfo?.split(":".toRegex())?.dropLastWhile { it.isEmpty() }?.toTypedArray() + if ((info?.size ?: 0) > 1) { + ar[0] = "${info?.get(0)}" + ar[1] = "${info?.get(1)}" } return ar } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt index c476b172f0..cc5d3953b4 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt @@ -145,7 +145,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers mRealm = DatabaseService(this).realmInstance requestAllPermissions() progressDialog = ProgressDialog(this) - progressDialog!!.setCancelable(false) + progressDialog?.setCancelable(false) prefData = SharedPrefManager(this) profileDbHandler = UserProfileDbHandler(this) defaultPref = PreferenceManager.getDefaultSharedPreferences(this) @@ -188,25 +188,26 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers @Throws(Exception::class) fun isServerReachable(processedUrl: String?): Boolean { - progressDialog!!.setMessage(getString(R.string.connecting_to_server)) - progressDialog!!.show() - val apiInterface = client!!.create(ApiInterface::class.java) + progressDialog?.setMessage(getString(R.string.connecting_to_server)) + progressDialog?.show() + val apiInterface = client?.create(ApiInterface::class.java) Utilities.log("$processedUrl/_all_dbs") - apiInterface.isPlanetAvailable("$processedUrl/_all_dbs").enqueue( + apiInterface?.isPlanetAvailable("$processedUrl/_all_dbs")?.enqueue( object : Callback { override fun onResponse(call: Call, response: Response) { try { - progressDialog!!.dismiss() - val ss = response.body()!!.string() - val myList = listOf(*ss.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) + progressDialog?.dismiss() + val ss = response.body()?.string() + val myList = ss?.split(",".toRegex())?.dropLastWhile { it.isEmpty() } + ?.let { listOf(*it.toTypedArray()) } Utilities.log("List size $ss") - if (myList.size < 8) { + if ((myList?.size ?: 0) < 8) { alertDialogOkay(getString(R.string.check_the_server_address_again_what_i_connected_to_wasn_t_the_planet_server)) } else { startSync() } } catch (e: Exception) { alertDialogOkay(getString(R.string.device_couldn_t_reach_server_check_and_try_again)) - progressDialog!!.dismiss() + progressDialog?.dismiss() } } @@ -215,7 +216,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers if (!mRealm.isClosed) { mRealm.close() } - progressDialog!!.dismiss() + progressDialog?.dismiss() } }) return connectionResult @@ -223,7 +224,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers private fun declareHideKeyboardElements() { findViewById(R.id.constraintLayout).setOnTouchListener { view: View?, _: MotionEvent? -> - hideKeyboard(view!!) + hideKeyboard(view) false } } @@ -264,10 +265,12 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers editor.commit() } - fun authenticateUser(settings: SharedPreferences?, username: String?, password: String, isManagerMode: Boolean): Boolean { + fun authenticateUser(settings: SharedPreferences?, username: String?, password: String?, isManagerMode: Boolean): Boolean { return try { mRealm = Realm.getDefaultInstance() - this.settings = settings!! + if (settings != null) { + this.settings = settings + } if (mRealm.isEmpty) { alertDialogOkay(getString(R.string.server_not_configured_properly_connect_this_device_with_planet_server)) false @@ -281,19 +284,19 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers } } - private fun checkName(username: String?, password: String, isManagerMode: Boolean): Boolean { + private fun checkName(username: String?, password: String?, isManagerMode: Boolean): Boolean { try { mRealm = Realm.getDefaultInstance() val decrypt = AndroidDecrypter() val db_users = mRealm.where(RealmUserModel::class.java).equalTo("name", username).findAll() for (user in db_users) { - if (user._id!!.isEmpty()) { + if (user._id?.isEmpty() == true) { if (username == user.name && password == user.password) { saveUserInfoPref(settings, password, user) return true } } else { - if (AndroidDecrypter(username!!, password, user.derived_key!!, user.salt!!)) { + if (AndroidDecrypter(username, password, user.derived_key, user.salt)) { if (isManagerMode && !user.isManager()) return false saveUserInfoPref(settings, password, user) return true @@ -319,18 +322,18 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers dialog.dismiss() saveSyncInfoToPreference() var processedUrl = "" - val protocol = (dialog.customView!!.findViewById(R.id.input_server_url_protocol) as EditText).text.toString() - var url = (dialog.customView!!.findViewById(R.id.input_server_url) as EditText).text.toString() - val pin = (dialog.customView!!.findViewById(R.id.input_server_Password) as EditText).text.toString() - settings.edit().putString("customDeviceName", (dialog.customView!!.findViewById(R.id.deviceName) as EditText).text.toString()).apply() + val protocol = (dialog.customView?.findViewById(R.id.input_server_url_protocol) as EditText).text.toString() + var url = (dialog.customView?.findViewById(R.id.input_server_url) as EditText).text.toString() + val pin = (dialog.customView?.findViewById(R.id.input_server_Password) as EditText).text.toString() + settings.edit().putString("customDeviceName", (dialog.customView?.findViewById(R.id.deviceName) as EditText).text.toString()).apply() url = protocol + url if (isUrlValid(url)) processedUrl = setUrlParts(url, pin, this) return processedUrl } override fun onSyncStarted() { - progressDialog!!.setMessage(getString(R.string.syncing_data_please_wait)) - progressDialog!!.show() + progressDialog?.setMessage(getString(R.string.syncing_data_please_wait)) + progressDialog?.show() } override fun onSyncFailed(s: String?) { @@ -347,7 +350,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers } override fun onSyncComplete() { - progressDialog!!.dismiss() + progressDialog?.dismiss() if (::syncIconDrawable.isInitialized) { runOnUiThread { syncIconDrawable = syncIcon.drawable as AnimationDrawable @@ -440,7 +443,9 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers inputPassword.setText(settings.getString(getString(R.string.login_password), "")) } if (isNetworkConnected()) { - service.syncPlanetServers(mRealm, { success: String? -> Utilities.toast(this, success!!) }) + service.syncPlanetServers(mRealm) { success: String? -> + Utilities.toast(this, success) + } } inputName.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} @@ -497,7 +502,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers } } - fun submitForm(name: String?, password: String) { + fun submitForm(name: String?, password: String?) { if (forceSyncTrigger()) { return } @@ -511,14 +516,14 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers onLogin() saveUsers(inputName.text.toString(), inputPassword.text.toString(), "member") } else { - instance!!.login(name!!, password, object : SyncListener { + instance?.login(name, password, object : SyncListener { override fun onSyncStarted() { - progressDialog!!.setMessage(getString(R.string.please_wait)) - progressDialog!!.show() + progressDialog?.setMessage(getString(R.string.please_wait)) + progressDialog?.show() } override fun onSyncComplete() { - progressDialog!!.dismiss() + progressDialog?.dismiss() Utilities.log("on complete") val log = authenticateUser(settings, name, password, true) if (log) { @@ -534,7 +539,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers override fun onSyncFailed(msg: String?) { Utilities.toast(MainApplication.context, msg) - progressDialog!!.dismiss() + progressDialog?.dismiss() syncIconDrawable.stop() syncIconDrawable.selectDrawable(0) } @@ -706,9 +711,9 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers val existingUser = mRealm.where(RealmUserModel::class.java).equalTo("name", username).findFirst() dialog.dismiss() if (existingUser != null) { - if (existingUser._id!!.contains("guest")) { + if (existingUser._id?.contains("guest") == true) { showGuestDialog(username) - } else if (existingUser._id!!.contains("org.couchdb.user:")) { + } else if (existingUser._id?.contains("org.couchdb.user:") == true) { showUserAlreadyMemberDialog(username) } } else { @@ -769,13 +774,13 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers fun saveUsers(name: String?, password: String?, source: String) { if (source === "guest") { - val newUser = User("", name!!, password!!, "", "guest") + val newUser = User("", name, password, "", "guest") val existingUsers: MutableList = ArrayList( prefData.getSAVEDUSERS() ) var newUserExists = false for ((_, name1) in existingUsers) { - if (name1 == newUser.name.trim { it <= ' ' }) { + if (name1 == newUser.name?.trim { it <= ' ' }) { newUserExists = true break } @@ -785,21 +790,19 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers prefData.setSAVEDUSERS(existingUsers) } } else if (source === "member") { - var userProfile = profileDbHandler.userModel!!.userImage - var fullName: String? = profileDbHandler.userModel!!.getFullName() + var userProfile = profileDbHandler.userModel?.userImage + var fullName: String? = profileDbHandler.userModel?.getFullName() if (userProfile == null) { userProfile = "" } - if (fullName!!.trim { it <= ' ' }.isEmpty()) { - fullName = profileDbHandler.userModel!!.name + if (fullName?.trim { it <= ' ' }?.isEmpty() == true) { + fullName = profileDbHandler.userModel?.name } - val newUser = User(fullName!!, name!!, password!!, userProfile, "member") - val existingUsers: MutableList = ArrayList( - prefData.getSAVEDUSERS() - ) + val newUser = User(fullName, name, password, userProfile, "member") + val existingUsers: MutableList = ArrayList(prefData.getSAVEDUSERS()) var newUserExists = false for ((fullName1) in existingUsers) { - if (fullName1 == newUser.fullName.trim { it <= ' ' }) { + if (fullName1 == newUser.fullName?.trim { it <= ' ' }) { newUserExists = true break } @@ -839,7 +842,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers if (selectedTeamId == null) { saveConfigAndContinue(dialog) } else { - val url = serverUrlProtocol!!.text.toString() + serverUrl.text.toString() + val url = "${serverUrlProtocol?.text}${serverUrl.text}" if (isUrlValid(url)) { prefData.setSELECTEDTEAMID(selectedTeamId) (activity as LoginActivity).getTeamMembers() @@ -937,17 +940,14 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers settings.edit().putString("serverProtocol", getString(R.string.http_protocol)) .apply() } - if (settings.getString( - "serverProtocol", - "" - ) == getString(R.string.https_protocol) && settings.getString("serverURL", "") != "" + if (settings.getString("serverProtocol", "") == getString(R.string.https_protocol) + && settings.getString("serverURL", "") != "" && settings.getString("serverURL", "") != "https://planet.learning.ole.org" ) { binding.radioHttps.isChecked = true - settings.edit().putString("serverProtocol", getString(R.string.https_protocol)) - .apply() + settings.edit().putString("serverProtocol", getString(R.string.https_protocol)).apply() } - serverUrl.setText(removeProtocol(settings.getString("serverURL", ""))) + serverUrl.setText(settings.getString("serverURL", "")?.let { removeProtocol(it) }) serverPassword.setText(settings.getString("serverPin", "")) serverUrl.isEnabled = true serverPassword.isEnabled = true @@ -965,7 +965,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers if (teams.isNotEmpty() && show && binding.inputServerUrl.text.toString() != "") { binding.team.visibility = View.VISIBLE teamAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, teamList) - teamAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + teamAdapter?.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) teamList.clear() teamList.add("select team") for (team in teams) { @@ -986,16 +986,11 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers } } binding.team.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected( - parentView: AdapterView<*>?, - selectedItemView: View, - position: Int, - id: Long - ) { + override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long) { if (position > 0) { val selectedTeam = teams[position - 1] if (selectedTeam != null) { - selectedTeamId = selectedTeam._id!! + selectedTeamId = selectedTeam._id } } } @@ -1038,7 +1033,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers if (checked) { onChangeServerUrl() } else { - serverUrl.setText(removeProtocol(settings.getString("serverURL", ""))) + serverUrl.setText(settings.getString("serverURL", "")?.let { removeProtocol(it) }) serverPassword.setText(settings.getString("serverPin", "")) protocol_checkin.check( if (TextUtils.equals(settings.getString("serverProtocol", ""), "http://")) { @@ -1067,9 +1062,9 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers } } - private fun removeProtocol(url: String?): String { + private fun removeProtocol(url: String): String { var url = url - url = url!!.replaceFirst(getString(R.string.https_protocol).toRegex(), "") + url = url.replaceFirst(getString(R.string.https_protocol).toRegex(), "") url = url.replaceFirst(getString(R.string.http_protocol).toRegex(), "") return url } @@ -1100,27 +1095,29 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers override fun onSuccess(s: String?) { Utilities.log("Sync completed ") - if (progressDialog!!.isShowing && s!!.contains("Crash")) progressDialog!!.dismiss() + if (progressDialog?.isShowing == true && s?.contains("Crash") == true) { + progressDialog?.dismiss() + } if (::btnSignIn.isInitialized) { - showSnack(btnSignIn, s!!) + showSnack(btnSignIn, s) } settings.edit().putLong("lastUsageUploaded", Date().time).apply() if (::lblLastSyncDate.isInitialized) { lblLastSyncDate.text = - getString(R.string.last_sync) + Utilities.getRelativeTime(Date().time) + " >>" + "${getString(R.string.last_sync)}${Utilities.getRelativeTime(Date().time)} >>" } } - override fun onUpdateAvailable(info: MyPlanet, cancelable: Boolean) { + override fun onUpdateAvailable(info: MyPlanet?, cancelable: Boolean) { try { mRealm = Realm.getDefaultInstance() - val builder = getUpdateDialog(this, info, progressDialog!!) + val builder = getUpdateDialog(this, info, progressDialog) if (cancelable || getCustomDeviceName(this).endsWith("###")) { builder.setNegativeButton(R.string.update_later) { _: DialogInterface?, _: Int -> continueSyncProcess(forceSync = false, isSync = true) } } else { - mRealm.executeTransactionAsync(Realm.Transaction { realm: Realm -> realm.deleteAll() }) + mRealm.executeTransactionAsync { realm: Realm -> realm.deleteAll() } } builder.setCancelable(cancelable) builder.show() @@ -1132,8 +1129,8 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers } override fun onCheckingVersion() { - progressDialog!!.setMessage(getString(R.string.checking_version)) - progressDialog!!.show() + progressDialog?.setMessage(getString(R.string.checking_version)) + progressDialog?.show() } fun registerReceiver() { @@ -1148,7 +1145,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers if (msg.startsWith("Config")) { settingDialog(this) } - progressDialog!!.dismiss() + progressDialog?.dismiss() if (!block) continueSyncProcess(forceSync = false, isSync = true) else { syncIconDrawable.stop() syncIconDrawable.selectDrawable(0) @@ -1230,8 +1227,9 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers "serverProtocol", "http://" ) - if (view!!.id == R.id.input_server_url) positiveAction.isEnabled = s.toString() - .trim { it <= ' ' }.isNotEmpty() && URLUtil.isValidUrl(protocol + s.toString()) + if (view?.id == R.id.input_server_url) { + positiveAction.isEnabled = "$s".trim { it <= ' ' }.isNotEmpty() && URLUtil.isValidUrl(protocol + "$s") + } } override fun afterTextChanged(editable: Editable) {} diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt index 8a73cac6f2..400ff3d400 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt @@ -40,7 +40,7 @@ class TeamListAdapter(private val membersList: MutableList, val context: C class ViewHolder(private val binding: UserListItemBinding) : RecyclerView.ViewHolder(binding.root) { fun bindView(account: User) { - if (account.fullName.isEmpty() || account.fullName == " ") { + if (account.fullName?.isEmpty() == true || account.fullName == " ") { binding.userNameTextView.text = account.name } else { binding.userNameTextView.text = account.fullName diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/AndroidDecrypter.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/AndroidDecrypter.kt index 454d2e38f5..5b5e593254 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/AndroidDecrypter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/AndroidDecrypter.kt @@ -95,9 +95,9 @@ class AndroidDecrypter { } @JvmStatic - fun AndroidDecrypter(usr_ID: String, usr_rawPswd: String, db_PswdkeyValue: String, db_Salt: String): Boolean { + fun AndroidDecrypter(usr_ID: String?, usr_rawPswd: String?, db_PswdkeyValue: String?, db_Salt: String?): Boolean { try { - val p = PBKDF2Parameters("HmacSHA1", "utf-8", db_Salt.toByteArray(), 10) + val p = PBKDF2Parameters("HmacSHA1", "utf-8", db_Salt?.toByteArray(), 10) val dk = PBKDF2Engine(p).deriveKey(usr_rawPswd, 20) println("$usr_ID Value ${BinTools.bin2hex(dk).lowercase(Locale.ROOT)}") return db_PswdkeyValue.equals(BinTools.bin2hex(dk).lowercase(Locale.ROOT), ignoreCase = true) diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt index 4e496d2092..d045ae532b 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt @@ -31,9 +31,9 @@ object DialogUtils { } @JvmStatic - fun showError(prgDialog: ProgressDialog, message: String) { - prgDialog.setTitle(message) - prgDialog.getButton(ProgressDialog.BUTTON_NEGATIVE)?.isEnabled = false + fun showError(prgDialog: ProgressDialog?, message: String?) { + prgDialog?.setTitle(message) + prgDialog?.getButton(ProgressDialog.BUTTON_NEGATIVE)?.isEnabled = false } @JvmStatic @@ -61,8 +61,10 @@ object DialogUtils { } @JvmStatic - fun showSnack(v: View?, s: String) { - if (v != null) Snackbar.make(v, s, Snackbar.LENGTH_LONG).show() + fun showSnack(v: View?, s: String?) { + if (v != null) { + s?.let { Snackbar.make(v, it, Snackbar.LENGTH_LONG).show() } + } } @JvmStatic @@ -107,15 +109,15 @@ object DialogUtils { } @JvmStatic - fun getUpdateDialog(context: Context, info: MyPlanet, progressDialog: ProgressDialog): AlertDialog.Builder { + fun getUpdateDialog(context: Context, info: MyPlanet?, progressDialog: ProgressDialog?): AlertDialog.Builder { return AlertDialog.Builder(context) .setTitle(R.string.new_version_of_my_planet_available) .setMessage(R.string.download_first_to_continue) .setNeutralButton(R.string.upgrade_local) { _, _ -> - startDownloadUpdate(context, Utilities.getApkUpdateUrl(info.localapkpath!!), progressDialog) + startDownloadUpdate(context, Utilities.getApkUpdateUrl(info?.localapkpath), progressDialog) } .setPositiveButton(R.string.upgrade) { _, _ -> - startDownloadUpdate(context, info.apkpath!!, progressDialog) + info?.apkpath?.let { startDownloadUpdate(context, it, progressDialog) } } }