Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature updates #27

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ android {
minSdkVersion 16
compileSdk compileSdkVersionCode
targetSdkVersion 34
versionCode 336
versionName "3.3.6"
versionCode 338
versionName "3.3.8"
vectorDrawables.useSupportLibrary true
javaCompileOptions {
annotationProcessorOptions {
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/de/dreier/mytargets/base/db/dao/ImageDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@

package de.dreier.mytargets.base.db.dao

import android.content.Context
import android.database.sqlite.SQLiteException
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import java.io.File

@Dao
interface ImageDAO {
Expand All @@ -29,4 +33,38 @@ interface ImageDAO {
"UNION SELECT `fileName` FROM `ArrowImage`"
)
fun loadAllFileNames(): List<String>

@Transaction
fun removeAllPhotos(context: Context) {
try {
// 1. Delete entries from the database tables
deleteBowImages()
deleteEndImages()
deleteArrowImages()
} catch (e: SQLiteException) {
// Handle exceptions if tables don't exist (e.g., log a warning)
}

// 2. Delete the corresponding files from storage
val fileNames = try {
loadAllFileNames()
} catch (e: SQLiteException) {
// Handle exceptions if the database hasn't been initialized (e.g., return an empty list)
emptyList()
}

for (fileName in fileNames) {
val file = File(context.filesDir, fileName)
file.delete()
}
}

@Query("DELETE FROM BowImage")
fun deleteBowImages()

@Query("DELETE FROM EndImage")
fun deleteEndImages()

@Query("DELETE FROM ArrowImage")
fun deleteArrowImages()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ data class ScoreboardConfiguration(
var showStatistics: Boolean = false,
var showComments: Boolean = false,
var showPointsColored: Boolean = false,
var showSignature: Boolean = false
var showSignature: Boolean = false,
var showTimeRange: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import de.dreier.mytargets.shared.models.db.Shot
import de.dreier.mytargets.shared.models.db.Training
import de.dreier.mytargets.shared.targets.scoringstyle.ScoringStyle
import de.dreier.mytargets.utils.ScoreUtils
import java.util.*
import java.util.Locale

class DefaultScoreboardLayout(
private val context: Context,
Expand Down Expand Up @@ -100,6 +100,8 @@ class DefaultScoreboardLayout(
if (configuration.showSignature) {
appendSignature(training)
}
val legendText = context.getString(R.string.legend_text)
builder.title(legendText)
}

private fun getTrainingInfoTable(
Expand Down Expand Up @@ -251,7 +253,7 @@ class DefaultScoreboardLayout(
var arrowDiameter = Dimension(0.714f, Dimension.Unit.CENTIMETER)
if (training.arrowId != null) {
val arrow = arrowDAO.loadArrow(training.arrowId!!)
if (arrow.diameter != null){
if (arrow.diameter != null) {
arrowDiameter = arrow.diameter
}
}
Expand Down Expand Up @@ -284,10 +286,12 @@ class DefaultScoreboardLayout(
val table = Table(false)
appendTableHeader(table, round.shotsPerEnd)
var carry = 0
for (end in roundDAO.loadEnds(round.id)) {
val ends = roundDAO.loadEnds(round.id)

for ((index, end) in ends.withIndex()) {
val row = table.startRow()
row.addCell(end.index + 1)
var sum = 0
row.addCell(index + 1) // Display the calculated end number (1-based)
var sum = 0 // Reset sum for each end
val shots = ArrayList(endDAO.loadShots(end.id))
if (SettingsManager.shouldSortTarget(round.target)) {
shots.sort()
Expand All @@ -296,10 +300,10 @@ class DefaultScoreboardLayout(
appendPointsCell(row, shot, round.target)
val points = round.target.getScoreByZone(shot.scoringRing, shot.index)
sum += points
carry += points
carry += points // Update the carry value
}
row.addCell(sum)
row.addCell(carry)
row.addCell(sum) // End total
row.addCell(carry) // Display carry value
}
return table
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ object SettingsManager {
config.showComments = preferences["scoreboard_comments", true]
config.showPointsColored = preferences["scoreboard_points_colored", true]
config.showSignature = preferences["scoreboard_signature", true]
config.showTimeRange = preferences["scoreboard_time_range", true]
return config
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ class AboutFragment : Fragment() {
BuildConfig.VERSION_NAME
) + " (${BuildConfig.VERSION_CODE})"

private val crowdinElement: Element
get() = WebElement(
R.string.translate_crowdin, R.drawable.about_icon_crowdin,
URL_CROWDIN
)


private val betaTesterElement: Element
get() = WebElement(R.string.test_beta, R.drawable.about_icon_beta_test, URL_PLAY_STORE)
Expand All @@ -51,11 +47,6 @@ class AboutFragment : Fragment() {
URL_SLACK
)

private val linkedInItem: Element
get() = WebElement(
R.string.network_linkedin, R.drawable.about_icon_linkedin,
URL_LINKEDIN
)

private val shareElement: Element
get() {
Expand Down Expand Up @@ -83,14 +74,10 @@ class AboutFragment : Fragment() {
.setDescription(getString(R.string.my_targets) + "\n" + version)
.addGroup(getString(R.string.contribute))
.addItem(shareElement)
.addItem(crowdinElement)
.addItem(betaTesterElement)
.addGroup(getString(R.string.connect))
.addEmail("[email protected]")
.addPlayStore("de.dreier.mytargets")
.addItem(slackElement)
.addGitHub("DreierF")
.addItem(linkedInItem)
.addGroup(getString(R.string.special_thanks_to))
.addItem(Element(getString(R.string.all_beta_testers), null))
.addItem(
Expand Down Expand Up @@ -134,8 +121,5 @@ class AboutFragment : Fragment() {
"https://join.slack.com/t/mytargets/shared_invite/enQtNjk2NTE0MzU5NzE0LTc3NjAwYmZiNTcxMDA1NTI0M2UzYWY4ZGQwMjVhYjEyODQ0MDE2MjlhZjZiZTUwODg2YTE5YjhkN2FmZTQ2Njc"
private const val URL_PLAY_STORE =
"http://play.google.com/store/apps/details?id=de.dreier.mytargets"
private const val URL_PAYPAL = "https://www.paypal.me/floriandreier"
private const val URL_CROWDIN = "https://crowdin.com/project/mytargets"
private const val URL_LINKEDIN = "https://de.linkedin.com/in/florian-dreier-b056a1113"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.text.format.DateUtils
import android.view.*
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.DividerItemDecoration.VERTICAL
import com.afollestad.materialdialogs.MaterialDialog
Expand All @@ -50,14 +57,19 @@ import de.dreier.mytargets.features.settings.backup.synchronization.GenericAccou
import de.dreier.mytargets.features.settings.backup.synchronization.SyncUtils
import de.dreier.mytargets.utils.ToolbarUtils
import de.dreier.mytargets.utils.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import permissions.dispatcher.NeedsPermission
import permissions.dispatcher.OnNeverAskAgain
import permissions.dispatcher.OnPermissionDenied
import permissions.dispatcher.RuntimePermissions
import timber.log.Timber
import java.io.FileNotFoundException
import java.text.SimpleDateFormat
import java.util.*
import java.util.Locale
import java.util.Timer
import java.util.TimerTask

@RuntimePermissions
class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoadFinishedListener {
Expand Down Expand Up @@ -157,10 +169,25 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa
} else if (item.itemId == R.id.action_fix_db) {
DatabaseFixer.fix(ApplicationInstance.db)
return true
} else if (item.itemId == R.id.action_remove_photos) {
deleteAllPhotos()

}
return super.onOptionsItemSelected(item)
}

private fun deleteAllPhotos() {
lifecycleScope.launch(Dispatchers.IO) { // Launch coroutine on IO dispatcher (background thread)
ApplicationInstance.db.imageDAO().removeAllPhotos(requireContext())

// Back on the main thread for UI updates (Toast)
withContext(Dispatchers.Main) {
Toast.makeText(requireContext(), "All photos removed", Toast.LENGTH_SHORT)
.show()
}
}
}

override fun onResume() {
super.onResume()
if (!isLeaving) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ import android.app.LoaderManager
import android.content.AsyncTaskLoader
import android.content.Intent
import android.content.Loader
import androidx.databinding.DataBindingUtil
import android.net.Uri
import android.os.AsyncTask
import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import android.view.Menu
import android.view.MenuItem
import androidx.core.view.GravityCompat.END
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.core.view.GravityCompat.END
import android.view.Menu
import android.view.MenuItem
import com.afollestad.materialdialogs.MaterialDialog
import com.evernote.android.state.State
import com.google.android.material.snackbar.Snackbar
import de.dreier.mytargets.R
import de.dreier.mytargets.app.ApplicationInstance
import de.dreier.mytargets.base.activities.ChildActivityBase
Expand All @@ -46,7 +46,8 @@ import de.dreier.mytargets.utils.toUri
import java.io.File
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
import java.util.Locale

class StatisticsActivity : ChildActivityBase(),
LoaderManager.LoaderCallbacks<List<Pair<Training, Round>>> {
Expand Down Expand Up @@ -165,6 +166,7 @@ class StatisticsActivity : ChildActivityBase(),
export()
true
}

R.id.action_filter -> {
if (!binding.drawerLayout.isDrawerOpen(END)) {
binding.drawerLayout.openDrawer(END)
Expand All @@ -173,6 +175,7 @@ class StatisticsActivity : ChildActivityBase(),
}
true
}

else -> super.onOptionsItemSelected(item)
}
}
Expand Down Expand Up @@ -206,8 +209,10 @@ class StatisticsActivity : ChildActivityBase(),
.map { value1 -> Pair(value1.value[0].target, value1.value) }
.sortedByDescending { it.second.size }
val animate = binding.viewPager.adapter == null
val environment =
if (trainingDAO.loadTrainings().first().environment.indoor) "Indoor" else "Outdoor"
val adapter = StatisticsPagerAdapter(
supportFragmentManager, filteredRounds!!, animate
supportFragmentManager, filteredRounds!!, animate, environment
)
binding.viewPager.adapter = adapter
}
Expand Down Expand Up @@ -308,7 +313,8 @@ class StatisticsActivity : ChildActivityBase(),
inner class StatisticsPagerAdapter internal constructor(
fm: FragmentManager,
private val targets: List<Pair<Target, List<Round>>>,
private val animate: Boolean
private val animate: Boolean,
private val environment: String
) : FragmentStatePagerAdapter(fm) {

override fun getItem(position: Int): Fragment {
Expand All @@ -321,8 +327,8 @@ class StatisticsActivity : ChildActivityBase(),
return targets.size
}

override fun getPageTitle(position: Int): CharSequence? {
return targets[position].first.toString()
override fun getPageTitle(position: Int): CharSequence {
return targets[position].first.toString() + " - " + environment
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/menu/settings_backup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
android:id="@+id/action_fix_db"
android:title="@string/fix_db"
app:showAsAction="never"/>
<item
android:id="@+id/action_remove_photos"
android:title="@string/remove_all_photos"
app:showAsAction="never"/>

</menu>
10 changes: 10 additions & 0 deletions app/src/main/res/raw/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ <h2>Statistics</h2>
<li>https://www.mckinley.biz/</li>
<li>https://www.canfordmagnabowmen.co.uk/</li>
</ul>
<h3>Official Handicap Tables and Related Documents(Updated) </h3>
<ul>
<li><a href="https://archerygb.org/files/outdoor-classifications-amp-handicaps-barebow-190123111828.pdf" target="_blank">Outdoor Classification Tables: Barebow</a></li>
<li><a href="https://archerygb.org/files/outdoor-classifications-amp-handicaps-compound-190123111916.pdf" target="_blank">Outdoor Classifications & Handicaps: Compound</a></li>
<li><a href="https://archerygb.org/files/outdoor-classifications-amp-handicaps-longbow-190123111853.pdf" target="_blank">Outdoor Classifications & Handicaps: Longbow</a></li>
<li><a href="https://archerygb.org/files/outdoor-classifications-amp-handicaps-recurve-190123111801.pdf" target="_blank">Outdoor Classifications & Handicaps: Recurve</a></li>
<li><a href="https://archerygb.org/files/outdoor-classifications-amp-handicaps-changeover-procedures-120923153640.pdf" target="_blank">Outdoor Classifications & Handicaps: Changeover Procedures</a></li>
<li><a href="https://archerygb.org/files/outdoor-handicap-amp-classification-calculator-excel-270923102831.xlsx" target="_blank">Outdoor Handicap & Classification Calculator: Excel</a></li>
<li><a href="https://archerygb.org/files/outdoor-handicap-tables-120923153655.pdf" target="_blank">Outdoor Handicap Tables</a></li>
</ul>
</details>
<details>
<summary>Analysis scope</summary>
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@
<string name="scoreboard">Scoreboard</string>
<string name="arrows">Arrows</string>
<string name="sum">Score</string>
<string name="carry">R.Total</string>
<string name="carry">Running Total</string>
<string name="action_print">Print</string>
<string name="average">Average</string>
<string name="avg_symbol">Ø</string>
<string name="handicap_symbol">∑</string>
<string name="avg_symbol" translatable="false">Ø</string>
<string name="handicap_symbol" translatable="false">∑</string>
<string name="legend_text">Legend for Ø = Hits and Average ∑ = Handicap in App</string>

<!-- Input mode -->
<string name="comment">Comment</string>
Expand Down Expand Up @@ -394,4 +395,6 @@
<string name="permission_required">Permission required</string>
<string name="backup_permission_explanation"><![CDATA[To be able to make a backup of your data, the app needs permission to access the internal storage of your phone. To use the backup feature go to system settings > Apps > MyTargets > Permissions and enable the entry \'Storage\'.]]></string>
<string name="fix_db">Attempt to fix database</string>
<string name="time_range" translatable="false">Time range</string>
<string name="remove_all_photos">Remove All Photos</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@
android:defaultValue="true"
android:key="scoreboard_signature"
android:title="@string/show_signature"/>
<!-- <CheckBoxPreference-->
<!-- android:defaultValue="true"-->
<!-- android:key="scoreboard_time_range"-->
<!-- android:title="@string/time_range"/>-->
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
Expand Down
Loading