Skip to content

Commit 2a81d80

Browse files
authored
Merge pull request #75 from aashishksahu/weird-camera-bug
Weird camera bug
2 parents e707d90 + efd00af commit 2a81d80

22 files changed

Lines changed: 310 additions & 278 deletions

.idea/deploymentTargetSelector.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616

1717
minSdk 29
1818
targetSdk 34
19-
versionCode 33
20-
versionName "2.0.2"
19+
versionCode 34
20+
versionName "2.0.3"
2121

2222
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2323
vectorDrawables {

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
android:theme="@style/Theme.SafeSpace" />
3838
<activity
3939
android:name=".media.MediaActivity"
40+
android:configChanges="keyboardHidden|orientation|screenSize"
4041
android:exported="false" />
4142
<activity
4243
android:name=".camera.CameraActivity"

app/src/main/java/org/privacymatters/safespace/AuthActivity.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.privacymatters.safespace
22

3+
import android.annotation.SuppressLint
34
import android.content.Context
45
import android.content.Intent
56
import android.content.SharedPreferences
67
import android.os.Bundle
78
import android.os.CountDownTimer
89
import android.view.KeyEvent
10+
import android.widget.Button
911
import android.widget.EditText
1012
import android.widget.ImageButton
1113
import android.widget.TextView
@@ -48,6 +50,7 @@ class AuthActivity : AppCompatActivity() {
4850
private var attemptCount = 0
4951
private lateinit var loginBlockMsg: TextView
5052
private lateinit var loginBlockTimer: TextView
53+
private lateinit var okBtn: Button
5154
private var loginBlockedTime: Long = Constants.DEF_NUM_FLAG
5255

5356

@@ -72,7 +75,6 @@ class AuthActivity : AppCompatActivity() {
7275
super.onCreate(savedInstanceState)
7376
setContentView(R.layout.activity_auth)
7477

75-
7678
authTouch = findViewById(R.id.fingerprint)
7779
pinField = findViewById(R.id.editTextPassword)
7880

@@ -81,6 +83,8 @@ class AuthActivity : AppCompatActivity() {
8183
loginBlockedTime =
8284
sharedPref.getLong(Constants.TIME_TO_UNLOCK_START, Constants.DEF_NUM_FLAG)
8385

86+
okBtn = findViewById(R.id.okBtn)
87+
8488
// check if user is blocked from login
8589
val isLoginUnlocked = checkLoginUnlocked() // returns a pair(is blocked?, for how long)
8690

@@ -122,6 +126,15 @@ class AuthActivity : AppCompatActivity() {
122126
}
123127

124128
}
129+
130+
okBtn.setOnClickListener {
131+
if (!isHardPinSet) {
132+
setUpHardPin()
133+
} else {
134+
authenticateUsingHardPin()
135+
}
136+
}
137+
125138
}
126139

127140
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
@@ -141,6 +154,7 @@ class AuthActivity : AppCompatActivity() {
141154
}
142155
}
143156

157+
@SuppressLint("SetTextI18n")
144158
private fun authenticateUsingHardPin() {
145159
if (pinField.text.toString() == EncPref.getString(
146160
Constants.HARD_PIN,
@@ -220,6 +234,7 @@ class AuthActivity : AppCompatActivity() {
220234

221235
private fun blockLogin(blockDuration: Long) {
222236
setLoginBlockMsg()
237+
okBtn.isEnabled = false
223238

224239
biometricPossible = false
225240

@@ -228,6 +243,7 @@ class AuthActivity : AppCompatActivity() {
228243

229244
private fun unlockLogin() {
230245
removeLoginBlockMsg()
246+
okBtn.isEnabled = true
231247
sharedPref.edit()
232248
.putLong(Constants.TIME_TO_UNLOCK_DURATION, Constants.DEF_NUM_FLAG)
233249
.putLong(Constants.TIME_TO_UNLOCK_START, Constants.DEF_NUM_FLAG)
@@ -270,6 +286,7 @@ class AuthActivity : AppCompatActivity() {
270286
loginBlockTimer.text = remainingTime
271287
}
272288

289+
@SuppressLint("SetTextI18n")
273290
override fun onFinish() {
274291
unlockLogin()
275292
loginBlockTimer.text = ""
@@ -284,12 +301,14 @@ class AuthActivity : AppCompatActivity() {
284301
authTouch.isEnabled = false
285302
}
286303

304+
@SuppressLint("SetTextI18n")
287305
private fun removeLoginBlockMsg() {
288306
loginBlockMsg.text = ""
289307
pinField.isEnabled = true
290308
authTouch.isEnabled = true
291309
}
292310

311+
@SuppressLint("SetTextI18n")
293312
private fun setUpHardPin() {
294313

295314
pinField.hint = getString(R.string.set_pin_text)

app/src/main/java/org/privacymatters/safespace/LogActivity.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.PaddingValues
88
import androidx.compose.foundation.layout.fillMaxSize
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.rememberScrollState
11+
import androidx.compose.foundation.text.selection.SelectionContainer
1112
import androidx.compose.foundation.verticalScroll
1213
import androidx.compose.material3.Icon
1314
import androidx.compose.material3.IconButton
@@ -70,21 +71,23 @@ class LogActivity : ComponentActivity() {
7071
)
7172
}
7273
}) { innerPadding ->
73-
Text(
74-
text = content.toString(),
75-
modifier = Modifier
76-
.padding(
77-
PaddingValues(
78-
top = innerPadding.calculateTopPadding(),
79-
bottom = innerPadding.calculateBottomPadding(),
80-
start = 5.dp,
81-
end = 5.dp
74+
SelectionContainer {
75+
Text(
76+
text = content.toString(),
77+
modifier = Modifier
78+
.padding(
79+
PaddingValues(
80+
top = innerPadding.calculateTopPadding(),
81+
bottom = innerPadding.calculateBottomPadding(),
82+
start = 5.dp,
83+
end = 5.dp
84+
)
8285
)
83-
)
84-
.fillMaxSize()
85-
.verticalScroll(rememberScrollState())
86-
.horizontalScroll(rememberScrollState())
87-
)
86+
.fillMaxSize()
87+
.verticalScroll(rememberScrollState())
88+
.horizontalScroll(rememberScrollState())
89+
)
90+
}
8891
}
8992
}
9093
}

app/src/main/java/org/privacymatters/safespace/experimental/main/DataManager.kt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ object DataManager {
4141
var internalPath: ArrayList<String> = arrayListOf(Constants.ROOT)
4242
private lateinit var application: Application
4343

44-
// val itemStateList = mutableStateListOf<Item>()
45-
4644
private val privateItemList = MutableStateFlow<List<Item>>(emptyList())
4745
val itemListFlow = privateItemList.asStateFlow()
4846

@@ -339,7 +337,11 @@ object DataManager {
339337
)
340338

341339
} catch (exception: Exception) {
342-
Utils.exportToLog(application, "@ DataManager.copyFileWithProgressNotification() ", exception)
340+
Utils.exportToLog(
341+
application,
342+
"@ DataManager.copyFileWithProgressNotification() ",
343+
exception
344+
)
343345
exception.printStackTrace()
344346
fileTransferNotification.showFailureNotification(sourceFileName, exception)
345347
}
@@ -580,6 +582,31 @@ object DataManager {
580582
return FileOpCode.SUCCESS
581583
}
582584

585+
fun renameFile(item: Item, newName: String): Boolean {
586+
587+
try {
588+
val absolutePath = joinPath(getInternalPath(), File.separator)
589+
590+
val absoluteFilePathOld = File(absolutePath + item.name)
591+
592+
val newNameWithExt = if (item.isDir) {
593+
newName
594+
} else {
595+
"$newName.${item.name.substringAfterLast('.')}"
596+
}
597+
598+
val absoluteFilePathNew = File(absolutePath + newNameWithExt)
599+
600+
absoluteFilePathOld.renameTo(absoluteFilePathNew)
601+
602+
} catch (e: Exception) {
603+
Utils.exportToLog(application, "@DataManager.renameFile()", e)
604+
return false
605+
}
606+
607+
return true
608+
}
609+
583610
/*
584611
private fun getThumbsDir(): String {
585612
// thumbnails folder

app/src/main/java/org/privacymatters/safespace/experimental/main/MainActivityViewModel.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class MainActivityViewModel(private val application: Application) : AndroidViewM
138138
}
139139
}
140140
} catch (e: Exception) {
141-
Utils.exportToLog(application,"@DataManager.moveToDestination()", e)
141+
Utils.exportToLog(application, "@DataManager.moveToDestination()", e)
142142
status = FileOpCode.FAIL
143143
} finally {
144144
getItems()
@@ -196,7 +196,7 @@ class MainActivityViewModel(private val application: Application) : AndroidViewM
196196
sourceFileStream?.close()
197197
targetFileStream?.close()
198198
} catch (e: Exception) {
199-
Utils.exportToLog(application,"@DataManager.copyToDestination()", e)
199+
Utils.exportToLog(application, "@DataManager.copyToDestination()", e)
200200
status = FileOpCode.FAIL
201201
} finally {
202202
transferList.clear()
@@ -340,17 +340,15 @@ class MainActivityViewModel(private val application: Application) : AndroidViewM
340340
transferList.removeIf { it.id == item?.id }
341341

342342
if (ops.itemListFlow.value.all { !it.isSelected }) {
343-
appBarType.value = ActionBarType.NORMAL
344-
selectedFileCount.intValue = 0
345-
selectedFolderCount.intValue = 0
343+
clearSelection()
346344
}
347345
}
348346

349347

350348
fun clearSelection() {
351349
selectedFileCount.intValue = 0
352350
selectedFolderCount.intValue = 0
353-
351+
appBarType.value = ActionBarType.NORMAL
354352
transferList.clear()
355353

356354
ops.clearSelection()
@@ -387,6 +385,18 @@ class MainActivityViewModel(private val application: Application) : AndroidViewM
387385
}
388386

389387
fun exportToLog(msg: String, e: Exception) {
390-
Utils.exportToLog(application,msg, e)
388+
Utils.exportToLog(application, msg, e)
389+
}
390+
391+
fun renameFile(newName: String): Boolean {
392+
393+
val item = ops.itemListFlow.value.find { it.isSelected }
394+
395+
if (item != null && ops.renameFile(item, newName)) {
396+
clearSelection()
397+
getItems()
398+
return true
399+
}
400+
return false
391401
}
392402
}

0 commit comments

Comments
 (0)