Skip to content

Commit

Permalink
Merge pull request #2 from therxmv/dev
Browse files Browse the repository at this point in the history
[V.1.1.1] Fixed crash on the AuthScreen, fixed auto-deleting the cache and other improvements
  • Loading branch information
therxmv authored Jul 30, 2023
2 parents aac82c0 + d5d0a16 commit 3bfc3b2
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 207 deletions.
1 change: 1 addition & 0 deletions .idea/.gitignore

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

8 changes: 4 additions & 4 deletions .idea/deploymentTargetDropDown.xml

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

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

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 "com.therxmv.dirolreader"
minSdk 23
targetSdk 33
versionCode 110
versionName "1.1"
versionCode 111
versionName "1.1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -72,6 +72,9 @@ android {
dependencies {
implementation project(path: ':libtd')

// Gson
implementation 'com.google.code.gson:gson:2.10.1'

// Firebase
implementation platform("com.google.firebase:firebase-bom:32.2.0")
implementation("com.google.firebase:firebase-crashlytics-ktx")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.therxmv.dirolreader

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ class AppSharedPrefsRepository(
set(value) {
appSharedPrefsDataSource.isAutoDeleteEnabled = value
}

var channelsRating: MutableMap<Long, Int>
get() {
return appSharedPrefsDataSource.channelsRating
}
set(value) {
appSharedPrefsDataSource.channelsRating = value
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.therxmv.dirolreader.data.repository

import com.therxmv.dirolreader.data.source.locale.ChannelLocaleDataSource
import com.therxmv.dirolreader.data.entity.toDomain
import com.therxmv.dirolreader.data.source.locale.ChannelLocaleDataSource
import com.therxmv.dirolreader.data.source.remote.ChannelRemoteDataSource
import com.therxmv.dirolreader.domain.models.ChannelModel
import com.therxmv.dirolreader.domain.models.toEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.therxmv.dirolreader.data.repository

import android.util.Log
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
Expand All @@ -12,9 +11,7 @@ import com.therxmv.dirolreader.domain.models.MessageModel
import com.therxmv.dirolreader.domain.paging.MessagesPagingSource
import com.therxmv.dirolreader.domain.repository.MessageRepository
import com.therxmv.dirolreader.utils.PAGE_SIZE
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import org.drinkless.td.libcore.telegram.Client

class MessageRepositoryImpl(
Expand All @@ -24,6 +21,7 @@ class MessageRepositoryImpl(
override fun getMessagePaging(client: Client?): Flow<PagingData<MessageModel>> {
return Pager(
config = PagingConfig(
initialLoadSize = PAGE_SIZE,
pageSize = PAGE_SIZE,
enablePlaceholders = false,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ package com.therxmv.dirolreader.data.repository

import com.therxmv.dirolreader.data.source.remote.UserRemoteDataSource
import com.therxmv.dirolreader.domain.repository.UserRepository
import com.therxmv.dirolreader.ui.news.utils.ToolbarState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.drinkless.td.libcore.telegram.Client
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.td.libcore.telegram.TdApi.User
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

class UserRepositoryImpl(
private val userRemoteDataSource: UserRemoteDataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.therxmv.dirolreader.data.source.locale

import android.content.Context
import androidx.core.content.edit
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.therxmv.dirolreader.utils.SHARED_PREFS
import com.therxmv.dirolreader.utils.SHARED_PREFS_CHANNELS_RATING
import com.therxmv.dirolreader.utils.SHARED_PREFS_IS_AUTO_DELETE_ENABLED
import com.therxmv.dirolreader.utils.SHARED_PREFS_IS_DYNAMIC

Expand All @@ -16,9 +19,8 @@ class AppSharedPrefsDataSource(
return sharedPrefs.getBoolean(SHARED_PREFS_IS_DYNAMIC, false)
}
set(value) {
sharedPrefs.edit {
sharedPrefs.edit(true) {
putBoolean(SHARED_PREFS_IS_DYNAMIC, value)
apply()
}
}

Expand All @@ -27,9 +29,26 @@ class AppSharedPrefsDataSource(
return sharedPrefs.getBoolean(SHARED_PREFS_IS_AUTO_DELETE_ENABLED, false)
}
set(value) {
sharedPrefs.edit {
sharedPrefs.edit(true) {
putBoolean(SHARED_PREFS_IS_AUTO_DELETE_ENABLED, value)
apply()
}
}

var channelsRating: MutableMap<Long, Int>
get() {
val str = sharedPrefs.getString(SHARED_PREFS_CHANNELS_RATING, "")

if(str.isNullOrEmpty()) return mutableMapOf()

val type = object : TypeToken<Map<Long, Int>>() {}.type

return Gson().fromJson(str, type)
}
set(value) {
sharedPrefs.edit(true) {
val str = if(value.isEmpty()) "" else Gson().toJson(value)

putString(SHARED_PREFS_CHANNELS_RATING, str)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ package com.therxmv.dirolreader.data.source.remote
import com.therxmv.dirolreader.domain.models.ChannelModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.withContext
import org.drinkless.td.libcore.telegram.Client
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.td.libcore.telegram.TdApi.ChatListFilter
import org.drinkless.td.libcore.telegram.TdApi.ChatListMain
import org.drinkless.td.libcore.telegram.TdApi.Chats
import org.drinkless.td.libcore.telegram.TdApi.GetChat
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/therxmv/dirolreader/di/DomainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import com.therxmv.dirolreader.domain.repository.ClientRepository
import com.therxmv.dirolreader.domain.repository.MessageRepository
import com.therxmv.dirolreader.domain.repository.UserRepository
import com.therxmv.dirolreader.domain.usecase.AuthViewModelUseCases
import com.therxmv.dirolreader.domain.usecase.client.CreateClientUseCase
import com.therxmv.dirolreader.domain.usecase.client.GetClientUseCase
import com.therxmv.dirolreader.domain.usecase.user.GetCurrentUserAvatarUseCase
import com.therxmv.dirolreader.domain.usecase.user.GetCurrentUserUseCase
import com.therxmv.dirolreader.domain.usecase.GetTdLibParametersUseCase
import com.therxmv.dirolreader.domain.usecase.NewsViewModelUseCases
import com.therxmv.dirolreader.domain.usecase.ProfileViewModelUseCase
import com.therxmv.dirolreader.domain.usecase.channel.AddChannelToLocaleUseCase
import com.therxmv.dirolreader.domain.usecase.channel.GetLocaleChannelsUseCase
import com.therxmv.dirolreader.domain.usecase.channel.GetRemoteChannelsIdsUseCase
import com.therxmv.dirolreader.domain.usecase.channel.UpdateChannelRatingUseCase
import com.therxmv.dirolreader.domain.usecase.message.GetMessagePagingUseCase
import com.therxmv.dirolreader.domain.usecase.client.CreateClientUseCase
import com.therxmv.dirolreader.domain.usecase.client.GetClientUseCase
import com.therxmv.dirolreader.domain.usecase.message.GetMessageMediaUseCase
import com.therxmv.dirolreader.domain.usecase.message.GetMessagePagingUseCase
import com.therxmv.dirolreader.domain.usecase.user.GetCurrentUserAvatarUseCase
import com.therxmv.dirolreader.domain.usecase.user.GetCurrentUserUseCase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.therxmv.dirolreader.domain.paging

import android.util.Log
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.therxmv.dirolreader.domain.models.MessageModel
Expand Down Expand Up @@ -74,6 +73,16 @@ class MessagesPagingSource(
}
}

return temp
return filterDuplicates(temp)
}

private fun filterDuplicates(list: List<MessageModel>): List<MessageModel> {
val uniqueList = LinkedHashMap<Long, MessageModel>()

for (item in list) {
uniqueList[item.id] = item
}

return uniqueList.values.toList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.therxmv.dirolreader.domain.usecase.channel.AddChannelToLocaleUseCase
import com.therxmv.dirolreader.domain.usecase.channel.GetRemoteChannelsIdsUseCase
import com.therxmv.dirolreader.domain.usecase.channel.UpdateChannelRatingUseCase
import com.therxmv.dirolreader.domain.usecase.client.GetClientUseCase
import com.therxmv.dirolreader.domain.usecase.message.GetMessagePagingUseCase
import com.therxmv.dirolreader.domain.usecase.message.GetMessageMediaUseCase
import com.therxmv.dirolreader.domain.usecase.message.GetMessagePagingUseCase
import com.therxmv.dirolreader.domain.usecase.user.GetCurrentUserAvatarUseCase
import com.therxmv.dirolreader.domain.usecase.user.GetCurrentUserUseCase

Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/therxmv/dirolreader/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.therxmv.dirolreader.ui

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import com.therxmv.dirolreader.data.repository.AppSharedPrefsRepository
import com.therxmv.dirolreader.ui.navigation.DirolNavHost
import com.therxmv.dirolreader.ui.theme.AppTheme
import com.therxmv.dirolreader.utils.FILES_PATH
import dagger.hilt.android.AndroidEntryPoint
import java.io.File
import javax.inject.Inject

@AndroidEntryPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -42,9 +42,9 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import com.therxmv.dirolreader.R
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.therxmv.dirolreader.R
import com.therxmv.dirolreader.ui.auth.utils.AuthState
import com.therxmv.dirolreader.ui.auth.utils.AuthUiEvent

Expand Down
32 changes: 27 additions & 5 deletions app/src/main/java/com/therxmv/dirolreader/ui/auth/AuthViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ package com.therxmv.dirolreader.ui.auth

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.therxmv.dirolreader.data.repository.AppSharedPrefsRepository
import com.therxmv.dirolreader.domain.usecase.AuthViewModelUseCases
import com.therxmv.dirolreader.ui.auth.utils.AuthState
import com.therxmv.dirolreader.ui.auth.utils.AuthUiEvent
import com.therxmv.dirolreader.ui.auth.utils.AuthUiState
import com.therxmv.dirolreader.utils.FILES_PATH
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.stateIn
import org.drinkless.td.libcore.telegram.Client
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.td.libcore.telegram.TdApi.AuthorizationState
import java.io.File
import javax.inject.Inject

@HiltViewModel
class AuthViewModel @Inject constructor(
private val useCases: AuthViewModelUseCases
private val useCases: AuthViewModelUseCases,
private val appSharedPrefsRepository: AppSharedPrefsRepository
): ViewModel() {
private val _state = MutableStateFlow(AuthUiState())
val state = _state.asStateFlow()
Expand All @@ -31,6 +31,28 @@ class AuthViewModel @Inject constructor(
createClient()
}

override fun onCleared() {
super.onCleared()
Log.d("rozmi", "cleared")
if(appSharedPrefsRepository.isAutoDeleteEnabled) {
clearCache()
}
}

private fun clearCache() {
if(appSharedPrefsRepository.isAutoDeleteEnabled) {
File(FILES_PATH).listFiles()?.forEach {
if(it.isDirectory) {
it.listFiles()?.forEach { elem ->
if(!elem.path.contains(".nomedia")) {
elem.delete()
}
}
}
}
}
}

private fun createClient() {
client = useCases.createClientUseCase(ClientUpdateHandler())
getAuthorizationState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.therxmv.dirolreader.ui.navigation

import android.util.Log
import androidx.compose.runtime.Composable
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/therxmv/dirolreader/ui/news/NewsPost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.therxmv.dirolreader.ui.news

import android.graphics.BitmapFactory
import android.text.format.DateUtils
import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand All @@ -13,7 +12,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down
Loading

0 comments on commit 3bfc3b2

Please sign in to comment.