Browse Source

Use bottom bar for previous/next navigation

main
M66B 6 years ago
parent
commit
dcd6b7c384
7 changed files with 123 additions and 16 deletions
  1. +6
    -1
      app/src/main/java/eu/faircode/email/ActivityView.java
  2. +34
    -14
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  3. +36
    -0
      app/src/main/java/eu/faircode/email/ViewModelMessages.java
  4. +10
    -0
      app/src/main/res/drawable/baseline_navigate_before_24.xml
  5. +10
    -0
      app/src/main/res/drawable/baseline_navigate_next_24.xml
  6. +14
    -1
      app/src/main/res/layout/fragment_messages.xml
  7. +13
    -0
      app/src/main/res/menu/action_messages.xml

+ 6
- 1
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -74,6 +74,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.paging.PagedList; import androidx.paging.PagedList;
@ -303,8 +304,10 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
intent.setAction(null); intent.setAction(null);
setIntent(intent); setIntent(intent);
ViewModelMessages model = ViewModelProviders.of(this).get(ViewModelMessages.class);
model.setMessages(null);
intent.putExtra("thread", action.split(":", 2)[1]); intent.putExtra("thread", action.split(":", 2)[1]);
getSupportFragmentManager().popBackStack("unified", 0);
onViewThread(intent); onViewThread(intent);
} }
} }
@ -767,6 +770,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
} }
private void onViewThread(Intent intent) { private void onViewThread(Intent intent) {
getSupportFragmentManager().popBackStack("thread", FragmentManager.POP_BACK_STACK_INCLUSIVE);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account", intent.getLongExtra("account", -1)); args.putLong("account", intent.getLongExtra("account", -1));
args.putString("thread", intent.getStringExtra("thread")); args.putString("thread", intent.getStringExtra("thread"));


+ 34
- 14
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -39,6 +39,7 @@ import android.widget.ImageButton;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -56,6 +57,7 @@ import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.paging.LivePagedListBuilder; import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList; import androidx.paging.PagedList;
@ -70,6 +72,7 @@ public class FragmentMessages extends FragmentEx {
private ImageButton ibHintActions; private ImageButton ibHintActions;
private RecyclerView rvMessage; private RecyclerView rvMessage;
private TextView tvNoEmail; private TextView tvNoEmail;
private BottomNavigationView bottom_navigation;
private ProgressBar pbWait; private ProgressBar pbWait;
private Group grpSupport; private Group grpSupport;
private Group grpHintSupport; private Group grpHintSupport;
@ -139,6 +142,7 @@ public class FragmentMessages extends FragmentEx {
ibHintActions = view.findViewById(R.id.ibHintActions); ibHintActions = view.findViewById(R.id.ibHintActions);
rvMessage = view.findViewById(R.id.rvFolder); rvMessage = view.findViewById(R.id.rvFolder);
tvNoEmail = view.findViewById(R.id.tvNoEmail); tvNoEmail = view.findViewById(R.id.tvNoEmail);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
grpSupport = view.findViewById(R.id.grpSupport); grpSupport = view.findViewById(R.id.grpSupport);
grpHintSupport = view.findViewById(R.id.grpHintSupport); grpHintSupport = view.findViewById(R.id.grpHintSupport);
@ -457,6 +461,20 @@ public class FragmentMessages extends FragmentEx {
} }
}).attachToRecyclerView(rvMessage); }).attachToRecyclerView(rvMessage);
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
String[] pn = (String[]) bottom_navigation.getTag();
String thread = (menuItem.getItemId() == R.id.action_prev ? pn[0] : pn[1]);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", account)
.putExtra("thread", thread));
return true;
}
});
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -467,19 +485,9 @@ public class FragmentMessages extends FragmentEx {
} }
}); });
View.OnClickListener navigate = new View.OnClickListener() {
@Override
public void onClick(View v) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", account)
.putExtra("thread", (String) v.getTag()));
}
};
// Initialize // Initialize
tvNoEmail.setVisibility(View.GONE); tvNoEmail.setVisibility(View.GONE);
bottom_navigation.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
@ -576,8 +584,16 @@ public class FragmentMessages extends FragmentEx {
// Messages // Messages
loadMessages(); loadMessages();
// Compose FAB
if (viewType != AdapterMessage.ViewType.THREAD) {
if (viewType == AdapterMessage.ViewType.THREAD) {
// Navigation
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
String[] pn = model.getPrevNext(thread);
bottom_navigation.setTag(pn);
bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(pn[0] != null);
bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(pn[1] != null);
bottom_navigation.setVisibility(pn[0] == null && pn[1] == null ? View.GONE : View.VISIBLE);
} else {
// Compose FAB
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account", account); args.putLong("account", account);
@ -832,7 +848,7 @@ public class FragmentMessages extends FragmentEx {
return; return;
} }
if (viewType == AdapterMessage.ViewType.THREAD)
if (viewType == AdapterMessage.ViewType.THREAD) {
if (autoExpand) { if (autoExpand) {
autoExpand = false; autoExpand = false;
@ -886,6 +902,10 @@ public class FragmentMessages extends FragmentEx {
finish(); finish();
} }
} }
} else {
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
model.setMessages(messages);
}
Log.i(Helper.TAG, "Submit messages=" + messages.size()); Log.i(Helper.TAG, "Submit messages=" + messages.size());
adapter.submitList(messages); adapter.submitList(messages);


+ 36
- 0
app/src/main/java/eu/faircode/email/ViewModelMessages.java View File

@ -0,0 +1,36 @@
package eu.faircode.email;
import androidx.lifecycle.ViewModel;
import androidx.paging.PagedList;
public class ViewModelMessages extends ViewModel {
private PagedList<TupleMessageEx> messages = null;
void setMessages(PagedList<TupleMessageEx> messages) {
this.messages = messages;
}
String[] getPrevNext(String thread) {
if (messages == null)
return new String[]{null, null};
boolean found = false;
TupleMessageEx prev = null;
TupleMessageEx next = null;
for (int i = 0; i < messages.size(); i++) {
TupleMessageEx item = messages.get(i);
if (item == null)
continue;
if (found) {
next = item;
messages.loadAround(i);
break;
}
if (thread.equals(item.thread))
found = true;
else
prev = item;
}
return new String[]{prev == null ? null : prev.thread, next == null ? null : next.thread};
}
}

+ 10
- 0
app/src/main/res/drawable/baseline_navigate_before_24.xml View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
</vector>

+ 10
- 0
app/src/main/res/drawable/baseline_navigate_next_24.xml View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
</vector>

+ 14
- 1
app/src/main/res/layout/fragment_messages.xml View File

@ -110,7 +110,7 @@
android:layout_height="0dp" android:layout_height="0dp"
android:scrollbarStyle="outsideOverlay" android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintActions" /> app:layout_constraintTop_toBottomOf="@id/vSeparatorHintActions" />
@ -126,6 +126,19 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:itemIconTint="@color/bottomnav_background"
app:itemTextColor="@color/bottomnav_background"
app:labelVisibilityMode="unlabeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/action_messages" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpSupport" android:id="@+id/grpSupport"
android:layout_width="0dp" android:layout_width="0dp"


+ 13
- 0
app/src/main/res/menu/action_messages.xml View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_prev"
android:icon="@drawable/baseline_navigate_before_24"
android:title="" />
<item
android:id="@+id/action_next"
android:icon="@drawable/baseline_navigate_next_24"
android:title="" />
</menu>

Loading…
Cancel
Save