mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 11:17:25 +01:00
Changing theme is now available.
This commit is contained in:
parent
a2fe95912b
commit
0840b7144f
@ -1,8 +1,11 @@
|
|||||||
package Settings;
|
package Settings;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
@ -12,6 +15,11 @@ import ml.docilealligator.infinityforreddit.ChangeNSFWEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
|
||||||
|
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link PreferenceFragmentCompat} subclass.
|
* A simple {@link PreferenceFragmentCompat} subclass.
|
||||||
*/
|
*/
|
||||||
@ -21,11 +29,42 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
setPreferencesFromResource(R.xml.main_preferences, rootKey);
|
setPreferencesFromResource(R.xml.main_preferences, rootKey);
|
||||||
|
|
||||||
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
|
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
|
||||||
|
ListPreference listPreference = findPreference(SharedPreferencesUtils.THEME_KEY);
|
||||||
|
|
||||||
if(nsfwSwitch != null) {
|
if(nsfwSwitch != null) {
|
||||||
nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));
|
EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||||||
|
|
||||||
|
if(listPreference != null) {
|
||||||
|
if(systemDefault) {
|
||||||
|
listPreference.setEntries(R.array.settings_theme_q);
|
||||||
|
} else {
|
||||||
|
listPreference.setEntries(R.array.settings_theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
listPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
int option = Integer.parseInt((String) newValue);
|
||||||
|
switch (option) {
|
||||||
|
case 0:
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if(systemDefault) {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
|
||||||
|
} else {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,20 +7,14 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
import androidx.work.Constraints;
|
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.google.common.util.concurrent.ListenableFuture;
|
|
||||||
|
|
||||||
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;
|
||||||
@ -87,25 +81,15 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} 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);
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(notificationIntervalListPreference != null) {
|
if(notificationIntervalListPreference != null) {
|
||||||
notificationIntervalListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
notificationIntervalListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
@Override
|
notificationInterval = Long.parseLong((String) newValue);
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
notificationInterval = (Long) newValue;
|
|
||||||
|
|
||||||
if(enableNotification) {
|
if(enableNotification) {
|
||||||
Constraints constraints = new Constraints.Builder()
|
Constraints constraints = new Constraints.Builder()
|
||||||
@ -121,19 +105,10 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} 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);
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,4 +38,5 @@ public interface AppComponent {
|
|||||||
void inject(PullNotificationWorker pullNotificationWorker);
|
void inject(PullNotificationWorker pullNotificationWorker);
|
||||||
void inject(ViewMessageActivity viewMessageActivity);
|
void inject(ViewMessageActivity viewMessageActivity);
|
||||||
void inject(NotificationPreferenceFragment notificationPreferenceFragment);
|
void inject(NotificationPreferenceFragment notificationPreferenceFragment);
|
||||||
|
void inject(LinkResolverActivity linkResolverActivity);
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,10 @@ class FetchSubredditData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void fetchSubredditListingData(Retrofit retrofit, String query, String after, String sortType,
|
static void fetchSubredditListingData(Retrofit retrofit, String query, String after, String sortType,
|
||||||
boolean nsfw,
|
|
||||||
final FetchSubredditListingDataListener fetchSubredditListingDataListener) {
|
final FetchSubredditListingDataListener fetchSubredditListingDataListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw);
|
Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType);
|
||||||
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) {
|
||||||
|
@ -56,11 +56,10 @@ public class FetchUserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, nsfw);
|
Call<String> userInfo = api.searchUsers(query, after, sortType);
|
||||||
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) {
|
||||||
|
@ -1,18 +1,27 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
import androidx.browser.customtabs.CustomTabsIntent;
|
import androidx.browser.customtabs.CustomTabsIntent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||||
import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION;
|
import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION;
|
||||||
|
|
||||||
public class LinkResolverActivity extends AppCompatActivity {
|
public class LinkResolverActivity extends AppCompatActivity {
|
||||||
@ -25,12 +34,42 @@ public class LinkResolverActivity extends AppCompatActivity {
|
|||||||
private static final String SUBREDDIT_PATTERN = "/r/\\w+/*";
|
private static final String SUBREDDIT_PATTERN = "/r/\\w+/*";
|
||||||
private static final String USER_PATTERN = "/user/\\w+/*";
|
private static final String USER_PATTERN = "/user/\\w+/*";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||||
|
|
||||||
|
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||||||
|
int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
|
||||||
|
switch (themeType) {
|
||||||
|
case 0:
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if(systemDefault) {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
|
||||||
|
} else {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Uri uri = getIntent().getData();
|
Uri uri = getIntent().getData();
|
||||||
|
if(uri == null) {
|
||||||
|
Toast.makeText(this, R.string.no_link_available, Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
String path = uri.getPath();
|
String path = uri.getPath();
|
||||||
|
if(path == null) {
|
||||||
|
deepLinkError(uri);
|
||||||
|
} else {
|
||||||
if(path.endsWith("/")) {
|
if(path.endsWith("/")) {
|
||||||
path = path.substring(0, path.length() - 1);
|
path = path.substring(0, path.length() - 1);
|
||||||
}
|
}
|
||||||
@ -87,9 +126,11 @@ public class LinkResolverActivity extends AppCompatActivity {
|
|||||||
} else {
|
} else {
|
||||||
deepLinkError(uri);
|
deepLinkError(uri);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void deepLinkError(Uri uri) {
|
private void deepLinkError(Uri uri) {
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
|
@ -21,6 +21,7 @@ import android.widget.Toast;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.core.view.GravityCompat;
|
import androidx.core.view.GravityCompat;
|
||||||
@ -37,7 +38,6 @@ 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;
|
||||||
@ -47,13 +47,10 @@ 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;
|
||||||
@ -67,6 +64,11 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
|||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||||
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
|
public class MainActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
|
||||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
|
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
|
||||||
|
|
||||||
@ -212,6 +214,24 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||||||
|
int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
|
||||||
|
switch (themeType) {
|
||||||
|
case 0:
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if(systemDefault) {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
|
||||||
|
} else {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
|
postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
|
||||||
|
|
||||||
bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
||||||
@ -297,18 +317,10 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
} else {
|
} 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);
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}).execute();
|
}).execute();
|
||||||
@ -331,18 +343,10 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
} else {
|
} 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);
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
@ -369,18 +373,10 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
} else {
|
} 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);
|
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
@ -388,6 +384,10 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
|
if(isDestroyed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
viewPager.setAdapter(sectionsPagerAdapter);
|
viewPager.setAdapter(sectionsPagerAdapter);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
viewPager.setOffscreenPageLimit(2);
|
||||||
|
@ -534,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, nsfw);
|
getPost = api.searchPosts(query, lastItem, sortType);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsOauth(query, lastItem, sortType, nsfw, RedditUtils.getOAuthHeader(accessToken));
|
getPost = api.searchPostsOauth(query, lastItem, sortType, RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, lastItem, nsfw);
|
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, lastItem);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, lastItem,
|
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, lastItem,
|
||||||
nsfw, RedditUtils.getOAuthHeader(accessToken));
|
RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,16 +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, nsfw);
|
getPost = api.searchPosts(query, after, sortType);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsOauth(query, after, sortType, nsfw, RedditUtils.getOAuthHeader(accessToken));
|
getPost = api.searchPostsOauth(query, after, sortType, RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(accessToken == null) {
|
if(accessToken == null) {
|
||||||
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, after, nsfw);
|
getPost = api.searchPostsInSpecificSubreddit(subredditOrUserName, query, after);
|
||||||
} else {
|
} else {
|
||||||
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, after,
|
getPost = api.searchPostsInSpecificSubredditOauth(subredditOrUserName, query, after,
|
||||||
nsfw, RedditUtils.getOAuthHeader(accessToken));
|
RedditUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ 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";
|
||||||
|
|
||||||
|
@ -75,31 +75,29 @@ public interface RedditAPI {
|
|||||||
|
|
||||||
@GET("subreddits/search.json?raw_json=1")
|
@GET("subreddits/search.json?raw_json=1")
|
||||||
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after,
|
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after,
|
||||||
@Query("sort") String sort, @Query("include_over_18") boolean nsfw);
|
@Query("sort") String sort);
|
||||||
|
|
||||||
@GET("search.json?raw_json=1&type=user")
|
@GET("search.json?raw_json=1&type=user")
|
||||||
Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after,
|
Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after,
|
||||||
@Query("sort") String sort, @Query("include_over_18") boolean nsfw);
|
@Query("sort") String sort);
|
||||||
|
|
||||||
@GET("search.json?raw_json=1&type=link")
|
@GET("search.json?raw_json=1&type=link")
|
||||||
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
|
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
|
||||||
@Query("sort") String sort, @Query("include_over_18") boolean nsfw,
|
@Query("sort") String sort,
|
||||||
@HeaderMap Map<String, String> headers);
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("search.json?raw_json=1&type=link")
|
@GET("search.json?raw_json=1&type=link")
|
||||||
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
|
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
|
||||||
@Query("sort") String sort, @Query("include_over_18") boolean nsfw);
|
@Query("sort") String sort);
|
||||||
|
|
||||||
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true")
|
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true")
|
||||||
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
|
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
|
||||||
@Query("q") String query, @Query("after") String after,
|
@Query("q") String query, @Query("after") String after,
|
||||||
@Query("include_over_18") boolean nsfw,
|
|
||||||
@HeaderMap Map<String, String> headers);
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true")
|
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true")
|
||||||
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
|
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
|
||||||
@Query("q") String query, @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")
|
||||||
|
@ -8,4 +8,5 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String ENABLE_NOTIFICATION_KEY = "enable_notification";
|
public static final String ENABLE_NOTIFICATION_KEY = "enable_notification";
|
||||||
public static final String NOTIFICATION_INTERVAL_KEY = "notificaiton_interval";
|
public static final String NOTIFICATION_INTERVAL_KEY = "notificaiton_interval";
|
||||||
public static final String NSFW_KEY = "nsfw";
|
public static final String NSFW_KEY = "nsfw";
|
||||||
|
public static final String THEME_KEY = "theme";
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ 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;
|
||||||
@ -25,11 +24,10 @@ 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, boolean nsfw) {
|
SubredditListingDataSource(Retrofit retrofit, String query, String sortType) {
|
||||||
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<>();
|
||||||
@ -54,7 +52,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
|
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||||
|
|
||||||
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType, nsfw,
|
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType,
|
||||||
new FetchSubredditData.FetchSubredditListingDataListener() {
|
new FetchSubredditData.FetchSubredditListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
||||||
@ -89,7 +87,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType, nsfw,
|
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType,
|
||||||
new FetchSubredditData.FetchSubredditListingDataListener() {
|
new FetchSubredditData.FetchSubredditListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
||||||
|
@ -9,23 +9,21 @@ 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, boolean nsfw) {
|
SubredditListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
|
||||||
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, nsfw);
|
subredditListingDataSource = new SubredditListingDataSource(retrofit, query, sortType);
|
||||||
subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource);
|
subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource);
|
||||||
return subredditListingDataSource;
|
return subredditListingDataSource;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ 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;
|
||||||
@ -100,7 +99,6 @@ 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,
|
||||||
@ -125,7 +123,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, nsfw);
|
PostDataSource.SORT_TYPE_RELEVANCE);
|
||||||
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, boolean nsfw) {
|
SubredditListingViewModel(Retrofit retrofit, String query, String sortType) {
|
||||||
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType, nsfw);
|
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
|
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
|
||||||
SubredditListingDataSource::getInitialLoadStateLiveData);
|
SubredditListingDataSource::getInitialLoadStateLiveData);
|
||||||
@ -81,19 +81,17 @@ 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, boolean nsfw) {
|
public Factory(Retrofit retrofit, String query, String sortType) {
|
||||||
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, nsfw);
|
return (T) new SubredditListingViewModel(retrofit, query, sortType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ 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;
|
||||||
@ -25,11 +24,10 @@ 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, boolean nsfw) {
|
UserListingDataSource(Retrofit retrofit, String query, String sortType) {
|
||||||
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<>();
|
||||||
@ -54,7 +52,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
|
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||||
|
|
||||||
FetchUserData.fetchUserListingData(retrofit, query, null, sortType, nsfw,
|
FetchUserData.fetchUserListingData(retrofit, query, null, sortType,
|
||||||
new FetchUserData.FetchUserListingDataListener() {
|
new FetchUserData.FetchUserListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
||||||
@ -89,7 +87,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType, nsfw,
|
FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType,
|
||||||
new FetchUserData.FetchUserListingDataListener() {
|
new FetchUserData.FetchUserListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
|
||||||
|
@ -9,23 +9,21 @@ 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, boolean nsfw) {
|
UserListingDataSourceFactory(Retrofit retrofit, String query, String sortType) {
|
||||||
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, nsfw);
|
userListingDataSource = new UserListingDataSource(retrofit, query, sortType);
|
||||||
userListingDataSourceMutableLiveData.postValue(userListingDataSource);
|
userListingDataSourceMutableLiveData.postValue(userListingDataSource);
|
||||||
return userListingDataSource;
|
return userListingDataSource;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ 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;
|
||||||
@ -103,7 +102,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, getArguments().getBoolean(EXTRA_NSFW));
|
PostDataSource.SORT_TYPE_RELEVANCE);
|
||||||
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, boolean nsfw) {
|
UserListingViewModel(Retrofit retrofit, String query, String sortType) {
|
||||||
userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType, nsfw);
|
userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
|
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
|
||||||
UserListingDataSource::getInitialLoadStateLiveData);
|
UserListingDataSource::getInitialLoadStateLiveData);
|
||||||
@ -81,19 +81,17 @@ 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, boolean nsfw) {
|
public Factory(Retrofit retrofit, String query, String sortType) {
|
||||||
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, nsfw);
|
return (T) new UserListingViewModel(retrofit, query, sortType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,18 @@
|
|||||||
<item>24</item>
|
<item>24</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="settings_theme">
|
<string-array name="settings_theme_q">
|
||||||
<item>Light Theme</item>
|
<item>Light Theme</item>
|
||||||
<item>Dark Theme</item>
|
<item>Dark Theme</item>
|
||||||
<item>Device Default</item>
|
<item>Device Default</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="settings_theme">
|
||||||
|
<item>Light Theme</item>
|
||||||
|
<item>Dark Theme</item>
|
||||||
|
<item>Set by Battery Saver</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="settings_theme_values">
|
<string-array name="settings_theme_values">
|
||||||
<item>0</item>
|
<item>0</item>
|
||||||
<item>1</item>
|
<item>1</item>
|
||||||
|
@ -250,4 +250,6 @@
|
|||||||
<string name="settings_theme_dark_theme_summary">Dark Theme</string>
|
<string name="settings_theme_dark_theme_summary">Dark Theme</string>
|
||||||
<string name="settings_theme_system_default_summary">Device default</string>
|
<string name="settings_theme_system_default_summary">Device default</string>
|
||||||
<string name="settings_enable_nsfw_title">Enable NSFW</string>
|
<string name="settings_enable_nsfw_title">Enable NSFW</string>
|
||||||
|
|
||||||
|
<string name="no_link_available">Cannot get the link</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -9,8 +9,7 @@
|
|||||||
app:fragment="Settings.NotificationPreferenceFragment" />
|
app:fragment="Settings.NotificationPreferenceFragment" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:defaultValue="0"
|
app:defaultValue="2"
|
||||||
app:entries="@array/settings_theme"
|
|
||||||
app:entryValues="@array/settings_theme_values"
|
app:entryValues="@array/settings_theme_values"
|
||||||
app:key="theme"
|
app:key="theme"
|
||||||
app:icon="@drawable/ic_outline_color_lens_24px"
|
app:icon="@drawable/ic_outline_color_lens_24px"
|
||||||
|
Loading…
Reference in New Issue
Block a user