mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-01 06:38:29 +02:00
Refactoring
This commit is contained in:
@@ -64,6 +64,8 @@ import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -715,10 +717,69 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
View getContentView() {
|
||||
if (drawerLayout == null || drawerLayout.getChildCount() == 0)
|
||||
return null;
|
||||
return drawerLayout.getChildAt(0);
|
||||
public void undo(String title, final Bundle args, final SimpleTask<Void> move, final SimpleTask<Void> show) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
int undo_timeout = prefs.getInt("undo_timeout", 5000);
|
||||
|
||||
if (undo_timeout == 0) {
|
||||
move.execute(this, args, "undo:move");
|
||||
return;
|
||||
}
|
||||
|
||||
if (drawerLayout == null || drawerLayout.getChildCount() == 0) {
|
||||
Log.e("Undo: drawer missing");
|
||||
return;
|
||||
}
|
||||
|
||||
final View content = drawerLayout.getChildAt(0);
|
||||
|
||||
final Snackbar snackbar = Snackbar.make(content, title, Snackbar.LENGTH_INDEFINITE)
|
||||
.setGestureInsetBottomIgnored(true);
|
||||
snackbar.setAction(R.string.title_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
snackbar.dismiss();
|
||||
snackbar.getView().setTag(true);
|
||||
show.execute(ActivityView.this, args, "undo:show");
|
||||
}
|
||||
});
|
||||
|
||||
snackbar.addCallback(new Snackbar.Callback() {
|
||||
private int margin;
|
||||
|
||||
@Override
|
||||
public void onShown(Snackbar sb) {
|
||||
ViewGroup.MarginLayoutParams lparam = (ViewGroup.MarginLayoutParams) content.getLayoutParams();
|
||||
margin = lparam.bottomMargin;
|
||||
lparam.bottomMargin += snackbar.getView().getHeight();
|
||||
content.setLayoutParams(lparam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissed(Snackbar transientBottomBar, int event) {
|
||||
ViewGroup.MarginLayoutParams lparam = (ViewGroup.MarginLayoutParams) content.getLayoutParams();
|
||||
lparam.bottomMargin = margin;
|
||||
content.setLayoutParams(lparam);
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
|
||||
// Wait
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i("Move timeout");
|
||||
|
||||
if (snackbar.getView().getTag() != null)
|
||||
return;
|
||||
|
||||
// Remove snackbar
|
||||
if (snackbar.isShown())
|
||||
snackbar.dismiss();
|
||||
|
||||
move.execute(ActivityView.this, args, "undo:move");
|
||||
}
|
||||
}, undo_timeout);
|
||||
}
|
||||
|
||||
private void checkFirst() {
|
||||
|
||||
Reference in New Issue
Block a user