Some fixes

This commit is contained in:
Thomas 2022-06-21 17:09:34 +02:00
parent a09c882b75
commit 0f372ccde0
27 changed files with 189 additions and 204 deletions

View file

@ -18,7 +18,6 @@ import static app.fedilab.android.BaseMainActivity.status.DISCONNECTED;
import static app.fedilab.android.BaseMainActivity.status.UNKNOWN; import static app.fedilab.android.BaseMainActivity.status.UNKNOWN;
import static app.fedilab.android.helper.CacheHelper.deleteDir; import static app.fedilab.android.helper.CacheHelper.deleteDir;
import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN;
import static app.fedilab.android.helper.Helper.getCurrentAccount;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -141,13 +140,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
public static boolean filterFetched; public static boolean filterFetched;
public static boolean show_boosts, show_replies, show_art_nsfw; public static boolean show_boosts, show_replies, show_art_nsfw;
public static String regex_home, regex_local, regex_public; public static String regex_home, regex_local, regex_public;
public static BaseAccount currentAccount;
Fragment currentFragment; Fragment currentFragment;
private BaseAccount account;
private AppBarConfiguration mAppBarConfiguration; private AppBarConfiguration mAppBarConfiguration;
private ActivityMainBinding binding; private ActivityMainBinding binding;
private Pinned pinned; private Pinned pinned;
private BottomMenu bottomMenu; private BottomMenu bottomMenu;
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() { private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -158,7 +156,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
redrawPinned(mastodonLists); redrawPinned(mastodonLists);
} }
if (b.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) { if (b.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) {
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(account, binding.bottomNavView); bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
if (bottomMenu != null) { if (bottomMenu != null) {
//ManageClick on bottom menu items //ManageClick on bottom menu items
if (binding.bottomNavView.findViewById(R.id.nav_home) != null) { if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
@ -366,7 +364,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
headerMainBinding.accountProfilePicture.setOnClickListener(v -> { headerMainBinding.accountProfilePicture.setOnClickListener(v -> {
Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class); Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, account.mastodon_account); b.putSerializable(Helper.ARG_ACCOUNT, currentAccount.mastodon_account);
intent.putExtras(b); intent.putExtras(b);
ActivityOptionsCompat options = ActivityOptionsCompat ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(BaseMainActivity.this, headerMainBinding.instanceInfoContainer, getString(R.string.activity_porfile_pp)); .makeSceneTransitionAnimation(BaseMainActivity.this, headerMainBinding.instanceInfoContainer, getString(R.string.activity_porfile_pp));
@ -500,17 +498,17 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
if (itemId == R.id.action_logout_account) { if (itemId == R.id.action_logout_account) {
AlertDialog.Builder alt_bld = new AlertDialog.Builder(BaseMainActivity.this, Helper.dialogStyle()); AlertDialog.Builder alt_bld = new AlertDialog.Builder(BaseMainActivity.this, Helper.dialogStyle());
alt_bld.setTitle(R.string.action_logout); alt_bld.setTitle(R.string.action_logout);
if (account.mastodon_account != null && account.mastodon_account.username != null && account.instance != null) { if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.username != null && currentAccount.instance != null) {
alt_bld.setMessage(getString(R.string.logout_account_confirmation, account.mastodon_account.username, account.instance)); alt_bld.setMessage(getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.username, currentAccount.instance));
} else if (account.mastodon_account != null && account.mastodon_account.acct != null) { } else if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.acct != null) {
alt_bld.setMessage(getString(R.string.logout_account_confirmation, account.mastodon_account.acct, "")); alt_bld.setMessage(getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.acct, ""));
} else { } else {
alt_bld.setMessage(getString(R.string.logout_account_confirmation, "", "")); alt_bld.setMessage(getString(R.string.logout_account_confirmation, "", ""));
} }
alt_bld.setPositiveButton(R.string.action_logout, (dialog, id) -> { alt_bld.setPositiveButton(R.string.action_logout, (dialog, id) -> {
dialog.dismiss(); dialog.dismiss();
try { try {
Helper.removeAccount(BaseMainActivity.this, null); Helper.removeAccount(BaseMainActivity.this);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -536,28 +534,28 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}); });
popup.show(); popup.show();
}); });
account = null; currentAccount = null;
//Update account details //Update account details
new Thread(() -> { new Thread(() -> {
try { try {
account = new Account(BaseMainActivity.this).getConnectedAccount(); currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
if (account == null) { if (currentAccount == null) {
//It is not, the user is redirected to the login page //It is not, the user is redirected to the login page
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
startActivity(myIntent); startActivity(myIntent);
finish(); finish();
return; return;
} }
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(account, binding.bottomNavView); bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
if (account.mastodon_account.locked) { if (currentAccount.mastodon_account.locked) {
binding.navView.getMenu().findItem(R.id.nav_follow_requests).setVisible(true); binding.navView.getMenu().findItem(R.id.nav_follow_requests).setVisible(true);
} }
if (account.admin) { if (currentAccount.admin) {
binding.navView.getMenu().findItem(R.id.nav_administration).setVisible(true); binding.navView.getMenu().findItem(R.id.nav_administration).setVisible(true);
} }
if (bottomMenu != null) { if (bottomMenu != null) {
@ -603,8 +601,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}); });
} }
currentInstance = account.instance; currentInstance = currentAccount.instance;
currentUserID = account.user_id; currentUserID = currentAccount.user_id;
show_boosts = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_BOOSTS) + currentUserID + currentInstance, true); show_boosts = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_BOOSTS) + currentUserID + currentInstance, true);
show_replies = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_REPLIES) + currentUserID + currentInstance, true); show_replies = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_REPLIES) + currentUserID + currentInstance, true);
regex_home = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_HOME) + currentUserID + currentInstance, null); regex_home = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_HOME) + currentUserID + currentInstance, null);
@ -612,14 +610,14 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
regex_public = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null); regex_public = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null);
show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false); show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false);
binding.profilePicture.setOnClickListener(v -> binding.drawerLayout.openDrawer(GravityCompat.START)); binding.profilePicture.setOnClickListener(v -> binding.drawerLayout.openDrawer(GravityCompat.START));
Helper.loadPP(binding.profilePicture, account); Helper.loadPP(binding.profilePicture, currentAccount);
headerMainBinding.accountAcc.setText(String.format("%s@%s", account.mastodon_account.username, account.instance)); headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance));
if (account.mastodon_account.display_name.isEmpty()) { if (currentAccount.mastodon_account.display_name.isEmpty()) {
account.mastodon_account.display_name = account.mastodon_account.acct; currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
} }
headerMainBinding.accountName.setText(account.mastodon_account.display_name); headerMainBinding.accountName.setText(currentAccount.mastodon_account.display_name);
Helper.loadPP(headerMainBinding.accountProfilePicture, account); Helper.loadPP(headerMainBinding.accountProfilePicture, currentAccount);
MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, account.mastodon_account, MastodonHelper.MediaAccountType.HEADER); MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
/* /*
* Some general data are loaded when the app starts such; * Some general data are loaded when the app starts such;
* - Instance info (for limits) * - Instance info (for limits)
@ -637,14 +635,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getFilters(currentInstance, currentToken) new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getFilters(currentInstance, currentToken)
.observe(BaseMainActivity.this, filters -> mainFilters = filters); .observe(BaseMainActivity.this, filters -> mainFilters = filters);
new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getConnectedAccount(currentInstance, currentToken) new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getConnectedAccount(currentInstance, currentToken)
.observe(BaseMainActivity.this, account1 -> { .observe(BaseMainActivity.this, mastodonAccount -> {
//Initialize static var //Initialize static var
getCurrentAccount(BaseMainActivity.this); currentAccount.mastodon_account = mastodonAccount;
new Thread(() -> { new Thread(() -> {
try { try {
//Update account in db //Update account in db
new Account(BaseMainActivity.this).insertOrUpdate(getCurrentAccount(BaseMainActivity.this)); new Account(BaseMainActivity.this).insertOrUpdate(currentAccount);
getCurrentAccount(BaseMainActivity.this);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -15,6 +15,7 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.BaseMainActivity.currentInstance; import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.emojis; import static app.fedilab.android.BaseMainActivity.emojis;
import static app.fedilab.android.ui.drawer.ComposeAdapter.prepareDraft; import static app.fedilab.android.ui.drawer.ComposeAdapter.prepareDraft;
@ -190,7 +191,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
statusDraft.statusDraftList = statuses; statusDraft.statusDraftList = statuses;
} }
if (account == null) { if (account == null) {
account = Helper.getCurrentAccount(ComposeActivity.this); account = currentAccount;
} }
if (account == null) { if (account == null) {
Toasty.error(ComposeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); Toasty.error(ComposeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
@ -268,7 +269,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
//We change order for mentions //We change order for mentions
//At first place the account that has been mentioned if it's not our //At first place the account that has been mentioned if it's not our
statusDraftList.get(0).mentions = new ArrayList<>(); statusDraftList.get(0).mentions = new ArrayList<>();
if (!statusReply.account.acct.equalsIgnoreCase(Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.acct)) { if (!statusReply.account.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) {
Mention mention = new Mention(); Mention mention = new Mention();
mention.acct = "@" + statusReply.account.acct; mention.acct = "@" + statusReply.account.acct;
mention.url = statusReply.account.url; mention.url = statusReply.account.url;
@ -279,7 +280,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
//There are other mentions to //There are other mentions to
if (statusReply.mentions != null && statusReply.mentions.size() > 0) { if (statusReply.mentions != null && statusReply.mentions.size() > 0) {
for (Mention mentionTmp : statusReply.mentions) { for (Mention mentionTmp : statusReply.mentions) {
if (!mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && !mentionTmp.acct.equalsIgnoreCase(Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.acct)) { if (!mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && !mentionTmp.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) {
statusDraftList.get(0).mentions.add(mentionTmp); statusDraftList.get(0).mentions.add(mentionTmp);
} }
} }

View file

@ -15,6 +15,7 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction; import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -84,7 +85,7 @@ public class ContextActivity extends BaseActivity {
finish(); finish();
return; return;
} }
MastodonHelper.loadPPMastodon(binding.profilePicture, Helper.getCurrentAccount(ContextActivity.this).mastodon_account); MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
new Thread(() -> { new Thread(() -> {
focusedStatus = SpannableHelper.convertStatus(getApplication().getApplicationContext(), focusedStatus); focusedStatus = SpannableHelper.convertStatus(getApplication().getApplicationContext(), focusedStatus);
@ -107,7 +108,7 @@ public class ContextActivity extends BaseActivity {
new Thread(() -> { new Thread(() -> {
try { try {
new StatusCache(getApplication()).updateIfExists(statusCache); new StatusCache(getApplication()).updateIfExists(statusCache);
new QuickLoad(getApplication().getApplicationContext()).updateStatus(Helper.getCurrentAccount(ContextActivity.this), status); new QuickLoad(getApplication().getApplicationContext()).updateStatus(currentAccount, status);
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
//Update UI //Update UI
Runnable myRunnable = () -> sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null); Runnable myRunnable = () -> sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null);

View file

@ -14,6 +14,8 @@ package app.fedilab.android.activities;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.net.Uri; import android.net.Uri;
@ -99,7 +101,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
bundle_thumbnailurl = status.account.avatar; bundle_thumbnailurl = status.account.avatar;
} }
if (!bundle_creator.contains("@")) { if (!bundle_creator.contains("@")) {
bundle_creator = bundle_creator + "@" + Helper.getCurrentAccount(CustomSharingActivity.this).instance; bundle_creator = bundle_creator + "@" + currentAccount.instance;
} }
binding.setCustomSharingTitle.setEllipsize(TextUtils.TruncateAt.END); binding.setCustomSharingTitle.setEllipsize(TextUtils.TruncateAt.END);

View file

@ -14,6 +14,8 @@ package app.fedilab.android.activities;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -80,7 +82,7 @@ public class DraftActivity extends BaseActivity implements StatusDraftAdapter.Dr
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
} }
timelinesVM = new ViewModelProvider(DraftActivity.this).get(TimelinesVM.class); timelinesVM = new ViewModelProvider(DraftActivity.this).get(TimelinesVM.class);
timelinesVM.getDrafts(Helper.getCurrentAccount(DraftActivity.this)) timelinesVM.getDrafts(currentAccount)
.observe(DraftActivity.this, this::initializeDraftView); .observe(DraftActivity.this, this::initializeDraftView);
} }
@ -176,7 +178,7 @@ public class DraftActivity extends BaseActivity implements StatusDraftAdapter.Dr
super.onResume(); super.onResume();
//We need to check if drafts changed (ie when coming back from the compose activity) //We need to check if drafts changed (ie when coming back from the compose activity)
if (statusDrafts != null && timelinesVM != null) { if (statusDrafts != null && timelinesVM != null) {
timelinesVM.getDrafts(Helper.getCurrentAccount(DraftActivity.this)) timelinesVM.getDrafts(currentAccount)
.observe(DraftActivity.this, this::updateDrafts); .observe(DraftActivity.this, this::updateDrafts);
} }
} }

View file

@ -14,6 +14,7 @@ package app.fedilab.android.activities;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.BaseMainActivity.instanceInfo; import static app.fedilab.android.BaseMainActivity.instanceInfo;
import android.content.Intent; import android.content.Intent;
@ -74,7 +75,7 @@ public class EditProfileActivity extends BaseActivity {
new ViewModelProvider(EditProfileActivity.this).get(AccountsVM.class).getConnectedAccount(BaseMainActivity.currentInstance, BaseMainActivity.currentToken) new ViewModelProvider(EditProfileActivity.this).get(AccountsVM.class).getConnectedAccount(BaseMainActivity.currentInstance, BaseMainActivity.currentToken)
.observe(EditProfileActivity.this, account -> { .observe(EditProfileActivity.this, account -> {
if (account != null) { if (account != null) {
Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; currentAccount.mastodon_account = account;
initializeView(); initializeView();
} else { } else {
Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error)); Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error));
@ -86,19 +87,19 @@ public class EditProfileActivity extends BaseActivity {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void initializeView() { private void initializeView() {
//Hydrate values //Hydrate values
MastodonHelper.loadProfileMediaMastodon(binding.bannerPp, Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account, MastodonHelper.MediaAccountType.HEADER); MastodonHelper.loadProfileMediaMastodon(binding.bannerPp, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
MastodonHelper.loadPPMastodon(binding.accountPp, Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account); MastodonHelper.loadPPMastodon(binding.accountPp, currentAccount.mastodon_account);
binding.displayName.setText(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.display_name); binding.displayName.setText(currentAccount.mastodon_account.display_name);
binding.acct.setText(String.format(Locale.getDefault(), "%s@%s", Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.acct, BaseMainActivity.currentInstance)); binding.acct.setText(String.format(Locale.getDefault(), "%s@%s", currentAccount.mastodon_account.acct, BaseMainActivity.currentInstance));
String bio; String bio;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
bio = Html.fromHtml(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.note, Html.FROM_HTML_MODE_LEGACY).toString(); bio = Html.fromHtml(currentAccount.mastodon_account.note, Html.FROM_HTML_MODE_LEGACY).toString();
else else
bio = Html.fromHtml(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.note).toString(); bio = Html.fromHtml(currentAccount.mastodon_account.note).toString();
binding.bio.setText(bio); binding.bio.setText(bio);
if (Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.source != null) { if (currentAccount.mastodon_account.source != null) {
binding.sensitive.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.source.sensitive); binding.sensitive.setChecked(currentAccount.mastodon_account.source.sensitive);
switch (Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.source.privacy) { switch (currentAccount.mastodon_account.source.privacy) {
case "public": case "public":
binding.visibilityPublic.setChecked(true); binding.visibilityPublic.setChecked(true);
break; break;
@ -117,15 +118,15 @@ public class EditProfileActivity extends BaseActivity {
binding.visibilityGroup.setVisibility(View.GONE); binding.visibilityGroup.setVisibility(View.GONE);
} }
binding.bot.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.bot); binding.bot.setChecked(currentAccount.mastodon_account.bot);
binding.discoverable.setChecked(Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.discoverable); binding.discoverable.setChecked(currentAccount.mastodon_account.discoverable);
if (Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.locked) { if (currentAccount.mastodon_account.locked) {
binding.locked.setChecked(true); binding.locked.setChecked(true);
} else { } else {
binding.unlocked.setChecked(true); binding.unlocked.setChecked(true);
} }
List<Field> fields = Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account.fields; List<Field> fields = currentAccount.mastodon_account.fields;
if (fields != null && fields.size() > 0) { if (fields != null && fields.size() > 0) {
for (Field field : fields) { for (Field field : fields) {
AccountFieldItemBinding fieldItemBinding = AccountFieldItemBinding.inflate(getLayoutInflater()); AccountFieldItemBinding fieldItemBinding = AccountFieldItemBinding.inflate(getLayoutInflater());
@ -201,11 +202,11 @@ public class EditProfileActivity extends BaseActivity {
if (account != null) { if (account != null) {
sendBroadCast(account); sendBroadCast(account);
binding.avatarProgress.setVisibility(View.GONE); binding.avatarProgress.setVisibility(View.GONE);
Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; currentAccount.mastodon_account = account;
Helper.recreateMainActivity(EditProfileActivity.this); Helper.recreateMainActivity(EditProfileActivity.this);
new Thread(() -> { new Thread(() -> {
try { try {
new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -226,10 +227,10 @@ public class EditProfileActivity extends BaseActivity {
if (account != null) { if (account != null) {
sendBroadCast(account); sendBroadCast(account);
binding.headerProgress.setVisibility(View.GONE); binding.headerProgress.setVisibility(View.GONE);
Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; currentAccount.mastodon_account = account;
new Thread(() -> { new Thread(() -> {
try { try {
new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -320,10 +321,10 @@ public class EditProfileActivity extends BaseActivity {
) )
.observe(EditProfileActivity.this, account -> { .observe(EditProfileActivity.this, account -> {
if (account != null) { if (account != null) {
Helper.getCurrentAccount(EditProfileActivity.this).mastodon_account = account; currentAccount.mastodon_account = account;
new Thread(() -> { new Thread(() -> {
try { try {
new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(Helper.getCurrentAccount(EditProfileActivity.this)); new app.fedilab.android.client.entities.app.Account(EditProfileActivity.this).insertOrUpdate(currentAccount);
sendBroadCast(account); sendBroadCast(account);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -15,6 +15,8 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
@ -107,7 +109,7 @@ public class HashTagActivity extends BaseActivity {
} else if (item.getItemId() == R.id.action_add_timeline) { } else if (item.getItemId() == R.id.action_add_timeline) {
new Thread(() -> { new Thread(() -> {
try { try {
Pinned pinned = new Pinned(HashTagActivity.this).getPinned(Helper.getCurrentAccount(HashTagActivity.this)); Pinned pinned = new Pinned(HashTagActivity.this).getPinned(currentAccount);
boolean canBeAdded = true; boolean canBeAdded = true;
boolean update = true; boolean update = true;
if (pinned == null) { if (pinned == null) {

View file

@ -46,10 +46,10 @@ import es.dmoral.toasty.Toasty;
public class LoginActivity extends BaseActivity { public class LoginActivity extends BaseActivity {
private final int PICK_IMPORT = 5557;
private boolean requestedAdmin;
public static Account.API apiLogin; public static Account.API apiLogin;
public static String currentInstanceLogin, client_idLogin, client_secretLogin, softwareLogin; public static String currentInstanceLogin, client_idLogin, client_secretLogin, softwareLogin;
private final int PICK_IMPORT = 5557;
private boolean requestedAdmin;
private void manageItent(Intent intent) { private void manageItent(Intent intent) {
if (intent != null && intent.getData() != null && intent.getData().toString().contains(REDIRECT_CONTENT_WEB + "?code=")) { if (intent != null && intent.getData() != null && intent.getData().toString().contains(REDIRECT_CONTENT_WEB + "?code=")) {

View file

@ -15,6 +15,8 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
@ -541,7 +543,7 @@ public class ProfileActivity extends BaseActivity {
private void updateAccount() { private void updateAccount() {
//The value for account is from same server so id can be used //The value for account is from same server so id can be used
if (account.id.equals(Helper.getCurrentAccount(ProfileActivity.this).user_id)) { if (account.id.equals(currentAccount.user_id)) {
binding.accountFollow.setVisibility(View.GONE); binding.accountFollow.setVisibility(View.GONE);
binding.headerEditProfile.setVisibility(View.VISIBLE); binding.headerEditProfile.setVisibility(View.VISIBLE);
binding.headerEditProfile.bringToFront(); binding.headerEditProfile.bringToFront();

View file

@ -14,6 +14,8 @@ package app.fedilab.android.activities;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
@ -26,7 +28,6 @@ import com.google.android.material.tabs.TabLayout;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityScheduledBinding; import app.fedilab.android.databinding.ActivityScheduledBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper; import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.pageadapter.FedilabScheduledPageAdapter; import app.fedilab.android.ui.pageadapter.FedilabScheduledPageAdapter;
@ -53,7 +54,7 @@ public class ScheduledActivity extends BaseActivity {
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
} }
MastodonHelper.loadPPMastodon(binding.profilePicture, Helper.getCurrentAccount(ScheduledActivity.this).mastodon_account); MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
binding.title.setText(R.string.scheduled); binding.title.setText(R.string.scheduled);
binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_server))); binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_server)));
binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_client))); binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_client)));

View file

@ -14,6 +14,8 @@ package app.fedilab.android.activities;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
@ -31,7 +33,6 @@ import java.util.Locale;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivitySettingsBinding; import app.fedilab.android.databinding.ActivitySettingsBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.settings.FragmentComposeSettings; import app.fedilab.android.ui.fragment.settings.FragmentComposeSettings;
import app.fedilab.android.ui.fragment.settings.FragmentInterfaceSettings; import app.fedilab.android.ui.fragment.settings.FragmentInterfaceSettings;
@ -69,7 +70,7 @@ public class SettingsActivity extends BaseActivity {
binding.setTheming.setOnClickListener(v -> displaySettings(SettingsEnum.THEMING)); binding.setTheming.setOnClickListener(v -> displaySettings(SettingsEnum.THEMING));
binding.setAdministration.setOnClickListener(v -> displaySettings(SettingsEnum.ADMINISTRATION)); binding.setAdministration.setOnClickListener(v -> displaySettings(SettingsEnum.ADMINISTRATION));
binding.setLanguage.setOnClickListener(v -> displaySettings(SettingsEnum.LANGUAGE)); binding.setLanguage.setOnClickListener(v -> displaySettings(SettingsEnum.LANGUAGE));
if (Helper.getCurrentAccount(SettingsActivity.this).admin) { if (currentAccount.admin) {
binding.setAdministration.setVisibility(View.VISIBLE); binding.setAdministration.setVisibility(View.VISIBLE);
} else { } else {
binding.setAdministration.setVisibility(View.GONE); binding.setAdministration.setVisibility(View.GONE);

View file

@ -105,6 +105,7 @@ public class Status implements Serializable, Cloneable {
public transient boolean setCursorToEnd = false; public transient boolean setCursorToEnd = false;
public transient int cursorPosition = 0; public transient int cursorPosition = 0;
public transient boolean submitted = false; public transient boolean submitted = false;
@NonNull @NonNull
public Object clone() throws CloneNotSupportedException { public Object clone() throws CloneNotSupportedException {
return super.clone(); return super.clone();

View file

@ -51,13 +51,12 @@ public class QuickLoad {
@SerializedName("notifications") @SerializedName("notifications")
public List<Notification> notifications; public List<Notification> notifications;
private Context _mContext; private Context _mContext;
private type typeOfFetch;
public QuickLoad() { public QuickLoad() {
db = null; db = null;
} }
private type typeOfFetch;
public QuickLoad(Context context) { public QuickLoad(Context context) {
//Creation of the DB with tables //Creation of the DB with tables
this.db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); this.db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
@ -72,6 +71,16 @@ public class QuickLoad {
this.typeOfFetch = type; this.typeOfFetch = type;
} }
/**
* Check if the current timeline can be stored
*
* @param timeLineType - Timeline.TimeLineEnum
* @return boolean
*/
private static boolean cannotBeStored(Timeline.TimeLineEnum timeLineType) {
return timeLineType != Timeline.TimeLineEnum.HOME && timeLineType != Timeline.TimeLineEnum.LOCAL && timeLineType != Timeline.TimeLineEnum.PUBLIC && timeLineType != Timeline.TimeLineEnum.REMOTE && timeLineType != Timeline.TimeLineEnum.LIST && timeLineType != Timeline.TimeLineEnum.TAG;
}
/** /**
* Update a QuickLoad in db * Update a QuickLoad in db
* *
@ -99,16 +108,6 @@ public class QuickLoad {
} }
} }
/**
* Check if the current timeline can be stored
*
* @param timeLineType - Timeline.TimeLineEnum
* @return boolean
*/
private static boolean cannotBeStored(Timeline.TimeLineEnum timeLineType) {
return timeLineType != Timeline.TimeLineEnum.HOME && timeLineType != Timeline.TimeLineEnum.LOCAL && timeLineType != Timeline.TimeLineEnum.PUBLIC && timeLineType != Timeline.TimeLineEnum.REMOTE && timeLineType != Timeline.TimeLineEnum.LIST && timeLineType != Timeline.TimeLineEnum.TAG;
}
/** /**
* Insert or update a QuickLoad * Insert or update a QuickLoad
* *

View file

@ -109,16 +109,6 @@ public class CacheHelper {
} }
} }
public interface Callback {
void getCacheSize(float size);
}
public interface CallbackAccount {
void getcount(List<Integer> countStatuses);
}
public static void clearCache(Context context, boolean clearFiles, List<CacheAccount> cacheAccounts, CallbackClear callbackClear) { public static void clearCache(Context context, boolean clearFiles, List<CacheAccount> cacheAccounts, CallbackClear callbackClear) {
new Thread(() -> { new Thread(() -> {
if (clearFiles) { if (clearFiles) {
@ -157,6 +147,15 @@ public class CacheHelper {
}).start(); }).start();
} }
public interface Callback {
void getCacheSize(float size);
}
public interface CallbackAccount {
void getcount(List<Integer> countStatuses);
}
public interface CallbackClear { public interface CallbackClear {
void onCleared(); void onCleared();
} }

View file

@ -15,6 +15,7 @@ package app.fedilab.android.helper;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static android.content.Context.DOWNLOAD_SERVICE; import static android.content.Context.DOWNLOAD_SERVICE;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.webview.ProxyHelper.setProxy; import static app.fedilab.android.webview.ProxyHelper.setProxy;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -588,7 +589,6 @@ public class Helper {
return date; return date;
} }
private static BaseAccount currentAccount;
/** /**
* Converts dp to pixel * Converts dp to pixel
@ -847,58 +847,40 @@ public class Helper {
* Log out the authenticated user by removing its token * Log out the authenticated user by removing its token
* *
* @param activity Activity * @param activity Activity
* @param account {@link Account}
* @throws DBException Exception * @throws DBException Exception
*/ */
public static void removeAccount(Activity activity, BaseAccount account) throws DBException { public static void removeAccount(Activity activity) throws DBException {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
//Current user //Current user
String userId = sharedpreferences.getString(PREF_USER_ID, null); String userId = sharedpreferences.getString(PREF_USER_ID, null);
String instance = sharedpreferences.getString(PREF_USER_INSTANCE, null); String instance = sharedpreferences.getString(PREF_USER_INSTANCE, null);
Account accountDB = new Account(activity); Account accountDB = new Account(activity);
boolean accountRemovedIsLogged = false;
//Remove the current account OauthVM oauthVM = new ViewModelProvider((ViewModelStoreOwner) activity).get(OauthVM.class);
if (account == null) {
account = accountDB.getUniqAccount(userId, instance); //Revoke the token
accountRemovedIsLogged = true; oauthVM.revokeToken(currentAccount.instance, currentAccount.token, currentAccount.client_id, currentAccount.client_secret);
}
if (account != null) {
BaseAccount finalAccount = account;
OauthVM oauthVM = new ViewModelProvider((ViewModelStoreOwner) activity).get(OauthVM.class);
//Revoke the token
oauthVM.revokeToken(account.instance, account.token, account.client_id, account.client_secret);
//Revoke token and remove user
new Thread(() -> {
try {
accountDB.removeUser(finalAccount);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
//If the account removed is not the logged one, no need to log out the current user
if (!accountRemovedIsLogged) {
return;
}
//Log out the current user //Log out the current user
accountDB.removeUser(currentAccount);
BaseAccount newAccount = accountDB.getLastUsedAccount(); BaseAccount newAccount = accountDB.getLastUsedAccount();
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
if (newAccount == null) { if (newAccount == null) {
editor.putString(PREF_USER_TOKEN, null); editor.putString(PREF_USER_TOKEN, null);
editor.putString(PREF_USER_INSTANCE, null); editor.putString(PREF_USER_INSTANCE, null);
editor.putString(PREF_USER_ID, null); editor.putString(PREF_USER_ID, null);
editor.apply(); editor.commit();
Intent loginActivity = new Intent(activity, LoginActivity.class); Intent loginActivity = new Intent(activity, LoginActivity.class);
activity.startActivity(loginActivity); activity.startActivity(loginActivity);
activity.finish(); activity.finish();
} else { } else {
currentAccount = newAccount;
editor.putString(PREF_USER_TOKEN, newAccount.token); editor.putString(PREF_USER_TOKEN, newAccount.token);
editor.putString(PREF_USER_INSTANCE, newAccount.instance); editor.putString(PREF_USER_INSTANCE, newAccount.instance);
editor.putString(PREF_USER_ID, newAccount.user_id); editor.putString(PREF_USER_ID, newAccount.user_id);
BaseMainActivity.currentUserID = newAccount.user_id; BaseMainActivity.currentUserID = newAccount.user_id;
BaseMainActivity.currentToken = newAccount.token; BaseMainActivity.currentToken = newAccount.token;
BaseMainActivity.currentInstance = newAccount.instance; BaseMainActivity.currentInstance = newAccount.instance;
editor.apply(); editor.commit();
Intent changeAccount = new Intent(activity, MainActivity.class); Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.startActivity(changeAccount); activity.startActivity(changeAccount);
@ -1325,31 +1307,6 @@ public class Helper {
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
} }
//Enum that described actions to replace inside a toot content
public enum PatternType {
MENTION,
MENTION_LONG,
TAG,
GROUP
}
public enum NotifType {
FOLLLOW,
MENTION,
BOOST,
FAV,
POLL,
STATUS,
BACKUP,
STORE,
TOOT
}
public interface OnAttachmentCopied {
void onAttachmentCopied(Attachment attachment);
}
/** /**
* Sends notification with intent * Sends notification with intent
* *
@ -1501,7 +1458,6 @@ public class Helper {
notificationManager.notify(notificationId, summaryNotification); notificationManager.notify(notificationId, summaryNotification);
} }
public static void transfertIfExist(Context context) { public static void transfertIfExist(Context context) {
File dbFile = context.getDatabasePath(OLD_DB_NAME); File dbFile = context.getDatabasePath(OLD_DB_NAME);
if (!dbFile.exists()) { if (!dbFile.exists()) {
@ -1525,7 +1481,6 @@ public class Helper {
context.deleteDatabase(OLD_DB_NAME); context.deleteDatabase(OLD_DB_NAME);
} }
public static String dateDiffFull(Date dateToot) { public static String dateDiffFull(Date dateToot) {
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault()); SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault());
try { try {
@ -1566,16 +1521,29 @@ public class Helper {
return "@fedilab_fetch_more_" + uuid; return "@fedilab_fetch_more_" + uuid;
} }
public static BaseAccount getCurrentAccount(Context context) {
if (currentAccount == null) { //Enum that described actions to replace inside a toot content
try { public enum PatternType {
currentAccount = new Account(context).getUniqAccount(MainActivity.currentUserID, MainActivity.currentInstance); MENTION,
} catch (DBException e) { MENTION_LONG,
e.printStackTrace(); TAG,
} GROUP
}
return currentAccount;
} }
public enum NotifType {
FOLLLOW,
MENTION,
BOOST,
FAV,
POLL,
STATUS,
BACKUP,
STORE,
TOOT
}
public interface OnAttachmentCopied {
void onAttachmentCopied(Attachment attachment);
}
} }

View file

@ -15,6 +15,7 @@ package app.fedilab.android.helper;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static android.content.Context.DOWNLOAD_SERVICE; import static android.content.Context.DOWNLOAD_SERVICE;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.helper.Helper.notify_user; import static app.fedilab.android.helper.Helper.notify_user;
import android.app.Activity; import android.app.Activity;
@ -162,7 +163,7 @@ public class MediaHelper {
Uri uri = Uri.fromFile(backupFile); Uri uri = Uri.fromFile(backupFile);
intent.setDataAndType(uri, mime); intent.setDataAndType(uri, mime);
if (!share) { if (!share) {
notify_user(context, Helper.NOTIFICATION_MEDIA, Helper.getCurrentAccount(context), intent, BitmapFactory.decodeResource(context.getResources(), notify_user(context, Helper.NOTIFICATION_MEDIA, currentAccount, intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
Toasty.success(context, context.getString(R.string.save_over), Toasty.LENGTH_LONG).show(); Toasty.success(context, context.getString(R.string.save_over), Toasty.LENGTH_LONG).show();
} else { } else {

View file

@ -14,6 +14,7 @@ package app.fedilab.android.helper;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.ui.pageadapter.FedilabPageAdapter.BOTTOM_TIMELINE_COUNT; import static app.fedilab.android.ui.pageadapter.FedilabPageAdapter.BOTTOM_TIMELINE_COUNT;
import android.content.Context; import android.content.Context;
@ -261,7 +262,7 @@ public class PinnedTimelineHelper {
int toRemove = 0; int toRemove = 0;
try { try {
//If some menu items have been hidden we should not create tab for them //If some menu items have been hidden we should not create tab for them
bottomMenuDb = new BottomMenu(context).getAllBottomMenu(Helper.getCurrentAccount(context)); bottomMenuDb = new BottomMenu(context).getAllBottomMenu(currentAccount);
if (bottomMenuDb != null) { if (bottomMenuDb != null) {
List<BottomMenu.MenuItem> menuItemList = bottomMenuDb.bottom_menu; List<BottomMenu.MenuItem> menuItemList = bottomMenuDb.bottom_menu;
if (menuItemList != null) { if (menuItemList != null) {

View file

@ -15,6 +15,7 @@ package app.fedilab.android.helper;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.helper.Helper.USER_AGENT; import static app.fedilab.android.helper.Helper.USER_AGENT;
import static app.fedilab.android.helper.Helper.convertDpToPixel; import static app.fedilab.android.helper.Helper.convertDpToPixel;
import static app.fedilab.android.helper.Helper.urlPattern; import static app.fedilab.android.helper.Helper.urlPattern;
@ -379,7 +380,7 @@ public class SpannableHelper {
Matcher matcherLink = link.matcher(url); Matcher matcherLink = link.matcher(url);
if (matcherLink.find() && !url.contains("medium.com")) { if (matcherLink.find() && !url.contains("medium.com")) {
if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot
CrossActionHelper.fetchRemoteStatus(context, Helper.getCurrentAccount(context), url, new CrossActionHelper.Callback() { CrossActionHelper.fetchRemoteStatus(context, currentAccount, url, new CrossActionHelper.Callback() {
@Override @Override
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
@ -394,7 +395,7 @@ public class SpannableHelper {
} }
}); });
} else {//It's an account } else {//It's an account
CrossActionHelper.fetchRemoteAccount(context, Helper.getCurrentAccount(context), status.account, new CrossActionHelper.Callback() { CrossActionHelper.fetchRemoteAccount(context, currentAccount, status.account, new CrossActionHelper.Callback() {
@Override @Override
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
@ -843,7 +844,7 @@ public class SpannableHelper {
Matcher matcherLink = link.matcher(url); Matcher matcherLink = link.matcher(url);
if (matcherLink.find() && !url.contains("medium.com")) { if (matcherLink.find() && !url.contains("medium.com")) {
if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot
CrossActionHelper.fetchRemoteStatus(context, Helper.getCurrentAccount(context), url, new CrossActionHelper.Callback() { CrossActionHelper.fetchRemoteStatus(context, currentAccount, url, new CrossActionHelper.Callback() {
@Override @Override
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);

View file

@ -15,6 +15,7 @@ package app.fedilab.android.ui.drawer;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.BaseMainActivity.emojis; import static app.fedilab.android.BaseMainActivity.emojis;
import static app.fedilab.android.BaseMainActivity.instanceInfo; import static app.fedilab.android.BaseMainActivity.instanceInfo;
import static app.fedilab.android.activities.ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE; import static app.fedilab.android.activities.ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE;
@ -421,8 +422,8 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
List<Attachment> attachmentList = statusList.get(position).media_attachments; List<Attachment> attachmentList = statusList.get(position).media_attachments;
if (attachmentList != null && attachmentList.size() > 0) { if (attachmentList != null && attachmentList.size() > 0) {
holder.binding.sensitiveMedia.setVisibility(View.VISIBLE); holder.binding.sensitiveMedia.setVisibility(View.VISIBLE);
holder.binding.sensitiveMedia.setChecked(Helper.getCurrentAccount(context).mastodon_account.source.sensitive); holder.binding.sensitiveMedia.setChecked(currentAccount.mastodon_account.source.sensitive);
statusList.get(position).sensitive = Helper.getCurrentAccount(context).mastodon_account.source.sensitive; statusList.get(position).sensitive = currentAccount.mastodon_account.source.sensitive;
holder.binding.sensitiveMedia.setOnCheckedChangeListener((buttonView, isChecked) -> statusList.get(position).sensitive = isChecked); holder.binding.sensitiveMedia.setOnCheckedChangeListener((buttonView, isChecked) -> statusList.get(position).sensitive = isChecked);
int mediaPosition = 0; int mediaPosition = 0;
for (Attachment attachment : attachmentList) { for (Attachment attachment : attachmentList) {
@ -1070,8 +1071,8 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
if (statusDraft.visibility == null) { if (statusDraft.visibility == null) {
if (position > 0) { if (position > 0) {
statusDraft.visibility = statusList.get(position - 1).visibility; statusDraft.visibility = statusList.get(position - 1).visibility;
} else if (Helper.getCurrentAccount(context).mastodon_account != null && Helper.getCurrentAccount(context).mastodon_account.source != null) { } else if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.source != null) {
statusDraft.visibility = Helper.getCurrentAccount(context).mastodon_account.source.privacy; statusDraft.visibility = currentAccount.mastodon_account.source.privacy;
} else { } else {
statusDraft.visibility = "public"; statusDraft.visibility = "public";
} }

View file

@ -58,8 +58,8 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
private final int TYPE_POLL = 5; private final int TYPE_POLL = 5;
private final int TYPE_STATUS = 6; private final int TYPE_STATUS = 6;
private final int NOTIFICATION_FETCH_MORE = 7; private final int NOTIFICATION_FETCH_MORE = 7;
private Context context;
public FetchMoreCallBack fetchMoreCallBack; public FetchMoreCallBack fetchMoreCallBack;
private Context context;
public NotificationAdapter(List<Notification> notificationList) { public NotificationAdapter(List<Notification> notificationList) {
this.notificationList = notificationList; this.notificationList = notificationList;
@ -254,11 +254,6 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} }
} }
public interface FetchMoreCallBack {
void onClick(String min_id, String fetchmoreId);
}
public long getItemId(int position) { public long getItemId(int position) {
return position; return position;
} }
@ -268,6 +263,9 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
return notificationList.size(); return notificationList.size();
} }
public interface FetchMoreCallBack {
void onClick(String min_id, String fetchmoreId);
}
static class ViewHolderFollow extends RecyclerView.ViewHolder { static class ViewHolderFollow extends RecyclerView.ViewHolder {
DrawerFollowBinding binding; DrawerFollowBinding binding;

View file

@ -139,8 +139,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private final List<Status> statusList; private final List<Status> statusList;
private final boolean minified; private final boolean minified;
private final Timeline.TimeLineEnum timelineType; private final Timeline.TimeLineEnum timelineType;
private Context context;
public FetchMoreCallBack fetchMoreCallBack; public FetchMoreCallBack fetchMoreCallBack;
private Context context;
public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified) { public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified) {
this.statusList = statuses; this.statusList = statuses;
@ -1818,10 +1818,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
} }
public interface FetchMoreCallBack {
void onClick(String min_id, String fetchmoreId);
}
@Override @Override
public int getItemCount() { public int getItemCount() {
return statusList.size(); return statusList.size();
@ -1838,6 +1834,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
} }
public interface FetchMoreCallBack {
void onClick(String min_id, String fetchmoreId);
}
public static class StatusViewHolder extends RecyclerView.ViewHolder { public static class StatusViewHolder extends RecyclerView.ViewHolder {
DrawerStatusBinding binding; DrawerStatusBinding binding;
DrawerStatusHiddenBinding bindingHidden; DrawerStatusHiddenBinding bindingHidden;

View file

@ -28,13 +28,14 @@ import es.dmoral.toasty.Toasty;
public class FragmentInterfaceSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { public class FragmentInterfaceSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
boolean recreate;
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.pref_interface); addPreferencesFromResource(R.xml.pref_interface);
createPref(); createPref();
} }
boolean recreate;
private void createPref() { private void createPref() {
getPreferenceScreen().removeAll(); getPreferenceScreen().removeAll();
addPreferencesFromResource(R.xml.pref_interface); addPreferencesFromResource(R.xml.pref_interface);

View file

@ -15,6 +15,7 @@ package app.fedilab.android.ui.fragment.settings;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -570,7 +571,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
Uri uri = Uri.parse("file://" + fullPath); Uri uri = Uri.parse("file://" + fullPath);
intentOpen.setDataAndType(uri, "text/csv"); intentOpen.setDataAndType(uri, "text/csv");
String title = getString(R.string.data_export_theme); String title = getString(R.string.data_export_theme);
Helper.notify_user(getActivity(), Helper.NOTIFICATION_THEMING, Helper.getCurrentAccount(requireActivity()), intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(), Helper.notify_user(getActivity(), Helper.NOTIFICATION_THEMING, currentAccount, intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(),
R.mipmap.ic_launcher), Helper.NotifType.BACKUP, title, message); R.mipmap.ic_launcher), Helper.NotifType.BACKUP, title, message);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -60,11 +60,11 @@ import app.fedilab.android.viewmodel.mastodon.NotificationsVM;
public class FragmentMastodonNotification extends Fragment implements NotificationAdapter.FetchMoreCallBack { public class FragmentMastodonNotification extends Fragment implements NotificationAdapter.FetchMoreCallBack {
private static final int NOTIFICATION_PRESENT = -1;
private static final int NOTIFICATION__AT_THE_BOTTOM = -2;
private FragmentPaginationBinding binding; private FragmentPaginationBinding binding;
private NotificationsVM notificationsVM; private NotificationsVM notificationsVM;
private boolean flagLoading; private boolean flagLoading;
private static final int NOTIFICATION_PRESENT = -1;
private static final int NOTIFICATION__AT_THE_BOTTOM = -2;
private List<Notification> notificationList; private List<Notification> notificationList;
private NotificationAdapter notificationAdapter; private NotificationAdapter notificationAdapter;
private final BroadcastReceiver receive_action = new BroadcastReceiver() { private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@ -177,7 +177,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -510,6 +509,26 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
super.onPause(); super.onPause();
} }
@Override
public void onClick(String min_id, String id) {
//Fetch more has been pressed
min_id_fetch_more = min_id;
Notification notification = null;
int position = 0;
for (Notification currentNotification : this.notificationList) {
if (currentNotification.id.compareTo(id) == 0) {
notification = currentNotification;
break;
}
position++;
}
if (notification != null) {
this.notificationList.remove(position);
notificationAdapter.notifyItemRemoved(position);
}
route(FragmentMastodonTimeline.DIRECTION.TOP, true);
}
public enum NotificationTypeEnum { public enum NotificationTypeEnum {
@SerializedName("ALL") @SerializedName("ALL")
@ -537,25 +556,4 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
return value; return value;
} }
} }
@Override
public void onClick(String min_id, String id) {
//Fetch more has been pressed
min_id_fetch_more = min_id;
Notification notification = null;
int position = 0;
for (Notification currentNotification : this.notificationList) {
if (currentNotification.id.compareTo(id) == 0) {
notification = currentNotification;
break;
}
position++;
}
if (notification != null) {
this.notificationList.remove(position);
notificationAdapter.notifyItemRemoved(position);
}
route(FragmentMastodonTimeline.DIRECTION.TOP, true);
}
} }

View file

@ -14,6 +14,8 @@ package app.fedilab.android.ui.fragment.timeline;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -80,7 +82,7 @@ public class FragmentScheduled extends Fragment implements StatusScheduledAdapte
} else if (type == Timeline.TimeLineEnum.SCHEDULED_TOOT_CLIENT) { } else if (type == Timeline.TimeLineEnum.SCHEDULED_TOOT_CLIENT) {
new Thread(() -> { new Thread(() -> {
try { try {
List<StatusDraft> scheduledDrafts = new StatusDraft(requireActivity()).geStatusDraftScheduledList(Helper.getCurrentAccount(requireActivity())); List<StatusDraft> scheduledDrafts = new StatusDraft(requireActivity()).geStatusDraftScheduledList(currentAccount);
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
binding.loader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
@ -105,7 +107,7 @@ public class FragmentScheduled extends Fragment implements StatusScheduledAdapte
} else if (type == Timeline.TimeLineEnum.SCHEDULED_BOOST) { } else if (type == Timeline.TimeLineEnum.SCHEDULED_BOOST) {
new Thread(() -> { new Thread(() -> {
try { try {
List<ScheduledBoost> scheduledBoosts = new ScheduledBoost(requireActivity()).getScheduled(Helper.getCurrentAccount(requireActivity())); List<ScheduledBoost> scheduledBoosts = new ScheduledBoost(requireActivity()).getScheduled(currentAccount);
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
binding.loader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);

View file

@ -14,6 +14,8 @@ package app.fedilab.android.viewmodel.mastodon;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.app.Application; import android.app.Application;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -68,7 +70,7 @@ public class ReorderVM extends AndroidViewModel {
new Thread(() -> { new Thread(() -> {
Pinned pinned = null; Pinned pinned = null;
try { try {
pinned = new Pinned(getApplication().getApplicationContext()).getAllPinned(Helper.getCurrentAccount(getApplication().getApplicationContext())); pinned = new Pinned(getApplication().getApplicationContext()).getAllPinned(currentAccount);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -86,7 +88,7 @@ public class ReorderVM extends AndroidViewModel {
new Thread(() -> { new Thread(() -> {
BottomMenu bottomMenu = null; BottomMenu bottomMenu = null;
try { try {
bottomMenu = new BottomMenu(getApplication().getApplicationContext()).getAllBottomMenu(Helper.getCurrentAccount(getApplication().getApplicationContext())); bottomMenu = new BottomMenu(getApplication().getApplicationContext()).getAllBottomMenu(currentAccount);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -14,6 +14,8 @@ package app.fedilab.android.viewmodel.mastodon;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.app.Application; import android.app.Application;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -25,7 +27,7 @@ import androidx.lifecycle.MutableLiveData;
import app.fedilab.android.client.entities.app.Pinned; import app.fedilab.android.client.entities.app.Pinned;
import app.fedilab.android.exception.DBException; import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
public class TopBarVM extends AndroidViewModel { public class TopBarVM extends AndroidViewModel {
@ -42,7 +44,7 @@ public class TopBarVM extends AndroidViewModel {
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Pinned pinnedTimeline = null; Pinned pinnedTimeline = null;
try { try {
pinnedTimeline = pinned.getPinned(Helper.getCurrentAccount(getApplication().getApplicationContext())); pinnedTimeline = pinned.getPinned(currentAccount);
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
} }