Using FeedSettingsFragment without Activity
This commit is contained in:
parent
510f00e204
commit
0187786047
|
@ -105,12 +105,6 @@
|
|||
android:value="de.danoeh.antennapod.activity.MainActivity"/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.FeedSettingsActivity"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:label="@string/feed_settings_label">
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".core.service.PlayerWidgetJobService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.graphics.LightingColorFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
||||
import de.danoeh.antennapod.core.glide.FastBlurTransformation;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.fragment.FeedSettingsFragment;
|
||||
import de.danoeh.antennapod.viewmodel.FeedSettingsViewModel;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Displays information about a feed.
|
||||
*/
|
||||
public class FeedSettingsActivity extends AppCompatActivity {
|
||||
public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId";
|
||||
private static final String TAG = "FeedSettingsActivity";
|
||||
private Feed feed;
|
||||
private Disposable disposable;
|
||||
private ImageView imgvCover;
|
||||
private TextView txtvTitle;
|
||||
private ImageView imgvBackground;
|
||||
private TextView txtvAuthorHeader;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(UserPreferences.getTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.feedsettings);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
imgvCover = findViewById(R.id.imgvCover);
|
||||
txtvTitle = findViewById(R.id.txtvTitle);
|
||||
txtvAuthorHeader = findViewById(R.id.txtvAuthor);
|
||||
imgvBackground = findViewById(R.id.imgvBackground);
|
||||
findViewById(R.id.butShowInfo).setVisibility(View.INVISIBLE);
|
||||
findViewById(R.id.butShowSettings).setVisibility(View.INVISIBLE);
|
||||
// https://github.com/bumptech/glide/issues/529
|
||||
imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000));
|
||||
|
||||
long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1);
|
||||
disposable = ViewModelProviders.of(this).get(FeedSettingsViewModel.class).getFeed(feedId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(result -> {
|
||||
feed = result;
|
||||
showFragment();
|
||||
showHeader();
|
||||
}, error -> {
|
||||
Log.d(TAG, Log.getStackTraceString(error));
|
||||
finish();
|
||||
}, () -> {
|
||||
Log.e(TAG, "Activity was started with invalid arguments");
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
private void showFragment() {
|
||||
FeedSettingsFragment fragment = new FeedSettingsFragment();
|
||||
fragment.setArguments(getIntent().getExtras());
|
||||
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
FragmentTransaction fragmentTransaction =
|
||||
fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.settings_fragment_container, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void showHeader() {
|
||||
txtvTitle.setText(feed.getTitle());
|
||||
|
||||
if (!TextUtils.isEmpty(feed.getAuthor())) {
|
||||
txtvAuthorHeader.setText(feed.getAuthor());
|
||||
}
|
||||
|
||||
Glide.with(FeedSettingsActivity.this)
|
||||
.load(feed.getImageLocation())
|
||||
.apply(new RequestOptions()
|
||||
.placeholder(R.color.light_gray)
|
||||
.error(R.color.light_gray)
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.fitCenter()
|
||||
.dontAnimate())
|
||||
.into(imgvCover);
|
||||
Glide.with(FeedSettingsActivity.this)
|
||||
.load(feed.getImageLocation())
|
||||
.apply(new RequestOptions()
|
||||
.placeholder(R.color.image_readability_tint)
|
||||
.error(R.color.image_readability_tint)
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.transform(new FastBlurTransformation())
|
||||
.dontAnimate())
|
||||
.into(imgvBackground);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,6 @@ import org.greenrobot.eventbus.ThreadMode;
|
|||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.FeedSettingsActivity;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.adapter.FeedItemlistAdapter;
|
||||
import de.danoeh.antennapod.core.asynctask.FeedRemover;
|
||||
|
@ -495,10 +494,8 @@ public class FeedItemlistFragment extends ListFragment {
|
|||
imgvCover.setOnClickListener(v -> showFeedInfo());
|
||||
butShowSettings.setOnClickListener(v -> {
|
||||
if (feed != null) {
|
||||
Intent startIntent = new Intent(getActivity(), FeedSettingsActivity.class);
|
||||
startIntent.putExtra(FeedSettingsActivity.EXTRA_FEED_ID,
|
||||
feed.getId());
|
||||
startActivity(startIntent);
|
||||
FeedSettingsFragment fragment = FeedSettingsFragment.newInstance(feed);
|
||||
((MainActivity) getActivity()).loadChildFragment(fragment, TransitionEffect.FLIP);
|
||||
}
|
||||
});
|
||||
headerCreated = true;
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.support.v14.preference.SwitchPreference;
|
|||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedFilter;
|
||||
|
@ -18,17 +19,25 @@ import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
|||
import de.danoeh.antennapod.dialog.EpisodeFilterDialog;
|
||||
import de.danoeh.antennapod.viewmodel.FeedSettingsViewModel;
|
||||
|
||||
import static de.danoeh.antennapod.activity.FeedSettingsActivity.EXTRA_FEED_ID;
|
||||
|
||||
public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
||||
private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter";
|
||||
private static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId";
|
||||
private Feed feed;
|
||||
private FeedPreferences feedPreferences;
|
||||
|
||||
public static FeedSettingsFragment newInstance(Feed feed) {
|
||||
FeedSettingsFragment fragment = new FeedSettingsFragment();
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putLong(EXTRA_FEED_ID, feed.getId());
|
||||
fragment.setArguments(arguments);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.feed_settings);
|
||||
|
||||
postponeEnterTransition();
|
||||
long feedId = getArguments().getLong(EXTRA_FEED_ID);
|
||||
ViewModelProviders.of(getActivity()).get(FeedSettingsViewModel.class).getFeed(feedId)
|
||||
.subscribe(result -> {
|
||||
|
@ -43,9 +52,16 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
|||
|
||||
updateAutoDeleteSummary();
|
||||
updateAutoDownloadEnabled();
|
||||
startPostponedEnterTransition();
|
||||
}).dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.feed_settings_label);
|
||||
}
|
||||
|
||||
private void setupEpisodeFilterPreference() {
|
||||
findPreference(PREF_EPISODE_FILTER).setOnPreferenceClickListener(preference -> {
|
||||
new EpisodeFilterDialog(getContext(), feedPreferences.getFilter()) {
|
||||
|
|
Loading…
Reference in New Issue