Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Update 1.0.2 | Final update
Browse files Browse the repository at this point in the history
  • Loading branch information
D4rK7355608 committed Feb 15, 2024
1 parent 6ab46a5 commit b2f63e7
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 19 deletions.
10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version 1.1.0:
- **Patch**: Fixed app crashes caused by the swipe to refresh layout.
- **Patch**: Fixed image upload feature.
- **Patch**: Updated dependencies to the latest versions.

# Version 1.0.2:
- **Patch**: Fixed issue with Build CI on GitHub.

Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("com.google.android.material:material:1.9.0")
implementation("com.google.android.material:material:1.11.0")
implementation("me.zhanghai.android.fastscroll:library:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature android:name="android.hardware.camera" android:required="true"/>
<application
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
Expand All @@ -25,5 +27,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
53 changes: 47 additions & 6 deletions app/src/main/kotlin/com/google/android/apps/bard/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ import android.webkit.WebView
import android.webkit.WebViewClient
import android.window.OnBackInvokedDispatcher
import android.content.SharedPreferences
import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import android.webkit.CookieManager
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import androidx.core.content.FileProvider
import com.google.android.apps.bard.databinding.ActivityMainBinding
import com.google.android.material.snackbar.Snackbar
import me.zhanghai.android.fastscroll.FastScrollerBuilder
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
class MainActivity : Activity() {
private val userAgent = "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.60 Mobile Safari/537.36"
private val userAgent = "Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6127.2 Mobile Safari/537.36"
private val chatUrl = "https://bard.google.com/"
private lateinit var binding: ActivityMainBinding
private lateinit var sharedPreferences: SharedPreferences
private lateinit var cookieManager: CookieManager
private var uploadMessage: ValueCallback<Array<Uri>>? = null
private val fileChooserResultCode = 1
@SuppressLint("SetJavaScriptEnabled")
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
Expand Down Expand Up @@ -52,11 +64,41 @@ class MainActivity : Activity() {
configureWebViewSettings()
setupWebViewInterface()
setupWebViewClient()
binding.swipeRefreshLayout.setOnRefreshListener {
binding.webView.reload()
binding.swipeRefreshLayout.isRefreshing = false
binding.webView.webChromeClient = object : WebChromeClient() {
override fun onShowFileChooser(webView: WebView, filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: FileChooserParams): Boolean {
uploadMessage = filePathCallback
val galleryIntent = Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "image/*"
}
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
val photoFile = createImageFile()
val photoURI = FileProvider.getUriForFile(this@MainActivity, "com.example.fileprovider", photoFile)
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
val chooserIntent = Intent.createChooser(galleryIntent, "Image Chooser").apply {
putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(cameraIntent))
}
startActivityForResult(chooserIntent, fileChooserResultCode)
return true
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == fileChooserResultCode) {
if (uploadMessage != null) {
val result = WebChromeClient.FileChooserParams.parseResult(resultCode, data)
uploadMessage?.onReceiveValue(result)
uploadMessage = null
}
}
}
private fun createImageFile(): File {
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
val imageFileName = "JPEG_${timeStamp}_"
val storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES)
return File.createTempFile(imageFileName, ".jpg", storageDir)
}
private fun initializeFastScroller() {
FastScrollerBuilder(binding.webView).useMd2Style().build()
}
Expand Down Expand Up @@ -113,8 +155,6 @@ class MainActivity : Activity() {
saveUserAccount(userAccount)
}
}
binding.swipeRefreshLayout.isRefreshing = false
binding.swipeRefreshLayout.isEnabled = !(binding.webView.url?.contains(chatUrl) == true && !binding.webView.url.toString().contains("/auth"))
binding.webView.evaluateJavascript("""
(() => {
navigator.clipboard.writeText = (text) => {
Expand All @@ -126,6 +166,7 @@ class MainActivity : Activity() {
)
}
}

}
private fun extractUserAccountFromWebPage(): String {
var userAccount = ""
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</me.zhanghai.android.fastscroll.FastScrollWebView>
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<paths>
<external-path name="my_images" path="Android/data/${applicationId}/files/Pictures" />
</paths>
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("com.android.application") version "8.1.2" apply false
id("com.android.library") version "8.1.2" apply false
id("com.android.application") version "8.1.4" apply false
id("com.android.library") version "8.1.4" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 07 13:33:33 EEST 2023
#Thu Dec 21 20:38:52 EET 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit b2f63e7

Please sign in to comment.