Skip to content

Commit

Permalink
Merge pull request #12 from mateusz-bak/dev
Browse files Browse the repository at this point in the history
Version 1.2.1
  • Loading branch information
mateusz-bak authored Jun 14, 2021
2 parents 87e91ca + 623bd0a commit 6bd09e9
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 6 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "software.mdev.bookstracker"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.2.0"
versionCode 2
versionName "1.2.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -75,4 +75,7 @@ dependencies {

// PREFERENCES
implementation "androidx.preference:preference-ktx:1.1.1"

// https://github.com/javiersantos/AppUpdater
implementation 'com.github.javiersantos:AppUpdater:2.7'
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="software.mdev.bookstracker">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_books"
Expand All @@ -20,5 +22,4 @@
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ object Constants {
const val SHARED_PREFERENCES_KEY_ACCENT = "KEY_ACCENT"
const val SHARED_PREFERENCES_KEY_RECOMMENDATIONS = "KEY_RECOMMENDATIONS"
const val SHARED_PREFERENCES_REFRESHED = "refreshed"
const val KEY_CHECK_FOR_UPDATES = "KEY_CHECK_FOR_UPDATES"

const val EMPTY_STRING = ""

Expand All @@ -55,4 +56,7 @@ object Constants {
const val THEME_ACCENT_YELLOW_500 = "accent_yellow"

const val THEME_ACCENT_DEFAULT = THEME_ACCENT_GREEN_500

const val GITHUB_USER = "mateusz-bak"
const val GITHUB_REPO = "books-tracker-android"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import com.github.javiersantos.appupdater.AppUpdater
import com.github.javiersantos.appupdater.enums.Display
import com.github.javiersantos.appupdater.enums.UpdateFrom
import kotlinx.android.synthetic.main.activity_list.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import software.mdev.bookstracker.R
import software.mdev.bookstracker.data.db.BooksDatabase
import software.mdev.bookstracker.data.repositories.BooksRepository
Expand All @@ -29,7 +35,7 @@ class ListActivity : AppCompatActivity() {
setAppTheme()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_list)

checkForAppUpdate(this)
bottomNavigationView.setupWithNavController(booksNavHostFragment.findNavController())

booksNavHostFragment.findNavController()
Expand Down Expand Up @@ -68,4 +74,18 @@ class ListActivity : AppCompatActivity() {
}
}

fun checkForAppUpdate(context: Context) = CoroutineScope(Dispatchers.Main).launch {
var appUpdater = AppUpdater(context)
appUpdater
.setTitleOnUpdateAvailable(getString(R.string.setTitleOnUpdateAvailable))
.setContentOnUpdateAvailable(getString(R.string.setContentOnUpdateAvailable))
.setButtonUpdate(getString(R.string.setButtonUpdate))
.setButtonDismiss(getString(R.string.setButtonDismiss))
.setButtonDoNotShowAgain(getString(R.string.setButtonDoNotShowAgain))
.setUpdateFrom(UpdateFrom.GITHUB)
.setGitHubUserAndRepo(Constants.GITHUB_USER, Constants.GITHUB_REPO)
.setDisplay(Display.DIALOG)
.showAppUpdated(false)
.start()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import software.mdev.bookstracker.other.Constants.SERIALIZABLE_BUNDLE_BOOK
import software.mdev.bookstracker.other.Constants.SHARED_PREFERENCES_NAME
import software.mdev.bookstracker.other.Constants.SORT_ORDER_AUTHOR_ASC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_AUTHOR_DESC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_DATE_ASC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_DATE_DESC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_PAGES_ASC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_PAGES_DESC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_RATING_ASC
Expand Down Expand Up @@ -130,6 +132,7 @@ class InProgressFragment : Fragment(R.layout.fragment_in_progress) {

bookAdapter.setOnBookClickListener {
etSearch.setText(EMPTY_STRING)
fabAddBook.visibility = View.GONE
val bundle = Bundle().apply {
putSerializable(SERIALIZABLE_BUNDLE_BOOK, it)
}
Expand Down Expand Up @@ -236,6 +239,8 @@ class InProgressFragment : Fragment(R.layout.fragment_in_progress) {
SORT_ORDER_RATING_ASC -> viewModel.getSortedBooksByRatingAsc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_PAGES_DESC -> viewModel.getSortedBooksByPagesDesc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_PAGES_ASC -> viewModel.getSortedBooksByPagesAsc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_DATE_DESC -> viewModel.getSortedBooksByDateDesc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_DATE_ASC -> viewModel.getSortedBooksByDateAsc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package software.mdev.bookstracker.ui.bookslist.fragments

import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.os.Bundle
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.github.javiersantos.appupdater.AppUpdater
import com.github.javiersantos.appupdater.enums.Display
import com.github.javiersantos.appupdater.enums.UpdateFrom
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import software.mdev.bookstracker.R
import software.mdev.bookstracker.other.Constants
import software.mdev.bookstracker.other.Constants.KEY_CHECK_FOR_UPDATES
import software.mdev.bookstracker.other.Constants.SHARED_PREFERENCES_KEY_ACCENT
import software.mdev.bookstracker.other.Constants.SHARED_PREFERENCES_KEY_RECOMMENDATIONS
import software.mdev.bookstracker.other.Constants.SHARED_PREFERENCES_REFRESHED
Expand All @@ -24,6 +34,15 @@ class SettingsFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeLis
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
viewModel = (activity as ListActivity).booksViewModel

var preferenceCheckForUpdates = findPreference<Preference>(KEY_CHECK_FOR_UPDATES)

if (preferenceCheckForUpdates != null) {
preferenceCheckForUpdates.onPreferenceClickListener = Preference.OnPreferenceClickListener {
context?.let { it1 -> checkForAppUpdate(it1) }
true
}
}
}

override fun onResume() {
Expand Down Expand Up @@ -57,4 +76,21 @@ class SettingsFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeLis
findNavController().navigate(R.id.readFragment, null)
(activity as FragmentActivity).recreate()
}

fun checkForAppUpdate(context: Context) = CoroutineScope(Dispatchers.Main).launch {
var appUpdater = AppUpdater(context)
appUpdater
.setTitleOnUpdateAvailable(getString(R.string.setTitleOnUpdateAvailable))
.setContentOnUpdateAvailable(getString(R.string.setContentOnUpdateAvailable))
.setButtonUpdate(getString(R.string.setButtonUpdate))
.setButtonDismiss(getString(R.string.setButtonDismiss))
.setButtonDoNotShowAgain(getString(R.string.setButtonDoNotShowAgain))
.setContentOnUpdateNotAvailable(getString(R.string.setContentOnUpdateNotAvailable))
.setTitleOnUpdateNotAvailable(getString(R.string.setTitleOnUpdateNotAvailable))
.setUpdateFrom(UpdateFrom.GITHUB)
.setGitHubUserAndRepo(Constants.GITHUB_USER, Constants.GITHUB_REPO)
.setDisplay(Display.DIALOG)
.showAppUpdated(true)
.start()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import software.mdev.bookstracker.other.Constants.SERIALIZABLE_BUNDLE_BOOK
import software.mdev.bookstracker.other.Constants.SHARED_PREFERENCES_NAME
import software.mdev.bookstracker.other.Constants.SORT_ORDER_AUTHOR_ASC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_AUTHOR_DESC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_DATE_ASC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_DATE_DESC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_PAGES_ASC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_PAGES_DESC
import software.mdev.bookstracker.other.Constants.SORT_ORDER_RATING_ASC
Expand Down Expand Up @@ -130,6 +132,7 @@ class ToReadFragment : Fragment(R.layout.fragment_to_read) {

bookAdapter.setOnBookClickListener {
etSearch.setText(EMPTY_STRING)
fabAddBook.visibility = View.GONE
val bundle = Bundle().apply {
putSerializable(SERIALIZABLE_BUNDLE_BOOK, it)
}
Expand Down Expand Up @@ -236,6 +239,8 @@ class ToReadFragment : Fragment(R.layout.fragment_to_read) {
SORT_ORDER_RATING_ASC -> viewModel.getSortedBooksByRatingAsc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_PAGES_DESC -> viewModel.getSortedBooksByPagesDesc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_PAGES_ASC -> viewModel.getSortedBooksByPagesAsc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_DATE_DESC -> viewModel.getSortedBooksByDateDesc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
SORT_ORDER_DATE_ASC -> viewModel.getSortedBooksByDateAsc(currentFragment).observe(viewLifecycleOwner, Observer { some_books -> bookAdapter.differ.submitList(some_books)})
}
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/values-pl-rPL/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@
<string name="btnAdderSaveFinishDate">Ustaw</string>
<string name="not_set">Nie ustawiono</string>
<string name="tvSortDate">Data</string>
<string name="setTitleOnUpdateAvailable">Aktualizacja!</string>
<string name="setContentOnUpdateAvailable">"Nowsza wersja aplikacji Books Tracker jest dostępna.\n\nKliknij \"aktualizuj\", żeby przejść na stronę pobierania."</string>
<string name="setButtonUpdate">Aktualizuj</string>
<string name="setButtonDismiss">Później</string>
<string name="setButtonDoNotShowAgain">Ignoruj</string>
<string name="setContentOnUpdateNotAvailable">Masz zainstalowaną najnowszą wersję aplikacji Books Tracker!</string>
<string name="setTitleOnUpdateNotAvailable">Brak dostępnych aktualizacji</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@
<string name="btnAdderSaveFinishDate">Ustaw</string>
<string name="not_set">Nie ustawiono</string>
<string name="tvSortDate">Data</string>
<string name="setTitleOnUpdateAvailable">Aktualizacja!</string>
<string name="setContentOnUpdateAvailable">"Nowsza wersja aplikacji Books Tracker jest dostępna.\n\nKliknij \"aktualizuj\", żeby przejść na stronę pobierania."</string>
<string name="setButtonUpdate">Aktualizuj</string>
<string name="setButtonDismiss">Później</string>
<string name="setButtonDoNotShowAgain">Ignoruj</string>
<string name="setContentOnUpdateNotAvailable">Masz zainstalowaną najnowszą wersję aplikacji Books Tracker!</string>
<string name="setTitleOnUpdateNotAvailable">Brak dostępnych aktualizacji</string>
</resources>
10 changes: 8 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
<string name="hintBookTitle" translatable="false">booktitle</string>
<string name="hintBookAuthor" translatable="false">bookauthor</string>
<string name="hintSearch" translatable="false">booksearch</string>

nomn <string name="app_version" translatable="false">v1.2.0</string>
<string name="app_version" translatable="false">v1.2.1</string>
<string name="notYetImplemented">Not yet implemented</string>
<string name="dismiss">Dismiss</string>
<string name="bookDeleted">Book deleted</string>
Expand Down Expand Up @@ -123,5 +122,12 @@ nomn <string name="app_version" translatable="false">v1.2.0</string>
<string name="tvSortDate">Date</string>
<string name="tvNumberOfPages" translatable="false">101 pages</string>
<string name="tvDateFinished" translatable="false">13 Jun 2021</string>
<string name="setTitleOnUpdateAvailable">New update!</string>
<string name="setContentOnUpdateAvailable">"Newer version of the Books Tracker app is available.\n\nClick \"update\" to go to the downloading page."</string>
<string name="setButtonUpdate">Update</string>
<string name="setButtonDismiss">Dismiss</string>
<string name="setButtonDoNotShowAgain">Ignore</string>
<string name="setContentOnUpdateNotAvailable">You\'ve got the latest version available of Books Tracker app!</string>
<string name="setTitleOnUpdateNotAvailable">No updates available</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
</Preference>

<Preference
android:key="KEY_CHECK_FOR_UPDATES"
android:title="@string/app_version_title"
android:summary="@string/app_version">
</Preference>
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ allprojects {
repositories {
google()
jcenter()
maven {
url "https://jitpack.io"
}
}
}

Expand Down

0 comments on commit 6bd09e9

Please sign in to comment.