Skip to content

Commit

Permalink
1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
matthaigh27 committed Feb 3, 2023
1 parent dc02c9f commit 0a8f454
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 156 deletions.
37 changes: 18 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
33 changes: 16 additions & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.matthaigh27.chatgptwrapper">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:icon="@mipmap/gpt_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/gpt_icon_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat"
android:hardwareAccelerated="true">
<activity
<application
android:hardwareAccelerated="true"
android:icon="@mipmap/gpt_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/gpt_icon_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
28 changes: 0 additions & 28 deletions app/src/main/java/com/matthaigh27/chatgptwrapper/CustomWebView.kt

This file was deleted.

37 changes: 24 additions & 13 deletions app/src/main/java/com/matthaigh27/chatgptwrapper/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 0a8f454

Please sign in to comment.