diff --git a/app/build.gradle b/app/build.gradle index 235a421..57dec64 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,45 +1,44 @@ plugins { id 'com.android.application' id 'kotlin-android' - id 'kotlin-android-extensions' } android { namespace 'com.matthaigh27.chatgptwrapper' - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.matthaigh27.chatgptwrapper" - minSdk 31 - targetSdk 32 + minSdk 28 + targetSdk 33 versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + versionName "1.2" } buildTypes { release { - minifyEnabled false + minifyEnabled true + shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + + buildFeatures { + viewBinding true + } + compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = JavaVersion.VERSION_11 } } dependencies { - - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.appcompat:appcompat:1.5.1' - implementation 'com.google.android.material:material:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.4' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' + implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.appcompat:appcompat:1.6.0' + implementation 'com.google.android.material:material:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5adb446..ce43656 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,24 +1,23 @@ - + - + - - + - - - - - - + + + + + + diff --git a/app/src/main/java/com/matthaigh27/chatgptwrapper/CustomWebView.kt b/app/src/main/java/com/matthaigh27/chatgptwrapper/CustomWebView.kt deleted file mode 100644 index 8d8f642..0000000 --- a/app/src/main/java/com/matthaigh27/chatgptwrapper/CustomWebView.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.matthaigh27.chatgptwrapper - -import android.content.Context -import android.util.AttributeSet -import android.view.inputmethod.BaseInputConnection -import android.view.inputmethod.EditorInfo -import android.view.inputmethod.InputConnection -import android.webkit.WebView - -class CustomWebView(context: Context, attrs: AttributeSet?) : WebView(context, attrs) { - var loggedIn : Boolean = false - - override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection { - val inputConnection = super.onCreateInputConnection(outAttrs) - if (!loggedIn || inputConnection == null) { - return BaseInputConnection(this, false) - } - - outAttrs.inputType = EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE - outAttrs.imeOptions = EditorInfo.IME_ACTION_GO - - return inputConnection - } - - override fun onCheckIsTextEditor(): Boolean { - return true - } -} \ No newline at end of file diff --git a/app/src/main/java/com/matthaigh27/chatgptwrapper/MainActivity.kt b/app/src/main/java/com/matthaigh27/chatgptwrapper/MainActivity.kt index cb46f16..d5a840f 100644 --- a/app/src/main/java/com/matthaigh27/chatgptwrapper/MainActivity.kt +++ b/app/src/main/java/com/matthaigh27/chatgptwrapper/MainActivity.kt @@ -8,38 +8,49 @@ import android.os.Bundle import android.view.WindowManager import android.webkit.WebView import android.webkit.WebViewClient -import kotlinx.android.synthetic.main.activity_main.* +import android.window.OnBackInvokedDispatcher +import com.matthaigh27.chatgptwrapper.databinding.ActivityMainBinding class MainActivity : Activity() { - private val userAgent = "Mozilla/5.0 (Linux; Android " + Build.VERSION.RELEASE + ") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.5359.79 Mobile Safari/537.36" + private val userAgent = + "Mozilla/5.0 (Linux; Android " + Build.VERSION.RELEASE + ") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.5359.79 Mobile Safari/537.36" private val chatUrl = "https://chat.openai.com/" + private lateinit var binding: ActivityMainBinding + private lateinit var webView: WebView @SuppressLint("SetJavaScriptEnabled") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) - window.statusBarColor = Color.parseColor("#343541") - - webView.webViewClient = object : WebViewClient() { - override fun onLoadResource(view: WebView, url: String) { - if (view is CustomWebView && url == "https://chat.openai.com/backend-api/models") { - view.loggedIn = true + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + webView = binding.webView + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + onBackInvokedDispatcher.registerOnBackInvokedCallback( + OnBackInvokedDispatcher.PRIORITY_DEFAULT + ) { + if (webView.canGoBack()) { + webView.goBack() + } else { + finish() } - return super.onLoadResource(view, url) } } + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + window.statusBarColor = Color.parseColor("#343541") + webView.settings.userAgentString = userAgent webView.settings.domStorageEnabled = true webView.settings.javaScriptEnabled = true + webView.webViewClient = WebViewClient() webView.loadUrl(chatUrl) } + @Deprecated("Deprecated in Java") override fun onBackPressed() { - if (webView.canGoBack()) + if (webView.canGoBack() && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) webView.goBack() else super.onBackPressed() diff --git a/app/src/main/res/drawable/gpt_icon_background.xml b/app/src/main/res/drawable/gpt_icon_background.xml index ca3826a..07d5da9 100644 --- a/app/src/main/res/drawable/gpt_icon_background.xml +++ b/app/src/main/res/drawable/gpt_icon_background.xml @@ -1,74 +1,170 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:viewportHeight="108"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index cd88d0a..cb39fa2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,10 +5,10 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + android:focusableInTouchMode="true" /> diff --git a/app/src/main/res/mipmap-anydpi-v26/gpt_icon.xml b/app/src/main/res/mipmap-anydpi-v26/gpt_icon.xml index cdb8490..3807d02 100644 --- a/app/src/main/res/mipmap-anydpi-v26/gpt_icon.xml +++ b/app/src/main/res/mipmap-anydpi-v26/gpt_icon.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/gpt_icon_round.xml b/app/src/main/res/mipmap-anydpi-v26/gpt_icon_round.xml index cdb8490..3807d02 100644 --- a/app/src/main/res/mipmap-anydpi-v26/gpt_icon_round.xml +++ b/app/src/main/res/mipmap-anydpi-v26/gpt_icon_round.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 60aeb09..83cab40 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '7.3.1' apply false - id 'com.android.library' version '7.3.1' apply false + id 'com.android.application' version '7.4.0' apply false + id 'com.android.library' version '7.4.0' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c2a6483..21b9656 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Dec 05 16:03:39 AEST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME