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

Two issues solved: #46

Merged
merged 1 commit into from
Oct 4, 2016
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
87 changes: 68 additions & 19 deletions app/src/main/java/com/sigmobile/dawebmail/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
import com.sigmobile.dawebmail.database.CurrentUser;
import com.sigmobile.dawebmail.database.EmailMessage;
import com.sigmobile.dawebmail.database.User;
import com.sigmobile.dawebmail.database.CurrentUser;
import com.sigmobile.dawebmail.fragments.FolderFragment;
import com.sigmobile.dawebmail.fragments.InboxFragment;
import com.sigmobile.dawebmail.fragments.SmartBoxFragment;
import com.sigmobile.dawebmail.network.AnalyticsAPI;
import com.sigmobile.dawebmail.services.NotificationMaker;
import com.sigmobile.dawebmail.utils.Constants;
import com.sigmobile.dawebmail.utils.Settings;
Expand All @@ -60,6 +59,7 @@ public class MainActivity extends AppCompatActivity {
private SecondaryDrawerItem sSettings, sFeedback, sContribute;
private ArrayList<IProfile> allAccountHeaders;
private IDrawerItem selectedDrawerItem;
private String currentDrawerItem;
private Settings settings;
private static final int MY_PERMISSIONS_REQUEST_WRITE_STORAGE = 108;

Expand All @@ -74,13 +74,32 @@ protected void onCreate(Bundle savedInstanceState) {
setupToolbar();
setupDrawer();

selectedDrawerItem = pInbox;
if(savedInstanceState != null){
currentDrawerItem = savedInstanceState.getString("currentDrawerItem", "inbox");
}
else {
currentDrawerItem = "inbox";
}

switch(currentDrawerItem){
case "inbox": selectedDrawerItem = pInbox; break;
case "smartbox": selectedDrawerItem = pSmartBox; break;
case "sentbox": selectedDrawerItem = pSentBox; break;
case "trashbox": selectedDrawerItem = pTrashBox; break;
default: selectedDrawerItem = pInbox;
currentDrawerItem = "inbox";
}

setSelectedAccountHeader(true);

showUpdatesDialog();
checkPermission();
}

AnalyticsAPI.sendValueLessAction(AnalyticsAPI.ACTION_APP_OPEN, getApplicationContext());
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("currentDrawerItem", currentDrawerItem);
}

@Override
Expand Down Expand Up @@ -125,15 +144,18 @@ public boolean onProfileChanged(View view, IProfile profile, boolean current) {
CurrentUser.setCurrentUser(null, getApplicationContext());
startActivity(new Intent(MainActivity.this, LoginActivity.class));
drawer.closeDrawer();
AnalyticsAPI.sendValueLessAction(AnalyticsAPI.ACTION_NEW_ACCOUNT, getApplicationContext());
return true;
} else {
CurrentUser.setCurrentUser(User.getUserFromUserName(profile.getName().getText()), getApplicationContext());
drawer.closeDrawer();
if (selectedDrawerItem == null)
if (selectedDrawerItem == null) {
selectedDrawerItem = pInbox;
else if (!selectedDrawerItem.isSelectable())
currentDrawerItem = "inbox";
}
else if (!selectedDrawerItem.isSelectable()) {
selectedDrawerItem = pInbox;
currentDrawerItem = "inbox";
}
setDrawerSelection(selectedDrawerItem);
setToolbarTitle(selectedDrawerItem);
return true;
Expand Down Expand Up @@ -172,29 +194,55 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
setToolbarTitle(drawerItem);
if (drawerItem.equals(pInbox)) {
selectedDrawerItem = (PrimaryDrawerItem) drawerItem;
fragment = new InboxFragment();
currentDrawerItem = "inbox";

if(getSupportFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_INBOX)!=null) {
fragment = getSupportFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_INBOX);
}
else {
fragment = new InboxFragment();
}

Snackbar.make(frameLayout, getString(R.string.drawer_inbox), Snackbar.LENGTH_SHORT).show();
fragmentTag = Constants.FRAGMENT_TAG_INBOX;
} else if (drawerItem.equals(pSmartBox)) {
selectedDrawerItem = (PrimaryDrawerItem) drawerItem;
currentDrawerItem = "smartbox";
fragment = new SmartBoxFragment();
Snackbar.make(frameLayout, getString(R.string.drawer_smartbox), Snackbar.LENGTH_SHORT).show();
fragmentTag = Constants.FRAGMENT_TAG_SMARTBOX;
} else if (drawerItem.equals(pSentBox)) {
selectedDrawerItem = (PrimaryDrawerItem) drawerItem;
fragment = new FolderFragment();
bundle = new Bundle();
bundle.putString(Constants.FOLDER, Constants.SENT);
fragment.setArguments(bundle);
fragmentTag = Constants.FRAGMENT_TAG_FOLDER;
currentDrawerItem = "sentbox";

if(getSupportFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_FOLDER + Constants.SENT)!=null){
fragment = getSupportFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_FOLDER + Constants.SENT);
}
else{
fragment = new FolderFragment();
bundle = new Bundle();
bundle.putString(Constants.FOLDER, Constants.SENT);
fragment.setArguments(bundle);
}


fragmentTag = Constants.FRAGMENT_TAG_FOLDER + Constants.SENT;
Snackbar.make(frameLayout, getString(R.string.drawer_sent), Snackbar.LENGTH_SHORT).show();
} else if (drawerItem.equals(pTrashBox)) {
selectedDrawerItem = (PrimaryDrawerItem) drawerItem;
fragment = new FolderFragment();
bundle = new Bundle();
bundle.putString(Constants.FOLDER, Constants.TRASH);
fragment.setArguments(bundle);
fragmentTag = Constants.FRAGMENT_TAG_FOLDER;
currentDrawerItem = "trashbox";

if(getSupportFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_FOLDER + Constants.TRASH)!=null){
fragment = getSupportFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_FOLDER + Constants.TRASH);
}
else{
fragment = new FolderFragment();
bundle = new Bundle();
bundle.putString(Constants.FOLDER, Constants.TRASH);
fragment.setArguments(bundle);
}

fragmentTag = Constants.FRAGMENT_TAG_FOLDER + Constants.TRASH;
Snackbar.make(frameLayout, getString(R.string.drawer_trash), Snackbar.LENGTH_SHORT).show();
} else if (drawerItem.equals(sSettings)) {
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
Expand Down Expand Up @@ -290,7 +338,6 @@ public void onClick(View view) {
else
CurrentUser.setCurrentUser(null, getApplicationContext());

AnalyticsAPI.sendValueLessAction(AnalyticsAPI.ACTION_LOGOUT, getApplicationContext());

new Handler().postDelayed(new Runnable() {
@Override
Expand Down Expand Up @@ -415,4 +462,6 @@ public void onClick(View v) {
Log.d(TAG, "Already Granted");
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import java.util.ArrayList;

public class MailAdapter extends RecyclerView.Adapter<MailAdapter.ViewHolder> {
public class MailAdapter extends RecyclerView.Adapter<MailAdapter.ViewHolder>{

private final String TAG = "MailAdapter";

Expand Down Expand Up @@ -181,4 +181,17 @@ public void setEmails(ArrayList<EmailMessage> emails) {
this.emails = emails;
clickedForDelete = new boolean[this.emails.size()];
}

public boolean[] getMarkedMails(){
return clickedForDelete;
}

public void restoreMarkedMails(boolean marked[]){
for(int i=0; i<emails.size(); i++){
if(marked[i]){
addEmailForDelete(i, emails.get(i));
}
}
multiMailActionSelectedListener.onItemClickedForDelete(emailsMarkedForAction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
import com.sigmobile.dawebmail.asyncTasks.MultiMailActionListener;
import com.sigmobile.dawebmail.asyncTasks.RefreshInbox;
import com.sigmobile.dawebmail.asyncTasks.RefreshInboxListener;
import com.sigmobile.dawebmail.database.CurrentUser;
import com.sigmobile.dawebmail.database.EmailMessage;
import com.sigmobile.dawebmail.database.User;
import com.sigmobile.dawebmail.database.CurrentUser;
import com.sigmobile.dawebmail.utils.Constants;

import java.util.ArrayList;
import java.util.Arrays;

import butterknife.Bind;
import butterknife.ButterKnife;
Expand All @@ -62,6 +63,8 @@ public class FolderFragment extends Fragment implements RefreshInboxListener, Mu
private ArrayList<EmailMessage> allEmails;
private User currentUser;
private String folder;
private MenuItem selectAll;
private boolean markedMails[];

public FolderFragment() {
}
Expand Down Expand Up @@ -92,6 +95,24 @@ else if (folder.equals(Constants.TRASH))
return rootView;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if(savedInstanceState != null)
markedMails = savedInstanceState.getBooleanArray("markedEmails");
else
markedMails = null;

setHasOptionsMenu(true);
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBooleanArray("markedEmails", mailAdapter.getMarkedMails());
}

@Override
public void onResume() {
super.onResume();
Expand Down Expand Up @@ -139,22 +160,29 @@ public void onRefresh() {
android.R.color.holo_blue_dark);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_folder_menu, menu);
selectAll = menu.getItem(0);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_logout) {
logout();
}else if(id == R.id.action_selectall){
if(item.isChecked()){
item.setChecked(false);
item.setIcon(R.drawable.ic_action_selectall_unchecked);
selectAllMails(false);
setupSelectAll(false);
}
else{
item.setChecked(true);
item.setIcon(R.drawable.ic_action_selectall_checked);
selectAllMails(true);
}
}
return super.onOptionsItemSelected(item);
}
Expand All @@ -175,15 +203,27 @@ public void onPostRefresh(boolean success, final ArrayList<EmailMessage> refresh
* Check if the fragment is attached to the activity
* if it isn't, then set bundle stating that a refresh is required.
*/
FolderFragment thisFragment = (FolderFragment) getFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_FOLDER);
if (!thisFragment.isAdded()) {
if (getFragmentManager() != null) {
FolderFragment thisFragment = (FolderFragment) getFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_FOLDER+folder);
if (thisFragment != null) {
Bundle bundle = new Bundle();
bundle.putInt(Constants.BUNDLE_ON_POST_REFRESH_EMAILS_SIZE, refreshedEmails.size());
thisFragment.setArguments(bundle);
if (!thisFragment.isAdded()) {
if (thisFragment != null) {
Bundle bundle = new Bundle();
bundle.putInt(Constants.BUNDLE_ON_POST_REFRESH_EMAILS_SIZE, refreshedEmails.size());
thisFragment.setArguments(bundle);
}
} else {
onPostRefresh(refreshedEmails.size());
}
} else {
refreshAdapter();
progressDialog2.dismiss();
swipeRefreshLayout.setRefreshing(false);
}
} else {
onPostRefresh(refreshedEmails.size());
refreshAdapter();
progressDialog2.dismiss();
swipeRefreshLayout.setRefreshing(false);
}
}

Expand Down Expand Up @@ -238,6 +278,7 @@ public void refreshAdapter() {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
restoreMarkedMails();
recyclerView.setAdapter(mailAdapter);
}

Expand All @@ -260,12 +301,45 @@ public void onClick(View view) {
if (fabDelete.getVisibility() != View.VISIBLE) {
fabDelete.setVisibility(View.VISIBLE);
fabDelete.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.abc_slide_in_bottom));
setupSelectAll(true);
}
} else {
if (fabDelete.getVisibility() != View.GONE) {
fabDelete.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.abc_slide_out_bottom));
fabDelete.setVisibility(View.GONE);
setupSelectAll(false);
}
}
}

private void setupSelectAll(boolean set){
if(selectAll != null){
if(set){
selectAll.setVisible(true);
selectAll.setEnabled(true);
}
else{
selectAll.setVisible(false);
selectAll.setEnabled(false);
}
}
}

private void selectAllMails(boolean select){
markedMails = new boolean[ allEmails.size() ];
if(select){
Arrays.fill(markedMails, true);
}
else{
Arrays.fill(markedMails, false);
}
refreshAdapter();
}

private void restoreMarkedMails(){
if(markedMails != null) {
mailAdapter.restoreMarkedMails(markedMails);
markedMails = null;
}
}
}
Loading