mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-24 00:44:43 +01:00
Enabling or disabling nsfw are now available.
This commit is contained in:
parent
9bad5024ff
commit
a2fe95912b
@ -4,8 +4,13 @@ package Settings;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.ChangeNSFWEvent;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link PreferenceFragmentCompat} subclass.
|
* A simple {@link PreferenceFragmentCompat} subclass.
|
||||||
@ -14,5 +19,13 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
setPreferencesFromResource(R.xml.main_preferences, rootKey);
|
setPreferencesFromResource(R.xml.main_preferences, rootKey);
|
||||||
|
|
||||||
|
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
|
||||||
|
if(nsfwSwitch != null) {
|
||||||
|
nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,141 @@
|
|||||||
package Settings;
|
package Settings;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
import androidx.work.Constraints;
|
||||||
|
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||||
|
import androidx.work.NetworkType;
|
||||||
|
import androidx.work.PeriodicWorkRequest;
|
||||||
|
import androidx.work.WorkInfo;
|
||||||
|
import androidx.work.WorkManager;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
|
import ml.docilealligator.infinityforreddit.PullNotificationWorker;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
*/
|
*/
|
||||||
public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
|
private boolean enableNotification;
|
||||||
|
private long notificationInterval;
|
||||||
|
|
||||||
|
private WorkManager workManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
SharedPreferences sharedPreferences;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
setPreferencesFromResource(R.xml.notification_preferences, rootKey);
|
setPreferencesFromResource(R.xml.notification_preferences, rootKey);
|
||||||
|
|
||||||
|
Activity activity = getActivity();
|
||||||
|
|
||||||
|
if(activity != null) {
|
||||||
|
workManager = WorkManager.getInstance(activity);
|
||||||
|
|
||||||
|
((Infinity) activity.getApplication()).getAppComponent().inject(this);
|
||||||
|
|
||||||
|
SwitchPreference enableNotificationSwitchPreference = findPreference(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY);
|
||||||
|
ListPreference notificationIntervalListPreference = findPreference(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY);
|
||||||
|
|
||||||
|
enableNotification = sharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
||||||
|
notificationInterval = Long.parseLong(sharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1"));
|
||||||
|
|
||||||
|
if(enableNotification) {
|
||||||
|
if (notificationIntervalListPreference != null) {
|
||||||
|
notificationIntervalListPreference.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(enableNotificationSwitchPreference != null) {
|
||||||
|
enableNotificationSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
enableNotification = ((Boolean) newValue);
|
||||||
|
if(notificationIntervalListPreference != null) {
|
||||||
|
notificationIntervalListPreference.setVisible(enableNotification);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(enableNotification) {
|
||||||
|
Constraints constraints = new Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
|
notificationInterval, TimeUnit.HOURS)
|
||||||
|
.setConstraints(constraints)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
|
} else {
|
||||||
|
ListenableFuture<List<WorkInfo>> workInfo = workManager.getWorkInfosByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
try {
|
||||||
|
List<WorkInfo> list = workInfo.get();
|
||||||
|
if(list != null && list.size() != 0) {
|
||||||
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(notificationIntervalListPreference != null) {
|
||||||
|
notificationIntervalListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
notificationInterval = (Long) newValue;
|
||||||
|
|
||||||
|
if(enableNotification) {
|
||||||
|
Constraints constraints = new Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
|
notificationInterval, TimeUnit.HOURS)
|
||||||
|
.setConstraints(constraints)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
|
} else {
|
||||||
|
ListenableFuture<List<WorkInfo>> workInfo = workManager.getWorkInfosByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
try {
|
||||||
|
List<WorkInfo> list = workInfo.get();
|
||||||
|
if(list != null && list.size() != 0) {
|
||||||
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,4 +255,9 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing
|
|||||||
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
|
||||||
|
((FragmentCommunicator) mFragment).changeNSFW(changeNSFWEvent.nsfw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import Settings.NotificationPreferenceFragment;
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(modules = AppModule.class)
|
@Component(modules = AppModule.class)
|
||||||
interface AppComponent {
|
public interface AppComponent {
|
||||||
void inject(MainActivity mainActivity);
|
void inject(MainActivity mainActivity);
|
||||||
void inject(LoginActivity loginActivity);
|
void inject(LoginActivity loginActivity);
|
||||||
void inject(PostFragment postFragment);
|
void inject(PostFragment postFragment);
|
||||||
@ -36,4 +37,5 @@ interface AppComponent {
|
|||||||
void inject(AccountPostsActivity accountPostsActivity);
|
void inject(AccountPostsActivity accountPostsActivity);
|
||||||
void inject(PullNotificationWorker pullNotificationWorker);
|
void inject(PullNotificationWorker pullNotificationWorker);
|
||||||
void inject(ViewMessageActivity viewMessageActivity);
|
void inject(ViewMessageActivity viewMessageActivity);
|
||||||
|
void inject(NotificationPreferenceFragment notificationPreferenceFragment);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -78,4 +81,10 @@ class AppModule {
|
|||||||
RedditDataRoomDatabase provideRedditDataRoomDatabase() {
|
RedditDataRoomDatabase provideRedditDataRoomDatabase() {
|
||||||
return RedditDataRoomDatabase.getDatabase(mApplication);
|
return RedditDataRoomDatabase.getDatabase(mApplication);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
SharedPreferences provideSharedPreferences() {
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(mApplication);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
public class ChangeNSFWEvent {
|
||||||
|
boolean nsfw;
|
||||||
|
public ChangeNSFWEvent(boolean nsfw) {
|
||||||
|
this.nsfw = nsfw;
|
||||||
|
}
|
||||||
|
}
|
@ -51,16 +51,18 @@ class FetchSubredditData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
Log.i("call failed", t.getMessage());
|
Log.i("call failed", "message " + t.getMessage());
|
||||||
fetchSubredditDataListener.onFetchSubredditDataFail();
|
fetchSubredditDataListener.onFetchSubredditDataFail();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fetchSubredditListingData(Retrofit retrofit, String query, String after, String sortType, final FetchSubredditListingDataListener fetchSubredditListingDataListener) {
|
static void fetchSubredditListingData(Retrofit retrofit, String query, String after, String sortType,
|
||||||
|
boolean nsfw,
|
||||||
|
final FetchSubredditListingDataListener fetchSubredditListingDataListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType);
|
Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw);
|
||||||
subredditDataCall.enqueue(new Callback<String>() {
|
subredditDataCall.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
@ -85,7 +87,7 @@ class FetchSubredditData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
Log.i("call failed", t.getMessage());
|
Log.i("call failed", "message " + t.getMessage());
|
||||||
fetchSubredditListingDataListener.onFetchSubredditListingDataFail();
|
fetchSubredditListingDataListener.onFetchSubredditListingDataFail();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -49,17 +49,18 @@ public class FetchUserData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
Log.i("call failed", t.getMessage());
|
Log.i("call failed", "message " + t.getMessage());
|
||||||
fetchUserDataListener.onFetchUserDataFailed();
|
fetchUserDataListener.onFetchUserDataFailed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fetchUserListingData(Retrofit retrofit, String query, String after, String sortType,
|
public static void fetchUserListingData(Retrofit retrofit, String query, String after, String sortType,
|
||||||
|
boolean nsfw,
|
||||||
FetchUserListingDataListener fetchUserListingDataListener) {
|
FetchUserListingDataListener fetchUserListingDataListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
Call<String> userInfo = api.searchUsers(query, after, sortType);
|
Call<String> userInfo = api.searchUsers(query, after, sortType, nsfw);
|
||||||
userInfo.enqueue(new Callback<String>() {
|
userInfo.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
@ -83,7 +84,7 @@ public class FetchUserData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
Log.i("call failed", t.getMessage());
|
Log.i("call failed", "message " + t.getMessage());
|
||||||
fetchUserListingDataListener.onFetchUserListingDataFailed();
|
fetchUserListingDataListener.onFetchUserListingDataFailed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
interface FragmentCommunicator {
|
interface FragmentCommunicator {
|
||||||
void refresh();
|
void refresh();
|
||||||
|
default void changeNSFW(boolean nsfw) {};
|
||||||
default void startLazyMode() {}
|
default void startLazyMode() {}
|
||||||
default void stopLazyMode() {}
|
default void stopLazyMode() {}
|
||||||
default void resumeLazyMode(boolean resumeNow) {}
|
default void resumeLazyMode(boolean resumeNow) {}
|
||||||
@ -9,4 +10,5 @@ interface FragmentCommunicator {
|
|||||||
default boolean isInLazyMode() {
|
default boolean isInLazyMode() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -36,6 +37,7 @@ import androidx.work.Constraints;
|
|||||||
import androidx.work.ExistingPeriodicWorkPolicy;
|
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||||
import androidx.work.NetworkType;
|
import androidx.work.NetworkType;
|
||||||
import androidx.work.PeriodicWorkRequest;
|
import androidx.work.PeriodicWorkRequest;
|
||||||
|
import androidx.work.WorkInfo;
|
||||||
import androidx.work.WorkManager;
|
import androidx.work.WorkManager;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
@ -45,10 +47,13 @@ import com.google.android.material.appbar.AppBarLayout;
|
|||||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -145,6 +150,9 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
@Inject
|
@Inject
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -255,6 +263,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
private void getCurrentAccountAndBindView() {
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
||||||
|
String notificationInterval = mSharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1");
|
||||||
|
|
||||||
|
WorkManager workManager = WorkManager.getInstance(this);
|
||||||
|
|
||||||
if(mNewAccountName != null) {
|
if(mNewAccountName != null) {
|
||||||
if(account == null || !account.getUsername().equals(mNewAccountName)) {
|
if(account == null || !account.getUsername().equals(mNewAccountName)) {
|
||||||
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> {
|
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> {
|
||||||
@ -270,18 +283,31 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
mProfileImageUrl = newAccount.getProfileImageUrl();
|
mProfileImageUrl = newAccount.getProfileImageUrl();
|
||||||
mBannerImageUrl = newAccount.getBannerImageUrl();
|
mBannerImageUrl = newAccount.getBannerImageUrl();
|
||||||
mKarma = newAccount.getKarma();
|
mKarma = newAccount.getKarma();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(enableNotification) {
|
||||||
Constraints constraints = new Constraints.Builder()
|
Constraints constraints = new Constraints.Builder()
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class, 1, TimeUnit.HOURS)
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
|
Long.parseLong(notificationInterval), TimeUnit.HOURS)
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
|
} else {
|
||||||
|
ListenableFuture<List<WorkInfo>> workInfo = workManager.getWorkInfosByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
try {
|
||||||
|
List<WorkInfo> list = workInfo.get();
|
||||||
|
if(list != null && list.size() != 0) {
|
||||||
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
@ -293,17 +319,30 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
mBannerImageUrl = account.getBannerImageUrl();
|
mBannerImageUrl = account.getBannerImageUrl();
|
||||||
mKarma = account.getKarma();
|
mKarma = account.getKarma();
|
||||||
|
|
||||||
|
if(enableNotification) {
|
||||||
Constraints constraints = new Constraints.Builder()
|
Constraints constraints = new Constraints.Builder()
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class, 1, TimeUnit.HOURS)
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
|
Long.parseLong(notificationInterval), TimeUnit.HOURS)
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
|
} else {
|
||||||
|
ListenableFuture<List<WorkInfo>> workInfo = workManager.getWorkInfosByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
try {
|
||||||
|
List<WorkInfo> list = workInfo.get();
|
||||||
|
if(list != null && list.size() != 0) {
|
||||||
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
@ -316,18 +355,31 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
mProfileImageUrl = account.getProfileImageUrl();
|
mProfileImageUrl = account.getProfileImageUrl();
|
||||||
mBannerImageUrl = account.getBannerImageUrl();
|
mBannerImageUrl = account.getBannerImageUrl();
|
||||||
mKarma = account.getKarma();
|
mKarma = account.getKarma();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(enableNotification) {
|
||||||
Constraints constraints = new Constraints.Builder()
|
Constraints constraints = new Constraints.Builder()
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class, 1, TimeUnit.HOURS)
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
|
Long.parseLong(notificationInterval), TimeUnit.HOURS)
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
|
} else {
|
||||||
|
ListenableFuture<List<WorkInfo>> workInfo = workManager.getWorkInfosByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
try {
|
||||||
|
List<WorkInfo> list = workInfo.get();
|
||||||
|
if(list != null && list.size() != 0) {
|
||||||
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
@ -748,6 +800,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
|
||||||
|
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
|
||||||
|
}
|
||||||
|
|
||||||
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||||
private PostFragment frontPagePostFragment;
|
private PostFragment frontPagePostFragment;
|
||||||
private PostFragment popularPostFragment;
|
private PostFragment popularPostFragment;
|
||||||
@ -993,5 +1050,17 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeNSFW(boolean nsfw) {
|
||||||
|
if(frontPagePostFragment != null) {
|
||||||
|
frontPagePostFragment.changeNSFW(nsfw);
|
||||||
|
}
|
||||||
|
if(popularPostFragment != null) {
|
||||||
|
popularPostFragment.changeNSFW(nsfw);
|
||||||
|
}
|
||||||
|
if(allPostFragment != null) {
|
||||||
|
allPostFragment.changeNSFW(nsfw);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,13 @@ class ParsePost {
|
|||||||
void onParsePostFail();
|
void onParsePostFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parsePosts(String response, Locale locale, int nPosts, int filter, ParsePostsListingListener parsePostsListingListener) {
|
static void parsePosts(String response, Locale locale, int nPosts, int filter, boolean nsfw,
|
||||||
new ParsePostDataAsyncTask(response, locale, nPosts, filter, parsePostsListingListener).execute();
|
ParsePostsListingListener parsePostsListingListener) {
|
||||||
|
new ParsePostDataAsyncTask(response, locale, nPosts, filter, nsfw, parsePostsListingListener).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parsePost(String response, Locale locale, ParsePostListener parsePostListener) {
|
static void parsePost(String response, Locale locale, ParsePostListener parsePostListener) {
|
||||||
new ParsePostDataAsyncTask(response, locale, parsePostListener).execute();
|
new ParsePostDataAsyncTask(response, locale, true, parsePostListener).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ParsePostDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
private static class ParsePostDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
@ -41,6 +42,7 @@ class ParsePost {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private int nPosts;
|
private int nPosts;
|
||||||
private int filter;
|
private int filter;
|
||||||
|
private boolean nsfw;
|
||||||
private ParsePostsListingListener parsePostsListingListener;
|
private ParsePostsListingListener parsePostsListingListener;
|
||||||
private ParsePostListener parsePostListener;
|
private ParsePostListener parsePostListener;
|
||||||
private ArrayList<Post> newPosts;
|
private ArrayList<Post> newPosts;
|
||||||
@ -48,7 +50,7 @@ class ParsePost {
|
|||||||
private String lastItem;
|
private String lastItem;
|
||||||
private boolean parseFailed;
|
private boolean parseFailed;
|
||||||
|
|
||||||
ParsePostDataAsyncTask(String response, Locale locale, int nPosts, int filter,
|
ParsePostDataAsyncTask(String response, Locale locale, int nPosts, int filter, boolean nsfw,
|
||||||
ParsePostsListingListener parsePostsListingListener) {
|
ParsePostsListingListener parsePostsListingListener) {
|
||||||
this.parsePostsListingListener = parsePostsListingListener;
|
this.parsePostsListingListener = parsePostsListingListener;
|
||||||
try {
|
try {
|
||||||
@ -58,6 +60,7 @@ class ParsePost {
|
|||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.nPosts = nPosts;
|
this.nPosts = nPosts;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
newPosts = new ArrayList<>();
|
newPosts = new ArrayList<>();
|
||||||
parseFailed = false;
|
parseFailed = false;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -66,12 +69,13 @@ class ParsePost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ParsePostDataAsyncTask(String response, Locale locale,
|
ParsePostDataAsyncTask(String response, Locale locale, boolean nsfw,
|
||||||
ParsePostListener parsePostListener) {
|
ParsePostListener parsePostListener) {
|
||||||
this.parsePostListener = parsePostListener;
|
this.parsePostListener = parsePostListener;
|
||||||
try {
|
try {
|
||||||
allData = new JSONArray(response).getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
allData = new JSONArray(response).getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
|
this.nsfw = nsfw;
|
||||||
parseFailed = false;
|
parseFailed = false;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -112,6 +116,7 @@ class ParsePost {
|
|||||||
try {
|
try {
|
||||||
JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||||
Post post = parseBasicData(data, locale, i);
|
Post post = parseBasicData(data, locale, i);
|
||||||
|
if(!(!nsfw && post.isNSFW())) {
|
||||||
if (filter == PostFragment.EXTRA_NO_FILTER) {
|
if (filter == PostFragment.EXTRA_NO_FILTER) {
|
||||||
newPosts.add(post);
|
newPosts.add(post);
|
||||||
} else if (filter == post.getPostType()) {
|
} else if (filter == post.getPostType()) {
|
||||||
@ -119,6 +124,7 @@ class ParsePost {
|
|||||||
} else if (filter == Post.LINK_TYPE && post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
} else if (filter == Post.LINK_TYPE && post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
||||||
newPosts.add(post);
|
newPosts.add(post);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e("parsing post error", "message: " + e.getMessage());
|
Log.e("parsing post error", "message: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
private String query;
|
private String query;
|
||||||
private int postType;
|
private int postType;
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
private boolean nsfw;
|
||||||
private int filter;
|
private int filter;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
private LoadCallback<String, Post> callback;
|
private LoadCallback<String, Post> callback;
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
||||||
int filter) {
|
int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -67,10 +68,11 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType,
|
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType,
|
||||||
String sortType, int filter) {
|
String sortType, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -81,10 +83,11 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType,
|
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType,
|
||||||
String sortType, String where, int filter) {
|
String sortType, String where, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -96,10 +99,11 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
userWhere = where;
|
userWhere = where;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, String query,
|
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, String query,
|
||||||
int postType, String sortType, int filter) {
|
int postType, String sortType, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -111,6 +115,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
MutableLiveData<NetworkState> getPaginationNetworkStateLiveData() {
|
MutableLiveData<NetworkState> getPaginationNetworkStateLiveData() {
|
||||||
@ -206,7 +211,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter,
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
new ParsePost.ParsePostsListingListener() {
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
@ -261,7 +266,8 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter, new ParsePost.ParsePostsListingListener() {
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
||||||
@ -323,7 +329,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter,
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
new ParsePost.ParsePostsListingListener() {
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
@ -384,7 +390,8 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter, new ParsePost.ParsePostsListingListener() {
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
||||||
@ -429,7 +436,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter,
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
new ParsePost.ParsePostsListingListener() {
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
@ -489,7 +496,8 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter, new ParsePost.ParsePostsListingListener() {
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
||||||
@ -526,16 +534,16 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
|
|
||||||
if(subredditOrUserName == null) {
|
if(subredditOrUserName == null) {
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
getPost = api.searchPosts(query, lastItem, sortType);
|
getPost = api.searchPosts(query, lastItem, sortType, nsfw);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsOauth(query, lastItem, sortType, RedditUtils.getOAuthHeader(accessToken));
|
getPost = api.searchPostsOauth(query, lastItem, sortType, nsfw, RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, lastItem);
|
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, lastItem, nsfw);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, lastItem,
|
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, lastItem,
|
||||||
RedditUtils.getOAuthHeader(accessToken));
|
nsfw, RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,7 +551,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter,
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
new ParsePost.ParsePostsListingListener() {
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
@ -595,15 +603,16 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
|
|
||||||
if(subredditOrUserName == null) {
|
if(subredditOrUserName == null) {
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
getPost = api.searchPosts(query, after, sortType);
|
getPost = api.searchPosts(query, after, sortType, nsfw);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsOauth(query, after, sortType, RedditUtils.getOAuthHeader(accessToken));
|
getPost = api.searchPostsOauth(query, after, sortType, nsfw, RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, after);
|
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, after, nsfw);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, after, RedditUtils.getOAuthHeader(accessToken));
|
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, after,
|
||||||
|
nsfw, RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,7 +620,8 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParsePost.parsePosts(response.body(), locale, -1, filter, new ParsePost.ParsePostsListingListener() {
|
ParsePost.parsePosts(response.body(), locale, -1, filter, nsfw,
|
||||||
|
new ParsePost.ParsePostsListingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostsListingSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) {
|
||||||
|
@ -17,12 +17,13 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
private String sortType;
|
private String sortType;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private int filter;
|
private int filter;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
private PostDataSource postDataSource;
|
private PostDataSource postDataSource;
|
||||||
private MutableLiveData<PostDataSource> postDataSourceLiveData;
|
private MutableLiveData<PostDataSource> postDataSourceLiveData;
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
||||||
int filter) {
|
int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -30,10 +31,11 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
||||||
int postType, String sortType, int filter) {
|
int postType, String sortType, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -42,10 +44,11 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
||||||
int postType, String sortType, String where, int filter) {
|
int postType, String sortType, String where, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -55,10 +58,11 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
userWhere = where;
|
userWhere = where;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName,
|
||||||
String query, int postType, String sortType, int filter) {
|
String query, int postType, String sortType, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -68,22 +72,23 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataSource create() {
|
public DataSource create() {
|
||||||
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, sortType,
|
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, sortType,
|
||||||
filter);
|
filter, nsfw);
|
||||||
} else if(postType == PostDataSource.TYPE_SEARCH) {
|
} else if(postType == PostDataSource.TYPE_SEARCH) {
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, query,
|
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, query,
|
||||||
postType, sortType, filter);
|
postType, sortType, filter, nsfw);
|
||||||
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
|
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType,
|
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType,
|
||||||
sortType, filter);
|
sortType, filter, nsfw);
|
||||||
} else {
|
} else {
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType,
|
postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType,
|
||||||
sortType, userWhere, filter);
|
sortType, userWhere, filter, nsfw);
|
||||||
}
|
}
|
||||||
|
|
||||||
postDataSourceLiveData.postValue(postDataSource);
|
postDataSourceLiveData.postValue(postDataSource);
|
||||||
@ -102,8 +107,8 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeAccessTokenAndSortType(String accessToken, String sortType) {
|
void changeNSFWAndSortType(boolean nsfw, String sortType) {
|
||||||
this.accessToken = accessToken;
|
this.nsfw = nsfw;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -49,7 +50,7 @@ import retrofit2.Retrofit;
|
|||||||
public class PostFragment extends Fragment implements FragmentCommunicator {
|
public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||||
|
|
||||||
static final String EXTRA_NAME = "EN";
|
static final String EXTRA_NAME = "EN";
|
||||||
static final String EXTRA_USER_NAME = "EN";
|
static final String EXTRA_USER_NAME = "EUN";
|
||||||
static final String EXTRA_USER_WHERE = "EUW";
|
static final String EXTRA_USER_WHERE = "EUW";
|
||||||
static final String EXTRA_QUERY = "EQ";
|
static final String EXTRA_QUERY = "EQ";
|
||||||
static final String EXTRA_POST_TYPE = "EPT";
|
static final String EXTRA_POST_TYPE = "EPT";
|
||||||
@ -57,6 +58,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
static final String EXTRA_FILTER = "EF";
|
static final String EXTRA_FILTER = "EF";
|
||||||
static final int EXTRA_NO_FILTER = -1;
|
static final int EXTRA_NO_FILTER = -1;
|
||||||
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||||
|
static final String EXTRA_NSFW = "ENSFW";
|
||||||
|
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||||
|
|
||||||
@ -91,7 +93,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
|
|
||||||
public PostFragment() {
|
public PostFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@ -188,6 +193,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
String sortType = getArguments().getString(EXTRA_SORT_TYPE);
|
String sortType = getArguments().getString(EXTRA_SORT_TYPE);
|
||||||
int filter = getArguments().getInt(EXTRA_FILTER);
|
int filter = getArguments().getInt(EXTRA_FILTER);
|
||||||
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
|
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, true);
|
||||||
|
|
||||||
PostViewModel.Factory factory;
|
PostViewModel.Factory factory;
|
||||||
|
|
||||||
@ -195,7 +201,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
String subredditName = getArguments().getString(EXTRA_NAME);
|
String subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
String query = getArguments().getString(EXTRA_QUERY);
|
String query = getArguments().getString(EXTRA_QUERY);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -216,16 +222,18 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
factory = new PostViewModel.Factory(mRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, subredditName, query, postType, sortType, filter);
|
getResources().getConfiguration().locale, subredditName, query, postType,
|
||||||
|
sortType, filter, nsfw);
|
||||||
} else {
|
} else {
|
||||||
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, subredditName, query, postType, sortType, filter);
|
getResources().getConfiguration().locale, subredditName, query, postType,
|
||||||
|
sortType, filter, nsfw);
|
||||||
}
|
}
|
||||||
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
|
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||||
String subredditName = getArguments().getString(EXTRA_NAME);
|
String subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
|
|
||||||
boolean displaySubredditName = subredditName.equals("popular") || subredditName.equals("all");
|
boolean displaySubredditName = subredditName.equals("popular") || subredditName.equals("all");
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, displaySubredditName, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, displaySubredditName, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -245,10 +253,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
factory = new PostViewModel.Factory(mRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, subredditName, postType, sortType, filter);
|
getResources().getConfiguration().locale, subredditName, postType, sortType,
|
||||||
|
filter, nsfw);
|
||||||
} else {
|
} else {
|
||||||
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, subredditName, postType, sortType, filter);
|
getResources().getConfiguration().locale, subredditName, postType, sortType,
|
||||||
|
filter, nsfw);
|
||||||
}
|
}
|
||||||
} else if(postType == PostDataSource.TYPE_USER) {
|
} else if(postType == PostDataSource.TYPE_USER) {
|
||||||
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFetchPostInfoLinearLayout.getLayoutParams();
|
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFetchPostInfoLinearLayout.getLayoutParams();
|
||||||
@ -258,7 +268,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
String username = getArguments().getString(EXTRA_USER_NAME);
|
String username = getArguments().getString(EXTRA_USER_NAME);
|
||||||
String where = getArguments().getString(EXTRA_USER_WHERE);
|
String where = getArguments().getString(EXTRA_USER_WHERE);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -279,13 +289,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
factory = new PostViewModel.Factory(mRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, username, postType, sortType, where, filter);
|
getResources().getConfiguration().locale, username, postType, sortType, where,
|
||||||
|
filter, nsfw);
|
||||||
} else {
|
} else {
|
||||||
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, username, postType, sortType, where, filter);
|
getResources().getConfiguration().locale, username, postType, sortType, where,
|
||||||
|
filter, nsfw);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
||||||
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -304,7 +316,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, postType, sortType, filter);
|
getResources().getConfiguration().locale, postType, sortType, filter, nsfw);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPostRecyclerView.setAdapter(mAdapter);
|
mPostRecyclerView.setAdapter(mAdapter);
|
||||||
@ -369,6 +381,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changeNSFW(boolean nsfw) {
|
||||||
|
mPostViewModel.changeNSFW(nsfw);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startLazyMode() {
|
public void startLazyMode() {
|
||||||
isInLazyMode = true;
|
isInLazyMode = true;
|
||||||
|
@ -21,13 +21,14 @@ public class PostViewModel extends ViewModel {
|
|||||||
private LiveData<NetworkState> initialLoadingState;
|
private LiveData<NetworkState> initialLoadingState;
|
||||||
private LiveData<Boolean> hasPostLiveData;
|
private LiveData<Boolean> hasPostLiveData;
|
||||||
private LiveData<PagedList<Post>> posts;
|
private LiveData<PagedList<Post>> posts;
|
||||||
private MutableLiveData<String> accessTokenLiveData;
|
private MutableLiveData<Boolean> nsfwLiveData;
|
||||||
private MutableLiveData<String> sortTypeLiveData;
|
private MutableLiveData<String> sortTypeLiveData;
|
||||||
private AccessTokenAndSortTypeLiveData accessTokenAndSortTypeLiveData;
|
private nsfwAndSortTypeLiveData NSFWAndSortTypeLiveData;
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
||||||
int filter) {
|
int filter, boolean nsfw) {
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType, sortType, filter);
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType,
|
||||||
|
sortType, filter, nsfw);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::getInitialLoadStateLiveData);
|
PostDataSource::getInitialLoadStateLiveData);
|
||||||
@ -36,12 +37,12 @@ public class PostViewModel extends ViewModel {
|
|||||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::hasPostLiveData);
|
PostDataSource::hasPostLiveData);
|
||||||
|
|
||||||
accessTokenLiveData = new MutableLiveData<>();
|
nsfwLiveData = new MutableLiveData<>();
|
||||||
accessTokenLiveData.postValue(accessToken);
|
nsfwLiveData.postValue(nsfw);
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
|
|
||||||
accessTokenAndSortTypeLiveData = new AccessTokenAndSortTypeLiveData(accessTokenLiveData, sortTypeLiveData);
|
NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
|
||||||
|
|
||||||
PagedList.Config pagedListConfig =
|
PagedList.Config pagedListConfig =
|
||||||
(new PagedList.Config.Builder())
|
(new PagedList.Config.Builder())
|
||||||
@ -49,16 +50,16 @@ public class PostViewModel extends ViewModel {
|
|||||||
.setPageSize(25)
|
.setPageSize(25)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
posts = Transformations.switchMap(accessTokenAndSortTypeLiveData, sort -> {
|
posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> {
|
||||||
postDataSourceFactory.changeAccessTokenAndSortType(accessTokenLiveData.getValue(), sortTypeLiveData.getValue());
|
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
|
||||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
||||||
String sortType, int filter) {
|
String sortType, int filter, boolean nsfw) {
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
||||||
postType, sortType, filter);
|
postType, sortType, filter, nsfw);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::getInitialLoadStateLiveData);
|
PostDataSource::getInitialLoadStateLiveData);
|
||||||
@ -67,12 +68,12 @@ public class PostViewModel extends ViewModel {
|
|||||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::hasPostLiveData);
|
PostDataSource::hasPostLiveData);
|
||||||
|
|
||||||
accessTokenLiveData = new MutableLiveData<>();
|
nsfwLiveData = new MutableLiveData<>();
|
||||||
accessTokenLiveData.postValue(accessToken);
|
nsfwLiveData.postValue(nsfw);
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
|
|
||||||
accessTokenAndSortTypeLiveData = new AccessTokenAndSortTypeLiveData(accessTokenLiveData, sortTypeLiveData);
|
NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
|
||||||
|
|
||||||
PagedList.Config pagedListConfig =
|
PagedList.Config pagedListConfig =
|
||||||
(new PagedList.Config.Builder())
|
(new PagedList.Config.Builder())
|
||||||
@ -80,16 +81,16 @@ public class PostViewModel extends ViewModel {
|
|||||||
.setPageSize(25)
|
.setPageSize(25)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
posts = Transformations.switchMap(accessTokenAndSortTypeLiveData, sort -> {
|
posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> {
|
||||||
postDataSourceFactory.changeAccessTokenAndSortType(accessTokenLiveData.getValue(), sortTypeLiveData.getValue());
|
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
|
||||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
||||||
String sortType, String where, int filter) {
|
String sortType, String where, int filter, boolean nsfw) {
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
||||||
postType, sortType, where, filter);
|
postType, sortType, where, filter, nsfw);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::getInitialLoadStateLiveData);
|
PostDataSource::getInitialLoadStateLiveData);
|
||||||
@ -98,12 +99,12 @@ public class PostViewModel extends ViewModel {
|
|||||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::hasPostLiveData);
|
PostDataSource::hasPostLiveData);
|
||||||
|
|
||||||
accessTokenLiveData = new MutableLiveData<>();
|
nsfwLiveData = new MutableLiveData<>();
|
||||||
accessTokenLiveData.postValue(accessToken);
|
nsfwLiveData.postValue(nsfw);
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
|
|
||||||
accessTokenAndSortTypeLiveData = new AccessTokenAndSortTypeLiveData(accessTokenLiveData, sortTypeLiveData);
|
NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
|
||||||
|
|
||||||
PagedList.Config pagedListConfig =
|
PagedList.Config pagedListConfig =
|
||||||
(new PagedList.Config.Builder())
|
(new PagedList.Config.Builder())
|
||||||
@ -111,16 +112,16 @@ public class PostViewModel extends ViewModel {
|
|||||||
.setPageSize(25)
|
.setPageSize(25)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
posts = Transformations.switchMap(accessTokenAndSortTypeLiveData, sort -> {
|
posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> {
|
||||||
postDataSourceFactory.changeAccessTokenAndSortType(accessTokenLiveData.getValue(), sortTypeLiveData.getValue());
|
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
|
||||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
||||||
int postType, String sortType, int filter) {
|
int postType, String sortType, int filter, boolean nsfw) {
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName,
|
||||||
query, postType, sortType, filter);
|
query, postType, sortType, filter, nsfw);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::getInitialLoadStateLiveData);
|
PostDataSource::getInitialLoadStateLiveData);
|
||||||
@ -129,12 +130,12 @@ public class PostViewModel extends ViewModel {
|
|||||||
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
PostDataSource::hasPostLiveData);
|
PostDataSource::hasPostLiveData);
|
||||||
|
|
||||||
accessTokenLiveData = new MutableLiveData<>();
|
nsfwLiveData = new MutableLiveData<>();
|
||||||
accessTokenLiveData.postValue(accessToken);
|
nsfwLiveData.postValue(nsfw);
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
|
|
||||||
accessTokenAndSortTypeLiveData = new AccessTokenAndSortTypeLiveData(accessTokenLiveData, sortTypeLiveData);
|
NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
|
||||||
|
|
||||||
PagedList.Config pagedListConfig =
|
PagedList.Config pagedListConfig =
|
||||||
(new PagedList.Config.Builder())
|
(new PagedList.Config.Builder())
|
||||||
@ -143,7 +144,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
posts = Transformations.switchMap(sortTypeLiveData, sort -> {
|
posts = Transformations.switchMap(sortTypeLiveData, sort -> {
|
||||||
postDataSourceFactory.changeAccessTokenAndSortType(accessTokenLiveData.getValue(), sortTypeLiveData.getValue());
|
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
|
||||||
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -180,8 +181,8 @@ public class PostViewModel extends ViewModel {
|
|||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeAccessToken(String accessToken) {
|
void changeNSFW(boolean nsfw) {
|
||||||
accessTokenLiveData.postValue(accessToken);
|
nsfwLiveData.postValue(nsfw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||||
@ -194,19 +195,21 @@ public class PostViewModel extends ViewModel {
|
|||||||
private String sortType;
|
private String sortType;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private int filter;
|
private int filter;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
|
||||||
int filter) {
|
int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
||||||
String sortType, int filter) {
|
String sortType, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -214,10 +217,11 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
|
||||||
String sortType, String where, int filter) {
|
String sortType, String where, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -226,10 +230,11 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
userWhere = where;
|
userWhere = where;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, String query,
|
||||||
int postType, String sortType, int filter) {
|
int postType, String sortType, int filter, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
@ -238,27 +243,32 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||||
return (T) new PostViewModel(retrofit, accessToken, locale, postType, sortType, filter);
|
return (T) new PostViewModel(retrofit, accessToken, locale, postType, sortType, filter,
|
||||||
|
nsfw);
|
||||||
} else if(postType == PostDataSource.TYPE_SEARCH){
|
} else if(postType == PostDataSource.TYPE_SEARCH){
|
||||||
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, query, postType, sortType, filter);
|
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, query,
|
||||||
|
postType, sortType, filter, nsfw);
|
||||||
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
|
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||||
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, sortType, filter);
|
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType,
|
||||||
|
sortType, filter, nsfw);
|
||||||
} else {
|
} else {
|
||||||
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType, sortType, userWhere, filter);
|
return (T) new PostViewModel(retrofit, accessToken, locale, subredditName, postType,
|
||||||
|
sortType, userWhere, filter, nsfw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AccessTokenAndSortTypeLiveData extends MediatorLiveData<Pair<String, String>> {
|
private static class nsfwAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, String>> {
|
||||||
public AccessTokenAndSortTypeLiveData(LiveData<String> accessToken, LiveData<String> sortType) {
|
public nsfwAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<String> sortType) {
|
||||||
addSource(accessToken, accessToken1 -> setValue(Pair.create(accessToken1, sortType.getValue())));
|
addSource(nsfw, accessToken1 -> setValue(Pair.create(accessToken1, sortType.getValue())));
|
||||||
addSource(sortType, sortType1 -> setValue(Pair.create(accessToken.getValue(), sortType1)));
|
addSource(sortType, sortType1 -> setValue(Pair.create(nsfw.getValue(), sortType1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import retrofit2.Response;
|
|||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class PullNotificationWorker extends Worker {
|
public class PullNotificationWorker extends Worker {
|
||||||
static final String WORKER_TAG = "PNWT";
|
public static final String WORKER_TAG = "PNWT";
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
|
@ -73,26 +73,33 @@ public interface RedditAPI {
|
|||||||
@GET("/api/info.json?raw_json=1")
|
@GET("/api/info.json?raw_json=1")
|
||||||
Call<String> getInfo(@Query("id") String id);
|
Call<String> getInfo(@Query("id") String id);
|
||||||
|
|
||||||
@GET("subreddits/search.json?raw_json=1&include_over_18=on")
|
@GET("subreddits/search.json?raw_json=1")
|
||||||
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after, @Query("sort") String sort);
|
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after,
|
||||||
|
@Query("sort") String sort, @Query("include_over_18") boolean nsfw);
|
||||||
|
|
||||||
@GET("search.json?raw_json=1&type=user&include_over_18=on")
|
@GET("search.json?raw_json=1&type=user")
|
||||||
Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after, @Query("sort") String sort);
|
Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after,
|
||||||
|
@Query("sort") String sort, @Query("include_over_18") boolean nsfw);
|
||||||
|
|
||||||
@GET("search.json?raw_json=1&type=link&include_over_18=on")
|
@GET("search.json?raw_json=1&type=link")
|
||||||
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after, @Query("sort") String sort,
|
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
|
||||||
|
@Query("sort") String sort, @Query("include_over_18") boolean nsfw,
|
||||||
@HeaderMap Map<String, String> headers);
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("search.json?raw_json=1&type=link&include_over_18=on")
|
@GET("search.json?raw_json=1&type=link")
|
||||||
Call<String> searchPosts(@Query("q") String query, @Query("after") String after, @Query("sort") String sort);
|
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
|
||||||
|
@Query("sort") String sort, @Query("include_over_18") boolean nsfw);
|
||||||
|
|
||||||
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true&include_over_18=on")
|
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true")
|
||||||
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName, @Query("q") String query,
|
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
|
||||||
@Query("after") String after, @HeaderMap Map<String, String> headers);
|
@Query("q") String query, @Query("after") String after,
|
||||||
|
@Query("include_over_18") boolean nsfw,
|
||||||
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true&include_over_18=on")
|
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true")
|
||||||
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName, @Query("q") String query,
|
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
|
||||||
@Query("after") String after);
|
@Query("q") String query, @Query("after") String after,
|
||||||
|
@Query("include_over_18") boolean nsfw);
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("api/comment")
|
@POST("api/comment")
|
||||||
|
@ -132,11 +132,9 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
|
|
||||||
// Get the intent, verify the action and get the query
|
// Get the intent, verify the action and get the query
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String query = intent.getExtras().getString(EXTRA_QUERY);
|
String query = intent.getStringExtra(EXTRA_QUERY);
|
||||||
|
|
||||||
if(intent.hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||||
mSubredditName = intent.getExtras().getString(EXTRA_SUBREDDIT_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(query != null) {
|
if(query != null) {
|
||||||
mQuery = query;
|
mQuery = query;
|
||||||
@ -233,6 +231,11 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
|
||||||
|
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
|
||||||
|
}
|
||||||
|
|
||||||
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||||
|
|
||||||
private PostFragment postFragment;
|
private PostFragment postFragment;
|
||||||
@ -349,5 +352,11 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
getItem(1);
|
getItem(1);
|
||||||
getItem(2);
|
getItem(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeNSFW(boolean nsfw) {
|
||||||
|
if(postFragment != null) {
|
||||||
|
postFragment.changeNSFW(nsfw);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,7 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class SharedPreferencesUtils {
|
public class SharedPreferencesUtils {
|
||||||
static final String AUTH_CODE_FILE_KEY = "Auth_Code_Pref";
|
public static final String ENABLE_NOTIFICATION_KEY = "enable_notification";
|
||||||
static final String USER_INFO_FILE_KEY = "User_Info";
|
public static final String NOTIFICATION_INTERVAL_KEY = "notificaiton_interval";
|
||||||
static final String AUTH_CODE_KEY = "code";
|
public static final String NSFW_KEY = "nsfw";
|
||||||
public static final String ACCESS_TOKEN_KEY = "accessToken";
|
|
||||||
static final String REFRESH_TOKEN_KEY = "refreshToken";
|
|
||||||
static final String USER_KEY = "user";
|
|
||||||
static final String PROFILE_IMAGE_URL_KEY = "profileImageUrl";
|
|
||||||
static final String BANNER_IMAGE_URL_KEY = "bannerImageUrl";
|
|
||||||
static final String KARMA_KEY = "karma";
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
||||||
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
||||||
@ -24,10 +25,11 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
private LoadParams<String> params;
|
private LoadParams<String> params;
|
||||||
private LoadCallback<String, SubredditData> callback;
|
private LoadCallback<String, SubredditData> callback;
|
||||||
|
|
||||||
SubredditListingDataSource(Retrofit retrofit, String query, String sortType) {
|
SubredditListingDataSource(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
this.nsfw = nsfw;
|
||||||
paginationNetworkStateLiveData = new MutableLiveData<>();
|
paginationNetworkStateLiveData = new MutableLiveData<>();
|
||||||
initialLoadStateLiveData = new MutableLiveData<>();
|
initialLoadStateLiveData = new MutableLiveData<>();
|
||||||
hasSubredditLiveData = new MutableLiveData<>();
|
hasSubredditLiveData = new MutableLiveData<>();
|
||||||
@ -52,7 +54,8 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
|
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||||
|
|
||||||
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType, new FetchSubredditData.FetchSubredditListingDataListener() {
|
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType, nsfw,
|
||||||
|
new FetchSubredditData.FetchSubredditListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
||||||
if(subredditData.size() == 0) {
|
if(subredditData.size() == 0) {
|
||||||
@ -86,7 +89,8 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType, new FetchSubredditData.FetchSubredditListingDataListener() {
|
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType, nsfw,
|
||||||
|
new FetchSubredditData.FetchSubredditListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
||||||
callback.onResult(subredditData, after);
|
callback.onResult(subredditData, after);
|
||||||
|
@ -9,21 +9,23 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
|
|||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
private SubredditListingDataSource subredditListingDataSource;
|
private SubredditListingDataSource subredditListingDataSource;
|
||||||
private MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData;
|
private MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData;
|
||||||
|
|
||||||
SubredditListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
|
SubredditListingDataSourceFactory(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
this.nsfw = nsfw;
|
||||||
subredditListingDataSourceMutableLiveData = new MutableLiveData<>();
|
subredditListingDataSourceMutableLiveData = new MutableLiveData<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public DataSource create() {
|
public DataSource create() {
|
||||||
subredditListingDataSource = new SubredditListingDataSource(retrofit, query, sortType);
|
subredditListingDataSource = new SubredditListingDataSource(retrofit, query, sortType, nsfw);
|
||||||
subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource);
|
subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource);
|
||||||
return subredditListingDataSource;
|
return subredditListingDataSource;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
static final String EXTRA_IS_POSTING = "EIP";
|
static final String EXTRA_IS_POSTING = "EIP";
|
||||||
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||||
static final String EXTRA_ACCOUNT_NAME = "EAN";
|
static final String EXTRA_ACCOUNT_NAME = "EAN";
|
||||||
|
static final String EXTRA_NSFW = "EN";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_subreddit_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
@BindView(R.id.coordinator_layout_subreddit_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
||||||
@BindView(R.id.recycler_view_subreddit_listing_fragment) RecyclerView mSubredditListingRecyclerView;
|
@BindView(R.id.recycler_view_subreddit_listing_fragment) RecyclerView mSubredditListingRecyclerView;
|
||||||
@ -99,6 +100,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
boolean isPosting = getArguments().getBoolean(EXTRA_IS_POSTING);
|
boolean isPosting = getArguments().getBoolean(EXTRA_IS_POSTING);
|
||||||
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||||
|
boolean nsfw = getArguments().getBoolean(EXTRA_NSFW);
|
||||||
|
|
||||||
mAdapter = new SubredditListingRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
mAdapter = new SubredditListingRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
||||||
accessToken, accountName, redditDataRoomDatabase,
|
accessToken, accountName, redditDataRoomDatabase,
|
||||||
@ -123,7 +125,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
mSubredditListingRecyclerView.setAdapter(mAdapter);
|
mSubredditListingRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query,
|
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query,
|
||||||
PostDataSource.SORT_TYPE_RELEVANCE);
|
PostDataSource.SORT_TYPE_RELEVANCE, nsfw);
|
||||||
mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class);
|
mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class);
|
||||||
mSubredditListingViewModel.getSubreddits().observe(this, subredditData -> mAdapter.submitList(subredditData));
|
mSubredditListingViewModel.getSubreddits().observe(this, subredditData -> mAdapter.submitList(subredditData));
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ public class SubredditListingViewModel extends ViewModel {
|
|||||||
private LiveData<PagedList<SubredditData>> subreddits;
|
private LiveData<PagedList<SubredditData>> subreddits;
|
||||||
private MutableLiveData<String> sortTypeLiveData;
|
private MutableLiveData<String> sortTypeLiveData;
|
||||||
|
|
||||||
SubredditListingViewModel(Retrofit retrofit, String query, String sortType) {
|
SubredditListingViewModel(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType);
|
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType, nsfw);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
|
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
|
||||||
SubredditListingDataSource::getInitialLoadStateLiveData);
|
SubredditListingDataSource::getInitialLoadStateLiveData);
|
||||||
@ -81,17 +81,19 @@ public class SubredditListingViewModel extends ViewModel {
|
|||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String query, String sortType) {
|
public Factory(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
return (T) new SubredditListingViewModel(retrofit, query, sortType);
|
return (T) new SubredditListingViewModel(retrofit, query, sortType, nsfw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
||||||
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
||||||
@ -24,10 +25,11 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
private PageKeyedDataSource.LoadParams<String> params;
|
private PageKeyedDataSource.LoadParams<String> params;
|
||||||
private PageKeyedDataSource.LoadCallback<String, UserData> callback;
|
private PageKeyedDataSource.LoadCallback<String, UserData> callback;
|
||||||
|
|
||||||
UserListingDataSource(Retrofit retrofit, String query, String sortType) {
|
UserListingDataSource(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
this.nsfw = nsfw;
|
||||||
paginationNetworkStateLiveData = new MutableLiveData<>();
|
paginationNetworkStateLiveData = new MutableLiveData<>();
|
||||||
initialLoadStateLiveData = new MutableLiveData<>();
|
initialLoadStateLiveData = new MutableLiveData<>();
|
||||||
hasUserLiveData = new MutableLiveData<>();
|
hasUserLiveData = new MutableLiveData<>();
|
||||||
@ -52,7 +54,8 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
|
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||||
|
|
||||||
FetchUserData.fetchUserListingData(retrofit, query, null, sortType, new FetchUserData.FetchUserListingDataListener() {
|
FetchUserData.fetchUserListingData(retrofit, query, null, sortType, nsfw,
|
||||||
|
new FetchUserData.FetchUserListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
||||||
if(UserData.size() == 0) {
|
if(UserData.size() == 0) {
|
||||||
@ -86,7 +89,8 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType, new FetchUserData.FetchUserListingDataListener() {
|
FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType, nsfw,
|
||||||
|
new FetchUserData.FetchUserListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
||||||
callback.onResult(UserData, after);
|
callback.onResult(UserData, after);
|
||||||
|
@ -9,21 +9,23 @@ public class UserListingDataSourceFactory extends DataSource.Factory {
|
|||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
private UserListingDataSource userListingDataSource;
|
private UserListingDataSource userListingDataSource;
|
||||||
private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData;
|
private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData;
|
||||||
|
|
||||||
UserListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
|
UserListingDataSourceFactory(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
this.nsfw = nsfw;
|
||||||
userListingDataSourceMutableLiveData = new MutableLiveData<>();
|
userListingDataSourceMutableLiveData = new MutableLiveData<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public DataSource create() {
|
public DataSource create() {
|
||||||
userListingDataSource = new UserListingDataSource(retrofit, query, sortType);
|
userListingDataSource = new UserListingDataSource(retrofit, query, sortType, nsfw);
|
||||||
userListingDataSourceMutableLiveData.postValue(userListingDataSource);
|
userListingDataSourceMutableLiveData.postValue(userListingDataSource);
|
||||||
return userListingDataSource;
|
return userListingDataSource;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
|
|||||||
static final String EXTRA_QUERY = "EQ";
|
static final String EXTRA_QUERY = "EQ";
|
||||||
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||||
static final String EXTRA_ACCOUNT_NAME = "EAN";
|
static final String EXTRA_ACCOUNT_NAME = "EAN";
|
||||||
|
static final String EXTRA_NSFW = "EN";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_user_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
@BindView(R.id.coordinator_layout_user_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
||||||
@BindView(R.id.recycler_view_user_listing_fragment) RecyclerView mUserListingRecyclerView;
|
@BindView(R.id.recycler_view_user_listing_fragment) RecyclerView mUserListingRecyclerView;
|
||||||
@ -102,7 +103,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
|
|||||||
mUserListingRecyclerView.setAdapter(mAdapter);
|
mUserListingRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
|
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
|
||||||
PostDataSource.SORT_TYPE_RELEVANCE);
|
PostDataSource.SORT_TYPE_RELEVANCE, getArguments().getBoolean(EXTRA_NSFW));
|
||||||
mUserListingViewModel = new ViewModelProvider(this, factory).get(UserListingViewModel.class);
|
mUserListingViewModel = new ViewModelProvider(this, factory).get(UserListingViewModel.class);
|
||||||
mUserListingViewModel.getUsers().observe(this, UserData -> mAdapter.submitList(UserData));
|
mUserListingViewModel.getUsers().observe(this, UserData -> mAdapter.submitList(UserData));
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ public class UserListingViewModel extends ViewModel {
|
|||||||
private LiveData<PagedList<UserData>> users;
|
private LiveData<PagedList<UserData>> users;
|
||||||
private MutableLiveData<String> sortTypeLiveData;
|
private MutableLiveData<String> sortTypeLiveData;
|
||||||
|
|
||||||
UserListingViewModel(Retrofit retrofit, String query, String sortType) {
|
UserListingViewModel(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType);
|
userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType, nsfw);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
|
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
|
||||||
UserListingDataSource::getInitialLoadStateLiveData);
|
UserListingDataSource::getInitialLoadStateLiveData);
|
||||||
@ -81,17 +81,19 @@ public class UserListingViewModel extends ViewModel {
|
|||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private String query;
|
private String query;
|
||||||
private String sortType;
|
private String sortType;
|
||||||
|
private boolean nsfw;
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String query, String sortType) {
|
public Factory(Retrofit retrofit, String query, String sortType, boolean nsfw) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
|
this.nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
return (T) new UserListingViewModel(retrofit, query, sortType);
|
return (T) new UserListingViewModel(retrofit, query, sortType, nsfw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,6 +545,12 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
|
||||||
|
((FragmentCommunicator) mFragment).changeNSFW(changeNSFWEvent.nsfw);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class InsertSubredditDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
private static class InsertSubredditDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
interface InsertSubredditDataAsyncTaskListener {
|
interface InsertSubredditDataAsyncTaskListener {
|
||||||
|
@ -572,6 +572,11 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
|
||||||
|
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
|
||||||
|
}
|
||||||
|
|
||||||
private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
interface InsertUserDataAsyncTaskListener {
|
interface InsertUserDataAsyncTaskListener {
|
||||||
@ -710,5 +715,11 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeNSFW(boolean nsfw) {
|
||||||
|
if(postFragment != null) {
|
||||||
|
postFragment.changeNSFW(nsfw);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@
|
|||||||
android:id="@+id/subreddit_name_relative_layout_search_activity"
|
android:id="@+id/subreddit_name_relative_layout_search_activity"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:background="?attr/selectableItemBackground">
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/search_in_text_view_search_activity"
|
android:id="@+id/search_in_text_view_search_activity"
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
app:defaultValue="true"
|
app:defaultValue="false"
|
||||||
app:key="nsfw"
|
app:key="nsfw"
|
||||||
app:title="@string/settings_enable_nsfw_title"/>
|
app:title="@string/settings_enable_nsfw_title"/>
|
||||||
|
|
||||||
|
@ -9,12 +9,13 @@
|
|||||||
app:title="@string/settings_notification_enable_notification_title"/>
|
app:title="@string/settings_notification_enable_notification_title"/>
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:defaultValue="2"
|
app:defaultValue="1"
|
||||||
app:entries="@array/settings_notification_interval"
|
app:entries="@array/settings_notification_interval"
|
||||||
app:entryValues="@array/settings_notification_interval_values"
|
app:entryValues="@array/settings_notification_interval_values"
|
||||||
app:key="notificaiton_interval"
|
app:key="notificaiton_interval"
|
||||||
app:icon="@drawable/ic_outline_access_time_24px"
|
app:icon="@drawable/ic_outline_access_time_24px"
|
||||||
app:title="@string/settings_notification_interval_title"
|
app:title="@string/settings_notification_interval_title"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true"
|
||||||
|
app:isPreferenceVisible="false" />
|
||||||
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user