Skip to content

Commit

Permalink
Merge branch 'gsoc-2023' into gsoc_2023_migrating_cast_vote_activity_…
Browse files Browse the repository at this point in the history
…to_jetpack_compose
  • Loading branch information
narendraanjana09 authored Aug 30, 2023
2 parents bf5490c + 7a21f26 commit a095b39
Show file tree
Hide file tree
Showing 114 changed files with 4,576 additions and 4,986 deletions.
12 changes: 1 addition & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,21 @@ before_script:
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- apt-get --quiet install curl --yes
- export ANDROID_HOME="${PWD}/android-home"
# Create a new directory at specified location
- install -d $ANDROID_HOME
# Here we are installing androidSDK tools from official source,
# (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well)
# after that unzipping those tools and
# then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build
- wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
# move to the archive at ANDROID_HOME
- pushd $ANDROID_HOME
- unzip -d cmdline-tools cmdline-tools.zip
- pushd cmdline-tools
# since commandline tools version 7583922 the root folder is named "cmdline-tools" so we rename it if necessary
- mv cmdline-tools tools || true
- popd
- popd
- export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
# Nothing fancy here, just checking sdkManager version
- sdkmanager --version
# use yes to accept all licenses
- yes | sdkmanager --licenses || true
- sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}"
- sdkmanager "platform-tools"
- sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}"
- touch local.properties && echo -e "fbApiKey=$FB_API_KEY\nfbApiScheme=$FB_API_SCHEME\nsecretKey=$SECRET_KEY\nserverKey=$SERVER_KEY" > local.properties
- touch local.properties && echo -e "fbApiKey=$FB_API_KEY\nfbClientSecret=$FB_CLIENT_SECRET\nfbApiScheme=$FB_API_SCHEME\nsecretKey=$SECRET_KEY\nserverKey=$SERVER_KEY" > local.properties
- touch app/google-services.json && echo $FIREBASE_JSON > app/google-services.json
- touch signing.properties && echo -e "storeFile=keystore.jks\nstorePassword=$KEYSTORE_PASSWORD\nkeyAlias=$KEY_ALIAS\nkeyPassword=$KEY_PASSWORD" > signing.properties
- touch app/keystore.jks && echo $KEYSTORE | base64 --decode > app/keystore.jks
Expand All @@ -49,7 +40,6 @@ before_script:
- apt-get --quiet install ruby ruby-dev build-essential dh-autoreconf --yes
- gem install bundler:1.17.2
- bundle install
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- set -o pipefail

Expand Down
11 changes: 9 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def fbApiScheme = properties.getProperty('fbApiScheme')
def fbApiKey = properties.getProperty('fbApiKey')
def fbClientSecret = properties.getProperty('fbClientSecret')
def secretKey = properties.getProperty('secretKey')
def serverKey = properties.getProperty('serverKey')

Expand All @@ -30,6 +31,7 @@ android {
compileSdkVersion rootProject.ext.compileSdk
defaultConfig {
resValue("string", "fbApiKey", fbApiKey)
resValue("string", "fbClientSecret", fbClientSecret)
resValue("string", "fbApiScheme", fbApiScheme)
resValue("string", "secretKey", secretKey)
resValue("string", "serverKey", serverKey)
Expand Down Expand Up @@ -104,7 +106,6 @@ dependencies {
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test:runner:$testRunnerVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleRuntime"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleExtensions"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
Expand All @@ -121,7 +122,6 @@ dependencies {
//Shimmer
implementation "com.facebook.shimmer:shimmer:$facebookShimmerVersion"
//Facebook Login
implementation "com.facebook.android:facebook-login:$facebookLoginVersion"
implementation "com.facebook.android:facebook-android-sdk:$facebookAndroidSDK"
//Pie Chart
implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
Expand Down Expand Up @@ -208,10 +208,17 @@ 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")

//extended Material Icons
implementation "androidx.compose.material:material-icons-extended:1.4.3"

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

//for language change
implementation "com.github.YarikSOffice:lingver:$rootProject.languageLibrary"
}
12 changes: 5 additions & 7 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 Expand Up @@ -67,10 +64,8 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="@string/fbApiScheme"
tools:ignore="AppLinkUrlError" />
Expand All @@ -80,6 +75,9 @@
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/fbApiKey" />
<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="@string/fbClientSecret" />
<service
android:name=".FcmService"
android:exported="false">
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 @@ -16,6 +16,7 @@ import org.aossie.agoraandroid.data.network.dto.ElectionDto
import org.aossie.agoraandroid.data.network.dto.VotersDto
import org.aossie.agoraandroid.data.network.dto.WinnerDto
import org.aossie.agoraandroid.data.network.responses.Ballots
import org.aossie.agoraandroid.data.network.responses.ElectionListResponse
import org.aossie.agoraandroid.data.network.responses.ElectionResponse
import org.aossie.agoraandroid.domain.repository.ElectionsRepository
import org.aossie.agoraandroid.utilities.ApiException
Expand Down Expand Up @@ -107,7 +108,7 @@ constructor(
db.getElectionDao()
.getPendingElections(currentDate)

override suspend fun fetchElections() {
override suspend fun fetchElections(): ElectionListResponse {
val isNeeded = prefs.getUpdateNeeded().first()
if (isNeeded) {
try {
Expand All @@ -117,12 +118,14 @@ constructor(
elections.postValue(it)
}
Timber.d(response.toString())
return response
} catch (e: NoInternetException) {
} catch (e: ApiException) {
} catch (e: SessionExpirationException) {
} catch (e: IOException) {
}
}
return ElectionListResponse(elections.value!!)
}

override fun getFinishedElections(currentDate: String): Flow<List<Election>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class UserRepositoryImpl(
.deleteAllElections()
}

override suspend fun sendForgotPasswordLink(username: String?): String {
override suspend fun sendForgotPasswordLink(username: String?): List<String> {
return apiRequest { api.sendForgotPassword(username) }
}

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
Expand Up @@ -39,7 +39,7 @@ interface Api {
suspend fun resendOTP(@Path("userName") userName: String?): Response<AuthResponse>

@POST("auth/forgotPassword/send/{userName}")
suspend fun sendForgotPassword(@Path("userName") userName: String?): Response<String>
suspend fun sendForgotPassword(@Path("userName") userName: String?): Response<List<String>>

@GET("election")
suspend fun getAllElections(): Response<ElectionListResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import org.aossie.agoraandroid.data.network.dto.ElectionDto
import org.aossie.agoraandroid.data.network.dto.VotersDto
import org.aossie.agoraandroid.data.network.dto.WinnerDto
import org.aossie.agoraandroid.data.network.responses.Ballots
import org.aossie.agoraandroid.data.network.responses.ElectionListResponse
import org.aossie.agoraandroid.data.network.responses.ElectionResponse

interface ElectionsRepository {
suspend fun fetchAndSaveElections()
suspend fun fetchAndSaveElections(): ElectionListResponse
fun getElections(): Flow<List<Election>>
fun getFinishedElectionsCount(currentDate: String): LiveData<Int>
fun getPendingElectionsCount(currentDate: String): LiveData<Int>
fun getTotalElectionsCount(): LiveData<Int>
fun getActiveElectionsCount(currentDate: String): LiveData<Int>
suspend fun saveElections(elections: List<ElectionResponse>)
fun getPendingElections(currentDate: String): Flow<List<Election>>
suspend fun fetchElections()
suspend fun fetchElections(): ElectionListResponse
fun getFinishedElections(currentDate: String): Flow<List<Election>>
fun getActiveElections(currentDate: String): Flow<List<Election>>
fun getElectionById(id: String): Flow<Election>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface UserRepository {
suspend fun logout()
fun getUser(): Flow<User>
suspend fun deleteUser()
suspend fun sendForgotPasswordLink(username: String?): String
suspend fun sendForgotPasswordLink(username: String?): List<String>
suspend fun updateUser(updateUserData: UpdateUserDto): List<String>
suspend fun changeAvatar(url: String): List<String>
suspend fun changePassword(password: String): List<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SendForgotPasswordLinkUseCase @Inject constructor(
) {
suspend operator fun invoke(
username: String?
): String {
): List<String> {
return repository.sendForgotPasswordLink(username)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.aossie.agoraandroid.domain.useCases.homeFragment

import org.aossie.agoraandroid.data.network.responses.ElectionListResponse
import org.aossie.agoraandroid.domain.repository.ElectionsRepository
import javax.inject.Inject

class FetchAndSaveElectionUseCase @Inject constructor(
private val electionsRepository: ElectionsRepository
) {
suspend operator fun invoke() {
suspend operator fun invoke(): ElectionListResponse {
return electionsRepository.fetchAndSaveElections()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ class MainActivity : AppCompatActivity() {
-> {
supportActionBar?.hide()
}
R.id.twoFactorAuthFragment
-> {
supportActionBar?.hide()
}
else -> {
window.clearFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS)
supportActionBar?.show()
Expand Down
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
Expand Up @@ -4,23 +4,34 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import org.aossie.agoraandroid.databinding.FragmentAboutBinding
import org.aossie.agoraandroid.ui.screens.about.AboutScreen
import org.aossie.agoraandroid.ui.theme.AgoraTheme

/**
* A simple [Fragment] subclass.
*/
class AboutFragment : Fragment() {

private lateinit var binding: FragmentAboutBinding
private lateinit var composeView: ComposeView

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
// Inflate the layout for this fragment
binding = FragmentAboutBinding.inflate(layoutInflater)
return binding.root
return ComposeView(requireContext()).also {
composeView = it
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
composeView.setContent {
AgoraTheme {
AboutScreen()
}
}
}
}
Loading

0 comments on commit a095b39

Please sign in to comment.