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

Fixes #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

## Installation

Downloadable form Google Apps to devicues running at least Android API level 29.
Downloadable form Google Apps to devices running at least Android API level 29.
>TBD

## User guide
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {

implementation "com.github.bumptech.glide:glide:4.11.0"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.6'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'

debugImplementation 'com.facebook.flipper:flipper:0.110.0'
debugImplementation 'com.facebook.soloader:soloader:0.10.1'
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
package="com.shuffleus.app">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
<application android:requestLegacyExternalStorage="true"
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
Expand All @@ -30,6 +31,14 @@
android:value=".settings.SettingsActivity"/>
</activity>

<activity
android:name=".schedule.ScheduleActivity"
android:parentActivityName=".main.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".schedule.ScheduleActivity"/>
</activity>

<receiver
android:name="com.shuffleus.app.utils.TimerExpiredReceiver"
android:enabled="true"
Expand Down
17 changes: 7 additions & 10 deletions app/src/main/java/com/shuffleus/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.shuffleus.app
import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.os.Build
import androidx.core.app.NotificationManagerCompat

class App: Application() {
Expand All @@ -14,16 +13,14 @@ class App: Application() {
}

private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
NOTIFICATION_CHANNEL_MAIN_ID,
NOTIFICATION_CHANNEL_MAIN_DESCRIPTION,
NotificationManager.IMPORTANCE_HIGH
).apply {
description = NOTIFICATION_CHANNEL_MAIN_DESCRIPTION
}
NotificationManagerCompat.from(this).createNotificationChannel(channel)
val channel = NotificationChannel(
NOTIFICATION_CHANNEL_MAIN_ID,
NOTIFICATION_CHANNEL_MAIN_DESCRIPTION,
NotificationManager.IMPORTANCE_HIGH
).apply {
description = NOTIFICATION_CHANNEL_MAIN_DESCRIPTION
}
NotificationManagerCompat.from(this).createNotificationChannel(channel)
}

companion object {
Expand Down
84 changes: 74 additions & 10 deletions app/src/main/java/com/shuffleus/app/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.shuffleus.app.AppSettings.Companion.APP_PREFERENCES
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map

Expand All @@ -18,32 +18,96 @@ class AppSettings(private val context: Context) {

companion object {
const val APP_PREFERENCES = "shuffleus_client"
private val KEY_APP_LAUNCH_COUNT = intPreferencesKey("app_launches")
private val KEY_GROUPNAMES_IDX = intPreferencesKey("groupnames")
private val KEY_OLD_GROUPNAMES_IDX = intPreferencesKey("old_groupnames")
private val KEY_GROUPSIZE = intPreferencesKey("groupsize")
private val KEY_OLD_GROUPSIZE = intPreferencesKey("old_groupsize")
private val KEY_SEED = intPreferencesKey("seed")
private val KEY_OLD_SEED = intPreferencesKey("old_seed")
private val KEY_TIMER_IDX = intPreferencesKey("timer_idx")
private val KEY_TIMER_LENGTH = intPreferencesKey("timer_length")
private val KEY_TIMER_PREVIOUS_LENGTH = longPreferencesKey("timer_previous_length")
private val KEY_TIMER_STATE = intPreferencesKey("timer_state")
private val KEY_SECONDS_REMAINING = longPreferencesKey("seconds_remaining")
private val KEY_ALARM_TIME = longPreferencesKey("alarm_time")
}


/**
* Read timer state
*/
suspend fun getAlarmSetTime(): Long = context.dataStore.data.map { preferences ->
preferences[KEY_ALARM_TIME] ?: 0
}.first()

/**
* Set timer state
*/
suspend fun setAlarmSetTime(value: Long) {
context.dataStore.edit { preferences ->
preferences[KEY_ALARM_TIME] = value
}
}
/**
* Read remaining seconds
*/
suspend fun getSecondsRemaining(): Long = context.dataStore.data.map { preferences ->
preferences[KEY_SECONDS_REMAINING] ?: 1
}.first()

/**
* Set remaining seconds
*/
suspend fun setSecondsRemaining(value: Long) {
context.dataStore.edit { preferences ->
preferences[KEY_SECONDS_REMAINING] = value
}
}
/**
* Read timer state
*/
suspend fun getTimerState(): Int = context.dataStore.data.map { preferences ->
preferences[KEY_TIMER_STATE] ?: 1
}.first()

/**
* Set timer state
*/
suspend fun setTimerState(value: Int) {
context.dataStore.edit { preferences ->
preferences[KEY_TIMER_STATE] = value
}
}

/**
* Read timer length
*/
suspend fun getTimerLength(): Int = context.dataStore.data.map { preferences ->
preferences[KEY_TIMER_LENGTH] ?: 1
}.first()

/**
* Set timer length
*/
suspend fun setTimerLength(value: Int) {
context.dataStore.edit { preferences ->
preferences[KEY_TIMER_LENGTH] = value
}
}

/**
* Get how many times the application was launched.
* Read timer previous length
*/
suspend fun getAppLaunchesCount() = context.dataStore.data.map { preferences ->
preferences[KEY_APP_LAUNCH_COUNT] ?: 0
suspend fun getPreviousTimerLengthSeconds(): Long = context.dataStore.data.map { preferences ->
preferences[KEY_TIMER_PREVIOUS_LENGTH] ?: 1
}.first()

/**
* Increase app launched counter.
* Set timer previous length
*/
suspend fun increaseAppLaunchesCount() {
suspend fun setPreviousTimerLengthSeconds(value: Long) {
context.dataStore.edit { preferences ->
val appLaunchCount = preferences[KEY_APP_LAUNCH_COUNT] ?: 0
preferences[KEY_APP_LAUNCH_COUNT] = appLaunchCount + 1
preferences[KEY_TIMER_PREVIOUS_LENGTH] = value
}
}

Expand Down Expand Up @@ -117,7 +181,7 @@ class AppSettings(private val context: Context) {
/**
* Get seed
*/
suspend fun getSeed() = context.dataStore.data.map { preferences ->
private suspend fun getSeed() = context.dataStore.data.map { preferences ->
preferences[KEY_SEED] ?: 1
}.first()

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/shuffleus/app/data/GroupNames.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.shuffleus.app.data

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/shuffleus/app/data/Lecture.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.shuffleus.app.data

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class Lecture(
var day : Int,
var startTime : Int,
var endTime : Int,
var subject : String,
var lecturer : String,
var lection : Boolean,
var room : String,
var code : String)
{
@PrimaryKey(autoGenerate = true)
var lectureId: Long = 0
}
1 change: 0 additions & 1 deletion app/src/main/java/com/shuffleus/app/data/User.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.shuffleus.app.data

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

Expand Down
8 changes: 0 additions & 8 deletions app/src/main/java/com/shuffleus/app/data/UserGroup.kt
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
package com.shuffleus.app.data

import androidx.room.Entity

@Entity(primaryKeys = ["groupId", "userId"])
data class UserGroups(
val groupId: Long,
val userId: Long)
6 changes: 6 additions & 0 deletions app/src/main/java/com/shuffleus/app/di/DatabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package com.shuffleus.app.di
import android.content.Context
import com.shuffleus.app.repository.room.AppDatabase
import com.shuffleus.app.repository.room.GroupNamesDao
import com.shuffleus.app.repository.room.LectureDao
import com.shuffleus.app.repository.room.UserDao

import dagger.Module
Expand All @@ -28,6 +29,11 @@ class DatabaseModule {
return appDatabase.userDao()
}

@Provides
fun provideLectureDao(appDatabase: AppDatabase): LectureDao {
return appDatabase.lectureDao()
}

@Provides
fun provideGroupNamesDao(appDatabase: AppDatabase): GroupNamesDao {
return appDatabase.groupNamesDao()
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/java/com/shuffleus/app/main/GroupsAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package com.shuffleus.app.main
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.shuffleus.app.R
import com.shuffleus.app.data.RailsItem
import com.shuffleus.app.utils.inflate

class GroupsAdapter() : RecyclerView.Adapter<BaseRailsViewHolder<RailsItem>>(){
class GroupsAdapter : RecyclerView.Adapter<BaseRailsViewHolder<RailsItem>>(){

var groups:List<RailsItem> = emptyList()
set(value) {
Expand Down Expand Up @@ -43,13 +42,11 @@ class RailsGroupNameViewHolder(view: View) :BaseRailsViewHolder<RailsItem.RailsG
}
}

class RailsPeopleViewHolder(view: View) :BaseRailsViewHolder<RailsItem.RailsPeople>(view){
private val view = view

class RailsPeopleViewHolder(private val view: View) :BaseRailsViewHolder<RailsItem.RailsPeople>(view){
private val rvPeople by lazy { view.findViewById<RecyclerView>(R.id.rv_group)}

override fun bind(item: RailsItem.RailsPeople) {
var adapter = UsersAdapter()
val adapter = UsersAdapter()

rvPeople.adapter = adapter
rvPeople.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false)
Expand Down
Loading