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