Skip to content

Commit

Permalink
show message info
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jun 2, 2021
1 parent bffd061 commit 9858b28
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Iterator;
import java.util.List;

import androidx.appcompat.app.AlertDialog;

import static com.zoffcc.applications.trifa.TrifaToxService.orma;

public class HelperMessage
Expand Down Expand Up @@ -701,6 +703,99 @@ public int compare(Long o1, Long o2)
}
}

static void show_select_message_info(Context c)
{
try
{
if (!MainActivity.selected_messages_text_only.isEmpty())
{
// sort ascending (lowest ID on top)
Collections.sort(MainActivity.selected_messages_text_only, new Comparator<Long>()
{
public int compare(Long o1, Long o2)
{
return o1.compareTo(o2);
}
});
StringBuilder copy_text = new StringBuilder();
boolean first = true;
Iterator i = MainActivity.selected_messages_text_only.iterator();

if (i.hasNext())
{
try
{
final Message m = orma.selectFromMessage().idEq((Long) i.next()).get(0);

// @formatter:off
final AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.
setMessage(
"id:"+m.id+"\n"+
"message_id:"+m.message_id+"\n"+
"direction:"+m.direction+"\n"+
"state:"+m.state+"\n"+
"read:"+m.read+"\n"+
"msg_version:"+m.msg_version+"\n"+
"msg_at_relay:"+m.msg_at_relay+"\n"+
"resend_count:"+m.resend_count+"\n"+
"send_retries:"+m.send_retries+"\n"+
"is_new:"+m.is_new+"\n"+
"msg_id_hash:"+m.msg_id_hash+"\n"+
"sent_timestamp:"+m.sent_timestamp+"\n"+
"sent_timestamp_ms:"+m.sent_timestamp_ms+"\n"+
"rcvd_timestamp:"+m.rcvd_timestamp+"\n"+
"rcvd_timestamp_ms:"+m.rcvd_timestamp_ms+"\n"+
"TOX_MESSAGE_TYPE:"+m.TOX_MESSAGE_TYPE+"\n"
).
setTitle("Message Info").
setCancelable(false).
setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.dismiss();
}
}).
setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.dismiss();
}
});

final AlertDialog alert = builder.create();
alert.show();
// @formatter:on
}
catch (Exception e)
{
e.printStackTrace();
}
}

MainActivity.selected_messages.clear();
MainActivity.selected_messages_incoming_file.clear();
MainActivity.selected_messages_text_only.clear();

try
{
// need to redraw all items again here, to remove the selections
MainActivity.message_list_fragment.adapter.redraw_all_items();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
catch (Exception e2)
{
e2.printStackTrace();
}
}

static void save_selected_messages(Context c)
{
ProgressDialog progressDialog2 = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public class MessageListActivity extends AppCompatActivity
static boolean attachemnt_instead_of_send = true;
static ActionMode amode = null;
static MenuItem amode_save_menu_item = null;
static MenuItem amode_info_menu_item = null;
static boolean oncreate_finished = false;
CustomSpinner spinner_filter_msgs = null;
SearchView messageSearchView = null;
Expand All @@ -165,6 +166,7 @@ protected void onCreate(Bundle savedInstanceState)

amode = null;
amode_save_menu_item = null;
amode_info_menu_item = null;
selected_messages.clear();
selected_messages_text_only.clear();
selected_messages_incoming_file.clear();
Expand Down Expand Up @@ -1802,6 +1804,15 @@ static boolean onClick_message_helper(final View v, boolean is_selected, final M
amode_save_menu_item.setVisible(false);
}

if ((selected_messages.size() == 1) && (selected_messages_text_only.size() == 1))
{
amode_info_menu_item.setVisible(true);
}
else
{
amode_info_menu_item.setVisible(false);
}

if (selected_messages.isEmpty())
{
// last item was de-selected
Expand Down Expand Up @@ -1843,6 +1854,15 @@ else if (message_.TRIFA_MESSAGE_TYPE == TRIFA_MSG_FILE.value)
amode_save_menu_item.setVisible(false);
}

if ((selected_messages.size() == 1) && (selected_messages_text_only.size() == 1))
{
amode_info_menu_item.setVisible(true);
}
else
{
amode_info_menu_item.setVisible(false);
}

if (amode != null)
{
amode.setTitle("" + selected_messages.size() + " selected");
Expand Down Expand Up @@ -1881,6 +1901,7 @@ static long_click_message_return onLongClick_message_helper(Context context, fin
{
amode = message_list_activity.startSupportActionMode(new ToolbarActionMode(context));
amode_save_menu_item = amode.getMenu().findItem(R.id.action_save);
amode_info_menu_item = amode.getMenu().findItem(R.id.action_info);
v.setBackgroundColor(Color.GRAY);
ret.is_selected = true;
selected_messages.add(message_.id);
Expand All @@ -1905,6 +1926,15 @@ else if (message_.TRIFA_MESSAGE_TYPE == TRIFA_MSG_FILE.value)
amode_save_menu_item.setVisible(false);
}

if ((selected_messages.size() == 1) && (selected_messages_text_only.size() == 1))
{
amode_info_menu_item.setVisible(true);
}
else
{
amode_info_menu_item.setVisible(false);
}

if (amode != null)
{
amode.setTitle("" + selected_messages.size() + " selected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@

package com.zoffcc.applications.trifa;


import android.content.Context;
import android.os.Build;
import androidx.core.view.MenuItemCompat;
import androidx.appcompat.view.ActionMode;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import androidx.appcompat.view.ActionMode;
import androidx.core.view.MenuItemCompat;

import static com.zoffcc.applications.trifa.HelperConference.copy_selected_conference_messages;
import static com.zoffcc.applications.trifa.HelperConference.delete_selected_conference_messages;
import static com.zoffcc.applications.trifa.HelperMessage.copy_selected_messages;
import static com.zoffcc.applications.trifa.HelperMessage.delete_selected_messages;
import static com.zoffcc.applications.trifa.HelperMessage.save_selected_messages;
import static com.zoffcc.applications.trifa.HelperMessage.show_select_message_info;
import static com.zoffcc.applications.trifa.MainActivity.selected_conference_messages;
import static com.zoffcc.applications.trifa.MainActivity.selected_messages;
import static com.zoffcc.applications.trifa.MainActivity.selected_messages_incoming_file;
import static com.zoffcc.applications.trifa.MainActivity.selected_messages_text_only;
import static com.zoffcc.applications.trifa.MessageListActivity.amode;
import static com.zoffcc.applications.trifa.MessageListActivity.amode_info_menu_item;
import static com.zoffcc.applications.trifa.MessageListActivity.amode_save_menu_item;

public class ToolbarActionMode implements ActionMode.Callback
Expand Down Expand Up @@ -66,7 +68,7 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu)
{
// Log.i(TAG, "onPrepareActionMode");

//Sometimes the meu will not be visible so for that we need to set their visibility manually in this method
//Sometimes the menu will not be visible so for that we need to set their visibility manually in this method
//So here show action menu according to SDK Levels
if (Build.VERSION.SDK_INT < 11)
{
Expand Down Expand Up @@ -127,6 +129,12 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item)
save_selected_messages(context);
mode.finish(); // Finish action mode
break;

case R.id.action_info:
action_active = true;
show_select_message_info(context);
mode.finish(); // Finish action mode
break;
}
return false;
}
Expand Down Expand Up @@ -175,6 +183,7 @@ public void onDestroyActionMode(ActionMode mode)
{
amode = null;
amode_save_menu_item = null;
amode_info_menu_item = null;
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
android:icon="@drawable/ic_delete_white_24dp"
android:title="@string/layout___delete"
app:showAsAction="always"/>
<item
android:id="@+id/action_info"
android:icon="@drawable/ic_info_white_24dp"
android:title="@string/layout___info"
android:visible="false"
app:showAsAction="ifRoom"/>
</menu>

0 comments on commit 9858b28

Please sign in to comment.