diff options
Diffstat (limited to 'app/src/main/java')
37 files changed, 117 insertions, 103 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/Application.java b/app/src/main/java/net/lacolaco/smileessence/Application.java index 6870d653..fccf3ad0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/Application.java +++ b/app/src/main/java/net/lacolaco/smileessence/Application.java @@ -24,48 +24,61 @@ package net.lacolaco.smileessence; -import android.content.Context; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.preference.UserPreferenceHelper; import net.lacolaco.smileessence.util.Themes; +import java.lang.ref.WeakReference; + public class Application extends com.activeandroid.app.Application { // ------------------------------ FIELDS ------------------------------ - private static Context context; - private static Account currentAccount; - private static int resId = -1; + private static WeakReference<Application> instance; + private Account currentAccount; + private int resId = -1; @Override public void onCreate() { super.onCreate(); - context = getApplicationContext(); // onCreate は一度しか呼ばれないはずだから安全なはず + instance = new WeakReference<>(this); } // --------------------- STATIC METHODS --------------------- - public static Context getContext() { - if (context == null) { - throw new IllegalStateException("[BUG] Application is not initialized"); + public static Application getInstance() { + Application obj = null; + if (instance != null) { + obj = instance.get(); + } + if (obj == null) { + throw new IllegalStateException("[BUG] Application is not initialized?"); + } else { + return obj; } - return context; } - public static int getThemeResId() { + // --------------------- INSTANCE METHODS --------------------- + + public int getThemeResId() { if (resId == -1) { - Logger.debug("setting theme index: " + String.valueOf(UserPreferenceHelper.getInstance().getThemeIndex())); + Logger.debug("setting theme index: " + UserPreferenceHelper.getInstance().getThemeIndex()); resId = Themes.getThemeResId(UserPreferenceHelper.getInstance().getThemeIndex()); } return resId; } - public static Account getCurrentAccount() { + public Account getCurrentAccount() { return currentAccount; } - public static void setCurrentAccount(Account val) { + public void setCurrentAccount(Account val) { currentAccount = val; } + + public void resetState() { + currentAccount = null; + resId = -1; + } } diff --git a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java index 1fe5a967..13941955 100644 --- a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java +++ b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java @@ -124,7 +124,7 @@ public class IntentRouter { } private static void showStatusDialog(final MainActivity activity, long id) { - new ShowStatusTask(Application.getCurrentAccount(), id) + new ShowStatusTask(Application.getInstance().getCurrentAccount(), id) .onDoneUI(tweet -> { StatusDetailDialogFragment fragment = new StatusDetailDialogFragment(); fragment.setStatusID(tweet.getId()); diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/EditCommandActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/EditCommandActivity.java index 901e372d..0a0b531d 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/EditCommandActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/EditCommandActivity.java @@ -83,7 +83,7 @@ public class EditCommandActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_edit_list); diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java index 8d8a36da..5543e679 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java @@ -111,7 +111,7 @@ public class EditExtractionActivity extends Activity implements AdapterView.OnIt @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_edit_list); diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/EditTabActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/EditTabActivity.java index 58ee1d8a..521b0691 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/EditTabActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/EditTabActivity.java @@ -87,7 +87,7 @@ public class EditTabActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_edit_list); diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/EditTemplateActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/EditTemplateActivity.java index 44dfff4d..1ae7376d 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/EditTemplateActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/EditTemplateActivity.java @@ -111,7 +111,7 @@ public class EditTemplateActivity extends Activity implements AdapterView.OnItem @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_edit_list); diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/LicenseActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/LicenseActivity.java index 53946bd4..8d159502 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/LicenseActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/LicenseActivity.java @@ -60,7 +60,7 @@ public class LicenseActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_license); diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java index d1e45509..23a81500 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java @@ -153,7 +153,7 @@ public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { Logger.debug("onCreate"); - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); Notificator.initialize(this); @@ -176,6 +176,7 @@ public class MainActivity extends Activity { stream.shutdown(); } Notificator.getInstance().onBackground(); + Application.getInstance().resetState(); Logger.debug("onDestroy"); } @@ -227,15 +228,15 @@ public class MainActivity extends Activity { return true; } case R.id.actionbar_favstar: { - new CommandOpenURL(this, Application.getCurrentAccount().getUser().getFavstarRecentURL()).execute(); + new CommandOpenURL(this, Application.getInstance().getCurrentAccount().getUser().getFavstarRecentURL()).execute(); return true; } case R.id.actionbar_aclog: { - new CommandOpenURL(this, Application.getCurrentAccount().getUser().getAclogTimelineURL()).execute(); + new CommandOpenURL(this, Application.getInstance().getCurrentAccount().getUser().getAclogTimelineURL()).execute(); return true; } case R.id.actionbar_twilog: { - new CommandOpenURL(this, Application.getCurrentAccount().getUser().getTwilogURL()).execute(); + new CommandOpenURL(this, Application.getInstance().getCurrentAccount().getUser().getTwilogURL()).execute(); return true; } case R.id.actionbar_report: { @@ -337,8 +338,8 @@ public class MainActivity extends Activity { if (stream != null) { stream.shutdown(); } - stream = Application.getCurrentAccount().getTwitterStream(); - userStreamListener = new UserStreamListener(Application.getCurrentAccount()); + stream = Application.getInstance().getCurrentAccount().getTwitterStream(); + userStreamListener = new UserStreamListener(Application.getInstance().getCurrentAccount()); stream.addListener(userStreamListener); stream.addConnectionLifeCycleListener(userStreamListener); stream.user(); @@ -350,7 +351,7 @@ public class MainActivity extends Activity { return; // TODO: error message? } - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); User user = account.getUser(); startStream(); MuteUserIds.refresh(account); @@ -428,7 +429,7 @@ public class MainActivity extends Activity { account = Account.all().get(0); } if (account != null) { - Application.setCurrentAccount(account); + Application.getInstance().setCurrentAccount(account); return true; } else { return false; diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java index 792aef87..3fc7c937 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java @@ -48,7 +48,7 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_edit_list); @@ -77,7 +77,7 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt ConfirmDialogFragment.show(this, getString(R.string.dialog_confirm_clear_account, account.getUser().getScreenName()), () -> { adapter.removeAt(i); Account.unregister(account.getModelId()); - if (account == Application.getCurrentAccount()) { + if (account == Application.getInstance().getCurrentAccount()) { setCurrentAccount(adapter.getItem(0)); } }, false); @@ -116,7 +116,7 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt } private void safeFinish() { - if (Application.getCurrentAccount() != null) { + if (Application.getInstance().getCurrentAccount() != null) { setResult(RESULT_OK); finish(); } else { @@ -145,7 +145,7 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt data.getLongExtra(OAuthSession.KEY_USER_ID, -1L), data.getStringExtra(OAuthSession.KEY_SCREEN_NAME)); adapter.add(account); - if (Application.getCurrentAccount() == null) { + if (Application.getInstance().getCurrentAccount() == null) { setCurrentAccount(account); } } else { @@ -155,7 +155,7 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt } private void setCurrentAccount(Account account) { - Application.setCurrentAccount(account); + Application.getInstance().setCurrentAccount(account); InternalPreferenceHelper.getInstance().set(R.string.key_last_used_account_id, account.getModelId()); } @@ -190,7 +190,7 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt Account account = getItem(position); TextView textView = (TextView) convertView.findViewById(R.id.textView_menuItem_simple); String text = account.getUser().getScreenName(); - if (account == Application.getCurrentAccount()) { + if (account == Application.getInstance().getCurrentAccount()) { text = "(*) " + text; } textView.setText(text); // TODO: show profile image diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/SettingActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/SettingActivity.java index 2cd63e49..c9370025 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/SettingActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/SettingActivity.java @@ -37,7 +37,7 @@ public class SettingActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(Application.getThemeResId()); + setTheme(Application.getInstance().getThemeResId()); super.onCreate(savedInstanceState); setContentView(R.layout.layout_setting); } diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java index f43bbe8a..31167ae8 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java @@ -62,7 +62,7 @@ public class CommandOpenUserDetail extends Command { @Override public boolean execute() { - new ShowUserTask(Application.getCurrentAccount(), screenName) + new ShowUserTask(Application.getInstance().getCurrentAccount(), screenName) .onDoneUI(user -> { UserDetailDialogFragment fragment = new UserDetailDialogFragment(); fragment.setUserID(user.getId()); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java index 50a9b7d2..d7f64b0c 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java @@ -84,8 +84,8 @@ public class StatusCommandCongratulate extends StatusCommand implements IConfirm StatusUpdate update = new TweetBuilder().setText(build()) .setInReplyToStatusID(getOriginalStatus().getId()) .build(); - new TweetTask(Application.getCurrentAccount(), update).execute(); - new FavoriteTask(Application.getCurrentAccount(), getOriginalStatus().getId()) + new TweetTask(Application.getInstance().getCurrentAccount(), update).execute(); + new FavoriteTask(Application.getInstance().getCurrentAccount(), getOriginalStatus().getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_favorite_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_favorite_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java index 122a4bac..525c41f9 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java @@ -54,18 +54,18 @@ public class StatusCommandFavAndRT extends StatusCommand implements IConfirmable @Override public boolean isEnabled() { User user = getOriginalStatus().getUser(); - return !user.isProtected() && user != Application.getCurrentAccount().getUser(); + return !user.isProtected() && user != Application.getInstance().getCurrentAccount().getUser(); } // -------------------------- OTHER METHODS -------------------------- @Override public boolean execute() { - new FavoriteTask(Application.getCurrentAccount(), getOriginalStatus().getId()) + new FavoriteTask(Application.getInstance().getCurrentAccount(), getOriginalStatus().getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_favorite_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_favorite_failed, NotificationType.ALERT)) .execute(); - new RetweetTask(Application.getCurrentAccount(), getOriginalStatus().getId()) + new RetweetTask(Application.getInstance().getCurrentAccount(), getOriginalStatus().getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_retweet_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_retweet_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java index 35f73691..e0d63ec7 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java @@ -77,9 +77,9 @@ public class StatusCommandMakeAnonymous extends StatusCommand implements IConfir @Override public boolean execute() { - StatusUpdate update = new TweetBuilder().setText(build(getActivity(), getOriginalStatus(), Application.getCurrentAccount())).build(); - new TweetTask(Application.getCurrentAccount(), update).execute(); - new FavoriteTask(Application.getCurrentAccount(), getOriginalStatus().getId()) + StatusUpdate update = new TweetBuilder().setText(build(getActivity(), getOriginalStatus(), Application.getInstance().getCurrentAccount())).build(); + new TweetTask(Application.getInstance().getCurrentAccount(), update).execute(); + new FavoriteTask(Application.getInstance().getCurrentAccount(), getOriginalStatus().getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_favorite_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_favorite_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java index c01679ec..3eda0f02 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java @@ -60,7 +60,7 @@ public class StatusCommandNanigaja extends StatusCommand implements IConfirmable // -------------------------- OTHER METHODS -------------------------- public String build() { - User user = Application.getCurrentAccount().getUser(); + User user = Application.getInstance().getCurrentAccount().getUser(); String str = getOriginalStatus().getText(); String header = ""; if (str.startsWith(".")) { @@ -79,8 +79,8 @@ public class StatusCommandNanigaja extends StatusCommand implements IConfirmable StatusUpdate update = new TweetBuilder().setText(build()) .setInReplyToStatusID(getOriginalStatus().getId()) .build(); - new TweetTask(Application.getCurrentAccount(), update).execute(); - new FavoriteTask(Application.getCurrentAccount(), getOriginalStatus().getId()) + new TweetTask(Application.getInstance().getCurrentAccount(), update).execute(); + new FavoriteTask(Application.getInstance().getCurrentAccount(), getOriginalStatus().getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_favorite_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_favorite_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java index 3c826005..e2e0b381 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java @@ -50,14 +50,14 @@ public class UserCommandBlock extends UserCommand implements IConfirmable { @Override public boolean isEnabled() { - return getUser() != Application.getCurrentAccount().getUser(); + return getUser() != Application.getInstance().getCurrentAccount().getUser(); } // -------------------------- OTHER METHODS -------------------------- @Override public boolean execute() { - new BlockTask(Application.getCurrentAccount(), getUser().getId()) + new BlockTask(Application.getInstance().getCurrentAccount(), getUser().getId()) .onDone(user -> Notificator.getInstance().publish(R.string.notice_block_succeeded)) .onFail(ex -> Notificator.getInstance().publish(R.string.notice_block_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java index 85cfb0cc..453c87a4 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java @@ -50,14 +50,14 @@ public class UserCommandReportForSpam extends UserCommand implements IConfirmabl @Override public boolean isEnabled() { - return getUser() != Application.getCurrentAccount().getUser(); + return getUser() != Application.getInstance().getCurrentAccount().getUser(); } // -------------------------- OTHER METHODS -------------------------- @Override public boolean execute() { - new ReportForSpamTask(Application.getCurrentAccount(), getUser().getId()) + new ReportForSpamTask(Application.getInstance().getCurrentAccount(), getUser().getId()) .onDone(user -> Notificator.getInstance().publish(R.string.notice_r4s_succeeded)) .onFail(ex -> Notificator.getInstance().publish(R.string.notice_r4s_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java index 6b726e72..e0a08a9f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java @@ -48,7 +48,7 @@ public class UserCommandSendMessage extends UserCommand { @Override public boolean isEnabled() { - return getUser() != Application.getCurrentAccount().getUser(); + return getUser() != Application.getInstance().getCurrentAccount().getUser(); } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java index 992ed285..a8387de0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java @@ -50,14 +50,14 @@ public class UserCommandUnblock extends UserCommand implements IConfirmable { @Override public boolean isEnabled() { - return getUser() != Application.getCurrentAccount().getUser(); + return getUser() != Application.getInstance().getCurrentAccount().getUser(); } // -------------------------- OTHER METHODS -------------------------- @Override public boolean execute() { - new UnblockTask(Application.getCurrentAccount(), getUser().getId()) + new UnblockTask(Application.getInstance().getCurrentAccount(), getUser().getId()) .onDone(user -> Notificator.getInstance().publish(R.string.notice_unblock_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_unblock_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/preference/InternalPreferenceHelper.java b/app/src/main/java/net/lacolaco/smileessence/preference/InternalPreferenceHelper.java index 50bc3b12..798b4963 100644 --- a/app/src/main/java/net/lacolaco/smileessence/preference/InternalPreferenceHelper.java +++ b/app/src/main/java/net/lacolaco/smileessence/preference/InternalPreferenceHelper.java @@ -45,6 +45,6 @@ public class InternalPreferenceHelper extends SharedPreferenceHelper { // --------------------------- OVERRIDE --------------------------- @Override protected SharedPreferences getPreferences() { - return Application.getContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); + return Application.getInstance().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/preference/SharedPreferenceHelper.java b/app/src/main/java/net/lacolaco/smileessence/preference/SharedPreferenceHelper.java index 51283078..979dc732 100644 --- a/app/src/main/java/net/lacolaco/smileessence/preference/SharedPreferenceHelper.java +++ b/app/src/main/java/net/lacolaco/smileessence/preference/SharedPreferenceHelper.java @@ -117,7 +117,7 @@ public abstract class SharedPreferenceHelper { private String getString(int resID) { try { - return Application.getContext().getString(resID); + return Application.getInstance().getString(resID); } catch (Exception e) { return null; } diff --git a/app/src/main/java/net/lacolaco/smileessence/preference/UserPreferenceHelper.java b/app/src/main/java/net/lacolaco/smileessence/preference/UserPreferenceHelper.java index cba6555d..8ac0514f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/preference/UserPreferenceHelper.java +++ b/app/src/main/java/net/lacolaco/smileessence/preference/UserPreferenceHelper.java @@ -45,7 +45,7 @@ public class UserPreferenceHelper extends SharedPreferenceHelper { // --------------------- GETTER / SETTER METHODS --------------------- @Override protected SharedPreferences getPreferences() { - return PreferenceManager.getDefaultSharedPreferences(Application.getContext()); + return PreferenceManager.getDefaultSharedPreferences(Application.getInstance()); } // --------------------- HELPER METHODS --------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java index e3b81ac6..9f4dbed2 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java @@ -67,7 +67,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { adapter.removeByStatusID(id); adapter.updateForce(); }); - final Account account = Application.getCurrentAccount(); + final Account account = Application.getInstance().getCurrentAccount(); new HomeTimelineTask(account) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) .onFail(e -> Notificator.getInstance().publish(R.string.notice_error_get_home, NotificationType.ALERT)) @@ -94,7 +94,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { }); return; } - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); new HomeTimelineTask(currentAccount) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) .setSinceId(adapter.getTopID()) @@ -114,7 +114,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { final StatusListAdapter adapter = getAdapter(); - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); new HomeTimelineTask(currentAccount) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) .setMaxId(adapter.getLastID() - 1) diff --git a/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java index 9bce0f77..2158a784 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java @@ -71,7 +71,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { adapter.removeByStatusID(id); adapter.updateForce(); }); - final Account account = Application.getCurrentAccount(); + final Account account = Application.getInstance().getCurrentAccount(); final StatusListAdapter adapter_ = adapter; new MentionsTimelineTask(account) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) @@ -90,7 +90,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final StatusListAdapter adapter = getAdapter(); new MentionsTimelineTask(currentAccount) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) @@ -107,7 +107,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final StatusListAdapter adapter = getAdapter(); new MentionsTimelineTask(currentAccount) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) diff --git a/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java index f90c0b7e..e3d77721 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java @@ -67,7 +67,7 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { adapter.removeByMessageID(id); adapter.updateForce(); }); - final Account account = Application.getCurrentAccount(); + final Account account = Application.getInstance().getCurrentAccount(); new DirectMessagesTask(account) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) .onFail(x -> Notificator.getInstance().publish(R.string.notice_error_get_messages, NotificationType.ALERT)) @@ -92,7 +92,7 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final MessageListAdapter adapter = getAdapter(); new DirectMessagesTask(currentAccount) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) @@ -109,7 +109,7 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final MessageListAdapter adapter = getAdapter(); new DirectMessagesTask(currentAccount) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) diff --git a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java index 663582c2..b5457222 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java @@ -353,7 +353,7 @@ public class PostFragment extends PageFragment implements TextWatcher, View.OnFo PostState state = PostState.getState(); MainActivity mainActivity = (MainActivity) getActivity(); boolean resizeFlag = UserPreferenceHelper.getInstance().get(R.string.key_setting_resize_post_image, false); - TweetTask tweetTask = new TweetTask(Application.getCurrentAccount(), state.toStatusUpdate(), state.getMediaFilePath(), resizeFlag); + TweetTask tweetTask = new TweetTask(Application.getInstance().getCurrentAccount(), state.toStatusUpdate(), state.getMediaFilePath(), resizeFlag); tweetTask.execute(); PostState.newState().beginTransaction().commit(); mainActivity.openHomePage(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java index 90872622..6025e8bb 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java @@ -130,7 +130,7 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final SearchListAdapter adapter = getAdapter(); String queryString = adapter.getQuery(); if (TextUtils.isEmpty(queryString)) { @@ -170,7 +170,7 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final SearchListAdapter adapter = getAdapter(); String queryString = adapter.getQuery(); if (TextUtils.isEmpty(queryString)) { @@ -337,14 +337,14 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem query.setQuery(queryString); query.setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()); query.setResultType(Query.RECENT); - new SearchTask(Application.getCurrentAccount(), query) + new SearchTask(Application.getInstance().getCurrentAccount(), query) .onDoneUI(queryResult -> { if (queryResult != null) { List<twitter4j.Status> tweets = queryResult.getTweets(); for (int i = tweets.size() - 1; i >= 0; i--) { twitter4j.Status status = tweets.get(i); if (!status.isRetweet()) { - StatusViewModel viewModel = new StatusViewModel(Tweet.fromTwitter(status, Application.getCurrentAccount().getUserId())); + StatusViewModel viewModel = new StatusViewModel(Tweet.fromTwitter(status, Application.getInstance().getCurrentAccount().getUserId())); adapter.addToTop(viewModel); StatusFilter.getInstance().filter(viewModel); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java index 208b2f7d..e282287f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java @@ -98,7 +98,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final UserListListAdapter adapter = getAdapter(); String listFullName = adapter.getListFullName(); if (TextUtils.isEmpty(listFullName)) { @@ -126,7 +126,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { - final Account currentAccount = Application.getCurrentAccount(); + final Account currentAccount = Application.getInstance().getCurrentAccount(); final UserListListAdapter adapter = getAdapter(); String listFullName = adapter.getListFullName(); if (TextUtils.isEmpty(listFullName)) { @@ -203,7 +203,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im adapter.setListFullName(listFullName); adapter.clear(); adapter.updateForce(); - new UserListStatusesTask(Application.getCurrentAccount(), listFullName) + new UserListStatusesTask(Application.getInstance().getCurrentAccount(), listFullName) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) .onFail(x -> Notificator.getInstance().publish(R.string.notice_error_get_list, NotificationType.ALERT)) .onDoneUI(tweets -> { diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java index 9e98fc01..309e605e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java @@ -156,7 +156,7 @@ public class MessageDetailDialogFragment extends StackableDialogFragment impleme public void deleteMessage(final DirectMessage message) { ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), () -> { - new DeleteMessageTask(Application.getCurrentAccount(), message.getId()) + new DeleteMessageTask(Application.getInstance().getCurrentAccount(), message.getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_message_delete_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_message_delete_failed, NotificationType.ALERT)) .execute(); @@ -194,7 +194,7 @@ public class MessageDetailDialogFragment extends StackableDialogFragment impleme ImageButton reply = (ImageButton) view.findViewById(R.id.button_status_detail_reply); reply.setOnClickListener(this); ImageButton delete = (ImageButton) view.findViewById(R.id.button_status_detail_delete); - delete.setVisibility(Application.getCurrentAccount().canDelete(message) ? View.VISIBLE : View.GONE); + delete.setVisibility(Application.getInstance().getCurrentAccount().canDelete(message) ? View.VISIBLE : View.GONE); delete.setOnClickListener(this); ImageButton menuButton = (ImageButton) view.findViewById(R.id.button_status_detail_menu); menuButton.setOnClickListener(this); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java index 4a635709..f36961d8 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java @@ -62,7 +62,7 @@ public class SelectUserListDialogFragment extends MenuDialogFragment { public List<Command> getCommands() { MainActivity activity = (MainActivity) getActivity(); ArrayList<Command> commands = new ArrayList<>(); - for (String fullName : Application.getCurrentAccount().getListSubscriptions()) { + for (String fullName : Application.getInstance().getCurrentAccount().getListSubscriptions()) { commands.add(new CommandOpenUserList(activity, fullName)); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java index 8c2d4b01..57d978a0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java @@ -153,7 +153,7 @@ public class SendMessageDialogFragment extends StackableDialogFragment implement private void sendMessage() { hideIME(); String text = editText.getText().toString(); - new SendMessageTask(Application.getCurrentAccount(), screenName, text) + new SendMessageTask(Application.getInstance().getCurrentAccount(), screenName, text) .onDone(x -> Notificator.getInstance().publish(R.string.notice_message_send_succeeded)) .onFail(x -> Notificator.getInstance().publish(R.string.notice_message_send_failed, NotificationType.ALERT)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java index 206c795a..4ff79cfb 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java @@ -117,7 +117,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen return new DisposeDialog(getActivity()); } - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); View header = getTitleView(tweet); @@ -193,8 +193,8 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen } private void updateViewButtons(View view, Tweet tweet) { - int themeResId = Application.getThemeResId(); - Account account = Application.getCurrentAccount(); + int themeResId = Application.getInstance().getThemeResId(); + Account account = Application.getInstance().getCurrentAccount(); //--- buttons ImageButton message = (ImageButton) view.findViewById(R.id.button_status_detail_reply); @@ -250,7 +250,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen private void deleteStatus(final Tweet tweet) { confirm(() -> { - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); new DeleteStatusTask(account, tweet.getOriginalTweet().getId()) .onDone(t -> Notificator.getInstance().publish(R.string.notice_status_delete_succeeded)) @@ -279,7 +279,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen } private void replyToStatus(Tweet tweet) { - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); Tweet originalTweet = tweet.getOriginalTweet(); TweetBuilder builder = new TweetBuilder(); @@ -301,7 +301,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen } private void toggleFavorite(Tweet tweet) { - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); if (tweet.isFavoritedBy(account.getUserId())) { new UnfavoriteTask(account, tweet.getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_unfavorite_succeeded)) @@ -316,7 +316,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen } private void toggleRetweet(final Tweet tweet) { - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); confirm(() -> { if (tweet.isRetweetedBy(account.getUserId())) { new DeleteStatusTask(account, tweet.getRetweetIdBy(account.getUserId())) diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java index fe72a7ff..8e82c10c 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java @@ -60,7 +60,7 @@ public class TalkChainDialogFragment extends StackableDialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { MainActivity activity = (MainActivity) getActivity(); - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_talk_list, null); ListView listView = (ListView) view.findViewById(R.id.listview_dialog_talk_list); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java index 8bfc119d..0b42e7ad 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java @@ -150,7 +150,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { - Account currentAccount = Application.getCurrentAccount(); + Account currentAccount = Application.getInstance().getCurrentAccount(); new UserTimelineTask(currentAccount, getUserID()) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) .setSinceId(adapter.getTopID()) @@ -167,7 +167,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { - Account currentAccount = Application.getCurrentAccount(); + Account currentAccount = Application.getInstance().getCurrentAccount(); new UserTimelineTask(currentAccount, getUserID()) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) .setMaxId(adapter.getLastID() - 1) @@ -239,7 +239,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements } private void executeUserTimelineTask(final User user, final StatusListAdapter adapter) { - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); tabHost.getTabWidget().getChildTabViewAt(1).setVisibility(View.GONE); new UserTimelineTask(account, user.getId()) .setCount(UserPreferenceHelper.getInstance().getRequestCountPerPage()) @@ -351,7 +351,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements } private void toggleFollowing(final User user) { - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); lockFollowButton(); Boolean isFollowing = buttonFollow.getTag() != null ? (Boolean) buttonFollow.getTag() : false; if (isFollowing) { @@ -401,12 +401,12 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements private void updateRelationship(final long userId) { MainActivity mainActivity = (MainActivity) getActivity(); - Account account = Application.getCurrentAccount(); + Account account = Application.getInstance().getCurrentAccount(); if (userId == account.getUserId()) { textViewFollowed.setText(R.string.user_detail_followed_is_me); buttonFollow.setVisibility(View.GONE); } else { - int theme = Application.getThemeResId(); + int theme = Application.getInstance().getThemeResId(); lockFollowButton(); textViewFollowed.setText(R.string.user_detail_loading); final Drawable red = Themes.getStyledDrawable(mainActivity, theme, R.attr.button_round_red); diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java index f586f2e2..4d73b321 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java @@ -116,7 +116,7 @@ public class EventViewModel implements IViewModel { } int textSize = UserPreferenceHelper.getInstance().getTextSize(); - int theme = Application.getThemeResId(); + int theme = Application.getInstance().getThemeResId(); TextView header = (TextView) convertedView.findViewById(R.id.textview_status_header); header.setTextSize(textSize); @@ -157,7 +157,7 @@ public class EventViewModel implements IViewModel { // -------------------------- OTHER METHODS -------------------------- public String getFormattedString() { - return Application.getContext().getString(event.getTextFormatResourceID(), source.getScreenName()); + return Application.getInstance().getString(event.getTextFormatResourceID(), source.getScreenName()); } public enum EnumEvent { diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java index ecb47823..5b3ed8f3 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java @@ -93,7 +93,7 @@ public class MessageViewModel implements IViewModel { convertedView.setTag(bundle); } - int theme = Application.getThemeResId(); + int theme = Application.getInstance().getThemeResId(); int colorBgMessage = Themes.getStyledColor(activity, theme, R.attr.color_message_bg_normal, 0); convertedView.setBackgroundColor(colorBgMessage); convertedView.setOnClickListener(new ListItemClickListener(activity, () -> { @@ -120,7 +120,7 @@ public class MessageViewModel implements IViewModel { private void updateViewSender(Activity activity, View convertedView) { int textSize = UserPreferenceHelper.getInstance().getTextSize(); int nameStyle = UserPreferenceHelper.getInstance().getNameStyle(); - int theme = Application.getThemeResId(); + int theme = Application.getInstance().getThemeResId(); NetworkImageView icon = (NetworkImageView) convertedView.findViewById(R.id.imageview_status_icon); ImageCache.getInstance().setImageToView(directMessage.getSender().getProfileImageUrl(), icon); @@ -139,7 +139,7 @@ public class MessageViewModel implements IViewModel { private void updateViewBody(Activity activity, View convertedView) { int textSize = UserPreferenceHelper.getInstance().getTextSize(); - int theme = Application.getThemeResId(); + int theme = Application.getInstance().getThemeResId(); TextView content = (TextView) convertedView.findViewById(R.id.textview_status_text); content.setTextSize(textSize); @@ -150,6 +150,6 @@ public class MessageViewModel implements IViewModel { footer.setTextSize(textSize - 2); int colorFooter = Themes.getStyledColor(activity, theme, R.attr.color_status_text_footer, 0); footer.setTextColor(colorFooter); - footer.setText(getFooterText(Application.getCurrentAccount())); + footer.setText(getFooterText(Application.getInstance().getCurrentAccount())); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java index cb7cde63..acb663de 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java @@ -127,7 +127,7 @@ public class StatusViewModel implements IViewModel { private void updateViewUser(MainActivity activity, View convertedView) { int textSize = UserPreferenceHelper.getInstance().getTextSize(); int nameStyle = UserPreferenceHelper.getInstance().getNameStyle(); - int theme = Application.getThemeResId(); + int theme = Application.getInstance().getThemeResId(); NetworkImageView icon = (NetworkImageView) convertedView.findViewById(R.id.imageview_status_icon); ImageCache.getInstance().setImageToView(tweet.getOriginalTweet().getUser().getProfileImageUrl(), icon); @@ -137,13 +137,13 @@ public class StatusViewModel implements IViewModel { header.setTextSize(textSize); int colorHeader = Themes.getStyledColor(activity, theme, R.attr.color_status_text_header, 0); int colorMineHeader = Themes.getStyledColor(activity, theme, R.attr.color_status_text_mine, 0); - header.setTextColor(tweet.getUser() == Application.getCurrentAccount().getUser() ? colorMineHeader : colorHeader); + header.setTextColor(tweet.getUser() == Application.getInstance().getCurrentAccount().getUser() ? colorMineHeader : colorHeader); header.setText(NameStyles.getNameString(nameStyle, tweet.getOriginalTweet().getUser())); } private void updateViewBody(MainActivity activity, View convertedView) { int textSize = UserPreferenceHelper.getInstance().getTextSize(); - int theme = Application.getThemeResId(); + int theme = Application.getInstance().getThemeResId(); TextView content = (TextView) convertedView.findViewById(R.id.textview_status_text); content.setTextSize(textSize); @@ -165,7 +165,7 @@ public class StatusViewModel implements IViewModel { if (tweet.isRetweet()) { int colorBgRetweet = Themes.getStyledColor(activity, theme, R.attr.color_status_bg_retweet, 0); convertedView.setBackgroundColor(colorBgRetweet); - } else if (tweet.getOriginalTweet().getMentions().contains(Application.getCurrentAccount().getUser().getScreenName())) { + } else if (tweet.getOriginalTweet().getMentions().contains(Application.getInstance().getCurrentAccount().getUser().getScreenName())) { int colorBgMention = Themes.getStyledColor(activity, theme, R.attr.color_status_bg_mention, 0); convertedView.setBackgroundColor(colorBgMention); } else { @@ -176,7 +176,7 @@ public class StatusViewModel implements IViewModel { private void updateViewFavorited(MainActivity activity, View convertedView) { ImageView favorited = (ImageView) convertedView.findViewById(R.id.imageview_status_favorited); - favorited.setVisibility(tweet.isFavoritedBy(Application.getCurrentAccount().getUserId()) ? View.VISIBLE : View.GONE); + favorited.setVisibility(tweet.isFavoritedBy(Application.getInstance().getCurrentAccount().getUserId()) ? View.VISIBLE : View.GONE); } private void updateViewEmbeddeds(MainActivity activity, View convertedView, boolean extendStatusURL) { @@ -191,7 +191,7 @@ public class StatusViewModel implements IViewModel { if (embeddedStatusIDs.size() > 0) { embeddedStatus.setVisibility(View.VISIBLE); for (long id : embeddedStatusIDs) { - BackgroundTask task = Application.getCurrentAccount().fetchTweet(id, embeddedTweet -> { + BackgroundTask task = Application.getInstance().getCurrentAccount().fetchTweet(id, embeddedTweet -> { if (embeddedTweet != null) { StatusViewModel viewModel = new StatusViewModel(embeddedTweet); View embeddedHolder = viewModel.getView(activity, activity.getLayoutInflater(), null, false); |