|
@ -36,7 +36,6 @@ import android.view.MenuItem; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.view.ViewGroup; |
|
|
import android.view.ViewGroup; |
|
|
import android.widget.ImageButton; |
|
|
import android.widget.ImageButton; |
|
|
import android.widget.PopupMenu; |
|
|
|
|
|
import android.widget.ProgressBar; |
|
|
import android.widget.ProgressBar; |
|
|
import android.widget.TextView; |
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
@ -45,12 +44,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; |
|
|
import com.google.android.material.snackbar.Snackbar; |
|
|
import com.google.android.material.snackbar.Snackbar; |
|
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
import java.io.Serializable; |
|
|
import java.text.Collator; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Collections; |
|
|
|
|
|
import java.util.Comparator; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Locale; |
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
import java.util.concurrent.ExecutorService; |
|
|
import java.util.concurrent.Executors; |
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
@ -75,7 +70,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
private TextView tvSupport; |
|
|
private TextView tvSupport; |
|
|
private ImageButton ibHintSupport; |
|
|
private ImageButton ibHintSupport; |
|
|
private ImageButton ibHintActions; |
|
|
private ImageButton ibHintActions; |
|
|
private View popupAnchor; |
|
|
|
|
|
private TextView tvNoEmail; |
|
|
private TextView tvNoEmail; |
|
|
private RecyclerView rvMessage; |
|
|
private RecyclerView rvMessage; |
|
|
private BottomNavigationView bottom_navigation; |
|
|
private BottomNavigationView bottom_navigation; |
|
@ -100,7 +94,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
|
|
|
|
|
|
private int autoCount = 0; |
|
|
private int autoCount = 0; |
|
|
private boolean autoExpand = true; |
|
|
private boolean autoExpand = true; |
|
|
private long swipeTarget = -1; |
|
|
|
|
|
private List<Long> expanded = new ArrayList<>(); |
|
|
private List<Long> expanded = new ArrayList<>(); |
|
|
private List<Long> headers = new ArrayList<>(); |
|
|
private List<Long> headers = new ArrayList<>(); |
|
|
private List<Long> images = new ArrayList<>(); |
|
|
private List<Long> images = new ArrayList<>(); |
|
@ -147,7 +140,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
tvSupport = view.findViewById(R.id.tvSupport); |
|
|
tvSupport = view.findViewById(R.id.tvSupport); |
|
|
ibHintSupport = view.findViewById(R.id.ibHintSupport); |
|
|
ibHintSupport = view.findViewById(R.id.ibHintSupport); |
|
|
ibHintActions = view.findViewById(R.id.ibHintActions); |
|
|
ibHintActions = view.findViewById(R.id.ibHintActions); |
|
|
popupAnchor = view.findViewById(R.id.popupAnchor); |
|
|
|
|
|
tvNoEmail = view.findViewById(R.id.tvNoEmail); |
|
|
tvNoEmail = view.findViewById(R.id.tvNoEmail); |
|
|
rvMessage = view.findViewById(R.id.rvFolder); |
|
|
rvMessage = view.findViewById(R.id.rvFolder); |
|
|
bottom_navigation = view.findViewById(R.id.bottom_navigation); |
|
|
bottom_navigation = view.findViewById(R.id.bottom_navigation); |
|
@ -159,8 +151,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
fab = view.findViewById(R.id.fab); |
|
|
fab = view.findViewById(R.id.fab); |
|
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
if (folder >= 0) |
|
|
|
|
|
swipeTarget = prefs.getLong("swipe." + folder, -1); |
|
|
|
|
|
|
|
|
|
|
|
// Wire controls |
|
|
// Wire controls |
|
|
|
|
|
|
|
@ -277,9 +267,8 @@ public class FragmentMessages extends FragmentEx { |
|
|
|
|
|
|
|
|
if (dX > margin) { |
|
|
if (dX > margin) { |
|
|
// Right swipe |
|
|
// Right swipe |
|
|
Drawable d = getResources().getDrawable(swipeTarget < 0 |
|
|
|
|
|
? (inbox ? R.drawable.baseline_move_to_inbox_24 : R.drawable.baseline_archive_24) |
|
|
|
|
|
: R.drawable.baseline_folder_24, |
|
|
|
|
|
|
|
|
Drawable d = getResources().getDrawable( |
|
|
|
|
|
inbox ? R.drawable.baseline_move_to_inbox_24 : R.drawable.baseline_archive_24, |
|
|
getContext().getTheme()); |
|
|
getContext().getTheme()); |
|
|
int padding = (itemView.getHeight() - d.getIntrinsicHeight()); |
|
|
int padding = (itemView.getHeight() - d.getIntrinsicHeight()); |
|
|
d.setBounds( |
|
|
d.setBounds( |
|
@ -316,16 +305,13 @@ public class FragmentMessages extends FragmentEx { |
|
|
|
|
|
|
|
|
Bundle args = new Bundle(); |
|
|
Bundle args = new Bundle(); |
|
|
args.putLong("id", message.id); |
|
|
args.putLong("id", message.id); |
|
|
args.putLong("folder", folder); |
|
|
|
|
|
args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD); |
|
|
args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD); |
|
|
args.putInt("direction", direction); |
|
|
args.putInt("direction", direction); |
|
|
args.putLong("swipeTarget", swipeTarget); |
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<MessageTarget>() { |
|
|
new SimpleTask<MessageTarget>() { |
|
|
@Override |
|
|
@Override |
|
|
protected MessageTarget onLoad(Context context, Bundle args) { |
|
|
protected MessageTarget onLoad(Context context, Bundle args) { |
|
|
long id = args.getLong("id"); |
|
|
long id = args.getLong("id"); |
|
|
long fid = args.getLong("folder"); |
|
|
|
|
|
boolean thread = args.getBoolean("thread"); |
|
|
boolean thread = args.getBoolean("thread"); |
|
|
int direction = args.getInt("direction"); |
|
|
int direction = args.getInt("direction"); |
|
|
|
|
|
|
|
@ -339,21 +325,17 @@ public class FragmentMessages extends FragmentEx { |
|
|
|
|
|
|
|
|
EntityMessage message = db.message().getMessage(id); |
|
|
EntityMessage message = db.message().getMessage(id); |
|
|
|
|
|
|
|
|
if (fid < 0 || swipeTarget < 0 || direction == ItemTouchHelper.LEFT) { |
|
|
|
|
|
EntityFolder folder = db.folder().getFolder(message.folder); |
|
|
|
|
|
if (EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.TRASH.equals(folder.type)) |
|
|
|
|
|
|
|
|
EntityFolder folder = db.folder().getFolder(message.folder); |
|
|
|
|
|
if (EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.TRASH.equals(folder.type)) |
|
|
|
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); |
|
|
|
|
|
else { |
|
|
|
|
|
if (direction == ItemTouchHelper.RIGHT) |
|
|
|
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE); |
|
|
|
|
|
if (direction == ItemTouchHelper.LEFT || target == null) |
|
|
|
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.TRASH); |
|
|
|
|
|
if (target == null) |
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); |
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); |
|
|
else { |
|
|
|
|
|
if (direction == ItemTouchHelper.RIGHT) |
|
|
|
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE); |
|
|
|
|
|
else if (direction == ItemTouchHelper.LEFT) |
|
|
|
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.TRASH); |
|
|
|
|
|
} |
|
|
|
|
|
} else |
|
|
|
|
|
target = db.folder().getFolder(swipeTarget); |
|
|
|
|
|
|
|
|
|
|
|
if (target == null || !target.account.equals((message.account))) |
|
|
|
|
|
throw new IllegalArgumentException(getString(R.string.title_no_target)); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
result.target = target.name; |
|
|
result.target = target.name; |
|
|
result.display = (target.display == null ? target.name : target.display); |
|
|
result.display = (target.display == null ? target.name : target.display); |
|
@ -521,7 +503,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
super.onSaveInstanceState(outState); |
|
|
super.onSaveInstanceState(outState); |
|
|
outState.putBoolean("autoExpand", autoExpand); |
|
|
outState.putBoolean("autoExpand", autoExpand); |
|
|
outState.putInt("autoCount", autoCount); |
|
|
outState.putInt("autoCount", autoCount); |
|
|
outState.putLong("swipeTarget", swipeTarget); |
|
|
|
|
|
outState.putLongArray("expanded", Helper.toLongArray(expanded)); |
|
|
outState.putLongArray("expanded", Helper.toLongArray(expanded)); |
|
|
outState.putLongArray("headers", Helper.toLongArray(headers)); |
|
|
outState.putLongArray("headers", Helper.toLongArray(headers)); |
|
|
outState.putLongArray("images", Helper.toLongArray(images)); |
|
|
outState.putLongArray("images", Helper.toLongArray(images)); |
|
@ -534,7 +515,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
if (savedInstanceState != null) { |
|
|
if (savedInstanceState != null) { |
|
|
autoExpand = savedInstanceState.getBoolean("autoExpand"); |
|
|
autoExpand = savedInstanceState.getBoolean("autoExpand"); |
|
|
autoCount = savedInstanceState.getInt("autoCount"); |
|
|
autoCount = savedInstanceState.getInt("autoCount"); |
|
|
swipeTarget = savedInstanceState.getLong("swipeTarget"); |
|
|
|
|
|
expanded = Helper.fromLongArray(savedInstanceState.getLongArray("expanded")); |
|
|
expanded = Helper.fromLongArray(savedInstanceState.getLongArray("expanded")); |
|
|
headers = Helper.fromLongArray(savedInstanceState.getLongArray("headers")); |
|
|
headers = Helper.fromLongArray(savedInstanceState.getLongArray("headers")); |
|
|
images = Helper.fromLongArray(savedInstanceState.getLongArray("images")); |
|
|
images = Helper.fromLongArray(savedInstanceState.getLongArray("images")); |
|
@ -711,7 +691,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
menu.findItem(R.id.menu_sort_on).setVisible(TextUtils.isEmpty(search)); |
|
|
menu.findItem(R.id.menu_sort_on).setVisible(TextUtils.isEmpty(search)); |
|
|
menu.findItem(R.id.menu_folders).setVisible(primary >= 0); |
|
|
menu.findItem(R.id.menu_folders).setVisible(primary >= 0); |
|
|
menu.findItem(R.id.menu_folders).setIcon(connected ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24); |
|
|
menu.findItem(R.id.menu_folders).setIcon(connected ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24); |
|
|
menu.findItem(R.id.menu_swipe).setVisible(folder >= 0); |
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
String sort = prefs.getString("sort", "time"); |
|
|
String sort = prefs.getString("sort", "time"); |
|
@ -754,10 +733,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
loadMessages(); |
|
|
loadMessages(); |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
case R.id.menu_swipe: |
|
|
|
|
|
onMenuSwipeTarget(); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
default: |
|
|
return super.onOptionsItemSelected(item); |
|
|
return super.onOptionsItemSelected(item); |
|
|
} |
|
|
} |
|
@ -777,79 +752,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
fragmentTransaction.commit(); |
|
|
fragmentTransaction.commit(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void onMenuSwipeTarget() { |
|
|
|
|
|
Bundle args = new Bundle(); |
|
|
|
|
|
args.putLong("folder", folder); |
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<List<EntityFolder>>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
protected List<EntityFolder> onLoad(Context context, Bundle args) { |
|
|
|
|
|
long fid = args.getLong("folder"); |
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context); |
|
|
|
|
|
EntityFolder folder = db.folder().getFolder(fid); |
|
|
|
|
|
List<EntityFolder> folders = db.folder().getUserFolders(folder.account); |
|
|
|
|
|
|
|
|
|
|
|
final Collator collator = Collator.getInstance(Locale.getDefault()); |
|
|
|
|
|
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc |
|
|
|
|
|
|
|
|
|
|
|
Collections.sort(folders, new Comparator<EntityFolder>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public int compare(EntityFolder f1, EntityFolder f2) { |
|
|
|
|
|
return collator.compare(f1.name, f2.name); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
EntityFolder junk = db.folder().getFolderByType(folder.account, EntityFolder.JUNK); |
|
|
|
|
|
if (junk != null && !junk.id.equals(fid)) |
|
|
|
|
|
folders.add(0, junk); |
|
|
|
|
|
|
|
|
|
|
|
EntityFolder trash = db.folder().getFolderByType(folder.account, EntityFolder.TRASH); |
|
|
|
|
|
if (trash != null && !trash.id.equals(fid)) |
|
|
|
|
|
folders.add(0, trash); |
|
|
|
|
|
|
|
|
|
|
|
EntityFolder archive = db.folder().getFolderByType(folder.account, EntityFolder.ARCHIVE); |
|
|
|
|
|
if (archive != null && !archive.id.equals(fid)) |
|
|
|
|
|
folders.add(0, archive); |
|
|
|
|
|
|
|
|
|
|
|
EntityFolder sent = db.folder().getFolderByType(folder.account, EntityFolder.SENT); |
|
|
|
|
|
if (sent != null && !sent.id.equals(fid)) |
|
|
|
|
|
folders.add(0, sent); |
|
|
|
|
|
|
|
|
|
|
|
EntityFolder inbox = db.folder().getFolderByType(folder.account, EntityFolder.INBOX); |
|
|
|
|
|
if (inbox != null && !inbox.id.equals(fid)) |
|
|
|
|
|
folders.add(0, inbox); |
|
|
|
|
|
|
|
|
|
|
|
return folders; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void onLoaded(final Bundle args, List<EntityFolder> folders) { |
|
|
|
|
|
PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor); |
|
|
|
|
|
|
|
|
|
|
|
int order = 0; |
|
|
|
|
|
for (EntityFolder folder : folders) { |
|
|
|
|
|
String name = (folder.display == null |
|
|
|
|
|
? Helper.localizeFolderName(getContext(), folder.name) |
|
|
|
|
|
: folder.display); |
|
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, name); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onMenuItemClick(final MenuItem target) { |
|
|
|
|
|
swipeTarget = target.getItemId(); |
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
|
|
|
prefs.edit().putLong("swipe." + folder, swipeTarget).apply(); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
popupMenu.show(); |
|
|
|
|
|
} |
|
|
|
|
|
}.load(this, args); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void loadMessages() { |
|
|
private void loadMessages() { |
|
|
final DB db = DB.getInstance(getContext()); |
|
|
final DB db = DB.getInstance(getContext()); |
|
|
|
|
|
|
|
|