-
Notifications
You must be signed in to change notification settings - Fork 425
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-776 Migrated Logs activity to kotlin #766
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 0 additions & 62 deletions
62
openmrs-client/src/main/java/org/openmrs/mobile/activities/logs/LogsActivity.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
openmrs-client/src/main/java/org/openmrs/mobile/activities/logs/LogsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.mobile.activities.logs | ||
|
||
import android.os.Bundle | ||
import android.view.Menu | ||
import org.openmrs.mobile.R | ||
import org.openmrs.mobile.activities.ACBaseActivity | ||
|
||
class LogsActivity : ACBaseActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_logs) | ||
val actionBar = supportActionBar | ||
if (actionBar != null) { | ||
actionBar.elevation = 0f | ||
actionBar.setDisplayHomeAsUpEnabled(true) | ||
} | ||
// Create fragment | ||
var logsFragment = supportFragmentManager.findFragmentById(R.id.logsContentFragment) as LogsFragment? | ||
if (logsFragment == null) { | ||
logsFragment = LogsFragment.newInstance() | ||
} | ||
if (!logsFragment.isActive) { | ||
addFragmentToActivity(supportFragmentManager, | ||
logsFragment, R.id.logsContentFragment) | ||
} | ||
// Create the presenter | ||
LogsPresenter(logsFragment, mOpenMRSLogger) | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
super.onCreateOptionsMenu(menu) | ||
//Disable Settings Option in Menu | ||
val settingsItem = menu.findItem(R.id.actionSettings) | ||
settingsItem.isVisible = false | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
openmrs-client/src/main/java/org/openmrs/mobile/activities/logs/LogsFragment.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
openmrs-client/src/main/java/org/openmrs/mobile/activities/logs/LogsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.mobile.activities.logs | ||
|
||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import org.openmrs.mobile.R | ||
import org.openmrs.mobile.activities.ACBaseFragment | ||
import org.openmrs.mobile.databinding.FragmentLogsBinding | ||
|
||
class LogsFragment : ACBaseFragment<LogsContract.Presenter>(), LogsContract.View { | ||
|
||
private lateinit var _binding: FragmentLogsBinding | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle?): View? { | ||
_binding = FragmentLogsBinding.inflate(inflater, container, false) | ||
return _binding.root | ||
} | ||
|
||
override fun attachLogsToTextView(logs: String?) { | ||
_binding.tvLogs.text = logs | ||
} | ||
|
||
override fun fabCopyAll(textLogs: String?) { | ||
_binding.fab.setOnClickListener { | ||
setClipboard(context, textLogs) | ||
Toast.makeText(context, R.string.logs_copied_to_clipboard_message, | ||
Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
private fun setClipboard(context: Context?, text: String?) { | ||
val clipboard = context!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager | ||
val clip = ClipData.newPlainText(getString(R.string.copied_text), text) | ||
clipboard.primaryClip = clip | ||
} | ||
|
||
companion object { | ||
fun newInstance(): LogsFragment { | ||
return LogsFragment() | ||
} | ||
} | ||
} |
70 changes: 0 additions & 70 deletions
70
openmrs-client/src/main/java/org/openmrs/mobile/activities/logs/LogsPresenter.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
openmrs-client/src/main/java/org/openmrs/mobile/activities/logs/LogsPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.mobile.activities.logs | ||
|
||
import org.openmrs.mobile.activities.BasePresenter | ||
import org.openmrs.mobile.application.OpenMRS | ||
import org.openmrs.mobile.application.OpenMRSLogger | ||
import java.io.* | ||
|
||
class LogsPresenter(private val mLogsView: LogsContract.View, private val mOpenMRSLogger: OpenMRSLogger) : BasePresenter(), LogsContract.Presenter { | ||
|
||
override fun subscribe() { | ||
val logsText = getLogs() | ||
mLogsView.attachLogsToTextView(logsText) | ||
mLogsView.fabCopyAll(logsText) | ||
} | ||
|
||
init { | ||
mLogsView.setPresenter(this) | ||
} | ||
|
||
private fun getLogs(): String { | ||
var textLogs = "" | ||
val filename = (OpenMRS.getInstance().openMRSDir | ||
+ File.separator + mOpenMRSLogger.logFilename) | ||
try { | ||
val myFile = File(filename) | ||
val fIn = FileInputStream(myFile) | ||
val myReader = BufferedReader(InputStreamReader(fIn)) | ||
while (myReader.readLine() != null) { | ||
textLogs += myReader.readLine() | ||
} | ||
myReader.close() | ||
} catch (e: FileNotFoundException) { | ||
e.printStackTrace() | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
return textLogs | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rishabh-997 can we do away with the underscore is it necessary ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a practice followed in kotlin where unused variables are marked as _... As suggested by Android Studio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay @rishabh-997 👍