Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kammerer committed May 30, 2024
1 parent 26f728c commit 7dffc14
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.drawable.DrawableCompat
import androidx.navigation.NavController
import androidx.navigation.navOptions
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import com.google.android.material.color.MaterialColors
import universe.constellation.orion.viewer.device.AndroidDevice
Expand All @@ -63,6 +61,8 @@ abstract class OrionBaseActivity(createDevice: Boolean = true, val viewerType: I

val analytics by lazy { orionContext.analytics }

val globalOptions by lazy { orionContext.options }

@SuppressLint("MissingSuperCall")
override fun onCreate(savedInstanceState: Bundle?) {
onOrionCreate(savedInstanceState, -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT
var controller: Controller? = null
private set

val globalOptions: GlobalOptions by lazy {
orionContext.options
}

private var myState: MyState = MyState.PROCESSING_INTENT

@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.SharedPreferences
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.preference.PreferenceManager
import android.view.Menu
import android.view.MenuItem
import android.view.SubMenu
Expand All @@ -28,7 +27,6 @@ import universe.constellation.orion.viewer.R
import universe.constellation.orion.viewer.android.isAtLeastKitkat
import universe.constellation.orion.viewer.getVectorDrawable
import universe.constellation.orion.viewer.log
import universe.constellation.orion.viewer.prefs.GlobalOptions
import java.io.File
import java.io.FilenameFilter

Expand All @@ -49,10 +47,6 @@ abstract class OrionFileManagerActivityBase @JvmOverloads constructor(
var prefs: SharedPreferences? = null
private set

lateinit var globalOptions: GlobalOptions

private var justCreated: Boolean = false

val selectDocumentInSystem = if (isAtLeastKitkat()) registerForActivityResult(
ActivityResultContracts.OpenDocument()
) { result ->
Expand All @@ -67,16 +61,13 @@ abstract class OrionFileManagerActivityBase @JvmOverloads constructor(
onOrionCreate(savedInstanceState, R.layout.file_manager, true)
log("Creating file manager")

prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
globalOptions = orionContext.options
prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(applicationContext)

initFileManager()

justCreated = true

initDrawer()

showPermissionRequestDialog()

onNewIntent(intent)
}

private fun initDrawer() {
Expand All @@ -99,7 +90,7 @@ abstract class OrionFileManagerActivityBase @JvmOverloads constructor(
for (storage in this.describeStorages()) {
val folder = storage.file
val subMenu = locations.subMenu!!//.addSubMenu(storage.description)
val parentItem = addFodlerItem(
addFodlerItem(
subMenu,
storage.description,
viewPager,
Expand Down Expand Up @@ -162,6 +153,7 @@ abstract class OrionFileManagerActivityBase @JvmOverloads constructor(
}
}

@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
log("FileManager: On activity result requestCode=$requestCode resultCode=$resultCode")
Expand Down Expand Up @@ -197,26 +189,13 @@ abstract class OrionFileManagerActivityBase @JvmOverloads constructor(
checkAndRequestStorageAccessPermissionOrReadOne(Permissions.ASK_READ_PERMISSION_FOR_FILE_MANAGER)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
justCreated = false
}

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (drawerLayout.isDrawerOpen(findViewById(R.id.nav_view))) {
drawerLayout.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}

}

override fun onResume() {
super.onResume()
if (justCreated) {
justCreated = false
onNewIntent(intent)
}
}

fun openFile(uri: Uri, isFromSystemFM: Boolean = false) {
Expand Down Expand Up @@ -249,7 +228,6 @@ abstract class OrionFileManagerActivityBase @JvmOverloads constructor(

val folderTab = tabLayout.getTabAt(0)
folderTab?.setIcon(getVectorDrawable(R.drawable.new_folder))
folderTab?.setContentDescription(R.string.file_manager_title)

if (showRecentsAndSavePath) {
val recentTab = tabLayout.getTabAt(1)
Expand Down
3 changes: 3 additions & 0 deletions orion-viewer/src/main/res/values-ru/file_manager.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="file_manager_title">Менеджер файлов</string>
<string name="file_manager_fodlers">Папки</string>
<string name="file_manager_history">История</string>

<string name="file_manager_select_tip">Выберите файл для открытия в Orion Viewer</string>
<string name="file_manager_path">Путь:</string>
<string name="file_manager_documents">Документы</string>
Expand Down
3 changes: 3 additions & 0 deletions orion-viewer/src/main/res/values/file_manager.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="file_manager_title">File Manager</string>
<string name="file_manager_fodlers">Folders</string>
<string name="file_manager_history">History</string>

<string name="file_manager_select_tip">Please select a file to open in Orion Viewer</string>
<string name="file_manager_path">Path:</string>
<string name="file_manager_documents">Documents</string>
Expand Down

0 comments on commit 7dffc14

Please sign in to comment.