Fix issue #34 - Avatar and header inversed when editing profile

This commit is contained in:
Thomas 2022-05-07 19:07:33 +02:00
parent 7d923ed93b
commit ea984f0553
5 changed files with 22 additions and 21 deletions

View file

@ -165,9 +165,9 @@ public class EditProfileActivity extends BaseActivity {
});
//Actions with the activity
accountsVM = new ViewModelProvider(EditProfileActivity.this).get(AccountsVM.class);
binding.headerSelect.setOnClickListener(view -> startActivityForResult(prepareIntent(), EditProfileActivity.PICK_MEDIA_AVATAR));
binding.headerSelect.setOnClickListener(view -> startActivityForResult(prepareIntent(), EditProfileActivity.PICK_MEDIA_HEADER));
binding.avatarSelect.setOnClickListener(view -> startActivityForResult(prepareIntent(), EditProfileActivity.PICK_MEDIA_HEADER));
binding.avatarSelect.setOnClickListener(view -> startActivityForResult(prepareIntent(), EditProfileActivity.PICK_MEDIA_AVATAR));
}
@Override
@ -185,6 +185,7 @@ public class EditProfileActivity extends BaseActivity {
sendBroadCast(account);
binding.avatarProgress.setVisibility(View.GONE);
BaseMainActivity.accountWeakReference.get().mastodon_account = account;
Helper.recreateMainActivity(EditProfileActivity.this);
});
} else if (requestCode == PICK_MEDIA_HEADER && resultCode == RESULT_OK) {
Glide.with(EditProfileActivity.this)
@ -198,6 +199,7 @@ public class EditProfileActivity extends BaseActivity {
sendBroadCast(account);
binding.headerProgress.setVisibility(View.GONE);
BaseMainActivity.accountWeakReference.get().mastodon_account = account;
Helper.recreateMainActivity(EditProfileActivity.this);
});
}
}

View file

@ -82,6 +82,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide;
@ -1473,6 +1474,20 @@ public class Helper {
}
}
/**
* Send broadcast to recreate Mainactivity
*
* @param activity - Activity
*/
public static void recreateMainActivity(Activity activity) {
Bundle b = new Bundle();
b.putBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b);
LocalBroadcastManager.getInstance(activity).sendBroadcast(intentBD);
}
public static void showKeyboard(Context context, View view) {
view.requestFocus();
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

View file

@ -18,12 +18,10 @@ import static android.content.Context.WINDOW_SERVICE;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
@ -35,7 +33,6 @@ import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import com.google.android.material.button.MaterialButton;
@ -365,18 +362,6 @@ public class ThemeHelper {
return new ColorStateList(states, colors);
}
/**
* Send broadcast to recreate Mainactivity
*
* @param activity - Activity
*/
public static void recreateMainActivity(Activity activity) {
Bundle b = new Bundle();
b.putBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b);
LocalBroadcastManager.getInstance(activity).sendBroadcast(intentBD);
}
public interface SlideAnimation {
void onAnimationEnded();

View file

@ -22,7 +22,6 @@ import androidx.preference.PreferenceFragmentCompat;
import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
public class FragmentLanguageSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -43,7 +42,7 @@ public class FragmentLanguageSettings extends PreferenceFragmentCompat implement
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.compareToIgnoreCase(getString(R.string.SET_DEFAULT_LOCALE_NEW)) == 0) {
requireActivity().recreate();
ThemeHelper.recreateMainActivity(requireActivity());
Helper.recreateMainActivity(requireActivity());
}
}

View file

@ -108,7 +108,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
if (key.equals("use_custom_theme")) {
createPref();
}
ThemeHelper.recreateMainActivity(requireActivity());
Helper.recreateMainActivity(requireActivity());
}
@ -298,7 +298,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
}
appEditor.commit();
cyaneaEditor.apply().recreate(requireActivity());
ThemeHelper.recreateMainActivity(requireActivity());
Helper.recreateMainActivity(requireActivity());
} catch (IOException e) {
e.printStackTrace();
} finally {