Skip to content

Commit

Permalink
all: less utilities warnings is more (fixes #3944) (#3947)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
2 people authored and rlam20 committed Aug 1, 2024
1 parent a7a2686 commit 1bf9b25
Show file tree
Hide file tree
Showing 25 changed files with 120 additions and 310 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1720
versionName "0.17.20"
versionCode 1721
versionName "0.17.21"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/ole/planet/myplanet/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME
import org.ole.planet.myplanet.utilities.LocaleHelper
import org.ole.planet.myplanet.utilities.NetworkUtils.initialize
import org.ole.planet.myplanet.utilities.NetworkUtils.startListenNetworkState
import org.ole.planet.myplanet.utilities.NotificationUtil.cancellAll
import org.ole.planet.myplanet.utilities.NotificationUtil.cancelAll
import org.ole.planet.myplanet.utilities.Utilities
import org.ole.planet.myplanet.utilities.VersionUtils.getVersionName
import java.util.Date
Expand Down Expand Up @@ -186,7 +186,7 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks {
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}

override fun onActivityDestroyed(activity: Activity) {
cancellAll(this)
cancelAll(this)
}

private fun onAppForegrounded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.realm.Realm
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.callback.SyncListener
import org.ole.planet.myplanet.model.RealmUserModel.Companion.populateUsersTable
import org.ole.planet.myplanet.utilities.AndroidDecrypter.Companion.AndroidDecrypter
import org.ole.planet.myplanet.utilities.AndroidDecrypter.Companion.androidDecrypter
import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME
import org.ole.planet.myplanet.utilities.JsonUtils
import org.ole.planet.myplanet.utilities.Utilities
Expand Down Expand Up @@ -41,7 +41,7 @@ class ManagerSync private constructor(context: Context) {
// val decrypt = AndroidDecrypter()
val derivedKey = jsonDoc["derived_key"].asString
val salt = jsonDoc["salt"].asString
if (AndroidDecrypter(userName, password, derivedKey, salt)) {
if (androidDecrypter(userName, password, derivedKey, salt)) {
checkManagerAndInsert(jsonDoc, mRealm, listener)
} else {
listener.onSyncFailed("Name or password is incorrect.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open class BaseDashboardFragmentPlugin : BaseContainerFragment() {
if (f is TeamDetailFragment) {
b.putBoolean("isMyTeam", true)
}
prefData.setTEAMNAME(title)
prefData.setTeamName(title)
f.arguments = b
homeItemClickListener?.openCallFragment(f)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AdapterReports(private val context: Context, private var list: RealmResult

override fun onBindViewHolder(holder: ViewHolderReports, position: Int) {
val report = list[position]
reportListItemBinding.tvReportTitle.text = context.getString(R.string.team_financial_report, prefData.getTEAMNAME())
reportListItemBinding.tvReportTitle.text = context.getString(R.string.team_financial_report, prefData.getTeamName())
report?.let {
with(reportListItemBinding) {
val totalIncome = report.sales + report.otherIncome
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ReportsFragment : BaseTeamFragment() {
val currentDate = Date()
val dateFormat = SimpleDateFormat("EEE_MMM_dd_yyyy", Locale.US)
val formattedDate = dateFormat.format(currentDate)
val teamName = prefData.getTEAMNAME()?.replace(" ", "_")
val teamName = prefData.getTeamName()?.replace(" ", "_")

val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
Expand Down Expand Up @@ -200,7 +200,7 @@ class ReportsFragment : BaseTeamFragment() {
.equalTo("docType", "report")
.sort("date", Sort.DESCENDING).findAll()
val csvBuilder = StringBuilder()
csvBuilder.append("${prefData.getTEAMNAME()} Financial Report Summary\n\n")
csvBuilder.append("${prefData.getTeamName()} Financial Report Summary\n\n")
csvBuilder.append("Start Date, End Date, Created Date, Updated Date, Beginning Balance, Sales, Other Income, Wages, Other Expenses, Profit/Loss, Ending Balance\n")
for (report in reports) {
val dateFormat = SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z (z)", Locale.US)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class AdapterNews(var context: Context, private val list: MutableList<RealmNews?
viewHolder.rowNewsBinding.btnShowReply.visibility = View.GONE
}
viewHolder.rowNewsBinding.btnShowReply.setOnClickListener {
sharedPreferences?.setREPLIEDNEWSID(finalNews?.id)
sharedPreferences?.setRepliedNewsId(finalNews?.id)
listener?.showReply(finalNews, fromLogin)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OnBoardingActivity : AppCompatActivity() {
return
}

if (prefData.getFIRSTLAUNCH()) {
if (prefData.getFirstLaunch()) {
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class OnBoardingActivity : AppCompatActivity() {
}

private fun finishTutorial() {
prefData.setFIRSTLAUNCH(true)
prefData.setFirstLaunch(true)
startActivity(Intent(this, LoginActivity::class.java))
}
}
22 changes: 11 additions & 11 deletions app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,25 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
}

fun getTeamMembers() {
selectedTeamId = prefData.getSELECTEDTEAMID().toString()
selectedTeamId = prefData.getSelectedTeamId().toString()
if (selectedTeamId?.isNotEmpty() == true) {
users = RealmMyTeam.getUsers(selectedTeamId, mRealm, "membership")
val userList = (users as? MutableList<RealmUserModel>)?.map {
User(it.name ?: "", it.name ?: "", "", it.userImage ?: "", "team")
} ?: emptyList()

val existingUsers = prefData.getSAVEDUSERS().toMutableList()
val existingUsers = prefData.getSavedUsers().toMutableList()
val filteredExistingUsers = existingUsers.filter { it.source != "team" }
val updatedUserList = userList.filterNot { user -> filteredExistingUsers.any { it.name == user.name } } + filteredExistingUsers
prefData.setSAVEDUSERS(updatedUserList)
prefData.setSavedUsers(updatedUserList)
}

if (mAdapter == null) {
mAdapter = TeamListAdapter(prefData.getSAVEDUSERS().toMutableList(), this, this)
mAdapter = TeamListAdapter(prefData.getSavedUsers().toMutableList(), this, this)
activityLoginBinding.recyclerView.layoutManager = LinearLayoutManager(this)
activityLoginBinding.recyclerView.adapter = mAdapter
} else {
mAdapter?.updateList(prefData.getSAVEDUSERS().toMutableList())
mAdapter?.updateList(prefData.getSavedUsers().toMutableList())
}

activityLoginBinding.recyclerView.isNestedScrollingEnabled = true
Expand Down Expand Up @@ -515,7 +515,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
if (source === "guest") {
val newUser = User("", name, password, "", "guest")
val existingUsers: MutableList<User> = ArrayList(
prefData.getSAVEDUSERS()
prefData.getSavedUsers()
)
var newUserExists = false
for ((_, name1) in existingUsers) {
Expand All @@ -526,7 +526,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
}
if (!newUserExists) {
existingUsers.add(newUser)
prefData.setSAVEDUSERS(existingUsers)
prefData.setSavedUsers(existingUsers)
}
} else if (source === "member") {
var userProfile = profileDbHandler.userModel?.userImage
Expand All @@ -535,7 +535,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
userProfile = ""
}
val newUser = User(userName, name, password, userProfile, "member")
val existingUsers: MutableList<User> = ArrayList(prefData.getSAVEDUSERS())
val existingUsers: MutableList<User> = ArrayList(prefData.getSavedUsers())
var newUserExists = false
for ((fullName1) in existingUsers) {
if (fullName1 == newUser.fullName?.trim { it <= ' ' }) {
Expand All @@ -545,7 +545,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
}
if (!newUserExists) {
existingUsers.add(newUser)
prefData.setSAVEDUSERS(existingUsers)
prefData.setSavedUsers(existingUsers)
}
}
}
Expand All @@ -564,7 +564,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
}

private fun resetGuestAsMember(username: String?) {
val existingUsers = prefData.getSAVEDUSERS().toMutableList()
val existingUsers = prefData.getSavedUsers().toMutableList()
var newUserExists = false
for ((_, name) in existingUsers) {
if (name == username) {
Expand All @@ -580,7 +580,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
iterator.remove()
}
}
prefData.setSAVEDUSERS(existingUsers)
prefData.setSavedUsers(existingUsers)
}
}

Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.ole.planet.myplanet.model.*
import org.ole.planet.myplanet.service.*
import org.ole.planet.myplanet.ui.dashboard.DashboardActivity
import org.ole.planet.myplanet.ui.team.AdapterTeam.OnUserSelectedListener
import org.ole.planet.myplanet.utilities.AndroidDecrypter.Companion.AndroidDecrypter
import org.ole.planet.myplanet.utilities.AndroidDecrypter.Companion.androidDecrypter
import org.ole.planet.myplanet.utilities.*
import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME
import org.ole.planet.myplanet.utilities.Constants.autoSynFeature
Expand All @@ -41,7 +41,7 @@ import org.ole.planet.myplanet.utilities.DialogUtils.showAlert
import org.ole.planet.myplanet.utilities.DialogUtils.showSnack
import org.ole.planet.myplanet.utilities.DialogUtils.showWifiSettingDialog
import org.ole.planet.myplanet.utilities.NetworkUtils.getCustomDeviceName
import org.ole.planet.myplanet.utilities.NotificationUtil.cancellAll
import org.ole.planet.myplanet.utilities.NotificationUtil.cancelAll
import org.ole.planet.myplanet.utilities.Utilities.getRelativeTime
import org.ole.planet.myplanet.utilities.Utilities.openDownloadService
import retrofit2.Call
Expand Down Expand Up @@ -259,7 +259,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
return true
}
} else {
if (AndroidDecrypter(username, password, it.derived_key, it.salt)) {
if (androidDecrypter(username, password, it.derived_key, it.salt)) {
if (isManagerMode && !it.isManager()) return false
saveUserInfoPref(settings, password, it)
return true
Expand Down Expand Up @@ -319,7 +319,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
createLog("synced successfully")
showSnack(findViewById(android.R.id.content), getString(R.string.sync_completed))
downloadAdditionalResources()
cancellAll(this)
cancelAll(this)
}
}
}
Expand Down Expand Up @@ -418,7 +418,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
service.getMinApk(this, url, pin)
}
}
if (!prefData.getMANUALCONFIG()) {
if (!prefData.getManualConfig()) {
dialogServerUrlBinding.manualConfiguration.isChecked = false
showConfigurationUIElements(dialogServerUrlBinding, false)
} else {
Expand All @@ -429,7 +429,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
positiveAction = dialog.getActionButton(DialogAction.POSITIVE)
dialogServerUrlBinding.manualConfiguration.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
if (isChecked) {
prefData.setMANUALCONFIG(true)
prefData.setManualConfig(true)
editor.putString("serverURL", "").apply()
editor.putString("serverPin", "").apply()
dialogServerUrlBinding.radioHttp.isChecked = true
Expand Down Expand Up @@ -464,7 +464,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
setUrlAndPin(settings.getBoolean("switchCloudUrl", false))
protocolSemantics()
} else {
prefData.setMANUALCONFIG(false)
prefData.setManualConfig(false)
showConfigurationUIElements(dialogServerUrlBinding, false)
editor.putBoolean("switchCloudUrl", false).apply()
}
Expand All @@ -491,7 +491,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
}
}
dialogServerUrlBinding.team.adapter = teamAdapter
val lastSelection = prefData.getSELECTEDTEAMID()
val lastSelection = prefData.getSelectedTeamId()
if (!lastSelection.isNullOrEmpty()) {
for (i in teams.indices) {
val team = teams[i]
Expand All @@ -506,9 +506,9 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long) {
if (position > 0) {
val selectedTeam = teams[position - 1]
val currentTeamId = prefData.getSELECTEDTEAMID()
val currentTeamId = prefData.getSelectedTeamId()
if (currentTeamId != selectedTeam._id) {
prefData.setSELECTEDTEAMID(selectedTeam._id)
prefData.setSelectedTeamId(selectedTeam._id)
if (this@SyncActivity is LoginActivity) {
this@SyncActivity.getTeamMembers()
}
Expand Down Expand Up @@ -744,7 +744,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
fun clearSharedPref() {
val settings = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
val editor = settings.edit()
val keysToKeep = setOf(SharedPrefManager(context).FIRSTLAUNCH)
val keysToKeep = setOf(SharedPrefManager(context).firstLaunch)
val tempStorage = HashMap<String, Boolean>()
for (key in keysToKeep) {
tempStorage[key] = settings.getBoolean(key, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AdapterTeamList(private val context: Context, private val list: List<Realm
b.putBoolean("isMyTeam", isMyTeam)
f.arguments = b
(context as OnHomeItemClickListener).openCallFragment(f)
prefData.setTEAMNAME(filteredList[position].name)
prefData.setTeamName(filteredList[position].name)
}
}
itemTeamListBinding.btnFeedback.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.ole.planet.myplanet.service.AudioRecorderService.AudioRecordListener
import org.ole.planet.myplanet.ui.resources.AddResourceFragment
import org.ole.planet.myplanet.utilities.FileUtils
import org.ole.planet.myplanet.utilities.IntentUtils.openAudioFile
import org.ole.planet.myplanet.utilities.NotificationUtil.cancellAll
import org.ole.planet.myplanet.utilities.NotificationUtil.cancelAll
import org.ole.planet.myplanet.utilities.NotificationUtil.create
import org.ole.planet.myplanet.utilities.Utilities
import java.io.File
Expand Down Expand Up @@ -93,7 +93,7 @@ class PDFReaderActivity : AppCompatActivity(), OnPageChangeListener, OnLoadCompl

override fun onRecordStopped(outputFile: String?) {
Utilities.toast(this, getString(R.string.recording_stopped))
cancellAll(this)
cancelAll(this)
updateTranslation(outputFile)
AddResourceFragment.showAlert(this, outputFile)
activityPdfReaderBinding.fabRecord.setImageResource(R.drawable.ic_mic)
Expand All @@ -116,7 +116,7 @@ class PDFReaderActivity : AppCompatActivity(), OnPageChangeListener, OnLoadCompl
}

override fun onError(error: String?) {
cancellAll(this)
cancelAll(this)
Utilities.toast(this, error)
activityPdfReaderBinding.fabRecord.setImageResource(R.drawable.ic_mic)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.ole.planet.myplanet.utilities
import de.rtner.misc.BinTools
import de.rtner.security.auth.spi.PBKDF2Engine
import de.rtner.security.auth.spi.PBKDF2Parameters
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
import java.util.Locale
Expand All @@ -15,27 +14,6 @@ import javax.crypto.spec.SecretKeySpec

class AndroidDecrypter {
companion object {
@JvmStatic
fun md5(s: String): String {
val MD5 = "MD5"
try {
val digest = MessageDigest.getInstance(MD5)
digest.update(s.toByteArray())
val messageDigest = digest.digest()

val hexString = StringBuilder()
for (aMessageDigest in messageDigest) {
var h = Integer.toHexString(0xFF and aMessageDigest.toInt())
while (h.length < 2) h = "0$h"
hexString.append(h)
}
return hexString.toString()

} catch (e: NoSuchAlgorithmException) {
e.printStackTrace()
}
return ""
}

@JvmStatic
@Throws(Exception::class)
Expand Down Expand Up @@ -95,12 +73,12 @@ class AndroidDecrypter {
}

@JvmStatic
fun AndroidDecrypter(usr_ID: String?, usr_rawPswd: String?, db_PswdkeyValue: String?, db_Salt: String?): Boolean {
fun androidDecrypter(usrId: String?, usrRawPwd: String?, dbPwdKeyValue: String?, dbSalt: String?): Boolean {
try {
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)
val p = PBKDF2Parameters("HmacSHA1", "utf-8", dbSalt?.toByteArray(), 10)
val dk = PBKDF2Engine(p).deriveKey(usrRawPwd, 20)
println("$usrId Value ${BinTools.bin2hex(dk).lowercase(Locale.ROOT)}")
return dbPwdKeyValue.equals(BinTools.bin2hex(dk).lowercase(Locale.ROOT), ignoreCase = true)

} catch (e: Exception) {
e.printStackTrace()
Expand All @@ -111,10 +89,10 @@ class AndroidDecrypter {
@JvmStatic
fun generateIv(): String {
try {
val IV = ByteArray(16)
val iv = ByteArray(16)
val random = SecureRandom()
random.nextBytes(IV)
return bytesToHex(IV)
random.nextBytes(iv)
return bytesToHex(iv)
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down
Loading

0 comments on commit 1bf9b25

Please sign in to comment.