Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Utils class #169

Merged
merged 2 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
49 changes: 14 additions & 35 deletions app/src/main/java/com/example/saar/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Void>() {
Expand All @@ -128,7 +129,7 @@ public void onComplete(@NonNull Task<Void> 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.");
Expand All @@ -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;
}
Expand Down Expand Up @@ -318,31 +319,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();

}
}
44 changes: 44 additions & 0 deletions app/src/main/java/com/example/saar/Utils/Utils.java
Original file line number Diff line number Diff line change
@@ -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();
}

}