Skip to content

Commit

Permalink
Merge branch 'master' into 3727-better-placeholder-for-empty-teamente…
Browse files Browse the repository at this point in the history
…rprise-list
  • Loading branch information
Okuro3499 authored Jul 3, 2024
2 parents 0c2c462 + bfc79e0 commit f83aca5
Show file tree
Hide file tree
Showing 18 changed files with 790 additions and 134 deletions.
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

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 1640
versionName "0.16.40"
versionCode 1646
versionName "0.16.46"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.dashboard.DashboardActivity
import org.ole.planet.myplanet.ui.dashboard.DashboardFragment
import org.ole.planet.myplanet.ui.sync.LoginActivity
import org.ole.planet.myplanet.ui.sync.SyncActivity.Companion.clearRealmDb
import org.ole.planet.myplanet.ui.sync.SyncActivity.Companion.clearSharedPref
import org.ole.planet.myplanet.ui.sync.SyncActivity.Companion.restartApp
import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME
import org.ole.planet.myplanet.utilities.DialogUtils
import org.ole.planet.myplanet.utilities.FileUtils.availableOverTotalMemoryFormattedString
Expand Down Expand Up @@ -100,15 +103,9 @@ class SettingActivity : AppCompatActivity() {
preference.onPreferenceClickListener = OnPreferenceClickListener {
AlertDialog.Builder(requireActivity()).setTitle(R.string.are_you_sure)
.setPositiveButton(R.string.yes) { _: DialogInterface?, _: Int ->
BaseResourceFragment.settings?.edit()?.clear()?.apply()
mRealm.executeTransactionAsync(
Realm.Transaction { realm: Realm -> realm.deleteAll() },
Realm.Transaction.OnSuccess {
Utilities.toast(requireActivity(), R.string.data_cleared.toString())
startActivity(Intent(requireActivity(), LoginActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK))
openDashboard = false
requireActivity().finish()
})
clearRealmDb()
clearSharedPref()
restartApp()
}.setNegativeButton(R.string.no, null).show()
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,26 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa

private fun setUpMyLife(userId: String?) {
val realm = DatabaseService(requireContext()).realmInstance
val realmObjects = RealmMyLife.getMyLifeByUserId(mRealm, settings)
if (realmObjects.isEmpty()) {
if (!realm.isInTransaction) {
realm.beginTransaction()
}
val myLifeListBase = getMyLifeListBase(userId)
var ml: RealmMyLife
var weight = 1
for (item in myLifeListBase) {
ml = realm.createObject(RealmMyLife::class.java, UUID.randomUUID().toString())
ml.title = item.title
ml.imageId = item.imageId
ml.weight = weight
ml.userId = item.userId
ml.isVisible = true
weight++
realm.executeTransactionAsync({ realmTransaction ->
val realmObjects = RealmMyLife.getMyLifeByUserId(realmTransaction, settings)
if (realmObjects.isEmpty()) {
val myLifeListBase = getMyLifeListBase(userId)
var weight = 1
for (item in myLifeListBase) {
val ml = realmTransaction.createObject(RealmMyLife::class.java, UUID.randomUUID().toString())
ml.title = item.title
ml.imageId = item.imageId
ml.weight = weight
ml.userId = item.userId
ml.isVisible = true
weight++
}
}
realm.commitTransaction()
}
}, {
realm.close()
}, {
realm.close()
})
}

private fun myLibraryItemClickAction(textView: TextView, items: RealmMyLibrary?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.drawerlayout.widget.DrawerLayout
Expand Down Expand Up @@ -99,10 +98,10 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
val userProfileModel = profileDbHandler.userModel
if (userProfileModel != null) {
var name: String? = userProfileModel.getFullName()
if (name?.trim { it <= ' ' }?.isEmpty() == true) {
if (name.isNullOrBlank()) {
name = profileDbHandler.userModel?.name
}
activityDashboardBinding.appBarBell.appTitleName.text = "$name's Planet"
activityDashboardBinding.appBarBell.appTitleName.text = getString(R.string.planet_name, name)
} else {
activityDashboardBinding.appBarBell.appTitleName.text = getString(R.string.app_project_name)
}
Expand Down Expand Up @@ -131,7 +130,6 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
result?.stickyFooter?.setPadding(0, 0, 0, 0) // moves logout button to the very bottom of the drawer. Without it, the "logout" button suspends a little.
result?.actionBarDrawerToggle?.isDrawerIndicatorEnabled = true
dl = result?.drawerLayout
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.statusBars())
result?.drawerLayout?.fitsSystemWindows = false
topbarSetting()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.drawerlayout.widget.DrawerLayout
Expand Down Expand Up @@ -99,10 +98,10 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
val userProfileModel = profileDbHandler.userModel
if (userProfileModel != null) {
var name: String? = userProfileModel.getFullName()
if (name?.trim { it <= ' ' }?.isEmpty() == true) {
if (name.isNullOrBlank()) {
name = profileDbHandler.userModel?.name
}
activityDashboardBinding.appBarBell.appTitleName.text = "$name's Planet"
activityDashboardBinding.appBarBell.appTitleName.text = getString(R.string.planet_name, name)
} else {
activityDashboardBinding.appBarBell.appTitleName.text = getString(R.string.app_project_name)
}
Expand Down Expand Up @@ -131,7 +130,6 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
result?.stickyFooter?.setPadding(0, 0, 0, 0) // moves logout button to the very bottom of the drawer. Without it, the "logout" button suspends a little.
result?.actionBarDrawerToggle?.isDrawerIndicatorEnabled = true
dl = result?.drawerLayout
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.statusBars())
result?.drawerLayout?.fitsSystemWindows = false
topbarSetting()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.google.gson.JsonParser.parseString
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.databinding.FragmentHelpWantedBinding
import org.ole.planet.myplanet.ui.sync.SyncActivity
import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME
import org.ole.planet.myplanet.utilities.JsonUtils.getString

Expand All @@ -23,7 +22,7 @@ class HelpWantedFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
fragmentHelpWantedBinding = FragmentHelpWantedBinding.inflate(inflater, container, false)
settings = requireActivity().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
if (settings.contains("user_admin")) manager = JsonParser().parse(settings.getString("user_admin", "")).asJsonObject
if (settings.contains("user_admin")) manager = parseString(settings.getString("user_admin", "")).asJsonObject
return fragmentHelpWantedBinding.root
}

Expand Down
20 changes: 6 additions & 14 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 @@ -258,7 +258,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
selectedTeamId = prefData.getSELECTEDTEAMID().toString()
if (selectedTeamId?.isNotEmpty() == true) {
users = RealmMyTeam.getUsers(selectedTeamId, mRealm, "")
val userList = (users as MutableList<RealmUserModel>?)?.map {
val userList = (users as? MutableList<RealmUserModel>)?.map {
User(it.getFullName(), it.name ?: "", "", it.userImage ?: "", "team")
} ?: emptyList()

Expand All @@ -268,22 +268,14 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
prefData.setSAVEDUSERS(updatedUserList)
}

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

activityLoginBinding.recyclerView.layoutManager = LinearLayoutManager(this)
activityLoginBinding.recyclerView.adapter = mAdapter

val layoutManager: RecyclerView.LayoutManager = object : LinearLayoutManager(this) {
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
return RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
}
activityLoginBinding.recyclerView.layoutManager = layoutManager
activityLoginBinding.recyclerView.isNestedScrollingEnabled = true
activityLoginBinding.recyclerView.setHasFixedSize(true)
}
Expand Down
137 changes: 67 additions & 70 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 @@ -134,35 +134,6 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
.show()
}

private fun clearSharedPref() {
val keysToKeep = setOf(prefData.FIRSTLAUNCH)
val tempStorage = HashMap<String, Boolean>()
for (key in keysToKeep) {
tempStorage[key] = settings.getBoolean(key, false)
}
editor.clear().commit()
val editor = editor
for ((key, value) in tempStorage) {
editor.putBoolean(key, value)
}
editor.commit()
}

private fun clearRealmDb(){
val realm = Realm.getDefaultInstance()
realm.executeTransaction { transactionRealm ->
transactionRealm.deleteAll()
}
realm.close()
}

private fun restartApp() {
val intent = packageManager.getLaunchIntentForPackage(packageName)
val mainIntent = Intent.makeRestartActivityTask(intent?.component)
startActivity(mainIntent)
Runtime.getRuntime().exit(0)
}

private fun clearInternalStorage() {
val myDir = File(Utilities.SD_PATH)
if (myDir.isDirectory) {
Expand Down Expand Up @@ -505,55 +476,51 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
dialogServerUrlBinding.clearData.setOnClickListener {
clearDataDialog(getString(R.string.are_you_sure_you_want_to_clear_data))
}
if (prefData.getMANUALCONFIG()) {
val teams: List<RealmMyTeam> = mRealm.where(RealmMyTeam::class.java).isEmpty("teamId").equalTo("status", "active").findAll()
if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" != "") {
dialogServerUrlBinding.team.visibility = View.VISIBLE
teamAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, teamList)
teamAdapter?.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
teamList.clear()
teamList.add("select team")
for (team in teams) {
if (team.isValid) {
teamList.add(team.name)
}
val teams: List<RealmMyTeam> = mRealm.where(RealmMyTeam::class.java).isEmpty("teamId").equalTo("status", "active").findAll()
if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" != "") {
dialogServerUrlBinding.team.visibility = View.VISIBLE
teamAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, teamList)
teamAdapter?.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
teamList.clear()
teamList.add("select team")
for (team in teams) {
if (team.isValid) {
teamList.add(team.name)
}
dialogServerUrlBinding.team.adapter = teamAdapter
val lastSelection = prefData.getSELECTEDTEAMID()
if (!lastSelection.isNullOrEmpty()) {
for (i in teams.indices) {
val team = teams[i]
if (team._id != null && team._id == lastSelection && team.isValid) {
val lastSelectedPosition = i + 1
dialogServerUrlBinding.team.setSelection(lastSelectedPosition)
break
}
}
dialogServerUrlBinding.team.adapter = teamAdapter
val lastSelection = prefData.getSELECTEDTEAMID()
if (!lastSelection.isNullOrEmpty()) {
for (i in teams.indices) {
val team = teams[i]
if (team._id != null && team._id == lastSelection && team.isValid) {
val lastSelectedPosition = i + 1
dialogServerUrlBinding.team.setSelection(lastSelectedPosition)
break
}
}
dialogServerUrlBinding.team.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long) {
if (position > 0) {
val selectedTeam = teams[position - 1]
val currentTeamId = prefData.getSELECTEDTEAMID()
if (currentTeamId != selectedTeam._id) {
prefData.setSELECTEDTEAMID(selectedTeam._id)
if (this@SyncActivity is LoginActivity) {
this@SyncActivity.getTeamMembers()
}
dialog.dismiss()
}
dialogServerUrlBinding.team.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long) {
if (position > 0) {
val selectedTeam = teams[position - 1]
val currentTeamId = prefData.getSELECTEDTEAMID()
if (currentTeamId != selectedTeam._id) {
prefData.setSELECTEDTEAMID(selectedTeam._id)
if (this@SyncActivity is LoginActivity) {
this@SyncActivity.getTeamMembers()
}
dialog.dismiss()
}
}

override fun onNothingSelected(parentView: AdapterView<*>?) {
// Do nothing when nothing is selected
}
}
} else if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" == "") {
dialogServerUrlBinding.team.visibility = View.GONE
} else {
dialogServerUrlBinding.team.visibility = View.GONE

override fun onNothingSelected(parentView: AdapterView<*>?) { }
}
} else if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" == "") {
dialogServerUrlBinding.team.visibility = View.GONE
} else {
dialogServerUrlBinding.team.visibility = View.GONE
}
dialog.show()
sync(dialog)
Expand Down Expand Up @@ -763,5 +730,35 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
companion object {
lateinit var cal_today: Calendar
lateinit var cal_last_Sync: Calendar

fun clearRealmDb() {
val realm = Realm.getDefaultInstance()
realm.executeTransaction { transactionRealm ->
transactionRealm.deleteAll()
}
realm.close()
}

fun clearSharedPref() {
val settings = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
val editor = settings.edit()
val keysToKeep = setOf(SharedPrefManager(context).FIRSTLAUNCH)
val tempStorage = HashMap<String, Boolean>()
for (key in keysToKeep) {
tempStorage[key] = settings.getBoolean(key, false)
}
editor.clear().commit()
for ((key, value) in tempStorage) {
editor.putBoolean(key, value)
}
editor.commit()
}

fun restartApp() {
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
val mainIntent = Intent.makeRestartActivityTask(intent?.component)
context.startActivity(mainIntent)
Runtime.getRuntime().exit(0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.databinding.UserListItemBinding
import org.ole.planet.myplanet.model.User

class TeamListAdapter(private val membersList: MutableList<User>, val context: Context, private val onItemClickListener: OnItemClickListener) : RecyclerView.Adapter<TeamListAdapter.ViewHolder>() {
class TeamListAdapter(private var membersList: MutableList<User>, val context: Context, private val onItemClickListener: OnItemClickListener) : RecyclerView.Adapter<TeamListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = UserListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
Expand Down Expand Up @@ -38,6 +38,11 @@ class TeamListAdapter(private val membersList: MutableList<User>, val context: C
notifyDataSetChanged()
}

fun updateList(newUserList: MutableList<User>) {
membersList = newUserList
notifyDataSetChanged()
}

class ViewHolder(private val binding: UserListItemBinding) : RecyclerView.ViewHolder(binding.root) {
fun bindView(account: User) {
if (account.fullName?.isEmpty() == true || account.fullName == " ") {
Expand Down
Loading

0 comments on commit f83aca5

Please sign in to comment.