Added optional message text preview

pull/146/head
M66B 6 years ago
parent 6464bb4f23
commit 74c85fab07

@ -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();
}

@ -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);

@ -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

@ -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"

@ -20,6 +20,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCompact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_compact"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swEnabled" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAvatars"
android:layout_width="match_parent"
@ -27,7 +36,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_avatars"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swEnabled" />
app:layout_constraintTop_toBottomOf="@id/swCompact" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swIdenticons"
@ -38,6 +47,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAvatars" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPreview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_preview"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swIdenticons" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swLight"
android:layout_width="match_parent"
@ -45,7 +63,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_light"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swIdenticons" />
app:layout_constraintTop_toBottomOf="@id/swPreview" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swBrowse"
@ -65,15 +83,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swBrowse" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCompact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_compact"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSwipe" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNav"
android:layout_width="match_parent"
@ -81,7 +90,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_nav"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swCompact" />
app:layout_constraintTop_toBottomOf="@id/swSwipe" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swInsecure"

@ -165,6 +165,22 @@
app:layout_constraintEnd_toStartOf="@+id/paddingEnd"
app:layout_constraintTop_toTopOf="@id/tvSubject" />
<TextView
android:id="@+id/tvPreview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:ellipsize="end"
android:fontFamily="monospace"
android:maxLines="2"
android:text="Preview"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toStartOf="@+id/paddingEnd"
app:layout_constraintStart_toEndOf="@id/paddingStart"
app:layout_constraintTop_toBottomOf="@id/tvSubject" />
<TextView
android:id="@+id/tvError"
android:layout_width="0dp"
@ -177,7 +193,7 @@
android:textIsSelectable="true"
app:layout_constraintEnd_toStartOf="@+id/paddingEnd"
app:layout_constraintStart_toEndOf="@id/paddingStart"
app:layout_constraintTop_toBottomOf="@id/tvSubject" />
app:layout_constraintTop_toBottomOf="@id/tvPreview" />
<View
android:id="@+id/paddingEnd"

@ -162,6 +162,23 @@
app:layout_constraintEnd_toStartOf="@+id/paddingEnd"
app:layout_constraintTop_toTopOf="@id/tvSubject" />
<TextView
android:id="@+id/tvPreview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:ellipsize="end"
android:fontFamily="monospace"
android:maxLines="2"
android:text="Preview"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toStartOf="@+id/paddingEnd"
app:layout_constraintStart_toEndOf="@id/paddingStart"
app:layout_constraintTop_toBottomOf="@id/tvSubject" />
<TextView
android:id="@+id/tvError"
android:layout_width="0dp"
@ -175,7 +192,7 @@
android:textIsSelectable="true"
app:layout_constraintEnd_toStartOf="@+id/paddingEnd"
app:layout_constraintStart_toEndOf="@id/paddingStart"
app:layout_constraintTop_toBottomOf="@id/tvSubject" />
app:layout_constraintTop_toBottomOf="@id/tvPreview" />
<View
android:id="@+id/paddingEnd"

@ -82,12 +82,13 @@
<string name="title_advanced">Advanced options</string>
<string name="title_advanced_enabled">Enabled</string>
<string name="title_advanced_compact">Compact message view</string>
<string name="title_advanced_avatars">Show contact photos</string>
<string name="title_advanced_identicons">Show identicons</string>
<string name="title_advanced_preview">Show message preview</string>
<string name="title_advanced_light">Use notification light</string>
<string name="title_advanced_browse">Browse messages on the server</string>
<string name="title_advanced_swipe">Swipe actions</string>
<string name="title_advanced_compact">Compact message view</string>
<string name="title_advanced_nav">Previous/next navigation</string>
<string name="title_advanced_debug">Debug mode</string>

Loading…
Cancel
Save