Skip to content

Commit

Permalink
V3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
woheller69 committed May 5, 2024
1 parent c9d3495 commit 91e7a5c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
24 changes: 12 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -30,6 +31,7 @@ class ViewActivity : AppCompatActivity() {
private lateinit var birdObservations: ArrayList<BirdObservation>
private lateinit var assetList: List<String>
private lateinit var labelList: List<String>
private lateinit var eBirdList: List<String>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -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()
}
Expand All @@ -107,6 +110,7 @@ class ViewActivity : AppCompatActivity() {
}
loadLabels(this)
loadAssetList(this)
loadEbirdList(this)
}

override fun onResume() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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<String>()
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
Expand Down Expand Up @@ -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])))
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
android:layout_toEndOf="@id/webview_reload"
android:src="@drawable/ic_share_24dp"
android:onClick="share"/>
<ImageButton
android:id="@+id/webview_ebird"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="@id/webview_reload"
android:src="@drawable/ic_info_24dp"
android:onClick="ebird"/>
<TextView
android:id="@+id/webview_url"
android:layout_width="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/31.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add info button with link to eBird
Update for Android 14 (SDK 34)

0 comments on commit 91e7a5c

Please sign in to comment.