Search in sources :

Example 21 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class NotificationsAdapter method onClick.

@Override
public void onClick(Notification notification, FragmentActivity fragmentActivity) {
    /* Mark notification read */
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    String sessId = Utils.getSessionIDHeader();
    retrofitInterface.markNotificationRead(sessId, notification.getNotificationId().toString()).enqueue(new EmptyCallback<Void>());
    ShortcutBadger.applyCount(fragmentActivity.getApplicationContext(), NotificationId.decrementAndGetCurrentCount());
    /* Close the bottom sheet */
    notificationsFragment.dismiss();
    Gson gson = Utils.gson;
    /* Open event */
    if (notification.isEvent()) {
        Event event = gson.fromJson(gson.toJson(notification.getNotificationActor()), Event.class);
        Utils.openEventFragment(event, fragmentActivity);
    } else if (notification.isNews()) {
        NewsFragment newsFragment = new NewsFragment();
        NewsArticle newsArticle = gson.fromJson(gson.toJson(notification.getNotificationActor()), NewsArticle.class);
        newsFragment.withId(newsArticle.getId());
        Utils.updateFragment(newsFragment, fragmentActivity);
    } else if (notification.isBlogPost()) {
        PlacementBlogPost post = gson.fromJson(gson.toJson(notification.getNotificationActor()), PlacementBlogPost.class);
        Fragment fragment;
        if (post.getLink().contains("training")) {
            fragment = (new TrainingBlogFragment()).withId(post.getId());
        } else {
            fragment = (new PlacementBlogFragment()).withId(post.getId());
        }
        Utils.updateFragment(fragment, fragmentActivity);
    }
}
Also used : NewsArticle(app.insti.api.model.NewsArticle) PlacementBlogPost(app.insti.api.model.PlacementBlogPost) PlacementBlogFragment(app.insti.fragment.PlacementBlogFragment) Gson(com.google.gson.Gson) Event(app.insti.api.model.Event) NewsFragment(app.insti.fragment.NewsFragment) NotificationsFragment(app.insti.fragment.NotificationsFragment) NewsFragment(app.insti.fragment.NewsFragment) TrainingBlogFragment(app.insti.fragment.TrainingBlogFragment) Fragment(androidx.fragment.app.Fragment) PlacementBlogFragment(app.insti.fragment.PlacementBlogFragment) TrainingBlogFragment(app.insti.fragment.TrainingBlogFragment) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 22 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class MainActivity method fetchNotifications.

/**
 * Get the notifications from memory cache or network
 */
private void fetchNotifications() {
    // Try memory cache
    if (Utils.notificationCache != null) {
        showNotifications();
        return;
    }
    // Get from network
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    retrofitInterface.getNotifications(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<List<Notification>>() {

        @Override
        public void onResponse(Call<List<Notification>> call, Response<List<Notification>> response) {
            if (response.isSuccessful()) {
                Utils.notificationCache = new UpdatableList<>();
                Utils.notificationCache.setList(response.body());
                showNotifications();
                NotificationId.setCurrentCount(Utils.notificationCache.size());
                ShortcutBadger.applyCount(getApplicationContext(), NotificationId.getCurrentCount());
            }
        }
    });
}
Also used : UpdatableList(app.insti.UpdatableList) List(java.util.List) UpdatableList(app.insti.UpdatableList) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 23 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class MainActivity method updateFCMId.

/**
 * Update FCM Id and update profile
 */
private void updateFCMId() {
    FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {

        @Override
        public void onSuccess(InstanceIdResult instanceIdResult) {
            final String fcmId = instanceIdResult.getToken();
            RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
            retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserFCMPatchRequest(fcmId, getCurrentVersion())).enqueue(new EmptyCallback<User>() {

                @Override
                public void onResponse(Call<User> call, Response<User> response) {
                    if (response.isSuccessful()) {
                        session.createLoginSession(response.body().getUserName(), response.body(), session.getSessionID());
                        currentUser = response.body();
                        Utils.currentUserCache = currentUser;
                    } else {
                        session.logout();
                        currentUser = null;
                        Toast.makeText(MainActivity.this, "Your session has expired!", Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    });
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) EmptyCallback(app.insti.api.EmptyCallback) InstanceIdResult(com.google.firebase.iid.InstanceIdResult) RetrofitInterface(app.insti.api.RetrofitInterface) UserFCMPatchRequest(app.insti.api.request.UserFCMPatchRequest)

Example 24 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class LoginActivity method login.

private void login(final String authorizationCode, final String redirectURL) {
    /* This can be null if play services is hung */
    RetrofitInterface retrofitInterface = getRetrofitInterface();
    Call<LoginResponse> call;
    if (fcmId == null) {
        call = retrofitInterface.login(authorizationCode, redirectURL);
    } else {
        call = retrofitInterface.login(authorizationCode, redirectURL, fcmId);
    }
    call.enqueue(new EmptyCallback<LoginResponse>() {

        @Override
        public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
            if (response.isSuccessful()) {
                session.createLoginSession(response.body().getUser().getUserName(), response.body().getUser(), response.body().getSessionID());
                progressDialog.dismiss();
                openMainActivity();
                finish();
            } else {
                Toast.makeText(LoginActivity.this, "Authorization Failed!", Toast.LENGTH_LONG).show();
                progressDialog.dismiss();
            }
        }
    });
}
Also used : LoginResponse(app.insti.api.response.LoginResponse) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 25 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class ExploreFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    // Initialize
    sessionId = Utils.getSessionIDHeader();
    initRecyclerView();
    Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
    toolbar.setTitle("Explore");
    Utils.setSelectedMenuItem(getActivity(), R.id.nav_explore);
    final EditText searchEditText = getView().findViewById(R.id.explore_search);
    // Get all bodies
    if (allBodies.size() == 0) {
        RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
        retrofitInterface.getAllBodies(sessionId).enqueue(new EmptyCallback<List<Body>>() {

            @Override
            public void onResponse(Call<List<Body>> call, Response<List<Body>> response) {
                allBodies = response.body();
                bodies = allBodies;
                updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
            }
        });
    } else {
        // Check if search box is not empty
        if (searchEditText.getText() != null && !searchEditText.getText().toString().equals("")) {
            updateAdapter(bodies, events, users);
        } else {
            updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
        }
        getView().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
    }
    // Close keyboard on search click
    searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                MainActivity.hideKeyboard(getActivity());
                return true;
            }
            return false;
        }
    });
    // Search on text change in search
    searchEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // Do nothing
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // Do nothing
        }

        @Override
        public void afterTextChanged(Editable s) {
            currentQuery = s.toString();
            if (currentQuery.length() >= 3) {
                doSearch(searchEditText.getText().toString());
            } else if (currentQuery.length() == 0) {
                updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
            }
        }
    });
}
Also used : EditText(android.widget.EditText) User(app.insti.api.model.User) ArrayList(java.util.ArrayList) KeyEvent(android.view.KeyEvent) KeyEvent(android.view.KeyEvent) Event(app.insti.api.model.Event) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ArrayList(java.util.ArrayList) List(java.util.List) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

RetrofitInterface (app.insti.api.RetrofitInterface)35 List (java.util.List)12 Venter (app.insti.api.model.Venter)6 Call (retrofit2.Call)6 Response (retrofit2.Response)6 Event (app.insti.api.model.Event)5 ArrayList (java.util.ArrayList)5 Callback (retrofit2.Callback)5 User (app.insti.api.model.User)4 DialogInterface (android.content.DialogInterface)3 TextView (android.widget.TextView)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Toolbar (androidx.appcompat.widget.Toolbar)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 SessionManager (app.insti.SessionManager)2 UpdatableList (app.insti.UpdatableList)2