Skip to content

Commit

Permalink
Merge pull request #167 from UdacityAndroidDevScholarship/fix-notific…
Browse files Browse the repository at this point in the history
…ation_click_discussion

Fix notification click discussion
  • Loading branch information
drulabs authored May 20, 2018
2 parents 0631eea + f5b484e commit 6059f4a
Show file tree
Hide file tree
Showing 49 changed files with 144 additions and 83 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<application
android:name=".application.AppClass"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/ic_launcher_12"
android:label="@string/quiz_app"
android:roundIcon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:allowBackup">
Expand Down Expand Up @@ -64,7 +64,7 @@
android:theme="@style/AppTheme" />

<activity
android:name=".settings.SettingsActivity"
android:name=".ui.settings.SettingsActivity"
android:label="@string/settings"
android:parentActivityName=".ui.home.HomeActivity" />

Expand Down
Binary file modified app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ public boolean isLoggedIn() {
return (mPreferences.getSlackHandle() != null);
}

@Override
public void destroy() {
mPreferences.destroy();
// mDBHandler.destroy(); // this is yet to be implemented
mFirebaseHandler.destroy();
}

/**
* internal class for converting {@link FirebaseHandler} Callback to {@link DataHandler} Callback
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public interface DataHandler {

boolean isLoggedIn();

void destroy();
/**
* Generic callback interface for passing response to caller.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.developervishalsehgal.udacityscholarsapp.services;

import com.developervishalsehgal.udacityscholarsapp.data.models.Notification;
import com.developervishalsehgal.udacityscholarsapp.utils.AppConstants;
import com.developervishalsehgal.udacityscholarsapp.utils.NotificationUtils;

import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.util.Log;
import android.support.v7.preference.PreferenceManager;

import com.developervishalsehgal.udacityscholarsapp.R;
import com.developervishalsehgal.udacityscholarsapp.data.DataHandlerProvider;
import com.developervishalsehgal.udacityscholarsapp.data.models.Notification;
import com.developervishalsehgal.udacityscholarsapp.utils.AppConstants;
import com.developervishalsehgal.udacityscholarsapp.utils.NotificationUtils;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

Expand Down Expand Up @@ -79,7 +79,10 @@ private void storeNotification(@NonNull Notification notification) {
* @param notification - {@link Notification} object generated from received data payload
*/
private void raiseSystemNotification(@NonNull Notification notification) {

NotificationUtils.createNotification(this, notification, notification.getType());
// Before raising notification check if user has disabled notifications
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPrefs.getBoolean(getString(R.string.get_notification_key), false)) {
NotificationUtils.createNotification(this, notification, notification.getType());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class QuizDiscussionAdapter extends RecyclerView.Adapter<QuizDiscussionAdapter.ViewHolder> {
Expand Down Expand Up @@ -59,25 +58,15 @@ public void setComments(List<Comment> comments) {
this.mComments.clear();
this.mComments.addAll(comments);

Collections.sort(mComments, new Comparator<Comment>() {
@Override
public int compare(Comment o1, Comment o2) {
return (int) (o1.getCommentedOn() - o2.getCommentedOn());
}
});
Collections.sort(mComments, (o1, o2) -> (int) (o1.getCommentedOn() - o2.getCommentedOn()));

notifyDataSetChanged();
}

public void addComment(@NonNull Comment comment) {
mComments.add(comment);

Collections.sort(mComments, new Comparator<Comment>() {
@Override
public int compare(Comment o1, Comment o2) {
return (int) (o1.getCommentedOn() - o2.getCommentedOn());
}
});
Collections.sort(mComments, (o1, o2) -> (int) (o1.getCommentedOn() - o2.getCommentedOn()));

notifyDataSetChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
import com.bumptech.glide.Glide;
import com.developervishalsehgal.udacityscholarsapp.R;
import com.developervishalsehgal.udacityscholarsapp.data.models.Quiz;
import com.developervishalsehgal.udacityscholarsapp.settings.SettingsActivity;
import com.developervishalsehgal.udacityscholarsapp.ui.PresenterInjector;
import com.developervishalsehgal.udacityscholarsapp.ui.discussion.QuizDiscussionActivity;
import com.developervishalsehgal.udacityscholarsapp.ui.discussion.QuizDiscussionContract;
import com.developervishalsehgal.udacityscholarsapp.ui.notification.NotificationActivity;
import com.developervishalsehgal.udacityscholarsapp.ui.quizdetails.QuizDetailsActivity;
import com.developervishalsehgal.udacityscholarsapp.ui.quizdetails.QuizDetailsContract;
import com.developervishalsehgal.udacityscholarsapp.ui.settings.SettingsActivity;
import com.developervishalsehgal.udacityscholarsapp.utils.AppConstants;
import com.developervishalsehgal.udacityscholarsapp.utils.Connectivity;

Expand All @@ -63,7 +65,6 @@ public class HomeActivity extends AppCompatActivity implements HomeContract.View
private static final int SLIDE_UP_DELAY_ON_CHECKED_CHANGED = 350;
private static final int BACK_PRESS_DURATION = 3000;
private static final int DELAY_NAV_ITEM_CLICK = 250;
private static final String DEMO_TOAST_MSG = "Clicked!";

private QuizAdapter mQuizAdapter;

Expand All @@ -78,16 +79,16 @@ public class HomeActivity extends AppCompatActivity implements HomeContract.View
// UI Elements
private DrawerLayout mDrawerLayout;
private RecyclerView mQuizRecyclerView;
//////////////

private TextView mTvQuizCount;
private LottieAnimationView progressBar;
// Reference of the quiz filter list layout

private RadioGroup mRGHomeQuizListFilter;
//Empty View elements

private ImageView mIVEmptyFilterResult;
private TextView mTVEmptyFilterResult;
private LinearLayout mLLEmptyFilterResultContainer;
//////////////

boolean mTwiceClicked = false;
Snackbar mSnackbar;

Expand Down Expand Up @@ -127,7 +128,7 @@ private void initializeUI() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(getDrawable(R.mipmap.ic_launcher));
actionBar.setHomeAsUpIndicator(getDrawable(R.drawable.ic_menu_white_24dp));
}

mQuizRecyclerView = findViewById(R.id.recyclerview_quizzes);
Expand Down Expand Up @@ -166,6 +167,12 @@ private void initializeUI() {
mTvSlackHandle = navHeaderView.findViewById(R.id.slack_name_nav_drawer);
mTvUserName = navHeaderView.findViewById(R.id.username_nav_drawer);

findViewById(R.id.settings).setOnClickListener(v -> {
if (mPresenter != null) {
mPresenter.onNavigationItemSelected(HomeContract.NAVIGATION_SETTINGS);
}
});

//initializing empty view
mEmptyStateTextView = findViewById(R.id.empty_view);
}
Expand Down Expand Up @@ -212,7 +219,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public void loadQuizzes(List<Quiz> quizzes) {
if(!quizzes.isEmpty()) {
if (!quizzes.isEmpty()) {
mLLEmptyFilterResultContainer.setVisibility(View.GONE);
}
mQuizRecyclerView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -260,13 +267,13 @@ public void navigateToQuizDesc(Quiz quiz) {
@Override
public void navigateToScoreboard() {
// TODO: Navigate to Scoreboard screen
Toast.makeText(getApplicationContext(), DEMO_TOAST_MSG, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.msg_under_construction, Toast.LENGTH_SHORT).show();
}

@Override
public void navigateToCreateQuiz() {
// TODO: Navigate to Create Quiz screen
Toast.makeText(getApplicationContext(), DEMO_TOAST_MSG, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.msg_under_construction, Toast.LENGTH_SHORT).show();
}

@Override
Expand All @@ -284,20 +291,34 @@ public void navigateToResources() {

@Override
public void navigateToSettings() {
// TODO: Navigate to Settings screen
Toast.makeText(getApplicationContext(), DEMO_TOAST_MSG, Toast.LENGTH_SHORT).show();
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}

@Override
public void navigateToAboutScreen() {
// TODO: Navigate to About screen
Toast.makeText(getApplicationContext(), DEMO_TOAST_MSG, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.msg_under_construction, Toast.LENGTH_SHORT).show();
}

@Override
public void navigateToEditProfile() {
// TODO: Navigate to edit profile activity
Toast.makeText(getApplicationContext(), DEMO_TOAST_MSG, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.msg_under_construction, Toast.LENGTH_SHORT).show();
}

@Override
public void navigateToQuizDiscussion(String quizId) {
Intent quizDiscussionIntent = new Intent(this, QuizDiscussionActivity.class);
quizDiscussionIntent.putExtra(QuizDiscussionContract.KEY_QUIZ_ID, quizId);
startActivity(quizDiscussionIntent);
}

@Override
public void navigateToQuizDetails(String quizId) {
Intent quizDetailsIntent = new Intent(this, QuizDiscussionActivity.class);
quizDetailsIntent.putExtra(QuizDetailsContract.KEY_QUIZ_ID, quizId);
startActivity(quizDetailsIntent);
}

@Override
Expand Down Expand Up @@ -560,6 +581,9 @@ private void setUpSwipeRefresh() {
swipeRefreshLayout.setColorSchemeResources(R.color.bnv_color, R.color.blue_jeans,
R.color.ufo_green, R.color.vivid_tangelo);
swipeRefreshLayout.setOnRefreshListener(() -> {

mPresenter.start(getIntent().getExtras());

swipeRefreshLayout.setRefreshing(true);

Handler handler = new Handler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ interface View extends BaseView<Presenter> {

void navigateToEditProfile();

void navigateToQuizDiscussion(String quizId);

void navigateToQuizDetails(String quizId);

void handleEmptyView(String selectedFilter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.developervishalsehgal.udacityscholarsapp.data.DataHandler;
import com.developervishalsehgal.udacityscholarsapp.data.DataHandlerProvider;
import com.developervishalsehgal.udacityscholarsapp.data.models.Quiz;
import com.developervishalsehgal.udacityscholarsapp.utils.AppConstants;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,8 +31,17 @@ public HomePresenter(HomeContract.View view) {

@Override
public void start(@Nullable Bundle extras) {
// TODO: check the bundle extras here if it contains quiz, or resource or some other id.
// TODO: If it does, take action accordingly and navigate to the right quiz / resource.
if (extras != null && extras.containsKey(AppConstants.KEY_TYPE)) {
if (AppConstants.NOTIFICATION_TYPE_DISCUSSION.equalsIgnoreCase(
extras.getString(AppConstants.KEY_TYPE))) {
String quizId = extras.getString(AppConstants.KEY_ACTION);
mView.navigateToQuizDiscussion(quizId);
} else if (AppConstants.NOTIFICATION_TYPE_QUIZ.equalsIgnoreCase(
extras.getString(AppConstants.KEY_TYPE))) {
String quizId = extras.getString(AppConstants.KEY_ACTION);
mView.navigateToQuizDetails(quizId);
}
}

mView.showLoading();
mDataHandler.fetchQuizzes(0, new DataHandler.Callback<List<Quiz>>() {
Expand Down Expand Up @@ -117,7 +127,7 @@ public void onAttemptedQuizSelected() {
attemptedQuizzes.add(quiz);
}
}
if(attemptedQuizzes.isEmpty()) {
if (attemptedQuizzes.isEmpty()) {
mView.handleEmptyView(HomeContract.ATTEMPTED_QUIZZES);
}
mView.loadQuizzes(attemptedQuizzes);
Expand All @@ -131,7 +141,7 @@ public void onUnAttemptedQuizSelected() {
unAttemptedQuizzes.add(quiz);
}
}
if(unAttemptedQuizzes.isEmpty()) {
if (unAttemptedQuizzes.isEmpty()) {
mView.handleEmptyView(HomeContract.UNATTEMPTED_QUIZZES);
}
mView.loadQuizzes(unAttemptedQuizzes);
Expand All @@ -145,7 +155,7 @@ public void onBookmarkSelected() {
bookmarkedQuizzes.add(quiz);
}
}
if(bookmarkedQuizzes.isEmpty()) {
if (bookmarkedQuizzes.isEmpty()) {
mView.handleEmptyView(HomeContract.BOOKMARKED_QUIZZES);
}
mView.loadQuizzes(bookmarkedQuizzes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.developervishalsehgal.udacityscholarsapp.settings;
package com.developervishalsehgal.udacityscholarsapp.ui.settings;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.developervishalsehgal.udacityscholarsapp.R;

Expand Down
Loading

0 comments on commit 6059f4a

Please sign in to comment.