├── .gitignore ├── CODEOWNERS ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── org │ │ └── aossie │ │ └── agoraandroid │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── org │ │ │ └── aossie │ │ │ └── agoraandroid │ │ │ ├── SplashScreenActivity.java │ │ │ ├── adapters │ │ │ ├── BallotRecyclerAdapter.java │ │ │ ├── CandidateRecyclerAdapter.java │ │ │ ├── ElectionsRecyclerAdapter.java │ │ │ ├── VoterRecyclerAdapter.java │ │ │ └── VotersRecyclerAdapter.java │ │ │ ├── createElection │ │ │ ├── CreateElectionFour.java │ │ │ ├── CreateElectionOne.java │ │ │ ├── CreateElectionThree.java │ │ │ ├── CreateElectionTwo.java │ │ │ ├── CreateElectionViewModel.java │ │ │ └── ElectionDetailsSharedPrefs.java │ │ │ ├── displayElections │ │ │ ├── ActiveElectionsActivity.java │ │ │ ├── BallotActivity.java │ │ │ ├── DisplayElectionViewModel.java │ │ │ ├── ElectionActivity.java │ │ │ ├── FinishedElectionsActivity.java │ │ │ ├── PendingElectionsActivity.java │ │ │ ├── TotalElectionsActivity.java │ │ │ └── VotersActivity.java │ │ │ ├── forgotPassword │ │ │ ├── ForgotPasswordSend.java │ │ │ └── ForgotPasswordViewModel.java │ │ │ ├── home │ │ │ ├── AboutFragment.java │ │ │ ├── ContactUsFragment.java │ │ │ ├── HomeActivity.java │ │ │ ├── HomeFragment.java │ │ │ ├── HomeViewModel.java │ │ │ ├── ProfileFragment.java │ │ │ ├── ReportBugFragment.java │ │ │ └── ShareWithOthersFragment.java │ │ │ ├── inviteVoters │ │ │ ├── InviteVotersActivity.java │ │ │ └── InviteVotersViewModel.java │ │ │ ├── logIn │ │ │ ├── LogInActivity.java │ │ │ └── LoginViewModel.java │ │ │ ├── main │ │ │ └── MainActivity.java │ │ │ ├── remote │ │ │ ├── APIService.java │ │ │ └── RetrofitClient.java │ │ │ ├── result │ │ │ ├── ResultActivity.java │ │ │ └── ResultViewModel.java │ │ │ ├── signUp │ │ │ ├── SignUpActivity.java │ │ │ └── SignUpViewModel.java │ │ │ └── utilities │ │ │ ├── SharedPrefs.java │ │ │ └── TinyDB.java │ └── res │ │ ├── anim │ │ └── rotate.xml │ │ ├── drawable-v24 │ │ ├── ic_launcher_foreground.xml │ │ ├── rounded_button.xml │ │ └── white_background.png │ │ ├── drawable │ │ ├── agora.png │ │ ├── ic_access_time.xml │ │ ├── ic_bug_report_black_24dp.xml │ │ ├── ic_call_received_black_24dp.xml │ │ ├── ic_code_black_24dp.xml │ │ ├── ic_date_range_50dp.xml │ │ ├── ic_done_all.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_launcher_round.png │ │ ├── ic_local_post_office_black_24dp.xml │ │ ├── ic_message_24dp.xml │ │ ├── ic_people_24dp.xml │ │ ├── ic_person_black_24dp.xml │ │ ├── ic_play_arrow.xml │ │ ├── ic_share_black_24dp.xml │ │ ├── ic_view_carousel_black_24dp.xml │ │ ├── ic_view_carousel_white.xml │ │ ├── rounded_button.xml │ │ ├── spinner_background.xml │ │ └── white_background.png │ │ ├── layout │ │ ├── activity_active_elections.xml │ │ ├── activity_ballot.xml │ │ ├── activity_create_election_four.xml │ │ ├── activity_create_election_one.xml │ │ ├── activity_create_election_three.xml │ │ ├── activity_create_election_two.xml │ │ ├── activity_election.xml │ │ ├── activity_finished_elections.xml │ │ ├── activity_forgot_password_send.xml │ │ ├── activity_home.xml │ │ ├── activity_invite_voters.xml │ │ ├── activity_log_in.xml │ │ ├── activity_main.xml │ │ ├── activity_pending_elections.xml │ │ ├── activity_result.xml │ │ ├── activity_sign_up.xml │ │ ├── activity_splash_screen.xml │ │ ├── activity_total_elections.xml │ │ ├── activity_voters.xml │ │ ├── data_placeholder_shimmer_layout.xml │ │ ├── fragment_about.xml │ │ ├── fragment_contact_us.xml │ │ ├── fragment_home.xml │ │ ├── fragment_profile.xml │ │ ├── fragment_report_bug.xml │ │ ├── fragment_share_with_others.xml │ │ ├── list_item_ballot_details.xml │ │ ├── list_item_candidate_name.xml │ │ ├── list_item_election_details.xml │ │ ├── list_item_voter_details.xml │ │ └── nav_header.xml │ │ ├── menu │ │ ├── nav_menu.xml │ │ └── option_menu.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── navigation │ │ └── nav_graph.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── org │ └── aossie │ └── agoraandroid │ └── ExampleUnitTest.java ├── build.gradle ├── docs └── GSOC │ └── 2019 │ └── Mukul.md ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | .idea/ 4 | /local.properties 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | Project code owners 2 | 3 | * @Thuva4 @icemc @prudhvir3ddy 4 | 5 | # Both usernames or email addresses can be used to match 6 | # users. Everything else will be ignored. For example this will 7 | # specify `@legal` and a user with email `janedoe@gitlab.com` as the 8 | # owner for the LICENSE file -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Agora Android Application 2 | 3 | ## Readme 4 | 5 | _Android Application for Agora Web that uses [Agora](https://gitlab.com/aossie/Agora/): An Electronic Voting Library implemented in Scala. This application uses [Agora Web API](https://gitlab.com/aossie/Agora-Web) as backend application_ 6 | 7 | This project is created using [JavaSE](https://www.oracle.com/technetwork/java/javase/downloads/index.html) on [Android Studio](https://developer.android.com/studio). 8 | 9 | To run the development environment for this frontend, you need [Git](https://git-scm.com/) installed. 10 | 11 | ## Table of contents 12 | 13 | - [Agora-Web Frontend](#agora-web-frontend) 14 | - [Readme](#readme) 15 | - [Table of contents](#table-of-contents) 16 | - [Installation](#installation) 17 | - [Running the application](#running-the-application) 18 | - [Troubleshooting your local environment](#troubleshooting-your-local-environment) 19 | - [Best Practices](#best-practices) 20 | - [Some Don'ts](#some-donts) 21 | - [Further Reading / Useful Links](#further-reading-useful-links) 22 | 23 | 24 | 25 | ## Installation 26 | 27 | Make sure you have the latest version of [Android Studio](https://developer.android.com/studio) and [JavaSE](https://www.oracle.com/technetwork/java/javase/downloads/index.html) installed. We strongly recommend you to update all the libraries and sync the project(might take a minute). 28 | 29 | 30 | 31 | ## Running the application 32 | To use Facebook login you will need to change "XXXXXXXXXXXXXXX" with your app id in app/src/main/res/values/string.xml 33 | here 34 | ``` XXXXXXXXXXXXXXX 35 | ``` and here 36 | ``` 37 | fbXXXXXXXXXXXXXXX 38 | ``` 39 | 40 | **Note:** Don't forget to add "fb" before your fb_login_protocol_scheme. 41 | 42 | 43 | ## Troubleshooting your local environment 44 | 45 | Always `git pull` and get the latest from master. [Google](https://www.google.com) and [Stackoverflow](https://stackoverflow.com/) are your friends. You can find answers for most technical problems there. If you run into problems you can't resolve, feel free to open an issue. 46 | 47 | 48 | ## Best practices 49 | 50 | 1. Try to do a root cause analysis for the issue, if applicable. 51 | 2. Reference the issue being fixed in the corresponding PR. 52 | 3. Use meaningful commit messages in a PR. 53 | 4. Use one commit per task. Do not over commit (add unnecessary commits for a single task) or under commit (merge 2 or more tasks in one commit). 54 | 5. Add screenshot/short video in case the changes made in the PR, are being reflected in the UI of the application. 55 | 6. Close the issue as soon as the corresponding PR is accepted/closed. 56 | 57 | 58 | ## Some don'ts 59 | 60 | 1. Send a MR without an existing issue. 61 | 2. Fix an issue assigned to somebody else and submit a PR before the assignee does. 62 | 3. Report issues which are previously reported by others. (Please check both the open and closed issues). 63 | 4. Suggest unnecessary or completely new features in the issue list. 64 | 5. Add unnecessary spacing or indentation to the code. 65 | 66 | 67 | ## Further Reading / Useful Links 68 | 69 | * [Retrofit](https://square.github.io/retrofit/)-A type-safe HTTP client for Android and Java. 70 | * [Material Design For Android](https://developer.android.com/guide/topics/ui/look-and-feel)-Material design is a comprehensive guide for visual, motion, and interaction design across platforms and devices. 71 | * [Shimmer For Android](https://facebook.github.io/shimmer-android/)-Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. 72 | * [gson](https://github.com/google/gson)-A Java serialization/deserialization library to convert Java Objects into JSON and back. 73 | * [Navigation Component](https://developer.android.com/guide/navigation/navigation-getting-started)- Android Jetpack's Navigation component helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer. 74 | * [Recycler View](https://developer.android.com/guide/topics/ui/layout/recyclerview)- To display a scrolling list of elements based on large data sets (or data that frequently changes). 75 | * [Card View](https://developer.android.com/guide/topics/ui/layout/cardview)- To create card views. 76 | * [Design support](https://developer.android.com/topic/libraries/support-library/packages)- The Android Support Library contains several library packages that can be included in your application. Each of these libraries supports a specific range of Android platform versions and set of features. 77 | * [Pie Chart](https://github.com/PhilJay/MPAndroidChart)- A powerful & easy to use chart library for Android. 78 | * [Facebook Login](https://developers.facebook.com/docs/facebook-login/)- To implement User login using social media account. 79 | * [Load Toast](https://github.com/code-mc/loadtoast)-Pretty material design toasts with feedback animations. 80 | 81 | 82 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: "androidx.navigation.safeargs" 4 | 5 | 6 | android { 7 | compileSdkVersion 28 8 | defaultConfig { 9 | vectorDrawables.useSupportLibrary = true 10 | applicationId "org.aossie.agoraandroid" 11 | minSdkVersion 15 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | dataBinding { 24 | enabled = true 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation 'androidx.appcompat:appcompat:1.0.2' 31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 32 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'androidx.test:runner:1.2.0' 35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 36 | // Lifecycle components 37 | implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion" 38 | annotationProcessor "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion" 39 | //Design Support Library 40 | implementation "com.google.android.material:material:1.0.0-rc01" 41 | //Library for CardView 42 | implementation "androidx.cardview:cardview:1.0.0" 43 | //Retrofit 44 | implementation 'com.squareup.retrofit2:retrofit:2.6.0' 45 | implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' 46 | //GSON and GSON converter 47 | implementation 'com.squareup.retrofit2:converter-gson:2.6.0' 48 | implementation 'com.google.code.gson:gson:2.8.5' 49 | //Navigation Architecture Dependencies 50 | def nav_version = "2.1.0-beta02" 51 | implementation "androidx.navigation:navigation-fragment:$nav_version" 52 | implementation "androidx.navigation:navigation-ui:$nav_version" 53 | //Recycler View 54 | implementation "com.android.support:recyclerview-v7:28.0.0" 55 | //Shimmer 56 | implementation 'com.facebook.shimmer:shimmer:0.5.0' 57 | //Facebook Login 58 | implementation 'com.facebook.android:facebook-login:5.2.0' 59 | //Pie Chart 60 | implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' 61 | //Load Toast 62 | implementation 'net.steamcrafted:load-toast:1.0.12' 63 | 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/org/aossie/agoraandroid/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.InstrumentationRegistry; 6 | import androidx.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("org.aossie.agoraandroid", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 42 | 46 | 50 | 54 | 58 | 61 | 65 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 87 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/SplashScreenActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.animation.Animation; 6 | import android.view.animation.AnimationUtils; 7 | import android.widget.ImageView; 8 | 9 | import androidx.appcompat.app.AppCompatActivity; 10 | 11 | import org.aossie.agoraandroid.home.HomeActivity; 12 | import org.aossie.agoraandroid.main.MainActivity; 13 | import org.aossie.agoraandroid.utilities.SharedPrefs; 14 | 15 | public class SplashScreenActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_splash_screen); 21 | final SharedPrefs sharedPrefs = new SharedPrefs(SplashScreenActivity.this); 22 | // Rotation And Fade Out Animation 23 | 24 | final ImageView rotatingAgora = findViewById(R.id.image_agora); 25 | final Animation rotateAnimation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.rotate); 26 | final Animation fadeOutAnimation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.abc_fade_out); 27 | 28 | rotatingAgora.startAnimation(rotateAnimation); 29 | rotateAnimation.setAnimationListener(new Animation.AnimationListener() { 30 | @Override 31 | public void onAnimationStart(Animation animation) { 32 | 33 | } 34 | 35 | @Override 36 | public void onAnimationEnd(Animation animation) { 37 | rotatingAgora.startAnimation(fadeOutAnimation); 38 | String userName = sharedPrefs.getUserName(); 39 | String password=sharedPrefs.getPass(); 40 | if (userName == null || password==null) { 41 | startActivity(new Intent(SplashScreenActivity.this, MainActivity.class)); 42 | finish(); 43 | 44 | } else { 45 | startActivity(new Intent(SplashScreenActivity.this, HomeActivity.class)); 46 | finish(); 47 | } 48 | } 49 | 50 | @Override 51 | public void onAnimationRepeat(Animation animation) { 52 | 53 | } 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/adapters/BallotRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.adapters; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.recyclerview.widget.RecyclerView; 11 | 12 | import org.aossie.agoraandroid.R; 13 | 14 | import java.util.ArrayList; 15 | 16 | public class BallotRecyclerAdapter extends RecyclerView.Adapter { 17 | private final ArrayList mVoteBallotList,mVoterEmailList; 18 | 19 | public BallotRecyclerAdapter(ArrayList mVoterEmailList, ArrayList mVoteBallotList ) { 20 | this.mVoteBallotList = mVoteBallotList; 21 | this.mVoterEmailList = mVoterEmailList; 22 | } 23 | 24 | @NonNull 25 | @Override 26 | public BallotViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 27 | LayoutInflater layoutInflater = (LayoutInflater) parent.getContext() 28 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 29 | View itemView = layoutInflater.inflate(R.layout.list_item_ballot_details, parent, false); 30 | 31 | return new BallotRecyclerAdapter.BallotViewHolder(itemView); } 32 | 33 | 34 | @Override 35 | public void onBindViewHolder(@NonNull BallotViewHolder holder, int position) { 36 | holder.mVoterEmail.setText(mVoterEmailList.get(position)); 37 | holder.mVoterBallot.setText(mVoteBallotList.get(position)); 38 | } 39 | 40 | @Override 41 | public int getItemCount() { 42 | return mVoteBallotList.size(); 43 | } 44 | 45 | 46 | class BallotViewHolder extends RecyclerView.ViewHolder { 47 | final TextView mVoterBallot, mVoterEmail; 48 | 49 | BallotViewHolder(@NonNull View itemView) { 50 | super(itemView); 51 | mVoterBallot = itemView.findViewById(R.id.text_view_vote_ballot); 52 | mVoterEmail = itemView.findViewById(R.id.text_view_voter_email); 53 | 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/adapters/CandidateRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.adapters; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | import androidx.annotation.NonNull; 9 | import androidx.recyclerview.widget.RecyclerView; 10 | import org.aossie.agoraandroid.R; 11 | import java.util.ArrayList; 12 | 13 | public class CandidateRecyclerAdapter extends RecyclerView.Adapter { 14 | private final ArrayList candidates; 15 | 16 | public CandidateRecyclerAdapter(ArrayList candidates) { 17 | this.candidates = candidates; 18 | } 19 | 20 | @NonNull 21 | @Override 22 | public CandidateViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 23 | LayoutInflater li = (LayoutInflater) parent.getContext() 24 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 25 | View candidateView = li.inflate(R.layout.list_item_candidate_name, parent, false); 26 | return new CandidateViewHolder(candidateView); 27 | } 28 | 29 | @Override 30 | public void onBindViewHolder(@NonNull CandidateViewHolder holder, int position) { 31 | holder.candidateName.setText(candidates.get(position)); 32 | 33 | } 34 | 35 | 36 | @Override 37 | public int getItemCount() { 38 | return candidates.size(); 39 | } 40 | 41 | static class CandidateViewHolder extends RecyclerView.ViewHolder { 42 | final TextView candidateName; 43 | final View itemView; 44 | 45 | public CandidateViewHolder(@NonNull View itemView) { 46 | super(itemView); 47 | candidateName = itemView.findViewById(R.id.text_candidate_name); 48 | this.itemView = itemView; 49 | } 50 | 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/adapters/ElectionsRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.adapters; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Color; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.LinearLayout; 10 | import android.widget.TextView; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.constraintlayout.widget.ConstraintLayout; 14 | import androidx.recyclerview.widget.RecyclerView; 15 | 16 | import org.aossie.agoraandroid.R; 17 | import org.aossie.agoraandroid.displayElections.ElectionActivity; 18 | 19 | 20 | import java.util.ArrayList; 21 | 22 | public class ElectionsRecyclerAdapter extends RecyclerView.Adapter { 23 | 24 | private final ArrayList electionNameList, electionDescriptionList, startDateList, endDateList, statusList, candidateList,mIDList; 25 | private final String electionType; 26 | private Context mContext; 27 | 28 | public ElectionsRecyclerAdapter(ArrayList mIDList,Context context, ArrayList electionNameList, ArrayList electionDescriptionList, ArrayList startDateList, ArrayList endDateList, ArrayList statusList, ArrayList candidateList, String type) { 29 | this.mIDList=mIDList; 30 | mContext = context; 31 | this.electionNameList = electionNameList; 32 | this.electionDescriptionList = electionDescriptionList; 33 | this.startDateList = startDateList; 34 | this.endDateList = endDateList; 35 | this.statusList = statusList; 36 | this.candidateList = candidateList; 37 | this.electionType = type; 38 | } 39 | 40 | @NonNull 41 | @Override 42 | public ElectionsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 43 | LayoutInflater layoutInflater = (LayoutInflater) parent.getContext() 44 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 45 | View itemView = layoutInflater.inflate(R.layout.list_item_election_details, parent, false); 46 | 47 | return new ElectionsViewHolder(itemView); 48 | } 49 | 50 | @Override 51 | public void onBindViewHolder(@NonNull ElectionsViewHolder holder, final int position) { 52 | holder.mElectionName.setText(electionNameList.get(position)); 53 | holder.mElectionDescription.setText(electionDescriptionList.get(position)); 54 | holder.mEndDate.setText(endDateList.get(position)); 55 | holder.mStartDate.setText(startDateList.get(position)); 56 | holder.mStatus.setText(statusList.get(position)); 57 | holder.mCandidateList.setText(candidateList.get(position)); 58 | switch (electionType) { 59 | case "active": 60 | holder.constraintLayout.setBackgroundColor(Color.rgb(226, 11, 11)); 61 | break; 62 | case "finished": 63 | holder.constraintLayout.setBackgroundColor(Color.rgb(5, 176, 197)); 64 | break; 65 | case "pending": 66 | holder.constraintLayout.setBackgroundColor(Color.rgb(75, 166, 79)); 67 | break; 68 | case "total": 69 | holder.constraintLayout.setBackgroundColor(Color.rgb(254, 157, 24)); 70 | break; 71 | } 72 | holder.electionLayout.setOnClickListener(new View.OnClickListener() { 73 | @Override 74 | public void onClick(View v) { 75 | Intent intent = new Intent(mContext, ElectionActivity.class); 76 | intent.putExtra("election_name", electionNameList.get(position)); 77 | intent.putExtra("election_description", electionDescriptionList.get(position)); 78 | intent.putExtra("start_date", startDateList.get(position)); 79 | intent.putExtra("end_date", endDateList.get(position)); 80 | intent.putExtra("candidates", candidateList.get(position)); 81 | intent.putExtra("status", statusList.get(position)); 82 | intent.putExtra("id",mIDList.get(position)); 83 | mContext.startActivity(intent); 84 | } 85 | }); 86 | 87 | } 88 | 89 | @Override 90 | public int getItemCount() { 91 | return electionNameList.size(); 92 | } 93 | 94 | class ElectionsViewHolder extends RecyclerView.ViewHolder { 95 | final TextView mElectionName, mElectionDescription, mStartDate, mEndDate, mStatus, mCandidateList; 96 | final ConstraintLayout constraintLayout; 97 | final LinearLayout electionLayout; 98 | 99 | ElectionsViewHolder(@NonNull View itemView) { 100 | super(itemView); 101 | mElectionName = itemView.findViewById(R.id.text_view_election_name); 102 | mElectionDescription = itemView.findViewById(R.id.text_view_election_description); 103 | mStartDate = itemView.findViewById(R.id.text_view_start_date); 104 | mEndDate = itemView.findViewById(R.id.text_view_end_date); 105 | mStatus = itemView.findViewById(R.id.text_view_status); 106 | mCandidateList = itemView.findViewById(R.id.text_view_candidate_list); 107 | constraintLayout = itemView.findViewById(R.id.constraintLayout); 108 | electionLayout = itemView.findViewById(R.id.linearLayout); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/adapters/VoterRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.adapters; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.recyclerview.widget.RecyclerView; 11 | 12 | import org.aossie.agoraandroid.R; 13 | 14 | import java.util.ArrayList; 15 | 16 | public class VoterRecyclerAdapter extends RecyclerView.Adapter { 17 | private final ArrayList mVoterNameList; 18 | private final ArrayList mVoterEmailList; 19 | 20 | public VoterRecyclerAdapter(ArrayList mVoterNameList, ArrayList mVoterEmailList) { 21 | this.mVoterNameList = mVoterNameList; 22 | this.mVoterEmailList = mVoterEmailList; 23 | } 24 | 25 | @NonNull 26 | @Override 27 | public VoterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 28 | LayoutInflater li = (LayoutInflater) parent.getContext() 29 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 30 | View voterView = li.inflate(R.layout.list_item_voter_details, parent, false); 31 | return new VoterRecyclerAdapter.VoterViewHolder(voterView); 32 | } 33 | 34 | @Override 35 | public void onBindViewHolder(@NonNull VoterViewHolder holder, int position) { 36 | holder.voterName.setText(mVoterNameList.get(position)); 37 | holder.voterEmail.setText(mVoterEmailList.get(position)); 38 | 39 | 40 | } 41 | 42 | @Override 43 | public int getItemCount() { 44 | return mVoterEmailList.size(); 45 | } 46 | 47 | 48 | static class VoterViewHolder extends RecyclerView.ViewHolder { 49 | final TextView voterName,voterEmail; 50 | final View itemView; 51 | 52 | public VoterViewHolder(@NonNull View itemView) { 53 | super(itemView); 54 | voterName = itemView.findViewById(R.id.text_view_voter_name); 55 | voterEmail = itemView.findViewById(R.id.text_view_voters_email); 56 | this.itemView = itemView; 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/adapters/VotersRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.adapters; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.recyclerview.widget.RecyclerView; 11 | 12 | import org.aossie.agoraandroid.R; 13 | 14 | import java.util.ArrayList; 15 | 16 | public class VotersRecyclerAdapter extends RecyclerView.Adapter { 17 | private final ArrayList mVoteNameList, mVoterEmailList; 18 | 19 | public VotersRecyclerAdapter(ArrayList mVoteNameList, ArrayList mVoterEmailList) { 20 | this.mVoteNameList = mVoteNameList; 21 | this.mVoterEmailList = mVoterEmailList; 22 | } 23 | 24 | @NonNull 25 | @Override 26 | public VoterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 27 | LayoutInflater layoutInflater = (LayoutInflater) parent.getContext() 28 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 29 | View itemView = layoutInflater.inflate(R.layout.list_item_voter_details, parent, false); 30 | 31 | return new VotersRecyclerAdapter.VoterViewHolder(itemView); 32 | } 33 | 34 | @Override 35 | public void onBindViewHolder(@NonNull VoterViewHolder holder, int position) { 36 | holder.mVoterEmail.setText(mVoterEmailList.get(position)); 37 | holder.mVoterName.setText(mVoteNameList.get(position)); 38 | } 39 | 40 | @Override 41 | public int getItemCount() { 42 | return mVoteNameList.size(); 43 | } 44 | 45 | class VoterViewHolder extends RecyclerView.ViewHolder { 46 | final TextView mVoterName, mVoterEmail; 47 | 48 | VoterViewHolder(@NonNull View itemView) { 49 | super(itemView); 50 | mVoterName = itemView.findViewById(R.id.text_view_voter_name); 51 | mVoterEmail = itemView.findViewById(R.id.text_view_voters_email); 52 | 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/createElection/CreateElectionFour.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.createElection; 2 | 3 | import androidx.annotation.RequiresApi; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.CheckBox; 11 | import android.widget.RadioButton; 12 | import android.widget.RadioGroup; 13 | 14 | import org.aossie.agoraandroid.R; 15 | 16 | public class CreateElectionFour extends AppCompatActivity { 17 | private ElectionDetailsSharedPrefs electionDetailsSharedPrefs; 18 | private CreateElectionViewModel createElectionViewModel; 19 | private CheckBox isInvite; 20 | private CheckBox isRealTime; 21 | private Boolean mFinalIsInvite; 22 | private Boolean mFinalIsRealTime; 23 | private Boolean voterListVisibility; 24 | private RadioButton radioButtonListVoters; 25 | private RadioButton radioButtonBallots; 26 | private RadioGroup radioGroupListVoters; 27 | private RadioGroup radioGroupBallots; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | electionDetailsSharedPrefs = new ElectionDetailsSharedPrefs(getApplication()); 33 | createElectionViewModel = new CreateElectionViewModel(getApplication(), this); 34 | setContentView(R.layout.activity_create_election_four); 35 | Button mSubmitButton = findViewById(R.id.button_submit_details); 36 | isInvite = findViewById(R.id.check_invite_voters); 37 | isRealTime = findViewById(R.id.check_real_time_results); 38 | radioGroupListVoters = findViewById(R.id.radioGroup2); 39 | radioGroupBallots = findViewById(R.id.radioGroup); 40 | 41 | 42 | mSubmitButton.setOnClickListener(new View.OnClickListener() { 43 | @RequiresApi(api = Build.VERSION_CODES.KITKAT) 44 | @Override 45 | public void onClick(View v) { 46 | int radioId = radioGroupListVoters.getCheckedRadioButtonId(); 47 | radioButtonListVoters = findViewById(radioId); 48 | 49 | int radioId1 = radioGroupBallots.getCheckedRadioButtonId(); 50 | radioButtonBallots = findViewById(radioId1); 51 | 52 | 53 | voterListVisibility = !radioButtonListVoters.getText().toString().equals("Only me"); 54 | 55 | mFinalIsInvite = isInvite.isChecked(); 56 | mFinalIsRealTime = isRealTime.isChecked(); 57 | electionDetailsSharedPrefs.saveIsInvite(mFinalIsInvite); 58 | electionDetailsSharedPrefs.saveIsRealTime(mFinalIsRealTime); 59 | electionDetailsSharedPrefs.saveVoterListVisibility(voterListVisibility); 60 | electionDetailsSharedPrefs.saveBallotVisibility(radioButtonBallots.getText().toString().trim()); 61 | createElectionViewModel.createElection(); 62 | } 63 | }); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/createElection/CreateElectionThree.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.createElection; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.RadioButton; 10 | import android.widget.RadioGroup; 11 | 12 | import org.aossie.agoraandroid.R; 13 | 14 | public class CreateElectionThree extends AppCompatActivity { 15 | private ElectionDetailsSharedPrefs electionDetailsSharedPrefs; 16 | private String votingAlgorithm; 17 | private RadioGroup radioGroup; 18 | private RadioButton radioButton; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_create_election_three); 24 | electionDetailsSharedPrefs =new ElectionDetailsSharedPrefs(getApplication()); 25 | Button mFinalStepButton = findViewById(R.id.button_to_final_step); 26 | radioGroup = findViewById(R.id.radioGroup); 27 | mFinalStepButton.setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View v) { 30 | int radioId = radioGroup.getCheckedRadioButtonId(); 31 | radioButton = findViewById(radioId); 32 | votingAlgorithm = radioButton.getText().toString(); 33 | electionDetailsSharedPrefs.saveVotingAlgo(votingAlgorithm); 34 | startActivity(new Intent(CreateElectionThree.this, CreateElectionFour.class)); 35 | } 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/createElection/CreateElectionTwo.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.createElection; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import androidx.recyclerview.widget.ItemTouchHelper; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | 9 | import android.content.Intent; 10 | import android.os.Bundle; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.Toast; 14 | 15 | import com.google.android.material.textfield.TextInputLayout; 16 | 17 | import org.aossie.agoraandroid.R; 18 | import org.aossie.agoraandroid.adapters.CandidateRecyclerAdapter; 19 | import org.aossie.agoraandroid.utilities.TinyDB; 20 | 21 | import java.util.ArrayList; 22 | 23 | @SuppressWarnings("ConstantConditions") 24 | public class CreateElectionTwo extends AppCompatActivity { 25 | private TinyDB tinydb; 26 | private final ArrayList mCandidates = new ArrayList<>(); 27 | private CandidateRecyclerAdapter candidateRecyclerAdapter; 28 | private TextInputLayout mAddCandidateTextInput; 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_create_election_two); 34 | Button mAddCandidateButton = findViewById(R.id.button_add_candidate); 35 | tinydb= new TinyDB(getApplication()); 36 | Button mNextButton = findViewById(R.id.button_next_two); 37 | mAddCandidateTextInput = findViewById(R.id.text_input_candidate); 38 | RecyclerView mRecyclerView = findViewById(R.id.recycler_view_names); 39 | 40 | candidateRecyclerAdapter = new CandidateRecyclerAdapter(mCandidates); 41 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); 42 | new ItemTouchHelper(itemTouchHelperCallback).attachToRecyclerView(mRecyclerView); 43 | mRecyclerView.setAdapter(candidateRecyclerAdapter); 44 | mNextButton.setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | if (mCandidates != null) { 48 | tinydb.putListString("Candidates",mCandidates); 49 | startActivity(new Intent(CreateElectionTwo.this, CreateElectionThree.class)); 50 | } else { 51 | Toast.makeText(CreateElectionTwo.this, "Please Add At least One Candidate", Toast.LENGTH_SHORT).show(); 52 | } 53 | } 54 | }); 55 | mAddCandidateButton.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View v) { 58 | final String name = mAddCandidateTextInput.getEditText().getText().toString(); 59 | addCandidate(name); 60 | } 61 | }); 62 | 63 | } 64 | 65 | 66 | private void addCandidate(String cName) { 67 | mCandidates.add(cName); 68 | candidateRecyclerAdapter.notifyDataSetChanged(); 69 | mAddCandidateTextInput.getEditText().setText(""); 70 | } 71 | 72 | private final ItemTouchHelper.SimpleCallback itemTouchHelperCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT) { 73 | @Override 74 | public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { 75 | return false; 76 | } 77 | 78 | @Override 79 | public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { 80 | mCandidates.remove(viewHolder.getAdapterPosition()); 81 | candidateRecyclerAdapter.notifyDataSetChanged(); 82 | 83 | } 84 | }; 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/createElection/CreateElectionViewModel.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.createElection; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Build; 7 | import android.widget.Toast; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.annotation.RequiresApi; 11 | import androidx.lifecycle.AndroidViewModel; 12 | 13 | import net.steamcrafted.loadtoast.LoadToast; 14 | 15 | import org.aossie.agoraandroid.home.HomeActivity; 16 | import org.aossie.agoraandroid.remote.APIService; 17 | import org.aossie.agoraandroid.remote.RetrofitClient; 18 | import org.aossie.agoraandroid.utilities.SharedPrefs; 19 | import org.aossie.agoraandroid.utilities.TinyDB; 20 | import org.json.JSONArray; 21 | import org.json.JSONException; 22 | import org.json.JSONObject; 23 | 24 | import java.util.ArrayList; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | import retrofit2.Call; 29 | import retrofit2.Callback; 30 | import retrofit2.Response; 31 | 32 | 33 | class CreateElectionViewModel extends AndroidViewModel { 34 | private final Context context; 35 | private final ElectionDetailsSharedPrefs electionDetailsSharedPrefs = new ElectionDetailsSharedPrefs(getApplication()); 36 | private final SharedPrefs sharedPrefs = new SharedPrefs(getApplication()); 37 | private final TinyDB tinydb = new TinyDB(getApplication()); 38 | private LoadToast loadToast; 39 | 40 | 41 | CreateElectionViewModel(@NonNull Application application, Context context) { 42 | super(application); 43 | this.context = context; 44 | 45 | } 46 | 47 | @RequiresApi(api = Build.VERSION_CODES.KITKAT) 48 | public void createElection() { 49 | loadToast = new LoadToast(context); 50 | loadToast.setText("Creating Election"); 51 | loadToast.show(); 52 | ArrayList candidates = tinydb.getListString("Candidates"); 53 | JSONArray jsArray = new JSONArray(candidates); 54 | String token = sharedPrefs.getToken(); 55 | final JSONObject jsonObject = new JSONObject(); 56 | try { 57 | Map map = new HashMap<>(); 58 | map.put("voteBallot", ""); 59 | map.put("voterEmail", ""); 60 | JSONArray ballot = new JSONArray(new Map[]{map}); 61 | jsonObject.put("ballot", ballot); //Append the other JSONObject to the parent one 62 | jsonObject.put("name", electionDetailsSharedPrefs.getElectionName()); 63 | jsonObject.put("description", electionDetailsSharedPrefs.getElectionDesc()); 64 | jsonObject.put("voterListVisibility", electionDetailsSharedPrefs.getVoterListVisibility()); 65 | jsonObject.put("startingDate", electionDetailsSharedPrefs.getStartTime()); 66 | jsonObject.put("endingDate", electionDetailsSharedPrefs.getEndTime()); 67 | jsonObject.put("isInvite", electionDetailsSharedPrefs.getIsInvite()); 68 | jsonObject.put("ballotVisibility", electionDetailsSharedPrefs.getBallotVisibility()); 69 | jsonObject.put("isRealTime", electionDetailsSharedPrefs.getIsRealTime()); 70 | jsonObject.put("votingAlgo", electionDetailsSharedPrefs.getVotingAlgo()); 71 | jsonObject.put("candidates", jsArray); 72 | jsonObject.put("noVacancies", 1); 73 | } catch (JSONException e) { 74 | e.printStackTrace(); 75 | } 76 | APIService apiService = RetrofitClient.getAPIService(); 77 | Call electionResponse = apiService.createElection(jsonObject.toString(), token); 78 | electionResponse.enqueue(new Callback() { 79 | @Override 80 | public void onResponse(Call call, Response response) { 81 | 82 | if (response.message().equals("OK")) { 83 | loadToast.success(); 84 | Toast.makeText(getApplication(), "Created Successfully", Toast.LENGTH_SHORT).show(); 85 | electionDetailsSharedPrefs.clearElectionData(); 86 | context.startActivity(new Intent(context, HomeActivity.class)); 87 | } else { 88 | loadToast.error(); 89 | Toast.makeText(getApplication(), "Something went wrong please try again", Toast.LENGTH_SHORT).show(); 90 | } 91 | } 92 | 93 | @Override 94 | public void onFailure(Call call, Throwable t) { 95 | loadToast.error(); 96 | Toast.makeText(getApplication(), "Something went wrong please try again", Toast.LENGTH_SHORT).show(); 97 | } 98 | }); 99 | 100 | } 101 | } -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/createElection/ElectionDetailsSharedPrefs.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.createElection; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | @SuppressWarnings("SpellCheckingInspection") 7 | public class ElectionDetailsSharedPrefs { 8 | private static final String myPrefs = "myPrefs"; 9 | private static final String NameKey = "electionName"; 10 | private static final String StartTimeKey = "startTime"; 11 | private static final String EndTimeKey = "endTime"; 12 | private static final String IsInvitedKey = "isInvited"; 13 | private static final String IsRealTimeKey = "isRealTime"; 14 | private static final String VoterListVisibilityKey = "voterListVisibility"; 15 | private static final String DescriptionKey = "electionDescription"; 16 | private static final String VotingAlgoKey = "votingAlgorithm"; 17 | private static final String BallotVisibilityKey = "ballotVisibility"; 18 | private static final String ElectionDetailsKey = "electionDetails"; 19 | private final SharedPreferences sharedPreferences; 20 | private final SharedPreferences.Editor editor; 21 | 22 | 23 | public ElectionDetailsSharedPrefs(Context context) { 24 | sharedPreferences = context.getSharedPreferences(myPrefs, Context.MODE_PRIVATE); 25 | editor = sharedPreferences.edit(); 26 | } 27 | 28 | 29 | //Saving name of election 30 | public void saveElectionName(String name) { 31 | editor.putString(NameKey, name); 32 | editor.commit(); 33 | } 34 | 35 | public String getElectionName() { 36 | return sharedPreferences.getString(NameKey, null); 37 | } 38 | 39 | //Saving Election Description 40 | public void saveElectionDesc(String desc) { 41 | editor.putString(DescriptionKey, desc); 42 | editor.commit(); 43 | 44 | } 45 | 46 | public String getElectionDesc() { 47 | return sharedPreferences.getString(DescriptionKey, null); 48 | } 49 | 50 | 51 | //Saving Start Time 52 | public void saveStartTime(String desc) { 53 | editor.putString(StartTimeKey, desc); 54 | editor.commit(); 55 | 56 | } 57 | 58 | public String getStartTime() { 59 | return sharedPreferences.getString(StartTimeKey, null); 60 | } 61 | 62 | //Saving End Time 63 | public void saveEndTime(String desc) { 64 | editor.putString(EndTimeKey, desc); 65 | editor.commit(); 66 | 67 | } 68 | 69 | public String getEndTime() { 70 | return sharedPreferences.getString(EndTimeKey, null); 71 | } 72 | 73 | //Save voters visibility 74 | public void saveIsRealTime(Boolean isRealTime) { 75 | editor.putBoolean(IsRealTimeKey, isRealTime); 76 | editor.commit(); 77 | 78 | } 79 | 80 | public Boolean getIsRealTime() { 81 | return sharedPreferences.getBoolean(IsRealTimeKey, false); 82 | } 83 | 84 | //Save Real Time Results or not 85 | public void saveVoterListVisibility(Boolean voterListVisibility) { 86 | editor.putBoolean(VoterListVisibilityKey, voterListVisibility); 87 | editor.commit(); 88 | 89 | } 90 | 91 | public Boolean getVoterListVisibility() { 92 | return sharedPreferences.getBoolean(VoterListVisibilityKey, false); 93 | } 94 | 95 | //Voters are invited or not 96 | public void saveIsInvite(Boolean isInvited) { 97 | editor.putBoolean(IsInvitedKey, isInvited); 98 | editor.commit(); 99 | 100 | } 101 | public Boolean getIsInvite() { 102 | return sharedPreferences.getBoolean(IsInvitedKey, false); 103 | } 104 | 105 | 106 | public void saveVotingAlgo(String algo) { 107 | editor.putString(VotingAlgoKey, algo); 108 | editor.commit(); 109 | 110 | } 111 | 112 | public String getVotingAlgo() { 113 | return sharedPreferences.getString(VotingAlgoKey, null); 114 | } 115 | 116 | 117 | public void saveBallotVisibility(String ballotVisibility) { 118 | editor.putString(BallotVisibilityKey, ballotVisibility); 119 | editor.commit(); 120 | 121 | } 122 | 123 | public String getBallotVisibility() { 124 | return sharedPreferences.getString(BallotVisibilityKey, null); 125 | } 126 | 127 | public void saveElectionDetails(String electionDetails) { 128 | editor.putString(ElectionDetailsKey, electionDetails); 129 | editor.commit(); 130 | 131 | } 132 | 133 | public String getElectionDetails() { 134 | return sharedPreferences.getString(ElectionDetailsKey, null); 135 | } 136 | public void clearElectionData() { 137 | editor.putString(NameKey, null); 138 | editor.putString(StartTimeKey, null); 139 | editor.putString(EndTimeKey, null); 140 | editor.putString(IsInvitedKey, null); 141 | editor.putString(IsRealTimeKey, null); 142 | editor.putString(VoterListVisibilityKey, null); 143 | editor.putString(DescriptionKey, null); 144 | editor.putString(VotingAlgoKey, null); 145 | editor.putString(BallotVisibilityKey, null); 146 | 147 | editor.commit(); 148 | } 149 | 150 | 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/displayElections/ActiveElectionsActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.displayElections; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.recyclerview.widget.LinearLayoutManager; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import android.os.Bundle; 8 | 9 | import org.aossie.agoraandroid.R; 10 | import org.aossie.agoraandroid.adapters.ElectionsRecyclerAdapter; 11 | import org.aossie.agoraandroid.createElection.ElectionDetailsSharedPrefs; 12 | import org.json.JSONArray; 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import java.text.ParseException; 17 | import java.text.SimpleDateFormat; 18 | import java.util.ArrayList; 19 | import java.util.Calendar; 20 | import java.util.Date; 21 | 22 | public class ActiveElectionsActivity extends AppCompatActivity { 23 | private final ArrayList mElectionNameList = new ArrayList<>(); 24 | private final ArrayList mElectionDescriptionList = new ArrayList<>(); 25 | private final ArrayList mElectionStartDateList = new ArrayList<>(); 26 | private final ArrayList mElectionEndDateList = new ArrayList<>(); 27 | private final ArrayList mElectionStatusList = new ArrayList<>(); 28 | private final ArrayList mCandidatesList = new ArrayList<>(); 29 | private final ArrayList mIDList = new ArrayList<>(); 30 | 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_active_elections); 36 | ElectionDetailsSharedPrefs electionDetailsSharedPrefs = new ElectionDetailsSharedPrefs(getApplicationContext()); 37 | RecyclerView rvElectionDetails = findViewById(R.id.rv_active_elections); 38 | 39 | 40 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); 41 | rvElectionDetails.setLayoutManager(mLayoutManager); 42 | try { 43 | JSONObject jsonObject = new JSONObject(electionDetailsSharedPrefs.getElectionDetails()); 44 | JSONArray electionsJsonArray = jsonObject.getJSONArray("elections"); 45 | 46 | for (int i = 0; i < electionsJsonArray.length(); i++) { 47 | StringBuilder mCandidateName = new StringBuilder(); 48 | JSONObject singleElectionJsonObject = electionsJsonArray.getJSONObject(i); 49 | 50 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 51 | Date formattedStartingDate = formatter.parse(singleElectionJsonObject.getString("start")); 52 | Date formattedEndingDate = formatter.parse(singleElectionJsonObject.getString("end")); 53 | Date currentDate = Calendar.getInstance().getTime(); 54 | 55 | if (currentDate.after(formattedStartingDate) && currentDate.before(formattedEndingDate)) { 56 | mElectionStatusList.add("Active"); 57 | mElectionStartDateList.add(formattedStartingDate.toString()); 58 | mElectionEndDateList.add(formattedEndingDate.toString()); 59 | mElectionNameList.add(singleElectionJsonObject.getString("name")); 60 | mIDList.add(singleElectionJsonObject.getString("_id")); 61 | mElectionDescriptionList.add(singleElectionJsonObject.getString("description")); 62 | } 63 | JSONArray candidatesJsonArray = singleElectionJsonObject.getJSONArray("candidates"); 64 | for (int j = 0; j < candidatesJsonArray.length(); j++) { 65 | mCandidateName.append(candidatesJsonArray.getString(j)).append("\n"); 66 | } 67 | mCandidatesList.add(mCandidateName.toString().trim()); 68 | } 69 | } catch (JSONException e) { 70 | e.printStackTrace(); 71 | } catch (ParseException e) { 72 | e.printStackTrace(); 73 | } 74 | 75 | ElectionsRecyclerAdapter electionsRecyclerAdapter = new ElectionsRecyclerAdapter(mIDList,this,mElectionNameList, mElectionDescriptionList, mElectionStartDateList, mElectionEndDateList, mElectionStatusList, mCandidatesList,"active"); 76 | rvElectionDetails.setAdapter(electionsRecyclerAdapter); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/displayElections/BallotActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.displayElections; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.recyclerview.widget.LinearLayoutManager; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import android.os.Bundle; 8 | 9 | import org.aossie.agoraandroid.R; 10 | import org.aossie.agoraandroid.adapters.BallotRecyclerAdapter; 11 | import org.json.JSONArray; 12 | import org.json.JSONException; 13 | import org.json.JSONObject; 14 | 15 | import java.util.ArrayList; 16 | 17 | public class BallotActivity extends AppCompatActivity { 18 | private String ballotResponse; 19 | private final ArrayList mVoterEmailList = new ArrayList<>(); 20 | private final ArrayList mVoteBallotList = new ArrayList<>(); 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_ballot); 26 | RecyclerView rvBallotDetails = findViewById(R.id.recycler_view_ballots); 27 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); 28 | rvBallotDetails.setLayoutManager(mLayoutManager); 29 | 30 | if (getIntent().hasExtra("ballot_response")) { 31 | ballotResponse = getIntent().getStringExtra("ballot_response"); 32 | } 33 | try { 34 | JSONObject jsonObject = new JSONObject(ballotResponse); 35 | JSONArray ballotJsonArray = jsonObject.getJSONArray("ballots"); 36 | for (int i = 0; i < ballotJsonArray.length(); i++) { 37 | JSONObject ballotJsonObject = ballotJsonArray.getJSONObject(i); 38 | 39 | mVoterEmailList.add(ballotJsonObject.getString("voterEmail")); 40 | mVoteBallotList.add(ballotJsonObject.getString("voteBallot")); 41 | 42 | } 43 | 44 | } catch (JSONException e) { 45 | e.printStackTrace(); 46 | } 47 | 48 | BallotRecyclerAdapter ballotRecyclerAdapter = new BallotRecyclerAdapter(mVoterEmailList, mVoteBallotList); 49 | rvBallotDetails.setAdapter(ballotRecyclerAdapter); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/displayElections/DisplayElectionViewModel.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.displayElections; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.widget.Toast; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.lifecycle.AndroidViewModel; 10 | 11 | import net.steamcrafted.loadtoast.LoadToast; 12 | 13 | import org.aossie.agoraandroid.home.HomeActivity; 14 | import org.aossie.agoraandroid.remote.APIService; 15 | import org.aossie.agoraandroid.remote.RetrofitClient; 16 | 17 | import retrofit2.Call; 18 | import retrofit2.Callback; 19 | import retrofit2.Response; 20 | 21 | class DisplayElectionViewModel extends AndroidViewModel { 22 | private final Context context; 23 | private LoadToast loadToast; 24 | 25 | DisplayElectionViewModel(@NonNull Application application, Context context) { 26 | super(application); 27 | this.context = context; 28 | } 29 | 30 | void getBallot(String token, String id) { 31 | loadToast = new LoadToast(context); 32 | loadToast.setText("Getting Details"); 33 | loadToast.show(); 34 | APIService apiService = RetrofitClient.getAPIService(); 35 | Call getBallotResponse = apiService.getBallot(token, id); 36 | getBallotResponse.enqueue(new Callback() { 37 | @Override 38 | public void onResponse(Call call, Response response) { 39 | if (response.message().equals("OK")) { 40 | loadToast.success(); 41 | Intent intent = new Intent(context, BallotActivity.class); 42 | intent.putExtra("ballot_response", response.body()); 43 | context.startActivity(intent); 44 | } 45 | } 46 | 47 | @Override 48 | public void onFailure(Call call, Throwable t) { 49 | loadToast.error(); 50 | Toast.makeText(getApplication(), "Something Went Wrong Please Try Again Later", Toast.LENGTH_SHORT).show(); 51 | } 52 | }); 53 | 54 | 55 | } 56 | 57 | void getVoter(String token, String id) { 58 | loadToast = new LoadToast(context); 59 | loadToast.setText("Getting Voters"); 60 | loadToast.show(); 61 | APIService apiService = RetrofitClient.getAPIService(); 62 | Call getVotersResponse = apiService.getVoters(token, id); 63 | getVotersResponse.enqueue(new Callback() { 64 | @Override 65 | public void onResponse(Call call, Response response) { 66 | if (response.message().equals("OK")) { 67 | loadToast.success(); 68 | Intent intent = new Intent(context, VotersActivity.class); 69 | intent.putExtra("voters_response", response.body()); 70 | context.startActivity(intent); 71 | } 72 | } 73 | 74 | @Override 75 | public void onFailure(Call call, Throwable t) { 76 | loadToast.error(); 77 | Toast.makeText(getApplication(), "Something Went Wrong Please Try Again Later", Toast.LENGTH_SHORT).show(); 78 | } 79 | }); 80 | 81 | 82 | } 83 | 84 | void deleteElection(String token, String id) { 85 | loadToast = new LoadToast(context); 86 | loadToast.setText("Deleting Election"); 87 | loadToast.show(); 88 | APIService apiService = RetrofitClient.getAPIService(); 89 | Call deleteElectionResponse = apiService.deleteElection(token, id); 90 | deleteElectionResponse.enqueue(new Callback() { 91 | @Override 92 | public void onResponse(Call call, Response response) { 93 | if (response.message().equals("OK")) { 94 | loadToast.success(); 95 | Toast.makeText(getApplication(), "Election Deleted Successfully", Toast.LENGTH_SHORT).show(); 96 | context.startActivity(new Intent(getApplication(), HomeActivity.class)); 97 | } 98 | } 99 | 100 | @Override 101 | public void onFailure(Call call, Throwable t) { 102 | loadToast.show(); 103 | Toast.makeText(getApplication(), "Something Went Wrong Please Try Again Later", Toast.LENGTH_SHORT).show(); 104 | } 105 | }); 106 | 107 | 108 | } 109 | 110 | 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/displayElections/FinishedElectionsActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.displayElections; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.recyclerview.widget.LinearLayoutManager; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import android.os.Bundle; 8 | 9 | import org.aossie.agoraandroid.R; 10 | import org.aossie.agoraandroid.adapters.ElectionsRecyclerAdapter; 11 | import org.aossie.agoraandroid.createElection.ElectionDetailsSharedPrefs; 12 | import org.json.JSONArray; 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import java.text.ParseException; 17 | import java.text.SimpleDateFormat; 18 | import java.util.ArrayList; 19 | import java.util.Calendar; 20 | import java.util.Date; 21 | 22 | public class FinishedElectionsActivity extends AppCompatActivity { 23 | 24 | private final ArrayList mElectionNameList = new ArrayList<>(); 25 | private final ArrayList mElectionDescriptionList = new ArrayList<>(); 26 | private final ArrayList mElectionStartDateList = new ArrayList<>(); 27 | private final ArrayList mElectionEndDateList = new ArrayList<>(); 28 | private final ArrayList mElectionStatusList = new ArrayList<>(); 29 | private final ArrayList mCandidatesList = new ArrayList<>(); 30 | private final ArrayList mIDList = new ArrayList<>(); 31 | 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_finished_elections); 37 | ElectionDetailsSharedPrefs electionDetailsSharedPrefs = new ElectionDetailsSharedPrefs(getApplicationContext()); 38 | RecyclerView rvElectionDetails = findViewById(R.id.rv_finished_elections); 39 | 40 | 41 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); 42 | rvElectionDetails.setLayoutManager(mLayoutManager); 43 | try { 44 | JSONObject jsonObject = new JSONObject(electionDetailsSharedPrefs.getElectionDetails()); 45 | JSONArray electionsJsonArray = jsonObject.getJSONArray("elections"); 46 | 47 | for (int i = 0; i < electionsJsonArray.length(); i++) { 48 | StringBuilder mCandidateName = new StringBuilder(); 49 | JSONObject singleElectionJsonObject = electionsJsonArray.getJSONObject(i); 50 | 51 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 52 | Date formattedStartingDate = formatter.parse(singleElectionJsonObject.getString("start")); 53 | Date formattedEndingDate = formatter.parse(singleElectionJsonObject.getString("end")); 54 | Date currentDate = Calendar.getInstance().getTime(); 55 | 56 | if (currentDate.after(formattedEndingDate)) { 57 | mElectionStatusList.add("Finished"); 58 | mElectionStartDateList.add(formattedStartingDate.toString()); 59 | mElectionEndDateList.add(formattedEndingDate.toString()); 60 | mElectionNameList.add(singleElectionJsonObject.getString("name")); 61 | mIDList.add(singleElectionJsonObject.getString("_id")); 62 | mElectionDescriptionList.add(singleElectionJsonObject.getString("description")); 63 | } 64 | JSONArray candidatesJsonArray = singleElectionJsonObject.getJSONArray("candidates"); 65 | for (int j = 0; j < candidatesJsonArray.length(); j++) { 66 | mCandidateName.append(candidatesJsonArray.getString(j)).append("\n"); 67 | } 68 | mCandidatesList.add(mCandidateName.toString().trim()); 69 | } 70 | } catch (JSONException e) { 71 | e.printStackTrace(); 72 | } catch (ParseException e) { 73 | e.printStackTrace(); 74 | } 75 | 76 | ElectionsRecyclerAdapter electionsRecyclerAdapter = new ElectionsRecyclerAdapter(mIDList,this,mElectionNameList, mElectionDescriptionList, mElectionStartDateList, mElectionEndDateList, mElectionStatusList, mCandidatesList, "finished"); 77 | rvElectionDetails.setAdapter(electionsRecyclerAdapter); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/displayElections/PendingElectionsActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.displayElections; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.recyclerview.widget.LinearLayoutManager; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import android.os.Bundle; 8 | 9 | import org.aossie.agoraandroid.R; 10 | import org.aossie.agoraandroid.adapters.ElectionsRecyclerAdapter; 11 | import org.aossie.agoraandroid.createElection.ElectionDetailsSharedPrefs; 12 | import org.json.JSONArray; 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import java.text.ParseException; 17 | import java.text.SimpleDateFormat; 18 | import java.util.ArrayList; 19 | import java.util.Calendar; 20 | import java.util.Date; 21 | 22 | public class PendingElectionsActivity extends AppCompatActivity { 23 | private final ArrayList mElectionNameList = new ArrayList<>(); 24 | private final ArrayList mElectionDescriptionList = new ArrayList<>(); 25 | private final ArrayList mElectionStartDateList = new ArrayList<>(); 26 | private final ArrayList mElectionEndDateList = new ArrayList<>(); 27 | private final ArrayList mElectionStatusList = new ArrayList<>(); 28 | private final ArrayList mCandidatesList = new ArrayList<>(); 29 | private final ArrayList mIDList = new ArrayList<>(); 30 | 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_pending_elections); 36 | ElectionDetailsSharedPrefs electionDetailsSharedPrefs = new ElectionDetailsSharedPrefs(getApplicationContext()); 37 | RecyclerView rvElectionDetails = findViewById(R.id.rv_pending_elections); 38 | 39 | 40 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); 41 | rvElectionDetails.setLayoutManager(mLayoutManager); 42 | try { 43 | JSONObject jsonObject = new JSONObject(electionDetailsSharedPrefs.getElectionDetails()); 44 | JSONArray electionsJsonArray = jsonObject.getJSONArray("elections"); 45 | 46 | for (int i = 0; i < electionsJsonArray.length(); i++) { 47 | StringBuilder mCandidateName = new StringBuilder(); 48 | JSONObject singleElectionJsonObject = electionsJsonArray.getJSONObject(i); 49 | 50 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 51 | Date formattedStartingDate = formatter.parse(singleElectionJsonObject.getString("start")); 52 | Date formattedEndingDate = formatter.parse(singleElectionJsonObject.getString("end")); 53 | Date currentDate = Calendar.getInstance().getTime(); 54 | 55 | if (currentDate.before(formattedStartingDate)) { 56 | mElectionStatusList.add("Pending"); 57 | mElectionStartDateList.add(formattedStartingDate.toString()); 58 | mElectionEndDateList.add(formattedEndingDate.toString()); 59 | mElectionNameList.add(singleElectionJsonObject.getString("name")); 60 | mIDList.add(singleElectionJsonObject.getString("_id")); 61 | mElectionDescriptionList.add(singleElectionJsonObject.getString("description")); 62 | } 63 | JSONArray candidatesJsonArray = singleElectionJsonObject.getJSONArray("candidates"); 64 | for (int j = 0; j < candidatesJsonArray.length(); j++) { 65 | mCandidateName.append(candidatesJsonArray.getString(j)).append("\n"); 66 | } 67 | mCandidatesList.add(mCandidateName.toString().trim()); 68 | } 69 | } catch (JSONException e) { 70 | e.printStackTrace(); 71 | } catch (ParseException e) { 72 | e.printStackTrace(); 73 | } 74 | 75 | ElectionsRecyclerAdapter electionsRecyclerAdapter = new ElectionsRecyclerAdapter(mIDList,this,mElectionNameList, mElectionDescriptionList, mElectionStartDateList, mElectionEndDateList, mElectionStatusList, mCandidatesList, "pending"); 76 | rvElectionDetails.setAdapter(electionsRecyclerAdapter); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/displayElections/TotalElectionsActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.displayElections; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.recyclerview.widget.LinearLayoutManager; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import android.os.Bundle; 8 | 9 | import org.aossie.agoraandroid.R; 10 | import org.aossie.agoraandroid.adapters.ElectionsRecyclerAdapter; 11 | import org.aossie.agoraandroid.createElection.ElectionDetailsSharedPrefs; 12 | import org.json.JSONArray; 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import java.text.ParseException; 17 | import java.text.SimpleDateFormat; 18 | import java.util.ArrayList; 19 | import java.util.Calendar; 20 | import java.util.Date; 21 | 22 | public class TotalElectionsActivity extends AppCompatActivity { 23 | private final ArrayList mElectionNameList = new ArrayList<>(); 24 | private final ArrayList mElectionDescriptionList = new ArrayList<>(); 25 | private final ArrayList mElectionStartDateList = new ArrayList<>(); 26 | private final ArrayList mElectionEndDateList = new ArrayList<>(); 27 | private final ArrayList mElectionStatusList = new ArrayList<>(); 28 | private final ArrayList mCandidatesList = new ArrayList<>(); 29 | private final ArrayList mIDList = new ArrayList<>(); 30 | 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_total_elections); 36 | ElectionDetailsSharedPrefs electionDetailsSharedPrefs = new ElectionDetailsSharedPrefs(getApplicationContext()); 37 | RecyclerView rvElectionDetails = findViewById(R.id.rv_total_elections); 38 | 39 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); 40 | rvElectionDetails.setLayoutManager(mLayoutManager); 41 | try { 42 | JSONObject jsonObject = new JSONObject(electionDetailsSharedPrefs.getElectionDetails()); 43 | JSONArray electionsJsonArray = jsonObject.getJSONArray("elections"); 44 | 45 | for (int i = 0; i < electionsJsonArray.length(); i++) { 46 | StringBuilder mCandidateName = new StringBuilder(); 47 | JSONObject singleElectionJsonObject = electionsJsonArray.getJSONObject(i); 48 | mElectionNameList.add(singleElectionJsonObject.getString("name")); 49 | mIDList.add(singleElectionJsonObject.getString("_id")); 50 | mElectionDescriptionList.add(singleElectionJsonObject.getString("description")); 51 | 52 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 53 | Date formattedStartingDate = formatter.parse(singleElectionJsonObject.getString("start")); 54 | Date formattedEndingDate = formatter.parse(singleElectionJsonObject.getString("end")); 55 | mElectionStartDateList.add(formattedStartingDate.toString()); 56 | mElectionEndDateList.add(formattedEndingDate.toString()); 57 | Date currentDate = Calendar.getInstance().getTime(); 58 | if (currentDate.before(formattedStartingDate)) { 59 | mElectionStatusList.add("Pending"); 60 | } else if (currentDate.after(formattedStartingDate) && currentDate.before(formattedEndingDate)) { 61 | mElectionStatusList.add("Active"); 62 | } else if (currentDate.after(formattedEndingDate)) { 63 | mElectionStatusList.add("Finished"); 64 | } 65 | JSONArray candidatesJsonArray = singleElectionJsonObject.getJSONArray("candidates"); 66 | for (int j = 0; j < candidatesJsonArray.length(); j++) { 67 | mCandidateName.append(candidatesJsonArray.getString(j)).append("\n"); 68 | } 69 | mCandidatesList.add(mCandidateName.toString().trim()); 70 | 71 | 72 | } 73 | } catch (JSONException e) { 74 | e.printStackTrace(); 75 | } catch (ParseException e) { 76 | e.printStackTrace(); 77 | } 78 | 79 | ElectionsRecyclerAdapter electionsRecyclerAdapter = new ElectionsRecyclerAdapter(mIDList,this,mElectionNameList, mElectionDescriptionList, mElectionStartDateList, mElectionEndDateList, mElectionStatusList, mCandidatesList, "total"); 80 | rvElectionDetails.setAdapter(electionsRecyclerAdapter); 81 | 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/displayElections/VotersActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.displayElections; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.recyclerview.widget.LinearLayoutManager; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import android.os.Bundle; 8 | 9 | import org.aossie.agoraandroid.R; 10 | import org.aossie.agoraandroid.adapters.VotersRecyclerAdapter; 11 | import org.json.JSONArray; 12 | import org.json.JSONException; 13 | import org.json.JSONObject; 14 | 15 | import java.util.ArrayList; 16 | 17 | public class VotersActivity extends AppCompatActivity { 18 | private String voterResponse; 19 | private final ArrayList mVoterEmailList = new ArrayList<>(); 20 | private final ArrayList mVoterNameList = new ArrayList<>(); 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_voters); 26 | RecyclerView rvVotersDetails = findViewById(R.id.recycler_view_voters); 27 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); 28 | rvVotersDetails.setLayoutManager(mLayoutManager); 29 | 30 | 31 | if (getIntent().hasExtra("voters_response")) { 32 | voterResponse = getIntent().getStringExtra("voters_response"); 33 | } 34 | try { 35 | JSONObject jsonObject = new JSONObject(voterResponse); 36 | JSONArray ballotJsonArray = jsonObject.getJSONArray("voters"); 37 | for (int i = 0; i < ballotJsonArray.length(); i++) { 38 | JSONObject ballotJsonObject = ballotJsonArray.getJSONObject(i); 39 | 40 | mVoterEmailList.add(ballotJsonObject.getString("email")); 41 | mVoterNameList.add(ballotJsonObject.getString("name")); 42 | 43 | } 44 | 45 | } catch (JSONException e) { 46 | e.printStackTrace(); 47 | } 48 | VotersRecyclerAdapter votersRecyclerAdapter = new VotersRecyclerAdapter(mVoterNameList, mVoterEmailList); 49 | rvVotersDetails.setAdapter(votersRecyclerAdapter); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/forgotPassword/ForgotPasswordSend.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.forgotPassword; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | import com.google.android.material.textfield.TextInputLayout; 10 | 11 | import org.aossie.agoraandroid.R; 12 | public class ForgotPasswordSend extends AppCompatActivity { 13 | 14 | private ForgotPasswordViewModel forgotPasswordViewModel; 15 | private TextInputLayout mUserNameEditText; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_forgot_password_send); 21 | forgotPasswordViewModel = new ForgotPasswordViewModel(getApplication(),this); 22 | Button sendLinkButton = findViewById(R.id.button_send_link); 23 | mUserNameEditText = findViewById(R.id.edit_text_user_name); 24 | sendLinkButton.setOnClickListener(new View.OnClickListener() { 25 | @Override 26 | public void onClick(View v) { 27 | String userName = mUserNameEditText.getEditText().getText().toString().trim(); 28 | if (userName.isEmpty()) { 29 | mUserNameEditText.setError("Please Enter User Name"); 30 | } else { 31 | forgotPasswordViewModel.sendForgotPassLink(userName); 32 | } 33 | } 34 | }); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/forgotPassword/ForgotPasswordViewModel.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.forgotPassword; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.widget.Toast; 6 | 7 | import androidx.annotation.NonNull; 8 | import androidx.lifecycle.AndroidViewModel; 9 | 10 | import net.steamcrafted.loadtoast.LoadToast; 11 | 12 | import org.aossie.agoraandroid.remote.APIService; 13 | import org.aossie.agoraandroid.remote.RetrofitClient; 14 | 15 | 16 | import retrofit2.Call; 17 | import retrofit2.Callback; 18 | import retrofit2.Response; 19 | 20 | public class ForgotPasswordViewModel extends AndroidViewModel { 21 | private LoadToast loadToast; 22 | private Context context; 23 | ForgotPasswordViewModel(@NonNull Application application, Context context) { 24 | super(application); 25 | this.context=context; 26 | } 27 | 28 | void sendForgotPassLink(String userName) { 29 | loadToast = new LoadToast(context); 30 | loadToast.setText("Processing"); 31 | loadToast.show(); 32 | 33 | APIService apiService = RetrofitClient.getAPIService(); 34 | Call forgotPasswordResponse = apiService.sendForgotPassword(userName); 35 | forgotPasswordResponse.enqueue(new Callback() { 36 | @Override 37 | public void onResponse(Call call, Response response) { 38 | loadToast.success(); 39 | Toast.makeText(getApplication(), "Link Sent, Please Check Your Emails", Toast.LENGTH_SHORT).show(); 40 | } 41 | 42 | @Override 43 | public void onFailure(Call call, Throwable t) { 44 | loadToast.error(); 45 | Toast.makeText(getApplication(), "Something Went Wrong Please Try Again Later", Toast.LENGTH_SHORT).show(); 46 | } 47 | }); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/home/AboutFragment.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.home; 2 | 3 | 4 | import android.os.Bundle; 5 | 6 | import androidx.fragment.app.Fragment; 7 | 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import org.aossie.agoraandroid.R; 13 | 14 | /** 15 | * A simple {@link Fragment} subclass. 16 | */ 17 | public class AboutFragment extends Fragment { 18 | 19 | 20 | public AboutFragment() { 21 | // Required empty public constructor 22 | } 23 | 24 | 25 | @Override 26 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 27 | Bundle savedInstanceState) { 28 | // Inflate the layout for this fragment 29 | return inflater.inflate(R.layout.fragment_about, container, false); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/home/ContactUsFragment.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.home; 2 | 3 | 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import androidx.fragment.app.Fragment; 11 | 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.Button; 16 | 17 | import org.aossie.agoraandroid.R; 18 | 19 | /** 20 | * A simple {@link Fragment} subclass. 21 | */ 22 | @SuppressWarnings("SpellCheckingInspection") 23 | public class ContactUsFragment extends Fragment { 24 | 25 | 26 | public ContactUsFragment() { 27 | } 28 | 29 | 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 32 | Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_contact_us, null); 34 | Button gitlabBtn = view.findViewById(R.id.button_gitlab); 35 | Button gitterBtn = view.findViewById(R.id.button_gitter); 36 | gitterBtn.setOnClickListener(new View.OnClickListener() { 37 | @Override 38 | public void onClick(View v) { 39 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://gitter.im/aossie/home"))); 40 | } 41 | }); 42 | gitlabBtn.setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://gitlab.com/aossie"))); 46 | } 47 | }); 48 | 49 | return view; 50 | } 51 | 52 | @Override 53 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 54 | super.onViewCreated(view, savedInstanceState); 55 | 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/home/HomeActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.home; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.drawerlayout.widget.DrawerLayout; 5 | import androidx.navigation.Navigation; 6 | import androidx.navigation.ui.NavigationUI; 7 | 8 | import android.content.Intent; 9 | import android.os.Bundle; 10 | import android.view.Menu; 11 | import android.view.MenuInflater; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.widget.TextView; 15 | 16 | import com.google.android.material.navigation.NavigationView; 17 | 18 | import org.aossie.agoraandroid.R; 19 | import org.aossie.agoraandroid.utilities.SharedPrefs; 20 | 21 | 22 | public class HomeActivity extends AppCompatActivity { 23 | private DrawerLayout drawerLayout; 24 | private HomeViewModel homeViewModel; 25 | private SharedPrefs sharedPrefs; 26 | 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_home); 32 | homeViewModel = new HomeViewModel(getApplication(), this); 33 | sharedPrefs = new SharedPrefs(getApplicationContext()); 34 | androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar); 35 | NavigationView navView = findViewById(R.id.nav_view); 36 | 37 | View hView = navView.getHeaderView(0); 38 | TextView nav_user_name = hView.findViewById(R.id.header_user_name); 39 | TextView nav_user_email = hView.findViewById(R.id.header_email); 40 | nav_user_name.setText(sharedPrefs.getUserName()); 41 | nav_user_email.setText(sharedPrefs.getEmail()); 42 | 43 | 44 | drawerLayout = findViewById(R.id.drawer_layout); 45 | 46 | setSupportActionBar(toolbar); 47 | 48 | Navigation.findNavController(this, R.id.fragment);// navController 49 | 50 | NavigationUI.setupWithNavController(navView, Navigation.findNavController(this, R.id.fragment)); 51 | 52 | NavigationUI.setupActionBarWithNavController(this, Navigation.findNavController(this, R.id.fragment), 53 | drawerLayout); 54 | } 55 | 56 | @Override 57 | public boolean onSupportNavigateUp() { 58 | return NavigationUI.navigateUp(Navigation.findNavController(this, R.id.fragment), 59 | drawerLayout); 60 | } 61 | 62 | @Override 63 | public boolean onCreateOptionsMenu(Menu menu) { 64 | MenuInflater inflater = getMenuInflater(); 65 | inflater.inflate(R.menu.option_menu, menu); 66 | return true; 67 | } 68 | 69 | @Override 70 | public boolean onOptionsItemSelected(MenuItem item) { 71 | // Handle item selection 72 | if (item.getItemId() == R.id.action_logout) { 73 | homeViewModel.doLogout(sharedPrefs.getToken()); 74 | return true; 75 | } 76 | return super.onOptionsItemSelected(item); 77 | } 78 | 79 | @Override 80 | public void onBackPressed(){ 81 | Intent intent = new Intent(Intent.ACTION_MAIN); 82 | intent.addCategory(Intent.CATEGORY_HOME); 83 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 84 | startActivity(intent); 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/home/HomeViewModel.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.home; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.widget.Toast; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.lifecycle.AndroidViewModel; 10 | 11 | import net.steamcrafted.loadtoast.LoadToast; 12 | 13 | import org.aossie.agoraandroid.main.MainActivity; 14 | import org.aossie.agoraandroid.remote.APIService; 15 | import org.aossie.agoraandroid.remote.RetrofitClient; 16 | import org.aossie.agoraandroid.utilities.SharedPrefs; 17 | 18 | import retrofit2.Call; 19 | import retrofit2.Callback; 20 | import retrofit2.Response; 21 | 22 | class HomeViewModel extends AndroidViewModel { 23 | private final Context context; 24 | private LoadToast loadToast; 25 | private final SharedPrefs sharedPrefs = new SharedPrefs(getApplication()); 26 | 27 | 28 | public HomeViewModel(@NonNull Application application, Context context) { 29 | super(application); 30 | this.context = context; 31 | } 32 | 33 | void doLogout(String token) { 34 | loadToast = new LoadToast(context); 35 | loadToast.setText("Logging out"); 36 | loadToast.show(); 37 | APIService apiService = RetrofitClient.getAPIService(); 38 | Call logoutResponse = apiService.logout(token); 39 | logoutResponse.enqueue(new Callback() { 40 | @Override 41 | public void onResponse(Call call, Response response) { 42 | if (response.message().equals("OK")) { 43 | loadToast.success(); 44 | Toast.makeText(getApplication(), "Logged Out Successfully", Toast.LENGTH_SHORT).show(); 45 | sharedPrefs.clearLogin(); 46 | context.startActivity(new Intent(getApplication(), MainActivity.class)); 47 | } 48 | } 49 | 50 | @Override 51 | public void onFailure(Call call, Throwable t) { 52 | loadToast.error(); 53 | Toast.makeText(getApplication(), "Something Went Wrong Please Try Again Later", Toast.LENGTH_SHORT).show(); 54 | } 55 | }); 56 | 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/home/ProfileFragment.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.home; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.util.Log; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Button; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | 13 | import androidx.annotation.NonNull; 14 | import androidx.annotation.Nullable; 15 | import androidx.fragment.app.Fragment; 16 | 17 | import com.google.android.material.textfield.TextInputLayout; 18 | 19 | import net.steamcrafted.loadtoast.LoadToast; 20 | 21 | import org.aossie.agoraandroid.R; 22 | import org.aossie.agoraandroid.utilities.SharedPrefs; 23 | import org.aossie.agoraandroid.remote.APIService; 24 | import org.aossie.agoraandroid.remote.RetrofitClient; 25 | import org.json.JSONException; 26 | import org.json.JSONObject; 27 | 28 | import retrofit2.Call; 29 | import retrofit2.Callback; 30 | import retrofit2.Response; 31 | 32 | /** 33 | * A simple {@link Fragment} subclass. 34 | */ 35 | public class ProfileFragment extends Fragment { 36 | private TextInputLayout mNewPAss, mConfirmPass; 37 | private LoadToast loadToast; 38 | 39 | @Override 40 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 41 | Bundle savedInstanceState) { 42 | SharedPrefs sharedPrefs = new SharedPrefs(getActivity()); 43 | View view = inflater.inflate(R.layout.fragment_profile, null); 44 | TextView userName = view.findViewById(R.id.text_user_name); 45 | TextView emailId = view.findViewById(R.id.text_email_id); 46 | TextView fullName = view.findViewById(R.id.text_full_name); 47 | final String token = sharedPrefs.getToken(); 48 | Button mChangePassButton = view.findViewById(R.id.button_change_password); 49 | mNewPAss = view.findViewById(R.id.textInputLayout_new_password); 50 | mConfirmPass = view.findViewById(R.id.textInputLayout_confirm_password); 51 | mChangePassButton.setOnClickListener(new View.OnClickListener() { 52 | @Override 53 | public void onClick(View v) { 54 | String newPass = mNewPAss.getEditText().getText().toString().trim(); 55 | String confirmPass = mConfirmPass.getEditText().getText().toString().trim(); 56 | if (newPass.equals(confirmPass)) 57 | doChangePasswordRequest(confirmPass, token); 58 | else mConfirmPass.setError("Password Does Not Matches"); 59 | } 60 | }); 61 | String username = sharedPrefs.getUserName(); 62 | String email = sharedPrefs.getEmail(); 63 | String userFullName = sharedPrefs.getfullName(); 64 | 65 | userName.setText(username); 66 | emailId.setText(email); 67 | fullName.setText(userFullName); 68 | return view; 69 | } 70 | 71 | @Override 72 | 73 | public void onViewCreated(@NonNull View view, @Nullable Bundle 74 | savedInstanceState) { 75 | super.onViewCreated(view, savedInstanceState); 76 | 77 | } 78 | 79 | private void doChangePasswordRequest(String password, String token) { 80 | loadToast = new LoadToast(getActivity()); 81 | loadToast.setText("Changing Password"); 82 | loadToast.show(); 83 | final JSONObject jsonObject = new JSONObject(); 84 | try { 85 | 86 | jsonObject.put("password", password); 87 | 88 | } catch (JSONException e) { 89 | e.printStackTrace(); 90 | } 91 | APIService apiService = RetrofitClient.getAPIService(); 92 | Call changePassResponse = apiService.changePassword(jsonObject.toString(), token); 93 | changePassResponse.enqueue(new Callback() { 94 | @Override 95 | public void onResponse(Call call, Response response) { 96 | if (response.message().equals("OK")) { 97 | loadToast.success(); 98 | Toast.makeText(getActivity(), "Password Changed Successfully", Toast.LENGTH_SHORT).show(); 99 | 100 | 101 | } else { 102 | Log.d("TAG", "onResponse:" + response.body()); 103 | loadToast.error(); 104 | Toast.makeText(getActivity(), "Wrong User Name or Password", Toast.LENGTH_SHORT).show(); 105 | } 106 | } 107 | 108 | @Override 109 | public void onFailure(Call call, Throwable t) { 110 | loadToast.error(); 111 | Toast.makeText(getActivity(), "Something went wrong please try again", Toast.LENGTH_SHORT).show(); 112 | 113 | } 114 | }); 115 | 116 | } 117 | } -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/home/ReportBugFragment.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.home; 2 | 3 | 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import androidx.fragment.app.Fragment; 11 | 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.Button; 16 | 17 | import org.aossie.agoraandroid.R; 18 | 19 | /** 20 | * A simple {@link Fragment} subclass. 21 | */ 22 | public class ReportBugFragment extends Fragment { 23 | 24 | 25 | public ReportBugFragment() { 26 | } 27 | 28 | 29 | @Override 30 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 31 | Bundle savedInstanceState) { 32 | View view = inflater.inflate(R.layout.fragment_report_bug, null); 33 | Button openConsole = view.findViewById(R.id.button_report_bug); 34 | openConsole.setOnClickListener(new View.OnClickListener() { 35 | @Override 36 | public void onClick(View v) { 37 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://gitlab.com/aossie/agora-android/issues/new"))); 38 | 39 | } 40 | }); 41 | return view; 42 | } 43 | 44 | @Override 45 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 46 | super.onViewCreated(view, savedInstanceState); 47 | 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/home/ShareWithOthersFragment.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.home; 2 | 3 | 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | 7 | import androidx.fragment.app.Fragment; 8 | 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Button; 13 | 14 | import org.aossie.agoraandroid.R; 15 | 16 | import static com.facebook.FacebookSdk.getApplicationContext; 17 | 18 | /** 19 | * A simple {@link Fragment} subclass. 20 | */ 21 | public class ShareWithOthersFragment extends Fragment { 22 | 23 | public ShareWithOthersFragment() { 24 | } 25 | 26 | 27 | @Override 28 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 29 | Bundle savedInstanceState) { 30 | View view = inflater.inflate(R.layout.fragment_share_with_others, container, false); 31 | Button shareBtn = view.findViewById(R.id.button_share_now); 32 | shareBtn.setOnClickListener(new View.OnClickListener() { 33 | @Override 34 | public void onClick(View v) { 35 | Intent shareIntent = new Intent(Intent.ACTION_SEND); 36 | 37 | //Get the app link in the Play Store 38 | final String appPackageName = getApplicationContext().getPackageName(); 39 | String strAppLink; 40 | try { 41 | strAppLink = "https://play.google.com/store/apps/details?id=" + appPackageName; 42 | } catch (android.content.ActivityNotFoundException activityNotFound) { 43 | strAppLink = "https://play.google.com/store/apps/details?id=" + appPackageName; 44 | } 45 | 46 | // This is the sharing part 47 | shareIntent.setType("text/link"); 48 | String shareBody = "Hey! Download Agora Vote application for Free and create Elections right now" + 49 | "\n" + "" + strAppLink; 50 | String shareSub = "APP NAME/TITLE"; 51 | shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSub); 52 | shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody); 53 | startActivity(Intent.createChooser(shareIntent, "Share Agora Vote Using")); 54 | } 55 | 56 | }); 57 | return view; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/inviteVoters/InviteVotersActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.inviteVoters; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import androidx.recyclerview.widget.ItemTouchHelper; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | 9 | import android.os.Bundle; 10 | import android.view.View; 11 | import android.widget.Button; 12 | 13 | import com.google.android.material.textfield.TextInputLayout; 14 | 15 | import org.aossie.agoraandroid.R; 16 | import org.aossie.agoraandroid.adapters.VoterRecyclerAdapter; 17 | import org.json.JSONException; 18 | 19 | import java.util.ArrayList; 20 | 21 | public class InviteVotersActivity extends AppCompatActivity { 22 | private InviteVotersViewModel inviteVotersViewModel; 23 | private VoterRecyclerAdapter voterRecyclerAdapter; 24 | private TextInputLayout mVoterNameTextInput, mVoterEmailTextInput; 25 | private final ArrayList mVoterNames = new ArrayList<>(); 26 | private final ArrayList mVoterEmails = new ArrayList<>(); 27 | 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_invite_voters); 33 | inviteVotersViewModel = new InviteVotersViewModel(getApplication(), this); 34 | 35 | mVoterNameTextInput = findViewById(R.id.text_input_voter_name); 36 | mVoterEmailTextInput = findViewById(R.id.text_input_voter_email); 37 | Button mAddVoters = findViewById(R.id.button_add_voter); 38 | Button mInviteVotes = findViewById(R.id.button_invite_voter); 39 | RecyclerView mRecyclerView = findViewById(R.id.recycler_view_voters); 40 | 41 | voterRecyclerAdapter = new VoterRecyclerAdapter(mVoterNames, mVoterEmails); 42 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); 43 | new ItemTouchHelper(itemTouchHelperCallback).attachToRecyclerView(mRecyclerView); 44 | mRecyclerView.setAdapter(voterRecyclerAdapter); 45 | 46 | 47 | mInviteVotes.setOnClickListener(new View.OnClickListener() { 48 | @Override 49 | public void onClick(View v) { 50 | try { 51 | if (getIntent().hasExtra("id") && getIntent().hasExtra("token")) { 52 | String id = getIntent().getStringExtra("id"); 53 | String token = getIntent().getStringExtra("token"); 54 | inviteVotersViewModel.inviteVoters(mVoterNames, mVoterEmails, id, token); 55 | } 56 | } catch (JSONException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | }); 61 | 62 | mAddVoters.setOnClickListener(new View.OnClickListener() { 63 | @Override 64 | public void onClick(View v) { 65 | final String name = mVoterNameTextInput.getEditText().getText().toString(); 66 | final String email = mVoterEmailTextInput.getEditText().getText().toString(); 67 | if (name.isEmpty()) 68 | mVoterNameTextInput.setError("Please enter Voter's Name"); 69 | else mVoterNameTextInput.setError(null); 70 | 71 | if (email.isEmpty()) { 72 | mVoterEmailTextInput.setError("Please enter Voter's Email"); 73 | } else { 74 | mVoterEmailTextInput.setError(null); 75 | addCandidate(name, email); 76 | } 77 | } 78 | }); 79 | } 80 | 81 | private void addCandidate(String voterName, String voterEmail) { 82 | mVoterNames.add(voterName); 83 | mVoterEmails.add(voterEmail); 84 | voterRecyclerAdapter.notifyDataSetChanged(); 85 | mVoterNameTextInput.getEditText().setText(""); 86 | mVoterEmailTextInput.getEditText().setText(""); 87 | 88 | } 89 | 90 | 91 | private final ItemTouchHelper.SimpleCallback itemTouchHelperCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT) { 92 | @Override 93 | public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { 94 | return false; 95 | } 96 | 97 | @Override 98 | public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { 99 | mVoterNames.remove(viewHolder.getAdapterPosition()); 100 | mVoterEmails.remove(viewHolder.getAdapterPosition()); 101 | voterRecyclerAdapter.notifyDataSetChanged(); 102 | 103 | } 104 | }; 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/inviteVoters/InviteVotersViewModel.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.inviteVoters; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.util.Log; 7 | import android.widget.Toast; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.lifecycle.AndroidViewModel; 11 | 12 | import net.steamcrafted.loadtoast.LoadToast; 13 | 14 | import org.aossie.agoraandroid.home.HomeActivity; 15 | import org.aossie.agoraandroid.remote.APIService; 16 | import org.aossie.agoraandroid.remote.RetrofitClient; 17 | import org.json.JSONArray; 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | import java.util.ArrayList; 22 | 23 | import retrofit2.Call; 24 | import retrofit2.Callback; 25 | import retrofit2.Response; 26 | 27 | class InviteVotersViewModel extends AndroidViewModel { 28 | private final Context context; 29 | private LoadToast loadToast; 30 | 31 | public InviteVotersViewModel(@NonNull Application application, Context context) { 32 | super(application); 33 | this.context = context; 34 | } 35 | 36 | public void inviteVoters(ArrayList mVoterNames, ArrayList mVoterEmails, String id, String token) throws JSONException { 37 | loadToast = new LoadToast(context); 38 | loadToast.setText("Inviting Voters"); 39 | loadToast.show(); 40 | JSONArray jsonArray = new JSONArray(); 41 | for (int i = 0; i < mVoterEmails.size(); i++) { 42 | JSONObject jsonObject = new JSONObject(); 43 | jsonObject.put("name", mVoterNames.get(i)); 44 | jsonObject.put("email", mVoterEmails.get(i)); 45 | jsonArray.put(jsonObject); 46 | Log.d("TAG", "inviteVoters: " + jsonArray); 47 | sendVoters(id, token, jsonArray); 48 | } 49 | } 50 | 51 | private void sendVoters(String id, String token, JSONArray jsonArray) { 52 | APIService apiService = RetrofitClient.getAPIService(); 53 | Call sendVotersResponse = apiService.sendVoters(token, id, jsonArray.toString()); 54 | sendVotersResponse.enqueue(new Callback() { 55 | @Override 56 | public void onResponse(Call call, Response response) { 57 | if (response.message().equals("OK")) { 58 | loadToast.success(); 59 | Toast.makeText(context, "Voters Added Successfully", Toast.LENGTH_SHORT).show(); 60 | context.startActivity(new Intent(context, HomeActivity.class)); 61 | } 62 | else if(response.message().equals("Internal Server Error")){ 63 | loadToast.error(); 64 | Toast.makeText(context, "Internal server error", Toast.LENGTH_SHORT).show(); 65 | } 66 | } 67 | 68 | @Override 69 | public void onFailure(Call call, Throwable t) { 70 | loadToast.error(); 71 | Toast.makeText(getApplication(), "Something went wrong please try again", Toast.LENGTH_SHORT).show(); 72 | } 73 | }); 74 | 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/logIn/LogInActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.logIn; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.TextView; 10 | 11 | import com.google.android.material.textfield.TextInputLayout; 12 | 13 | import org.aossie.agoraandroid.R; 14 | import org.aossie.agoraandroid.forgotPassword.ForgotPasswordSend; 15 | 16 | @SuppressWarnings("ConstantConditions") 17 | public class LogInActivity extends AppCompatActivity { 18 | private TextInputLayout mLoginUserName, mLoginPassword; 19 | private LoginViewModel loginViewModel; 20 | 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_log_in); 26 | loginViewModel = new LoginViewModel(getApplication(), this); 27 | 28 | 29 | mLoginPassword = findViewById(R.id.logInPassword); 30 | mLoginUserName = findViewById(R.id.logInUserName); 31 | Button mFinalLoginButton = findViewById(R.id.finalLogInButton); 32 | TextView mForgotPassword = findViewById(R.id.text_view_forgot_password); 33 | mForgotPassword.setOnClickListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View v) { 36 | startActivity(new Intent(LogInActivity.this, ForgotPasswordSend.class)); 37 | } 38 | }); 39 | 40 | mFinalLoginButton.setOnClickListener(new View.OnClickListener() { 41 | @Override 42 | public void onClick(View v) { 43 | final String userName = mLoginUserName.getEditText().getText().toString().trim(); 44 | final String userPass = mLoginPassword.getEditText().getText().toString().trim(); 45 | 46 | if (userName.isEmpty()) 47 | mLoginUserName.setError("Please enter User Name"); 48 | else mLoginUserName.setError(null); 49 | 50 | if (userPass.isEmpty()) { 51 | mLoginPassword.setError("Please enter password"); 52 | } else { 53 | mLoginPassword.setError(null); 54 | loginViewModel.logInRequest(userName, userPass); 55 | } 56 | } 57 | 58 | 59 | }); 60 | 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/main/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.main; 2 | 3 | import androidx.annotation.Nullable; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.Toast; 12 | 13 | import com.facebook.AccessToken; 14 | import com.facebook.AccessTokenTracker; 15 | import com.facebook.CallbackManager; 16 | import com.facebook.FacebookCallback; 17 | import com.facebook.FacebookException; 18 | import com.facebook.FacebookSdk; 19 | 20 | import com.facebook.login.LoginManager; 21 | import com.facebook.login.LoginResult; 22 | 23 | import org.aossie.agoraandroid.R; 24 | import org.aossie.agoraandroid.logIn.LoginViewModel; 25 | import org.aossie.agoraandroid.signUp.SignUpActivity; 26 | import org.aossie.agoraandroid.logIn.LogInActivity; 27 | 28 | import java.util.Arrays; 29 | 30 | public class MainActivity extends AppCompatActivity { 31 | private CallbackManager callbackManager; 32 | private LoginViewModel loginViewModel; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | Button signIn = findViewById(R.id.signin); 39 | Button signUp = findViewById(R.id.signup); 40 | loginViewModel = new LoginViewModel(getApplication(), this); 41 | FacebookSdk.sdkInitialize(this.getApplicationContext()); 42 | 43 | callbackManager = CallbackManager.Factory.create(); 44 | Button facebookLogin = findViewById(R.id.button_facebook_login); 45 | 46 | LoginManager.getInstance().registerCallback(callbackManager, 47 | new FacebookCallback() { 48 | @Override 49 | public void onSuccess(LoginResult loginResult) { 50 | Log.d("Success", "Login"); 51 | } 52 | 53 | @Override 54 | public void onCancel() { 55 | Toast.makeText(MainActivity.this, "Login Cancel", Toast.LENGTH_LONG).show(); 56 | } 57 | 58 | @Override 59 | public void onError(FacebookException exception) { 60 | Toast.makeText(MainActivity.this, exception.getMessage(), Toast.LENGTH_LONG).show(); 61 | } 62 | }); 63 | 64 | facebookLogin.setOnClickListener(new View.OnClickListener() { 65 | @Override 66 | public void onClick(View view) { 67 | LoginManager.getInstance().logInWithReadPermissions(MainActivity.this, Arrays.asList("public_profile", "user_friends")); 68 | } 69 | }); 70 | signIn.setOnClickListener(new View.OnClickListener() { 71 | @Override 72 | public void onClick(View v) { 73 | Intent logInIntent = new Intent(MainActivity.this, LogInActivity.class); 74 | startActivity(logInIntent); 75 | } 76 | }); 77 | signUp.setOnClickListener(new View.OnClickListener() { 78 | @Override 79 | public void onClick(View v) { 80 | Intent signUpIntent = new Intent(MainActivity.this, SignUpActivity.class); 81 | startActivity(signUpIntent); 82 | } 83 | }); 84 | } 85 | 86 | 87 | @Override 88 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 89 | callbackManager.onActivityResult(requestCode, resultCode, data); 90 | super.onActivityResult(requestCode, resultCode, data); 91 | } 92 | 93 | AccessTokenTracker accessTokenTracker = new AccessTokenTracker() { 94 | @Override 95 | protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { 96 | if (currentAccessToken == null) { 97 | Toast.makeText(MainActivity.this, "User Logged Out", Toast.LENGTH_SHORT).show(); 98 | } else { 99 | String facebookAccessToken = currentAccessToken.getToken(); 100 | loginViewModel.facebookLogInRequest(facebookAccessToken); 101 | } 102 | } 103 | }; 104 | 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/remote/APIService.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.remote; 2 | 3 | 4 | import retrofit2.Call; 5 | import retrofit2.http.Body; 6 | import retrofit2.http.DELETE; 7 | import retrofit2.http.GET; 8 | import retrofit2.http.Header; 9 | import retrofit2.http.Headers; 10 | import retrofit2.http.POST; 11 | import retrofit2.http.Path; 12 | 13 | @SuppressWarnings("SpellCheckingInspection") 14 | public interface APIService { 15 | //POST Request For SignUp 16 | @Headers({ 17 | "Accept: application/json", 18 | "Content-Type: application/json" 19 | }) 20 | @POST("auth/signup") 21 | Call createUser(@Body String body); 22 | 23 | //POST request for LogIn 24 | @Headers({ 25 | "Accept: application/json", 26 | "Content-Type: application/json" 27 | }) 28 | 29 | @POST("auth/login") 30 | Call logIn(@Body String body); 31 | 32 | 33 | //POST request to change password 34 | @Headers({ 35 | "Accept: application/json", 36 | "Content-Type: application/json" 37 | }) 38 | 39 | @POST("user/changePassword") 40 | Call changePassword(@Body String body, @Header("X-Auth-Token") String authToken); 41 | 42 | 43 | //POST request to create a new election 44 | @Headers({ 45 | "Accept: application/json", 46 | "Content-Type: application/json" 47 | }) 48 | @POST("election") 49 | Call createElection(@Body String body, @Header("X-Auth-Token") String authToken); 50 | 51 | 52 | //POST Request ToSend Link Of Forgot Password 53 | @POST("auth/forgotPassword/send/{userName}") 54 | Call sendForgotPassword(@Path("userName") String userName); 55 | 56 | 57 | //GET Request To Perform Logout 58 | @Headers({ 59 | "Accept: application/json", 60 | "Content-Type: application/json" 61 | }) 62 | @GET("user/logout") 63 | Call logout(@Header("X-Auth-Token") String authToken); 64 | 65 | 66 | //GET Request To Get Data of All Elections 67 | @Headers({ 68 | "Accept: application/json", 69 | "Content-Type: application/json" 70 | }) 71 | @GET("election") 72 | Call getAllElections(@Header("X-Auth-Token") String authToken); 73 | 74 | //GET request to log in via facebook Access Token 75 | @Headers({ 76 | "Accept: application/json", 77 | "Content-Type: application/json" 78 | }) 79 | @GET("auth/authenticate/facebook") 80 | Call facebookLogin(@Header("Access-Token") String accessToken); 81 | 82 | 83 | //GET request to get user's data 84 | @Headers({ 85 | "Accept: application/json", 86 | "Content-Type: application/json" 87 | }) 88 | @GET("user") 89 | Call getUserData(@Header("X-Auth-Token") String authToken); 90 | 91 | //DELETE election with specified id 92 | @Headers({ 93 | "Accept: application/json", 94 | "Content-Type: application/json" 95 | }) 96 | @DELETE("election/{id}") 97 | Call deleteElection(@Header("X-Auth-Token") String authToken, @Path("id") String id); 98 | 99 | //GET Ballots for election with specified id 100 | @Headers({ 101 | "Accept: application/json", 102 | "Content-Type: application/json" 103 | }) 104 | @GET("election/{id}/ballots") 105 | Call getBallot(@Header("X-Auth-Token") String authToken, @Path("id") String id); 106 | 107 | //GET Voters for election with specified id 108 | @Headers({ 109 | "Accept: application/json", 110 | "Content-Type: application/json" 111 | }) 112 | @GET("election/{id}/voters") 113 | Call getVoters(@Header("X-Auth-Token") String authToken, @Path("id") String id); 114 | 115 | //POST the list of voters to election 116 | @Headers({ 117 | "Accept: application/json", 118 | "Content-Type: application/json" 119 | }) 120 | @POST("election/{id}/voters") 121 | Call sendVoters(@Header("X-Auth-Token") String authToken, @Path("id") String id, @Body String body); 122 | 123 | //GET Result for election with specified id 124 | @Headers({ 125 | "Accept: application/json", 126 | "Content-Type: application/json" 127 | }) 128 | @GET("result/{id}") 129 | Call getResult(@Header("X-Auth-Token") String authToken, @Path("id") String id); 130 | 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/remote/RetrofitClient.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.remote; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import retrofit2.Retrofit; 6 | import retrofit2.converter.gson.GsonConverterFactory; 7 | import retrofit2.converter.scalars.ScalarsConverterFactory; 8 | 9 | 10 | public class RetrofitClient { 11 | 12 | 13 | private static final String BASE_URL = "https://agora-rest-api.herokuapp.com/api/v1/"; 14 | 15 | private static Retrofit getRetrofitInstance() { 16 | 17 | Gson gson = new GsonBuilder().setLenient().create(); 18 | 19 | return new Retrofit.Builder() 20 | .baseUrl(BASE_URL) 21 | .addConverterFactory(ScalarsConverterFactory.create()) 22 | .addConverterFactory(GsonConverterFactory 23 | .create(gson)) 24 | .build(); 25 | 26 | } 27 | 28 | 29 | public static APIService getAPIService() { 30 | return getRetrofitInstance().create(APIService.class); 31 | } 32 | 33 | 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/result/ResultActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.result; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.os.Bundle; 6 | import android.widget.TextView; 7 | 8 | import com.github.mikephil.charting.charts.PieChart; 9 | import com.github.mikephil.charting.components.Description; 10 | import com.github.mikephil.charting.data.PieData; 11 | import com.github.mikephil.charting.data.PieDataSet; 12 | import com.github.mikephil.charting.data.PieEntry; 13 | import com.github.mikephil.charting.utils.ColorTemplate; 14 | 15 | import org.aossie.agoraandroid.R; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public class ResultActivity extends AppCompatActivity { 21 | private final List value = new ArrayList<>(); 22 | private String mWinnerName; 23 | private int numerator, denominator; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_result); 29 | TextView winnerName = findViewById(R.id.text_view_winner_name); 30 | 31 | 32 | if (getIntent().hasExtra("name") && getIntent().hasExtra("numerator") && getIntent().hasExtra("denominator")) { 33 | mWinnerName = getIntent().getStringExtra("name"); 34 | numerator = Integer.parseInt(getIntent().getStringExtra("numerator")); 35 | denominator = Integer.parseInt(getIntent().getStringExtra("denominator")); 36 | } 37 | PieChart pieChart = findViewById(R.id.pie_chart); 38 | pieChart.setUsePercentValues(true); 39 | 40 | Description description = new Description(); 41 | description.setText("Election Result in percentage"); 42 | pieChart.setDescription(description); 43 | 44 | value.add(new PieEntry(numerator, mWinnerName)); 45 | value.add(new PieEntry(denominator, "Others")); 46 | 47 | PieDataSet pieDataSet = new PieDataSet(value, ""); 48 | PieData pieData = new PieData(pieDataSet); 49 | pieChart.setData(pieData); 50 | pieDataSet.setColors(ColorTemplate.MATERIAL_COLORS); 51 | pieChart.animateXY(1400, 1400); 52 | winnerName.setText(mWinnerName); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/result/ResultViewModel.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.result; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.widget.Toast; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.lifecycle.AndroidViewModel; 10 | 11 | import net.steamcrafted.loadtoast.LoadToast; 12 | 13 | import org.aossie.agoraandroid.remote.APIService; 14 | import org.aossie.agoraandroid.remote.RetrofitClient; 15 | import org.json.JSONArray; 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | 19 | import retrofit2.Call; 20 | import retrofit2.Callback; 21 | import retrofit2.Response; 22 | 23 | public class ResultViewModel extends AndroidViewModel { 24 | private final Context context; 25 | private LoadToast loadToast; 26 | 27 | public ResultViewModel(@NonNull Application application, Context context) { 28 | super(application); 29 | this.context = context; 30 | } 31 | 32 | public void getResult(String token, String id) { 33 | loadToast = new LoadToast(context); 34 | loadToast.setText("Getting Results"); 35 | loadToast.show(); 36 | APIService apiService = RetrofitClient.getAPIService(); 37 | Call getResultResponse = apiService.getResult(token, id); 38 | getResultResponse.enqueue(new Callback() { 39 | @Override 40 | public void onResponse(Call call, Response response) { 41 | if (response.message().equals("OK")) { 42 | loadToast.success(); 43 | try { 44 | JSONArray jsonArray = new JSONArray(response.body()); 45 | JSONObject jsonObject = jsonArray.getJSONObject(0); 46 | JSONObject candidateJsonObject = jsonObject.getJSONObject("candidate"); 47 | JSONObject scoreJsonObject = jsonObject.getJSONObject("score"); 48 | 49 | String candidateName = candidateJsonObject.getString("name"); 50 | String numerator = scoreJsonObject.getString("numerator"); 51 | String denominator = scoreJsonObject.getString("denominator"); 52 | 53 | Intent intent = new Intent(context, ResultActivity.class); 54 | intent.putExtra("name", candidateName); 55 | intent.putExtra("numerator", numerator); 56 | intent.putExtra("denominator", denominator); 57 | context.startActivity(intent); 58 | 59 | } catch (JSONException e) { 60 | e.printStackTrace(); 61 | } 62 | 63 | } else if (response.message().equals("No Content")) { 64 | loadToast.error(); 65 | Toast.makeText(getApplication(), "Nothing to show here", Toast.LENGTH_SHORT).show(); 66 | } 67 | } 68 | 69 | @Override 70 | public void onFailure(Call call, Throwable t) { 71 | loadToast.error(); 72 | Toast.makeText(getApplication(), "Something Went Wrong Please Try Again Later", Toast.LENGTH_SHORT).show(); 73 | } 74 | }); 75 | 76 | 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/signUp/SignUpActivity.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.signUp; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.appcompat.widget.AppCompatSpinner; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.AdapterView; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.Button; 11 | import android.widget.TextView; 12 | 13 | import com.google.android.material.textfield.TextInputLayout; 14 | import org.aossie.agoraandroid.R; 15 | import org.aossie.agoraandroid.logIn.LogInActivity; 16 | 17 | @SuppressWarnings("ConstantConditions") 18 | public class SignUpActivity extends AppCompatActivity { 19 | private TextInputLayout mUserNameEditText, mFirstNameEditText, mLastNameEditText, mEmailEditText, mPasswordEditText,mSecurityAnswer; 20 | private SignUpViewModel signUpViewModel; 21 | private AppCompatSpinner appCompatSpinner; 22 | private String securityQuestionOfSignUp; 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_sign_up); 27 | 28 | signUpViewModel = new SignUpViewModel(getApplication(),this); 29 | mUserNameEditText = findViewById(R.id.signUpUserName); 30 | mFirstNameEditText = findViewById(R.id.signUpFirstName); 31 | mLastNameEditText = findViewById(R.id.signUpLastName); 32 | mEmailEditText = findViewById(R.id.signUpEmail); 33 | mPasswordEditText = findViewById(R.id.signUpPassword); 34 | appCompatSpinner = findViewById(R.id.sign_up_security_question); 35 | mSecurityAnswer = findViewById(R.id.security_answer); 36 | TextView signIn=findViewById(R.id.signIn); 37 | Button mSignUpButton = findViewById(R.id.signUpButton); 38 | signIn.setOnClickListener(new View.OnClickListener() { 39 | @Override 40 | public void onClick(View v) { 41 | startActivity(new Intent(SignUpActivity.this,LogInActivity.class)); 42 | } 43 | }); 44 | mSignUpButton.setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | String userName = mUserNameEditText.getEditText().getText().toString(); 48 | String firstName = mFirstNameEditText.getEditText().getText().toString(); 49 | String lastName = mLastNameEditText.getEditText().getText().toString(); 50 | String userEmail = mEmailEditText.getEditText().getText().toString(); 51 | String userPass = mPasswordEditText.getEditText().getText().toString(); 52 | String securityQuestionAnswer = mSecurityAnswer.getEditText().getText().toString(); 53 | String securityQuestion = securityQuestionOfSignUp; 54 | 55 | if (userName.isEmpty()) 56 | mUserNameEditText.setError("Please enter User Name"); 57 | else mUserNameEditText.setError(null); 58 | 59 | if (firstName.isEmpty()) { 60 | mFirstNameEditText.setError("Please enter First Name"); 61 | } else mFirstNameEditText.setError(null); 62 | 63 | if (lastName.isEmpty()) { 64 | mLastNameEditText.setError("Please enter Last Name"); 65 | } else mLastNameEditText.setError(null); 66 | 67 | if (userEmail.isEmpty()) { 68 | mEmailEditText.setError("Please enter Email Address"); 69 | } else mEmailEditText.setError(null); 70 | 71 | if(securityQuestionAnswer.isEmpty()){ 72 | mSecurityAnswer.setError("Please enter Security Answer"); 73 | } else mSecurityAnswer.setError(null); 74 | 75 | if (userPass.isEmpty()) { 76 | mPasswordEditText.setError("Please enter password"); 77 | } else { 78 | mPasswordEditText.setError(null); 79 | signUpViewModel.signUpRequest(userName, userPass, userEmail, firstName, lastName, securityQuestion, securityQuestionAnswer); 80 | } 81 | 82 | } 83 | }); 84 | final ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.security_questions,android.R.layout.simple_spinner_item); 85 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 86 | appCompatSpinner.setAdapter(adapter); 87 | appCompatSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 88 | @Override 89 | public void onItemSelected(AdapterView adapterView, View view, int i, long l) { 90 | securityQuestionOfSignUp = adapterView.getItemAtPosition(i).toString(); 91 | } 92 | @Override 93 | public void onNothingSelected(AdapterView adapterView) { 94 | securityQuestionOfSignUp = getResources().getStringArray(R.array.security_questions)[0]; 95 | 96 | } 97 | }); 98 | } 99 | 100 | 101 | } 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/signUp/SignUpViewModel.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.signUp; 2 | 3 | 4 | import android.app.Application; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.widget.Toast; 8 | 9 | 10 | import androidx.annotation.NonNull; 11 | import androidx.lifecycle.AndroidViewModel; 12 | 13 | import net.steamcrafted.loadtoast.LoadToast; 14 | 15 | import org.aossie.agoraandroid.logIn.LogInActivity; 16 | import org.aossie.agoraandroid.remote.APIService; 17 | import org.aossie.agoraandroid.remote.RetrofitClient; 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | import retrofit2.Call; 22 | import retrofit2.Callback; 23 | import retrofit2.Response; 24 | 25 | class SignUpViewModel extends AndroidViewModel { 26 | private final Context context; 27 | private LoadToast loadToast; 28 | 29 | public SignUpViewModel(@NonNull Application application, Context context) { 30 | super(application); 31 | this.context = context; 32 | } 33 | 34 | 35 | public void signUpRequest(final String userName, String userPassword, String userEmail, String firstName, String lastName, String securityQuestion, String securityAnswer) { 36 | JSONObject jsonObject = new JSONObject(); 37 | JSONObject securityJsonObject = new JSONObject(); 38 | loadToast = new LoadToast(context); 39 | loadToast.setText("Signing in"); 40 | loadToast.show(); 41 | try { 42 | 43 | jsonObject.put("identifier", userName); 44 | jsonObject.put("password", userPassword); 45 | jsonObject.put("email", userEmail); 46 | jsonObject.put("firstName", firstName); 47 | jsonObject.put("lastName", lastName); 48 | securityJsonObject.put("question", securityQuestion); 49 | securityJsonObject.put("answer", securityAnswer); 50 | jsonObject.put("securityQuestion",securityJsonObject); 51 | 52 | } catch (JSONException e) { 53 | e.printStackTrace(); 54 | } 55 | 56 | APIService apiService = RetrofitClient.getAPIService(); 57 | Call signUpResponse = apiService.createUser(jsonObject.toString()); 58 | signUpResponse.enqueue(new Callback() { 59 | @Override 60 | public void onResponse(Call call, Response response) { 61 | if (response.message().equals("timeout")) { 62 | loadToast.error(); 63 | Toast.makeText(getApplication(), "Network Connection issues please try again", Toast.LENGTH_LONG).show(); 64 | } 65 | if (response.code() == 200) { 66 | loadToast.success(); 67 | Toast.makeText(getApplication(), "An activation link has been sent to your email. Follow it to activate your account.", Toast.LENGTH_LONG).show(); 68 | context.startActivity(new Intent(context, LogInActivity.class)); 69 | } else if (response.code() == 409) { 70 | loadToast.error(); 71 | Toast.makeText(getApplication(), "User With Same UserName already Exists", Toast.LENGTH_LONG).show(); 72 | } else { 73 | loadToast.error(); 74 | Toast.makeText(getApplication(), "Something went wrong please try again", Toast.LENGTH_LONG).show(); 75 | } 76 | } 77 | 78 | @Override 79 | public void onFailure(Call call, Throwable t) { 80 | loadToast.error(); 81 | Toast.makeText(getApplication(), "" + t.getMessage(), Toast.LENGTH_SHORT).show(); 82 | 83 | } 84 | }); 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/org/aossie/agoraandroid/utilities/SharedPrefs.java: -------------------------------------------------------------------------------- 1 | package org.aossie.agoraandroid.utilities; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | @SuppressWarnings("SpellCheckingInspection") 7 | public class SharedPrefs { 8 | 9 | private static final String myPrefs = "myPrefs"; 10 | private static final String UserNameKey = "userName"; 11 | private static final String EmailKey = "emailId"; 12 | private static final String FullNameKey = "fullName"; 13 | private static final String TokenKey = "token"; 14 | private static final String PassKey = "userPass"; 15 | private static final String ExpiresOnKey = "expiresOn"; 16 | private final SharedPreferences sharedPreferences; 17 | private final SharedPreferences.Editor editor; 18 | 19 | 20 | public SharedPrefs(Context context) { 21 | sharedPreferences = context.getSharedPreferences(myPrefs, Context.MODE_PRIVATE); 22 | editor = sharedPreferences.edit(); 23 | } 24 | 25 | 26 | //Save USerName in sharedPref and get Username 27 | public void saveUserName(String key) { 28 | editor.putString(UserNameKey, key); 29 | editor.commit(); 30 | } 31 | 32 | public String getUserName() { 33 | return sharedPreferences.getString(UserNameKey, null); 34 | } 35 | 36 | 37 | //Save Email in sharedPref and get Email 38 | public void saveEmail(String email) { 39 | editor.putString(EmailKey, email); 40 | editor.commit(); 41 | } 42 | 43 | public String getEmail() { 44 | return sharedPreferences.getString(EmailKey, null); 45 | } 46 | 47 | 48 | //Save firstName and lastName as fullName and get fullName 49 | public void saveFullName(String firstName, String lastName) { 50 | editor.putString(FullNameKey, firstName + " " + lastName); 51 | editor.commit(); 52 | } 53 | 54 | public String getfullName() { 55 | return sharedPreferences.getString(FullNameKey, null); 56 | } 57 | 58 | //Save Token and get Token when required 59 | public void saveToken(String token) { 60 | editor.putString(TokenKey, token); 61 | editor.commit(); 62 | } 63 | 64 | public String getToken() { 65 | return sharedPreferences.getString(TokenKey, null); 66 | } 67 | 68 | public void savePass(String password) { 69 | editor.putString(PassKey, password); 70 | editor.commit(); 71 | } 72 | 73 | public String getPass() { 74 | return sharedPreferences.getString(PassKey, null); 75 | } 76 | 77 | public void saveTokenExpiresOn(String ExpiresOn) { 78 | editor.putString(ExpiresOnKey, ExpiresOn); 79 | editor.commit(); 80 | } 81 | 82 | public String getTokenExpiresOn() { 83 | return sharedPreferences.getString(ExpiresOnKey, null); 84 | } 85 | 86 | public void clearLogin() { 87 | editor.putString(UserNameKey, null); 88 | editor.putString(EmailKey, null); 89 | editor.putString(FullNameKey, null); 90 | editor.commit(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/res/anim/rotate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/rounded_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/white_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AOSSIE-Org/Agora-Android/fd75037b4f1621e84537bfcc183abfb75fc2c7dd/app/src/main/res/drawable-v24/white_background.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/agora.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AOSSIE-Org/Agora-Android/fd75037b4f1621e84537bfcc183abfb75fc2c7dd/app/src/main/res/drawable/agora.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_access_time.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_bug_report_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_call_received_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_code_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_date_range_50dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_done_all.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AOSSIE-Org/Agora-Android/fd75037b4f1621e84537bfcc183abfb75fc2c7dd/app/src/main/res/drawable/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_local_post_office_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_message_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_people_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_person_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_play_arrow.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_share_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_view_carousel_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_view_carousel_white.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/rounded_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/spinner_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 17 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/white_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AOSSIE-Org/Agora-Android/fd75037b4f1621e84537bfcc183abfb75fc2c7dd/app/src/main/res/drawable/white_background.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_active_elections.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 27 | 28 | 29 | 30 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_ballot.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 17 | 18 | 26 | 27 | 28 | 29 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_finished_elections.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 27 | 28 | 29 | 30 | 31 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 21 | 22 | 29 | 30 | 31 | 32 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 24 | 25 | 38 | 39 |