Skip to content

Commit

Permalink
Merge pull request #21 from mateusz-bak/dev
Browse files Browse the repository at this point in the history
Version 1.7.1
  • Loading branch information
mateusz-bak authored Oct 25, 2021
2 parents 554d620 + 86891be commit a851bdf
Show file tree
Hide file tree
Showing 94 changed files with 3,451 additions and 4,831 deletions.
10 changes: 8 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 9
versionName "1.7.0"
versionCode 10
versionName "1.7.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -134,4 +134,10 @@ dependencies {

// https://stackoverflow.com/questions/44986626/android-room-database-how-to-handle-arraylist-in-an-entity
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1"

// https://github.com/zhanghai/MaterialRatingBar
implementation 'me.zhanghai.android.materialratingbar:library:1.4.0'

// https://www.section.io/engineering-education/bottom-sheet-dialogs-using-android-studio/
implementation 'com.google.android.material:material:1.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ class BookAdapter(
}
Constants.BOOK_STATUS_IN_PROGRESS -> {
rbRatingIndicator.visibility = View.GONE
tvNumberOfPages.visibility = View.GONE

tvDateStarted.visibility = View.GONE
tvDateStartedTitle.visibility = View.GONE

tvDateFinished.visibility = View.GONE
tvDateFinishedTitle.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class DeletedBookAdapter(
curBook.bookOLID,
curBook.bookISBN10,
curBook.bookISBN13,
curBook.bookPublishYear
curBook.bookPublishYear,
curBook.bookIsFav
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.BounceInterpolator
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_setup.view.*
import kotlinx.android.synthetic.main.layout_theme_selector.view.*
Expand Down Expand Up @@ -215,7 +216,7 @@ class SetupAdapter(
}

private fun selectBtn(holder: ViewPagerViewHolder, selectedBtn: View, position: Int) {
var scaleBig = 1.3F
var scaleBig = 1.1F
var scaleSmall = 0.9F
var listOfButtons = listOf(
holder.itemView.btn1,
Expand All @@ -235,8 +236,8 @@ class SetupAdapter(

for (btn in listOfButtons) {
if (btn == selectedBtn) {
btn.animate().scaleX(scaleBig).setDuration(250L).start()
btn.animate().scaleY(scaleBig).setDuration(250L).start()
btn.animate().scaleX(scaleBig).setDuration(500L).setInterpolator(BounceInterpolator()).start()
btn.animate().scaleY(scaleBig).setDuration(500L).setInterpolator(BounceInterpolator()).start()

btn.animate().alpha(1F).setDuration(100L).start()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package software.mdev.bookstracker.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.AsyncListDiffer
Expand All @@ -12,10 +13,8 @@ import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.formatter.DefaultValueFormatter
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter
import com.github.mikephil.charting.formatter.ValueFormatter
import com.github.mikephil.charting.utils.ColorTemplate
import kotlinx.android.synthetic.main.item_statistics.view.*
import kotlinx.coroutines.MainScope
Expand All @@ -39,7 +38,6 @@ import java.math.RoundingMode
import java.text.DecimalFormat
import java.util.*
import java.util.concurrent.TimeUnit
import com.github.mikephil.charting.utils.ViewPortHandler


class StatisticsAdapter(
Expand Down Expand Up @@ -169,7 +167,7 @@ class StatisticsAdapter(
tvLongestBook.text = curYear.yearLongestBook
}

if (curYear.yearShortestBook == "null"){
if (curYear.yearShortestBook == "null" || curYear.yearShortestBookVal == 0){
tvShortestBook.text = holder.itemView.resources.getString(R.string.need_more_data)
tvShortestBookValue.visibility = View.GONE
} else {
Expand Down Expand Up @@ -279,6 +277,13 @@ class StatisticsAdapter(

var data = BarData(barDataSet)
data.setValueFormatter(DefaultValueFormatter(0))

// color of values
data.setValueTextColor(itemView.resources.getColor(R.color.colorDefaultText))

// size of values
data.setValueTextSize(11F)

itemView.rbcBooksByMonth.data = data

//hide grid lines
Expand Down Expand Up @@ -310,6 +315,12 @@ class StatisticsAdapter(
//disable touch actions on graph
itemView.rbcBooksByMonth.setTouchEnabled(false)

// set x axis' text size
itemView.rbcBooksByMonth.xAxis.textSize = 11F

// the x labels are not cut
itemView.rbcBooksByMonth.extraBottomOffset = 8F

//draw chart
itemView.rbcBooksByMonth.invalidate()

Expand Down Expand Up @@ -367,6 +378,13 @@ class StatisticsAdapter(

var data = BarData(barDataSet)
data.setValueFormatter(DefaultValueFormatter(0))

// color of values
data.setValueTextColor(itemView.resources.getColor(R.color.colorDefaultText))

// size of values
data.setValueTextSize(11F)

itemView.rbcPagesByMonth.data = data

//hide grid lines
Expand Down Expand Up @@ -398,6 +416,12 @@ class StatisticsAdapter(
//disable touch actions on graph
itemView.rbcPagesByMonth.setTouchEnabled(false)

// set x axis' text size
itemView.rbcPagesByMonth.xAxis.textSize = 11F

// the x labels are not cut
itemView.rbcPagesByMonth.extraBottomOffset = 8F

//draw chart
itemView.rbcPagesByMonth.invalidate()

Expand Down Expand Up @@ -470,14 +494,20 @@ class StatisticsAdapter(

private fun callChallengeDialog(foundYear: Year?, it: View, challengeBooksRead: String) {
if (foundYear != null) {
ChallengeDialog(it.context,
val challengeDialog = ChallengeDialog(it.context,
foundYear,
object : ChallengeDialogListener {
override fun onSaveButtonClicked(year: Year) {
viewModel.upsertYear(year)
}
}
).show()
)
challengeDialog.show()

val width = (it.getResources().getDisplayMetrics().widthPixels * 0.80).toInt()

challengeDialog.getWindow()?.setLayout(width, WindowManager.LayoutParams.WRAP_CONTENT)

} else {
ChallengeDialog(it.context,
Year(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class YearsAdapter(

if (cbFilterYear.isChecked) {
cbFilterYear.isChecked = false
tvFilterYear.setTextColor(ContextCompat.getColor(context, R.color.grey))
tvFilterYear.setTextColor(ContextCompat.getColor(context, R.color.colorDefaultText))
tvFilterYear.setTypeface(null, Typeface.NORMAL)

if (curYear in currentArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface BooksDao {
@Delete
suspend fun delete(item: Book)

@Query("SELECT * FROM Book WHERE id LIKE :id")
fun getBook(id: Int?): LiveData<Book>

@Query("SELECT * FROM Book WHERE item_bookStatus LIKE 'read'")
fun getReadBooks(): LiveData<List<Book>>

Expand All @@ -38,7 +41,8 @@ interface BooksDao {
"item_bookOLID=:bookOLID, " +
"item_bookISBN10=:bookISBN10, " +
"item_bookISBN13=:bookISBN13, " +
"item_bookPublishYear=:bookPublishYear " +
"item_bookPublishYear=:bookPublishYear, " +
"item_bookIsFav=:bookIsFav " +
"WHERE id=:id")
suspend fun updateBook(id: Int?,
bookTitle: String,
Expand All @@ -56,7 +60,8 @@ interface BooksDao {
bookOLID: String,
bookISBN10: String,
bookISBN13: String,
bookPublishYear: Int
bookPublishYear: Int,
bookIsFav: Boolean
)

@Query("SELECT * FROM Book WHERE (item_bookTitle_ASCII LIKE '%' || :searchQuery || '%' OR item_bookAuthor_ASCII LIKE '%' || :searchQuery || '%' AND item_bookIsDeleted LIKE 0)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import software.mdev.bookstracker.other.Constants.DATABASE_FILE_NAME

@Database(
entities = [Book::class],
version = 7
version = 8
)
abstract class BooksDatabase: RoomDatabase() {

Expand All @@ -37,7 +37,8 @@ abstract class BooksDatabase: RoomDatabase() {
MIGRATION_3_4,
MIGRATION_4_5,
MIGRATION_5_6,
MIGRATION_6_7
MIGRATION_6_7,
MIGRATION_7_8
)
.build()

Expand All @@ -58,7 +59,8 @@ abstract class BooksDatabase: RoomDatabase() {
MIGRATION_3_4,
MIGRATION_4_5,
MIGRATION_5_6,
MIGRATION_6_7
MIGRATION_6_7,
MIGRATION_7_8
)
.build()
Companion.instance = instance
Expand Down Expand Up @@ -111,5 +113,11 @@ abstract class BooksDatabase: RoomDatabase() {
database.execSQL("ALTER TABLE Book ADD COLUMN item_bookPublishYear INTEGER NOT NULL DEFAULT 0")
}
}

private val MIGRATION_7_8 = object : Migration(7, 8) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE Book ADD COLUMN item_bookIsFav INTEGER NOT NULL DEFAULT 0")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,49 @@ data class Book (
var bookAuthor: String,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_RATING)
var bookRating: Float,
var bookRating: Float = 0F,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_STATUS)
var bookStatus: String,
var bookStatus: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_PRIORITY)
var bookPriority: String,
var bookPriority: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_START_DATE)
var bookStartDate: String,
var bookStartDate: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_FINISH_DATE)
var bookFinishDate: String,
var bookFinishDate: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_NUMBER_OF_PAGES)
var bookNumberOfPages: Int,
var bookNumberOfPages: Int = 0,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_TITLE_ASCII)
var bookTitle_ASCII: String,
var bookTitle_ASCII: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_AUTHOR_ASCII)
var bookAuthor_ASCII: String,
var bookAuthor_ASCII: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_IS_DELETED)
var bookIsDeleted: Boolean,
var bookIsDeleted: Boolean = false,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_COVER_URL)
var bookCoverUrl: String,
var bookCoverUrl: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_OLID)
var bookOLID: String,
var bookOLID: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_ISBN10)
var bookISBN10: String,
var bookISBN10: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_ISBN13)
var bookISBN13: String,
var bookISBN13: String = Constants.DATABASE_EMPTY_VALUE,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_PUBLISH_YEAR)
var bookPublishYear: Int
var bookPublishYear: Int = 0,

@ColumnInfo(name = Constants.DATABASE_ITEM_BOOK_IS_FAV)
var bookIsFav: Boolean = false,
): Serializable{
@PrimaryKey(autoGenerate = true)
var id: Int? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class BooksRepository (

suspend fun delete(item: Book) = db.getBooksDao().delete(item)

fun getBook(id: Int?) = db.getBooksDao().getBook(id)

fun getReadBooks() = db.getBooksDao().getReadBooks()

fun getInProgressBooks() = db.getBooksDao().getInProgressBooks()
Expand All @@ -33,7 +35,8 @@ class BooksRepository (
bookOLID: String,
bookISBN10: String,
bookISBN13: String,
bookPublishYear: Int
bookPublishYear: Int,
bookIsFav: Boolean,
) = db.getBooksDao().updateBook(
id,
bookTitle,
Expand All @@ -51,7 +54,8 @@ class BooksRepository (
bookOLID,
bookISBN10,
bookISBN13,
bookPublishYear
bookPublishYear,
bookIsFav
)

fun searchBooks(searchQuery: String) = db.getBooksDao().searchBooks(searchQuery)
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/software/mdev/bookstracker/other/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object Constants {
const val DATABASE_ITEM_BOOK_ISBN13 = "item_bookISBN13"
const val DATABASE_ITEM_BOOK_PUBLISH_YEAR = "item_bookPublishYear"
const val DATABASE_ITEM_BOOK_IS_DELETED = "item_bookIsDeleted"
const val DATABASE_ITEM_BOOK_IS_FAV = "item_bookIsFav"
const val DATABASE_EMPTY_VALUE = "none"

const val DATABASE_NAME_YEAR = "Year"
Expand Down Expand Up @@ -74,13 +75,11 @@ object Constants {
const val SORT_ORDER_FINISH_DATE_DESC = "ivSortFinishDateDesc"
const val SORT_ORDER_FINISH_DATE_ASC = "ivSortFinishDateAsc"

const val SERIALIZABLE_BUNDLE_BOOK = "book"
const val SERIALIZABLE_BUNDLE_ISBN = "isbn"

const val SHARED_PREFERENCES_KEY_FIRST_TIME_TOGGLE = "KEY_FIRST_TIME_TOGGLE"
const val SHARED_PREFERENCES_KEY_APP_VERSION = "SHARED_PREFERENCES_KEY_APP_VERSION"
const val SHARED_PREFERENCES_KEY_SORT_ORDER = "KEY_SORT_ORDER"
const val SHARED_PREFERENCES_KEY_FILTER_YEARS = "KEY_FILTER_YEARS"
const val SHARED_PREFERENCES_KEY_ONLY_FAV = "KEY_ONLY_FAV"
const val SHARED_PREFERENCES_KEY_ACCENT = "KEY_ACCENT"
const val SHARED_PREFERENCES_KEY_LANDING_PAGE = "KEY_LANDING_PAGE"
const val SHARED_PREFERENCES_KEY_TIME_TO_ASK_FOR_RATING = "KEY_TIME_TO_ASK_FOR_RATING"
Expand Down Expand Up @@ -127,4 +126,16 @@ object Constants {

const val MS_ONE_WEEK = 604800000L
const val MS_THREE_DAYS = 259200000L

// arguments between fragments
const val SERIALIZABLE_BUNDLE_BOOK = "book"
const val SERIALIZABLE_BUNDLE_ISBN = "isbn"
const val SERIALIZABLE_BUNDLE_ISBN_DEFAULT = "manual_search"
const val SERIALIZABLE_BUNDLE_BOOK_SOURCE = "bookSource"

// sources of book when passing to add/edit fragment
const val NO_SOURCE = 0
const val FROM_SEARCH = 1
const val FROM_SCAN = 2
const val FROM_DISPLAY = 3
}
Loading

0 comments on commit a851bdf

Please sign in to comment.