|
|
@ -1,9 +1,12 @@ |
|
|
|
package com.nivesh.production.niveshfd.util |
|
|
|
|
|
|
|
import android.Manifest |
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.app.Activity |
|
|
|
import android.app.AlertDialog |
|
|
|
import android.content.Context |
|
|
|
import android.content.Intent |
|
|
|
import android.content.pm.PackageManager |
|
|
|
import android.graphics.Color |
|
|
|
import android.graphics.drawable.GradientDrawable |
|
|
|
import android.net.ConnectivityManager |
|
|
@ -11,14 +14,18 @@ import android.net.NetworkCapabilities |
|
|
|
import android.net.Uri |
|
|
|
import android.os.Build |
|
|
|
import android.provider.Settings |
|
|
|
import android.telephony.TelephonyManager |
|
|
|
import android.text.TextUtils |
|
|
|
import android.text.format.DateFormat |
|
|
|
import android.util.Log |
|
|
|
import android.util.Patterns |
|
|
|
import androidx.core.app.ActivityCompat |
|
|
|
import com.google.android.material.textfield.MaterialAutoCompleteTextView |
|
|
|
import com.google.android.material.textfield.TextInputEditText |
|
|
|
import com.google.android.material.textfield.TextInputLayout |
|
|
|
import com.google.gson.JsonObject |
|
|
|
import com.nivesh.production.niveshfd.R |
|
|
|
import com.nivesh.production.niveshfd.model.DeviceInfo |
|
|
|
import com.nivesh.production.niveshfd.ui.activity.NiveshFdMainActivity |
|
|
|
import kotlinx.coroutines.CoroutineExceptionHandler |
|
|
|
import org.json.JSONObject |
|
|
@ -90,6 +97,12 @@ class Common { |
|
|
|
return mMatcher.matches() |
|
|
|
} |
|
|
|
|
|
|
|
fun isValidIndividualPan(pan: String?): Boolean { |
|
|
|
val mPattern = Pattern.compile("[A-Z]{3}[P][A-Z][0-9]{4}[A-Z]") |
|
|
|
val mMatcher = mPattern.matcher(pan.toString()) |
|
|
|
return mMatcher.matches() |
|
|
|
} |
|
|
|
|
|
|
|
//is Indian mobile Number |
|
|
|
fun isIndianMobileNo(mobileNumber: String?): Boolean { |
|
|
|
//(0/91): number starts with (0/91) |
|
|
@ -131,7 +144,11 @@ class Common { |
|
|
|
builder.setPositiveButton(activity.getString(R.string.Ok)) { dialogInterface, _ -> |
|
|
|
val intent = Intent( |
|
|
|
Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
|
|
|
Uri.fromParts("package", (activity as NiveshFdMainActivity).packageName, null) |
|
|
|
Uri.fromParts( |
|
|
|
"package", |
|
|
|
(activity as NiveshFdMainActivity).packageName, |
|
|
|
null |
|
|
|
) |
|
|
|
) |
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
|
|
activity.startActivity(intent) |
|
|
@ -208,20 +225,20 @@ class Common { |
|
|
|
return Resource.Error(response.message()) |
|
|
|
} |
|
|
|
|
|
|
|
fun handleResponse1(response: Response<String>): Resource<String> { |
|
|
|
if (response.isSuccessful && response.body() != null) { |
|
|
|
return if (response.body().toString().isNotEmpty()) { |
|
|
|
Log.e("response", "-->$response") |
|
|
|
val str: String = response.body().toString().replace("\r\n", "") |
|
|
|
Log.e("str", "-->$str") |
|
|
|
val jsonObject = JSONObject(str) |
|
|
|
Log.e("jsonObject", "-->$jsonObject") |
|
|
|
Resource.Success(jsonObject.toString()) |
|
|
|
}else { |
|
|
|
Resource.Error(response.message()) |
|
|
|
} |
|
|
|
} |
|
|
|
return Resource.Error(response.message()) |
|
|
|
fun handleResponse1(response: Response<String>): Resource<String> { |
|
|
|
if (response.isSuccessful && response.body() != null) { |
|
|
|
return if (response.body().toString().isNotEmpty()) { |
|
|
|
Log.e("response", "-->$response") |
|
|
|
val str: String = response.body().toString().replace("\r\n", "") |
|
|
|
Log.e("str", "-->$str") |
|
|
|
val jsonObject = JSONObject(str) |
|
|
|
Log.e("jsonObject", "-->$jsonObject") |
|
|
|
Resource.Success(jsonObject.toString()) |
|
|
|
} else { |
|
|
|
Resource.Error(response.message()) |
|
|
|
} |
|
|
|
} |
|
|
|
return Resource.Error(response.message()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -255,12 +272,11 @@ class Common { |
|
|
|
} |
|
|
|
|
|
|
|
/* this function is used for file size in readable format(End)*/ |
|
|
|
fun getFileSizeInMB(length: Long): Double { |
|
|
|
// Get length of file in bytes |
|
|
|
val fileSizeInBytes = length.toDouble() |
|
|
|
// Convert the bytes to Kilobytes (1 KB = 1024 Bytes) |
|
|
|
val fileSizeInKB = fileSizeInBytes / 1024 |
|
|
|
// Convert the KB to MegaBytes (1 MB = 1024 KBytes) |
|
|
|
fun getFileSizeInMB(length: Long): Double { // Get length of file in bytes |
|
|
|
val fileSizeInBytes = |
|
|
|
length.toDouble() // Convert the bytes to Kilobytes (1 KB = 1024 Bytes) |
|
|
|
val fileSizeInKB = |
|
|
|
fileSizeInBytes / 1024 // Convert the KB to MegaBytes (1 MB = 1024 KBytes) |
|
|
|
return fileSizeInKB / 1024 |
|
|
|
} |
|
|
|
|
|
|
@ -274,6 +290,87 @@ class Common { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("HardwareIds") |
|
|
|
fun getDeviceInfo(mContext: Context): DeviceInfo { |
|
|
|
val deviceInfo = DeviceInfo() |
|
|
|
var deviceId: String? = "" |
|
|
|
try { |
|
|
|
val telephonyManager = |
|
|
|
mContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager |
|
|
|
deviceInfo.device_model = if (TextUtils.isEmpty(Build.DEVICE)) "" else Build.DEVICE |
|
|
|
deviceInfo.device_os_version = |
|
|
|
if (TextUtils.isEmpty(Build.VERSION.RELEASE)) "" else Build.VERSION.RELEASE |
|
|
|
deviceInfo.device_name = if (TextUtils.isEmpty(Build.PRODUCT)) "" else Build.PRODUCT |
|
|
|
deviceInfo.device_type = "Android" |
|
|
|
|
|
|
|
if ((deviceId == null) || deviceId.isEmpty() || deviceId.equals( |
|
|
|
"unknown", |
|
|
|
ignoreCase = true |
|
|
|
) |
|
|
|
) { |
|
|
|
deviceId = if (TextUtils.isEmpty( |
|
|
|
Settings.Secure.getString( |
|
|
|
mContext.contentResolver, |
|
|
|
Settings.Secure.ANDROID_ID |
|
|
|
) |
|
|
|
) |
|
|
|
) "" else Settings.Secure.getString( |
|
|
|
mContext.contentResolver, |
|
|
|
Settings.Secure.ANDROID_ID |
|
|
|
) |
|
|
|
} |
|
|
|
// deviceInfo.device_id = device_id + "#" + preferenceHelper.getAppName() |
|
|
|
deviceInfo.device_id_for_UMSId = deviceId |
|
|
|
// deviceInfo.sdk_version = com.nivesh.production.BuildConfig.VERSION_NAME |
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission( |
|
|
|
mContext, |
|
|
|
Manifest.permission.READ_PHONE_STATE |
|
|
|
) != PackageManager.PERMISSION_GRANTED |
|
|
|
) { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
|
|
deviceId = telephonyManager.imei |
|
|
|
if (deviceId == null) { |
|
|
|
deviceId = |
|
|
|
if (TextUtils.isEmpty(Build.getSerial())) "" else Build.getSerial() |
|
|
|
} |
|
|
|
} else { |
|
|
|
deviceId = telephonyManager.deviceId |
|
|
|
if (deviceId == null) { |
|
|
|
deviceId = |
|
|
|
if (TextUtils.isEmpty(Build.SERIAL)) "" else Build.SERIAL |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
deviceId = telephonyManager.deviceId |
|
|
|
if (deviceId == null) { |
|
|
|
deviceId = if (TextUtils.isEmpty(Build.SERIAL)) "" else Build.SERIAL |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
e.printStackTrace() |
|
|
|
if ((deviceId == null) || deviceId.isEmpty() || deviceId.equals( |
|
|
|
"unknown", |
|
|
|
ignoreCase = true |
|
|
|
) |
|
|
|
) { |
|
|
|
deviceId = if (TextUtils.isEmpty( |
|
|
|
Settings.Secure.getString( |
|
|
|
mContext.contentResolver, |
|
|
|
Settings.Secure.ANDROID_ID |
|
|
|
) |
|
|
|
) |
|
|
|
) "" else Settings.Secure.getString( |
|
|
|
mContext.contentResolver, |
|
|
|
Settings.Secure.ANDROID_ID |
|
|
|
) |
|
|
|
} |
|
|
|
// deviceInfo.deviceId = device_id + "#" + preferenceHelper.getAppName() |
|
|
|
deviceInfo.device_id_for_UMSId = deviceId |
|
|
|
} |
|
|
|
return deviceInfo |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |