Improve Dependency Injection (#1120)
* inject TimelineCases directly into SFragment * inject ThemeUtils
This commit is contained in:
parent
db67096e12
commit
5f390b378b
|
@ -54,11 +54,11 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
||||||
|
|
||||||
protected List<Call> callList;
|
protected List<Call> callList;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ThemeUtils themeUtils;
|
||||||
@Inject
|
@Inject
|
||||||
public AccountManager accountManager;
|
public AccountManager accountManager;
|
||||||
|
|
||||||
ThemeUtils themeUtils = new ThemeUtils();
|
|
||||||
|
|
||||||
protected static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
protected static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -124,7 +124,7 @@ class PreferencesActivity : BaseActivity(), SharedPreferences.OnSharedPreference
|
||||||
"appTheme" -> {
|
"appTheme" -> {
|
||||||
val theme = sharedPreferences.getNonNullString("appTheme", ThemeUtils.APP_THEME_DEFAULT)
|
val theme = sharedPreferences.getNonNullString("appTheme", ThemeUtils.APP_THEME_DEFAULT)
|
||||||
Log.d("activeTheme", theme)
|
Log.d("activeTheme", theme)
|
||||||
ThemeUtils().setAppNightMode(theme, this)
|
themeUtils.setAppNightMode(theme, this)
|
||||||
|
|
||||||
restartActivitiesOnExit = true
|
restartActivitiesOnExit = true
|
||||||
this.restartCurrentActivity()
|
this.restartCurrentActivity()
|
||||||
|
|
|
@ -35,7 +35,6 @@ import com.keylesspalace.tusky.di.Injectable
|
||||||
import com.keylesspalace.tusky.di.ViewModelFactory
|
import com.keylesspalace.tusky.di.ViewModelFactory
|
||||||
import com.keylesspalace.tusky.fragment.SFragment
|
import com.keylesspalace.tusky.fragment.SFragment
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener
|
import com.keylesspalace.tusky.interfaces.StatusActionListener
|
||||||
import com.keylesspalace.tusky.network.TimelineCases
|
|
||||||
import com.keylesspalace.tusky.util.NetworkState
|
import com.keylesspalace.tusky.util.NetworkState
|
||||||
import com.keylesspalace.tusky.util.ThemeUtils
|
import com.keylesspalace.tusky.util.ThemeUtils
|
||||||
import com.keylesspalace.tusky.util.hide
|
import com.keylesspalace.tusky.util.hide
|
||||||
|
@ -44,8 +43,6 @@ import javax.inject.Inject
|
||||||
|
|
||||||
class ConversationsFragment : SFragment(), StatusActionListener, Injectable {
|
class ConversationsFragment : SFragment(), StatusActionListener, Injectable {
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var timelineCases: TimelineCases
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ViewModelFactory
|
lateinit var viewModelFactory: ViewModelFactory
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -165,10 +162,6 @@ class ConversationsFragment : SFragment(), StatusActionListener, Injectable {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun timelineCases(): TimelineCases {
|
|
||||||
return timelineCases
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeItem(position: Int) {
|
override fun removeItem(position: Int) {
|
||||||
viewModel.remove(position)
|
viewModel.remove(position)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ import com.keylesspalace.tusky.entity.Notification;
|
||||||
import com.keylesspalace.tusky.entity.Status;
|
import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
||||||
import com.keylesspalace.tusky.network.TimelineCases;
|
|
||||||
import com.keylesspalace.tusky.util.CollectionUtil;
|
import com.keylesspalace.tusky.util.CollectionUtil;
|
||||||
import com.keylesspalace.tusky.util.Either;
|
import com.keylesspalace.tusky.util.Either;
|
||||||
import com.keylesspalace.tusky.util.HttpHeaderLink;
|
import com.keylesspalace.tusky.util.HttpHeaderLink;
|
||||||
|
@ -122,8 +121,6 @@ public class NotificationsFragment extends SFragment implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
public TimelineCases timelineCases;
|
|
||||||
@Inject
|
@Inject
|
||||||
AccountManager accountManager;
|
AccountManager accountManager;
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -144,11 +141,6 @@ public class NotificationsFragment extends SFragment implements
|
||||||
private String bottomId;
|
private String bottomId;
|
||||||
private boolean alwaysShowSensitiveMedia;
|
private boolean alwaysShowSensitiveMedia;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TimelineCases timelineCases() {
|
|
||||||
return timelineCases;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Each element is either a Notification for loading data or a Placeholder
|
// Each element is either a Notification for loading data or a Placeholder
|
||||||
private final PairedList<Either<Placeholder, Notification>, NotificationViewData> notifications
|
private final PairedList<Either<Placeholder, Notification>, NotificationViewData> notifications
|
||||||
= new PairedList<>(new Function<Either<Placeholder, Notification>, NotificationViewData>() {
|
= new PairedList<>(new Function<Either<Placeholder, Notification>, NotificationViewData>() {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import com.keylesspalace.tusky.ViewMediaActivity;
|
||||||
import com.keylesspalace.tusky.ViewTagActivity;
|
import com.keylesspalace.tusky.ViewTagActivity;
|
||||||
import com.keylesspalace.tusky.db.AccountEntity;
|
import com.keylesspalace.tusky.db.AccountEntity;
|
||||||
import com.keylesspalace.tusky.db.AccountManager;
|
import com.keylesspalace.tusky.db.AccountManager;
|
||||||
|
import com.keylesspalace.tusky.di.Injectable;
|
||||||
import com.keylesspalace.tusky.entity.Attachment;
|
import com.keylesspalace.tusky.entity.Attachment;
|
||||||
import com.keylesspalace.tusky.entity.Status;
|
import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.keylesspalace.tusky.network.MastodonApi;
|
import com.keylesspalace.tusky.network.MastodonApi;
|
||||||
|
@ -61,9 +62,7 @@ import androidx.core.view.ViewCompat;
|
||||||
* adapters. I feel like the profile pages and thread viewer, which I haven't made yet, will also
|
* adapters. I feel like the profile pages and thread viewer, which I haven't made yet, will also
|
||||||
* overlap functionality. So, I'm momentarily leaving it and hopefully working on those will clear
|
* overlap functionality. So, I'm momentarily leaving it and hopefully working on those will clear
|
||||||
* up what needs to be where. */
|
* up what needs to be where. */
|
||||||
public abstract class SFragment extends BaseFragment {
|
public abstract class SFragment extends BaseFragment implements Injectable {
|
||||||
|
|
||||||
protected abstract TimelineCases timelineCases();
|
|
||||||
|
|
||||||
protected abstract void removeItem(int position);
|
protected abstract void removeItem(int position);
|
||||||
|
|
||||||
|
@ -75,6 +74,8 @@ public abstract class SFragment extends BaseFragment {
|
||||||
public MastodonApi mastodonApi;
|
public MastodonApi mastodonApi;
|
||||||
@Inject
|
@Inject
|
||||||
public AccountManager accountManager;
|
public AccountManager accountManager;
|
||||||
|
@Inject
|
||||||
|
public TimelineCases timelineCases;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startActivity(Intent intent) {
|
public void startActivity(Intent intent) {
|
||||||
|
@ -83,7 +84,7 @@ public abstract class SFragment extends BaseFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(@NonNull Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof BottomSheetActivity) {
|
if (context instanceof BottomSheetActivity) {
|
||||||
bottomSheetActivity = (BottomSheetActivity) context;
|
bottomSheetActivity = (BottomSheetActivity) context;
|
||||||
|
@ -236,11 +237,11 @@ public abstract class SFragment extends BaseFragment {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.status_mute: {
|
case R.id.status_mute: {
|
||||||
timelineCases().mute(accountId);
|
timelineCases.mute(accountId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.status_block: {
|
case R.id.status_block: {
|
||||||
timelineCases().block(accountId);
|
timelineCases.block(accountId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.status_report: {
|
case R.id.status_report: {
|
||||||
|
@ -260,7 +261,7 @@ public abstract class SFragment extends BaseFragment {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.pin: {
|
case R.id.pin: {
|
||||||
timelineCases().pin(status, !status.isPinned());
|
timelineCases.pin(status, !status.isPinned());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,7 +322,7 @@ public abstract class SFragment extends BaseFragment {
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(getActivity())
|
||||||
.setMessage(R.string.dialog_delete_toot_warning)
|
.setMessage(R.string.dialog_delete_toot_warning)
|
||||||
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
|
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
|
||||||
timelineCases().delete(id);
|
timelineCases.delete(id);
|
||||||
removeItem(position);
|
removeItem(position);
|
||||||
})
|
})
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
|
|
@ -29,10 +29,8 @@ import com.keylesspalace.tusky.AccountActivity
|
||||||
import com.keylesspalace.tusky.R
|
import com.keylesspalace.tusky.R
|
||||||
import com.keylesspalace.tusky.ViewTagActivity
|
import com.keylesspalace.tusky.ViewTagActivity
|
||||||
import com.keylesspalace.tusky.adapter.SearchResultsAdapter
|
import com.keylesspalace.tusky.adapter.SearchResultsAdapter
|
||||||
import com.keylesspalace.tusky.di.Injectable
|
|
||||||
import com.keylesspalace.tusky.entity.SearchResults
|
import com.keylesspalace.tusky.entity.SearchResults
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener
|
import com.keylesspalace.tusky.interfaces.StatusActionListener
|
||||||
import com.keylesspalace.tusky.network.TimelineCases
|
|
||||||
import com.keylesspalace.tusky.util.ViewDataUtils
|
import com.keylesspalace.tusky.util.ViewDataUtils
|
||||||
import com.keylesspalace.tusky.viewdata.StatusViewData
|
import com.keylesspalace.tusky.viewdata.StatusViewData
|
||||||
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from
|
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from
|
||||||
|
@ -42,12 +40,8 @@ import kotlinx.android.synthetic.main.fragment_search.*
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class SearchFragment : SFragment(), StatusActionListener, Injectable {
|
class SearchFragment : SFragment(), StatusActionListener {
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var timelineCases: TimelineCases
|
|
||||||
|
|
||||||
private lateinit var searchAdapter: SearchResultsAdapter
|
private lateinit var searchAdapter: SearchResultsAdapter
|
||||||
|
|
||||||
|
@ -129,10 +123,6 @@ class SearchFragment : SFragment(), StatusActionListener, Injectable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun timelineCases(): TimelineCases {
|
|
||||||
return timelineCases
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeItem(position: Int) {
|
override fun removeItem(position: Int) {
|
||||||
searchAdapter.removeStatusAtPosition(position)
|
searchAdapter.removeStatusAtPosition(position)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
||||||
import com.keylesspalace.tusky.network.MastodonApi;
|
import com.keylesspalace.tusky.network.MastodonApi;
|
||||||
import com.keylesspalace.tusky.network.TimelineCases;
|
|
||||||
import com.keylesspalace.tusky.repository.Placeholder;
|
import com.keylesspalace.tusky.repository.Placeholder;
|
||||||
import com.keylesspalace.tusky.repository.TimelineRepository;
|
import com.keylesspalace.tusky.repository.TimelineRepository;
|
||||||
import com.keylesspalace.tusky.repository.TimelineRequestMode;
|
import com.keylesspalace.tusky.repository.TimelineRequestMode;
|
||||||
|
@ -126,8 +125,6 @@ public class TimelineFragment extends SFragment implements
|
||||||
MIDDLE
|
MIDDLE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
public TimelineCases timelineCases;
|
|
||||||
@Inject
|
@Inject
|
||||||
public EventHub eventHub;
|
public EventHub eventHub;
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -160,11 +157,6 @@ public class TimelineFragment extends SFragment implements
|
||||||
private boolean alwaysShowSensitiveMedia;
|
private boolean alwaysShowSensitiveMedia;
|
||||||
private boolean initialUpdateFailed = false;
|
private boolean initialUpdateFailed = false;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TimelineCases timelineCases() {
|
|
||||||
return timelineCases;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PairedList<Either<Placeholder, Status>, StatusViewData> statuses =
|
private PairedList<Either<Placeholder, Status>, StatusViewData> statuses =
|
||||||
new PairedList<>(new Function<Either<Placeholder, Status>, StatusViewData>() {
|
new PairedList<>(new Function<Either<Placeholder, Status>, StatusViewData>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,7 +46,6 @@ import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.keylesspalace.tusky.entity.StatusContext;
|
import com.keylesspalace.tusky.entity.StatusContext;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
||||||
import com.keylesspalace.tusky.network.MastodonApi;
|
import com.keylesspalace.tusky.network.MastodonApi;
|
||||||
import com.keylesspalace.tusky.network.TimelineCases;
|
|
||||||
import com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate;
|
import com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate;
|
||||||
import com.keylesspalace.tusky.util.PairedList;
|
import com.keylesspalace.tusky.util.PairedList;
|
||||||
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
||||||
|
@ -83,8 +82,6 @@ public final class ViewThreadFragment extends SFragment implements
|
||||||
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, Injectable {
|
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, Injectable {
|
||||||
private static final String TAG = "ViewThreadFragment";
|
private static final String TAG = "ViewThreadFragment";
|
||||||
|
|
||||||
@Inject
|
|
||||||
public TimelineCases timelineCases;
|
|
||||||
@Inject
|
@Inject
|
||||||
public MastodonApi mastodonApi;
|
public MastodonApi mastodonApi;
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -118,11 +115,6 @@ public final class ViewThreadFragment extends SFragment implements
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TimelineCases timelineCases() {
|
|
||||||
return timelineCases;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
|
@ -29,11 +29,19 @@ import androidx.appcompat.app.AppCompatDelegate;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides runtime compatibility to obtain theme information and re-theme views, especially where
|
* Provides runtime compatibility to obtain theme information and re-theme views, especially where
|
||||||
* the ability to do so is not supported in resource files.
|
* the ability to do so is not supported in resource files.
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ThemeUtils {
|
public class ThemeUtils {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ThemeUtils(){}
|
||||||
|
|
||||||
public static final String APP_THEME_DEFAULT = ThemeUtils.THEME_NIGHT;
|
public static final String APP_THEME_DEFAULT = ThemeUtils.THEME_NIGHT;
|
||||||
|
|
||||||
private static final String THEME_NIGHT = "night";
|
private static final String THEME_NIGHT = "night";
|
||||||
|
|
Loading…
Reference in New Issue