diff --git a/app/build.gradle b/app/build.gradle index e2ec866261..4a81a6e981 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.kt index e3b5791f5e..c8c4719ac8 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.kt @@ -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 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() @@ -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() } @@ -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(R.id.btnNext).visibility = View.GONE rootView.findViewById(R.id.btnPrev).visibility = View.GONE rootView.findViewById(R.id.btnRepeatOne).visibility = View.GONE @@ -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]) } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.kt index 51a3054dc8..fffc1b5368 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.kt @@ -8,14 +8,13 @@ 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() } @@ -23,8 +22,8 @@ class CSVViewerActivity : AppCompatActivity() { 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("/")) { @@ -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() diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.kt index 0b1fbeecec..65f32c9577 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.kt @@ -11,12 +11,12 @@ 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() } @@ -24,11 +24,11 @@ class ImageViewerActivity : AppCompatActivity() { 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 { @@ -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() } @@ -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() @@ -59,6 +59,6 @@ class ImageViewerActivity : AppCompatActivity() { Glide.with(this) .load(fileName) .apply(requestOptions) - .into(activityImageViewerBinding!!.imageViewer) + .into(activityImageViewerBinding.imageViewer) } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.kt index 477373b233..04c540dc4a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.kt @@ -13,12 +13,12 @@ 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() } @@ -26,15 +26,15 @@ class MarkdownViewerActivity : AppCompatActivity() { 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() } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.kt index aca79acde1..4cd7282bc0 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.kt @@ -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 @@ -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 } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.kt index e04d00f1a1..c6d73e56da 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.kt @@ -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() } @@ -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() }