Skip to content

Commit

Permalink
Close Issue #13. Completed download, parse and view original message.
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed May 4, 2017
1 parent 64b7bcf commit c7a432e
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import android.widget.TextView;

import com.flowcrypt.email.BuildConfig;
import com.flowcrypt.email.R;
import com.flowcrypt.email.api.email.model.GeneralMessageDetails;
import com.flowcrypt.email.api.email.model.MessageInfo;
import com.flowcrypt.email.ui.activity.fragment.base.BaseGmailFragment;
import com.flowcrypt.email.ui.loader.LoadMessageInfoAsyncTaskLoader;
import com.flowcrypt.email.util.UIUtil;

/**
* This fragment describe details of some message.
Expand All @@ -30,6 +32,14 @@ public class MessageDetailsFragment extends BaseGmailFragment implements LoaderM
".KEY_GENERAL_MESSAGE_DETAILS";

private GeneralMessageDetails generalMessageDetails;
private TextView textViewSenderAddress;
private TextView textViewDate;
private TextView textViewSubject;
private TextView textViewMessage;
private View layoutContent;
private View progressBar;

private java.text.DateFormat dateFormat;

public MessageDetailsFragment() {
}
Expand All @@ -47,6 +57,8 @@ public static MessageDetailsFragment newInstance(GeneralMessageDetails generalMe
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

dateFormat = DateFormat.getTimeFormat(getContext());

Bundle args = getArguments();

if (args != null) {
Expand All @@ -60,6 +72,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return inflater.inflate(R.layout.fragment_message_details, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initViews(view);
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Expand All @@ -70,6 +88,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
public Loader<MessageInfo> onCreateLoader(int id, Bundle args) {
switch (id) {
case R.id.loader_id_load_message_info:
showProgress();
return new LoadMessageInfoAsyncTaskLoader(getContext(), getAccount(),
generalMessageDetails);

Expand All @@ -82,8 +101,19 @@ public Loader<MessageInfo> onCreateLoader(int id, Bundle args) {
public void onLoadFinished(Loader<MessageInfo> loader, MessageInfo messageInfo) {
switch (loader.getId()) {
case R.id.loader_id_load_message_info:
Toast.makeText(getContext(), "" + messageInfo, Toast.LENGTH_SHORT).show();
System.out.println(messageInfo);
if (messageInfo != null) {
updateViews(messageInfo);
showContent();
} else {
UIUtil.showSnackbar(getView(),
getString(R.string.something_wrong_with_receiving_message),
getString(R.string.refresh), new View.OnClickListener() {
@Override
public void onClick(View v) {
reloadMessageInfo();
}
});
}
break;
}
}
Expand All @@ -102,6 +132,57 @@ public void setGeneralMessageDetails(GeneralMessageDetails generalMessageDetails
this.generalMessageDetails = generalMessageDetails;
}

/**
* Make visible the main content. Hide the progress bar.
*/
private void showContent() {
if (layoutContent != null) {
layoutContent.setVisibility(View.VISIBLE);
}

if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}

/**
* Make visible the progress bar. Hide the main content.
*/
private void showProgress() {
if (layoutContent != null) {
layoutContent.setVisibility(View.GONE);
}

if (progressBar != null) {
progressBar.setVisibility(View.VISIBLE);
}
}

private void initViews(View view) {
textViewSenderAddress = (TextView) view.findViewById(R.id.textViewSenderAddress);
textViewDate = (TextView) view.findViewById(R.id.textViewDate);
textViewSubject = (TextView) view.findViewById(R.id.textViewSubject);
textViewMessage = (TextView) view.findViewById(R.id.textViewMessage);

layoutContent = view.findViewById(R.id.layoutContent);
progressBar = view.findViewById(R.id.progressBar);
}

private void updateViews(MessageInfo messageInfo) {
if (messageInfo != null) {
textViewSenderAddress.setText(messageInfo.getFrom().get(0));
textViewSubject.setText(messageInfo.getSubject());
textViewMessage.setText(messageInfo.getMessage());

if (messageInfo.getReceiveDate() != null) {
textViewDate.setText(dateFormat.format(messageInfo.getReceiveDate()));
}
}
}

/**
* Load an information about current general message details.
*/
private void reloadMessageInfo() {
if (generalMessageDetails != null && getAccount() != null) {
getLoaderManager().initLoader(R.id.loader_id_load_message_info, null, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public Account getAccount() {
* @param account A new current account.
*/
public void updateAccount(Account account) {
boolean isNeedCallAccountUpdate = !account.equals(this.account);
boolean isNeedCallAccountUpdate;

isNeedCallAccountUpdate = !(this.account == null && account == null) && (this.account ==
null || account == null || !account.name.equalsIgnoreCase(this.account.name));

this.account = account;
if (isNeedCallAccountUpdate) {
onAccountUpdated();
Expand Down
153 changes: 149 additions & 4 deletions FlowCrypt/src/main/res/layout/fragment_message_details.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.flowcrypt.email.ui.activity.fragment.MessageDetailsFragment"
tools:showIn="@layout/activity_message_details">
android:orientation="vertical">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.constraint.ConstraintLayout
android:id="@+id/layoutContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:context="com.flowcrypt.email.ui.activity.fragment.MessageDetailsFragment"
tools:visibility="visible">

<TextView
android:id="@+id/textViewSenderAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/mine_shaft"
android:textSize="@dimen/default_text_size_big"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guidelineLeft"
app:layout_constraintRight_toLeftOf="@+id/textViewDate"
app:layout_constraintTop_toTopOf="@+id/guidelineTop"
tools:text="tom@cryptup.org" />

<ImageButton
android:id="@+id/imageViewReplyAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/reply_all"
app:layout_constraintRight_toLeftOf="@+id/guidelineRight"
app:layout_constraintTop_toTopOf="@+id/guidelineTop"
app:srcCompat="@mipmap/ic_action_name" />

<TextView
android:id="@+id/textViewSubject"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/default_margin_medium"
android:layout_marginTop="@dimen/margin_top_message_subject"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/mine_shaft"
android:textSize="@dimen/default_text_size_medium"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guidelineLeft"
app:layout_constraintRight_toLeftOf="@+id/textViewDate"
app:layout_constraintTop_toBottomOf="@+id/textViewSenderAddress"
tools:text="What up man? How are you doing? Tell me please" />

<TextView
android:id="@+id/textViewDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/mine_shaft"
android:textSize="@dimen/default_text_size_medium"
app:layout_constraintRight_toLeftOf="@+id/guidelineRight"
app:layout_constraintTop_toTopOf="@+id/textViewSubject"
tools:text="1:05 PM" />

<LinearLayout
android:id="@+id/layoutFooterOfHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_medium"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewSubject">

<View
android:layout_width="@dimen/default_margin_medium"
android:layout_height="@dimen/height_silver_line"
android:layout_gravity="center"
android:background="@color/silver" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/default_margin_medium"
android:layout_marginRight="@dimen/default_margin_medium"
android:contentDescription="@string/lock"
android:src="@mipmap/ic_lock" />

<View
android:layout_width="0dp"
android:layout_height="@dimen/height_silver_line"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@color/silver" />

</LinearLayout>

<TextView
android:id="@+id/textViewMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_content"
android:textColor="@color/mine_shaft"
android:textSize="@dimen/default_text_size_medium"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guidelineLeft"
app:layout_constraintRight_toLeftOf="@+id/guidelineRight"
app:layout_constraintTop_toBottomOf="@+id/layoutFooterOfHeader"
tools:text="This email contains a key backup. It will help you access your encrypted messages from other computers (along with your pass phrase). You can safely leave it in your inbox or archive it.
The key below is protected with pass phrase that only you know. You should make sure to note your pass phrase down.
DO NOT DELETE THIS EMAIL. Write me at tom@cryptup.org so that I can help. I respond very promptly." />

<android.support.constraint.Guideline
android:id="@+id/guidelineLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/default_margin_content" />

<android.support.constraint.Guideline
android:id="@+id/guidelineTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="@dimen/margin_top_bottom_message" />

<android.support.constraint.Guideline
android:id="@+id/guidelineRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="@dimen/default_margin_content" />

</android.support.constraint.ConstraintLayout>
</ScrollView>


<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />

</FrameLayout>

</android.support.constraint.ConstraintLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FlowCrypt/src/main/res/mipmap-hdpi/ic_lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FlowCrypt/src/main/res/mipmap-mdpi/ic_lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FlowCrypt/src/main/res/mipmap-xhdpi/ic_lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FlowCrypt/src/main/res/mipmap-xxhdpi/ic_lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FlowCrypt/src/main/res/mipmap-xxxhdpi/ic_lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions FlowCrypt/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
<color name="de_york">#81C784</color>
<color name="scorpion">#5b5b5b</color>
<color name="gray">#898989</color>
<color name="mine_shaft">#333333</color>
<color name="silver">#C6C6C6</color>
</resources>
1 change: 1 addition & 0 deletions FlowCrypt/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<dimen name="margin_top_load_account">32dp</dimen>
<dimen name="margin_top_loading_account">32dp</dimen>
<dimen name="margin_top_button_select_another_account">24dp</dimen>
<dimen name="height_silver_line">1dp</dimen>
</resources>
3 changes: 3 additions & 0 deletions FlowCrypt/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@
<string name="passphrase_must_be_non_empty">Passphrase must be non empty!</string>
<string name="password_is_incorrect">Password is incorrect, try again!</string>
<string name="select_another_account">Select another Account</string>
<string name="reply_all">Reply all</string>
<string name="lock">Lock</string>
<string name="something_wrong_with_receiving_message">Something wrong with receiving a message!</string>
</resources>

0 comments on commit c7a432e

Please sign in to comment.