Skip to content

Commit

Permalink
all: safer with call operators in viewer (fixes #3258) (#3264)
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 Mar 18, 2024
1 parent 6ad2fc7 commit 144bf68
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 44 deletions.
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 1422
versionName "0.14.22"
versionCode 1423
versionName "0.14.23"
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 @@ -14,18 +14,18 @@ import java.io.File
import java.util.regex.Pattern

class AudioPlayerActivity : AppCompatActivity(), JcPlayerManagerListener {
private var activityAudioPlayerBinding: ActivityAudioPlayerBinding? = null
private lateinit var activityAudioPlayerBinding: ActivityAudioPlayerBinding
private lateinit var jcAudios: ArrayList<JcAudio>
private var isFullPath = false
private var filePath: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityAudioPlayerBinding = ActivityAudioPlayerBinding.inflate(layoutInflater)
setContentView(activityAudioPlayerBinding!!.root)
setContentView(activityAudioPlayerBinding.root)
filePath = intent.getStringExtra("TOUCHED_FILE")
jcAudios = ArrayList()
isFullPath = intent.getBooleanExtra("isFullPath", false)
if (filePath!!.matches(".*[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}//.*".toRegex())) {
if (filePath?.matches(".*[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}//.*".toRegex()) == true) {
playRecordedAudio()
} else {
playDownloadedAudio()
Expand All @@ -39,7 +39,9 @@ class AudioPlayerActivity : AppCompatActivity(), JcPlayerManagerListener {
val basePath = getExternalFilesDir(null)
File(basePath, "ole/$filePath").absolutePath
}
jcAudios.add(JcAudio.createFromFilePath(fullPath!!))
fullPath?.let {
JcAudio.createFromFilePath(it)
}?.let { jcAudios.add(it) }
initializeJCPlayer()
}

Expand All @@ -48,16 +50,18 @@ class AudioPlayerActivity : AppCompatActivity(), JcPlayerManagerListener {
val matcher = filePath?.let { uuidPattern.matcher(it) }
if (matcher != null) {
if (matcher.find()) {
filePath = filePath!!.substring(matcher.group().length)
filePath = filePath?.substring(matcher.group().length)
}
}
jcAudios.add(JcAudio.createFromFilePath(filePath!!))
filePath?.let {
JcAudio.createFromFilePath(it)
}?.let { jcAudios.add(it) }
initializeJCPlayer()
}

private fun initializeJCPlayer() {
activityAudioPlayerBinding!!.jcplayer.initPlaylist(jcAudios, null)
val rootView = activityAudioPlayerBinding!!.jcplayer.rootView
activityAudioPlayerBinding.jcplayer.initPlaylist(jcAudios, null)
val rootView = activityAudioPlayerBinding.jcplayer.rootView
rootView.findViewById<View>(R.id.btnNext).visibility = View.GONE
rootView.findViewById<View>(R.id.btnPrev).visibility = View.GONE
rootView.findViewById<View>(R.id.btnRepeatOne).visibility = View.GONE
Expand All @@ -72,20 +76,20 @@ class AudioPlayerActivity : AppCompatActivity(), JcPlayerManagerListener {

override fun onPause() {
super.onPause()
if (activityAudioPlayerBinding!!.jcplayer.isPlaying) {
activityAudioPlayerBinding!!.jcplayer.pause()
if (activityAudioPlayerBinding.jcplayer.isPlaying) {
activityAudioPlayerBinding.jcplayer.pause()
}
}

override fun onStop() {
super.onStop()
activityAudioPlayerBinding!!.jcplayer.kill()
activityAudioPlayerBinding.jcplayer.kill()
}

override fun onResume() {
super.onResume()
if (jcAudios.size > 0) {
activityAudioPlayerBinding!!.jcplayer.playAudio(jcAudios[0])
activityAudioPlayerBinding.jcplayer.playAudio(jcAudios[0])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ import com.opencsv.CSVReaderBuilder
import org.ole.planet.myplanet.databinding.ActivityCsvviewerBinding
import java.io.File
import java.io.FileReader
import java.util.Arrays

class CSVViewerActivity : AppCompatActivity() {
private var activityCsvviewerBinding: ActivityCsvviewerBinding? = null
private lateinit var activityCsvviewerBinding: ActivityCsvviewerBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityCsvviewerBinding = ActivityCsvviewerBinding.inflate(layoutInflater)
setContentView(activityCsvviewerBinding!!.root)
setContentView(activityCsvviewerBinding.root)
renderCSVFile()
}

private fun renderCSVFile() {
val csvFileOpenIntent = intent
val fileName = csvFileOpenIntent.getStringExtra("TOUCHED_FILE")
if (!fileName.isNullOrEmpty()) {
activityCsvviewerBinding!!.csvFileName.text = fileName
activityCsvviewerBinding!!.csvFileName.visibility = View.VISIBLE
activityCsvviewerBinding.csvFileName.text = fileName
activityCsvviewerBinding.csvFileName.visibility = View.VISIBLE
}
try {
val csvFile: File = if (fileName!!.startsWith("/")) {
Expand All @@ -40,8 +39,8 @@ class CSVViewerActivity : AppCompatActivity() {
).build()
val allRows = reader.readAll()
for (row in allRows) {
activityCsvviewerBinding!!.csvFileContent.append(Arrays.toString(row))
activityCsvviewerBinding!!.csvFileContent.append("\n")
activityCsvviewerBinding.csvFileContent.append(row.contentToString())
activityCsvviewerBinding.csvFileContent.append("\n")
}
} catch (e: Exception) {
e.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import java.io.File
import java.util.regex.Pattern

class ImageViewerActivity : AppCompatActivity() {
private var activityImageViewerBinding: ActivityImageViewerBinding? = null
private lateinit var activityImageViewerBinding: ActivityImageViewerBinding
var fileName: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityImageViewerBinding = ActivityImageViewerBinding.inflate(layoutInflater)
setContentView(activityImageViewerBinding!!.root)
setContentView(activityImageViewerBinding.root)
renderImageFile()
}

private fun renderImageFile() {
val isFullPath = intent.getBooleanExtra("isFullPath", false)
val imageOpenIntent = intent
fileName = imageOpenIntent.getStringExtra("TOUCHED_FILE")
if (fileName != null && fileName!!.isNotEmpty()) {
activityImageViewerBinding!!.imageFileName.text = fileName
activityImageViewerBinding!!.imageFileName.visibility = View.VISIBLE
if (fileName != null && fileName?.isNotEmpty() == true) {
activityImageViewerBinding.imageFileName.text = fileName
activityImageViewerBinding.imageFileName.visibility = View.VISIBLE
}
if (fileName!!.matches(".*[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}.*".toRegex())) {
if (fileName?.matches(".*[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}.*".toRegex()) == true) {
displayCapturedImage()
} else {
try {
Expand All @@ -38,7 +38,7 @@ class ImageViewerActivity : AppCompatActivity() {
val basePath = getExternalFilesDir(null)
File(basePath, "ole/$fileName")
}
Glide.with(applicationContext).load(imageFile).into(activityImageViewerBinding!!.imageViewer)
Glide.with(applicationContext).load(imageFile).into(activityImageViewerBinding.imageViewer)
} catch (e: Exception) {
e.printStackTrace()
}
Expand All @@ -50,7 +50,7 @@ class ImageViewerActivity : AppCompatActivity() {
val matcher = fileName?.let { uuidPattern.matcher(it) }
if (matcher != null) {
if (matcher.find()) {
fileName = fileName!!.substring(matcher.group().length)
fileName = fileName?.substring(matcher.group().length)
}
}
val requestOptions = RequestOptions()
Expand All @@ -59,6 +59,6 @@ class ImageViewerActivity : AppCompatActivity() {
Glide.with(this)
.load(fileName)
.apply(requestOptions)
.into(activityImageViewerBinding!!.imageViewer)
.into(activityImageViewerBinding.imageViewer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ import java.io.FileReader
import java.io.IOException

class MarkdownViewerActivity : AppCompatActivity() {
private var activityMarkdownViewerBinding: ActivityMarkdownViewerBinding? = null
private lateinit var activityMarkdownViewerBinding: ActivityMarkdownViewerBinding
private var fileName: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityMarkdownViewerBinding = ActivityMarkdownViewerBinding.inflate(layoutInflater)
setContentView(activityMarkdownViewerBinding!!.root)
setContentView(activityMarkdownViewerBinding.root)
renderMarkdownFile()
}

private fun renderMarkdownFile() {
val markdownOpenIntent = intent
fileName = markdownOpenIntent.getStringExtra("TOUCHED_FILE")
if (!fileName.isNullOrEmpty()) {
activityMarkdownViewerBinding!!.markdownFileName.text = fileName
activityMarkdownViewerBinding!!.markdownFileName.visibility = View.VISIBLE
activityMarkdownViewerBinding.markdownFileName.text = fileName
activityMarkdownViewerBinding.markdownFileName.visibility = View.VISIBLE
}
try {
val basePath = getExternalFilesDir(null)
val markdownFile = File(basePath, "ole/$fileName")
if (markdownFile.exists()) {
val markdownContent = readMarkdownFile(markdownFile)
setMarkdownText(activityMarkdownViewerBinding!!.markdownView, markdownContent)
setMarkdownText(activityMarkdownViewerBinding.markdownView, markdownContent)
} else {
Toast.makeText(this, getString(R.string.unable_to_load) + fileName, Toast.LENGTH_LONG).show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.io.File

class PDFReaderActivity : AppCompatActivity(), OnPageChangeListener, OnLoadCompleteListener, OnPageErrorListener, AudioRecordListener {
private lateinit var activityPdfreaderBinding: ActivityPdfreaderBinding
private lateinit var fileName: String
private var fileName: String? = null
private lateinit var audioRecorderService: AudioRecorderService
private lateinit var library: RealmMyLibrary
private lateinit var mRealm: Realm
Expand Down Expand Up @@ -57,8 +57,8 @@ class PDFReaderActivity : AppCompatActivity(), OnPageChangeListener, OnLoadCompl

private fun renderPdfFile() {
val pdfOpenIntent = intent
fileName = pdfOpenIntent.getStringExtra("TOUCHED_FILE")!!
if (this::fileName.isInitialized && fileName.isNotEmpty()) {
fileName = pdfOpenIntent.getStringExtra("TOUCHED_FILE")
if (fileName != null && fileName?.isNotEmpty() == true) {
activityPdfreaderBinding.pdfFileName.text = fileName
activityPdfreaderBinding.pdfFileName.visibility = View.VISIBLE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import java.io.File
import java.io.FileReader

class TextFileViewerActivity : AppCompatActivity() {
private var activityTextfileViewerBinding: ActivityTextfileViewerBinding? = null
private lateinit var activityTextfileViewerBinding: ActivityTextfileViewerBinding
private var fileName: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityTextfileViewerBinding = ActivityTextfileViewerBinding.inflate(layoutInflater)
setContentView(activityTextfileViewerBinding!!.root)
setContentView(activityTextfileViewerBinding.root)
renderTextFile()
}

private fun renderTextFile() {
val textFileOpenIntent = intent
fileName = textFileOpenIntent.getStringExtra("TOUCHED_FILE")
if (fileName != null && fileName!!.isNotEmpty()) {
activityTextfileViewerBinding!!.textFileName.text = fileName
activityTextfileViewerBinding!!.textFileName.visibility = View.VISIBLE
if (fileName != null && fileName?.isNotEmpty() == true) {
activityTextfileViewerBinding.textFileName.text = fileName
activityTextfileViewerBinding.textFileName.visibility = View.VISIBLE
}
renderTextFileThread()
}
Expand All @@ -42,7 +42,7 @@ class TextFileViewerActivity : AppCompatActivity() {
text.append('\n')
}
reader.close()
activityTextfileViewerBinding!!.textFileContent.text = text.toString()
activityTextfileViewerBinding.textFileContent.text = text.toString()
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down

0 comments on commit 144bf68

Please sign in to comment.