Added optional message text preview

This commit is contained in:
M66B
2018-11-04 12:42:41 +00:00
parent 6464bb4f23
commit 74c85fab07
8 changed files with 127 additions and 29 deletions

View File

@@ -82,7 +82,11 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
if (this.getClass().equals(ActivitySetup.class))
startActivity(getIntent());
} else if (!this.getClass().equals(ActivitySetup.class) &&
("avatars".equals(key) || "identicons".equals(key) || "compact".equals(key) || "debug".equals(key)))
("compact".equals(key) ||
"avatars".equals(key) ||
"identicons".equals(key) ||
"preview".equals(key) ||
"debug".equals(key)))
finish();
}

View File

@@ -66,6 +66,7 @@ import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.snackbar.Snackbar;
import org.jsoup.Jsoup;
import org.xml.sax.XMLReader;
import java.io.File;
@@ -111,10 +112,11 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private ViewType viewType;
private IProperties properties;
private boolean compact;
private boolean contacts;
private boolean avatars;
private boolean identicons;
private boolean compact;
private boolean preview;
private boolean debug;
private int dp24;
@@ -142,6 +144,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private TextView tvTimeEx;
private ImageView ivAttachments;
private TextView tvSubject;
private TextView tvPreview;
private TextView tvFolder;
private TextView tvCount;
private ImageView ivThread;
@@ -190,6 +193,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
tvTimeEx = itemView.findViewById(R.id.tvTimeEx);
ivAttachments = itemView.findViewById(R.id.ivAttachments);
tvSubject = itemView.findViewById(R.id.tvSubject);
tvPreview = itemView.findViewById(R.id.tvPreview);
tvFolder = itemView.findViewById(R.id.tvFolder);
tvCount = itemView.findViewById(R.id.tvCount);
ivThread = itemView.findViewById(R.id.ivThread);
@@ -257,6 +261,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
tvTime.setText(null);
ivAttachments.setVisibility(View.GONE);
tvSubject.setText(null);
if (tvPreview != null)
tvPreview.setText(null);
tvFolder.setText(null);
tvCount.setText(null);
ivThread.setVisibility(View.GONE);
@@ -328,6 +334,39 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivAttachments.setVisibility(message.attachments > 0 ? View.VISIBLE : View.GONE);
tvSubject.setText(message.subject);
tvPreview.setText(null);
tvPreview.setVisibility(preview && message.content ? View.VISIBLE : View.GONE);
if (message.content) {
Bundle args = new Bundle();
args.putSerializable("message", message);
new SimpleTask<String>() {
@Override
protected void onInit(Bundle args) {
tvPreview.setHasTransientState(true);
}
@Override
protected String onLoad(Context context, Bundle args) throws Throwable {
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
String body = message.read(context);
return Jsoup.parse(body).text();
}
@Override
protected void onLoaded(Bundle args, String preview) {
tvPreview.setText(preview);
tvPreview.setHasTransientState(false);
}
@Override
protected void onException(Bundle args, Throwable ex) {
tvPreview.setHasTransientState(false);
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
}
if (viewType == ViewType.UNIFIED)
tvFolder.setText(message.accountName);
else {
@@ -1405,11 +1444,12 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.compact = prefs.getBoolean("compact", false);
this.contacts = (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED);
this.avatars = (prefs.getBoolean("avatars", true) && this.contacts);
this.identicons = prefs.getBoolean("identicons", false);
this.compact = prefs.getBoolean("compact", false);
this.preview = prefs.getBoolean("preview", false);
this.debug = prefs.getBoolean("debug", false);
this.dp24 = Math.round(24 * Resources.getSystem().getDisplayMetrics().density);

View File

@@ -35,10 +35,11 @@ public class FragmentOptions extends FragmentEx {
private SwitchCompat swEnabled;
private SwitchCompat swAvatars;
private SwitchCompat swIdenticons;
private SwitchCompat swCompact;
private SwitchCompat swPreview;
private SwitchCompat swLight;
private SwitchCompat swBrowse;
private SwitchCompat swSwipe;
private SwitchCompat swCompact;
private SwitchCompat swNav;
private SwitchCompat swInsecure;
private SwitchCompat swDebug;
@@ -52,12 +53,13 @@ public class FragmentOptions extends FragmentEx {
// Get controls
swEnabled = view.findViewById(R.id.swEnabled);
swCompact = view.findViewById(R.id.swCompact);
swAvatars = view.findViewById(R.id.swAvatars);
swIdenticons = view.findViewById(R.id.swIdenticons);
swPreview = view.findViewById(R.id.swPreview);
swLight = view.findViewById(R.id.swLight);
swBrowse = view.findViewById(R.id.swBrowse);
swSwipe = view.findViewById(R.id.swSwipe);
swCompact = view.findViewById(R.id.swCompact);
swNav = view.findViewById(R.id.swNav);
swInsecure = view.findViewById(R.id.swInsecure);
swDebug = view.findViewById(R.id.swDebug);
@@ -78,6 +80,14 @@ public class FragmentOptions extends FragmentEx {
}
});
swCompact.setChecked(prefs.getBoolean("compact", false));
swCompact.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("compact", checked).apply();
}
});
swAvatars.setChecked(prefs.getBoolean("avatars", true));
swAvatars.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
@@ -94,6 +104,14 @@ public class FragmentOptions extends FragmentEx {
}
});
swPreview.setChecked(prefs.getBoolean("preview", false));
swPreview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("preview", checked).apply();
}
});
swLight.setChecked(prefs.getBoolean("light", false));
swLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
@@ -118,14 +136,6 @@ public class FragmentOptions extends FragmentEx {
}
});
swCompact.setChecked(prefs.getBoolean("compact", false));
swCompact.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("compact", checked).apply();
}
});
swNav.setChecked(prefs.getBoolean("navigation", true));
swNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

View File

@@ -106,12 +106,13 @@ public class FragmentSetup extends FragmentEx {
static final List<String> EXPORT_SETTINGS = Arrays.asList(
"enabled",
"compact",
"avatars",
"identicons",
"preview",
"light",
"browse",
"swipe",
"compat",
"navigation",
"insecure",
"sort"