diff --git a/app/src/main/java/com/example/saar/Login_SignUp/LoginFragment.java b/app/src/main/java/com/example/saar/Login_SignUp/LoginFragment.java index adcc941..0eb99ad 100644 --- a/app/src/main/java/com/example/saar/Login_SignUp/LoginFragment.java +++ b/app/src/main/java/com/example/saar/Login_SignUp/LoginFragment.java @@ -29,6 +29,7 @@ import com.example.saar.MainActivity; import com.example.saar.OtpActivity; import com.example.saar.R; +import com.example.saar.Utils.Utils; import org.json.JSONArray; import org.json.JSONException; @@ -117,6 +118,8 @@ private void getDatas() { } private void login() { + //closing soft Keyboard using Utils class method + Utils.closeKeyboard(getView(), getContext()); progressDialog = new ProgressDialog(getContext()); progressDialog.setMessage("Logging in...."); progressDialog.show(); diff --git a/app/src/main/java/com/example/saar/MainActivity.java b/app/src/main/java/com/example/saar/MainActivity.java index a51ec08..cd4d150 100644 --- a/app/src/main/java/com/example/saar/MainActivity.java +++ b/app/src/main/java/com/example/saar/MainActivity.java @@ -36,6 +36,7 @@ import com.example.saar.Share.ShareFragment; import com.example.saar.Team.TeamFragment; import com.example.saar.Timeline_Events.TimelineFragment; +import com.example.saar.Utils.Utils; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.messaging.FirebaseMessaging; @@ -106,7 +107,7 @@ public void onClick(View v) { } private void subscribeForNotification() { - notifications= PreferenceManager.getDefaultSharedPreferences(this).edit(); + notifications = PreferenceManager.getDefaultSharedPreferences(this).edit(); if (!preferences.getBoolean(Constant.SUBSCRIBE_NOTIFICATION, false)) { FirebaseMessaging.getInstance().subscribeToTopic("alumnus") .addOnCompleteListener(new OnCompleteListener() { @@ -128,7 +129,7 @@ public void onComplete(@NonNull Task task) { FirebaseMessaging.getInstance().subscribeToTopic(department); } } - notifications.putBoolean(Constant.SUBSCRIBE_NOTIFICATION,true); + notifications.putBoolean(Constant.SUBSCRIBE_NOTIFICATION, true); notifications.apply(); Toast.makeText(MainActivity.this, getString(R.string.msg_subscribed), Toast.LENGTH_SHORT).show(); Timber.d("Subscribed to notification."); @@ -143,18 +144,18 @@ private String getDepartment(String rollno) { private String getBatch(String rollno) { String year = rollno.substring(0, 2); String category = rollno.substring(2, 4); - String value= null; + String value = null; if (category.equals("01")) { - value= "btech" + year; + value = "btech" + year; } else if (category.equals("21")) { - value= "phd" + year; + value = "phd" + year; } else if (category.equals("11")) { - value= "mtech" + year; + value = "mtech" + year; } else if (category.equals("12")) { - value= "msc" + year; - }else { - value="unknown"; + value = "msc" + year; + } else { + value = "unknown"; } return value; } @@ -325,31 +326,9 @@ private void setHeaderData() { private void clearData() { editor = preferences.edit(); - if (preferences.getBoolean(Constant.LOGIN_STATUS, false)) { - //user is logged in and wants to log out - editor.putBoolean(Constant.LOGIN_STATUS, false); - editor.putString(Constant.ROLLNO, ""); - editor.putString(Constant.FIRST_NAME, ""); - editor.putString(Constant.LAST_NAME, ""); - editor.putString(Constant.EMAIL, ""); - editor.putString(Constant.PHONE, ""); - editor.putString(Constant.FB_LINK, ""); - editor.putString(Constant.LINKEDIN_LINK, ""); - editor.putString(Constant.DOB, ""); - editor.putString(Constant.GRADUATION_YEAR, ""); - editor.putString(Constant.DEGREE, ""); - editor.putString(Constant.DEPARTMENT, ""); - editor.putString(Constant.EMPLOYEMENT_TYPE, ""); - editor.putString(Constant.PRESENT_EMPLOYER, ""); - editor.putString(Constant.DESIGNATION, ""); - editor.putString(Constant.ADDRESS, ""); - editor.putString(Constant.COUNTRY, ""); - editor.putString(Constant.CITY, ""); - editor.putString(Constant.STATE, ""); - editor.putString(Constant.ACHIEVEMENTS, ""); - editor.apply(); - Toast.makeText(this, "Logged Out", Toast.LENGTH_LONG).show(); - } else - Toast.makeText(this, "Not Logged In", Toast.LENGTH_LONG).show(); + //method to reset shared preferences + Utils.resetSharedPreferences(preferences, editor); + Toast.makeText(this, "Logged Out", Toast.LENGTH_LONG).show(); + } } diff --git a/app/src/main/java/com/example/saar/Utils/Utils.java b/app/src/main/java/com/example/saar/Utils/Utils.java new file mode 100644 index 0000000..2ee8f28 --- /dev/null +++ b/app/src/main/java/com/example/saar/Utils/Utils.java @@ -0,0 +1,44 @@ +package com.example.saar.Utils; + +import android.content.Context; +import android.content.SharedPreferences; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +import com.example.saar.Constant; + +public class Utils { + + public static void closeKeyboard(View view, Context context) { + InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + if (inputManager != null) + inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.SHOW_FORCED); + } + + public static void resetSharedPreferences(SharedPreferences preferences, SharedPreferences.Editor editor) { + //setting all values of shared preferences to empty string + //login status is set to false + editor.putBoolean(Constant.LOGIN_STATUS, false); + editor.putString(Constant.ROLLNO, ""); + editor.putString(Constant.FIRST_NAME, ""); + editor.putString(Constant.LAST_NAME, ""); + editor.putString(Constant.EMAIL, ""); + editor.putString(Constant.PHONE, ""); + editor.putString(Constant.FB_LINK, ""); + editor.putString(Constant.LINKEDIN_LINK, ""); + editor.putString(Constant.DOB, ""); + editor.putString(Constant.GRADUATION_YEAR, ""); + editor.putString(Constant.DEGREE, ""); + editor.putString(Constant.DEPARTMENT, ""); + editor.putString(Constant.EMPLOYEMENT_TYPE, ""); + editor.putString(Constant.PRESENT_EMPLOYER, ""); + editor.putString(Constant.DESIGNATION, ""); + editor.putString(Constant.ADDRESS, ""); + editor.putString(Constant.COUNTRY, ""); + editor.putString(Constant.CITY, ""); + editor.putString(Constant.STATE, ""); + editor.putString(Constant.ACHIEVEMENTS, ""); + editor.apply(); + } + +}