Skip to content

Commit

Permalink
Merge pull request #52 from Nuwan-Harshakumara-Piyarathna/v2.1
Browse files Browse the repository at this point in the history
V2.1
  • Loading branch information
Nuwan-Harshakumara-Piyarathna authored Sep 10, 2021
2 parents 1deb38e + d24ed5c commit 98705d5
Show file tree
Hide file tree
Showing 30 changed files with 508 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

17 changes: 17 additions & 0 deletions .idea/misc.xml

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

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

12 changes: 9 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ android {
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.example.quizme"
applicationId "com.cipher.pera.quizme"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionCode 4
versionName "2.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -26,6 +26,12 @@ android {
buildFeatures {
viewBinding true
}

lintOptions {

checkReleaseBuilds false

}
}

dependencies {
Expand Down
Binary file added app/release/app-release.aab
Binary file not shown.
Binary file modified app/release/app-release.apk
Binary file not shown.
6 changes: 3 additions & 3 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.example.quizme",
"applicationId": "com.cipher.pera.quizme",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"versionCode": 1,
"versionName": "1.0",
"versionCode": 2,
"versionName": "2.0",
"outputFile": "app-release.apk"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_question);

requestStoragePermission();
// requestStoragePermission();

// questionImage = findViewById(R.id.quesImg);
// pickImage = findViewById(R.id.pickImage);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/quizme/EditQuizActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ protected void onPostExecute(String s) {
toast.show();
}
else{
Toast toast=Toast.makeText(con, "Question Successsfully Updated", Toast.LENGTH_SHORT);
Toast toast=Toast.makeText(con, "Question Successfully Updated", Toast.LENGTH_SHORT);
toast.show();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public HostedQuizAdopter(ArrayList<HostedQuizModel> hostedQuizModels, Context co
@NotNull
@Contract(pure = true)
private String genMessage(String link, String date, String time, String name) {
return "Quizz: " + name + "\nLink for the Quiz: " + link + "\non: " + date + "\nat: " + time;
return "Quizz: " + name + "\nLink for the Quiz: " + link + "\non: " + date + "\nat: " + time+"\n\nGet Quiz Me From PlayStore: \nhttps://play.google.com/store/apps/details?id=com.cipher.pera.quizme";
}

@NonNull
Expand Down
127 changes: 122 additions & 5 deletions app/src/main/java/com/example/quizme/LBFragment.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
package com.example.quizme;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class LBFragment extends Fragment {

SwipeRefreshLayout swipeRefreshLayout;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ViewGroup lbFrag = (ViewGroup)inflater.inflate(R.layout.lb_fragment, container, false);

RecyclerView recyclerView = lbFrag.findViewById(R.id.qNamesRev);
swipeRefreshLayout = lbFrag.findViewById(R.id.swipe_refresh_layout_leader_board);

String[] names = new String[GlobalData.getLeaderBoardLength()];
ArrayList<String> names = new ArrayList<>();

QuizResult quizResult;
for(int i=0;i<GlobalData.getLeaderBoardLength();i++){
names[i] = GlobalData.getLeaderBoardName(i);
names.add(GlobalData.getLeaderBoardName(i));
}


Expand All @@ -39,10 +59,107 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));


swipeRefreshLayout.setOnRefreshListener(() -> {
getLeaderBoards();
names.clear();
for(int i=0;i<GlobalData.getLeaderBoardLength();i++){
names.add(GlobalData.getLeaderBoardName(i));
}
adapter.notifyDataSetChanged();
swipeRefreshLayout.setRefreshing(false);
});
return lbFrag;



}
}

private void getLeaderBoards() {
SharedPreferences pref = getActivity().getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
String baseURL =pref.getString("baseURL",null);
String URL = baseURL + "/quiz/find/leaderboards";

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(getActivity());
String token = pref.getString("jwt", null);
final String auth = "Bearer " + token;
final String tkn = token;

// Request a string response from the provided URL.
JsonArrayRequest jsonObjectRequest = new JsonArrayRequest
(Request.Method.GET, URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {

//Log.e("...Quizzes",response.toString());
//Toast.makeText(getContext(),response.toString(),Toast.LENGTH_SHORT).show();
//Log.e("response",response.toString());

JSONObject tmpLeaderBoard;
String title;
JSONArray leaderBoards;
String name;
JSONArray tmpMarkList;
SingleResult[] tmpResultList;
LeaderBoard[] tmpLdrBoard = new LeaderBoard[response.length()];
LeaderBoard tmpL;


try {


for (int i = 0; i < response.length(); i++) {

tmpLeaderBoard = (JSONObject) response.get(i);
name = tmpLeaderBoard.getString("name");
Log.e("QuizName", name);
tmpMarkList = (JSONArray) tmpLeaderBoard.get("leaderboard");
tmpResultList = new SingleResult[tmpMarkList.length()];
SingleResult singleResult;
String user;
float mark;
JSONObject tmp;

for (int j = 0; j < tmpMarkList.length(); j++) {

tmp = (JSONObject)tmpMarkList.get(j);
tmpResultList[j] = new SingleResult(tmp.getString("name"),(float)tmp.getDouble("marks"));
}


tmpLdrBoard[i] = new LeaderBoard(name, tmpResultList);


}

GlobalData.setLeaderBoards(tmpLdrBoard);

} catch (JSONException e) {
e.printStackTrace();
}

}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
Log.e("regError", error.getMessage());


}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Authorization", auth);
return params;
}
};

// Add the request to the RequestQueue.
queue.add(jsonObjectRequest);
//loadDialog.dismissDialog();
}
}
Loading

0 comments on commit 98705d5

Please sign in to comment.