Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
feature(#12): fix error that app is requesting with incorrect uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
peterluo3131 committed Jun 6, 2023
1 parent fb6c74e commit f96324d
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 178 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
applicationId "com.matthaigh27.chatgptwrapper"
minSdk 28
targetSdk 33
versionCode 2
versionCode 7
versionName "1.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.matthaigh27.chatgptwrapper

import android.Manifest
import android.annotation.SuppressLint
import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
Expand All @@ -19,13 +20,17 @@ class MyApplication : Application() {

private var mFCMToken: String = String()
private var mUUID: String = String()
@SuppressLint("HardwareIds")
override fun onCreate() {
super.onCreate()

initToken()
// on below line we are getting device id.
mUUID = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
appContext = applicationContext as MyApplication

Log.v("risingandroid mUUID: ", mUUID)
Log.v("risingandroid FCMToken: ", mFCMToken)
}

private fun initToken() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,33 @@ class HomeActivity : AppCompatActivity() {
}

private fun requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val notGrantedPermissions = PERMISSIONS.filter {
checkSelfPermission(it) != PackageManager.PERMISSION_GRANTED
}
val notGrantedPermissions = PERMISSIONS.filter {
checkSelfPermission(it) != PackageManager.PERMISSION_GRANTED
}

if (notGrantedPermissions.isNotEmpty()) {
if (shouldShowRequestPermissionRationale(notGrantedPermissions[0])) {
// show custom permission rationale
val confirmDialog = CommonConfirmDialog(this)
confirmDialog.setMessage("This app requires SMS, Contacts and Phone permissions to function properly. Please grant the necessary permissions.")
confirmDialog.setOnClickListener(object :
CommonConfirmDialog.OnConfirmButtonClickListener {
override fun onPositiveButtonClick() {
requestPermissions(notGrantedPermissions.toTypedArray(), PERMISSIONS_REQUEST_CODE)
}
if (notGrantedPermissions.isNotEmpty()) {
if (shouldShowRequestPermissionRationale(notGrantedPermissions[0])) {
// show custom permission rationale
val confirmDialog = CommonConfirmDialog(this)
confirmDialog.setMessage("This app requires SMS, Contacts and Phone permissions to function properly. Please grant the necessary permissions.")
confirmDialog.setOnClickListener(object :
CommonConfirmDialog.OnConfirmButtonClickListener {
override fun onPositiveButtonClick() {
requestPermissions(
notGrantedPermissions.toTypedArray(), PERMISSIONS_REQUEST_CODE
)
}

override fun OnNegativeButtonClick() {
finish()
}
})
confirmDialog.show()
} else {
requestPermissions(notGrantedPermissions.toTypedArray(), PERMISSIONS_REQUEST_CODE)
}
override fun onNegativeButtonClick() {
finish()
}
})
confirmDialog.show()
} else {
// Permissions already granted, navigate to your desired fragment
navigateToChatFragment()
requestPermissions(notGrantedPermissions.toTypedArray(), PERMISSIONS_REQUEST_CODE)
}
} else {
// Permissions already granted for pre-M devices, navigate to your desired fragment
// Permissions already granted, navigate to your desired fragment
navigateToChatFragment()
}
}
Expand All @@ -75,17 +72,14 @@ class HomeActivity : AppCompatActivity() {

@SuppressLint("MissingSuperCall")
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
) {
when (requestCode) {
PERMISSIONS_REQUEST_CODE -> {
if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
// Permissions granted, navigate to your desired fragment
navigateToChatFragment()
} else {
Log.v("rising", "hello")
requestPermission()
}
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ class CommonConfirmDialog(context: Context) : Dialog(context), View.OnClickListe
mTvMessage?.text = mMessage
}


override fun onClick(view: View?) {
when (view?.id) {
R.id.btn_ok -> {
mClickListener.onPositiveButtonClick()
}

R.id.btn_cancel -> {
mClickListener.OnNegativeButtonClick()
mClickListener.onNegativeButtonClick()
}
}

Expand All @@ -67,6 +69,6 @@ class CommonConfirmDialog(context: Context) : Dialog(context), View.OnClickListe

interface OnConfirmButtonClickListener {
fun onPositiveButtonClick()
fun OnNegativeButtonClick()
fun onNegativeButtonClick()
}
}
Loading

0 comments on commit f96324d

Please sign in to comment.