Move folders to navigation menu, navigate by account

pull/30/head
M66B 6 years ago
parent d5a55f9e27
commit d075f56e2d

@ -38,18 +38,20 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
public class ActivityView extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
private boolean newIntent = false;
@ -101,8 +103,8 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = (DrawerItem) parent.getAdapter().getItem(position);
switch (item.getId()) {
case R.string.menu_folders:
onMenuFolders();
case -1:
onMenuFolders((long) item.getData());
break;
case R.string.menu_setup:
onMenuSetup();
@ -115,15 +117,39 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
break;
}
if (!item.isCheckable())
drawerLayout.closeDrawer(drawerList);
drawerLayout.closeDrawer(drawerList);
}
});
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
getSupportFragmentManager().addOnBackStackChangedListener(this);
updateDrawer();
DB.getInstance(this).account().liveAccounts().observe(this, new Observer<List<EntityAccount>>() {
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
ArrayAdapterDrawer drawerArray = new ArrayAdapterDrawer(ActivityView.this, R.layout.item_drawer);
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(accounts, new Comparator<EntityAccount>() {
@Override
public int compare(EntityAccount a1, EntityAccount a2) {
return collator.compare(a1.name, a2.name);
}
});
for (EntityAccount account : accounts)
drawerArray.add(new DrawerItem(-1, R.drawable.baseline_folder_24, account.name, account.id));
drawerArray.add(new DrawerItem(ActivityView.this, R.drawable.baseline_settings_applications_24, R.string.menu_setup));
if (getIntentFAQ().resolveActivity(getPackageManager()) != null)
drawerArray.add(new DrawerItem(ActivityView.this, R.drawable.baseline_question_answer_24, R.string.menu_faq));
drawerArray.add(new DrawerItem(ActivityView.this, R.drawable.baseline_help_24, R.string.menu_about));
drawerList.setAdapter(drawerArray);
}
});
if (getSupportFragmentManager().getFragments().size() == 0)
init();
@ -216,20 +242,6 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
init();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_view, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
menu.findItem(R.id.menu_folders).setVisible(prefs.getBoolean("eula" , false));
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item))
@ -239,9 +251,6 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
case android.R.id.home:
getSupportFragmentManager().popBackStack();
return true;
case R.id.menu_folders:
onMenuFolders();
return true;
default:
return false;
}
@ -280,26 +289,23 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
}
}
public void updateDrawer() {
ArrayAdapterDrawer drawerArray = new ArrayAdapterDrawer(this, R.layout.item_drawer);
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_setup));
if (getIntentFAQ().resolveActivity(getPackageManager()) != null)
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_faq));
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_about));
drawerList.setAdapter(drawerArray);
}
private Intent getIntentFAQ() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://github.com/M66B/open-source-email/blob/master/FAQ.md"));
return intent;
}
private void onMenuFolders() {
private void onMenuFolders(long account) {
getSupportFragmentManager().popBackStack("unified" , 0);
Bundle args = new Bundle();
args.putLong("account" , account);
FragmentFolders fragment = new FragmentFolders();
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentFolders()).addToBackStack("folders");
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("folders");
fragmentTransaction.commit();
}
@ -319,38 +325,29 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
private class DrawerItem {
private int id;
private int icon;
private String title;
private boolean checkable;
private boolean checked;
private Object data;
DrawerItem(Context context, int title) {
DrawerItem(Context context, int icon, int title) {
this.id = title;
this.icon = icon;
this.title = context.getString(title);
this.checkable = false;
this.checked = false;
}
DrawerItem(Context context, int title, boolean checked) {
this.id = title;
this.title = context.getString(title);
this.checkable = true;
this.checked = checked;
DrawerItem(int id, int icon, String title, Object data) {
this.id = id;
this.icon = icon;
this.title = title;
this.data = data;
}
public int getId() {
return this.id;
}
public String getTitle() {
return this.title;
}
public boolean isCheckable() {
return this.checkable;
}
public boolean isChecked() {
return this.checked;
public Object getData() {
return this.data;
}
}
@ -372,11 +369,11 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
DrawerItem item = getItem(position);
ImageView iv = row.findViewById(R.id.ivItem);
TextView tv = row.findViewById(R.id.tvItem);
CheckBox cb = row.findViewById(R.id.cbItem);
tv.setText(item.getTitle());
cb.setVisibility(item.isCheckable() ? View.VISIBLE : View.GONE);
cb.setChecked(item.isChecked());
iv.setImageResource(item.icon);
tv.setText(item.title);
return row;
}

@ -51,20 +51,20 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
implements View.OnClickListener, View.OnLongClickListener {
View itemView;
TextView tvName;
TextView tvMessages;
TextView tvType;
TextView tvAfter;
ImageView ivSync;
TextView tvAccount;
TextView tvType;
ViewHolder(View itemView) {
super(itemView);
this.itemView = itemView;
tvName = itemView.findViewById(R.id.tvName);
tvMessages = itemView.findViewById(R.id.tvMessages);
tvType = itemView.findViewById(R.id.tvType);
tvAfter = itemView.findViewById(R.id.tvAfter);
ivSync = itemView.findViewById(R.id.ivSync);
tvAccount = itemView.findViewById(R.id.tvAccount);
tvType = itemView.findViewById(R.id.tvType);
}
private void wire() {
@ -79,23 +79,25 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private void bindTo(TupleFolderEx folder) {
String name = Helper.localizeFolderName(context, folder.name);
tvName.setText(context.getString(R.string.title_folder_unseen, name, folder.unseen, folder.messages));
if (folder.unseen > 0)
tvName.setText(context.getString(R.string.title_folder_unseen, name, folder.unseen));
else
tvName.setText(name);
tvName.setTypeface(null, folder.unseen > 0 ? Typeface.BOLD : Typeface.NORMAL);
tvName.setTextColor(Helper.resolveColor(context, folder.unseen > 0 ? R.attr.colorUnread : android.R.attr.textColorSecondary));
tvAfter.setText(Integer.toString(folder.after));
tvAfter.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
ivSync.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
tvAccount.setText(folder.accountName);
tvAccount.setVisibility(EntityFolder.TYPE_OUTBOX.equals(folder.type) ? View.GONE : View.VISIBLE);
tvMessages.setText(Integer.toString(folder.messages));
int resid = context.getResources().getIdentifier(
"title_folder_" + folder.type.toLowerCase(),
"string" ,
context.getPackageName());
tvType.setText(resid > 0 ? context.getString(resid) : folder.type);
tvAfter.setText(Integer.toString(folder.after));
tvAfter.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
ivSync.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
}
@Override

@ -25,7 +25,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@ -45,7 +44,6 @@ public class FragmentAbout extends FragmentEx {
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.menu_about);
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_about, container, false);
@ -97,9 +95,4 @@ public class FragmentAbout extends FragmentEx {
return view;
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.clear();
}
}

@ -28,7 +28,6 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
@ -48,7 +47,6 @@ public class FragmentFolders extends FragmentEx {
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_list_folders);
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_folders, container, false);
@ -94,9 +92,4 @@ public class FragmentFolders extends FragmentEx {
return view;
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.clear();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save