Skip to content

Commit

Permalink
Merge pull request #116 from mubeen1519/work
Browse files Browse the repository at this point in the history
Fix crashes and add new features
  • Loading branch information
CrazyMarvin authored Oct 4, 2024
2 parents 77ec63c + 90bb5de commit be483fb
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 181 deletions.
2 changes: 2 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ dependencies {
implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
implementation ("androidx.glance:glance-appwidget:1.0.0")
implementation ("androidx.glance:glance-material3:1.0.0")
implementation ("androidx.lifecycle:lifecycle-livedata-ktx:2.8.6")

}

kapt{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.collectAsState
import androidx.core.os.LocaleListCompat
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint
import rocks.poopjournal.fucksgiven.presentation.navigation.NavGraph
Expand All @@ -30,16 +32,6 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
if (SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val localeManager = applicationContext
.getSystemService(LocaleManager::class.java)
localeManager.overrideLocaleConfig = LocaleConfig(
LocaleList.forLanguageTags("en-US,de,ur,fr")
)

val overrideLocaleConfig = localeManager.overrideLocaleConfig
val supportedLocales = overrideLocaleConfig?.supportedLocales
}
val theme = themeSetting.themeFlow.collectAsState()
val useDarkColors = when (theme.value) {
AppTheme.LIGHT -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package rocks.poopjournal.fucksgiven.data

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import kotlinx.coroutines.flow.Flow
import rocks.poopjournal.fucksgiven.presentation.ui.utils.THETABLE_TABLENAME

Expand All @@ -19,6 +21,12 @@ interface FuckDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(data: FuckData)

@Update
suspend fun update(data: FuckData)

@Delete
suspend fun delete(data: FuckData)

@Query("SELECT * FROM $THETABLE_TABLENAME WHERE date BETWEEN :startDate AND :endDate")
fun getDataBetweenDates(startDate: Long, endDate: Long): LiveData<List<FuckData>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rocks.poopjournal.fucksgiven.data

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.map
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.conflate
Expand All @@ -15,6 +16,8 @@ class FuckRepository @Inject constructor(
fun getAllFucks() : Flow<List<FuckData>> = fuckDao.getAllData().flowOn(Dispatchers.IO).conflate()
fun getFuck(id: Int) : Flow<FuckData> = fuckDao.getData(id).flowOn(Dispatchers.IO).conflate()
suspend fun insertFuck(fuckData: FuckData) = fuckDao.insert(fuckData)
suspend fun updateFuck(fuckData: FuckData) = fuckDao.update(fuckData)
suspend fun deleteFuck(fuckData: FuckData) = fuckDao.delete(fuckData)

fun getWeeklyData(): LiveData<List<FuckData>> {
val calendar = Calendar.getInstance().apply {
Expand All @@ -29,7 +32,9 @@ class FuckRepository @Inject constructor(
calendar.add(Calendar.DAY_OF_WEEK, 7)
val endOfWeek = calendar.timeInMillis

return fuckDao.getDataBetweenDates(startOfWeek, endOfWeek)
return fuckDao.getDataBetweenDates(startOfWeek, endOfWeek).map {
it ?: emptyList() // Convert null to empty list
}
}

fun getMonthlyData(): LiveData<List<FuckData>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package rocks.poopjournal.fucksgiven.presentation.component

import android.content.res.Configuration
import android.graphics.Typeface
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.res.ResourcesCompat
import androidx.core.text.layoutDirection
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.data.Entry
Expand All @@ -30,7 +23,6 @@ import rocks.poopjournal.fucksgiven.R
import rocks.poopjournal.fucksgiven.presentation.ui.theme.FuckGreen
import rocks.poopjournal.fucksgiven.presentation.ui.utils.AppTheme
import rocks.poopjournal.fucksgiven.presentation.ui.utils.ThemeSetting
import java.util.Locale

@Composable
fun LineChartComposable(
Expand Down Expand Up @@ -171,8 +163,8 @@ fun LineChartComposable(
chart.axisRight.isGranularityEnabled = true
chart.notifyDataSetChanged()
chart.fitScreen()
chart.viewPortHandler.setMaximumScaleX(2f);
chart.viewPortHandler.setMaximumScaleY(2f);
chart.viewPortHandler.setMaximumScaleX(2f)
chart.viewPortHandler.setMaximumScaleY(2f)
chart.isDoubleTapToZoomEnabled = false
chart.invalidate() // Refresh the chart
}
Expand Down
Loading

0 comments on commit be483fb

Please sign in to comment.