Migrate Fragments to AndroidX
This commit is contained in:
parent
73000962fe
commit
231d97ea81
|
@ -3,8 +3,6 @@ package eu.siacs.conversations.ui;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.app.FragmentManager;
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -52,6 +50,8 @@ import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.view.inputmethod.InputConnectionCompat;
|
import androidx.core.view.inputmethod.InputConnectionCompat;
|
||||||
import androidx.core.view.inputmethod.InputContentInfoCompat;
|
import androidx.core.view.inputmethod.InputContentInfoCompat;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
|
||||||
|
@ -465,41 +465,41 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
private boolean firstWord = false;
|
private boolean firstWord = false;
|
||||||
private Message mPendingDownloadableMessage;
|
private Message mPendingDownloadableMessage;
|
||||||
|
|
||||||
private static ConversationFragment findConversationFragment(Activity activity) {
|
private static ConversationFragment findConversationFragment(FragmentManager fragmentManager) {
|
||||||
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
|
Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
if (fragment instanceof ConversationFragment) {
|
if (fragment instanceof ConversationFragment) {
|
||||||
return (ConversationFragment) fragment;
|
return (ConversationFragment) fragment;
|
||||||
}
|
}
|
||||||
fragment = activity.getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
fragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
||||||
if (fragment instanceof ConversationFragment) {
|
if (fragment instanceof ConversationFragment) {
|
||||||
return (ConversationFragment) fragment;
|
return (ConversationFragment) fragment;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startStopPending(Activity activity) {
|
public static void startStopPending(FragmentManager fragmentManager) {
|
||||||
ConversationFragment fragment = findConversationFragment(activity);
|
ConversationFragment fragment = findConversationFragment(fragmentManager);
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
fragment.messageListAdapter.startStopPending();
|
fragment.messageListAdapter.startStopPending();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void downloadFile(Activity activity, Message message) {
|
public static void downloadFile(FragmentManager fragmentManager, Message message) {
|
||||||
ConversationFragment fragment = findConversationFragment(activity);
|
ConversationFragment fragment = findConversationFragment(fragmentManager);
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
fragment.startDownloadable(message);
|
fragment.startDownloadable(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerPendingMessage(Activity activity, Message message) {
|
public static void registerPendingMessage(FragmentManager fragmentManager, Message message) {
|
||||||
ConversationFragment fragment = findConversationFragment(activity);
|
ConversationFragment fragment = findConversationFragment(fragmentManager);
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
fragment.pendingMessage.push(message);
|
fragment.pendingMessage.push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openPendingMessage(Activity activity) {
|
public static void openPendingMessage(FragmentManager fragmentManager) {
|
||||||
ConversationFragment fragment = findConversationFragment(activity);
|
ConversationFragment fragment = findConversationFragment(fragmentManager);
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
Message message = fragment.pendingMessage.pop();
|
Message message = fragment.pendingMessage.pop();
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
|
@ -508,12 +508,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Conversation getConversation(Activity activity) {
|
public static Conversation getConversation(FragmentManager fragmentManager) {
|
||||||
return getConversation(activity, R.id.secondary_fragment);
|
return getConversation(fragmentManager, R.id.secondary_fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Conversation getConversation(Activity activity, @IdRes int res) {
|
private static Conversation getConversation(FragmentManager fragmentManager, @IdRes int res) {
|
||||||
final Fragment fragment = activity.getFragmentManager().findFragmentById(res);
|
final Fragment fragment = fragmentManager.findFragmentById(res);
|
||||||
if (fragment instanceof ConversationFragment) {
|
if (fragment instanceof ConversationFragment) {
|
||||||
return ((ConversationFragment) fragment).getConversation();
|
return ((ConversationFragment) fragment).getConversation();
|
||||||
} else {
|
} else {
|
||||||
|
@ -521,8 +521,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConversationFragment get(Activity activity) {
|
public static ConversationFragment get(FragmentManager fragmentManager) {
|
||||||
FragmentManager fragmentManager = activity.getFragmentManager();
|
|
||||||
Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
if (fragment instanceof ConversationFragment) {
|
if (fragment instanceof ConversationFragment) {
|
||||||
return (ConversationFragment) fragment;
|
return (ConversationFragment) fragment;
|
||||||
|
@ -532,12 +531,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Conversation getConversationReliable(Activity activity) {
|
public static Conversation getConversationReliable(FragmentManager fragmentManager) {
|
||||||
final Conversation conversation = getConversation(activity, R.id.secondary_fragment);
|
final Conversation conversation = getConversation(fragmentManager, R.id.secondary_fragment);
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
return conversation;
|
return conversation;
|
||||||
}
|
}
|
||||||
return getConversation(activity, R.id.main_fragment);
|
return getConversation(fragmentManager, R.id.main_fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean scrolledToBottom(AbsListView listView) {
|
private static boolean scrolledToBottom(AbsListView listView) {
|
||||||
|
|
|
@ -34,9 +34,6 @@ import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.app.FragmentManager;
|
|
||||||
import android.app.FragmentTransaction;
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -55,6 +52,9 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
|
|
||||||
|
@ -165,8 +165,8 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidateActionBarTitle();
|
invalidateActionBarTitle();
|
||||||
if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
|
if (binding.secondaryFragment != null && ConversationFragment.getConversation(getSupportFragmentManager()) == null) {
|
||||||
Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
|
Conversation conversation = ConversationsOverviewFragment.getSuggestion(getSupportFragmentManager());
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
openConversation(conversation, null);
|
openConversation(conversation, null);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
if (xmppConnectionService == null) {
|
if (xmppConnectionService == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_fragment);
|
||||||
if (fragment instanceof ConversationsOverviewFragment) {
|
if (fragment instanceof ConversationsOverviewFragment) {
|
||||||
if (ExceptionHelper.checkForCrash(this)) {
|
if (ExceptionHelper.checkForCrash(this)) {
|
||||||
return;
|
return;
|
||||||
|
@ -255,14 +255,14 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyFragmentOfBackendConnected(@IdRes int id) {
|
private void notifyFragmentOfBackendConnected(@IdRes int id) {
|
||||||
final Fragment fragment = getFragmentManager().findFragmentById(id);
|
final Fragment fragment = getSupportFragmentManager().findFragmentById(id);
|
||||||
if (fragment instanceof OnBackendConnected) {
|
if (fragment instanceof OnBackendConnected) {
|
||||||
((OnBackendConnected) fragment).onBackendConnected();
|
((OnBackendConnected) fragment).onBackendConnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshFragment(@IdRes int id) {
|
private void refreshFragment(@IdRes int id) {
|
||||||
final Fragment fragment = getFragmentManager().findFragmentById(id);
|
final Fragment fragment = getSupportFragmentManager().findFragmentById(id);
|
||||||
if (fragment instanceof XmppFragment) {
|
if (fragment instanceof XmppFragment) {
|
||||||
((XmppFragment) fragment).refresh();
|
((XmppFragment) fragment).refresh();
|
||||||
}
|
}
|
||||||
|
@ -287,10 +287,10 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_OPEN_MESSAGE:
|
case REQUEST_OPEN_MESSAGE:
|
||||||
refreshUiReal();
|
refreshUiReal();
|
||||||
ConversationFragment.openPendingMessage(this);
|
ConversationFragment.openPendingMessage(getSupportFragmentManager());
|
||||||
break;
|
break;
|
||||||
case REQUEST_PLAY_PAUSE:
|
case REQUEST_PLAY_PAUSE:
|
||||||
ConversationFragment.startStopPending(this);
|
ConversationFragment.startStopPending(getSupportFragmentManager());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNegativeActivityResult(int requestCode) {
|
private void handleNegativeActivityResult(int requestCode) {
|
||||||
Conversation conversation = ConversationFragment.getConversationReliable(this);
|
Conversation conversation = ConversationFragment.getConversationReliable(getSupportFragmentManager());
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_DECRYPT_PGP:
|
case REQUEST_DECRYPT_PGP:
|
||||||
if (conversation == null) {
|
if (conversation == null) {
|
||||||
|
@ -332,7 +332,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePositiveActivityResult(int requestCode, final Intent data) {
|
private void handlePositiveActivityResult(int requestCode, final Intent data) {
|
||||||
Conversation conversation = ConversationFragment.getConversationReliable(this);
|
Conversation conversation = ConversationFragment.getConversationReliable(getSupportFragmentManager());
|
||||||
if (conversation == null) {
|
if (conversation == null) {
|
||||||
Log.d(Config.LOGTAG, "conversation not found");
|
Log.d(Config.LOGTAG, "conversation not found");
|
||||||
return;
|
return;
|
||||||
|
@ -364,8 +364,8 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
|
||||||
setSupportActionBar(binding.toolbar);
|
setSupportActionBar(binding.toolbar);
|
||||||
configureActionBar(getSupportActionBar());
|
configureActionBar(getSupportActionBar());
|
||||||
this.getFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
|
this.getSupportFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
|
||||||
this.getFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
|
this.getSupportFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
|
||||||
this.initializeFragments();
|
this.initializeFragments();
|
||||||
this.invalidateActionBarTitle();
|
this.invalidateActionBarTitle();
|
||||||
final Intent intent;
|
final Intent intent;
|
||||||
|
@ -386,7 +386,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
final MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
|
final MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
|
||||||
if (qrCodeScanMenuItem != null) {
|
if (qrCodeScanMenuItem != null) {
|
||||||
if (isCameraFeatureAvailable()) {
|
if (isCameraFeatureAvailable()) {
|
||||||
Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_fragment);
|
||||||
boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
|
boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
|
||||||
&& fragment instanceof ConversationsOverviewFragment;
|
&& fragment instanceof ConversationsOverviewFragment;
|
||||||
qrCodeScanMenuItem.setVisible(visible);
|
qrCodeScanMenuItem.setVisible(visible);
|
||||||
|
@ -400,7 +400,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
@Override
|
@Override
|
||||||
public void onConversationSelected(Conversation conversation) {
|
public void onConversationSelected(Conversation conversation) {
|
||||||
clearPendingViewIntent();
|
clearPendingViewIntent();
|
||||||
if (ConversationFragment.getConversation(this) == conversation) {
|
if (ConversationFragment.getConversation(getSupportFragmentManager()) == conversation) {
|
||||||
Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
|
Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -428,7 +428,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openConversation(Conversation conversation, Bundle extras) {
|
private void openConversation(Conversation conversation, Bundle extras) {
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
fragmentManager.executePendingTransactions();
|
fragmentManager.executePendingTransactions();
|
||||||
ConversationFragment conversationFragment = (ConversationFragment) fragmentManager.findFragmentById(R.id.secondary_fragment);
|
ConversationFragment conversationFragment = (ConversationFragment) fragmentManager.findFragmentById(R.id.secondary_fragment);
|
||||||
final boolean mainNeedsRefresh;
|
final boolean mainNeedsRefresh;
|
||||||
|
@ -480,7 +480,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
if (fm.getBackStackEntryCount() > 0) {
|
if (fm.getBackStackEntryCount() > 0) {
|
||||||
try {
|
try {
|
||||||
fm.popBackStack();
|
fm.popBackStack();
|
||||||
|
@ -497,7 +497,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
startActivity(new Intent(this, SearchActivity.class));
|
startActivity(new Intent(this, SearchActivity.class));
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_search_this_conversation:
|
case R.id.action_search_this_conversation:
|
||||||
final Conversation conversation = ConversationFragment.getConversation(this);
|
final Conversation conversation = ConversationFragment.getConversation(getSupportFragmentManager());
|
||||||
if (conversation == null) {
|
if (conversation == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -512,7 +512,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_DPAD_UP && keyEvent.isCtrlPressed()) {
|
if (keyCode == KeyEvent.KEYCODE_DPAD_UP && keyEvent.isCtrlPressed()) {
|
||||||
final ConversationFragment conversationFragment = ConversationFragment.get(this);
|
final ConversationFragment conversationFragment = ConversationFragment.get(getSupportFragmentManager());
|
||||||
if (conversationFragment != null && conversationFragment.onArrowUpCtrlPressed()) {
|
if (conversationFragment != null && conversationFragment.onArrowUpCtrlPressed()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -567,14 +567,14 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeFragments() {
|
private void initializeFragments() {
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
||||||
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
||||||
if (mainFragment != null) {
|
if (mainFragment != null) {
|
||||||
if (binding.secondaryFragment != null) {
|
if (binding.secondaryFragment != null) {
|
||||||
if (mainFragment instanceof ConversationFragment) {
|
if (mainFragment instanceof ConversationFragment) {
|
||||||
getFragmentManager().popBackStack();
|
getSupportFragmentManager().popBackStack();
|
||||||
transaction.remove(mainFragment);
|
transaction.remove(mainFragment);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
fragmentManager.executePendingTransactions();
|
fragmentManager.executePendingTransactions();
|
||||||
|
@ -588,7 +588,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
if (secondaryFragment instanceof ConversationFragment) {
|
if (secondaryFragment instanceof ConversationFragment) {
|
||||||
transaction.remove(secondaryFragment);
|
transaction.remove(secondaryFragment);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
getFragmentManager().executePendingTransactions();
|
getSupportFragmentManager().executePendingTransactions();
|
||||||
transaction = fragmentManager.beginTransaction();
|
transaction = fragmentManager.beginTransaction();
|
||||||
transaction.replace(R.id.main_fragment, secondaryFragment);
|
transaction.replace(R.id.main_fragment, secondaryFragment);
|
||||||
transaction.addToBackStack(null);
|
transaction.addToBackStack(null);
|
||||||
|
@ -610,7 +610,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
if (actionBar == null) {
|
if (actionBar == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
if (mainFragment instanceof ConversationFragment) {
|
if (mainFragment instanceof ConversationFragment) {
|
||||||
final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
|
final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
|
||||||
|
@ -647,7 +647,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
if (performRedirectIfNecessary(conversation, false)) {
|
if (performRedirectIfNecessary(conversation, false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
if (mainFragment instanceof ConversationFragment) {
|
if (mainFragment instanceof ConversationFragment) {
|
||||||
try {
|
try {
|
||||||
|
@ -661,7 +661,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
||||||
if (secondaryFragment instanceof ConversationFragment) {
|
if (secondaryFragment instanceof ConversationFragment) {
|
||||||
if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
|
if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
|
||||||
Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
|
Conversation suggestion = ConversationsOverviewFragment.getSuggestion(getSupportFragmentManager(), conversation);
|
||||||
if (suggestion != null) {
|
if (suggestion != null) {
|
||||||
openConversation(suggestion, null);
|
openConversation(suggestion, null);
|
||||||
}
|
}
|
||||||
|
@ -671,7 +671,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConversationsListItemUpdated() {
|
public void onConversationsListItemUpdated() {
|
||||||
Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_fragment);
|
||||||
if (fragment instanceof ConversationsOverviewFragment) {
|
if (fragment instanceof ConversationsOverviewFragment) {
|
||||||
((ConversationsOverviewFragment) fragment).refresh();
|
((ConversationsOverviewFragment) fragment).refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
@ -46,6 +45,8 @@ import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
@ -139,7 +140,7 @@ public class ConversationsOverviewFragment extends XmppFragment {
|
||||||
activity.xmppConnectionService.archiveConversation(c);
|
activity.xmppConnectionService.archiveConversation(c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final boolean formerlySelected = ConversationFragment.getConversation(getActivity()) == swipedConversation.peek();
|
final boolean formerlySelected = ConversationFragment.getConversation(requireActivity().getSupportFragmentManager()) == swipedConversation.peek();
|
||||||
if (activity instanceof OnConversationArchived) {
|
if (activity instanceof OnConversationArchived) {
|
||||||
((OnConversationArchived) activity).onConversationArchived(swipedConversation.peek());
|
((OnConversationArchived) activity).onConversationArchived(swipedConversation.peek());
|
||||||
}
|
}
|
||||||
|
@ -202,19 +203,19 @@ public class ConversationsOverviewFragment extends XmppFragment {
|
||||||
|
|
||||||
private ItemTouchHelper touchHelper;
|
private ItemTouchHelper touchHelper;
|
||||||
|
|
||||||
public static Conversation getSuggestion(Activity activity) {
|
public static Conversation getSuggestion(FragmentManager fragmentManager) {
|
||||||
final Conversation exception;
|
final Conversation exception;
|
||||||
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
|
Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
if (fragment instanceof ConversationsOverviewFragment) {
|
if (fragment instanceof ConversationsOverviewFragment) {
|
||||||
exception = ((ConversationsOverviewFragment) fragment).swipedConversation.peek();
|
exception = ((ConversationsOverviewFragment) fragment).swipedConversation.peek();
|
||||||
} else {
|
} else {
|
||||||
exception = null;
|
exception = null;
|
||||||
}
|
}
|
||||||
return getSuggestion(activity, exception);
|
return getSuggestion(fragmentManager, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Conversation getSuggestion(Activity activity, Conversation exception) {
|
public static Conversation getSuggestion(FragmentManager fragmentManager, Conversation exception) {
|
||||||
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
|
Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
if (fragment instanceof ConversationsOverviewFragment) {
|
if (fragment instanceof ConversationsOverviewFragment) {
|
||||||
List<Conversation> conversations = ((ConversationsOverviewFragment) fragment).conversations;
|
List<Conversation> conversations = ((ConversationsOverviewFragment) fragment).conversations;
|
||||||
if (conversations.size() > 0) {
|
if (conversations.size() > 0) {
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
|
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationAdapte
|
||||||
viewHolder.binding.conversationName.setText(EmojiWrapper.transform(name));
|
viewHolder.binding.conversationName.setText(EmojiWrapper.transform(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conversation == ConversationFragment.getConversation(activity)) {
|
if (conversation == ConversationFragment.getConversation(activity.getSupportFragmentManager())) {
|
||||||
viewHolder.binding.frame.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.color_background_tertiary));
|
viewHolder.binding.frame.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.color_background_tertiary));
|
||||||
} else {
|
} else {
|
||||||
viewHolder.binding.frame.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.color_background_primary));
|
viewHolder.binding.frame.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.color_background_primary));
|
||||||
|
|
|
@ -510,7 +510,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
viewHolder.audioPlayer.setVisibility(View.GONE);
|
viewHolder.audioPlayer.setVisibility(View.GONE);
|
||||||
viewHolder.download_button.setVisibility(View.VISIBLE);
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
||||||
viewHolder.download_button.setText(text);
|
viewHolder.download_button.setText(text);
|
||||||
viewHolder.download_button.setOnClickListener(v -> ConversationFragment.downloadFile(activity, message));
|
viewHolder.download_button.setOnClickListener(v -> ConversationFragment.downloadFile(activity.getSupportFragmentManager(), message));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayOpenableMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
|
private void displayOpenableMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
|
||||||
|
@ -872,7 +872,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
|
|
||||||
public void openDownloadable(Message message) {
|
public void openDownloadable(Message message) {
|
||||||
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
ConversationFragment.registerPendingMessage(activity, message);
|
ConversationFragment.registerPendingMessage(activity.getSupportFragmentManager(), message);
|
||||||
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_OPEN_MESSAGE);
|
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_OPEN_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ public final class MucDetailsContextMenuHelper {
|
||||||
return true;
|
return true;
|
||||||
case R.id.send_private_message:
|
case R.id.send_private_message:
|
||||||
if (activity instanceof ConversationsActivity) {
|
if (activity instanceof ConversationsActivity) {
|
||||||
ConversationFragment conversationFragment = ConversationFragment.get(activity);
|
ConversationFragment conversationFragment = ConversationFragment.get(activity.getSupportFragmentManager());
|
||||||
if (conversationFragment != null) {
|
if (conversationFragment != null) {
|
||||||
conversationFragment.privateMessageWith(user.getFullJid());
|
conversationFragment.privateMessageWith(user.getFullJid());
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue