Skip to content

Commit

Permalink
GibQuote v2.6.6 | FAB ftw | Default Screens | Animations
Browse files Browse the repository at this point in the history
** Forgot to add CommonUtils and CommonUtilService **
** Added in this commit **

* GibQuoteFragment:
  - Implemented a FAB Menu, contanining two options
    - Change Quote Provider (Yeah, removed the spinner)
    - Clear Quotes from RecyclerView
    - Added in Animations for opening, and closing of this menu
    - TODO: Close the menu after any of the options has been used
  - There's a single TapTarget now, since the spinner has been removed

TODO: Show previously selected quote provider in AlertDialog

Default Screens: Add default messages in {Gib,Fav}QuoteFragment, when they're empty

Signed-off-by: a7r3 <arvindultimate7352@gmail.com>
  • Loading branch information
a7r3 committed Jan 6, 2018
1 parent 669800d commit 6621e21
Show file tree
Hide file tree
Showing 21 changed files with 770 additions and 154 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 16
targetSdkVersion 27
versionCode 2
versionName "2.6.5"
versionName "2.6.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/arvind/quote/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen
// Application's Shared Preferences
private SharedPreferences sharedPreferences;
// Theme ID - from styles.xml
private int themeId = R.style.AppTheme;
public static int themeId = R.style.AppTheme;
// Keep track of previous selected Drawer Item
// to make sure the same fragment isn't instantiated again
private MenuItem previousItem;
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/java/com/arvind/quote/adapter/FavQuoteAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.arvind.quote.R;
import com.arvind.quote.database.FavDatabaseHelper;
import com.arvind.quote.fragment.FavQuoteFragment;
import com.arvind.quote.utils.CommonUtils;

import java.util.List;
Expand Down Expand Up @@ -57,7 +58,7 @@ public int getItemCount() {
return favQuoteList.size();
}

public class QuoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {
public class QuoteViewHolder extends RecyclerView.ViewHolder {

final TextView quoteTextView;
final TextView authorTextView;
Expand All @@ -68,24 +69,35 @@ public class QuoteViewHolder extends RecyclerView.ViewHolder implements View.OnL
quoteTextView = itemView.findViewById(R.id.quote_text_view);
authorTextView = itemView.findViewById(R.id.author_text_view);

itemView.setOnLongClickListener(this);
itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
CommonUtils.shareQuote(context, favQuoteList.get(getAdapterPosition()));
return true;
}
});


// Implement Simple DoubleTap listener
final GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
final Quote quote = favQuoteList.get(getAdapterPosition());
new AlertDialog
.Builder(context)
.setIcon(android.R.drawable.ic_menu_delete)
.setTitle("Confirm Deletion of Quote ?")
.setTitle("Confirm Deletion of Quote")
.setMessage("Doing this will remove this quote from Favorites list")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
FavDatabaseHelper favDatabaseHelper = FavDatabaseHelper.getInstance(context);
favDatabaseHelper.removeFavQuote(favQuoteList.get(getAdapterPosition()).getId());
favQuoteList.remove(favQuoteList.get(getAdapterPosition()));
favDatabaseHelper.removeFavQuote(quote.getId());
quote.setStarred(false);
favQuoteList.remove(quote);
notifyItemRemoved(getAdapterPosition());
if(getItemCount() == 0)
FavQuoteFragment.showDefaultFragLayout();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
Expand All @@ -110,11 +122,5 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
}
});
}

@Override
public boolean onLongClick(View v) {
CommonUtils.shareQuote(context, favQuoteList.get(getAdapterPosition()));
return true;
}
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/arvind/quote/adapter/QuoteAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -17,6 +18,7 @@ public class QuoteAdapter extends RecyclerView.Adapter<QuoteAdapter.QuoteViewHol

private final List<Quote> quoteList;
private Context context = null;
public static boolean isClickable = true;

public QuoteAdapter(Context context, List<Quote> quoteDetails) {
this.context = context;
Expand Down Expand Up @@ -88,6 +90,8 @@ public class QuoteViewHolder extends RecyclerView.ViewHolder {
starQuoteView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!isClickable)
return;
Quote selectedQuote = quoteList.get(getAdapterPosition());
if (selectedQuote.isStarred()) {
CommonUtils.removeFromFavQuotesList(context, selectedQuote.getId());
Expand All @@ -104,6 +108,9 @@ public void onClick(View v) {
itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
Log.d("QAdapter", "kek");
if(!isClickable)
return false;
CommonUtils.shareQuote(context, quoteList.get(getAdapterPosition()));
return true;
}
Expand Down
34 changes: 25 additions & 9 deletions app/src/main/java/com/arvind/quote/fragment/FavQuoteFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arvind.quote.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
Expand All @@ -13,6 +14,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.arvind.quote.MainActivity;
import com.arvind.quote.R;
Expand All @@ -27,41 +29,45 @@ public class FavQuoteFragment extends Fragment {
private final String TAG = "FavQuoteFragment";
private SharedPreferences sharedPreferences;
private Snackbar snackbar;
private static LinearLayout favQuoteDefaultLayout;
private static RecyclerView quoteRecyclerView;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// RecyclerView's Adapter - Detects change on DataSet
FavDatabaseHelper dbHalp = FavDatabaseHelper.getInstance(getActivity().getApplicationContext());

View view = inflater.inflate(R.layout.fav_quote_fragment, container, false);

MainActivity.setActionBarTitle("FavQuotes");

// RecyclerView Object
RecyclerView quoteRecyclerView = view.findViewById(R.id.fav_quote_recyclerview);
quoteRecyclerView = view.findViewById(R.id.fav_quote_recyclerview);

// RecyclerView's Adapter - Detects change on DataSet
FavDatabaseHelper dbHalp = FavDatabaseHelper.getInstance(getActivity().getApplicationContext());
favQuoteDefaultLayout = view.findViewById(R.id.fav_quote_fragment_default_layout);

ArrayList<Quote> favQuoteArrayList = dbHalp.getFavQuotes();
if(dbHalp.getRowCount() == 0)
showDefaultFragLayout();
else
showFavRecycler();

// List of Fav Quotes, get it from Database
ArrayList<Quote> favQuoteArrayList = dbHalp.getFavQuotes();
FavQuoteAdapter favQuoteAdapter = new FavQuoteAdapter(getContext(), favQuoteArrayList);

// Allows Recycler to perform actions on the Layout
// whenever the particular adapter detects a change
quoteRecyclerView.setAdapter(favQuoteAdapter);

// RecyclerView's Layout Manager
// Used for viewing RecyclerView's nodes
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());

// Set Layout Manager for RecyclerView
// Two Managers available: 1. LinearLayoutManager 2. StaggeredGridLayoutManager
quoteRecyclerView.setLayoutManager(linearLayoutManager);

// Add Default ItemDecoration
// Used to Decorate every RecyclerView Item
// Any interaction with the Item won't affect the decoration
quoteRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
if (!sharedPreferences.getBoolean("IS_DELETE_QUOTE_SHOWN", false)) {
// Instruct the user
Expand All @@ -86,6 +92,16 @@ public void onClick(View view) {
return view;
}

public static void showDefaultFragLayout() {
favQuoteDefaultLayout.setVisibility(View.VISIBLE);
quoteRecyclerView.setVisibility(View.GONE);
}

public static void showFavRecycler() {
favQuoteDefaultLayout.setVisibility(View.GONE);
quoteRecyclerView.setVisibility(View.VISIBLE);
}

@Override
public void onDestroyView() {
if (snackbar != null)
Expand Down

0 comments on commit 6621e21

Please sign in to comment.