Skip to content

Commit

Permalink
teams: smoother reports deletion (fixes #4995) (#4996)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
Okuro3499 and dogi authored Jan 13, 2025
1 parent 5712f21 commit dc0ae67
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 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 26
targetSdkVersion 34
versionCode 2189
versionName "0.21.89"
versionCode 2190
versionName "0.21.90"
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 @@ -167,7 +167,15 @@ class AdapterReports(private val context: Context, private var list: RealmResult
builder.setTitle("Delete Report")
.setMessage(R.string.delete_record)
.setPositiveButton(R.string.ok) { _, _ ->
RealmMyTeam.deleteReport(reportId, mRealm)
mRealm.executeTransaction { realm ->
realm.where(RealmMyTeam::class.java)
.equalTo("_id", reportId)
.findFirst()?.apply {
status = "archived"
updated = true
}
}
notifyDataSetChanged()
}
.setNegativeButton("Cancel", null)
.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@ class ReportsFragment : BaseTeamFragment() {
createFileLauncher.launch(intent)
}

list = mRealm.where(RealmMyTeam::class.java).equalTo("teamId", teamId)
list = mRealm.where(RealmMyTeam::class.java)
.equalTo("teamId", teamId)
.equalTo("docType", "report")
.sort("date", Sort.DESCENDING).findAllAsync()
.notEqualTo("status", "archived")
.sort("date", Sort.DESCENDING)
.findAllAsync()

list?.addChangeListener { results ->
updatedReportsList(results)
Expand All @@ -176,9 +179,12 @@ class ReportsFragment : BaseTeamFragment() {
val uri = result.data?.data
if (uri != null) {
try {
val reports = mRealm.where(RealmMyTeam::class.java).equalTo("teamId", teamId)
val reports = mRealm.where(RealmMyTeam::class.java)
.equalTo("teamId", teamId)
.equalTo("docType", "report")
.sort("date", Sort.DESCENDING).findAll()
.notEqualTo("status", "archived")
.sort("date", Sort.DESCENDING)
.findAll()
val csvBuilder = StringBuilder()
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")
Expand Down Expand Up @@ -209,9 +215,12 @@ class ReportsFragment : BaseTeamFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
list = mRealm.where(RealmMyTeam::class.java).equalTo("teamId", teamId)
list = mRealm.where(RealmMyTeam::class.java)
.equalTo("teamId", teamId)
.equalTo("docType", "report")
.sort("date", Sort.DESCENDING).findAll()
.notEqualTo("status", "archived") // Add this line
.sort("date", Sort.DESCENDING)
.findAll()
updatedReportsList(list as RealmResults<RealmMyTeam>)
}

Expand All @@ -222,7 +231,7 @@ class ReportsFragment : BaseTeamFragment() {
llImage?.removeAllViews()
}

private fun updatedReportsList(results: RealmResults<RealmMyTeam>) {
fun updatedReportsList(results: RealmResults<RealmMyTeam>) {
activity?.runOnUiThread {
adapterReports = AdapterReports(requireContext(), results)
adapterReports.setNonTeamMember(!isMember())
Expand Down

0 comments on commit dc0ae67

Please sign in to comment.