Bug Fixes

This commit is contained in:
Hardcore Sushi 2020-07-18 18:44:53 +02:00
parent bc00740f5b
commit bfe7e88578
10 changed files with 43 additions and 54 deletions

View File

@ -43,4 +43,5 @@ dependencies {
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.jaredrummler:cyanea:1.0.2'
implementation 'com.github.bumptech.glide:glide:4.11.0'
}

View File

@ -1,9 +0,0 @@
package sushi.hardcore.droidfs
import android.widget.ImageView
class ColorEngine(val themeColor: Int) {
fun applyTo(imageView: ImageView){
imageView.setColorFilter(themeColor)
}
}

View File

@ -3,6 +3,7 @@ package sushi.hardcore.droidfs
import android.content.SharedPreferences
import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import com.jaredrummler.cyanea.app.CyaneaAppCompatActivity
@ -13,12 +14,9 @@ open class ColoredActivity: CyaneaAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this)
if (!sharedPrefs.getBoolean("usf_screenshot", false)){
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
}
val themeColor = ThemeColor.getThemeColor(this)
val backgroundColor = ContextCompat.getColor(this, R.color.backgroundColor)
if (cyanea.accent != themeColor){
val backgroundColor = ContextCompat.getColor(this, R.color.backgroundColor)
cyanea.edit{
accent(themeColor)
//accentDark(themeColor)

View File

@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.AdapterView.OnItemClickListener
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_change_password.*
@ -39,6 +40,9 @@ class OpenActivity : ColoredActivity() {
private var usf_fingerprint = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!sharedPrefs.getBoolean("usf_screenshot", false)){
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
}
setContentView(R.layout.activity_open)
setSupportActionBar(toolbar)
//val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this)

View File

@ -189,7 +189,7 @@ class ExplorerActivity : ExplorerActivityRO() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.explorer, menu)
handle_menu_items(menu)
handleMenuItems(menu)
if (usf_share){
menu.findItem(R.id.explorer_menu_share).isVisible = false
}

View File

@ -15,7 +15,7 @@ class ExplorerActivityDrop : ExplorerActivityRO() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.explorer_drop, menu)
handle_menu_items(menu)
handleMenuItems(menu)
menu.findItem(R.id.explorer_menu_validate).isVisible = explorer_adapter.selectedItems.isEmpty()
return true
}

View File

@ -41,7 +41,7 @@ class ExplorerActivityPick : ExplorerActivityRO() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.explorer_pick, menu)
handle_menu_items(menu)
handleMenuItems(menu)
val any_item_selected = explorer_adapter.selectedItems.isNotEmpty()
menu.findItem(R.id.explorer_menu_select_all).isVisible = any_item_selected
menu.findItem(R.id.explorer_menu_validate).isVisible = any_item_selected

View File

@ -54,7 +54,7 @@ open class ExplorerActivityRO : ColoredActivity() {
}
usf_open = sharedPrefs.getBoolean("usf_open", false)
val intent = intent
volume_name = intent.getStringExtra("volume_name")
volume_name = intent.getStringExtra("volume_name") ?: ""
val sessionID = intent.getIntExtra("sessionID", -1)
gocryptfsVolume = GocryptfsVolume(sessionID)
sort_modes_entries = resources.getStringArray(R.array.sort_orders_entries)
@ -143,7 +143,7 @@ open class ExplorerActivityRO : ColoredActivity() {
invalidateOptionsMenu()
}
private fun sort_explorer_elements() {
private fun sortExplorerElements() {
when (sort_modes_values[current_sort_mode_index]) {
"name" -> {
explorer_elements.sortWith(Comparator { o1, o2 -> o1.name.compareTo(o2.name) })
@ -171,7 +171,7 @@ open class ExplorerActivityRO : ColoredActivity() {
protected fun setCurrentPath(path: String) {
explorer_elements = gocryptfsVolume.list_dir(path)
text_dir_empty.visibility = if (explorer_elements.size == 0) View.VISIBLE else View.INVISIBLE
sort_explorer_elements()
sortExplorerElements()
if (path.isNotEmpty()) { //not root
explorer_elements.add(0, ExplorerElement("..", (-1).toShort(), -1, -1))
}
@ -213,7 +213,7 @@ open class ExplorerActivityRO : ColoredActivity() {
}
}
fun createFolder(folder_name: String){
private fun createFolder(folder_name: String){
if (folder_name.isEmpty()) {
Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show()
} else {
@ -270,7 +270,7 @@ open class ExplorerActivityRO : ColoredActivity() {
}
}
fun handle_menu_items(menu: Menu){
fun handleMenuItems(menu: Menu){
menu.findItem(R.id.explorer_menu_rename).isVisible = false
if (usf_open){
menu.findItem(R.id.explorer_menu_external_open)?.isVisible = false

View File

@ -15,7 +15,7 @@ import java.io.File
import java.util.ArrayList
abstract class FileViewerActivity: ColoredActivity() {
var cachedFiles: MutableList<Uri> = ArrayList()
private var cachedFiles: MutableList<Uri> = ArrayList()
lateinit var gocryptfsVolume: GocryptfsVolume
lateinit var filePath: String
override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -1,64 +1,59 @@
package sushi.hardcore.droidfs.file_viewers
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
import android.graphics.drawable.Drawable
import android.os.Handler
import android.util.DisplayMetrics
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import kotlinx.android.synthetic.main.activity_image_viewer.*
import sushi.hardcore.droidfs.R
import java.security.MessageDigest
class ImageViewer: FileViewerActivity() {
companion object {
private const val hideDelay: Long = 3000
}
private lateinit var bmpImage: Bitmap
private lateinit var glideImage: RequestBuilder<Drawable>
private var rotationAngle: Float = 0F
private val handler = Handler()
private val hideActionButtons = Runnable { action_buttons.visibility = View.GONE }
override fun viewFile() {
loadWholeFile(filePath)?.let {
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getRealMetrics(metrics)
bmpImage = decodeSampledBitmapFromBuffer(it, metrics.widthPixels, metrics.heightPixels)
val imageBuff = loadWholeFile(filePath)
if (imageBuff != null){
setContentView(R.layout.activity_image_viewer)
image_viewer.setImageBitmap(bmpImage)
glideImage = Glide.with(this).load(imageBuff)
glideImage.into(image_viewer)
handler.postDelayed(hideActionButtons, hideDelay)
}
}
private fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int {
var inSampleSize = 1
if (options.outHeight > reqHeight || options.outWidth > reqWidth){
val halfHeight = options.outHeight/2
val halfWidth = options.outWidth/2
while (halfHeight/inSampleSize >= reqHeight && halfWidth/inSampleSize >= reqWidth){
inSampleSize *= 2
class RotateTransformation(private val rotationAngle: Float): BitmapTransformation() {
override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap {
val matrix = Matrix()
matrix.postRotate(rotationAngle)
return Bitmap.createBitmap(toTransform, 0, 0, toTransform.width, toTransform.height, matrix, true)
}
}
return inSampleSize
}
private fun decodeSampledBitmapFromBuffer(buff: ByteArray, reqWidth: Int, reqHeight: Int): Bitmap {
return BitmapFactory.Options().run {
inJustDecodeBounds = true
BitmapFactory.decodeByteArray(buff, 0, buff.size, this)
inSampleSize = calculateInSampleSize(this, reqWidth, reqHeight)
inJustDecodeBounds = false
BitmapFactory.decodeByteArray(buff, 0, buff.size, this)
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
messageDigest.update("rotate$rotationAngle".toByteArray())
}
}
private fun rotateImage(degrees: Float){
val matrix = Matrix()
matrix.postRotate(degrees)
bmpImage = Bitmap.createBitmap(bmpImage, 0, 0, bmpImage.width, bmpImage.height, matrix, true)
image_viewer.setImageBitmap(bmpImage)
private fun rotateImage(){
glideImage.transform(RotateTransformation(rotationAngle)).into(image_viewer)
}
fun onCLickRotateRight(view: View){
rotateImage(90F)
rotationAngle += 90
rotateImage()
}
fun onClickRotateLeft(view: View){
rotateImage(-90F)
rotationAngle -= 90
rotateImage()
}
override fun onUserInteraction() {