Skip to content

Commit

Permalink
sync: stabler with safe call operators (fixes #3245) (#3248)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Mar 14, 2024
1 parent 1d78624 commit 5abd7d7
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 144 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ open class RealmMyTeam : RealmObject() {
}

@JvmStatic
fun getUsers(teamId: String, mRealm: Realm, docType: String): MutableList<RealmUserModel> {
fun getUsers(teamId: String?, mRealm: Realm, docType: String): MutableList<RealmUserModel> {
var query = mRealm.where(RealmMyTeam::class.java).equalTo("teamId", teamId)
if (docType.isNotEmpty()) {
query = query.equalTo("docType", docType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/ole/planet/myplanet/model/User.kt
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, B
profileDbHandler.onDestory()
}

override fun openCallFragment(f: Fragment?) {
override fun openCallFragment(f: Fragment) {
openCallFragment(f, "")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, B
profileDbHandler.onDestory()
}

override fun openCallFragment(f: Fragment?) {
override fun openCallFragment(f: Fragment) {
openCallFragment(f, "")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<RealmUserModel>?)?.map {
User(it.getFullName(), it.name ?: "", "", it.userImage ?: "", "team")
} ?: emptyList()
Expand All @@ -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)
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>("download")
checkDownloadResult(download, progressDialog!!)
checkDownloadResult(download, progressDialog)
}
}
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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()
}
Expand All @@ -193,10 +191,10 @@ abstract class ProcessUserDataActivity : PermissionActivity(), SuccessListener {

private fun getUserInfo(uri: Uri): Array<String> {
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
}
Expand Down
Loading

0 comments on commit 5abd7d7

Please sign in to comment.