diff --git a/app/build.gradle b/app/build.gradle index c4e9f94..4756a1c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,14 +4,14 @@ plugins { } android { - compileSdk 33 + compileSdk 34 defaultConfig { applicationId "org.woheller69.whobird" minSdk 30 - targetSdk 33 - versionCode 30 - versionName "3.0" + targetSdk 34 + versionCode 31 + versionName "3.1" } aaptOptions { @@ -44,13 +44,13 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "androidx.core:core-ktx:1.3.1" - implementation "androidx.appcompat:appcompat:1.2.0" - implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0" - implementation "androidx.constraintlayout:constraintlayout:2.0.1" - implementation "com.google.android.material:material:1.2.1" + implementation "androidx.core:core-ktx:1.13.0" + implementation "androidx.appcompat:appcompat:1.6.1" + implementation "androidx.lifecycle:lifecycle-common-java8:2.7.0" + implementation "androidx.constraintlayout:constraintlayout:2.1.4" + implementation "com.google.android.material:material:1.11.0" implementation "org.tensorflow:tensorflow-lite:2.6.0" - implementation 'androidx.preference:preference:1.2.0' - implementation 'com.squareup.okhttp3:okhttp:4.12.0' - implementation 'net.lingala.zip4j:zip4j:2.9.1' + implementation "androidx.preference:preference:1.2.1" + implementation "com.squareup.okhttp3:okhttp:4.12.0" + implementation "net.lingala.zip4j:zip4j:2.9.1" } \ No newline at end of file diff --git a/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/Downloader.java b/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/Downloader.java index 97aae46..f7a5933 100755 --- a/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/Downloader.java +++ b/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/Downloader.java @@ -64,6 +64,7 @@ public static boolean checkModels(final Activity activity) { } public static void downloadModels(final Activity activity, ActivityDownloadBinding binding) { + binding.downloadProgress.setProgress(0); File modelFile = new File(activity.getDir("filesdir", Context.MODE_PRIVATE) + "/" + modelFILE); if (!modelFile.exists()) { Log.d("whoBIRD", "model file does not exist"); diff --git a/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/ViewActivity.kt b/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/ViewActivity.kt index 04dcaf1..6f08fa3 100644 --- a/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/ViewActivity.kt +++ b/app/src/main/java/org/tensorflow/lite/examples/soundclassifier/ViewActivity.kt @@ -2,6 +2,7 @@ package org.tensorflow.lite.examples.soundclassifier import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Bundle import android.text.format.DateFormat import android.util.Log @@ -30,6 +31,7 @@ class ViewActivity : AppCompatActivity() { private lateinit var birdObservations: ArrayList private lateinit var assetList: List private lateinit var labelList: List + private lateinit var eBirdList: List override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -99,6 +101,7 @@ class ViewActivity : AppCompatActivity() { binding.webviewLatinname.setText("") binding.webviewLatinname.setVisibility(View.GONE) binding.webviewReload.setVisibility(View.GONE) + binding.webviewEbird.setVisibility(View.GONE) binding.webviewShare.setVisibility(View.GONE) }).setTextColor(this.getColor(R.color.orange500)).show() } @@ -107,6 +110,7 @@ class ViewActivity : AppCompatActivity() { } loadLabels(this) loadAssetList(this) + loadEbirdList(this) } override fun onResume() { @@ -137,6 +141,7 @@ class ViewActivity : AppCompatActivity() { binding.webviewLatinname.setText("") binding.webviewLatinname.setVisibility(View.GONE) binding.webviewReload.setVisibility(View.GONE) + binding.webviewEbird.setVisibility(View.GONE) binding.webviewShare.setVisibility(View.GONE) } else { if (binding.webviewUrl.toString() != url) { @@ -151,6 +156,8 @@ class ViewActivity : AppCompatActivity() { binding.webviewLatinname.setText(labelList[adapter.getSpeciesID(position)].split("_").first()) binding.webviewLatinname.setVisibility(View.VISIBLE) binding.webviewReload.setVisibility(View.VISIBLE) + binding.webviewEbird.setVisibility(View.VISIBLE) + binding.webviewEbird.setTag(position) binding.webviewShare.setVisibility(View.VISIBLE) binding.webviewShare.setTag(position) binding.icon.setVisibility(View.GONE) @@ -164,7 +171,7 @@ class ViewActivity : AppCompatActivity() { } - /** Retrieve asset list from "asset_list" file */ + /** Retrieve asset list from "assets" file */ private fun loadAssetList(context: Context) { try { @@ -182,6 +189,24 @@ class ViewActivity : AppCompatActivity() { } } + /** Retrieve eBird taxonomy list from "taxo_code" file */ + private fun loadEbirdList(context: Context) { + + try { + val reader = + BufferedReader(InputStreamReader(context.assets.open("taxo_code.txt"))) + val wordList = mutableListOf() + reader.useLines { lines -> + lines.forEach { + wordList.add(it.trim()) + } + } + eBirdList = wordList.map { it } + } catch (e: IOException) { + Log.e("ViewActivity", "Failed to read labels ${"taxo_code.txt"}: ${e.message}") + } + } + /** Retrieve labels from "labels.txt" file */ private fun loadLabels(context: Context) { //TODO: Refactor val localeList = context.resources.configuration.locales @@ -260,4 +285,10 @@ class ViewActivity : AppCompatActivity() { shareIntent.putExtra(Intent.EXTRA_TEXT, shareString) startActivity(Intent.createChooser(shareIntent, "")) } + + fun ebird(view: View) { + val position = binding.webviewShare.tag as Int + val id = adapter.getSpeciesID(position) + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://ebird.org/species/"+eBirdList[id]))) + } } diff --git a/app/src/main/res/layout/activity_view.xml b/app/src/main/res/layout/activity_view.xml index 38a0a71..8212a66 100644 --- a/app/src/main/res/layout/activity_view.xml +++ b/app/src/main/res/layout/activity_view.xml @@ -44,6 +44,14 @@ android:layout_toEndOf="@id/webview_reload" android:src="@drawable/ic_share_24dp" android:onClick="share"/> +