make archive menu item work

This commit is contained in:
Daniel Gultsch 2018-02-24 12:53:02 +01:00
parent 5e28a8f8d5
commit 4c8cbfe966
4 changed files with 52 additions and 12 deletions

View File

@ -204,6 +204,15 @@ public class ConversationActivity extends XmppActivity implements OnConversation
return super.onOptionsItemSelected(item);
}
@Override
protected void onStart() {
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
super.onStart();
}
@Override
protected void onNewIntent(final Intent intent) {
if (isViewIntent(intent)) {
@ -224,10 +233,6 @@ public class ConversationActivity extends XmppActivity implements OnConversation
@Override
public void onResume() {
super.onResume();
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
this.mActivityPaused = false;
}
@ -291,7 +296,22 @@ public class ConversationActivity extends XmppActivity implements OnConversation
@Override
public void onConversationArchived(Conversation conversation) {
//TODO; check if nothing more left;
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
if (mainFragment != null && mainFragment instanceof ConversationFragment) {
getFragmentManager().popBackStack();
return;
}
Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
if (suggestion != null) {
openConversation(suggestion, null);
return;
}
}
}
}
@Override

View File

@ -149,6 +149,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
@Override
public void onClick(View v) {
activity.xmppConnectionService.archiveConversation(conversation);
activity.onConversationArchived(conversation);
}
};
@ -1032,6 +1033,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
handleAttachmentSelection(item);
break;
case R.id.action_archive:
activity.xmppConnectionService.archiveConversation(conversation);
activity.onConversationArchived(conversation);
break;
case R.id.action_contact_details:
@ -1239,6 +1241,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
builder.setPositiveButton(getString(R.string.delete_messages), (dialog, which) -> {
this.activity.xmppConnectionService.clearConversationHistory(conversation);
if (endConversationCheckBox.isChecked()) {
this.activity.xmppConnectionService.archiveConversation(conversation);
this.activity.onConversationArchived(conversation);
} else {
activity.onConversationsListItemUpdated();
@ -1353,7 +1356,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
@Override
public void onResume() {
new Handler().post(() -> {
final PackageManager packageManager = getActivity().getPackageManager();
final Activity activity = getActivity();
if (activity == null) {
return;
}
final PackageManager packageManager = activity.getPackageManager();
ConversationMenuConfigurator.updateAttachmentAvailability(packageManager);
getActivity().invalidateOptionsMenu();
});

View File

@ -60,11 +60,29 @@ public class ConversationsOverviewFragment extends XmppFragment implements Enhan
private XmppActivity activity;
public static Conversation getSuggestion(Activity activity) {
final Conversation exception;
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
exception = ((ConversationsOverviewFragment) fragment).swipedConversation.peek();
} else {
exception = null;
}
return getSuggestion(activity, exception);
}
public static Conversation getSuggestion(Activity activity, Conversation exception) {
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
List<Conversation> conversations = ((ConversationsOverviewFragment) fragment).conversations;
if (conversations.size() > 0) {
return conversations.get(0);
Conversation suggestion = conversations.get(0);
if (suggestion == exception) {
if (conversations.size() > 1) {
return conversations.get(1);
}
} else {
return suggestion;
}
}
}
return null;
@ -74,7 +92,6 @@ public class ConversationsOverviewFragment extends XmppFragment implements Enhan
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Log.d(Config.LOGTAG, "on attach");
if (activity instanceof XmppActivity) {
this.activity = (XmppActivity) activity;
} else {

View File

@ -173,10 +173,6 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
@Override
public void notifyDataSetChanged() {
this.selectedConversation = ConversationFragment.getConversation(activity);
Log.d(Config.LOGTAG,"notify data set changed");
if (this.selectedConversation == null) {
Log.d(Config.LOGTAG,"selected conversation is null");
}
super.notifyDataSetChanged();
}