Skip to content

Commit

Permalink
minor bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyajit Ghosh committed Jan 24, 2022
1 parent a852f5c commit 2b1bab0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.satyajitghosh.mediclock"
minSdk 26
targetSdk 30
versionCode 7
versionName "1.6"
versionCode 8
versionName "1.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/com/satyajitghosh/mediclock/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getTime(); // It refreshes the times from the shared preferences
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
Expand All @@ -37,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
// the GoogleSignInAccount will be non-null.
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if (account != null) {
getTime(); // It refreshes the times from the shared preferences

startService(new Intent(this, AlarmRefreshService.class));
String personName = account.getDisplayName();
startActivity(new Intent(MainActivity.this, DisplayMedicineActivity.class).putExtra("UserName", personName).putExtra("Id", account.getId())
Expand Down Expand Up @@ -80,7 +80,7 @@ private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
String personName = account.getDisplayName();

//set the times
// Signed in successfully, show authenticated UI.
startActivity(new Intent(MainActivity.this, HomeActivity.class).putExtra("UserName", personName).putExtra("Id", account.getId())
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -94,9 +94,20 @@ private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {

}
}
public void initSharedPref(){
SharedPreferences sharedPref = getSharedPreferences("MySharedPref", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("MORNING", TIME.MORNING);
editor.putString("AFTERNOON", TIME.AFTERNOON);
editor.putString("NIGHT", TIME.NIGHT);
editor.apply();
}

public void getTime() {
SharedPreferences sharedPref = getSharedPreferences("MySharedPref", MODE_PRIVATE);
if( sharedPref.getString("MORNING", "").length()==0){ // This satisfy no SharedPreferences exist
initSharedPref();
}
TIME.MORNING = sharedPref.getString("MORNING", "");
TIME.AFTERNOON = sharedPref.getString("AFTERNOON", "");
TIME.NIGHT = sharedPref.getString("NIGHT", "");
Expand Down

0 comments on commit 2b1bab0

Please sign in to comment.