Skip to content

Commit 21c1bf7

Browse files
committed
fix : amqp client crash and add : anti-screenshot support,
- amqp is fixed with some occasional caught errors whilst config changes - Screenshot is disabled for MainActivity - some code refactoring.
1 parent 35f5b95 commit 21c1bf7

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed

app/src/main/java/com/projectdelta/zoro/ZoroApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ZoroApplication : Application() ,Configuration.Provider {
2929

3030
if (BuildConfig.DEBUG) {
3131
Timber.plant(CustomDebugTree())
32-
// setupStrictMode()
32+
setupStrictMode()
3333
}
3434

3535
}

app/src/main/java/com/projectdelta/zoro/ui/base/BaseActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.projectdelta.zoro.ui.base
66

77
import android.os.Bundle
8+
import android.view.WindowManager
89
import androidx.appcompat.app.AppCompatActivity
910
import com.projectdelta.zoro.data.preferences.PreferencesManager
1011
import com.projectdelta.zoro.di.NetworkModule
@@ -49,4 +50,11 @@ abstract class BaseActivity : AppCompatActivity() {
4950
super.onDestroy()
5051
}
5152

53+
/**
54+
* Sets secure flag (mostly prevents screenshots)
55+
*/
56+
protected fun setSecureMode(){
57+
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
58+
}
59+
5260
}

app/src/main/java/com/projectdelta/zoro/ui/login/LoginActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import androidx.activity.viewModels
1111
import androidx.biometric.BiometricPrompt
1212
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
1313
import androidx.core.view.isVisible
14-
import androidx.work.OneTimeWorkRequestBuilder
1514
import androidx.work.WorkManager
1615
import com.projectdelta.zoro.R
1716
import com.projectdelta.zoro.data.preferences.UserPreferences
@@ -29,7 +28,6 @@ import com.projectdelta.zoro.util.system.lang.toEditable
2928
import com.projectdelta.zoro.util.work.UpdateDatabaseWorker
3029
import com.tapadoo.alerter.Alerter
3130
import dagger.hilt.android.AndroidEntryPoint
32-
import javax.inject.Inject
3331

3432
@AndroidEntryPoint
3533
class LoginActivity : BaseViewBindingActivity<ActivityLoginBinding>() {

app/src/main/java/com/projectdelta/zoro/ui/main/MainActivity.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ class MainActivity : BaseViewBindingActivity<ActivityMainBinding>() {
3434

3535
_binding = ActivityMainBinding.inflate(layoutInflater)
3636

37+
setSecureMode()
38+
3739
setContentView(binding.root)
3840

3941
registerObservers()
4042

4143
setupNavController()
4244

43-
initUI()
44-
4545
}
4646

4747
private fun registerObservers() {
@@ -50,23 +50,20 @@ class MainActivity : BaseViewBindingActivity<ActivityMainBinding>() {
5050

5151
connectivityManager.isNetworkAvailable.observe(this) { isOnline ->
5252
when (isOnline) {
53-
true -> {
54-
viewModel.registerClient(userPreferences?.userId!!)
55-
}
56-
false -> {
57-
viewModel.unregisterClient()
58-
}
53+
true -> viewModel.registerClient(userPreferences?.userId!!)
54+
false -> viewModel.unregisterClient()
5955
}
6056
}
6157

6258
collectLatestLifecycleFlow(viewModel.newMessage) {
63-
if (it != null)
59+
if (it != null) {
6460
Alerter.create(this@MainActivity)
6561
.setTitle("New Message from a friend.")// TODO( Fetch SenderName form server to display here )
6662
.setText(it.data!!)
6763
.setDuration(ALERT_NOTIFICATION_DURATION)
6864
.setBackgroundColorInt(getResourceColor(R.attr.colorAccent))
6965
.show()
66+
}
7067
}
7168

7269
collectLatestLifecycleFlow(viewModel.bottomNavVisibility) { integer ->
@@ -95,10 +92,6 @@ class MainActivity : BaseViewBindingActivity<ActivityMainBinding>() {
9592
}
9693
}
9794

98-
private fun initUI() {
99-
100-
}
101-
10295
fun launchWebView(url: String, title: String?) {
10396
WebViewActivity.newIntent(this, url, null, title).also {
10497
startActivity(it)

app/src/main/java/com/projectdelta/zoro/ui/main/home/HomeFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
2929
@AndroidEntryPoint
3030
class HomeFragment : BaseViewBindingFragment<FragmentHomeBinding>() {
3131

32+
companion object{
33+
private const val DEFAULT_QUERY_HINT = "Contact name..."
34+
}
35+
3236
private var adapter: HomeRecyclerViewAdapter? = null
3337

3438
private val viewModel: HomeViewModel by viewModels()
@@ -72,7 +76,7 @@ class HomeFragment : BaseViewBindingFragment<FragmentHomeBinding>() {
7276
private fun setSearchBar() {
7377
val searchView: SearchView? =
7478
binding.toolbar.menu.findItem(R.id.action_search).actionView as SearchView?
75-
searchView?.queryHint = "Contact name..."
79+
searchView?.queryHint = DEFAULT_QUERY_HINT
7680

7781
searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
7882
override fun onQueryTextSubmit(query: String?): Boolean {

app/src/main/java/com/projectdelta/zoro/ui/main/user/UserFragment.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class UserFragment : BaseViewBindingFragment<FragmentUserBinding>() {
7474
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
7575
super.onViewCreated(view, savedInstanceState)
7676

77-
registerObservers()
78-
7977
initUI()
8078

8179
}
@@ -100,8 +98,6 @@ class UserFragment : BaseViewBindingFragment<FragmentUserBinding>() {
10098

10199
}
102100

103-
private fun registerObservers() {}
104-
105101
private fun showQr() {
106102
qrViewBinding.imageQr.setImageBitmap(viewModel.qrBitmap)
107103
MaterialDialog(requireActivity()).show {

app/src/main/java/com/projectdelta/zoro/util/networking/amqp/RabbitMQClient.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import com.rabbitmq.client.AMQP
1313
import com.rabbitmq.client.Channel
1414
import com.rabbitmq.client.Connection
1515
import com.rabbitmq.client.ConnectionFactory
16-
import com.rabbitmq.client.DefaultConsumer
17-
import com.rabbitmq.client.Envelope
1816
import timber.log.Timber
1917
import java.io.IOException
2018
import java.util.concurrent.TimeoutException
@@ -44,7 +42,8 @@ class RabbitMQClient(
4442

4543
companion object {
4644

47-
private const val AUTO_ACKNOWLEDGMENT = true
45+
private const val AUTO_ACKNOWLEDGMENT = true // send read receipts to broker
46+
private const val PORT_FOR_SSL = 5671 // 5671 uses ssl and 5672 does not.
4847

4948
@Volatile
5049
private var INSTANCE: RabbitMQClient? = null
@@ -81,10 +80,11 @@ class RabbitMQClient(
8180
factory.username = uName
8281
factory.password = password
8382
factory.isAutomaticRecoveryEnabled = false
84-
if( port == 5671 )
83+
if( port == PORT_FOR_SSL )
8584
factory.useSslProtocol()
8685
}
8786

87+
@Deprecated("Use registerAndConsume instead")
8888
override fun registerChannel() {
8989
if (!connected) {
9090
connected = true
@@ -138,11 +138,6 @@ class RabbitMQClient(
138138
override fun unregisterChannel() {
139139
if (connected) {
140140
connected = false
141-
// try {
142-
// if (channel.isOpen) channel.close(AMQP.RESOURCE_ERROR, "channel force exit")
143-
// } catch (e: Exception) {
144-
// Timber.e(e)
145-
// }
146141
try {
147142
if (connection.isOpen) connection.close(AMQP.REPLY_SUCCESS, "connection force exit", 10)
148143
} catch (e: Exception) {

config/detekt/detekt.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ style:
2222
active: true
2323
maxLineLength: 145
2424
MagicNumber:
25+
active: false
2526
excludes: [ '**/test/**/*' ]
2627
NewLineAtEndOfFile:
2728
active: false
2829
naming:
2930
ConstructorParameterNaming:
3031
active: false
32+
VariableNaming:
33+
active: false
3134
performance:
3235
SpreadOperator:
33-
active: false
36+
active: false
37+
exceptions:
38+
TooGenericExceptionCaught:
39+
active: false

0 commit comments

Comments
 (0)