Feat(profile): access basically done
This commit is contained in:
parent
f9eec3ec44
commit
f19f09027f
@ -29,7 +29,6 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'com.google.android.material:material:1.10.0'
|
implementation 'com.google.android.material:material:1.10.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
|
@ -74,14 +74,13 @@ public class AccessDBHelper extends SQLiteOpenHelper {
|
|||||||
String[] columns = {"access_id", "profile_id", "access_type", "timestamp"};
|
String[] columns = {"access_id", "profile_id", "access_type", "timestamp"};
|
||||||
String selection = "profile_id = ?";
|
String selection = "profile_id = ?";
|
||||||
String[] selectionArgs = {String.valueOf(profileID)};
|
String[] selectionArgs = {String.valueOf(profileID)};
|
||||||
String orderBy = "timestamp";
|
String orderBy = "timestamp DESC"; // sort by Latest Access First
|
||||||
|
|
||||||
cursor = db.query(AccessContract.AccessEntry.TABLE_NAME, columns, selection, selectionArgs, null, null, orderBy);
|
cursor = db.query(AccessContract.AccessEntry.TABLE_NAME, columns, selection, selectionArgs, null, null, orderBy);
|
||||||
|
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
// int accessID = cursor.getInt(cursor.getColumnIndexOrThrow("access_id"));
|
|
||||||
int _profileID = cursor.getInt(cursor.getColumnIndexOrThrow("profile_id"));
|
int _profileID = cursor.getInt(cursor.getColumnIndexOrThrow("profile_id"));
|
||||||
String accessType = cursor.getString(cursor.getColumnIndexOrThrow("access_type"));
|
String accessType = cursor.getString(cursor.getColumnIndexOrThrow("access_type"));
|
||||||
String timestamp = cursor.getString(cursor.getColumnIndexOrThrow("timestamp"));
|
String timestamp = cursor.getString(cursor.getColumnIndexOrThrow("timestamp"));
|
||||||
|
@ -14,12 +14,16 @@ import android.widget.Toast;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
|
import com.example.coen390_assignment2.Controllers.AccessDBHelper;
|
||||||
import com.example.coen390_assignment2.Controllers.StudentProfileDBHelper;
|
import com.example.coen390_assignment2.Controllers.StudentProfileDBHelper;
|
||||||
|
import com.example.coen390_assignment2.Models.Access;
|
||||||
|
import com.example.coen390_assignment2.Models.AccessType;
|
||||||
import com.example.coen390_assignment2.Models.StudentProfile;
|
import com.example.coen390_assignment2.Models.StudentProfile;
|
||||||
import com.example.coen390_assignment2.Models.StudentProfileIDComparator;
|
import com.example.coen390_assignment2.Models.StudentProfileIDComparator;
|
||||||
import com.example.coen390_assignment2.Models.StudentProfileSurnameComparator;
|
import com.example.coen390_assignment2.Models.StudentProfileSurnameComparator;
|
||||||
import com.example.coen390_assignment2.R;
|
import com.example.coen390_assignment2.R;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -27,6 +31,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
protected StudentProfileDBHelper studentProfileDBHelper;
|
protected StudentProfileDBHelper studentProfileDBHelper;
|
||||||
|
|
||||||
|
protected AccessDBHelper accessDBHelper;
|
||||||
|
|
||||||
protected Toolbar toolbar;
|
protected Toolbar toolbar;
|
||||||
protected Button showDialogButton;
|
protected Button showDialogButton;
|
||||||
|
|
||||||
@ -50,6 +56,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
studentProfileDBHelper = new StudentProfileDBHelper(getApplicationContext());
|
studentProfileDBHelper = new StudentProfileDBHelper(getApplicationContext());
|
||||||
|
|
||||||
|
accessDBHelper = new AccessDBHelper(getApplicationContext());
|
||||||
|
|
||||||
initAddProfileActionButton(showDialogButton);
|
initAddProfileActionButton(showDialogButton);
|
||||||
|
|
||||||
// surname when true, ID when false
|
// surname when true, ID when false
|
||||||
@ -86,6 +94,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
intent.putExtra("gpa", clickedProfile.getGPA());
|
intent.putExtra("gpa", clickedProfile.getGPA());
|
||||||
intent.putExtra("dateCreated", clickedProfile.getProfileCreationDate().toString());
|
intent.putExtra("dateCreated", clickedProfile.getProfileCreationDate().toString());
|
||||||
|
|
||||||
|
// create an Access entry
|
||||||
|
createAccessOpened(clickedProfile.getProfileID(), AccessType.OPENED, LocalDateTime.now());
|
||||||
|
|
||||||
// Start the ProfileActivity
|
// Start the ProfileActivity
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
@ -119,13 +130,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
profileNameDisplayMode = false;
|
profileNameDisplayMode = false;
|
||||||
onStart();
|
onStart();
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
} else if (id == R.id.toggle_profiles_display_mode && toggle.getTitle() == "By Surname"){
|
} else if (id == R.id.toggle_profiles_display_mode && toggle.getTitle() == "By Surname"){
|
||||||
profileNameDisplayMode = true;
|
profileNameDisplayMode = true;
|
||||||
|
|
||||||
onStart();
|
onStart();
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@ -173,4 +184,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createAccessOpened(long profileID, AccessType accessType, LocalDateTime timestamp){
|
||||||
|
Access access = new Access(profileID, accessType, timestamp);
|
||||||
|
accessDBHelper.insertAccess(access, getApplicationContext());
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,25 +1,27 @@
|
|||||||
package com.example.coen390_assignment2.Views;
|
package com.example.coen390_assignment2.Views;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
import com.example.coen390_assignment2.Controllers.AccessDBHelper;
|
import com.example.coen390_assignment2.Controllers.AccessDBHelper;
|
||||||
import com.example.coen390_assignment2.Models.Access;
|
import com.example.coen390_assignment2.Models.Access;
|
||||||
|
import com.example.coen390_assignment2.Models.AccessType;
|
||||||
import com.example.coen390_assignment2.R;
|
import com.example.coen390_assignment2.R;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ProfileActivity extends AppCompatActivity {
|
public class ProfileActivity extends AppCompatActivity {
|
||||||
@ -59,6 +61,18 @@ public class ProfileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
setTitle("Profile Activity");
|
setTitle("Profile Activity");
|
||||||
|
|
||||||
|
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
Log.d("ProfileActivity", "handleOnBackPressed: Pressed");
|
||||||
|
createAccessClosed(profileId, AccessType.CLOSED, LocalDateTime.now());
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add the callback to the back button dispatcher
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, callback);
|
||||||
|
|
||||||
// Retrieve the extra data from the Intent
|
// Retrieve the extra data from the Intent
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
|
|
||||||
@ -74,7 +88,7 @@ public class ProfileActivity extends AppCompatActivity {
|
|||||||
GPATextView.setText(Float.toString(gpa));
|
GPATextView.setText(Float.toString(gpa));
|
||||||
ProfileCreatedTextView.setText(creationDate);
|
ProfileCreatedTextView.setText(creationDate);
|
||||||
|
|
||||||
if (profileId != -1 || gpa != -1){
|
if (profileId != -1 || gpa != -1) {
|
||||||
List<Access> accessList = dbHelper.getAccessFromProfileID(profileId, getApplicationContext());
|
List<Access> accessList = dbHelper.getAccessFromProfileID(profileId, getApplicationContext());
|
||||||
|
|
||||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, accessListFromProfileIDToString(accessList));
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, accessListFromProfileIDToString(accessList));
|
||||||
@ -86,12 +100,16 @@ public class ProfileActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
super.onStart();
|
int id = item.getItemId();
|
||||||
|
if (id == android.R.id.home) {
|
||||||
|
createAccessClosed(profileId, AccessType.CLOSED, LocalDateTime.now());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] accessListFromProfileIDToString(List<Access> accessList){
|
protected String[] accessListFromProfileIDToString(List<Access> accessList) {
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd @ HH:mm:ss");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd @ HH:mm:ss");
|
||||||
|
|
||||||
List<String> formattedAccessStrings = new ArrayList<>();
|
List<String> formattedAccessStrings = new ArrayList<>();
|
||||||
@ -101,18 +119,12 @@ public class ProfileActivity extends AppCompatActivity {
|
|||||||
formattedAccessStrings.add(formattedAccessString);
|
formattedAccessStrings.add(formattedAccessString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the list of formatted String representations based on the timestamp
|
|
||||||
formattedAccessStrings.sort(new Comparator<String>() {
|
|
||||||
@Override
|
|
||||||
public int compare(String s1, String s2) {
|
|
||||||
// Extract the timestamps from the strings and compare them
|
|
||||||
LocalDateTime timestamp1 = LocalDateTime.parse(s1.split(" ")[0], formatter);
|
|
||||||
LocalDateTime timestamp2 = LocalDateTime.parse(s2.split(" ")[0], formatter);
|
|
||||||
return timestamp1.compareTo(timestamp2);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Convert the sorted formatted String list back to a String array
|
// Convert the sorted formatted String list back to a String array
|
||||||
return formattedAccessStrings.toArray(new String[0]);
|
return formattedAccessStrings.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createAccessClosed(long profileId, AccessType accessType, LocalDateTime timestamp) {
|
||||||
|
Access access = new Access(profileId, accessType, timestamp);
|
||||||
|
dbHelper.insertAccess(access, getApplicationContext());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user