Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AC-1041: Migrate settings package from MVP to MVVM architecture #962

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.openmrs.android_sdk.library.api.repository

import com.openmrs.android_sdk.library.dao.ConceptRoomDAO
import com.openmrs.android_sdk.library.databases.AppDatabaseHelper
import com.openmrs.android_sdk.library.models.ConceptAnswers
import com.openmrs.android_sdk.library.models.ConceptMembers
Expand All @@ -13,6 +14,8 @@ import java.util.concurrent.Callable
@Singleton
class ConceptRepository @Inject constructor() : BaseRepository() {

private val conceptRoomDAO: ConceptRoomDAO = db.conceptRoomDAO()

/**
* Gets system property.
*
Expand Down Expand Up @@ -57,4 +60,8 @@ class ConceptRepository @Inject constructor() : BaseRepository() {
}
})
}


fun getConceptCountFromDb() = conceptRoomDAO.conceptsCount

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ package org.openmrs.mobile.activities.logs

import android.os.Bundle
import android.view.Menu
import dagger.hilt.android.AndroidEntryPoint
import org.openmrs.mobile.R
import org.openmrs.mobile.activities.ACBaseActivity

@AndroidEntryPoint
class LogsActivity : ACBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -37,8 +39,6 @@ class LogsActivity : ACBaseActivity() {
addFragmentToActivity(supportFragmentManager,
logsFragment, R.id.logsContentFragment)
}
// Create the presenter
LogsPresenter(logsFragment, mOpenMRSLogger)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand All @@ -48,4 +48,4 @@ class LogsActivity : ACBaseActivity() {
settingsItem.isVisible = false
return true
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,51 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
import org.openmrs.mobile.R
import org.openmrs.mobile.activities.ACBaseFragment
import org.openmrs.mobile.activities.BaseFragment
import org.openmrs.mobile.databinding.FragmentLogsBinding

class LogsFragment : ACBaseFragment<LogsContract.Presenter>(), LogsContract.View {

@AndroidEntryPoint
class LogsFragment : BaseFragment() {
private var _binding: FragmentLogsBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
private val viewModel: LogsViewModel by viewModels()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentLogsBinding.inflate(inflater, container, false)

attachLogsToTextView()
setupCopyAllFAB()

return binding.root
}

override fun attachLogsToTextView(logs: String?) {
binding.tvLogs.text = logs
private fun attachLogsToTextView() {
binding.tvLogs.text = viewModel.logs
}

override fun fabCopyAll(textLogs: String?) {
private fun setupCopyAllFAB() {
binding.fab.setOnClickListener {
setClipboard(context, textLogs)
Toast.makeText(context, R.string.logs_copied_to_clipboard_message,
Toast.LENGTH_SHORT).show()
copyToClipboard(viewModel.logs)
Toast.makeText(context, R.string.logs_copied_to_clipboard_message, Toast.LENGTH_SHORT).show()
}
}

private fun setClipboard(context: Context?, text: String?) {
private fun copyToClipboard(text: String) {
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText(getString(R.string.copied_text), text)
clipboard.setPrimaryClip(clip)
}

companion object {
fun newInstance(): LogsFragment {
return LogsFragment()
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

companion object {
fun newInstance() = LogsFragment()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.openmrs.mobile.activities.logs

import com.openmrs.android_sdk.library.OpenMRSLogger
import com.openmrs.android_sdk.library.OpenmrsAndroid
import dagger.hilt.android.lifecycle.HiltViewModel
import org.openmrs.mobile.activities.BaseViewModel
import javax.inject.Inject
import java.io.BufferedReader
import java.io.File
import java.io.FileInputStream
import java.io.InputStreamReader

@HiltViewModel
class LogsViewModel @Inject constructor(private val openMRSLogger: OpenMRSLogger) : BaseViewModel<Unit>() {

val logs: String = readLogsFromFile()

private fun readLogsFromFile(): String {
var textLogs = ""
try {
val filename = OpenmrsAndroid.getOpenMRSDir() + File.separator + openMRSLogger.logFilename
val stream = FileInputStream(File(filename))
val reader = BufferedReader(InputStreamReader(stream))
while (reader.readLine() != null) textLogs += reader.readLine()
reader.close()
} catch (e: Exception) {
e.printStackTrace()
openMRSLogger.e(e.message)
}
return textLogs
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import android.app.Activity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import dagger.hilt.android.AndroidEntryPoint
import org.openmrs.mobile.R
import org.openmrs.mobile.activities.ACBaseActivity

@AndroidEntryPoint
class SettingsActivity : ACBaseActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
Expand All @@ -40,8 +43,6 @@ class SettingsActivity : ACBaseActivity() {
addFragmentToActivity(supportFragmentManager,
settingsFragment, R.id.settingsContentFrame)
}
// Create the presenter
SettingsPresenter(settingsFragment, mOpenMRSLogger)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand All @@ -67,4 +68,4 @@ class SettingsActivity : ACBaseActivity() {
setResult(Activity.RESULT_OK, null)
super.onBackPressed()
}
}
}

This file was deleted.

Loading