|
|
@ -4,23 +4,28 @@ import android.Manifest |
|
|
|
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 |
|
|
|
import android.net.NetworkCapabilities |
|
|
|
import android.net.Uri |
|
|
|
import android.os.Build |
|
|
|
import android.provider.Settings |
|
|
|
import android.text.format.DateFormat |
|
|
|
import android.util.Log |
|
|
|
import android.util.Patterns |
|
|
|
import androidx.activity.result.contract.ActivityResultContracts |
|
|
|
import androidx.core.app.ActivityCompat |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import androidx.core.content.ContextCompat.startActivity |
|
|
|
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.bajajfd.R |
|
|
|
import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity |
|
|
|
import kotlinx.coroutines.CoroutineExceptionHandler |
|
|
|
import org.json.JSONObject |
|
|
|
import retrofit2.HttpException |
|
|
@ -124,11 +129,18 @@ class Common { |
|
|
|
builder.show() |
|
|
|
} |
|
|
|
|
|
|
|
fun showDialogWithTwoButtons(activity: Activity?, message: CharSequence?) { |
|
|
|
fun showDialogWithTwoButtons(activity: Activity?, message: CharSequence?, title: String) { |
|
|
|
val builder = AlertDialog.Builder(activity) |
|
|
|
builder.setTitle(title) |
|
|
|
builder.setMessage(message) |
|
|
|
if (activity != null) { |
|
|
|
builder.setPositiveButton(activity.getString(R.string.Ok)) { dialogInterface, _ -> |
|
|
|
val intent = Intent( |
|
|
|
Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
|
|
|
Uri.fromParts("package", (activity as BajajFdMainActivity).packageName, null) |
|
|
|
) |
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
|
|
activity.startActivity(intent) |
|
|
|
dialogInterface.dismiss() |
|
|
|
} |
|
|
|
builder.setNegativeButton(activity.getString(R.string.cancel)) { dialogInterface, _ -> |
|
|
@ -194,21 +206,11 @@ class Common { |
|
|
|
} |
|
|
|
|
|
|
|
fun handleResponse(response: Response<JsonObject>): Resource<JsonObject> { |
|
|
|
// try { |
|
|
|
if (response.isSuccessful && response.body() != null) { |
|
|
|
response.body()?.let { resultResponse -> |
|
|
|
return Resource.Success(resultResponse) |
|
|
|
} |
|
|
|
} |
|
|
|
// } catch (t: Throwable) { |
|
|
|
// return when (t) { |
|
|
|
// is IOException -> Resource.Error("Response : " + t.message.plus(" Cause: " + t.cause)) |
|
|
|
// is HttpException -> Resource.Error("Response : " + t.message.plus(" Cause: " + t.cause)) |
|
|
|
// is SocketTimeoutException -> Resource.Error("Response : " + t.message.plus(" Cause: " + t.cause)) |
|
|
|
// is UnknownHostException -> Resource.Error("Response : " + t.message.plus(" Cause: " + t.cause)) |
|
|
|
// else -> Resource.Error(t.localizedMessage?.toString() ?: "") |
|
|
|
// } |
|
|
|
// } |
|
|
|
return Resource.Error(response.message()) |
|
|
|
} |
|
|
|
|
|
|
@ -247,7 +249,7 @@ class Common { |
|
|
|
} |
|
|
|
|
|
|
|
fun isMinor(date: String): Boolean { |
|
|
|
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) |
|
|
|
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US) |
|
|
|
val dt1: Date = simpleDateFormat.parse(date) as Date |
|
|
|
val year: Int = DateFormat.format("yyyy", dt1).toString().toInt() |
|
|
|
val month: Int = DateFormat.format("mm", dt1).toString().toInt() |
|
|
|