Upgradting leak canary

This commit is contained in:
MohitMaliFtechiz 2022-07-13 14:09:32 +05:30 committed by Kelson
parent 859bc35eaf
commit c844eb102d
5 changed files with 57 additions and 3 deletions

View File

@ -35,6 +35,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
@ -62,7 +63,6 @@ import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.ACTION_CHECK_IP_ADDRESS
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.ACTION_START_SERVER
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.ACTION_STOP_SERVER
import java.util.ArrayList
import javax.inject.Inject
class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
@ -140,6 +140,11 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
}
startServerButton.setOnClickListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ||
checkNearbyWifiDevicesPermission()
) {
startStopServer()
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P || checkCoarseLocationAccessPermission()) {
startStopServer()
}
@ -169,6 +174,33 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
true
}
private fun checkNearbyWifiDevicesPermission(): Boolean =
if (ContextCompat.checkSelfPermission(
requireActivity(),
Manifest.permission.NEARBY_WIFI_DEVICES
) == PackageManager.PERMISSION_DENIED
) {
if (ActivityCompat.shouldShowRequestPermissionRationale(
requireActivity(),
Manifest.permission.NEARBY_WIFI_DEVICES
)
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
alertDialogShower.show(
KiwixDialog.NearbyWifiPermissionRationaleOnHostZimFile,
::askNearbyWifiDevicesPermission
)
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
askNearbyWifiDevicesPermission()
}
}
false
} else {
true
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
@ -189,6 +221,14 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
)
}
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private fun askNearbyWifiDevicesPermission() {
ActivityCompat.requestPermissions(
requireActivity(), arrayOf(Manifest.permission.NEARBY_WIFI_DEVICES),
PERMISSION_REQUEST_CODE_COARSE_LOCATION
)
}
private fun startStopServer() {
when {
ServerUtils.isServerStarted -> stopServer()

View File

@ -52,7 +52,7 @@ object Versions {
const val javax_annotation_api: String = "1.3.2"
const val leakcanary_android: String = "2.5"
const val leakcanary_android: String = "2.9.1"
const val constraintlayout: String = "2.0.4"

View File

@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.core.downloader.fetch
import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent.FLAG_IMMUTABLE
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.app.PendingIntent.getActivity
import android.content.Context
@ -119,7 +120,12 @@ class FetchDownloadNotificationManager(context: Context) :
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(DOWNLOAD_NOTIFICATION_TITLE, downloadNotification.title)
}
notificationBuilder.setContentIntent(getActivity(context, 0, internal, FLAG_UPDATE_CURRENT))
val pendingIntent = if (Build.VERSION.SDK_INT >= VERSION_CODES.S) {
getActivity(context, 0, internal, FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT)
} else {
getActivity(context, 0, internal, FLAG_UPDATE_CURRENT)
}
notificationBuilder.setContentIntent(pendingIntent)
notificationBuilder.setAutoCancel(true)
}
}

View File

@ -56,6 +56,13 @@ sealed class KiwixDialog(
android.R.string.cancel
)
object NearbyWifiPermissionRationaleOnHostZimFile : KiwixDialog(
null,
R.string.permission_rationale_location_on_host_zim_file,
android.R.string.yes,
android.R.string.cancel
)
object StoragePermissionRationale : KiwixDialog(
null,
R.string.request_storage,

View File

@ -236,6 +236,7 @@
<string name="connection_failed" tools:keep="@string/connection_failed">Connection failed</string>
<string name="permission_rationale_location">Location permission is required by Android to allow the app to detect peer devices</string>
<string name="permission_rationale_location_on_host_zim_file">Location permission is required by Android to allow the app to Host Zim files</string>
<string name="permission_rationale_nearby_device_on_host_zim_file">Nearby wifi devices permission is required by Android to allow the app to Host Zim files</string>
<string name="permission_refused_location" tools:keep="@string/permission_refused_location">Cannot locate peer devices without location permissions</string>
<string name="permission_refused_storage" tools:keep="@string/permission_refused_storage">Cannot access zim files without storage permission</string>
<string name="request_enable_location">Enable location to allow detection of peers</string>