Skip to content

Commit

Permalink
Gsoc 2023 profile screen migration compose (#29)
Browse files Browse the repository at this point in the history
* Update for some issue In Deploy to Appetize

* removed Github Token from ci file

* Migrated fragment_login.xml to LoginScreen.kt Compose and Updated
facebook Sdk version to latest and added code changes according to new
methods in doc and updated gitlab-ci.yml for fbClientSecret

* Migrated fragment_home.xml to HomeScreen.kt in compose

* Migrated fragment_settings.xml to SettingScreen.kt in Compose

* Migrated fragment_profile.xml to ProfileScreen.kt in compose
  • Loading branch information
narendraanjana09 authored Aug 30, 2023
1 parent 42e58ca commit 7402bb9
Show file tree
Hide file tree
Showing 41 changed files with 1,849 additions and 2,198 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ dependencies {
debugImplementation 'androidx.compose.ui:ui-test-manifest'
implementation "androidx.activity:activity-compose:$rootProject.composeActivityVersion"
implementation "com.google.accompanist:accompanist-systemuicontroller:$rootProject.accompanist_version"
implementation "com.google.accompanist:accompanist-permissions:$rootProject.accompanist_version"

//Coil
implementation("io.coil-kt:coil-compose:$rootProject.coilVersion")
Expand All @@ -217,4 +218,7 @@ dependencies {

//for live data to state
implementation("androidx.compose.runtime:runtime-livedata:$rootProject.composeLiveData")

//for language change
implementation "com.github.YarikSOffice:lingver:$rootProject.languageLibrary"
}
7 changes: 2 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-feature
android:name="android.hardware.camera"
android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera.any"/>

<application
android:name=".AgoraApp"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/aossie/agoraandroid/AgoraApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package org.aossie.agoraandroid

import android.app.Application
import android.util.Log
import com.yariksoffice.lingver.Lingver
import org.aossie.agoraandroid.ui.di.AppComponent
import org.aossie.agoraandroid.ui.di.DaggerAppComponent
import org.aossie.agoraandroid.utilities.AppConstants
import timber.log.Timber
import timber.log.Timber.DebugTree
import timber.log.Timber.Tree
Expand Down Expand Up @@ -33,6 +35,7 @@ class AgoraApp : Application() {
override fun onCreate() {
super.onCreate()
Timber.plant(if (BuildConfig.DEBUG) DebugTree() else CrashReportingTree())
Lingver.init(this,AppConstants.DEFAULT_LANG)
}

private class CrashReportingTree : Tree() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ constructor(
private val REFRESH_TOKEN = stringPreferencesKey("refreshToken")
private val FACEBOOK_ACCESS_TOKEN = stringPreferencesKey("facebookAccessToken")
private val ENABLE_BIOMETRIC = booleanPreferencesKey("isBiometricEnabled")
private val APP_LANGUAGE = stringPreferencesKey("appLanguage")
}

private val userDataStore = context.userDataStore
Expand Down Expand Up @@ -166,4 +167,21 @@ constructor(
it.clear()
}
}

suspend fun updateAppLanguage(lang: String) {
userDataStore.edit {
it[APP_LANGUAGE] = lang?.let { _lang ->
securityUtil.encryptToken(_lang)
} ?: ""
}
}

fun getAppLanguage(): Flow<String> {
return userDataStore.data.map {
val language = it[APP_LANGUAGE]?.let { _lang ->
securityUtil.decryptToken(_lang)
}
language ?: "en"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.aossie.agoraandroid.ui.di.models

import android.content.Context

data class AppContext(
val context: Context
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import org.aossie.agoraandroid.domain.useCases.profile.GetUserDataUseCase
import org.aossie.agoraandroid.domain.useCases.profile.ProfileUseCases
import org.aossie.agoraandroid.domain.useCases.profile.ToggleTwoFactorAuthUseCase
import org.aossie.agoraandroid.domain.useCases.profile.UpdateUserUseCase
import org.aossie.agoraandroid.ui.di.models.AppContext
import org.aossie.agoraandroid.utilities.AppConstants
import org.aossie.agoraandroid.utilities.InternetManager
import org.aossie.agoraandroid.utilities.SecurityUtil
Expand Down Expand Up @@ -501,4 +502,10 @@ class AppModule {
): CastVoteActivityUseCases {
return CastVoteActivityUseCases(castVoteUseCase, verifyVotersUseCase)
}

@Singleton
@Provides
fun provideAppContext(context: Context): AppContext {
return AppContext(context)
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package org.aossie.agoraandroid.ui.fragments.home

import android.content.Context
import android.content.Intent
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.yariksoffice.lingver.Lingver
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import org.aossie.agoraandroid.data.db.PreferenceProvider
import org.aossie.agoraandroid.domain.useCases.homeFragment.HomeFragmentUseCases
import org.aossie.agoraandroid.ui.fragments.auth.SessionExpiredListener
import org.aossie.agoraandroid.ui.screens.common.Util.ScreensState
import org.aossie.agoraandroid.utilities.ApiException
import org.aossie.agoraandroid.utilities.AppConstants
import org.aossie.agoraandroid.utilities.LocaleUtil
import org.aossie.agoraandroid.utilities.NoInternetException
import org.aossie.agoraandroid.utilities.ResponseUI
import org.aossie.agoraandroid.utilities.SessionExpirationException
import java.text.SimpleDateFormat
import java.util.Calendar
Expand All @@ -30,10 +36,9 @@ const val ACTIVE_ELECTION_COUNT = "activeElectionsCount"

class HomeViewModel @Inject
constructor(
private val homeViewModelUseCases: HomeFragmentUseCases
private val homeViewModelUseCases: HomeFragmentUseCases,
private val prefs: PreferenceProvider
) : ViewModel() {
private val _getLogoutStateFLow: MutableStateFlow<ResponseUI<Any>?> = MutableStateFlow(null)
val getLogoutStateFlow: StateFlow<ResponseUI<Any>?> = _getLogoutStateFLow
var sessionExpiredListener: SessionExpiredListener? = null
private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH)
private val currentDate: Date = Calendar.getInstance()
Expand All @@ -46,6 +51,15 @@ constructor(
private val _countMediatorLiveData = MediatorLiveData<MutableMap<String, Int>>()
val countMediatorLiveData = _countMediatorLiveData

private val _progressAndErrorState = MutableStateFlow (ScreensState())
val progressAndErrorState = _progressAndErrorState.asStateFlow()

private val _uiEvents = MutableSharedFlow<UiEvents>()
val uiEvents = _uiEvents.asSharedFlow()

val appLanguage = prefs.getAppLanguage()
val getSupportedLanguages = LocaleUtil.getSupportedLanguages()

init {
_countMediatorLiveData.value = mutableMapOf(
TOTAL_ELECTION_COUNT to 0,
Expand Down Expand Up @@ -108,23 +122,44 @@ constructor(
}

fun doLogout() {
_getLogoutStateFLow.value = ResponseUI.loading()
showLoading("Logging you out...")
viewModelScope.launch {
try {
homeViewModelUseCases.logOut()
_getLogoutStateFLow.value = ResponseUI.success()
hideSnackBar()
hideLoading()
_uiEvents.emit(UiEvents.UserLoggedOut)
} catch (e: ApiException) {
_getLogoutStateFLow.value = ResponseUI.error(e.message)
showMessage(e.message!!)
} catch (e: SessionExpirationException) {
sessionExpiredListener?.onSessionExpired()
} catch (e: NoInternetException) {
_getLogoutStateFLow.value = ResponseUI.error(e.message)
showMessage(e.message!!)
} catch (e: Exception) {
_getLogoutStateFLow.value = ResponseUI.error(e.message)
showMessage(e.message!!)
}
}
}

fun changeLanguage(newLanguage: Pair<String, String>, context: Context) {
viewModelScope.launch {
prefs.updateAppLanguage(newLanguage.second)
Lingver.getInstance().setLocale(context, newLanguage.second)
delay(500)
restartApp(context)
}
}

private fun restartApp(context: Context) {
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}

sealed class UiEvents{
object UserLoggedOut:UiEvents()
}

private fun showLoading(message: Any) {
_progressAndErrorState.value = progressAndErrorState.value.copy(
loading = Pair(message,true)
Expand Down
Loading

0 comments on commit 7402bb9

Please sign in to comment.